wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Denis Peter, MPL AG Switzerland |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * SCSI support. |
| 10 | */ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 11 | #include <common.h> |
| 12 | #include <command.h> |
Simon Glass | f360947 | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 13 | #include <inttypes.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 14 | #include <asm/processor.h> |
| 15 | #include <scsi.h> |
| 16 | #include <image.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 17 | #include <pci.h> |
| 18 | |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 19 | #ifdef CONFIG_SCSI_DEV_LIST |
| 20 | #define SCSI_DEV_LIST CONFIG_SCSI_DEV_LIST |
| 21 | #else |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 22 | #ifdef CONFIG_SCSI_SYM53C8XX |
| 23 | #define SCSI_VEND_ID 0x1000 |
| 24 | #ifndef CONFIG_SCSI_DEV_ID |
| 25 | #define SCSI_DEV_ID 0x0001 |
| 26 | #else |
| 27 | #define SCSI_DEV_ID CONFIG_SCSI_DEV_ID |
| 28 | #endif |
Jin Zhengxiong | 4782ac8 | 2006-08-23 19:10:44 +0800 | [diff] [blame] | 29 | #elif defined CONFIG_SATA_ULI5288 |
| 30 | |
| 31 | #define SCSI_VEND_ID 0x10b9 |
| 32 | #define SCSI_DEV_ID 0x5288 |
| 33 | |
Rob Herring | 942e314 | 2011-07-06 16:13:36 +0000 | [diff] [blame] | 34 | #elif !defined(CONFIG_SCSI_AHCI_PLAT) |
Jin Zhengxiong | 4782ac8 | 2006-08-23 19:10:44 +0800 | [diff] [blame] | 35 | #error no scsi device defined |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 36 | #endif |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 37 | #define SCSI_DEV_LIST {SCSI_VEND_ID, SCSI_DEV_ID} |
| 38 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 39 | |
tang yuantian | 1a1cf6e | 2015-03-20 10:27:54 +0800 | [diff] [blame] | 40 | #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 41 | const struct pci_device_id scsi_device_list[] = { SCSI_DEV_LIST }; |
| 42 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 43 | static ccb tempccb; /* temporary scsi command buffer */ |
| 44 | |
| 45 | static unsigned char tempbuff[512]; /* temporary data buffer */ |
| 46 | |
| 47 | static int scsi_max_devs; /* number of highest available scsi device */ |
| 48 | |
| 49 | static int scsi_curr_dev; /* current device */ |
| 50 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 51 | static struct blk_desc scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE]; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************** |
| 54 | * forward declerations of some Setup Routines |
| 55 | */ |
| 56 | void scsi_setup_test_unit_ready(ccb * pccb); |
Mark Langsdorf | 35df893 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 57 | void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks); |
| 58 | void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks); |
Mark Langsdorf | 2b42c93 | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 59 | void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks); |
| 60 | |
Mark Langsdorf | 35df893 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 61 | static void scsi_setup_write_ext(ccb *pccb, lbaint_t start, |
| 62 | unsigned short blocks); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 63 | void scsi_setup_inquiry(ccb * pccb); |
| 64 | void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len); |
| 65 | |
| 66 | |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 67 | static int scsi_read_capacity(ccb *pccb, lbaint_t *capacity, |
| 68 | unsigned long *blksz); |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 69 | static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr, |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 70 | lbaint_t blkcnt, void *buffer); |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 71 | static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr, |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 72 | lbaint_t blkcnt, const void *buffer); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | /********************************************************************************* |
| 76 | * (re)-scan the scsi bus and reports scsi device info |
| 77 | * to the user if mode = 1 |
| 78 | */ |
| 79 | void scsi_scan(int mode) |
| 80 | { |
| 81 | unsigned char i,perq,modi,lun; |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 82 | lbaint_t capacity; |
| 83 | unsigned long blksz; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 84 | ccb* pccb=(ccb *)&tempccb; |
| 85 | |
| 86 | if(mode==1) { |
| 87 | printf("scanning bus for devices...\n"); |
| 88 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | for(i=0;i<CONFIG_SYS_SCSI_MAX_DEVICE;i++) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 90 | scsi_dev_desc[i].target=0xff; |
| 91 | scsi_dev_desc[i].lun=0xff; |
| 92 | scsi_dev_desc[i].lba=0; |
| 93 | scsi_dev_desc[i].blksz=0; |
Egbert Eich | 0472fbf | 2013-04-09 21:11:56 +0000 | [diff] [blame] | 94 | scsi_dev_desc[i].log2blksz = |
| 95 | LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz)); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 96 | scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN; |
| 97 | scsi_dev_desc[i].vendor[0]=0; |
| 98 | scsi_dev_desc[i].product[0]=0; |
| 99 | scsi_dev_desc[i].revision[0]=0; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 100 | scsi_dev_desc[i].removable = false; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 101 | scsi_dev_desc[i].if_type=IF_TYPE_SCSI; |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 102 | scsi_dev_desc[i].devnum = i; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 103 | scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN; |
| 104 | scsi_dev_desc[i].block_read=scsi_read; |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 105 | scsi_dev_desc[i].block_write = scsi_write; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 106 | } |
| 107 | scsi_max_devs=0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | for(i=0;i<CONFIG_SYS_SCSI_MAX_SCSI_ID;i++) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 109 | pccb->target=i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 110 | for(lun=0;lun<CONFIG_SYS_SCSI_MAX_LUN;lun++) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 111 | pccb->lun=lun; |
| 112 | pccb->pdata=(unsigned char *)&tempbuff; |
| 113 | pccb->datalen=512; |
| 114 | scsi_setup_inquiry(pccb); |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 115 | if (scsi_exec(pccb) != true) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 116 | if(pccb->contr_stat==SCSI_SEL_TIME_OUT) { |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 117 | debug ("Selection timeout ID %d\n",pccb->target); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 118 | continue; /* selection timeout => assuming no device present */ |
| 119 | } |
| 120 | scsi_print_error(pccb); |
| 121 | continue; |
| 122 | } |
| 123 | perq=tempbuff[0]; |
| 124 | modi=tempbuff[1]; |
| 125 | if((perq & 0x1f)==0x1f) { |
| 126 | continue; /* skip unknown devices */ |
| 127 | } |
| 128 | if((modi&0x80)==0x80) /* drive is removable */ |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 129 | scsi_dev_desc[scsi_max_devs].removable=true; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 130 | /* get info for this device */ |
Stefan Roese | 2309c13 | 2007-11-17 07:58:25 +0100 | [diff] [blame] | 131 | scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].vendor[0], |
| 132 | &tempbuff[8], 8); |
| 133 | scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].product[0], |
| 134 | &tempbuff[16], 16); |
| 135 | scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].revision[0], |
| 136 | &tempbuff[32], 4); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 137 | scsi_dev_desc[scsi_max_devs].target=pccb->target; |
| 138 | scsi_dev_desc[scsi_max_devs].lun=pccb->lun; |
| 139 | |
| 140 | pccb->datalen=0; |
| 141 | scsi_setup_test_unit_ready(pccb); |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 142 | if (scsi_exec(pccb) != true) { |
| 143 | if (scsi_dev_desc[scsi_max_devs].removable == true) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 144 | scsi_dev_desc[scsi_max_devs].type=perq; |
| 145 | goto removable; |
| 146 | } |
| 147 | scsi_print_error(pccb); |
| 148 | continue; |
| 149 | } |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 150 | if (scsi_read_capacity(pccb, &capacity, &blksz)) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 151 | scsi_print_error(pccb); |
| 152 | continue; |
| 153 | } |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 154 | scsi_dev_desc[scsi_max_devs].lba=capacity; |
| 155 | scsi_dev_desc[scsi_max_devs].blksz=blksz; |
Egbert Eich | 0472fbf | 2013-04-09 21:11:56 +0000 | [diff] [blame] | 156 | scsi_dev_desc[scsi_max_devs].log2blksz = |
| 157 | LOG2(scsi_dev_desc[scsi_max_devs].blksz); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 158 | scsi_dev_desc[scsi_max_devs].type=perq; |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 159 | part_init(&scsi_dev_desc[scsi_max_devs]); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 160 | removable: |
| 161 | if(mode==1) { |
| 162 | printf (" Device %d: ", scsi_max_devs); |
| 163 | dev_print(&scsi_dev_desc[scsi_max_devs]); |
| 164 | } /* if mode */ |
| 165 | scsi_max_devs++; |
| 166 | } /* next LUN */ |
| 167 | } |
| 168 | if(scsi_max_devs>0) |
| 169 | scsi_curr_dev=0; |
| 170 | else |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 171 | scsi_curr_dev = -1; |
Stefan Reinauer | 447c031 | 2012-10-29 05:23:48 +0000 | [diff] [blame] | 172 | |
| 173 | printf("Found %d device(s).\n", scsi_max_devs); |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 174 | #ifndef CONFIG_SPL_BUILD |
Stefan Reinauer | 447c031 | 2012-10-29 05:23:48 +0000 | [diff] [blame] | 175 | setenv_ulong("scsidevs", scsi_max_devs); |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 176 | #endif |
Stefan Reinauer | 447c031 | 2012-10-29 05:23:48 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | int scsi_get_disk_count(void) |
| 180 | { |
| 181 | return scsi_max_devs; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 182 | } |
| 183 | |
tang yuantian | 1a1cf6e | 2015-03-20 10:27:54 +0800 | [diff] [blame] | 184 | #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 185 | void scsi_init(void) |
| 186 | { |
Simon Glass | 9fbdb94 | 2015-11-29 13:17:51 -0700 | [diff] [blame] | 187 | int busdevfunc = -1; |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 188 | int i; |
| 189 | /* |
| 190 | * Find a device from the list, this driver will support a single |
| 191 | * controller. |
| 192 | */ |
| 193 | for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) { |
| 194 | /* get PCI Device ID */ |
Simon Glass | 9fbdb94 | 2015-11-29 13:17:51 -0700 | [diff] [blame] | 195 | #ifdef CONFIG_DM_PCI |
| 196 | struct udevice *dev; |
| 197 | int ret; |
| 198 | |
| 199 | ret = dm_pci_find_device(scsi_device_list[i].vendor, |
| 200 | scsi_device_list[i].device, 0, &dev); |
| 201 | if (!ret) { |
| 202 | busdevfunc = dm_pci_get_bdf(dev); |
| 203 | break; |
| 204 | } |
| 205 | #else |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 206 | busdevfunc = pci_find_device(scsi_device_list[i].vendor, |
| 207 | scsi_device_list[i].device, |
| 208 | 0); |
Simon Glass | 9fbdb94 | 2015-11-29 13:17:51 -0700 | [diff] [blame] | 209 | #endif |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 210 | if (busdevfunc != -1) |
| 211 | break; |
| 212 | } |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 213 | |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 214 | if (busdevfunc == -1) { |
| 215 | printf("Error: SCSI Controller(s) "); |
| 216 | for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) { |
| 217 | printf("%04X:%04X ", |
| 218 | scsi_device_list[i].vendor, |
| 219 | scsi_device_list[i].device); |
| 220 | } |
| 221 | printf("not found\n"); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 222 | return; |
| 223 | } |
| 224 | #ifdef DEBUG |
| 225 | else { |
Vadim Bendebury | 4ae5eb7 | 2012-10-29 05:23:45 +0000 | [diff] [blame] | 226 | printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n", |
| 227 | scsi_device_list[i].vendor, |
| 228 | scsi_device_list[i].device, |
| 229 | (busdevfunc >> 16) & 0xFF, |
| 230 | (busdevfunc >> 11) & 0x1F, |
| 231 | (busdevfunc >> 8) & 0x7); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 232 | } |
| 233 | #endif |
Simon Glass | abbdb26 | 2015-01-27 22:13:44 -0700 | [diff] [blame] | 234 | bootstage_start(BOOTSTAGE_ID_ACCUM_SCSI, "ahci"); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 235 | scsi_low_level_init(busdevfunc); |
| 236 | scsi_scan(1); |
Simon Glass | abbdb26 | 2015-01-27 22:13:44 -0700 | [diff] [blame] | 237 | bootstage_accum(BOOTSTAGE_ID_ACCUM_SCSI); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 238 | } |
Rob Herring | 942e314 | 2011-07-06 16:13:36 +0000 | [diff] [blame] | 239 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 240 | |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 241 | #ifdef CONFIG_PARTITIONS |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 242 | struct blk_desc *scsi_get_dev(int dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 243 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 244 | return (dev < CONFIG_SYS_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 245 | } |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 246 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 247 | |
Tom Rini | ba52426 | 2016-03-16 09:45:03 -0400 | [diff] [blame] | 248 | #ifndef CONFIG_SPL_BUILD |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 249 | /****************************************************************************** |
| 250 | * scsi boot command intepreter. Derived from diskboot |
| 251 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 252 | int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 253 | { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 254 | return common_diskboot(cmdtp, "scsi", argc, argv); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /********************************************************************************* |
| 258 | * scsi command intepreter |
| 259 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 260 | int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 261 | { |
| 262 | switch (argc) { |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 263 | case 0: |
| 264 | case 1: |
| 265 | return CMD_RET_USAGE; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 266 | |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 267 | case 2: |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 268 | if (strncmp(argv[1],"res",3) == 0) { |
| 269 | printf("\nReset SCSI\n"); |
| 270 | scsi_bus_reset(); |
| 271 | scsi_scan(1); |
| 272 | return 0; |
| 273 | } |
| 274 | if (strncmp(argv[1],"inf",3) == 0) { |
| 275 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 276 | for (i=0; i<CONFIG_SYS_SCSI_MAX_DEVICE; ++i) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 277 | if(scsi_dev_desc[i].type==DEV_TYPE_UNKNOWN) |
| 278 | continue; /* list only known devices */ |
| 279 | printf ("SCSI dev. %d: ", i); |
| 280 | dev_print(&scsi_dev_desc[i]); |
| 281 | } |
| 282 | return 0; |
| 283 | } |
| 284 | if (strncmp(argv[1],"dev",3) == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 285 | if ((scsi_curr_dev < 0) || (scsi_curr_dev >= CONFIG_SYS_SCSI_MAX_DEVICE)) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 286 | printf("\nno SCSI devices available\n"); |
| 287 | return 1; |
| 288 | } |
| 289 | printf ("\n Device %d: ", scsi_curr_dev); |
| 290 | dev_print(&scsi_dev_desc[scsi_curr_dev]); |
| 291 | return 0; |
| 292 | } |
| 293 | if (strncmp(argv[1],"scan",4) == 0) { |
| 294 | scsi_scan(1); |
| 295 | return 0; |
| 296 | } |
| 297 | if (strncmp(argv[1],"part",4) == 0) { |
| 298 | int dev, ok; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 299 | for (ok=0, dev=0; dev<CONFIG_SYS_SCSI_MAX_DEVICE; ++dev) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 300 | if (scsi_dev_desc[dev].type!=DEV_TYPE_UNKNOWN) { |
| 301 | ok++; |
| 302 | if (dev) |
| 303 | printf("\n"); |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 304 | debug ("print_part of %x\n",dev); |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 305 | part_print(&scsi_dev_desc[dev]); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | if (!ok) |
| 309 | printf("\nno SCSI devices available\n"); |
| 310 | return 1; |
| 311 | } |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 312 | return CMD_RET_USAGE; |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 313 | case 3: |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 314 | if (strncmp(argv[1],"dev",3) == 0) { |
| 315 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 316 | printf ("\nSCSI device %d: ", dev); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 317 | if (dev >= CONFIG_SYS_SCSI_MAX_DEVICE) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 318 | printf("unknown device\n"); |
| 319 | return 1; |
| 320 | } |
| 321 | printf ("\n Device %d: ", dev); |
| 322 | dev_print(&scsi_dev_desc[dev]); |
| 323 | if(scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) { |
| 324 | return 1; |
| 325 | } |
| 326 | scsi_curr_dev = dev; |
| 327 | printf("... is now current device\n"); |
| 328 | return 0; |
| 329 | } |
| 330 | if (strncmp(argv[1],"part",4) == 0) { |
| 331 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 332 | if(scsi_dev_desc[dev].type != DEV_TYPE_UNKNOWN) { |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 333 | part_print(&scsi_dev_desc[dev]); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 334 | } |
| 335 | else { |
| 336 | printf ("\nSCSI device %d not available\n", dev); |
| 337 | } |
| 338 | return 1; |
| 339 | } |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 340 | return CMD_RET_USAGE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 341 | default: |
| 342 | /* at least 4 args */ |
| 343 | if (strcmp(argv[1],"read") == 0) { |
| 344 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 345 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 346 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 347 | ulong n; |
| 348 | printf ("\nSCSI read: device %d block # %ld, count %ld ... ", |
| 349 | scsi_curr_dev, blk, cnt); |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 350 | n = scsi_read(&scsi_dev_desc[scsi_curr_dev], |
| 351 | blk, cnt, (ulong *)addr); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 352 | printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR"); |
| 353 | return 0; |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 354 | } else if (strcmp(argv[1], "write") == 0) { |
| 355 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 356 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 357 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 358 | ulong n; |
| 359 | printf("\nSCSI write: device %d block # %ld, " |
| 360 | "count %ld ... ", |
| 361 | scsi_curr_dev, blk, cnt); |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 362 | n = scsi_write(&scsi_dev_desc[scsi_curr_dev], |
| 363 | blk, cnt, (ulong *)addr); |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 364 | printf("%ld blocks written: %s\n", n, |
| 365 | (n == cnt) ? "OK" : "ERROR"); |
| 366 | return 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 367 | } |
| 368 | } /* switch */ |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 369 | return CMD_RET_USAGE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Tom Rini | ba52426 | 2016-03-16 09:45:03 -0400 | [diff] [blame] | 372 | U_BOOT_CMD( |
| 373 | scsi, 5, 1, do_scsi, |
| 374 | "SCSI sub-system", |
| 375 | "reset - reset SCSI controller\n" |
| 376 | "scsi info - show available SCSI devices\n" |
| 377 | "scsi scan - (re-)scan SCSI bus\n" |
| 378 | "scsi device [dev] - show or set current device\n" |
| 379 | "scsi part [dev] - print partition table of one or all SCSI devices\n" |
| 380 | "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" |
| 381 | " to memory address `addr'\n" |
| 382 | "scsi write addr blk# cnt - write `cnt' blocks starting at block\n" |
| 383 | " `blk#' from memory address `addr'" |
| 384 | ); |
| 385 | |
| 386 | U_BOOT_CMD( |
| 387 | scsiboot, 3, 1, do_scsiboot, |
| 388 | "boot from SCSI device", |
| 389 | "loadAddr dev:part" |
| 390 | ); |
| 391 | #endif |
| 392 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 393 | /**************************************************************************************** |
| 394 | * scsi_read |
| 395 | */ |
| 396 | |
Mark Langsdorf | 2b42c93 | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 397 | /* almost the maximum amount of the scsi_ext command.. */ |
| 398 | #define SCSI_MAX_READ_BLK 0xFFFF |
| 399 | #define SCSI_LBA48_READ 0xFFFFFFF |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 400 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 401 | static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr, |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 402 | lbaint_t blkcnt, void *buffer) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 403 | { |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 404 | int device = block_dev->devnum; |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 405 | lbaint_t start, blks; |
| 406 | uintptr_t buf_addr; |
Andre Przywara | c7d0fd7 | 2015-07-02 01:04:23 +0100 | [diff] [blame] | 407 | unsigned short smallblks = 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 408 | ccb* pccb=(ccb *)&tempccb; |
| 409 | device&=0xff; |
| 410 | /* Setup device |
| 411 | */ |
| 412 | pccb->target=scsi_dev_desc[device].target; |
| 413 | pccb->lun=scsi_dev_desc[device].lun; |
| 414 | buf_addr=(unsigned long)buffer; |
| 415 | start=blknr; |
| 416 | blks=blkcnt; |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 417 | debug("\nscsi_read: dev %d startblk " LBAF |
| 418 | ", blccnt " LBAF " buffer %lx\n", |
| 419 | device, start, blks, (unsigned long)buffer); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 420 | do { |
| 421 | pccb->pdata=(unsigned char *)buf_addr; |
Mark Langsdorf | 2b42c93 | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 422 | #ifdef CONFIG_SYS_64BIT_LBA |
| 423 | if (start > SCSI_LBA48_READ) { |
| 424 | unsigned long blocks; |
| 425 | blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK); |
| 426 | pccb->datalen = scsi_dev_desc[device].blksz * blocks; |
| 427 | scsi_setup_read16(pccb, start, blocks); |
| 428 | start += blocks; |
| 429 | blks -= blocks; |
Andre Przywara | c7d0fd7 | 2015-07-02 01:04:23 +0100 | [diff] [blame] | 430 | } else |
Mark Langsdorf | 2b42c93 | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 431 | #endif |
| 432 | if (blks > SCSI_MAX_READ_BLK) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 433 | pccb->datalen=scsi_dev_desc[device].blksz * SCSI_MAX_READ_BLK; |
| 434 | smallblks=SCSI_MAX_READ_BLK; |
| 435 | scsi_setup_read_ext(pccb,start,smallblks); |
| 436 | start+=SCSI_MAX_READ_BLK; |
| 437 | blks-=SCSI_MAX_READ_BLK; |
| 438 | } |
| 439 | else { |
| 440 | pccb->datalen=scsi_dev_desc[device].blksz * blks; |
| 441 | smallblks=(unsigned short) blks; |
| 442 | scsi_setup_read_ext(pccb,start,smallblks); |
| 443 | start+=blks; |
| 444 | blks=0; |
| 445 | } |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 446 | debug("scsi_read_ext: startblk " LBAF |
Simon Glass | f360947 | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 447 | ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 448 | start, smallblks, buf_addr); |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 449 | if (scsi_exec(pccb) != true) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 450 | scsi_print_error(pccb); |
| 451 | blkcnt-=blks; |
| 452 | break; |
| 453 | } |
| 454 | buf_addr+=pccb->datalen; |
| 455 | } while(blks!=0); |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 456 | debug("scsi_read_ext: end startblk " LBAF |
Simon Glass | f360947 | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 457 | ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 458 | return(blkcnt); |
| 459 | } |
| 460 | |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 461 | /******************************************************************************* |
| 462 | * scsi_write |
| 463 | */ |
| 464 | |
| 465 | /* Almost the maximum amount of the scsi_ext command.. */ |
| 466 | #define SCSI_MAX_WRITE_BLK 0xFFFF |
| 467 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 468 | static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr, |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 469 | lbaint_t blkcnt, const void *buffer) |
| 470 | { |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 471 | int device = block_dev->devnum; |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 472 | lbaint_t start, blks; |
| 473 | uintptr_t buf_addr; |
| 474 | unsigned short smallblks; |
| 475 | ccb* pccb = (ccb *)&tempccb; |
| 476 | device &= 0xff; |
| 477 | /* Setup device |
| 478 | */ |
| 479 | pccb->target = scsi_dev_desc[device].target; |
| 480 | pccb->lun = scsi_dev_desc[device].lun; |
| 481 | buf_addr = (unsigned long)buffer; |
| 482 | start = blknr; |
| 483 | blks = blkcnt; |
| 484 | debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", |
| 485 | __func__, device, start, blks, (unsigned long)buffer); |
| 486 | do { |
| 487 | pccb->pdata = (unsigned char *)buf_addr; |
| 488 | if (blks > SCSI_MAX_WRITE_BLK) { |
| 489 | pccb->datalen = (scsi_dev_desc[device].blksz * |
| 490 | SCSI_MAX_WRITE_BLK); |
| 491 | smallblks = SCSI_MAX_WRITE_BLK; |
| 492 | scsi_setup_write_ext(pccb, start, smallblks); |
| 493 | start += SCSI_MAX_WRITE_BLK; |
| 494 | blks -= SCSI_MAX_WRITE_BLK; |
| 495 | } else { |
| 496 | pccb->datalen = scsi_dev_desc[device].blksz * blks; |
| 497 | smallblks = (unsigned short)blks; |
| 498 | scsi_setup_write_ext(pccb, start, smallblks); |
| 499 | start += blks; |
| 500 | blks = 0; |
| 501 | } |
Simon Glass | f360947 | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 502 | debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 503 | __func__, start, smallblks, buf_addr); |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 504 | if (scsi_exec(pccb) != true) { |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 505 | scsi_print_error(pccb); |
| 506 | blkcnt -= blks; |
| 507 | break; |
| 508 | } |
| 509 | buf_addr += pccb->datalen; |
| 510 | } while (blks != 0); |
Simon Glass | f360947 | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 511 | debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 512 | __func__, start, smallblks, buf_addr); |
| 513 | return blkcnt; |
| 514 | } |
| 515 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 516 | /* copy src to dest, skipping leading and trailing blanks |
| 517 | * and null terminate the string |
| 518 | */ |
| 519 | void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len) |
| 520 | { |
| 521 | int start,end; |
| 522 | |
| 523 | start=0; |
| 524 | while(start<len) { |
| 525 | if(src[start]!=' ') |
| 526 | break; |
| 527 | start++; |
| 528 | } |
| 529 | end=len-1; |
| 530 | while(end>start) { |
| 531 | if(src[end]!=' ') |
| 532 | break; |
| 533 | end--; |
| 534 | } |
| 535 | for( ; start<=end; start++) { |
| 536 | *dest++=src[start]; |
| 537 | } |
| 538 | *dest='\0'; |
| 539 | } |
| 540 | |
| 541 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 542 | /* Trim trailing blanks, and NUL-terminate string |
| 543 | */ |
| 544 | void scsi_trim_trail (unsigned char *str, unsigned int len) |
| 545 | { |
| 546 | unsigned char *p = str + len - 1; |
| 547 | |
| 548 | while (len-- > 0) { |
| 549 | *p-- = '\0'; |
| 550 | if (*p != ' ') { |
| 551 | return; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 556 | int scsi_read_capacity(ccb *pccb, lbaint_t *capacity, unsigned long *blksz) |
| 557 | { |
| 558 | *capacity = 0; |
| 559 | |
| 560 | memset(pccb->cmd, 0, sizeof(pccb->cmd)); |
| 561 | pccb->cmd[0] = SCSI_RD_CAPAC10; |
| 562 | pccb->cmd[1] = pccb->lun << 5; |
| 563 | pccb->cmdlen = 10; |
| 564 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 565 | |
| 566 | pccb->datalen = 8; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 567 | if (scsi_exec(pccb) != true) |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 568 | return 1; |
| 569 | |
| 570 | *capacity = ((lbaint_t)pccb->pdata[0] << 24) | |
| 571 | ((lbaint_t)pccb->pdata[1] << 16) | |
| 572 | ((lbaint_t)pccb->pdata[2] << 8) | |
| 573 | ((lbaint_t)pccb->pdata[3]); |
| 574 | |
| 575 | if (*capacity != 0xffffffff) { |
| 576 | /* Read capacity (10) was sufficient for this drive. */ |
| 577 | *blksz = ((unsigned long)pccb->pdata[4] << 24) | |
| 578 | ((unsigned long)pccb->pdata[5] << 16) | |
| 579 | ((unsigned long)pccb->pdata[6] << 8) | |
| 580 | ((unsigned long)pccb->pdata[7]); |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | /* Read capacity (10) was insufficient. Use read capacity (16). */ |
| 585 | |
| 586 | memset(pccb->cmd, 0, sizeof(pccb->cmd)); |
| 587 | pccb->cmd[0] = SCSI_RD_CAPAC16; |
| 588 | pccb->cmd[1] = 0x10; |
| 589 | pccb->cmdlen = 16; |
| 590 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 591 | |
| 592 | pccb->datalen = 16; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 593 | if (scsi_exec(pccb) != true) |
Gabe Black | b4c5bbc | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 594 | return 1; |
| 595 | |
| 596 | *capacity = ((uint64_t)pccb->pdata[0] << 56) | |
| 597 | ((uint64_t)pccb->pdata[1] << 48) | |
| 598 | ((uint64_t)pccb->pdata[2] << 40) | |
| 599 | ((uint64_t)pccb->pdata[3] << 32) | |
| 600 | ((uint64_t)pccb->pdata[4] << 24) | |
| 601 | ((uint64_t)pccb->pdata[5] << 16) | |
| 602 | ((uint64_t)pccb->pdata[6] << 8) | |
| 603 | ((uint64_t)pccb->pdata[7]); |
| 604 | |
| 605 | *blksz = ((uint64_t)pccb->pdata[8] << 56) | |
| 606 | ((uint64_t)pccb->pdata[9] << 48) | |
| 607 | ((uint64_t)pccb->pdata[10] << 40) | |
| 608 | ((uint64_t)pccb->pdata[11] << 32) | |
| 609 | ((uint64_t)pccb->pdata[12] << 24) | |
| 610 | ((uint64_t)pccb->pdata[13] << 16) | |
| 611 | ((uint64_t)pccb->pdata[14] << 8) | |
| 612 | ((uint64_t)pccb->pdata[15]); |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 617 | |
| 618 | /************************************************************************************ |
| 619 | * Some setup (fill-in) routines |
| 620 | */ |
| 621 | void scsi_setup_test_unit_ready(ccb * pccb) |
| 622 | { |
| 623 | pccb->cmd[0]=SCSI_TST_U_RDY; |
| 624 | pccb->cmd[1]=pccb->lun<<5; |
| 625 | pccb->cmd[2]=0; |
| 626 | pccb->cmd[3]=0; |
| 627 | pccb->cmd[4]=0; |
| 628 | pccb->cmd[5]=0; |
| 629 | pccb->cmdlen=6; |
| 630 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
| 631 | } |
| 632 | |
Mark Langsdorf | 2b42c93 | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 633 | #ifdef CONFIG_SYS_64BIT_LBA |
| 634 | void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks) |
| 635 | { |
| 636 | pccb->cmd[0] = SCSI_READ16; |
| 637 | pccb->cmd[1] = pccb->lun<<5; |
| 638 | pccb->cmd[2] = ((unsigned char) (start >> 56)) & 0xff; |
| 639 | pccb->cmd[3] = ((unsigned char) (start >> 48)) & 0xff; |
| 640 | pccb->cmd[4] = ((unsigned char) (start >> 40)) & 0xff; |
| 641 | pccb->cmd[5] = ((unsigned char) (start >> 32)) & 0xff; |
| 642 | pccb->cmd[6] = ((unsigned char) (start >> 24)) & 0xff; |
| 643 | pccb->cmd[7] = ((unsigned char) (start >> 16)) & 0xff; |
| 644 | pccb->cmd[8] = ((unsigned char) (start >> 8)) & 0xff; |
| 645 | pccb->cmd[9] = ((unsigned char) (start)) & 0xff; |
| 646 | pccb->cmd[10] = 0; |
| 647 | pccb->cmd[11] = ((unsigned char) (blocks >> 24)) & 0xff; |
| 648 | pccb->cmd[12] = ((unsigned char) (blocks >> 16)) & 0xff; |
| 649 | pccb->cmd[13] = ((unsigned char) (blocks >> 8)) & 0xff; |
| 650 | pccb->cmd[14] = (unsigned char) blocks & 0xff; |
| 651 | pccb->cmd[15] = 0; |
| 652 | pccb->cmdlen = 16; |
| 653 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 654 | debug ("scsi_setup_read16: cmd: %02X %02X " |
| 655 | "startblk %02X%02X%02X%02X%02X%02X%02X%02X " |
| 656 | "blccnt %02X%02X%02X%02X\n", |
| 657 | pccb->cmd[0], pccb->cmd[1], |
| 658 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 659 | pccb->cmd[6], pccb->cmd[7], pccb->cmd[8], pccb->cmd[9], |
| 660 | pccb->cmd[11], pccb->cmd[12], pccb->cmd[13], pccb->cmd[14]); |
| 661 | } |
| 662 | #endif |
| 663 | |
Mark Langsdorf | 35df893 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 664 | void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 665 | { |
| 666 | pccb->cmd[0]=SCSI_READ10; |
| 667 | pccb->cmd[1]=pccb->lun<<5; |
| 668 | pccb->cmd[2]=((unsigned char) (start>>24))&0xff; |
| 669 | pccb->cmd[3]=((unsigned char) (start>>16))&0xff; |
| 670 | pccb->cmd[4]=((unsigned char) (start>>8))&0xff; |
| 671 | pccb->cmd[5]=((unsigned char) (start))&0xff; |
| 672 | pccb->cmd[6]=0; |
| 673 | pccb->cmd[7]=((unsigned char) (blocks>>8))&0xff; |
| 674 | pccb->cmd[8]=(unsigned char) blocks & 0xff; |
| 675 | pccb->cmd[6]=0; |
| 676 | pccb->cmdlen=10; |
| 677 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 678 | debug ("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n", |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 679 | pccb->cmd[0],pccb->cmd[1], |
| 680 | pccb->cmd[2],pccb->cmd[3],pccb->cmd[4],pccb->cmd[5], |
| 681 | pccb->cmd[7],pccb->cmd[8]); |
| 682 | } |
| 683 | |
Mark Langsdorf | 35df893 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 684 | void scsi_setup_write_ext(ccb *pccb, lbaint_t start, unsigned short blocks) |
Hung-Te Lin | 758c9e6 | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 685 | { |
| 686 | pccb->cmd[0] = SCSI_WRITE10; |
| 687 | pccb->cmd[1] = pccb->lun << 5; |
| 688 | pccb->cmd[2] = ((unsigned char) (start>>24)) & 0xff; |
| 689 | pccb->cmd[3] = ((unsigned char) (start>>16)) & 0xff; |
| 690 | pccb->cmd[4] = ((unsigned char) (start>>8)) & 0xff; |
| 691 | pccb->cmd[5] = ((unsigned char) (start)) & 0xff; |
| 692 | pccb->cmd[6] = 0; |
| 693 | pccb->cmd[7] = ((unsigned char) (blocks>>8)) & 0xff; |
| 694 | pccb->cmd[8] = (unsigned char)blocks & 0xff; |
| 695 | pccb->cmd[9] = 0; |
| 696 | pccb->cmdlen = 10; |
| 697 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 698 | debug("%s: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n", |
| 699 | __func__, |
| 700 | pccb->cmd[0], pccb->cmd[1], |
| 701 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 702 | pccb->cmd[7], pccb->cmd[8]); |
| 703 | } |
| 704 | |
Mark Langsdorf | 35df893 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 705 | void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 706 | { |
| 707 | pccb->cmd[0]=SCSI_READ6; |
| 708 | pccb->cmd[1]=pccb->lun<<5 | (((unsigned char)(start>>16))&0x1f); |
| 709 | pccb->cmd[2]=((unsigned char) (start>>8))&0xff; |
| 710 | pccb->cmd[3]=((unsigned char) (start))&0xff; |
| 711 | pccb->cmd[4]=(unsigned char) blocks & 0xff; |
| 712 | pccb->cmd[5]=0; |
| 713 | pccb->cmdlen=6; |
| 714 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 715 | debug ("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n", |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 716 | pccb->cmd[0],pccb->cmd[1], |
| 717 | pccb->cmd[2],pccb->cmd[3],pccb->cmd[4]); |
| 718 | } |
| 719 | |
| 720 | |
| 721 | void scsi_setup_inquiry(ccb * pccb) |
| 722 | { |
| 723 | pccb->cmd[0]=SCSI_INQUIRY; |
| 724 | pccb->cmd[1]=pccb->lun<<5; |
| 725 | pccb->cmd[2]=0; |
| 726 | pccb->cmd[3]=0; |
| 727 | if(pccb->datalen>255) |
| 728 | pccb->cmd[4]=255; |
| 729 | else |
| 730 | pccb->cmd[4]=(unsigned char)pccb->datalen; |
| 731 | pccb->cmd[5]=0; |
| 732 | pccb->cmdlen=6; |
| 733 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
| 734 | } |