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