Remove multiple KERN_ prefixes from printk formats
[linux-2.6.git] / drivers / usb / core / hcd.c
index 09a53e7..95ccfa0 100644 (file)
 
 /*-------------------------------------------------------------------------*/
 
+/* Keep track of which host controller drivers are loaded */
+unsigned long usb_hcds_loaded;
+EXPORT_SYMBOL_GPL(usb_hcds_loaded);
+
 /* host controllers we manage */
 LIST_HEAD (usb_bus_list);
 EXPORT_SYMBOL_GPL (usb_bus_list);
@@ -102,6 +106,9 @@ static DEFINE_SPINLOCK(hcd_root_hub_lock);
 /* used when updating an endpoint's URB list */
 static DEFINE_SPINLOCK(hcd_urb_list_lock);
 
+/* used to protect against unlinking URBs after the device is gone */
+static DEFINE_SPINLOCK(hcd_urb_unlink_lock);
+
 /* wait queue for synchronous unlinks */
 DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
 
@@ -121,6 +128,27 @@ static inline int is_root_hub(struct usb_device *udev)
 #define KERNEL_REL     ((LINUX_VERSION_CODE >> 16) & 0x0ff)
 #define KERNEL_VER     ((LINUX_VERSION_CODE >> 8) & 0x0ff)
 
+/* usb 3.0 root hub device descriptor */
+static const u8 usb3_rh_dev_descriptor[18] = {
+       0x12,       /*  __u8  bLength; */
+       0x01,       /*  __u8  bDescriptorType; Device */
+       0x00, 0x03, /*  __le16 bcdUSB; v3.0 */
+
+       0x09,       /*  __u8  bDeviceClass; HUB_CLASSCODE */
+       0x00,       /*  __u8  bDeviceSubClass; */
+       0x03,       /*  __u8  bDeviceProtocol; USB 3.0 hub */
+       0x09,       /*  __u8  bMaxPacketSize0; 2^9 = 512 Bytes */
+
+       0x6b, 0x1d, /*  __le16 idVendor; Linux Foundation */
+       0x02, 0x00, /*  __le16 idProduct; device 0x0002 */
+       KERNEL_VER, KERNEL_REL, /*  __le16 bcdDevice */
+
+       0x03,       /*  __u8  iManufacturer; */
+       0x02,       /*  __u8  iProduct; */
+       0x01,       /*  __u8  iSerialNumber; */
+       0x01        /*  __u8  bNumConfigurations; */
+};
+
 /* usb 2.0 root hub device descriptor */
 static const u8 usb2_rh_dev_descriptor [18] = {
        0x12,       /*  __u8  bLength; */
@@ -266,15 +294,56 @@ static const u8 hs_rh_config_descriptor [] = {
        0x0c        /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
 };
 
+static const u8 ss_rh_config_descriptor[] = {
+       /* one configuration */
+       0x09,       /*  __u8  bLength; */
+       0x02,       /*  __u8  bDescriptorType; Configuration */
+       0x19, 0x00, /*  __le16 wTotalLength; FIXME */
+       0x01,       /*  __u8  bNumInterfaces; (1) */
+       0x01,       /*  __u8  bConfigurationValue; */
+       0x00,       /*  __u8  iConfiguration; */
+       0xc0,       /*  __u8  bmAttributes;
+                                Bit 7: must be set,
+                                    6: Self-powered,
+                                    5: Remote wakeup,
+                                    4..0: resvd */
+       0x00,       /*  __u8  MaxPower; */
+
+       /* one interface */
+       0x09,       /*  __u8  if_bLength; */
+       0x04,       /*  __u8  if_bDescriptorType; Interface */
+       0x00,       /*  __u8  if_bInterfaceNumber; */
+       0x00,       /*  __u8  if_bAlternateSetting; */
+       0x01,       /*  __u8  if_bNumEndpoints; */
+       0x09,       /*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
+       0x00,       /*  __u8  if_bInterfaceSubClass; */
+       0x00,       /*  __u8  if_bInterfaceProtocol; */
+       0x00,       /*  __u8  if_iInterface; */
+
+       /* one endpoint (status change endpoint) */
+       0x07,       /*  __u8  ep_bLength; */
+       0x05,       /*  __u8  ep_bDescriptorType; Endpoint */
+       0x81,       /*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
+       0x03,       /*  __u8  ep_bmAttributes; Interrupt */
+                   /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
+                    * see hub.c:hub_configure() for details. */
+       (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
+       0x0c        /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
+       /*
+        * All 3.0 hubs should have an endpoint companion descriptor,
+        * but we're ignoring that for now.  FIXME?
+        */
+};
+
 /*-------------------------------------------------------------------------*/
 
 /*
  * helper routine for returning string descriptors in UTF-16LE
  * input can actually be ISO-8859-1; ASCII is its 7-bit subset
  */
-static int ascii2utf (char *s, u8 *utf, int utfmax)
+static unsigned ascii2utf(char *s, u8 *utf, int utfmax)
 {
-       int retval;
+       unsigned retval;
 
        for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
                *utf++ = *s++;
@@ -297,19 +366,15 @@ static int ascii2utf (char *s, u8 *utf, int utfmax)
  * Produces either a manufacturer, product or serial number string for the
  * virtual root hub device.
  */
-static int rh_string (
-       int             id,
-       struct usb_hcd  *hcd,
-       u8              *data,
-       int             len
-) {
+static unsigned rh_string(int id, struct usb_hcd *hcd, u8 *data, unsigned len)
+{
        char buf [100];
 
        // language ids
        if (id == 0) {
                buf[0] = 4;    buf[1] = 3;      /* 4 bytes string data */
                buf[2] = 0x09; buf[3] = 0x04;   /* MSFT-speak for "en-us" */
-               len = min (len, 4);
+               len = min_t(unsigned, len, 4);
                memcpy (data, buf, len);
                return len;
 
@@ -325,10 +390,7 @@ static int rh_string (
        } else if (id == 3) {
                snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
                        init_utsname()->release, hcd->driver->description);
-
-       // unsupported IDs --> "protocol stall"
-       } else
-               return -EPIPE;
+       }
 
        switch (len) {          /* All cases fall through */
        default:
@@ -353,9 +415,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
        u8              tbuf [sizeof (struct usb_hub_descriptor)]
                __attribute__((aligned(4)));
        const u8        *bufp = tbuf;
-       int             len = 0;
+       unsigned        len = 0;
        int             status;
-       int             n;
        u8              patch_wakeup = 0;
        u8              patch_protocol = 0;
 
@@ -427,32 +488,49 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
        case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
                switch (wValue & 0xff00) {
                case USB_DT_DEVICE << 8:
-                       if (hcd->driver->flags & HCD_USB2)
+                       switch (hcd->driver->flags & HCD_MASK) {
+                       case HCD_USB3:
+                               bufp = usb3_rh_dev_descriptor;
+                               break;
+                       case HCD_USB2:
                                bufp = usb2_rh_dev_descriptor;
-                       else if (hcd->driver->flags & HCD_USB11)
+                               break;
+                       case HCD_USB11:
                                bufp = usb11_rh_dev_descriptor;
-                       else
+                               break;
+                       default:
                                goto error;
+                       }
                        len = 18;
                        if (hcd->has_tt)
                                patch_protocol = 1;
                        break;
                case USB_DT_CONFIG << 8:
-                       if (hcd->driver->flags & HCD_USB2) {
+                       switch (hcd->driver->flags & HCD_MASK) {
+                       case HCD_USB3:
+                               bufp = ss_rh_config_descriptor;
+                               len = sizeof ss_rh_config_descriptor;
+                               break;
+                       case HCD_USB2:
                                bufp = hs_rh_config_descriptor;
                                len = sizeof hs_rh_config_descriptor;
-                       } else {
+                               break;
+                       case HCD_USB11:
                                bufp = fs_rh_config_descriptor;
                                len = sizeof fs_rh_config_descriptor;
+                               break;
+                       default:
+                               goto error;
                        }
                        if (device_can_wakeup(&hcd->self.root_hub->dev))
                                patch_wakeup = 1;
                        break;
                case USB_DT_STRING << 8:
-                       n = rh_string (wValue & 0xff, hcd, ubuf, wLength);
-                       if (n < 0)
+                       if ((wValue & 0xff) < 4)
+                               urb->actual_length = rh_string(wValue & 0xff,
+                                               hcd, ubuf, wLength);
+                       else /* unsupported IDs --> "protocol stall" */
                                goto error;
-                       urb->actual_length = n;
                        break;
                default:
                        goto error;
@@ -570,7 +648,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
        struct urb      *urb;
        int             length;
        unsigned long   flags;
-       char            buffer[4];      /* Any root hubs with > 31 ports? */
+       char            buffer[6];      /* Any root hubs with > 31 ports? */
 
        if (unlikely(!hcd->rh_registered))
                return;
@@ -622,7 +700,7 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
 {
        int             retval;
        unsigned long   flags;
-       int             len = 1 + (urb->dev->maxchild / 8);
+       unsigned        len = 1 + (urb->dev->maxchild / 8);
 
        spin_lock_irqsave (&hcd_root_hub_lock, flags);
        if (hcd->status_urb || urb->transfer_buffer_length < len) {
@@ -755,23 +833,6 @@ static struct attribute_group usb_bus_attr_group = {
 
 /*-------------------------------------------------------------------------*/
 
-static struct class *usb_host_class;
-
-int usb_host_init(void)
-{
-       int retval = 0;
-
-       usb_host_class = class_create(THIS_MODULE, "usb_host");
-       if (IS_ERR(usb_host_class))
-               retval = PTR_ERR(usb_host_class);
-       return retval;
-}
-
-void usb_host_cleanup(void)
-{
-       class_destroy(usb_host_class);
-}
-
 /**
  * usb_bus_init - shared initialization code
  * @bus: the bus structure being initialized
@@ -818,13 +879,6 @@ static int usb_register_bus(struct usb_bus *bus)
        set_bit (busnum, busmap.busmap);
        bus->busnum = busnum;
 
-       bus->dev = device_create_drvdata(usb_host_class, bus->controller,
-                                        MKDEV(0, 0), bus,
-                                        "usb_host%d", busnum);
-       result = PTR_ERR(bus->dev);
-       if (IS_ERR(bus->dev))
-               goto error_create_class_dev;
-
        /* Add it to the local list of buses */
        list_add (&bus->bus_list, &usb_bus_list);
        mutex_unlock(&usb_bus_list_lock);
@@ -835,8 +889,6 @@ static int usb_register_bus(struct usb_bus *bus)
                  "number %d\n", bus->busnum);
        return 0;
 
-error_create_class_dev:
-       clear_bit(busnum, busmap.busmap);
 error_find_busnum:
        mutex_unlock(&usb_bus_list_lock);
        return result;
@@ -866,8 +918,6 @@ static void usb_deregister_bus (struct usb_bus *bus)
        usb_notify_remove_bus(bus);
 
        clear_bit (bus->busnum, busmap.busmap);
-
-       device_unregister(bus->dev);
 }
 
 /**
@@ -895,19 +945,19 @@ static int register_root_hub(struct usb_hcd *hcd)
 
        mutex_lock(&usb_bus_list_lock);
 
-       usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
+       usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
        retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
        if (retval != sizeof usb_dev->descriptor) {
                mutex_unlock(&usb_bus_list_lock);
                dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
-                               usb_dev->dev.bus_id, retval);
+                               dev_name(&usb_dev->dev), retval);
                return (retval < 0) ? retval : -EMSGSIZE;
        }
 
        retval = usb_new_device (usb_dev);
        if (retval) {
                dev_err (parent_dev, "can't register root hub for %s, %d\n",
-                               usb_dev->dev.bus_id, retval);
+                               dev_name(&usb_dev->dev), retval);
        }
        mutex_unlock(&usb_bus_list_lock);
 
@@ -1004,7 +1054,7 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
        spin_lock(&hcd_urb_list_lock);
 
        /* Check that the URB isn't being killed */
-       if (unlikely(urb->reject)) {
+       if (unlikely(atomic_read(&urb->reject))) {
                rc = -EPERM;
                goto done;
        }
@@ -1200,7 +1250,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 
        /* Map the URB's buffers for DMA access.
         * Lower level HCD code should use *_dma exclusively,
-        * unless it uses pio or talks to another transport.
+        * unless it uses pio or talks to another transport,
+        * or uses the provided scatter gather list for bulk.
         */
        if (is_root_hub(urb->dev))
                return 0;
@@ -1334,7 +1385,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
                INIT_LIST_HEAD(&urb->urb_list);
                atomic_dec(&urb->use_count);
                atomic_dec(&urb->dev->urbnum);
-               if (urb->reject)
+               if (atomic_read(&urb->reject))
                        wake_up(&usb_kill_urb_queue);
                usb_put_urb(urb);
        }
@@ -1373,10 +1424,25 @@ static int unlink1(struct usb_hcd *hcd, struct urb *urb, int status)
 int usb_hcd_unlink_urb (struct urb *urb, int status)
 {
        struct usb_hcd          *hcd;
-       int                     retval;
+       int                     retval = -EIDRM;
+       unsigned long           flags;
 
-       hcd = bus_to_hcd(urb->dev->bus);
-       retval = unlink1(hcd, urb, status);
+       /* Prevent the device and bus from going away while
+        * the unlink is carried out.  If they are already gone
+        * then urb->use_count must be 0, since disconnected
+        * devices can't have any active URBs.
+        */
+       spin_lock_irqsave(&hcd_urb_unlink_lock, flags);
+       if (atomic_read(&urb->use_count) > 0) {
+               retval = 0;
+               usb_get_dev(urb->dev);
+       }
+       spin_unlock_irqrestore(&hcd_urb_unlink_lock, flags);
+       if (retval == 0) {
+               hcd = bus_to_hcd(urb->dev->bus);
+               retval = unlink1(hcd, urb, status);
+               usb_put_dev(urb->dev);
+       }
 
        if (retval == 0)
                retval = -EINPROGRESS;
@@ -1423,7 +1489,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
        urb->status = status;
        urb->complete (urb);
        atomic_dec (&urb->use_count);
-       if (unlikely (urb->reject))
+       if (unlikely(atomic_read(&urb->reject)))
                wake_up (&usb_kill_urb_queue);
        usb_put_urb (urb);
 }
@@ -1506,6 +1572,92 @@ rescan:
        }
 }
 
+/* Check whether a new configuration or alt setting for an interface
+ * will exceed the bandwidth for the bus (or the host controller resources).
+ * Only pass in a non-NULL config or interface, not both!
+ * Passing NULL for both new_config and new_intf means the device will be
+ * de-configured by issuing a set configuration 0 command.
+ */
+int usb_hcd_check_bandwidth(struct usb_device *udev,
+               struct usb_host_config *new_config,
+               struct usb_interface *new_intf)
+{
+       int num_intfs, i, j;
+       struct usb_interface_cache *intf_cache;
+       struct usb_host_interface *alt = 0;
+       int ret = 0;
+       struct usb_hcd *hcd;
+       struct usb_host_endpoint *ep;
+
+       hcd = bus_to_hcd(udev->bus);
+       if (!hcd->driver->check_bandwidth)
+               return 0;
+
+       /* Configuration is being removed - set configuration 0 */
+       if (!new_config && !new_intf) {
+               for (i = 1; i < 16; ++i) {
+                       ep = udev->ep_out[i];
+                       if (ep)
+                               hcd->driver->drop_endpoint(hcd, udev, ep);
+                       ep = udev->ep_in[i];
+                       if (ep)
+                               hcd->driver->drop_endpoint(hcd, udev, ep);
+               }
+               hcd->driver->check_bandwidth(hcd, udev);
+               return 0;
+       }
+       /* Check if the HCD says there's enough bandwidth.  Enable all endpoints
+        * each interface's alt setting 0 and ask the HCD to check the bandwidth
+        * of the bus.  There will always be bandwidth for endpoint 0, so it's
+        * ok to exclude it.
+        */
+       if (new_config) {
+               num_intfs = new_config->desc.bNumInterfaces;
+               /* Remove endpoints (except endpoint 0, which is always on the
+                * schedule) from the old config from the schedule
+                */
+               for (i = 1; i < 16; ++i) {
+                       ep = udev->ep_out[i];
+                       if (ep) {
+                               ret = hcd->driver->drop_endpoint(hcd, udev, ep);
+                               if (ret < 0)
+                                       goto reset;
+                       }
+                       ep = udev->ep_in[i];
+                       if (ep) {
+                               ret = hcd->driver->drop_endpoint(hcd, udev, ep);
+                               if (ret < 0)
+                                       goto reset;
+                       }
+               }
+               for (i = 0; i < num_intfs; ++i) {
+
+                       /* Dig the endpoints for alt setting 0 out of the
+                        * interface cache for this interface
+                        */
+                       intf_cache = new_config->intf_cache[i];
+                       for (j = 0; j < intf_cache->num_altsetting; j++) {
+                               if (intf_cache->altsetting[j].desc.bAlternateSetting == 0)
+                                       alt = &intf_cache->altsetting[j];
+                       }
+                       if (!alt) {
+                               printk(KERN_DEBUG "Did not find alt setting 0 for intf %d\n", i);
+                               continue;
+                       }
+                       for (j = 0; j < alt->desc.bNumEndpoints; j++) {
+                               ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]);
+                               if (ret < 0)
+                                       goto reset;
+                       }
+               }
+       }
+       ret = hcd->driver->check_bandwidth(hcd, udev);
+reset:
+       if (ret < 0)
+               hcd->driver->reset_bandwidth(hcd, udev);
+       return ret;
+}
+
 /* Disables the endpoint: synchronizes with the hcd to make sure all
  * endpoint state is gone from hardware.  usb_hcd_flush_endpoint() must
  * have been called previously.  Use for set_configuration, set_interface,
@@ -1525,6 +1677,43 @@ void usb_hcd_disable_endpoint(struct usb_device *udev,
                hcd->driver->endpoint_disable(hcd, ep);
 }
 
+/**
+ * usb_hcd_reset_endpoint - reset host endpoint state
+ * @udev: USB device.
+ * @ep:   the endpoint to reset.
+ *
+ * Resets any host endpoint state such as the toggle bit, sequence
+ * number and current window.
+ */
+void usb_hcd_reset_endpoint(struct usb_device *udev,
+                           struct usb_host_endpoint *ep)
+{
+       struct usb_hcd *hcd = bus_to_hcd(udev->bus);
+
+       if (hcd->driver->endpoint_reset)
+               hcd->driver->endpoint_reset(hcd, ep);
+       else {
+               int epnum = usb_endpoint_num(&ep->desc);
+               int is_out = usb_endpoint_dir_out(&ep->desc);
+               int is_control = usb_endpoint_xfer_control(&ep->desc);
+
+               usb_settoggle(udev, epnum, is_out, 0);
+               if (is_control)
+                       usb_settoggle(udev, epnum, !is_out, 0);
+       }
+}
+
+/* Protect against drivers that try to unlink URBs after the device
+ * is gone, by waiting until all unlinks for @udev are finished.
+ * Since we don't currently track URBs by device, simply wait until
+ * nothing is running in the locked region of usb_hcd_unlink_urb().
+ */
+void usb_hcd_synchronize_unlinks(struct usb_device *udev)
+{
+       spin_lock_irq(&hcd_urb_unlink_lock);
+       spin_unlock_irq(&hcd_urb_unlink_lock);
+}
+
 /*-------------------------------------------------------------------------*/
 
 /* called in any context */
@@ -1541,14 +1730,14 @@ int usb_hcd_get_frame_number (struct usb_device *udev)
 
 #ifdef CONFIG_PM
 
-int hcd_bus_suspend(struct usb_device *rhdev)
+int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
 {
        struct usb_hcd  *hcd = container_of(rhdev->bus, struct usb_hcd, self);
        int             status;
        int             old_state = hcd->state;
 
        dev_dbg(&rhdev->dev, "bus %s%s\n",
-                       rhdev->auto_pm ? "auto-" : "", "suspend");
+                       (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend");
        if (!hcd->driver->bus_suspend) {
                status = -ENOENT;
        } else {
@@ -1566,14 +1755,14 @@ int hcd_bus_suspend(struct usb_device *rhdev)
        return status;
 }
 
-int hcd_bus_resume(struct usb_device *rhdev)
+int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 {
        struct usb_hcd  *hcd = container_of(rhdev->bus, struct usb_hcd, self);
        int             status;
        int             old_state = hcd->state;
 
        dev_dbg(&rhdev->dev, "usb %s%s\n",
-                       rhdev->auto_pm ? "auto-" : "", "resume");
+                       (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume");
        if (!hcd->driver->bus_resume)
                return -ENOENT;
        if (hcd->state == HC_STATE_RUNNING)
@@ -1606,7 +1795,7 @@ static void hcd_resume_work(struct work_struct *work)
 
        usb_lock_device(udev);
        usb_mark_last_busy(udev);
-       usb_external_resume_device(udev);
+       usb_external_resume_device(udev, PMSG_REMOTE_RESUME);
        usb_unlock_device(udev);
 }
 
@@ -1684,19 +1873,30 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
 irqreturn_t usb_hcd_irq (int irq, void *__hcd)
 {
        struct usb_hcd          *hcd = __hcd;
-       int                     start = hcd->state;
+       unsigned long           flags;
+       irqreturn_t             rc;
 
-       if (unlikely(start == HC_STATE_HALT ||
-           !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
-               return IRQ_NONE;
-       if (hcd->driver->irq (hcd) == IRQ_NONE)
-               return IRQ_NONE;
+       /* IRQF_DISABLED doesn't work correctly with shared IRQs
+        * when the first handler doesn't use it.  So let's just
+        * assume it's never used.
+        */
+       local_irq_save(flags);
 
-       set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
+       if (unlikely(hcd->state == HC_STATE_HALT ||
+                    !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
+               rc = IRQ_NONE;
+       } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
+               rc = IRQ_NONE;
+       } else {
+               set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
+
+               if (unlikely(hcd->state == HC_STATE_HALT))
+                       usb_hc_died(hcd);
+               rc = IRQ_HANDLED;
+       }
 
-       if (unlikely(hcd->state == HC_STATE_HALT))
-               usb_hc_died (hcd);
-       return IRQ_HANDLED;
+       local_irq_restore(flags);
+       return rc;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -1744,7 +1944,7 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
  * If memory is unavailable, returns NULL.
  */
 struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
-               struct device *dev, char *bus_name)
+               struct device *dev, const char *bus_name)
 {
        struct usb_hcd *hcd;
 
@@ -1835,8 +2035,20 @@ int usb_add_hcd(struct usb_hcd *hcd,
                retval = -ENOMEM;
                goto err_allocate_root_hub;
        }
-       rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
-                       USB_SPEED_FULL;
+
+       switch (hcd->driver->flags & HCD_MASK) {
+       case HCD_USB11:
+               rhdev->speed = USB_SPEED_FULL;
+               break;
+       case HCD_USB2:
+               rhdev->speed = USB_SPEED_HIGH;
+               break;
+       case HCD_USB3:
+               rhdev->speed = USB_SPEED_SUPER;
+               break;
+       default:
+               goto err_allocate_root_hub;
+       }
        hcd->self.root_hub = rhdev;
 
        /* wakeup flag init defaults to "everything works" for root hubs,
@@ -1860,6 +2072,14 @@ int usb_add_hcd(struct usb_hcd *hcd,
 
        /* enable irqs just before we start the controller */
        if (hcd->driver->irq) {
+
+               /* IRQF_DISABLED doesn't work as advertised when used together
+                * with IRQF_SHARED. As usb_hcd_irq() will always disable
+                * interrupts we can remove it here.
+                */
+               if (irqflags & IRQF_SHARED)
+                       irqflags &= ~IRQF_DISABLED;
+
                snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
                                hcd->driver->description, hcd->self.busnum);
                if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
@@ -1977,7 +2197,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
 
 /*-------------------------------------------------------------------------*/
 
-#if defined(CONFIG_USB_MON)
+#if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
 
 struct usb_mon_operations *mon_ops;
 
@@ -2013,4 +2233,4 @@ void usb_mon_deregister (void)
 }
 EXPORT_SYMBOL_GPL (usb_mon_deregister);
 
-#endif /* CONFIG_USB_MON */
+#endif /* CONFIG_USB_MON || CONFIG_USB_MON_MODULE */