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