]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/usb_storage.c
Introduce CONFIG_SPL_PANIC_ON_RAW_IMAGE
[karo-tx-uboot.git] / common / usb_storage.c
index 67d26ce87af584c32ed2da075194ec52e9646fe6..1411737bed8912180810c0e9cb239f4602a52bfa 100644 (file)
  * BBB support based on /sys/dev/usb/umass.c from
  * FreeBSD.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /* Note:
@@ -50,6 +33,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <inttypes.h>
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 
@@ -170,9 +154,9 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *us,
                      block_dev_desc_t *dev_desc);
 int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
                      struct us_data *ss);
-unsigned long usb_stor_read(int device, unsigned long blknr,
+unsigned long usb_stor_read(int device, lbaint_t blknr,
                            lbaint_t blkcnt, void *buffer);
-unsigned long usb_stor_write(int device, unsigned long blknr,
+unsigned long usb_stor_write(int device, lbaint_t blknr,
                             lbaint_t blkcnt, const void *buffer);
 struct usb_device * usb_get_dev_index(int index);
 void uhci_show_temp_int_td(void);
@@ -269,9 +253,9 @@ int usb_stor_scan(int mode)
                             lun++) {
                                usb_dev_desc[usb_max_devs].lun = lun;
                                if (usb_stor_get_info(dev, &usb_stor[start],
-                                                     &usb_dev_desc[usb_max_devs]) == 1) {
-                               usb_max_devs++;
-               }
+                                   &usb_dev_desc[usb_max_devs]) == 1) {
+                                       usb_max_devs++;
+                               }
                        }
                }
                /* if storage device */
@@ -504,7 +488,7 @@ static int usb_stor_BBB_comdat(ccb *srb, struct us_data *us)
        dir_in = US_DIRECTION(srb->cmd[0]);
 
 #ifdef BBB_COMDAT_TRACE
-       printf("dir %d lun %d cmdlen %d cmd %p datalen %d pdata %p\n",
+       printf("dir %d lun %d cmdlen %d cmd %p datalen %lu pdata %p\n",
                dir_in, srb->lun, srb->cmdlen, srb->cmd, srb->datalen,
                srb->pdata);
        if (srb->cmdlen) {
@@ -1054,7 +1038,7 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor,
 }
 #endif /* CONFIG_USB_BIN_FIXUP */
 
-unsigned long usb_stor_read(int device, unsigned long blknr,
+unsigned long usb_stor_read(int device, lbaint_t blknr,
                            lbaint_t blkcnt, void *buffer)
 {
        lbaint_t start, blks;
@@ -1088,7 +1072,7 @@ unsigned long usb_stor_read(int device, unsigned long blknr,
        blks = blkcnt;
 
        debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF
-             " buffer %lx\n", device, start, blks, buf_addr);
+             " buffer %" PRIxPTR "\n", device, start, blks, buf_addr);
 
        do {
                /* XXX need some comment here */
@@ -1118,7 +1102,7 @@ retry_it:
        ss->flags &= ~USB_READY;
 
        debug("usb_read: end startblk " LBAF
-             ", blccnt %x buffer %lx\n",
+             ", blccnt %x buffer %" PRIxPTR "\n",
              start, smallblks, buf_addr);
 
        usb_disable_asynch(0); /* asynch transfer allowed */
@@ -1127,7 +1111,7 @@ retry_it:
        return blkcnt;
 }
 
-unsigned long usb_stor_write(int device, unsigned long blknr,
+unsigned long usb_stor_write(int device, lbaint_t blknr,
                                lbaint_t blkcnt, const void *buffer)
 {
        lbaint_t start, blks;
@@ -1162,7 +1146,7 @@ unsigned long usb_stor_write(int device, unsigned long blknr,
        blks = blkcnt;
 
        debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF
-             " buffer %lx\n", device, start, blks, buf_addr);
+             " buffer %" PRIxPTR "\n", device, start, blks, buf_addr);
 
        do {
                /* If write fails retry for max retry count else
@@ -1193,8 +1177,8 @@ retry_it:
        } while (blks != 0);
        ss->flags &= ~USB_READY;
 
-       debug("usb_write: end startblk " LBAF ", blccnt %x buffer %lx\n",
-             start, smallblks, buf_addr);
+       debug("usb_write: end startblk " LBAF ", blccnt %x buffer %"
+             PRIxPTR "\n", start, smallblks, buf_addr);
 
        usb_disable_asynch(0); /* asynch transfer allowed */
        if (blkcnt >= USB_MAX_XFER_BLK)
@@ -1209,6 +1193,7 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
 {
        struct usb_interface *iface;
        int i;
+       struct usb_endpoint_descriptor *ep_desc;
        unsigned int flags = 0;
 
        int protocol = 0;
@@ -1291,24 +1276,25 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
         * We will ignore any others.
         */
        for (i = 0; i < iface->desc.bNumEndpoints; i++) {
+               ep_desc = &iface->ep_desc[i];
                /* is it an BULK endpoint? */
-               if ((iface->ep_desc[i].bmAttributes &
+               if ((ep_desc->bmAttributes &
                     USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
-                       if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN)
-                               ss->ep_in = iface->ep_desc[i].bEndpointAddress &
-                                       USB_ENDPOINT_NUMBER_MASK;
+                       if (ep_desc->bEndpointAddress & USB_DIR_IN)
+                               ss->ep_in = ep_desc->bEndpointAddress &
+                                               USB_ENDPOINT_NUMBER_MASK;
                        else
                                ss->ep_out =
-                                       iface->ep_desc[i].bEndpointAddress &
+                                       ep_desc->bEndpointAddress &
                                        USB_ENDPOINT_NUMBER_MASK;
                }
 
                /* is it an interrupt endpoint? */
-               if ((iface->ep_desc[i].bmAttributes &
-                   USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
-                       ss->ep_int = iface->ep_desc[i].bEndpointAddress &
-                               USB_ENDPOINT_NUMBER_MASK;
-                       ss->irqinterval = iface->ep_desc[i].bInterval;
+               if ((ep_desc->bmAttributes &
+                    USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
+                       ss->ep_int = ep_desc->bEndpointAddress &
+                                               USB_ENDPOINT_NUMBER_MASK;
+                       ss->irqinterval = ep_desc->bInterval;
                }
        }
        debug("Endpoints In %d Out %d Int %d\n",
@@ -1365,8 +1351,11 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
        perq = usb_stor_buf[0];
        modi = usb_stor_buf[1];
 
-       if ((perq & 0x1f) == 0x1f) {
-               /* skip unknown devices */
+       /*
+        * Skip unknown devices (0x1f) and enclosure service devices (0x0d),
+        * they would not respond to test_unit_ready .
+        */
+       if (((perq & 0x1f) == 0x1f) || ((perq & 0x1f) == 0x0d)) {
                return 0;
        }
        if ((modi&0x80) == 0x80) {