]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/core/config.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / drivers / usb / core / config.c
index dd3482328ad2603e7726e10d07dd4f2dc09ffc58..568244c99bdc0f5d7b0e03d2177d1153e9d49d49 100644 (file)
@@ -85,15 +85,21 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
        memcpy(&endpoint->desc, d, n);
        INIT_LIST_HEAD(&endpoint->urb_list);
 
-       /* If the bInterval value is outside the legal range,
-        * set it to a default value: 32 ms */
+       /* Fix up bInterval values outside the legal range. Use 32 ms if no
+        * proper value can be guessed. */
        i = 0;          /* i = min, j = max, n = default */
        j = 255;
        if (usb_endpoint_xfer_int(d)) {
                i = 1;
                switch (to_usb_device(ddev)->speed) {
                case USB_SPEED_HIGH:
-                       n = 9;          /* 32 ms = 2^(9-1) uframes */
+                       /* Many device manufacturers are using full-speed
+                        * bInterval values in high-speed interrupt endpoint
+                        * descriptors. Try to fix those and fall back to a
+                        * 32 ms default value otherwise. */
+                       n = fls(d->bInterval*8);
+                       if (n == 0)
+                               n = 9;  /* 32 ms = 2^(9-1) uframes */
                        j = 16;
                        break;
                default:                /* USB_SPEED_FULL or _LOW */
@@ -124,6 +130,38 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
                endpoint->desc.bInterval = n;
        }
 
+       /* Some buggy low-speed devices have Bulk endpoints, which is
+        * explicitly forbidden by the USB spec.  In an attempt to make
+        * them usable, we will try treating them as Interrupt endpoints.
+        */
+       if (to_usb_device(ddev)->speed == USB_SPEED_LOW &&
+                       usb_endpoint_xfer_bulk(d)) {
+               dev_warn(ddev, "config %d interface %d altsetting %d "
+                   "endpoint 0x%X is Bulk; changing to Interrupt\n",
+                   cfgno, inum, asnum, d->bEndpointAddress);
+               endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
+               endpoint->desc.bInterval = 1;
+               if (le16_to_cpu(endpoint->desc.wMaxPacketSize) > 8)
+                       endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
+       }
+
+       /*
+        * Some buggy high speed devices have bulk endpoints using
+        * maxpacket sizes other than 512.  High speed HCDs may not
+        * be able to handle that particular bug, so let's warn...
+        */
+       if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
+                       && usb_endpoint_xfer_bulk(d)) {
+               unsigned maxp;
+
+               maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff;
+               if (maxp != 512)
+                       dev_warn(ddev, "config %d interface %d altsetting %d "
+                               "bulk endpoint 0x%X has invalid maxpacket %d\n",
+                               cfgno, inum, asnum, d->bEndpointAddress,
+                               maxp);
+       }
+
        /* Skip over any Class Specific or Vendor Specific descriptors;
         * find the next endpoint or interface descriptor */
        endpoint->extra = buffer;
@@ -217,7 +255,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
 
        /* Allocate space for the right(?) number of endpoints */
        num_ep = num_ep_orig = alt->desc.bNumEndpoints;
-       alt->desc.bNumEndpoints = 0;            // Use as a counter
+       alt->desc.bNumEndpoints = 0;            /* Use as a counter */
        if (num_ep > USB_MAXENDPOINTS) {
                dev_warn(ddev, "too many endpoints for config %d interface %d "
                    "altsetting %d: %d, using maximum allowed: %d\n",
@@ -225,7 +263,8 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
                num_ep = USB_MAXENDPOINTS;
        }
 
-       if (num_ep > 0) {       /* Can't allocate 0 bytes */
+       if (num_ep > 0) {
+               /* Can't allocate 0 bytes */
                len = sizeof(struct usb_host_endpoint) * num_ep;
                alt->endpoint = kzalloc(len, GFP_KERNEL);
                if (!alt->endpoint)
@@ -274,6 +313,7 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
        struct usb_descriptor_header *header;
        int len, retval;
        u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
+       unsigned iad_num = 0;
 
        memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
        if (config->desc.bDescriptorType != USB_DT_CONFIG ||
@@ -351,6 +391,20 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
                                ++n;
                        }
 
+               } else if (header->bDescriptorType ==
+                               USB_DT_INTERFACE_ASSOCIATION) {
+                       if (iad_num == USB_MAXIADS) {
+                               dev_warn(ddev, "found more Interface "
+                                              "Association Descriptors "
+                                              "than allocated for in "
+                                              "configuration %d\n", cfgno);
+                       } else {
+                               config->intf_assoc[iad_num] =
+                                       (struct usb_interface_assoc_descriptor
+                                       *)header;
+                               iad_num++;
+                       }
+
                } else if (header->bDescriptorType == USB_DT_DEVICE ||
                            header->bDescriptorType == USB_DT_CONFIG)
                        dev_warn(ddev, "config %d contains an unexpected "
@@ -439,8 +493,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
        return 0;
 }
 
-// hub-only!! ... and only exported for reset/reinit path.
-// otherwise used internally on disconnect/destroy path
+/* hub-only!! ... and only exported for reset/reinit path.
+ * otherwise used internally on disconnect/destroy path
+ */
 void usb_destroy_configuration(struct usb_device *dev)
 {
        int c, i;
@@ -462,7 +517,7 @@ void usb_destroy_configuration(struct usb_device *dev)
                kfree(cf->string);
                for (i = 0; i < cf->desc.bNumInterfaces; i++) {
                        if (cf->intf_cache[i])
-                               kref_put(&cf->intf_cache[i]->ref, 
+                               kref_put(&cf->intf_cache[i]->ref,
                                          usb_release_interface_cache);
                }
        }
@@ -471,18 +526,30 @@ void usb_destroy_configuration(struct usb_device *dev)
 }
 
 
-// hub-only!! ... and only in reset path, or usb_new_device()
-// (used by real hubs and virtual root hubs)
+/*
+ * Get the USB config descriptors, cache and parse'em
+ *
+ * hub-only!! ... and only in reset path, or usb_new_device()
+ * (used by real hubs and virtual root hubs)
+ *
+ * NOTE: if this is a WUSB device and is not authorized, we skip the
+ *       whole thing. A non-authorized USB device has no
+ *       configurations.
+ */
 int usb_get_configuration(struct usb_device *dev)
 {
        struct device *ddev = &dev->dev;
        int ncfg = dev->descriptor.bNumConfigurations;
-       int result = -ENOMEM;
+       int result = 0;
        unsigned int cfgno, length;
        unsigned char *buffer;
        unsigned char *bigbuffer;
-       struct usb_config_descriptor *desc;
+       struct usb_config_descriptor *desc;
 
+       cfgno = 0;
+       if (dev->authorized == 0)       /* Not really an error */
+               goto out_not_authorized;
+       result = -ENOMEM;
        if (ncfg > USB_MAXCONFIG) {
                dev_warn(ddev, "too many configurations: %d, "
                    "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
@@ -509,14 +576,15 @@ int usb_get_configuration(struct usb_device *dev)
                goto err2;
        desc = (struct usb_config_descriptor *)buffer;
 
-       for (cfgno = 0; cfgno < ncfg; cfgno++) {
+       result = 0;
+       for (; cfgno < ncfg; cfgno++) {
                /* We grab just the first descriptor so we know how long
                 * the whole configuration is */
                result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
                    buffer, USB_DT_CONFIG_SIZE);
                if (result < 0) {
                        dev_err(ddev, "unable to read config index %d "
-                           "descriptor/%s\n", cfgno, "start");
+                           "descriptor/%s: %d\n", cfgno, "start", result);
                        dev_err(ddev, "chopping to %d config(s)\n", cfgno);
                        dev->descriptor.bNumConfigurations = cfgno;
                        break;
@@ -563,6 +631,7 @@ int usb_get_configuration(struct usb_device *dev)
 
 err:
        kfree(buffer);
+out_not_authorized:
        dev->descriptor.bNumConfigurations = cfgno;
 err2:
        if (result == -ENOMEM)