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