Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Denis Peter, MPL AG Switzerland |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 9 | #include <inttypes.h> |
| 10 | #include <pci.h> |
| 11 | #include <scsi.h> |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 12 | #include <dm/device-internal.h> |
| 13 | #include <dm/uclass-internal.h> |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 14 | |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 15 | #if !defined(CONFIG_DM_SCSI) |
Simon Glass | 0ada891 | 2017-06-14 21:28:35 -0600 | [diff] [blame] | 16 | # ifdef CONFIG_SCSI_DEV_LIST |
| 17 | # define SCSI_DEV_LIST CONFIG_SCSI_DEV_LIST |
| 18 | # else |
| 19 | # ifdef CONFIG_SATA_ULI5288 |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 20 | |
Simon Glass | 0ada891 | 2017-06-14 21:28:35 -0600 | [diff] [blame] | 21 | # define SCSI_VEND_ID 0x10b9 |
| 22 | # define SCSI_DEV_ID 0x5288 |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 23 | |
Simon Glass | 0ada891 | 2017-06-14 21:28:35 -0600 | [diff] [blame] | 24 | # elif !defined(CONFIG_SCSI_AHCI_PLAT) |
| 25 | # error no scsi device defined |
| 26 | # endif |
| 27 | # define SCSI_DEV_LIST {SCSI_VEND_ID, SCSI_DEV_ID} |
| 28 | # endif |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 29 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 30 | |
Simon Glass | 57e7c2a | 2017-06-14 21:28:47 -0600 | [diff] [blame] | 31 | #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) && \ |
| 32 | !defined(CONFIG_DM_SCSI) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 33 | const struct pci_device_id scsi_device_list[] = { SCSI_DEV_LIST }; |
| 34 | #endif |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 35 | static struct scsi_cmd tempccb; /* temporary scsi command buffer */ |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 36 | |
| 37 | static unsigned char tempbuff[512]; /* temporary data buffer */ |
| 38 | |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 39 | #if !defined(CONFIG_DM_SCSI) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 40 | static int scsi_max_devs; /* number of highest available scsi device */ |
| 41 | |
| 42 | static int scsi_curr_dev; /* current device */ |
| 43 | |
| 44 | static struct blk_desc scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE]; |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 45 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 46 | |
| 47 | /* almost the maximum amount of the scsi_ext command.. */ |
| 48 | #define SCSI_MAX_READ_BLK 0xFFFF |
| 49 | #define SCSI_LBA48_READ 0xFFFFFFF |
| 50 | |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 51 | static void scsi_print_error(struct scsi_cmd *pccb) |
Simon Glass | 1674098 | 2017-06-14 21:28:23 -0600 | [diff] [blame] | 52 | { |
| 53 | /* Dummy function that could print an error for debugging */ |
| 54 | } |
| 55 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 56 | #ifdef CONFIG_SYS_64BIT_LBA |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 57 | void scsi_setup_read16(struct scsi_cmd *pccb, lbaint_t start, |
| 58 | unsigned long blocks) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 59 | { |
| 60 | pccb->cmd[0] = SCSI_READ16; |
| 61 | pccb->cmd[1] = pccb->lun << 5; |
| 62 | pccb->cmd[2] = (unsigned char)(start >> 56) & 0xff; |
| 63 | pccb->cmd[3] = (unsigned char)(start >> 48) & 0xff; |
| 64 | pccb->cmd[4] = (unsigned char)(start >> 40) & 0xff; |
| 65 | pccb->cmd[5] = (unsigned char)(start >> 32) & 0xff; |
| 66 | pccb->cmd[6] = (unsigned char)(start >> 24) & 0xff; |
| 67 | pccb->cmd[7] = (unsigned char)(start >> 16) & 0xff; |
| 68 | pccb->cmd[8] = (unsigned char)(start >> 8) & 0xff; |
| 69 | pccb->cmd[9] = (unsigned char)start & 0xff; |
| 70 | pccb->cmd[10] = 0; |
| 71 | pccb->cmd[11] = (unsigned char)(blocks >> 24) & 0xff; |
| 72 | pccb->cmd[12] = (unsigned char)(blocks >> 16) & 0xff; |
| 73 | pccb->cmd[13] = (unsigned char)(blocks >> 8) & 0xff; |
| 74 | pccb->cmd[14] = (unsigned char)blocks & 0xff; |
| 75 | pccb->cmd[15] = 0; |
| 76 | pccb->cmdlen = 16; |
| 77 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 78 | debug("scsi_setup_read16: cmd: %02X %02X startblk %02X%02X%02X%02X%02X%02X%02X%02X blccnt %02X%02X%02X%02X\n", |
| 79 | pccb->cmd[0], pccb->cmd[1], |
| 80 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 81 | pccb->cmd[6], pccb->cmd[7], pccb->cmd[8], pccb->cmd[9], |
| 82 | pccb->cmd[11], pccb->cmd[12], pccb->cmd[13], pccb->cmd[14]); |
| 83 | } |
| 84 | #endif |
| 85 | |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 86 | static void scsi_setup_read_ext(struct scsi_cmd *pccb, lbaint_t start, |
Michal Simek | 9ec32f3 | 2016-11-30 11:53:43 +0100 | [diff] [blame] | 87 | unsigned short blocks) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 88 | { |
| 89 | pccb->cmd[0] = SCSI_READ10; |
| 90 | pccb->cmd[1] = pccb->lun << 5; |
| 91 | pccb->cmd[2] = (unsigned char)(start >> 24) & 0xff; |
| 92 | pccb->cmd[3] = (unsigned char)(start >> 16) & 0xff; |
| 93 | pccb->cmd[4] = (unsigned char)(start >> 8) & 0xff; |
| 94 | pccb->cmd[5] = (unsigned char)start & 0xff; |
| 95 | pccb->cmd[6] = 0; |
| 96 | pccb->cmd[7] = (unsigned char)(blocks >> 8) & 0xff; |
| 97 | pccb->cmd[8] = (unsigned char)blocks & 0xff; |
| 98 | pccb->cmd[6] = 0; |
| 99 | pccb->cmdlen = 10; |
| 100 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 101 | debug("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n", |
| 102 | pccb->cmd[0], pccb->cmd[1], |
| 103 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 104 | pccb->cmd[7], pccb->cmd[8]); |
| 105 | } |
| 106 | |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 107 | static void scsi_setup_write_ext(struct scsi_cmd *pccb, lbaint_t start, |
Michal Simek | 9ec32f3 | 2016-11-30 11:53:43 +0100 | [diff] [blame] | 108 | unsigned short blocks) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 109 | { |
| 110 | pccb->cmd[0] = SCSI_WRITE10; |
| 111 | pccb->cmd[1] = pccb->lun << 5; |
| 112 | pccb->cmd[2] = (unsigned char)(start >> 24) & 0xff; |
| 113 | pccb->cmd[3] = (unsigned char)(start >> 16) & 0xff; |
| 114 | pccb->cmd[4] = (unsigned char)(start >> 8) & 0xff; |
| 115 | pccb->cmd[5] = (unsigned char)start & 0xff; |
| 116 | pccb->cmd[6] = 0; |
| 117 | pccb->cmd[7] = ((unsigned char)(blocks >> 8)) & 0xff; |
| 118 | pccb->cmd[8] = (unsigned char)blocks & 0xff; |
| 119 | pccb->cmd[9] = 0; |
| 120 | pccb->cmdlen = 10; |
| 121 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 122 | debug("%s: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n", |
| 123 | __func__, |
| 124 | pccb->cmd[0], pccb->cmd[1], |
| 125 | pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5], |
| 126 | pccb->cmd[7], pccb->cmd[8]); |
| 127 | } |
| 128 | |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 129 | static void scsi_setup_inquiry(struct scsi_cmd *pccb) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 130 | { |
| 131 | pccb->cmd[0] = SCSI_INQUIRY; |
| 132 | pccb->cmd[1] = pccb->lun << 5; |
| 133 | pccb->cmd[2] = 0; |
| 134 | pccb->cmd[3] = 0; |
| 135 | if (pccb->datalen > 255) |
| 136 | pccb->cmd[4] = 255; |
| 137 | else |
| 138 | pccb->cmd[4] = (unsigned char)pccb->datalen; |
| 139 | pccb->cmd[5] = 0; |
| 140 | pccb->cmdlen = 6; |
| 141 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 142 | } |
| 143 | |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 144 | #ifdef CONFIG_BLK |
| 145 | static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, |
| 146 | void *buffer) |
| 147 | #else |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 148 | static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr, |
| 149 | lbaint_t blkcnt, void *buffer) |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 150 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 151 | { |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 152 | #ifdef CONFIG_BLK |
| 153 | struct blk_desc *block_dev = dev_get_uclass_platdata(dev); |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 154 | struct udevice *bdev = dev->parent; |
| 155 | #else |
| 156 | struct udevice *bdev = NULL; |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 157 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 158 | lbaint_t start, blks; |
| 159 | uintptr_t buf_addr; |
| 160 | unsigned short smallblks = 0; |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 161 | struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 162 | |
| 163 | /* Setup device */ |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 164 | pccb->target = block_dev->target; |
| 165 | pccb->lun = block_dev->lun; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 166 | buf_addr = (unsigned long)buffer; |
| 167 | start = blknr; |
| 168 | blks = blkcnt; |
| 169 | debug("\nscsi_read: dev %d startblk " LBAF |
| 170 | ", blccnt " LBAF " buffer %lx\n", |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 171 | block_dev->devnum, start, blks, (unsigned long)buffer); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 172 | do { |
| 173 | pccb->pdata = (unsigned char *)buf_addr; |
| 174 | #ifdef CONFIG_SYS_64BIT_LBA |
| 175 | if (start > SCSI_LBA48_READ) { |
| 176 | unsigned long blocks; |
| 177 | blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK); |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 178 | pccb->datalen = block_dev->blksz * blocks; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 179 | scsi_setup_read16(pccb, start, blocks); |
| 180 | start += blocks; |
| 181 | blks -= blocks; |
| 182 | } else |
| 183 | #endif |
| 184 | if (blks > SCSI_MAX_READ_BLK) { |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 185 | pccb->datalen = block_dev->blksz * |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 186 | SCSI_MAX_READ_BLK; |
| 187 | smallblks = SCSI_MAX_READ_BLK; |
| 188 | scsi_setup_read_ext(pccb, start, smallblks); |
| 189 | start += SCSI_MAX_READ_BLK; |
| 190 | blks -= SCSI_MAX_READ_BLK; |
| 191 | } else { |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 192 | pccb->datalen = block_dev->blksz * blks; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 193 | smallblks = (unsigned short)blks; |
| 194 | scsi_setup_read_ext(pccb, start, smallblks); |
| 195 | start += blks; |
| 196 | blks = 0; |
| 197 | } |
| 198 | debug("scsi_read_ext: startblk " LBAF |
| 199 | ", blccnt %x buffer %" PRIXPTR "\n", |
| 200 | start, smallblks, buf_addr); |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 201 | if (scsi_exec(bdev, pccb)) { |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 202 | scsi_print_error(pccb); |
| 203 | blkcnt -= blks; |
| 204 | break; |
| 205 | } |
| 206 | buf_addr += pccb->datalen; |
| 207 | } while (blks != 0); |
| 208 | debug("scsi_read_ext: end startblk " LBAF |
| 209 | ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr); |
| 210 | return blkcnt; |
| 211 | } |
| 212 | |
| 213 | /******************************************************************************* |
| 214 | * scsi_write |
| 215 | */ |
| 216 | |
| 217 | /* Almost the maximum amount of the scsi_ext command.. */ |
| 218 | #define SCSI_MAX_WRITE_BLK 0xFFFF |
| 219 | |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 220 | #ifdef CONFIG_BLK |
| 221 | static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, |
| 222 | const void *buffer) |
| 223 | #else |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 224 | static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr, |
| 225 | lbaint_t blkcnt, const void *buffer) |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 226 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 227 | { |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 228 | #ifdef CONFIG_BLK |
| 229 | struct blk_desc *block_dev = dev_get_uclass_platdata(dev); |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 230 | struct udevice *bdev = dev->parent; |
| 231 | #else |
| 232 | struct udevice *bdev = NULL; |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 233 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 234 | lbaint_t start, blks; |
| 235 | uintptr_t buf_addr; |
| 236 | unsigned short smallblks; |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 237 | struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 238 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 239 | /* Setup device */ |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 240 | pccb->target = block_dev->target; |
| 241 | pccb->lun = block_dev->lun; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 242 | buf_addr = (unsigned long)buffer; |
| 243 | start = blknr; |
| 244 | blks = blkcnt; |
| 245 | debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 246 | __func__, block_dev->devnum, start, blks, (unsigned long)buffer); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 247 | do { |
| 248 | pccb->pdata = (unsigned char *)buf_addr; |
| 249 | if (blks > SCSI_MAX_WRITE_BLK) { |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 250 | pccb->datalen = (block_dev->blksz * |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 251 | SCSI_MAX_WRITE_BLK); |
| 252 | smallblks = SCSI_MAX_WRITE_BLK; |
| 253 | scsi_setup_write_ext(pccb, start, smallblks); |
| 254 | start += SCSI_MAX_WRITE_BLK; |
| 255 | blks -= SCSI_MAX_WRITE_BLK; |
| 256 | } else { |
Michal Simek | de6840a | 2016-11-18 16:22:42 +0100 | [diff] [blame] | 257 | pccb->datalen = block_dev->blksz * blks; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 258 | smallblks = (unsigned short)blks; |
| 259 | scsi_setup_write_ext(pccb, start, smallblks); |
| 260 | start += blks; |
| 261 | blks = 0; |
| 262 | } |
| 263 | debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
| 264 | __func__, start, smallblks, buf_addr); |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 265 | if (scsi_exec(bdev, pccb)) { |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 266 | scsi_print_error(pccb); |
| 267 | blkcnt -= blks; |
| 268 | break; |
| 269 | } |
| 270 | buf_addr += pccb->datalen; |
| 271 | } while (blks != 0); |
| 272 | debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", |
| 273 | __func__, start, smallblks, buf_addr); |
| 274 | return blkcnt; |
| 275 | } |
| 276 | |
Simon Glass | 57e7c2a | 2017-06-14 21:28:47 -0600 | [diff] [blame] | 277 | #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) && \ |
| 278 | !defined(CONFIG_DM_SCSI) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 279 | void scsi_init(void) |
| 280 | { |
| 281 | int busdevfunc = -1; |
| 282 | int i; |
| 283 | /* |
| 284 | * Find a device from the list, this driver will support a single |
| 285 | * controller. |
| 286 | */ |
| 287 | for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) { |
| 288 | /* get PCI Device ID */ |
| 289 | #ifdef CONFIG_DM_PCI |
| 290 | struct udevice *dev; |
| 291 | int ret; |
| 292 | |
| 293 | ret = dm_pci_find_device(scsi_device_list[i].vendor, |
| 294 | scsi_device_list[i].device, 0, &dev); |
| 295 | if (!ret) { |
| 296 | busdevfunc = dm_pci_get_bdf(dev); |
| 297 | break; |
| 298 | } |
| 299 | #else |
| 300 | busdevfunc = pci_find_device(scsi_device_list[i].vendor, |
| 301 | scsi_device_list[i].device, |
| 302 | 0); |
| 303 | #endif |
| 304 | if (busdevfunc != -1) |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | if (busdevfunc == -1) { |
| 309 | printf("Error: SCSI Controller(s) "); |
| 310 | for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) { |
| 311 | printf("%04X:%04X ", |
| 312 | scsi_device_list[i].vendor, |
| 313 | scsi_device_list[i].device); |
| 314 | } |
| 315 | printf("not found\n"); |
| 316 | return; |
| 317 | } |
| 318 | #ifdef DEBUG |
| 319 | else { |
| 320 | printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n", |
| 321 | scsi_device_list[i].vendor, |
| 322 | scsi_device_list[i].device, |
| 323 | (busdevfunc >> 16) & 0xFF, |
| 324 | (busdevfunc >> 11) & 0x1F, |
| 325 | (busdevfunc >> 8) & 0x7); |
| 326 | } |
| 327 | #endif |
| 328 | bootstage_start(BOOTSTAGE_ID_ACCUM_SCSI, "ahci"); |
| 329 | scsi_low_level_init(busdevfunc); |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 330 | scsi_scan(true); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 331 | bootstage_accum(BOOTSTAGE_ID_ACCUM_SCSI); |
| 332 | } |
| 333 | #endif |
| 334 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 335 | /* copy src to dest, skipping leading and trailing blanks |
| 336 | * and null terminate the string |
| 337 | */ |
Michal Simek | 9ec32f3 | 2016-11-30 11:53:43 +0100 | [diff] [blame] | 338 | static void scsi_ident_cpy(unsigned char *dest, unsigned char *src, |
| 339 | unsigned int len) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 340 | { |
| 341 | int start, end; |
| 342 | |
| 343 | start = 0; |
| 344 | while (start < len) { |
| 345 | if (src[start] != ' ') |
| 346 | break; |
| 347 | start++; |
| 348 | } |
| 349 | end = len-1; |
| 350 | while (end > start) { |
| 351 | if (src[end] != ' ') |
| 352 | break; |
| 353 | end--; |
| 354 | } |
| 355 | for (; start <= end; start++) |
| 356 | *dest ++= src[start]; |
| 357 | *dest = '\0'; |
| 358 | } |
| 359 | |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 360 | static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb, |
| 361 | lbaint_t *capacity, unsigned long *blksz) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 362 | { |
| 363 | *capacity = 0; |
| 364 | |
| 365 | memset(pccb->cmd, '\0', sizeof(pccb->cmd)); |
| 366 | pccb->cmd[0] = SCSI_RD_CAPAC10; |
| 367 | pccb->cmd[1] = pccb->lun << 5; |
| 368 | pccb->cmdlen = 10; |
| 369 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 370 | |
| 371 | pccb->datalen = 8; |
Simon Glass | a140e86 | 2017-06-14 21:28:44 -0600 | [diff] [blame] | 372 | if (scsi_exec(dev, pccb)) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 373 | return 1; |
| 374 | |
| 375 | *capacity = ((lbaint_t)pccb->pdata[0] << 24) | |
| 376 | ((lbaint_t)pccb->pdata[1] << 16) | |
| 377 | ((lbaint_t)pccb->pdata[2] << 8) | |
| 378 | ((lbaint_t)pccb->pdata[3]); |
| 379 | |
| 380 | if (*capacity != 0xffffffff) { |
| 381 | /* Read capacity (10) was sufficient for this drive. */ |
| 382 | *blksz = ((unsigned long)pccb->pdata[4] << 24) | |
| 383 | ((unsigned long)pccb->pdata[5] << 16) | |
| 384 | ((unsigned long)pccb->pdata[6] << 8) | |
| 385 | ((unsigned long)pccb->pdata[7]); |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | /* Read capacity (10) was insufficient. Use read capacity (16). */ |
| 390 | memset(pccb->cmd, '\0', sizeof(pccb->cmd)); |
| 391 | pccb->cmd[0] = SCSI_RD_CAPAC16; |
| 392 | pccb->cmd[1] = 0x10; |
| 393 | pccb->cmdlen = 16; |
| 394 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 395 | |
| 396 | pccb->datalen = 16; |
Simon Glass | a140e86 | 2017-06-14 21:28:44 -0600 | [diff] [blame] | 397 | if (scsi_exec(dev, pccb)) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 398 | return 1; |
| 399 | |
| 400 | *capacity = ((uint64_t)pccb->pdata[0] << 56) | |
| 401 | ((uint64_t)pccb->pdata[1] << 48) | |
| 402 | ((uint64_t)pccb->pdata[2] << 40) | |
| 403 | ((uint64_t)pccb->pdata[3] << 32) | |
| 404 | ((uint64_t)pccb->pdata[4] << 24) | |
| 405 | ((uint64_t)pccb->pdata[5] << 16) | |
| 406 | ((uint64_t)pccb->pdata[6] << 8) | |
| 407 | ((uint64_t)pccb->pdata[7]); |
| 408 | |
| 409 | *blksz = ((uint64_t)pccb->pdata[8] << 56) | |
| 410 | ((uint64_t)pccb->pdata[9] << 48) | |
| 411 | ((uint64_t)pccb->pdata[10] << 40) | |
| 412 | ((uint64_t)pccb->pdata[11] << 32) | |
| 413 | ((uint64_t)pccb->pdata[12] << 24) | |
| 414 | ((uint64_t)pccb->pdata[13] << 16) | |
| 415 | ((uint64_t)pccb->pdata[14] << 8) | |
| 416 | ((uint64_t)pccb->pdata[15]); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | /* |
| 423 | * Some setup (fill-in) routines |
| 424 | */ |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 425 | static void scsi_setup_test_unit_ready(struct scsi_cmd *pccb) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 426 | { |
| 427 | pccb->cmd[0] = SCSI_TST_U_RDY; |
| 428 | pccb->cmd[1] = pccb->lun << 5; |
| 429 | pccb->cmd[2] = 0; |
| 430 | pccb->cmd[3] = 0; |
| 431 | pccb->cmd[4] = 0; |
| 432 | pccb->cmd[5] = 0; |
| 433 | pccb->cmdlen = 6; |
| 434 | pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ |
| 435 | } |
| 436 | |
Michal Simek | 6241b52 | 2016-11-30 12:50:58 +0100 | [diff] [blame] | 437 | /** |
| 438 | * scsi_init_dev_desc_priv - initialize only SCSI specific blk_desc properties |
| 439 | * |
| 440 | * @dev_desc: Block device description pointer |
| 441 | */ |
| 442 | static void scsi_init_dev_desc_priv(struct blk_desc *dev_desc) |
Michal Simek | ac0a18d1 | 2016-11-18 15:27:00 +0100 | [diff] [blame] | 443 | { |
| 444 | dev_desc->target = 0xff; |
| 445 | dev_desc->lun = 0xff; |
Michal Simek | ac0a18d1 | 2016-11-18 15:27:00 +0100 | [diff] [blame] | 446 | dev_desc->log2blksz = |
| 447 | LOG2_INVALID(typeof(dev_desc->log2blksz)); |
| 448 | dev_desc->type = DEV_TYPE_UNKNOWN; |
| 449 | dev_desc->vendor[0] = 0; |
| 450 | dev_desc->product[0] = 0; |
| 451 | dev_desc->revision[0] = 0; |
| 452 | dev_desc->removable = false; |
Simon Glass | 5f4bd8c | 2017-07-04 13:31:19 -0600 | [diff] [blame] | 453 | #if !CONFIG_IS_ENABLED(BLK) |
Michal Simek | ac0a18d1 | 2016-11-18 15:27:00 +0100 | [diff] [blame] | 454 | dev_desc->block_read = scsi_read; |
| 455 | dev_desc->block_write = scsi_write; |
| 456 | #endif |
| 457 | } |
| 458 | |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 459 | #if !defined(CONFIG_DM_SCSI) |
Michal Simek | 6241b52 | 2016-11-30 12:50:58 +0100 | [diff] [blame] | 460 | /** |
| 461 | * scsi_init_dev_desc - initialize all SCSI specific blk_desc properties |
| 462 | * |
| 463 | * @dev_desc: Block device description pointer |
| 464 | * @devnum: Device number |
| 465 | */ |
| 466 | static void scsi_init_dev_desc(struct blk_desc *dev_desc, int devnum) |
| 467 | { |
| 468 | dev_desc->lba = 0; |
| 469 | dev_desc->blksz = 0; |
| 470 | dev_desc->if_type = IF_TYPE_SCSI; |
| 471 | dev_desc->devnum = devnum; |
| 472 | dev_desc->part_type = PART_TYPE_UNKNOWN; |
| 473 | |
| 474 | scsi_init_dev_desc_priv(dev_desc); |
| 475 | } |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 476 | #endif |
Michal Simek | 4091749 | 2016-11-18 16:14:24 +0100 | [diff] [blame] | 477 | |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 478 | /** |
| 479 | * scsi_detect_dev - Detect scsi device |
| 480 | * |
Michal Simek | 4091749 | 2016-11-18 16:14:24 +0100 | [diff] [blame] | 481 | * @target: target id |
Jean-Jacques Hiblot | 0c447f0 | 2017-04-07 13:42:06 +0200 | [diff] [blame] | 482 | * @lun: target lun |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 483 | * @dev_desc: block device description |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 484 | * |
| 485 | * The scsi_detect_dev detects and fills a dev_desc structure when the device is |
Jean-Jacques Hiblot | 0c447f0 | 2017-04-07 13:42:06 +0200 | [diff] [blame] | 486 | * detected. |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 487 | * |
| 488 | * Return: 0 on success, error value otherwise |
| 489 | */ |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 490 | static int scsi_detect_dev(struct udevice *dev, int target, int lun, |
| 491 | struct blk_desc *dev_desc) |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 492 | { |
| 493 | unsigned char perq, modi; |
| 494 | lbaint_t capacity; |
| 495 | unsigned long blksz; |
Simon Glass | 5fb559d | 2017-06-14 21:28:30 -0600 | [diff] [blame] | 496 | struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb; |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 497 | |
Michal Simek | 4091749 | 2016-11-18 16:14:24 +0100 | [diff] [blame] | 498 | pccb->target = target; |
Jean-Jacques Hiblot | 0c447f0 | 2017-04-07 13:42:06 +0200 | [diff] [blame] | 499 | pccb->lun = lun; |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 500 | pccb->pdata = (unsigned char *)&tempbuff; |
| 501 | pccb->datalen = 512; |
| 502 | scsi_setup_inquiry(pccb); |
Simon Glass | a140e86 | 2017-06-14 21:28:44 -0600 | [diff] [blame] | 503 | if (scsi_exec(dev, pccb)) { |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 504 | if (pccb->contr_stat == SCSI_SEL_TIME_OUT) { |
| 505 | /* |
| 506 | * selection timeout => assuming no |
| 507 | * device present |
| 508 | */ |
| 509 | debug("Selection timeout ID %d\n", |
| 510 | pccb->target); |
| 511 | return -ETIMEDOUT; |
| 512 | } |
| 513 | scsi_print_error(pccb); |
| 514 | return -ENODEV; |
| 515 | } |
| 516 | perq = tempbuff[0]; |
| 517 | modi = tempbuff[1]; |
| 518 | if ((perq & 0x1f) == 0x1f) |
| 519 | return -ENODEV; /* skip unknown devices */ |
| 520 | if ((modi & 0x80) == 0x80) /* drive is removable */ |
| 521 | dev_desc->removable = true; |
| 522 | /* get info for this device */ |
| 523 | scsi_ident_cpy((unsigned char *)dev_desc->vendor, |
| 524 | &tempbuff[8], 8); |
| 525 | scsi_ident_cpy((unsigned char *)dev_desc->product, |
| 526 | &tempbuff[16], 16); |
| 527 | scsi_ident_cpy((unsigned char *)dev_desc->revision, |
| 528 | &tempbuff[32], 4); |
| 529 | dev_desc->target = pccb->target; |
| 530 | dev_desc->lun = pccb->lun; |
| 531 | |
| 532 | pccb->datalen = 0; |
| 533 | scsi_setup_test_unit_ready(pccb); |
Simon Glass | a140e86 | 2017-06-14 21:28:44 -0600 | [diff] [blame] | 534 | if (scsi_exec(dev, pccb)) { |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 535 | if (dev_desc->removable) { |
| 536 | dev_desc->type = perq; |
| 537 | goto removable; |
| 538 | } |
| 539 | scsi_print_error(pccb); |
| 540 | return -EINVAL; |
| 541 | } |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 542 | if (scsi_read_capacity(dev, pccb, &capacity, &blksz)) { |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 543 | scsi_print_error(pccb); |
| 544 | return -EINVAL; |
| 545 | } |
| 546 | dev_desc->lba = capacity; |
| 547 | dev_desc->blksz = blksz; |
| 548 | dev_desc->log2blksz = LOG2(dev_desc->blksz); |
| 549 | dev_desc->type = perq; |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 550 | removable: |
| 551 | return 0; |
| 552 | } |
| 553 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 554 | /* |
| 555 | * (re)-scan the scsi bus and reports scsi device info |
| 556 | * to the user if mode = 1 |
| 557 | */ |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 558 | #if defined(CONFIG_DM_SCSI) |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 559 | static int do_scsi_scan_one(struct udevice *dev, int id, int lun, bool verbose) |
Jean-Jacques Hiblot | cdf96eb | 2017-04-24 11:51:26 +0200 | [diff] [blame] | 560 | { |
| 561 | int ret; |
| 562 | struct udevice *bdev; |
| 563 | struct blk_desc bd; |
| 564 | struct blk_desc *bdesc; |
| 565 | char str[10]; |
| 566 | |
| 567 | /* |
| 568 | * detect the scsi driver to get information about its geometry (block |
| 569 | * size, number of blocks) and other parameters (ids, type, ...) |
| 570 | */ |
| 571 | scsi_init_dev_desc_priv(&bd); |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 572 | if (scsi_detect_dev(dev, id, lun, &bd)) |
Jean-Jacques Hiblot | cdf96eb | 2017-04-24 11:51:26 +0200 | [diff] [blame] | 573 | return -ENODEV; |
| 574 | |
| 575 | /* |
| 576 | * Create only one block device and do detection |
| 577 | * to make sure that there won't be a lot of |
| 578 | * block devices created |
| 579 | */ |
| 580 | snprintf(str, sizeof(str), "id%dlun%d", id, lun); |
| 581 | ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1, |
Jean-Jacques Hiblot | 99b324a | 2017-06-09 16:45:18 +0200 | [diff] [blame] | 582 | bd.blksz, bd.lba, &bdev); |
Jean-Jacques Hiblot | cdf96eb | 2017-04-24 11:51:26 +0200 | [diff] [blame] | 583 | if (ret) { |
| 584 | debug("Can't create device\n"); |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | bdesc = dev_get_uclass_platdata(bdev); |
| 589 | bdesc->target = id; |
| 590 | bdesc->lun = lun; |
| 591 | bdesc->removable = bd.removable; |
| 592 | bdesc->type = bd.type; |
| 593 | memcpy(&bdesc->vendor, &bd.vendor, sizeof(bd.vendor)); |
| 594 | memcpy(&bdesc->product, &bd.product, sizeof(bd.product)); |
| 595 | memcpy(&bdesc->revision, &bd.revision, sizeof(bd.revision)); |
| 596 | part_init(bdesc); |
| 597 | |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 598 | if (verbose) { |
Jean-Jacques Hiblot | cdf96eb | 2017-04-24 11:51:26 +0200 | [diff] [blame] | 599 | printf(" Device %d: ", 0); |
| 600 | dev_print(bdesc); |
| 601 | } |
| 602 | return 0; |
| 603 | } |
| 604 | |
Simon Glass | 600d001 | 2017-06-14 21:28:45 -0600 | [diff] [blame] | 605 | int scsi_scan_dev(struct udevice *dev, bool verbose) |
| 606 | { |
| 607 | struct scsi_platdata *uc_plat; /* scsi controller platdata */ |
| 608 | int ret; |
| 609 | int i; |
| 610 | int lun; |
| 611 | |
| 612 | /* probe SCSI controller driver */ |
| 613 | ret = device_probe(dev); |
| 614 | if (ret) |
| 615 | return ret; |
| 616 | |
| 617 | /* Get controller platdata */ |
| 618 | uc_plat = dev_get_uclass_platdata(dev); |
| 619 | |
| 620 | for (i = 0; i < uc_plat->max_id; i++) |
| 621 | for (lun = 0; lun < uc_plat->max_lun; lun++) |
| 622 | do_scsi_scan_one(dev, i, lun, verbose); |
| 623 | |
| 624 | return 0; |
| 625 | } |
| 626 | |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 627 | int scsi_scan(bool verbose) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 628 | { |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 629 | struct uclass *uc; |
| 630 | struct udevice *dev; /* SCSI controller */ |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 631 | int ret; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 632 | |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 633 | if (verbose) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 634 | printf("scanning bus for devices...\n"); |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 635 | |
Michal Simek | 9c49b8c | 2017-01-02 09:40:09 +0100 | [diff] [blame] | 636 | blk_unbind_all(IF_TYPE_SCSI); |
| 637 | |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 638 | ret = uclass_get(UCLASS_SCSI, &uc); |
| 639 | if (ret) |
| 640 | return ret; |
| 641 | |
| 642 | uclass_foreach_dev(dev, uc) { |
Simon Glass | 600d001 | 2017-06-14 21:28:45 -0600 | [diff] [blame] | 643 | ret = scsi_scan_dev(dev, verbose); |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 644 | if (ret) |
| 645 | return ret; |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | #else |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 651 | int scsi_scan(bool verbose) |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 652 | { |
| 653 | unsigned char i, lun; |
| 654 | int ret; |
| 655 | |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 656 | if (verbose) |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 657 | printf("scanning bus for devices...\n"); |
Michal Simek | ac0a18d1 | 2016-11-18 15:27:00 +0100 | [diff] [blame] | 658 | for (i = 0; i < CONFIG_SYS_SCSI_MAX_DEVICE; i++) |
| 659 | scsi_init_dev_desc(&scsi_dev_desc[i], i); |
| 660 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 661 | scsi_max_devs = 0; |
| 662 | for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) { |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 663 | for (lun = 0; lun < CONFIG_SYS_SCSI_MAX_LUN; lun++) { |
Simon Glass | 11b2b62 | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 664 | ret = scsi_detect_dev(NULL, i, lun, |
Jean-Jacques Hiblot | 0c447f0 | 2017-04-07 13:42:06 +0200 | [diff] [blame] | 665 | &scsi_dev_desc[scsi_max_devs]); |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 666 | if (ret) |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 667 | continue; |
Jean-Jacques Hiblot | 37e721c | 2017-04-07 13:42:07 +0200 | [diff] [blame] | 668 | part_init(&scsi_dev_desc[scsi_max_devs]); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 669 | |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 670 | if (verbose) { |
Michal Simek | ebbde65 | 2016-11-18 15:42:13 +0100 | [diff] [blame] | 671 | printf(" Device %d: ", 0); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 672 | dev_print(&scsi_dev_desc[scsi_max_devs]); |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 673 | } |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 674 | scsi_max_devs++; |
| 675 | } /* next LUN */ |
| 676 | } |
| 677 | if (scsi_max_devs > 0) |
| 678 | scsi_curr_dev = 0; |
| 679 | else |
| 680 | scsi_curr_dev = -1; |
| 681 | |
| 682 | printf("Found %d device(s).\n", scsi_max_devs); |
| 683 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 684 | env_set_ulong("scsidevs", scsi_max_devs); |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 685 | #endif |
Michal Simek | 5dc196f | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 686 | return 0; |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 687 | } |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 688 | #endif |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 689 | |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 690 | #ifdef CONFIG_BLK |
| 691 | static const struct blk_ops scsi_blk_ops = { |
| 692 | .read = scsi_read, |
| 693 | .write = scsi_write, |
| 694 | }; |
| 695 | |
| 696 | U_BOOT_DRIVER(scsi_blk) = { |
| 697 | .name = "scsi_blk", |
| 698 | .id = UCLASS_BLK, |
| 699 | .ops = &scsi_blk_ops, |
| 700 | }; |
| 701 | #else |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 702 | U_BOOT_LEGACY_BLK(scsi) = { |
Ed Swarthout | 987a955 | 2016-06-01 08:11:24 -0500 | [diff] [blame] | 703 | .if_typename = "scsi", |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 704 | .if_type = IF_TYPE_SCSI, |
| 705 | .max_devs = CONFIG_SYS_SCSI_MAX_DEVICE, |
| 706 | .desc = scsi_dev_desc, |
| 707 | }; |
Simon Glass | 5bf96dc | 2016-05-01 11:36:24 -0600 | [diff] [blame] | 708 | #endif |