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 | d79de1d | 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 | c82961d | 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 | 3e9fa30 | 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 | ae180dc | 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 | c2829ff | 2011-07-06 16:13:36 +0000 | [diff] [blame] | 34 | #elif !defined(CONFIG_SCSI_AHCI_PLAT) |
Jin Zhengxiong | ae180dc | 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 | 3e9fa30 | 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 | e36994b | 2015-03-20 10:27:54 +0800 | [diff] [blame] | 40 | #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) |
Vadim Bendebury | 3e9fa30 | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | static block_dev_desc_t 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 | 911b959 | 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 | 5ed06fc | 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 | 911b959 | 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 | bcc3539 | 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 | 0d996a8 | 2013-07-03 07:11:41 -0700 | [diff] [blame] | 69 | static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt, |
| 70 | void *buffer); |
| 71 | static ulong scsi_write(int device, lbaint_t blknr, |
Hung-Te Lin | 98a6c4e | 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 | bcc3539 | 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 | 0383694 | 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 | 2eec2ab | 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 | 4a59809 | 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; |
| 102 | scsi_dev_desc[i].dev=i; |
| 103 | scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN; |
| 104 | scsi_dev_desc[i].block_read=scsi_read; |
Hung-Te Lin | 98a6c4e | 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 | 0383694 | 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 | 0383694 | 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 | 4a59809 | 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 | f1276d4 | 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 | 4a59809 | 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 | 4404c16 | 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 | 4a59809 | 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 | bcc3539 | 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 | 2eec2ab | 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; |
| 159 | init_part(&scsi_dev_desc[scsi_max_devs]); |
| 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 | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 171 | scsi_curr_dev = -1; |
Stefan Reinauer | e50a10e | 2012-10-29 05:23:48 +0000 | [diff] [blame] | 172 | |
| 173 | printf("Found %d device(s).\n", scsi_max_devs); |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 174 | #ifndef CONFIG_SPL_BUILD |
Stefan Reinauer | e50a10e | 2012-10-29 05:23:48 +0000 | [diff] [blame] | 175 | setenv_ulong("scsidevs", scsi_max_devs); |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 176 | #endif |
Stefan Reinauer | e50a10e | 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 | e36994b | 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 | 7c3f62a | 2015-11-29 13:17:51 -0700 | [diff] [blame] | 187 | int busdevfunc = -1; |
Vadim Bendebury | 3e9fa30 | 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 | 7c3f62a | 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 | 3e9fa30 | 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 | 7c3f62a | 2015-11-29 13:17:51 -0700 | [diff] [blame] | 209 | #endif |
Vadim Bendebury | 3e9fa30 | 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 | 3e9fa30 | 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 | 3e9fa30 | 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 | 230cfef | 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 | 230cfef | 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 | c2829ff | 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 | 6252b4f | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 241 | #ifdef CONFIG_PARTITIONS |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 242 | block_dev_desc_t * scsi_get_dev(int dev) |
| 243 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 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 | 6252b4f | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 246 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 247 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 248 | /****************************************************************************** |
| 249 | * scsi boot command intepreter. Derived from diskboot |
| 250 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 251 | 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] | 252 | { |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 253 | return common_diskboot(cmdtp, "scsi", argc, argv); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /********************************************************************************* |
| 257 | * scsi command intepreter |
| 258 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 259 | 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] | 260 | { |
| 261 | switch (argc) { |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 262 | case 0: |
| 263 | case 1: |
| 264 | return CMD_RET_USAGE; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 265 | |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 266 | case 2: |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 267 | if (strncmp(argv[1],"res",3) == 0) { |
| 268 | printf("\nReset SCSI\n"); |
| 269 | scsi_bus_reset(); |
| 270 | scsi_scan(1); |
| 271 | return 0; |
| 272 | } |
| 273 | if (strncmp(argv[1],"inf",3) == 0) { |
| 274 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 275 | for (i=0; i<CONFIG_SYS_SCSI_MAX_DEVICE; ++i) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 276 | if(scsi_dev_desc[i].type==DEV_TYPE_UNKNOWN) |
| 277 | continue; /* list only known devices */ |
| 278 | printf ("SCSI dev. %d: ", i); |
| 279 | dev_print(&scsi_dev_desc[i]); |
| 280 | } |
| 281 | return 0; |
| 282 | } |
| 283 | if (strncmp(argv[1],"dev",3) == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 284 | if ((scsi_curr_dev < 0) || (scsi_curr_dev >= CONFIG_SYS_SCSI_MAX_DEVICE)) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 285 | printf("\nno SCSI devices available\n"); |
| 286 | return 1; |
| 287 | } |
| 288 | printf ("\n Device %d: ", scsi_curr_dev); |
| 289 | dev_print(&scsi_dev_desc[scsi_curr_dev]); |
| 290 | return 0; |
| 291 | } |
| 292 | if (strncmp(argv[1],"scan",4) == 0) { |
| 293 | scsi_scan(1); |
| 294 | return 0; |
| 295 | } |
| 296 | if (strncmp(argv[1],"part",4) == 0) { |
| 297 | int dev, ok; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 298 | for (ok=0, dev=0; dev<CONFIG_SYS_SCSI_MAX_DEVICE; ++dev) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 299 | if (scsi_dev_desc[dev].type!=DEV_TYPE_UNKNOWN) { |
| 300 | ok++; |
| 301 | if (dev) |
| 302 | printf("\n"); |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 303 | debug ("print_part of %x\n",dev); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 304 | print_part(&scsi_dev_desc[dev]); |
| 305 | } |
| 306 | } |
| 307 | if (!ok) |
| 308 | printf("\nno SCSI devices available\n"); |
| 309 | return 1; |
| 310 | } |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 311 | return CMD_RET_USAGE; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 312 | case 3: |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 313 | if (strncmp(argv[1],"dev",3) == 0) { |
| 314 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 315 | printf ("\nSCSI device %d: ", dev); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 316 | if (dev >= CONFIG_SYS_SCSI_MAX_DEVICE) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 317 | printf("unknown device\n"); |
| 318 | return 1; |
| 319 | } |
| 320 | printf ("\n Device %d: ", dev); |
| 321 | dev_print(&scsi_dev_desc[dev]); |
| 322 | if(scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) { |
| 323 | return 1; |
| 324 | } |
| 325 | scsi_curr_dev = dev; |
| 326 | printf("... is now current device\n"); |
| 327 | return 0; |
| 328 | } |
| 329 | if (strncmp(argv[1],"part",4) == 0) { |
| 330 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 331 | if(scsi_dev_desc[dev].type != DEV_TYPE_UNKNOWN) { |
| 332 | print_part(&scsi_dev_desc[dev]); |
| 333 | } |
| 334 | else { |
| 335 | printf ("\nSCSI device %d not available\n", dev); |
| 336 | } |
| 337 | return 1; |
| 338 | } |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 339 | return CMD_RET_USAGE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 340 | default: |
| 341 | /* at least 4 args */ |
| 342 | if (strcmp(argv[1],"read") == 0) { |
| 343 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 344 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 345 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 346 | ulong n; |
| 347 | printf ("\nSCSI read: device %d block # %ld, count %ld ... ", |
| 348 | scsi_curr_dev, blk, cnt); |
| 349 | n = scsi_read(scsi_curr_dev, blk, cnt, (ulong *)addr); |
| 350 | printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR"); |
| 351 | return 0; |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 352 | } else if (strcmp(argv[1], "write") == 0) { |
| 353 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 354 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 355 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 356 | ulong n; |
| 357 | printf("\nSCSI write: device %d block # %ld, " |
| 358 | "count %ld ... ", |
| 359 | scsi_curr_dev, blk, cnt); |
| 360 | n = scsi_write(scsi_curr_dev, blk, cnt, |
| 361 | (ulong *)addr); |
| 362 | printf("%ld blocks written: %s\n", n, |
| 363 | (n == cnt) ? "OK" : "ERROR"); |
| 364 | return 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 365 | } |
| 366 | } /* switch */ |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 367 | return CMD_RET_USAGE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /**************************************************************************************** |
| 371 | * scsi_read |
| 372 | */ |
| 373 | |
Mark Langsdorf | 5ed06fc | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 374 | /* almost the maximum amount of the scsi_ext command.. */ |
| 375 | #define SCSI_MAX_READ_BLK 0xFFFF |
| 376 | #define SCSI_LBA48_READ 0xFFFFFFF |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 377 | |
Simon Glass | 0d996a8 | 2013-07-03 07:11:41 -0700 | [diff] [blame] | 378 | static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt, |
| 379 | void *buffer) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 380 | { |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 381 | lbaint_t start, blks; |
| 382 | uintptr_t buf_addr; |
Andre Przywara | 644a8bd | 2015-07-02 01:04:23 +0100 | [diff] [blame] | 383 | unsigned short smallblks = 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 384 | ccb* pccb=(ccb *)&tempccb; |
| 385 | device&=0xff; |
| 386 | /* Setup device |
| 387 | */ |
| 388 | pccb->target=scsi_dev_desc[device].target; |
| 389 | pccb->lun=scsi_dev_desc[device].lun; |
| 390 | buf_addr=(unsigned long)buffer; |
| 391 | start=blknr; |
| 392 | blks=blkcnt; |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 393 | debug("\nscsi_read: dev %d startblk " LBAF |
| 394 | ", blccnt " LBAF " buffer %lx\n", |
| 395 | device, start, blks, (unsigned long)buffer); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 396 | do { |
| 397 | pccb->pdata=(unsigned char *)buf_addr; |
Mark Langsdorf | 5ed06fc | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 398 | #ifdef CONFIG_SYS_64BIT_LBA |
| 399 | if (start > SCSI_LBA48_READ) { |
| 400 | unsigned long blocks; |
| 401 | blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK); |
| 402 | pccb->datalen = scsi_dev_desc[device].blksz * blocks; |
| 403 | scsi_setup_read16(pccb, start, blocks); |
| 404 | start += blocks; |
| 405 | blks -= blocks; |
Andre Przywara | 644a8bd | 2015-07-02 01:04:23 +0100 | [diff] [blame] | 406 | } else |
Mark Langsdorf | 5ed06fc | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 407 | #endif |
| 408 | if (blks > SCSI_MAX_READ_BLK) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 409 | pccb->datalen=scsi_dev_desc[device].blksz * SCSI_MAX_READ_BLK; |
| 410 | smallblks=SCSI_MAX_READ_BLK; |
| 411 | scsi_setup_read_ext(pccb,start,smallblks); |
| 412 | start+=SCSI_MAX_READ_BLK; |
| 413 | blks-=SCSI_MAX_READ_BLK; |
| 414 | } |
| 415 | else { |
| 416 | pccb->datalen=scsi_dev_desc[device].blksz * blks; |
| 417 | smallblks=(unsigned short) blks; |
| 418 | scsi_setup_read_ext(pccb,start,smallblks); |
| 419 | start+=blks; |
| 420 | blks=0; |
| 421 | } |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 422 | debug("scsi_read_ext: startblk " LBAF |
Simon Glass | c82961d | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 423 | ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 424 | start, smallblks, buf_addr); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 425 | if (scsi_exec(pccb) != true) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 426 | scsi_print_error(pccb); |
| 427 | blkcnt-=blks; |
| 428 | break; |
| 429 | } |
| 430 | buf_addr+=pccb->datalen; |
| 431 | } while(blks!=0); |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 432 | debug("scsi_read_ext: end startblk " LBAF |
Simon Glass | c82961d | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 433 | ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 434 | return(blkcnt); |
| 435 | } |
| 436 | |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 437 | /******************************************************************************* |
| 438 | * scsi_write |
| 439 | */ |
| 440 | |
| 441 | /* Almost the maximum amount of the scsi_ext command.. */ |
| 442 | #define SCSI_MAX_WRITE_BLK 0xFFFF |
| 443 | |
Simon Glass | 0d996a8 | 2013-07-03 07:11:41 -0700 | [diff] [blame] | 444 | static ulong scsi_write(int device, lbaint_t blknr, |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 445 | lbaint_t blkcnt, const void *buffer) |
| 446 | { |
| 447 | lbaint_t start, blks; |
| 448 | uintptr_t buf_addr; |
| 449 | unsigned short smallblks; |
| 450 | ccb* pccb = (ccb *)&tempccb; |
| 451 | device &= 0xff; |
| 452 | /* Setup device |
| 453 | */ |
| 454 | pccb->target = scsi_dev_desc[device].target; |
| 455 | pccb->lun = scsi_dev_desc[device].lun; |
| 456 | buf_addr = (unsigned long)buffer; |
| 457 | start = blknr; |
| 458 | blks = blkcnt; |
| 459 | debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", |
| 460 | __func__, device, start, blks, (unsigned long)buffer); |
| 461 | do { |
| 462 | pccb->pdata = (unsigned char *)buf_addr; |
| 463 | if (blks > SCSI_MAX_WRITE_BLK) { |
| 464 | pccb->datalen = (scsi_dev_desc[device].blksz * |
| 465 | SCSI_MAX_WRITE_BLK); |
| 466 | smallblks = SCSI_MAX_WRITE_BLK; |
| 467 | scsi_setup_write_ext(pccb, start, smallblks); |
| 468 | start += SCSI_MAX_WRITE_BLK; |
| 469 | blks -= SCSI_MAX_WRITE_BLK; |
| 470 | } else { |
| 471 | pccb->datalen = scsi_dev_desc[device].blksz * blks; |
| 472 | smallblks = (unsigned short)blks; |
| 473 | scsi_setup_write_ext(pccb, start, smallblks); |
| 474 | start += blks; |
| 475 | blks = 0; |
| 476 | } |
Simon Glass | c82961d | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 477 | debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 478 | __func__, start, smallblks, buf_addr); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 479 | if (scsi_exec(pccb) != true) { |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 480 | scsi_print_error(pccb); |
| 481 | blkcnt -= blks; |
| 482 | break; |
| 483 | } |
| 484 | buf_addr += pccb->datalen; |
| 485 | } while (blks != 0); |
Simon Glass | c82961d | 2014-10-15 04:38:37 -0600 | [diff] [blame] | 486 | debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 487 | __func__, start, smallblks, buf_addr); |
| 488 | return blkcnt; |
| 489 | } |
| 490 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 491 | /* copy src to dest, skipping leading and trailing blanks |
| 492 | * and null terminate the string |
| 493 | */ |
| 494 | void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len) |
| 495 | { |
| 496 | int start,end; |
| 497 | |
| 498 | start=0; |
| 499 | while(start<len) { |
| 500 | if(src[start]!=' ') |
| 501 | break; |
| 502 | start++; |
| 503 | } |
| 504 | end=len-1; |
| 505 | while(end>start) { |
| 506 | if(src[end]!=' ') |
| 507 | break; |
| 508 | end--; |
| 509 | } |
| 510 | for( ; start<=end; start++) { |
| 511 | *dest++=src[start]; |
| 512 | } |
| 513 | *dest='\0'; |
| 514 | } |
| 515 | |
| 516 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 517 | /* Trim trailing blanks, and NUL-terminate string |
| 518 | */ |
| 519 | void scsi_trim_trail (unsigned char *str, unsigned int len) |
| 520 | { |
| 521 | unsigned char *p = str + len - 1; |
| 522 | |
| 523 | while (len-- > 0) { |
| 524 | *p-- = '\0'; |
| 525 | if (*p != ' ') { |
| 526 | return; |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
Gabe Black | bcc3539 | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 531 | int scsi_read_capacity(ccb *pccb, lbaint_t *capacity, unsigned long *blksz) |
| 532 | { |
| 533 | *capacity = 0; |
| 534 | |
| 535 | memset(pccb->cmd, 0, sizeof(pccb->cmd)); |
| 536 | pccb->cmd[0] = SCSI_RD_CAPAC10; |
| 537 | pccb->cmd[1] = pccb->lun << 5; |
| 538 | pccb->cmdlen = 10; |
| 539 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 540 | |
| 541 | pccb->datalen = 8; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 542 | if (scsi_exec(pccb) != true) |
Gabe Black | bcc3539 | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 543 | return 1; |
| 544 | |
| 545 | *capacity = ((lbaint_t)pccb->pdata[0] << 24) | |
| 546 | ((lbaint_t)pccb->pdata[1] << 16) | |
| 547 | ((lbaint_t)pccb->pdata[2] << 8) | |
| 548 | ((lbaint_t)pccb->pdata[3]); |
| 549 | |
| 550 | if (*capacity != 0xffffffff) { |
| 551 | /* Read capacity (10) was sufficient for this drive. */ |
| 552 | *blksz = ((unsigned long)pccb->pdata[4] << 24) | |
| 553 | ((unsigned long)pccb->pdata[5] << 16) | |
| 554 | ((unsigned long)pccb->pdata[6] << 8) | |
| 555 | ((unsigned long)pccb->pdata[7]); |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | /* Read capacity (10) was insufficient. Use read capacity (16). */ |
| 560 | |
| 561 | memset(pccb->cmd, 0, sizeof(pccb->cmd)); |
| 562 | pccb->cmd[0] = SCSI_RD_CAPAC16; |
| 563 | pccb->cmd[1] = 0x10; |
| 564 | pccb->cmdlen = 16; |
| 565 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 566 | |
| 567 | pccb->datalen = 16; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 568 | if (scsi_exec(pccb) != true) |
Gabe Black | bcc3539 | 2012-10-29 05:23:57 +0000 | [diff] [blame] | 569 | return 1; |
| 570 | |
| 571 | *capacity = ((uint64_t)pccb->pdata[0] << 56) | |
| 572 | ((uint64_t)pccb->pdata[1] << 48) | |
| 573 | ((uint64_t)pccb->pdata[2] << 40) | |
| 574 | ((uint64_t)pccb->pdata[3] << 32) | |
| 575 | ((uint64_t)pccb->pdata[4] << 24) | |
| 576 | ((uint64_t)pccb->pdata[5] << 16) | |
| 577 | ((uint64_t)pccb->pdata[6] << 8) | |
| 578 | ((uint64_t)pccb->pdata[7]); |
| 579 | |
| 580 | *blksz = ((uint64_t)pccb->pdata[8] << 56) | |
| 581 | ((uint64_t)pccb->pdata[9] << 48) | |
| 582 | ((uint64_t)pccb->pdata[10] << 40) | |
| 583 | ((uint64_t)pccb->pdata[11] << 32) | |
| 584 | ((uint64_t)pccb->pdata[12] << 24) | |
| 585 | ((uint64_t)pccb->pdata[13] << 16) | |
| 586 | ((uint64_t)pccb->pdata[14] << 8) | |
| 587 | ((uint64_t)pccb->pdata[15]); |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 592 | |
| 593 | /************************************************************************************ |
| 594 | * Some setup (fill-in) routines |
| 595 | */ |
| 596 | void scsi_setup_test_unit_ready(ccb * pccb) |
| 597 | { |
| 598 | pccb->cmd[0]=SCSI_TST_U_RDY; |
| 599 | pccb->cmd[1]=pccb->lun<<5; |
| 600 | pccb->cmd[2]=0; |
| 601 | pccb->cmd[3]=0; |
| 602 | pccb->cmd[4]=0; |
| 603 | pccb->cmd[5]=0; |
| 604 | pccb->cmdlen=6; |
| 605 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 606 | } |
Mark Langsdorf | 5ed06fc | 2015-06-05 00:58:45 +0100 | [diff] [blame] | 607 | |
| 608 | #ifdef CONFIG_SYS_64BIT_LBA |
| 609 | void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks) |
| 610 | { |
| 611 | pccb->cmd[0] = SCSI_READ16; |
| 612 | pccb->cmd[1] = pccb->lun<<5; |
| 613 | pccb->cmd[2] = ((unsigned char) (start >> 56)) & 0xff; |
| 614 | pccb->cmd[3] = ((unsigned char) (start >> 48)) & 0xff; |
| 615 | pccb->cmd[4] = ((unsigned char) (start >> 40)) & 0xff; |
| 616 | pccb->cmd[5] = ((unsigned char) (start >> 32)) & 0xff; |
| 617 | pccb->cmd[6] = ((unsigned char) (start >> 24)) & 0xff; |
| 618 | pccb->cmd[7] = ((unsigned char) (start >> 16)) & 0xff; |
| 619 | pccb->cmd[8] = ((unsigned char) (start >> 8)) & 0xff; |
| 620 | pccb->cmd[9] = ((unsigned char) (start)) & 0xff; |
| 621 | pccb->cmd[10] = 0; |
| 622 | pccb->cmd[11] = ((unsigned char) (blocks >> 24)) & 0xff; |
| 623 | pccb->cmd[12] = ((unsigned char) (blocks >> 16)) & 0xff; |
| 624 | pccb->cmd[13] = ((unsigned char) (blocks >> 8)) & 0xff; |
| 625 | pccb->cmd[14] = (unsigned char) blocks & 0xff; |
| 626 | pccb->cmd[15] = 0; |
| 627 | pccb->cmdlen = 16; |
| 628 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 629 | debug ("scsi_setup_read16: cmd: %02X %02X " |
| 630 | "startblk %02X%02X%02X%02X%02X%02X%02X%02X " |
| 631 | "blccnt %02X%02X%02X%02X\n", |
| 632 | pccb->cmd[0], pccb->cmd[1], |
| 633 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 634 | pccb->cmd[6], pccb->cmd[7], pccb->cmd[8], pccb->cmd[9], |
| 635 | pccb->cmd[11], pccb->cmd[12], pccb->cmd[13], pccb->cmd[14]); |
| 636 | } |
| 637 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 638 | |
Mark Langsdorf | 911b959 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 639 | void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 640 | { |
| 641 | pccb->cmd[0]=SCSI_READ10; |
| 642 | pccb->cmd[1]=pccb->lun<<5; |
| 643 | pccb->cmd[2]=((unsigned char) (start>>24))&0xff; |
| 644 | pccb->cmd[3]=((unsigned char) (start>>16))&0xff; |
| 645 | pccb->cmd[4]=((unsigned char) (start>>8))&0xff; |
| 646 | pccb->cmd[5]=((unsigned char) (start))&0xff; |
| 647 | pccb->cmd[6]=0; |
| 648 | pccb->cmd[7]=((unsigned char) (blocks>>8))&0xff; |
| 649 | pccb->cmd[8]=(unsigned char) blocks & 0xff; |
| 650 | pccb->cmd[6]=0; |
| 651 | pccb->cmdlen=10; |
| 652 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 653 | 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] | 654 | pccb->cmd[0],pccb->cmd[1], |
| 655 | pccb->cmd[2],pccb->cmd[3],pccb->cmd[4],pccb->cmd[5], |
| 656 | pccb->cmd[7],pccb->cmd[8]); |
| 657 | } |
| 658 | |
Mark Langsdorf | 911b959 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 659 | void scsi_setup_write_ext(ccb *pccb, lbaint_t start, unsigned short blocks) |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 660 | { |
| 661 | pccb->cmd[0] = SCSI_WRITE10; |
| 662 | pccb->cmd[1] = pccb->lun << 5; |
| 663 | pccb->cmd[2] = ((unsigned char) (start>>24)) & 0xff; |
| 664 | pccb->cmd[3] = ((unsigned char) (start>>16)) & 0xff; |
| 665 | pccb->cmd[4] = ((unsigned char) (start>>8)) & 0xff; |
| 666 | pccb->cmd[5] = ((unsigned char) (start)) & 0xff; |
| 667 | pccb->cmd[6] = 0; |
| 668 | pccb->cmd[7] = ((unsigned char) (blocks>>8)) & 0xff; |
| 669 | pccb->cmd[8] = (unsigned char)blocks & 0xff; |
| 670 | pccb->cmd[9] = 0; |
| 671 | pccb->cmdlen = 10; |
| 672 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 673 | debug("%s: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n", |
| 674 | __func__, |
| 675 | pccb->cmd[0], pccb->cmd[1], |
| 676 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 677 | pccb->cmd[7], pccb->cmd[8]); |
| 678 | } |
| 679 | |
Mark Langsdorf | 911b959 | 2015-06-05 00:58:44 +0100 | [diff] [blame] | 680 | void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 681 | { |
| 682 | pccb->cmd[0]=SCSI_READ6; |
| 683 | pccb->cmd[1]=pccb->lun<<5 | (((unsigned char)(start>>16))&0x1f); |
| 684 | pccb->cmd[2]=((unsigned char) (start>>8))&0xff; |
| 685 | pccb->cmd[3]=((unsigned char) (start))&0xff; |
| 686 | pccb->cmd[4]=(unsigned char) blocks & 0xff; |
| 687 | pccb->cmd[5]=0; |
| 688 | pccb->cmdlen=6; |
| 689 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 690 | debug ("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n", |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 691 | pccb->cmd[0],pccb->cmd[1], |
| 692 | pccb->cmd[2],pccb->cmd[3],pccb->cmd[4]); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | void scsi_setup_inquiry(ccb * pccb) |
| 697 | { |
| 698 | pccb->cmd[0]=SCSI_INQUIRY; |
| 699 | pccb->cmd[1]=pccb->lun<<5; |
| 700 | pccb->cmd[2]=0; |
| 701 | pccb->cmd[3]=0; |
| 702 | if(pccb->datalen>255) |
| 703 | pccb->cmd[4]=255; |
| 704 | else |
| 705 | pccb->cmd[4]=(unsigned char)pccb->datalen; |
| 706 | pccb->cmd[5]=0; |
| 707 | pccb->cmdlen=6; |
| 708 | pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */ |
| 709 | } |
| 710 | |
Wolfgang Denk | 6a3d6b0 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 711 | |
| 712 | U_BOOT_CMD( |
| 713 | scsi, 5, 1, do_scsi, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 714 | "SCSI sub-system", |
Wolfgang Denk | 6a3d6b0 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 715 | "reset - reset SCSI controller\n" |
| 716 | "scsi info - show available SCSI devices\n" |
| 717 | "scsi scan - (re-)scan SCSI bus\n" |
| 718 | "scsi device [dev] - show or set current device\n" |
| 719 | "scsi part [dev] - print partition table of one or all SCSI devices\n" |
| 720 | "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 721 | " to memory address `addr'\n" |
| 722 | "scsi write addr blk# cnt - write `cnt' blocks starting at block\n" |
| 723 | " `blk#' from memory address `addr'" |
Wolfgang Denk | 6a3d6b0 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 724 | ); |
| 725 | |
| 726 | U_BOOT_CMD( |
| 727 | scsiboot, 3, 1, do_scsiboot, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 728 | "boot from SCSI device", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 729 | "loadAddr dev:part" |
Wolfgang Denk | 6a3d6b0 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 730 | ); |