3 * Denis Peter, MPL AG Switzerland
5 * Most of this source has been derived from the Linux USB
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * Currently only the CBI transport protocoll has been implemented, and it
30 * is only tested with a TEAC USB Floppy. Other Massstorages with CBI or CB
31 * transport protocoll may work as well.
37 #include <asm/processor.h>
40 #if (CONFIG_COMMANDS & CFG_CMD_USB)
43 #ifdef CONFIG_USB_STORAGE
48 #define USB_STOR_PRINTF(fmt,args...) printf (fmt ,##args)
50 #define USB_STOR_PRINTF(fmt,args...)
54 /* direction table -- this indicates the direction of the data
55 * transfer for each command code -- a 1 indicates input
57 unsigned char us_direction[256/8] = {
58 0x28, 0x81, 0x14, 0x14, 0x20, 0x01, 0x90, 0x77,
59 0x0C, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
63 #define US_DIRECTION(x) ((us_direction[x>>3] >> (x & 7)) & 1)
65 static unsigned char usb_stor_buf[512];
75 #define USB_MAX_STOR_DEV 5
76 static int usb_max_devs; /* number of highest available usb device */
78 static block_dev_desc_t usb_dev_desc[USB_MAX_STOR_DEV];
81 typedef int (*trans_cmnd)(ccb*, struct us_data*);
82 typedef int (*trans_reset)(struct us_data*);
85 struct usb_device *pusb_dev; /* this usb_device */
86 unsigned int flags; /* from filter initially */
87 unsigned char ifnum; /* interface number */
88 unsigned char ep_in; /* in endpoint */
89 unsigned char ep_out; /* out ....... */
90 unsigned char ep_int; /* interrupt . */
91 unsigned char subclass; /* as in overview */
92 unsigned char protocol; /* .............. */
93 unsigned char attention_done; /* force attn on first cmd */
94 unsigned short ip_data; /* interrupt data */
95 int action; /* what to do */
96 int ip_wanted; /* needed */
97 int *irq_handle; /* for USB int requests */
98 unsigned int irqpipe; /* pipe for release_irq */
99 unsigned char irqmaxp; /* max packed for irq Pipe */
100 unsigned char irqinterval; /* Intervall for IRQ Pipe */
101 ccb *srb; /* current srb */
102 trans_reset transport_reset; /* reset routine */
103 trans_cmnd transport; /* transport routine */
106 static struct us_data usb_stor[USB_MAX_STOR_DEV];
109 #define USB_STOR_TRANSPORT_GOOD 0
110 #define USB_STOR_TRANSPORT_FAILED -1
111 #define USB_STOR_TRANSPORT_ERROR -2
114 int usb_stor_get_info(struct usb_device *dev, struct us_data *us, block_dev_desc_t *dev_desc);
115 int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,struct us_data *ss);
116 unsigned long usb_stor_read(int device, unsigned long blknr, unsigned long blkcnt, unsigned long *buffer);
117 struct usb_device * usb_get_dev_index(int index);
118 void uhci_show_temp_int_td(void);
120 block_dev_desc_t *usb_stor_get_dev(int index)
122 return &usb_dev_desc[index];
126 void usb_show_progress(void)
131 /*********************************************************************************
132 * (re)-scan the usb and reports device info
133 * to the user if mode = 1
134 * returns current device or -1 if no
136 int usb_stor_scan(int mode)
139 struct usb_device *dev;
142 printf("scanning bus for storage devices...\n");
144 usb_disable_asynch(1); /* asynch transfer not allowed */
146 for(i=0;i<USB_MAX_STOR_DEV;i++) {
147 memset(&usb_dev_desc[i],0,sizeof(block_dev_desc_t));
148 usb_dev_desc[i].target=0xff;
149 usb_dev_desc[i].if_type=IF_TYPE_USB;
150 usb_dev_desc[i].dev=i;
151 usb_dev_desc[i].part_type=PART_TYPE_UNKNOWN;
152 usb_dev_desc[i].block_read=usb_stor_read;
155 for(i=0;i<USB_MAX_DEVICE;i++) {
156 dev=usb_get_dev_index(i); /* get device */
157 USB_STOR_PRINTF("i=%d\n",i);
159 break; /* no more devices avaiable */
161 if(usb_storage_probe(dev,0,&usb_stor[usb_max_devs])) { /* ok, it is a storage devices */
162 /* get info and fill it in */
164 if(usb_stor_get_info(dev, &usb_stor[usb_max_devs], &usb_dev_desc[usb_max_devs])) {
166 printf (" Device %d: ", usb_max_devs);
167 dev_print(&usb_dev_desc[usb_max_devs]);
170 } /* if get info ok */
171 } /* if storage device */
172 if(usb_max_devs==USB_MAX_STOR_DEV) {
173 printf("max USB Storage Device reached: %d stopping\n",usb_max_devs);
177 usb_disable_asynch(0); /* asynch transfer allowed */
184 static int usb_stor_irq(struct usb_device *dev)
187 us=(struct us_data *)dev->privptr;
196 #ifdef USB_STOR_DEBUG
198 static void usb_show_srb(ccb * pccb)
201 printf("SRB: len %d datalen 0x%lX\n ",pccb->cmdlen,pccb->datalen);
203 printf("%02X ",pccb->cmd[i]);
208 static void display_int_status(unsigned long tmp)
210 printf("Status: %s %s %s %s %s %s %s\n",
211 (tmp & USB_ST_ACTIVE) ? "Active" : "",
212 (tmp & USB_ST_STALLED) ? "Stalled" : "",
213 (tmp & USB_ST_BUF_ERR) ? "Buffer Error" : "",
214 (tmp & USB_ST_BABBLE_DET) ? "Babble Det" : "",
215 (tmp & USB_ST_NAK_REC) ? "NAKed" : "",
216 (tmp & USB_ST_CRC_ERR) ? "CRC Error" : "",
217 (tmp & USB_ST_BIT_ERR) ? "Bitstuff Error" : "");
220 /***********************************************************************
221 * Data transfer routines
222 ***********************************************************************/
224 static int us_one_transfer(struct us_data *us, int pipe, char *buf, int length)
233 /* determine the maximum packet size for these transfers */
234 max_size = usb_maxpacket(us->pusb_dev, pipe) * 16;
236 /* while we have data left to transfer */
239 /* calculate how long this will be -- maximum or a remainder */
240 this_xfer = length > max_size ? max_size : length;
243 /* setup the retry counter */
246 /* set up the transfer loop */
248 /* transfer the data */
249 USB_STOR_PRINTF("Bulk xfer 0x%x(%d) try #%d\n",
250 (unsigned int)buf, this_xfer, 11 - maxtry);
251 result = usb_bulk_msg(us->pusb_dev, pipe, buf,
252 this_xfer, &partial, USB_CNTL_TIMEOUT*5);
253 USB_STOR_PRINTF("bulk_msg returned %d xferred %d/%d\n",
254 result, partial, this_xfer);
255 if(us->pusb_dev->status!=0) {
256 /* if we stall, we need to clear it before we go on */
257 #ifdef USB_STOR_DEBUG
258 display_int_status(us->pusb_dev->status);
260 if (us->pusb_dev->status & USB_ST_STALLED) {
261 USB_STOR_PRINTF("stalled ->clearing endpoint halt for pipe 0x%x\n", pipe);
262 stat = us->pusb_dev->status;
263 usb_clear_halt(us->pusb_dev, pipe);
264 us->pusb_dev->status=stat;
265 if(this_xfer == partial) {
266 USB_STOR_PRINTF("bulk transferred with error %X, but data ok\n",us->pusb_dev->status);
272 if (us->pusb_dev->status & USB_ST_NAK_REC) {
273 USB_STOR_PRINTF("Device NAKed bulk_msg\n");
276 if(this_xfer == partial) {
277 USB_STOR_PRINTF("bulk transferred with error %d, but data ok\n",us->pusb_dev->status);
280 /* if our try counter reaches 0, bail out */
281 USB_STOR_PRINTF("bulk transferred with error %d, data %d\n",us->pusb_dev->status,partial);
285 /* update to show what data was transferred */
286 this_xfer -= partial;
288 /* continue until this transfer is done */
289 } while ( this_xfer );
292 /* if we get here, we're done and successful */
296 /* FIXME: this reset function doesn't really reset the port, and it
297 * should. Actually it should probably do what it's doing here, and
298 * reset the port physically
300 static int usb_stor_CB_reset(struct us_data *us)
302 unsigned char cmd[12];
305 USB_STOR_PRINTF("CB_reset\n");
306 memset(cmd, 0xFF, sizeof(cmd));
307 cmd[0] = SCSI_SEND_DIAG;
309 result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev,0),
310 US_CBI_ADSC, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
311 0, us->ifnum, cmd, sizeof(cmd), USB_CNTL_TIMEOUT*5);
313 /* long wait for reset */
315 USB_STOR_PRINTF("CB_reset result %d: status %X clearing endpoint halt\n",result,us->pusb_dev->status);
316 usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_in));
317 usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_out));
319 USB_STOR_PRINTF("CB_reset done\n");
323 /* FIXME: we also need a CBI_command which sets up the completion
324 * interrupt, and waits for it
326 int usb_stor_CB_comdat(ccb *srb, struct us_data *us)
331 unsigned long status;
334 dir_in=US_DIRECTION(srb->cmd[0]);
337 pipe=usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
339 pipe=usb_sndbulkpipe(us->pusb_dev, us->ep_out);
341 USB_STOR_PRINTF("CBI gets a command: Try %d\n",5-retry);
342 #ifdef USB_STOR_DEBUG
345 /* let's send the command via the control pipe */
346 result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev,0),
347 US_CBI_ADSC, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
349 srb->cmd, srb->cmdlen, USB_CNTL_TIMEOUT*5);
350 USB_STOR_PRINTF("CB_transport: control msg returned %d, status %X\n",result,us->pusb_dev->status);
351 /* check the return code for the command */
353 if(us->pusb_dev->status & USB_ST_STALLED) {
354 status=us->pusb_dev->status;
355 USB_STOR_PRINTF(" stall during command found, clear pipe\n");
356 usb_clear_halt(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev,0));
357 us->pusb_dev->status=status;
359 USB_STOR_PRINTF(" error during command %02X Stat = %X\n",srb->cmd[0],us->pusb_dev->status);
362 /* transfer the data payload for this command, if one exists*/
364 USB_STOR_PRINTF("CB_transport: control msg returned %d, direction is %s to go 0x%lx\n",result,dir_in ? "IN" : "OUT",srb->datalen);
366 result = us_one_transfer(us, pipe, srb->pdata,srb->datalen);
367 USB_STOR_PRINTF("CBI attempted to transfer data, result is %d status %lX, len %d\n", result,us->pusb_dev->status,us->pusb_dev->act_len);
368 if(!(us->pusb_dev->status & USB_ST_NAK_REC))
370 } /* if (srb->datalen) */
380 int usb_stor_CBI_get_status(ccb *srb, struct us_data *us)
385 submit_int_msg(us->pusb_dev,us->irqpipe,
386 (void *)&us->ip_data,us->irqmaxp ,us->irqinterval);
389 if((volatile int *)us->ip_wanted==0)
394 printf(" Did not get interrupt on CBI\n");
396 return USB_STOR_TRANSPORT_ERROR;
398 USB_STOR_PRINTF("Got interrupt data 0x%x, transfered %d status 0x%lX\n", us->ip_data,us->pusb_dev->irq_act_len,us->pusb_dev->irq_status);
399 /* UFI gives us ASC and ASCQ, like a request sense */
400 if (us->subclass == US_SC_UFI) {
401 if (srb->cmd[0] == SCSI_REQ_SENSE ||
402 srb->cmd[0] == SCSI_INQUIRY)
403 return USB_STOR_TRANSPORT_GOOD; /* Good */
406 return USB_STOR_TRANSPORT_FAILED;
408 return USB_STOR_TRANSPORT_GOOD;
410 /* otherwise, we interpret the data normally */
411 switch (us->ip_data) {
413 return USB_STOR_TRANSPORT_GOOD;
415 return USB_STOR_TRANSPORT_FAILED;
417 return USB_STOR_TRANSPORT_ERROR;
419 return USB_STOR_TRANSPORT_ERROR;
422 #define USB_TRANSPORT_UNKNOWN_RETRY 5
423 #define USB_TRANSPORT_NOT_READY_RETRY 10
425 int usb_stor_CB_transport(ccb *srb, struct us_data *us)
433 status=USB_STOR_TRANSPORT_GOOD;
436 /* issue the command */
438 result=usb_stor_CB_comdat(srb,us);
439 USB_STOR_PRINTF("command / Data returned %d, status %X\n",result,us->pusb_dev->status);
440 /* if this is an CBI Protocol, get IRQ */
441 if(us->protocol==US_PR_CBI) {
442 status=usb_stor_CBI_get_status(srb,us);
443 /* if the status is error, report it */
444 if(status==USB_STOR_TRANSPORT_ERROR) {
445 USB_STOR_PRINTF(" USB CBI Command Error\n");
448 srb->sense_buf[12]=(unsigned char)(us->ip_data>>8);
449 srb->sense_buf[13]=(unsigned char)(us->ip_data&0xff);
451 /* if the status is good, report it */
452 if(status==USB_STOR_TRANSPORT_GOOD) {
453 USB_STOR_PRINTF(" USB CBI Command Good\n");
458 /* do we have to issue an auto request? */
459 /* HERE we have to check the result */
460 if((result<0) && !(us->pusb_dev->status & USB_ST_STALLED)) {
461 USB_STOR_PRINTF("ERROR %X\n",us->pusb_dev->status);
462 us->transport_reset(us);
463 return USB_STOR_TRANSPORT_ERROR;
465 if((us->protocol==US_PR_CBI) &&
466 ((srb->cmd[0]==SCSI_REQ_SENSE) ||
467 (srb->cmd[0]==SCSI_INQUIRY))) { /* do not issue an autorequest after request sense */
468 USB_STOR_PRINTF("No auto request and good\n");
469 return USB_STOR_TRANSPORT_GOOD;
471 /* issue an request_sense */
472 memset(&psrb->cmd[0],0,12);
473 psrb->cmd[0]=SCSI_REQ_SENSE;
474 psrb->cmd[1]=srb->lun<<5;
477 psrb->pdata=&srb->sense_buf[0];
479 /* issue the command */
480 result=usb_stor_CB_comdat(psrb,us);
481 USB_STOR_PRINTF("auto request returned %d\n",result);
482 /* if this is an CBI Protocol, get IRQ */
483 if(us->protocol==US_PR_CBI) {
484 status=usb_stor_CBI_get_status(psrb,us);
486 if((result<0)&&!(us->pusb_dev->status & USB_ST_STALLED)) {
487 USB_STOR_PRINTF(" AUTO REQUEST ERROR %d\n",us->pusb_dev->status);
488 return USB_STOR_TRANSPORT_ERROR;
490 USB_STOR_PRINTF("autorequest returned 0x%02X 0x%02X 0x%02X 0x%02X\n",srb->sense_buf[0],srb->sense_buf[2],srb->sense_buf[12],srb->sense_buf[13]);
491 /* Check the auto request result */
492 if((srb->sense_buf[2]==0) &&
493 (srb->sense_buf[12]==0) &&
494 (srb->sense_buf[13]==0)) /* ok, no sense */
495 return USB_STOR_TRANSPORT_GOOD;
496 /* Check the auto request result */
497 switch(srb->sense_buf[2]) {
498 case 0x01: /* Recovered Error */
499 return USB_STOR_TRANSPORT_GOOD;
501 case 0x02: /* Not Ready */
502 if(notready++ > USB_TRANSPORT_NOT_READY_RETRY) {
503 printf("cmd 0x%02X returned 0x%02X 0x%02X 0x%02X 0x%02X (NOT READY)\n",
504 srb->cmd[0],srb->sense_buf[0],srb->sense_buf[2],srb->sense_buf[12],srb->sense_buf[13]);
505 return USB_STOR_TRANSPORT_FAILED;
513 if(retry++ > USB_TRANSPORT_UNKNOWN_RETRY) {
514 printf("cmd 0x%02X returned 0x%02X 0x%02X 0x%02X 0x%02X\n",
515 srb->cmd[0],srb->sense_buf[0],srb->sense_buf[2],srb->sense_buf[12],srb->sense_buf[13]);
516 return USB_STOR_TRANSPORT_FAILED;
522 return USB_STOR_TRANSPORT_FAILED;
526 static int usb_inquiry(ccb *srb,struct us_data *ss)
531 memset(&srb->cmd[0],0,12);
532 srb->cmd[0]=SCSI_INQUIRY;
533 srb->cmd[1]=srb->lun<<5;
537 i=ss->transport(srb,ss);
538 USB_STOR_PRINTF("inquiry returns %d\n",i);
543 printf("error in inquiry\n");
549 static int usb_request_sense(ccb *srb,struct us_data *ss)
554 memset(&srb->cmd[0],0,12);
555 srb->cmd[0]=SCSI_REQ_SENSE;
556 srb->cmd[1]=srb->lun<<5;
559 srb->pdata=&srb->sense_buf[0];
561 ss->transport(srb,ss);
562 USB_STOR_PRINTF("Request Sense returned %02X %02X %02X\n",srb->sense_buf[2],srb->sense_buf[12],srb->sense_buf[13]);
567 static int usb_test_unit_ready(ccb *srb,struct us_data *ss)
571 memset(&srb->cmd[0],0,12);
572 srb->cmd[0]=SCSI_TST_U_RDY;
573 srb->cmd[1]=srb->lun<<5;
576 if(ss->transport(srb,ss)==USB_STOR_TRANSPORT_GOOD)
584 static int usb_read_capacity(ccb *srb,struct us_data *ss)
587 retry=2; /* retries */
589 memset(&srb->cmd[0],0,12);
590 srb->cmd[0]=SCSI_RD_CAPAC;
591 srb->cmd[1]=srb->lun<<5;
594 if(ss->transport(srb,ss)==USB_STOR_TRANSPORT_GOOD) {
601 static int usb_read_10(ccb *srb,struct us_data *ss, unsigned long start, unsigned short blocks)
603 memset(&srb->cmd[0],0,12);
604 srb->cmd[0]=SCSI_READ10;
605 srb->cmd[1]=srb->lun<<5;
606 srb->cmd[2]=((unsigned char) (start>>24))&0xff;
607 srb->cmd[3]=((unsigned char) (start>>16))&0xff;
608 srb->cmd[4]=((unsigned char) (start>>8))&0xff;
609 srb->cmd[5]=((unsigned char) (start))&0xff;
610 srb->cmd[7]=((unsigned char) (blocks>>8))&0xff;
611 srb->cmd[8]=(unsigned char) blocks & 0xff;
613 USB_STOR_PRINTF("read10: start %lx blocks %x\n",start,blocks);
614 return ss->transport(srb,ss);
618 #define USB_MAX_READ_BLK 20
620 unsigned long usb_stor_read(int device, unsigned long blknr, unsigned long blkcnt, unsigned long *buffer)
622 unsigned long start,blks, buf_addr;
623 unsigned short smallblks;
624 struct usb_device *dev;
630 USB_STOR_PRINTF("\nusb_read: dev %d \n",device);
632 for(i=0;i<USB_MAX_DEVICE;i++) {
633 dev=usb_get_dev_index(i);
637 if(dev->devnum==usb_dev_desc[device].target)
641 usb_disable_asynch(1); /* asynch transfer not allowed */
642 srb->lun=usb_dev_desc[device].lun;
643 buf_addr=(unsigned long)buffer;
646 if(usb_test_unit_ready(srb,(struct us_data *)dev->privptr)) {
647 printf("Device NOT ready\n Request Sense returned %02X %02X %02X\n",
648 srb->sense_buf[2],srb->sense_buf[12],srb->sense_buf[13]);
651 USB_STOR_PRINTF("\nusb_read: dev %d startblk %lx, blccnt %lx buffer %lx\n",device,start,blks, buf_addr);
654 srb->pdata=(unsigned char *)buf_addr;
655 if(blks>USB_MAX_READ_BLK) {
656 smallblks=USB_MAX_READ_BLK;
659 smallblks=(unsigned short) blks;
662 if(smallblks==USB_MAX_READ_BLK)
664 srb->datalen=usb_dev_desc[device].blksz * smallblks;
665 srb->pdata=(unsigned char *)buf_addr;
666 if(usb_read_10(srb,(struct us_data *)dev->privptr, start, smallblks)) {
667 USB_STOR_PRINTF("Read ERROR\n");
668 usb_request_sense(srb,(struct us_data *)dev->privptr);
676 buf_addr+=srb->datalen;
678 USB_STOR_PRINTF("usb_read: end startblk %lx, blccnt %x buffer %lx\n",start,smallblks,buf_addr);
679 usb_disable_asynch(0); /* asynch transfer allowed */
680 if(blkcnt>=USB_MAX_READ_BLK)
686 /* Probe to see if a new device is actually a Storage device */
687 int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,struct us_data *ss)
689 struct usb_interface_descriptor *iface;
691 unsigned int flags = 0;
697 memset(ss, 0, sizeof(struct us_data));
699 /* let's examine the device now */
700 iface = &dev->config.if_desc[ifnum];
703 /* this is the place to patch some storage devices */
704 USB_STOR_PRINTF("iVendor %X iProduct %X\n",dev->descriptor.idVendor,dev->descriptor.idProduct);
705 if ((dev->descriptor.idVendor) == 0x066b && (dev->descriptor.idProduct) == 0x0103) {
706 USB_STOR_PRINTF("patched for E-USB\n");
708 subclass = US_SC_UFI; /* an assumption */
712 if (dev->descriptor.bDeviceClass != 0 ||
713 iface->bInterfaceClass != USB_CLASS_MASS_STORAGE ||
714 iface->bInterfaceSubClass < US_SC_MIN ||
715 iface->bInterfaceSubClass > US_SC_MAX) {
716 /* if it's not a mass storage, we go no further */
720 /* At this point, we know we've got a live one */
721 USB_STOR_PRINTF("\n\nUSB Mass Storage device detected\n");
723 /* Initialize the us_data structure with some useful info */
727 ss->attention_done = 0;
729 /* If the device has subclass and protocol, then use that. Otherwise,
730 * take data from the specific interface.
733 ss->subclass = subclass;
734 ss->protocol = protocol;
736 ss->subclass = iface->bInterfaceSubClass;
737 ss->protocol = iface->bInterfaceProtocol;
740 /* set the handler pointers based on the protocol */
741 USB_STOR_PRINTF("Transport: ");
742 switch (ss->protocol) {
744 USB_STOR_PRINTF("Control/Bulk\n");
745 ss->transport = usb_stor_CB_transport;
746 ss->transport_reset = usb_stor_CB_reset;
750 USB_STOR_PRINTF("Control/Bulk/Interrupt\n");
751 ss->transport = usb_stor_CB_transport;
752 ss->transport_reset = usb_stor_CB_reset;
755 printf("USB Starage Transport unknown / not yet implemented\n");
761 * We are expecting a minimum of 2 endpoints - in and out (bulk).
762 * An optional interrupt is OK (necessary for CBI protocol).
763 * We will ignore any others.
765 for (i = 0; i < iface->bNumEndpoints; i++) {
766 /* is it an BULK endpoint? */
767 if ((iface->ep_desc[i].bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
768 == USB_ENDPOINT_XFER_BULK) {
769 if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN)
770 ss->ep_in = iface->ep_desc[i].bEndpointAddress &
771 USB_ENDPOINT_NUMBER_MASK;
773 ss->ep_out = iface->ep_desc[i].bEndpointAddress &
774 USB_ENDPOINT_NUMBER_MASK;
777 /* is it an interrupt endpoint? */
778 if ((iface->ep_desc[i].bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
779 == USB_ENDPOINT_XFER_INT) {
780 ss->ep_int = iface->ep_desc[i].bEndpointAddress &
781 USB_ENDPOINT_NUMBER_MASK;
782 ss->irqinterval = iface->ep_desc[i].bInterval;
785 USB_STOR_PRINTF("Endpoints In %d Out %d Int %d\n",
786 ss->ep_in, ss->ep_out, ss->ep_int);
788 /* Do some basic sanity checks, and bail if we find a problem */
789 if (usb_set_interface(dev, iface->bInterfaceNumber, 0) ||
790 !ss->ep_in || !ss->ep_out ||
791 (ss->protocol == US_PR_CBI && ss->ep_int == 0)) {
792 USB_STOR_PRINTF("Problems with device\n");
795 /* set class specific stuff */
796 /* We only handle certain protocols. Currently, this is
799 if (ss->subclass != US_SC_UFI) {
800 printf("Sorry, protocol %d not yet supported.\n",ss->subclass);
803 if(ss->ep_int) /* we had found an interrupt endpoint, prepare irq pipe */
805 /* set up the IRQ pipe and handler */
807 ss->irqinterval = (ss->irqinterval > 0) ? ss->irqinterval : 255;
808 ss->irqpipe = usb_rcvintpipe(ss->pusb_dev, ss->ep_int);
809 ss->irqmaxp = usb_maxpacket(dev, ss->irqpipe);
810 dev->irq_handle=usb_stor_irq;
811 dev->privptr=(void *)ss;
816 int usb_stor_get_info(struct usb_device *dev,struct us_data *ss,block_dev_desc_t *dev_desc)
818 unsigned char perq,modi;
819 unsigned long cap[2];
820 unsigned long *capacity,*blksz;
823 ss->transport_reset(ss);
824 pccb->pdata=usb_stor_buf;
826 dev_desc->target=dev->devnum;
827 pccb->lun=dev_desc->lun;
828 USB_STOR_PRINTF(" address %d\n",dev_desc->target);
830 if(usb_inquiry(pccb,ss))
832 perq=usb_stor_buf[0];
833 modi=usb_stor_buf[1];
834 if((perq & 0x1f)==0x1f) {
835 return 0; /* skip unknown devices */
837 if((modi&0x80)==0x80) {/* drive is removable */
838 dev_desc->removable=1;
840 memcpy(&dev_desc->vendor[0], &usb_stor_buf[8], 8);
841 memcpy(&dev_desc->product[0], &usb_stor_buf[16], 16);
842 memcpy(&dev_desc->revision[0], &usb_stor_buf[32], 4);
843 dev_desc->vendor[8]=0;
844 dev_desc->product[16]=0;
845 dev_desc->revision[4]=0;
846 USB_STOR_PRINTF("ISO Vers %X, Response Data %X\n",usb_stor_buf[2],usb_stor_buf[3]);
847 if(usb_test_unit_ready(pccb,ss)) {
848 printf("Device NOT ready\n Request Sense returned %02X %02X %02X\n",pccb->sense_buf[2],pccb->sense_buf[12],pccb->sense_buf[13]);
849 if(dev_desc->removable==1) {
856 pccb->pdata=(unsigned char *)&cap[0];
857 memset(pccb->pdata,0,8);
858 if(usb_read_capacity(pccb,ss)!=0) {
859 printf("READ_CAP ERROR\n");
863 USB_STOR_PRINTF("Read Capacity returns: 0x%lx, 0x%lx\n",cap[0],cap[1]);
865 if(cap[0]>(0x200000 * 10)) /* greater than 10 GByte */
871 USB_STOR_PRINTF("Capacity = 0x%lx, blocksz = 0x%lx\n",*capacity,*blksz);
872 dev_desc->lba=*capacity;
873 dev_desc->blksz=*blksz;
875 USB_STOR_PRINTF(" address %d\n",dev_desc->target);
876 USB_STOR_PRINTF("partype: %d\n",dev_desc->part_type);
880 USB_STOR_PRINTF("partype: %d\n",dev_desc->part_type);
885 #endif /* CONFIG_USB_STORAGE */