2 * (C) Copyright Linus Torvalds 1999
3 * (C) Copyright Johannes Erdfelt 1999-2001
4 * (C) Copyright Andreas Gal 1999
5 * (C) Copyright Gregory P. Smith 1999
6 * (C) Copyright Deti Fliegl 1999
7 * (C) Copyright Randy Dunlap 2000
8 * (C) Copyright David Brownell 2000-2002
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/config.h>
27 #ifdef CONFIG_USB_DEBUG
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/completion.h>
36 #include <linux/utsname.h>
39 #include <asm/scatterlist.h>
40 #include <linux/device.h>
41 #include <linux/dma-mapping.h>
43 #include <asm/byteorder.h>
45 #include <linux/usb.h>
51 // #define USB_BANDWIDTH_MESSAGES
53 /*-------------------------------------------------------------------------*/
56 * USB Host Controller Driver framework
58 * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing
59 * HCD-specific behaviors/bugs.
61 * This does error checks, tracks devices and urbs, and delegates to a
62 * "hc_driver" only for code (and data) that really needs to know about
63 * hardware differences. That includes root hub registers, i/o queues,
64 * and so on ... but as little else as possible.
66 * Shared code includes most of the "root hub" code (these are emulated,
67 * though each HC's hardware works differently) and PCI glue, plus request
68 * tracking overhead. The HCD code should only block on spinlocks or on
69 * hardware handshaking; blocking on software events (such as other kernel
70 * threads releasing resources, or completing actions) is all generic.
72 * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
73 * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
74 * only by the hub driver ... and that neither should be seen or used by
75 * usb client device drivers.
77 * Contributors of ideas or unattributed patches include: David Brownell,
78 * Roman Weissgaerber, Rory Bolt, Greg Kroah-Hartman, ...
81 * 2002-02-21 Pull in most of the usb_bus support from usb.c; some
82 * associated cleanup. "usb_hcd" still != "usb_bus".
83 * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
86 /*-------------------------------------------------------------------------*/
88 /* host controllers we manage */
89 LIST_HEAD (usb_bus_list);
91 /* used when allocating bus numbers */
94 unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))];
96 static struct usb_busmap busmap;
98 /* used when updating list of hcds */
99 DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */
101 /* used when updating hcd data */
102 static DEFINE_SPINLOCK(hcd_data_lock);
104 /* wait queue for synchronous unlinks */
105 DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
107 /*-------------------------------------------------------------------------*/
110 * Sharable chunks of root hub code.
113 /*-------------------------------------------------------------------------*/
115 #define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff)
116 #define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff)
118 /* usb 2.0 root hub device descriptor */
119 static const u8 usb2_rh_dev_descriptor [18] = {
120 0x12, /* __u8 bLength; */
121 0x01, /* __u8 bDescriptorType; Device */
122 0x00, 0x02, /* __le16 bcdUSB; v2.0 */
124 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
125 0x00, /* __u8 bDeviceSubClass; */
126 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/
127 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
129 0x00, 0x00, /* __le16 idVendor; */
130 0x00, 0x00, /* __le16 idProduct; */
131 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
133 0x03, /* __u8 iManufacturer; */
134 0x02, /* __u8 iProduct; */
135 0x01, /* __u8 iSerialNumber; */
136 0x01 /* __u8 bNumConfigurations; */
139 /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
141 /* usb 1.1 root hub device descriptor */
142 static const u8 usb11_rh_dev_descriptor [18] = {
143 0x12, /* __u8 bLength; */
144 0x01, /* __u8 bDescriptorType; Device */
145 0x10, 0x01, /* __le16 bcdUSB; v1.1 */
147 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
148 0x00, /* __u8 bDeviceSubClass; */
149 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */
150 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
152 0x00, 0x00, /* __le16 idVendor; */
153 0x00, 0x00, /* __le16 idProduct; */
154 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
156 0x03, /* __u8 iManufacturer; */
157 0x02, /* __u8 iProduct; */
158 0x01, /* __u8 iSerialNumber; */
159 0x01 /* __u8 bNumConfigurations; */
163 /*-------------------------------------------------------------------------*/
165 /* Configuration descriptors for our root hubs */
167 static const u8 fs_rh_config_descriptor [] = {
169 /* one configuration */
170 0x09, /* __u8 bLength; */
171 0x02, /* __u8 bDescriptorType; Configuration */
172 0x19, 0x00, /* __le16 wTotalLength; */
173 0x01, /* __u8 bNumInterfaces; (1) */
174 0x01, /* __u8 bConfigurationValue; */
175 0x00, /* __u8 iConfiguration; */
176 0xc0, /* __u8 bmAttributes;
181 0x00, /* __u8 MaxPower; */
184 * USB 2.0, single TT organization (mandatory):
185 * one interface, protocol 0
187 * USB 2.0, multiple TT organization (optional):
188 * two interfaces, protocols 1 (like single TT)
189 * and 2 (multiple TT mode) ... config is
195 0x09, /* __u8 if_bLength; */
196 0x04, /* __u8 if_bDescriptorType; Interface */
197 0x00, /* __u8 if_bInterfaceNumber; */
198 0x00, /* __u8 if_bAlternateSetting; */
199 0x01, /* __u8 if_bNumEndpoints; */
200 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
201 0x00, /* __u8 if_bInterfaceSubClass; */
202 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
203 0x00, /* __u8 if_iInterface; */
205 /* one endpoint (status change endpoint) */
206 0x07, /* __u8 ep_bLength; */
207 0x05, /* __u8 ep_bDescriptorType; Endpoint */
208 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
209 0x03, /* __u8 ep_bmAttributes; Interrupt */
210 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
211 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
214 static const u8 hs_rh_config_descriptor [] = {
216 /* one configuration */
217 0x09, /* __u8 bLength; */
218 0x02, /* __u8 bDescriptorType; Configuration */
219 0x19, 0x00, /* __le16 wTotalLength; */
220 0x01, /* __u8 bNumInterfaces; (1) */
221 0x01, /* __u8 bConfigurationValue; */
222 0x00, /* __u8 iConfiguration; */
223 0xc0, /* __u8 bmAttributes;
228 0x00, /* __u8 MaxPower; */
231 * USB 2.0, single TT organization (mandatory):
232 * one interface, protocol 0
234 * USB 2.0, multiple TT organization (optional):
235 * two interfaces, protocols 1 (like single TT)
236 * and 2 (multiple TT mode) ... config is
242 0x09, /* __u8 if_bLength; */
243 0x04, /* __u8 if_bDescriptorType; Interface */
244 0x00, /* __u8 if_bInterfaceNumber; */
245 0x00, /* __u8 if_bAlternateSetting; */
246 0x01, /* __u8 if_bNumEndpoints; */
247 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
248 0x00, /* __u8 if_bInterfaceSubClass; */
249 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
250 0x00, /* __u8 if_iInterface; */
252 /* one endpoint (status change endpoint) */
253 0x07, /* __u8 ep_bLength; */
254 0x05, /* __u8 ep_bDescriptorType; Endpoint */
255 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
256 0x03, /* __u8 ep_bmAttributes; Interrupt */
257 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
258 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
261 /*-------------------------------------------------------------------------*/
264 * helper routine for returning string descriptors in UTF-16LE
265 * input can actually be ISO-8859-1; ASCII is its 7-bit subset
267 static int ascii2utf (char *s, u8 *utf, int utfmax)
271 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
279 * rh_string - provides manufacturer, product and serial strings for root hub
280 * @id: the string ID number (1: serial number, 2: product, 3: vendor)
281 * @hcd: the host controller for this root hub
282 * @type: string describing our driver
283 * @data: return packet in UTF-16 LE
284 * @len: length of the return packet
286 * Produces either a manufacturer, product or serial number string for the
287 * virtual root hub device.
289 static int rh_string (
299 *data++ = 4; *data++ = 3; /* 4 bytes string data */
300 *data++ = 0x09; *data++ = 0x04; /* MSFT-speak for "en-us" */
304 } else if (id == 1) {
305 strcpy (buf, hcd->self.bus_name);
307 // product description
308 } else if (id == 2) {
309 strcpy (buf, hcd->product_desc);
311 // id 3 == vendor description
312 } else if (id == 3) {
313 sprintf (buf, "%s %s %s", system_utsname.sysname,
314 system_utsname.release, hcd->driver->description);
316 // unsupported IDs --> "protocol stall"
320 data [0] = 2 * (strlen (buf) + 1);
321 data [1] = 3; /* type == string */
322 return 2 + ascii2utf (buf, data + 2, len - 2);
326 /* Root hub control transfers execute synchronously */
327 static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
329 struct usb_ctrlrequest *cmd;
330 u16 typeReq, wValue, wIndex, wLength;
331 const u8 *bufp = NULL;
332 u8 *ubuf = urb->transfer_buffer;
334 int patch_wakeup = 0;
337 cmd = (struct usb_ctrlrequest *) urb->setup_packet;
338 typeReq = (cmd->bRequestType << 8) | cmd->bRequest;
339 wValue = le16_to_cpu (cmd->wValue);
340 wIndex = le16_to_cpu (cmd->wIndex);
341 wLength = le16_to_cpu (cmd->wLength);
343 if (wLength > urb->transfer_buffer_length)
346 /* set up for success */
348 urb->actual_length = wLength;
351 /* DEVICE REQUESTS */
353 case DeviceRequest | USB_REQ_GET_STATUS:
354 ubuf [0] = (hcd->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP)
355 | (1 << USB_DEVICE_SELF_POWERED);
358 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
359 if (wValue == USB_DEVICE_REMOTE_WAKEUP)
360 hcd->remote_wakeup = 0;
364 case DeviceOutRequest | USB_REQ_SET_FEATURE:
365 if (hcd->can_wakeup && wValue == USB_DEVICE_REMOTE_WAKEUP)
366 hcd->remote_wakeup = 1;
370 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
373 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
375 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
376 switch (wValue & 0xff00) {
377 case USB_DT_DEVICE << 8:
378 if (hcd->driver->flags & HCD_USB2)
379 bufp = usb2_rh_dev_descriptor;
380 else if (hcd->driver->flags & HCD_USB11)
381 bufp = usb11_rh_dev_descriptor;
386 case USB_DT_CONFIG << 8:
387 if (hcd->driver->flags & HCD_USB2) {
388 bufp = hs_rh_config_descriptor;
389 len = sizeof hs_rh_config_descriptor;
391 bufp = fs_rh_config_descriptor;
392 len = sizeof fs_rh_config_descriptor;
397 case USB_DT_STRING << 8:
398 urb->actual_length = rh_string (
406 case DeviceRequest | USB_REQ_GET_INTERFACE:
409 case DeviceOutRequest | USB_REQ_SET_INTERFACE:
411 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
412 // wValue == urb->dev->devaddr
413 dev_dbg (hcd->self.controller, "root hub device address %d\n",
417 /* INTERFACE REQUESTS (no defined feature/status flags) */
419 /* ENDPOINT REQUESTS */
421 case EndpointRequest | USB_REQ_GET_STATUS:
422 // ENDPOINT_HALT flag
426 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
427 case EndpointOutRequest | USB_REQ_SET_FEATURE:
428 dev_dbg (hcd->self.controller, "no endpoint features yet\n");
431 /* CLASS REQUESTS (and errors) */
434 /* non-generic request */
435 if (HCD_IS_SUSPENDED (hcd->state))
436 urb->status = -EAGAIN;
438 urb->status = hcd->driver->hub_control (hcd,
439 typeReq, wValue, wIndex,
443 /* "protocol stall" on error */
444 urb->status = -EPIPE;
447 urb->actual_length = 0;
448 if (urb->status != -EPIPE) {
449 dev_dbg (hcd->self.controller,
450 "CTRL: TypeReq=0x%x val=0x%x "
451 "idx=0x%x len=%d ==> %d\n",
452 typeReq, wValue, wIndex,
453 wLength, urb->status);
457 if (urb->transfer_buffer_length < len)
458 len = urb->transfer_buffer_length;
459 urb->actual_length = len;
460 // always USB_DIR_IN, toward host
461 memcpy (ubuf, bufp, len);
463 /* report whether RH hardware supports remote wakeup */
465 ((struct usb_config_descriptor *)ubuf)->bmAttributes
466 |= USB_CONFIG_ATT_WAKEUP;
469 /* any errors get returned through the urb completion */
470 local_irq_save (flags);
471 usb_hcd_giveback_urb (hcd, urb, NULL);
472 local_irq_restore (flags);
476 /*-------------------------------------------------------------------------*/
479 * Root Hub interrupt transfers are synthesized with a timer.
480 * Completions are called in_interrupt() but not in_irq().
482 * Note: some root hubs (including common UHCI based designs) can't
483 * correctly issue port change IRQs. They're the ones that _need_ a
484 * timer; most other root hubs don't. Some systems could save a
485 * lot of battery power by eliminating these root hub timer IRQs.
488 static void rh_report_status (unsigned long ptr);
490 static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb)
492 int len = 1 + (urb->dev->maxchild / 8);
494 /* rh_timer protected by hcd_data_lock */
495 if (hcd->rh_timer.data || urb->transfer_buffer_length < len) {
496 dev_dbg (hcd->self.controller,
497 "not queuing rh status urb, stat %d\n",
502 init_timer (&hcd->rh_timer);
503 hcd->rh_timer.function = rh_report_status;
504 hcd->rh_timer.data = (unsigned long) urb;
505 /* USB 2.0 spec says 256msec; this is close enough */
506 hcd->rh_timer.expires = jiffies + HZ/4;
507 add_timer (&hcd->rh_timer);
508 urb->hcpriv = hcd; /* nonzero to indicate it's queued */
514 static void rh_report_status (unsigned long ptr)
521 urb = (struct urb *) ptr;
522 local_irq_save (flags);
523 spin_lock (&urb->lock);
525 /* do nothing if the urb's been unlinked */
527 || urb->status != -EINPROGRESS
528 || (hcd = urb->dev->bus->hcpriv) == NULL) {
529 spin_unlock (&urb->lock);
530 local_irq_restore (flags);
534 /* complete the status urb, or retrigger the timer */
535 spin_lock (&hcd_data_lock);
536 if (urb->dev->state == USB_STATE_CONFIGURED) {
537 length = hcd->driver->hub_status_data (
538 hcd, urb->transfer_buffer);
540 hcd->rh_timer.data = 0;
541 urb->actual_length = length;
545 mod_timer (&hcd->rh_timer, jiffies + HZ/4);
547 spin_unlock (&hcd_data_lock);
548 spin_unlock (&urb->lock);
550 /* local irqs are always blocked in completions */
552 usb_hcd_giveback_urb (hcd, urb, NULL);
553 local_irq_restore (flags);
556 /*-------------------------------------------------------------------------*/
558 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
560 if (usb_pipeint (urb->pipe)) {
564 spin_lock_irqsave (&hcd_data_lock, flags);
565 retval = rh_status_urb (hcd, urb);
566 spin_unlock_irqrestore (&hcd_data_lock, flags);
569 if (usb_pipecontrol (urb->pipe))
570 return rh_call_control (hcd, urb);
575 /*-------------------------------------------------------------------------*/
577 static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
581 /* note: always a synchronous unlink */
582 if ((unsigned long) urb == hcd->rh_timer.data) {
583 del_timer_sync (&hcd->rh_timer);
584 hcd->rh_timer.data = 0;
586 local_irq_save (flags);
588 usb_hcd_giveback_urb (hcd, urb, NULL);
589 local_irq_restore (flags);
591 } else if (usb_pipeendpoint(urb->pipe) == 0) {
592 spin_lock_irq(&urb->lock); /* from usb_kill_urb */
594 spin_unlock_irq(&urb->lock);
596 wait_event(usb_kill_urb_queue,
597 atomic_read(&urb->use_count) == 0);
599 spin_lock_irq(&urb->lock);
601 spin_unlock_irq(&urb->lock);
608 /*-------------------------------------------------------------------------*/
610 /* exported only within usbcore */
611 struct usb_bus *usb_bus_get (struct usb_bus *bus)
613 struct class_device *tmp;
618 tmp = class_device_get(&bus->class_dev);
620 return to_usb_bus(tmp);
625 /* exported only within usbcore */
626 void usb_bus_put (struct usb_bus *bus)
629 class_device_put(&bus->class_dev);
632 /*-------------------------------------------------------------------------*/
634 static void usb_host_release(struct class_device *class_dev)
636 struct usb_bus *bus = to_usb_bus(class_dev);
642 static struct class usb_host_class = {
644 .release = &usb_host_release,
647 int usb_host_init(void)
649 return class_register(&usb_host_class);
652 void usb_host_cleanup(void)
654 class_unregister(&usb_host_class);
658 * usb_bus_init - shared initialization code
659 * @bus: the bus structure being initialized
661 * This code is used to initialize a usb_bus structure, memory for which is
662 * separately managed.
664 void usb_bus_init (struct usb_bus *bus)
666 memset (&bus->devmap, 0, sizeof(struct usb_devmap));
668 bus->devnum_next = 1;
670 bus->root_hub = NULL;
673 bus->bandwidth_allocated = 0;
674 bus->bandwidth_int_reqs = 0;
675 bus->bandwidth_isoc_reqs = 0;
677 INIT_LIST_HEAD (&bus->bus_list);
679 class_device_initialize(&bus->class_dev);
680 bus->class_dev.class = &usb_host_class;
682 EXPORT_SYMBOL (usb_bus_init);
685 * usb_alloc_bus - creates a new USB host controller structure
686 * @op: pointer to a struct usb_operations that this bus structure should use
687 * Context: !in_interrupt()
689 * Creates a USB host controller bus structure with the specified
690 * usb_operations and initializes all the necessary internal objects.
692 * If no memory is available, NULL is returned.
694 * The caller should call usb_put_bus() when it is finished with the structure.
696 struct usb_bus *usb_alloc_bus (struct usb_operations *op)
700 bus = kmalloc (sizeof *bus, GFP_KERNEL);
703 memset(bus, 0, sizeof(struct usb_bus));
708 EXPORT_SYMBOL (usb_alloc_bus);
710 /*-------------------------------------------------------------------------*/
713 * usb_register_bus - registers the USB host controller with the usb core
714 * @bus: pointer to the bus to register
715 * Context: !in_interrupt()
717 * Assigns a bus number, and links the controller into usbcore data
718 * structures so that it can be seen by scanning the bus list.
720 int usb_register_bus(struct usb_bus *bus)
725 down (&usb_bus_list_lock);
726 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
727 if (busnum < USB_MAXBUS) {
728 set_bit (busnum, busmap.busmap);
729 bus->busnum = busnum;
731 printk (KERN_ERR "%s: too many buses\n", usbcore_name);
732 up(&usb_bus_list_lock);
736 snprintf(bus->class_dev.class_id, BUS_ID_SIZE, "usb%d", busnum);
737 bus->class_dev.dev = bus->controller;
738 retval = class_device_add(&bus->class_dev);
740 clear_bit(busnum, busmap.busmap);
741 up(&usb_bus_list_lock);
745 /* Add it to the local list of buses */
746 list_add (&bus->bus_list, &usb_bus_list);
747 up (&usb_bus_list_lock);
751 dev_info (bus->controller, "new USB bus registered, assigned bus number %d\n", bus->busnum);
754 EXPORT_SYMBOL (usb_register_bus);
757 * usb_deregister_bus - deregisters the USB host controller
758 * @bus: pointer to the bus to deregister
759 * Context: !in_interrupt()
761 * Recycles the bus number, and unlinks the controller from usbcore data
762 * structures so that it won't be seen by scanning the bus list.
764 void usb_deregister_bus (struct usb_bus *bus)
766 dev_info (bus->controller, "USB bus %d deregistered\n", bus->busnum);
769 * NOTE: make sure that all the devices are removed by the
770 * controller code, as well as having it call this when cleaning
773 down (&usb_bus_list_lock);
774 list_del (&bus->bus_list);
775 up (&usb_bus_list_lock);
777 usbfs_remove_bus (bus);
779 clear_bit (bus->busnum, busmap.busmap);
781 class_device_unregister(&bus->class_dev);
783 EXPORT_SYMBOL (usb_deregister_bus);
786 * usb_register_root_hub - called by HCD to register its root hub
787 * @usb_dev: the usb root hub device to be registered.
788 * @parent_dev: the parent device of this root hub.
790 * The USB host controller calls this function to register the root hub
791 * properly with the USB subsystem. It sets up the device properly in
792 * the device tree and stores the root_hub pointer in the bus structure,
793 * then calls usb_new_device() to register the usb device. It also
794 * assigns the root hub's USB address (always 1).
796 int usb_register_root_hub (struct usb_device *usb_dev, struct device *parent_dev)
798 const int devnum = 1;
801 usb_dev->devnum = devnum;
802 usb_dev->bus->devnum_next = devnum + 1;
803 memset (&usb_dev->bus->devmap.devicemap, 0,
804 sizeof usb_dev->bus->devmap.devicemap);
805 set_bit (devnum, usb_dev->bus->devmap.devicemap);
806 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
808 down (&usb_bus_list_lock);
809 usb_dev->bus->root_hub = usb_dev;
811 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
812 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
813 if (retval != sizeof usb_dev->descriptor) {
814 usb_dev->bus->root_hub = NULL;
815 up (&usb_bus_list_lock);
816 dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
817 usb_dev->dev.bus_id, retval);
818 return (retval < 0) ? retval : -EMSGSIZE;
821 usb_lock_device (usb_dev);
822 retval = usb_new_device (usb_dev);
823 usb_unlock_device (usb_dev);
825 usb_dev->bus->root_hub = NULL;
826 dev_err (parent_dev, "can't register root hub for %s, %d\n",
827 usb_dev->dev.bus_id, retval);
829 up (&usb_bus_list_lock);
832 EXPORT_SYMBOL (usb_register_root_hub);
835 /*-------------------------------------------------------------------------*/
838 * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
839 * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
840 * @is_input: true iff the transaction sends data to the host
841 * @isoc: true for isochronous transactions, false for interrupt ones
842 * @bytecount: how many bytes in the transaction.
844 * Returns approximate bus time in nanoseconds for a periodic transaction.
845 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
846 * scheduled in software, this function is only used for such scheduling.
848 long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
853 case USB_SPEED_LOW: /* INTR only */
855 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L;
856 return (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
858 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L;
859 return (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
861 case USB_SPEED_FULL: /* ISOC or INTR */
863 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
864 return (((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp);
866 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
867 return (9107L + BW_HOST_DELAY + tmp);
869 case USB_SPEED_HIGH: /* ISOC or INTR */
870 // FIXME adjust for input vs output
872 tmp = HS_USECS (bytecount);
874 tmp = HS_USECS_ISO (bytecount);
877 pr_debug ("%s: bogus device speed!\n", usbcore_name);
881 EXPORT_SYMBOL (usb_calc_bus_time);
884 * usb_check_bandwidth():
886 * old_alloc is from host_controller->bandwidth_allocated in microseconds;
887 * bustime is from calc_bus_time(), but converted to microseconds.
889 * returns <bustime in us> if successful,
890 * or -ENOSPC if bandwidth request fails.
893 * This initial implementation does not use Endpoint.bInterval
894 * in managing bandwidth allocation.
895 * It probably needs to be expanded to use Endpoint.bInterval.
896 * This can be done as a later enhancement (correction).
898 * This will also probably require some kind of
899 * frame allocation tracking...meaning, for example,
900 * that if multiple drivers request interrupts every 10 USB frames,
901 * they don't all have to be allocated at
902 * frame numbers N, N+10, N+20, etc. Some of them could be at
903 * N+11, N+21, N+31, etc., and others at
904 * N+12, N+22, N+32, etc.
906 * Similarly for isochronous transfers...
908 * Individual HCDs can schedule more directly ... this logic
909 * is not correct for high speed transfers.
911 int usb_check_bandwidth (struct usb_device *dev, struct urb *urb)
913 unsigned int pipe = urb->pipe;
915 int is_in = usb_pipein (pipe);
916 int is_iso = usb_pipeisoc (pipe);
917 int old_alloc = dev->bus->bandwidth_allocated;
921 bustime = NS_TO_US (usb_calc_bus_time (dev->speed, is_in, is_iso,
922 usb_maxpacket (dev, pipe, !is_in)));
924 bustime /= urb->number_of_packets;
926 new_alloc = old_alloc + (int) bustime;
927 if (new_alloc > FRAME_TIME_MAX_USECS_ALLOC) {
930 #ifdef CONFIG_USB_BANDWIDTH
935 dev_dbg (&dev->dev, "usb_check_bandwidth %sFAILED: %d + %ld = %d usec\n",
936 mode, old_alloc, bustime, new_alloc);
938 #ifdef CONFIG_USB_BANDWIDTH
939 bustime = -ENOSPC; /* report error */
945 EXPORT_SYMBOL (usb_check_bandwidth);
949 * usb_claim_bandwidth - records bandwidth for a periodic transfer
950 * @dev: source/target of request
951 * @urb: request (urb->dev == dev)
952 * @bustime: bandwidth consumed, in (average) microseconds per frame
953 * @isoc: true iff the request is isochronous
955 * Bus bandwidth reservations are recorded purely for diagnostic purposes.
956 * HCDs are expected not to overcommit periodic bandwidth, and to record such
957 * reservations whenever endpoints are added to the periodic schedule.
959 * FIXME averaging per-frame is suboptimal. Better to sum over the HCD's
960 * entire periodic schedule ... 32 frames for OHCI, 1024 for UHCI, settable
961 * for EHCI (256/512/1024 frames, default 1024) and have the bus expose how
962 * large its periodic schedule is.
964 void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb, int bustime, int isoc)
966 dev->bus->bandwidth_allocated += bustime;
968 dev->bus->bandwidth_isoc_reqs++;
970 dev->bus->bandwidth_int_reqs++;
971 urb->bandwidth = bustime;
973 #ifdef USB_BANDWIDTH_MESSAGES
974 dev_dbg (&dev->dev, "bandwidth alloc increased by %d (%s) to %d for %d requesters\n",
976 isoc ? "ISOC" : "INTR",
977 dev->bus->bandwidth_allocated,
978 dev->bus->bandwidth_int_reqs + dev->bus->bandwidth_isoc_reqs);
981 EXPORT_SYMBOL (usb_claim_bandwidth);
985 * usb_release_bandwidth - reverses effect of usb_claim_bandwidth()
986 * @dev: source/target of request
987 * @urb: request (urb->dev == dev)
988 * @isoc: true iff the request is isochronous
990 * This records that previously allocated bandwidth has been released.
991 * Bandwidth is released when endpoints are removed from the host controller's
994 void usb_release_bandwidth (struct usb_device *dev, struct urb *urb, int isoc)
996 dev->bus->bandwidth_allocated -= urb->bandwidth;
998 dev->bus->bandwidth_isoc_reqs--;
1000 dev->bus->bandwidth_int_reqs--;
1002 #ifdef USB_BANDWIDTH_MESSAGES
1003 dev_dbg (&dev->dev, "bandwidth alloc reduced by %d (%s) to %d for %d requesters\n",
1005 isoc ? "ISOC" : "INTR",
1006 dev->bus->bandwidth_allocated,
1007 dev->bus->bandwidth_int_reqs + dev->bus->bandwidth_isoc_reqs);
1011 EXPORT_SYMBOL (usb_release_bandwidth);
1014 /*-------------------------------------------------------------------------*/
1017 * Generic HC operations.
1020 /*-------------------------------------------------------------------------*/
1022 static void urb_unlink (struct urb *urb)
1024 unsigned long flags;
1026 /* Release any periodic transfer bandwidth */
1028 usb_release_bandwidth (urb->dev, urb,
1029 usb_pipeisoc (urb->pipe));
1031 /* clear all state linking urb to this dev (and hcd) */
1033 spin_lock_irqsave (&hcd_data_lock, flags);
1034 list_del_init (&urb->urb_list);
1035 spin_unlock_irqrestore (&hcd_data_lock, flags);
1036 usb_put_dev (urb->dev);
1040 /* may be called in any context with a valid urb->dev usecount
1041 * caller surrenders "ownership" of urb
1042 * expects usb_submit_urb() to have sanity checked and conditioned all
1045 static int hcd_submit_urb (struct urb *urb, int mem_flags)
1048 struct usb_hcd *hcd = urb->dev->bus->hcpriv;
1049 struct usb_host_endpoint *ep;
1050 unsigned long flags;
1052 ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out)
1053 [usb_pipeendpoint(urb->pipe)];
1058 * FIXME: make urb timeouts be generic, keeping the HCD cores
1059 * as simple as possible.
1062 // NOTE: a generic device/urb monitoring hook would go here.
1063 // hcd_monitor_hook(MONITOR_URB_SUBMIT, urb)
1064 // It would catch submission paths for all urbs.
1067 * Atomically queue the urb, first to our records, then to the HCD.
1068 * Access to urb->status is controlled by urb->lock ... changes on
1069 * i/o completion (normal or fault) or unlinking.
1072 // FIXME: verify that quiescing hc works right (RH cleans up)
1074 spin_lock_irqsave (&hcd_data_lock, flags);
1075 if (unlikely (urb->reject))
1077 else switch (hcd->state) {
1078 case USB_STATE_RUNNING:
1079 case USB_STATE_RESUMING:
1080 usb_get_dev (urb->dev);
1081 list_add_tail (&urb->urb_list, &ep->urb_list);
1085 status = -ESHUTDOWN;
1088 spin_unlock_irqrestore (&hcd_data_lock, flags);
1090 INIT_LIST_HEAD (&urb->urb_list);
1094 /* increment urb's reference count as part of giving it to the HCD
1095 * (which now controls it). HCD guarantees that it either returns
1096 * an error or calls giveback(), but not both.
1098 urb = usb_get_urb (urb);
1099 atomic_inc (&urb->use_count);
1101 if (urb->dev == hcd->self.root_hub) {
1102 /* NOTE: requirement on hub callers (usbfs and the hub
1103 * driver, for now) that URBs' urb->transfer_buffer be
1104 * valid and usb_buffer_{sync,unmap}() not be needed, since
1105 * they could clobber root hub response data.
1107 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP
1108 | URB_NO_SETUP_DMA_MAP);
1109 status = rh_urb_enqueue (hcd, urb);
1113 /* lower level hcd code should use *_dma exclusively,
1114 * unless it uses pio or talks to another transport.
1116 if (hcd->self.controller->dma_mask) {
1117 if (usb_pipecontrol (urb->pipe)
1118 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1119 urb->setup_dma = dma_map_single (
1120 hcd->self.controller,
1122 sizeof (struct usb_ctrlrequest),
1124 if (urb->transfer_buffer_length != 0
1125 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
1126 urb->transfer_dma = dma_map_single (
1127 hcd->self.controller,
1128 urb->transfer_buffer,
1129 urb->transfer_buffer_length,
1130 usb_pipein (urb->pipe)
1135 status = hcd->driver->urb_enqueue (hcd, ep, urb, mem_flags);
1137 if (unlikely (status)) {
1139 atomic_dec (&urb->use_count);
1141 wake_up (&usb_kill_urb_queue);
1147 /*-------------------------------------------------------------------------*/
1149 /* called in any context */
1150 static int hcd_get_frame_number (struct usb_device *udev)
1152 struct usb_hcd *hcd = (struct usb_hcd *)udev->bus->hcpriv;
1153 if (!HCD_IS_RUNNING (hcd->state))
1155 return hcd->driver->get_frame_number (hcd);
1158 /*-------------------------------------------------------------------------*/
1160 /* this makes the hcd giveback() the urb more quickly, by kicking it
1161 * off hardware queues (which may take a while) and returning it as
1162 * soon as practical. we've already set up the urb's return status,
1163 * but we can't know if the callback completed already.
1166 unlink1 (struct usb_hcd *hcd, struct urb *urb)
1170 if (urb->dev == hcd->self.root_hub)
1171 value = usb_rh_urb_dequeue (hcd, urb);
1174 /* The only reason an HCD might fail this call is if
1175 * it has not yet fully queued the urb to begin with.
1176 * Such failures should be harmless. */
1177 value = hcd->driver->urb_dequeue (hcd, urb);
1181 dev_dbg (hcd->self.controller, "dequeue %p --> %d\n",
1187 * called in any context
1189 * caller guarantees urb won't be recycled till both unlink()
1190 * and the urb's completion function return
1192 static int hcd_unlink_urb (struct urb *urb, int status)
1194 struct usb_host_endpoint *ep;
1195 struct usb_hcd *hcd = NULL;
1196 struct device *sys = NULL;
1197 unsigned long flags;
1198 struct list_head *tmp;
1203 if (!urb->dev || !urb->dev->bus)
1205 ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out)
1206 [usb_pipeendpoint(urb->pipe)];
1211 * we contend for urb->status with the hcd core,
1212 * which changes it while returning the urb.
1214 * Caller guaranteed that the urb pointer hasn't been freed, and
1215 * that it was submitted. But as a rule it can't know whether or
1216 * not it's already been unlinked ... so we respect the reversed
1217 * lock sequence needed for the usb_hcd_giveback_urb() code paths
1218 * (urb lock, then hcd_data_lock) in case some other CPU is now
1221 spin_lock_irqsave (&urb->lock, flags);
1222 spin_lock (&hcd_data_lock);
1224 sys = &urb->dev->dev;
1225 hcd = urb->dev->bus->hcpriv;
1231 /* running ~= hc unlink handshake works (irq, timer, etc)
1232 * halted ~= no unlink handshake is needed
1233 * suspended, resuming == should never happen
1235 WARN_ON (!HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_HALT);
1237 /* insist the urb is still queued */
1238 list_for_each(tmp, &ep->urb_list) {
1239 if (tmp == &urb->urb_list)
1242 if (tmp != &urb->urb_list) {
1247 /* Any status except -EINPROGRESS means something already started to
1248 * unlink this URB from the hardware. So there's no more work to do.
1250 if (urb->status != -EINPROGRESS) {
1255 /* IRQ setup can easily be broken so that USB controllers
1256 * never get completion IRQs ... maybe even the ones we need to
1257 * finish unlinking the initial failed usb_set_address()
1258 * or device descriptor fetch.
1260 if (!hcd->saw_irq && hcd->self.root_hub != urb->dev) {
1261 dev_warn (hcd->self.controller, "Unlink after no-IRQ? "
1262 "Controller is probably using the wrong IRQ."
1267 urb->status = status;
1269 spin_unlock (&hcd_data_lock);
1270 spin_unlock_irqrestore (&urb->lock, flags);
1272 retval = unlink1 (hcd, urb);
1274 retval = -EINPROGRESS;
1278 spin_unlock (&hcd_data_lock);
1279 spin_unlock_irqrestore (&urb->lock, flags);
1280 if (retval != -EIDRM && sys && sys->driver)
1281 dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval);
1285 /*-------------------------------------------------------------------------*/
1287 /* disables the endpoint: cancels any pending urbs, then synchronizes with
1288 * the hcd to make sure all endpoint state is gone from hardware. use for
1289 * set_configuration, set_interface, driver removal, physical disconnect.
1291 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1292 * type, maxpacket size, toggle, halt status, and scheduling.
1295 hcd_endpoint_disable (struct usb_device *udev, struct usb_host_endpoint *ep)
1297 struct usb_hcd *hcd;
1300 hcd = udev->bus->hcpriv;
1302 WARN_ON (!HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_HALT);
1304 local_irq_disable ();
1306 /* FIXME move most of this into message.c as part of its
1307 * endpoint disable logic
1310 /* ep is already gone from udev->ep_{in,out}[]; no more submits */
1312 spin_lock (&hcd_data_lock);
1313 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1316 /* another cpu may be in hcd, spinning on hcd_data_lock
1317 * to giveback() this urb. the races here should be
1318 * small, but a full fix needs a new "can't submit"
1320 * FIXME urb->reject should allow that...
1322 if (urb->status != -EINPROGRESS)
1325 spin_unlock (&hcd_data_lock);
1327 spin_lock (&urb->lock);
1329 if (tmp == -EINPROGRESS)
1330 urb->status = -ESHUTDOWN;
1331 spin_unlock (&urb->lock);
1333 /* kick hcd unless it's already returning this */
1334 if (tmp == -EINPROGRESS) {
1337 dev_dbg (hcd->self.controller,
1338 "shutdown urb %p pipe %08x ep%d%s%s\n",
1339 urb, tmp, usb_pipeendpoint (tmp),
1340 (tmp & USB_DIR_IN) ? "in" : "out",
1342 switch (usb_pipetype (tmp)) { \
1343 case PIPE_CONTROL: s = ""; break; \
1344 case PIPE_BULK: s = "-bulk"; break; \
1345 case PIPE_INTERRUPT: s = "-intr"; break; \
1346 default: s = "-iso"; break; \
1351 /* list contents may have changed */
1354 spin_unlock (&hcd_data_lock);
1355 local_irq_enable ();
1357 /* synchronize with the hardware, so old configuration state
1358 * clears out immediately (and will be freed).
1361 if (hcd->driver->endpoint_disable)
1362 hcd->driver->endpoint_disable (hcd, ep);
1365 /*-------------------------------------------------------------------------*/
1367 #ifdef CONFIG_USB_SUSPEND
1369 static int hcd_hub_suspend (struct usb_bus *bus)
1371 struct usb_hcd *hcd;
1373 hcd = container_of (bus, struct usb_hcd, self);
1374 if (hcd->driver->hub_suspend)
1375 return hcd->driver->hub_suspend (hcd);
1379 static int hcd_hub_resume (struct usb_bus *bus)
1381 struct usb_hcd *hcd;
1383 hcd = container_of (bus, struct usb_hcd, self);
1384 if (hcd->driver->hub_resume)
1385 return hcd->driver->hub_resume (hcd);
1391 /*-------------------------------------------------------------------------*/
1393 #ifdef CONFIG_USB_OTG
1396 * usb_bus_start_enum - start immediate enumeration (for OTG)
1397 * @bus: the bus (must use hcd framework)
1398 * @port: 1-based number of port; usually bus->otg_port
1399 * Context: in_interrupt()
1401 * Starts enumeration, with an immediate reset followed later by
1402 * khubd identifying and possibly configuring the device.
1403 * This is needed by OTG controller drivers, where it helps meet
1404 * HNP protocol timing requirements for starting a port reset.
1406 int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
1408 struct usb_hcd *hcd;
1409 int status = -EOPNOTSUPP;
1411 /* NOTE: since HNP can't start by grabbing the bus's address0_sem,
1412 * boards with root hubs hooked up to internal devices (instead of
1413 * just the OTG port) may need more attention to resetting...
1415 hcd = container_of (bus, struct usb_hcd, self);
1416 if (port_num && hcd->driver->start_port_reset)
1417 status = hcd->driver->start_port_reset(hcd, port_num);
1419 /* run khubd shortly after (first) root port reset finishes;
1420 * it may issue others, until at least 50 msecs have passed.
1423 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10));
1426 EXPORT_SYMBOL (usb_bus_start_enum);
1430 /*-------------------------------------------------------------------------*/
1433 * usb_hcd_operations - adapts usb_bus framework to HCD framework (bus glue)
1435 static struct usb_operations usb_hcd_operations = {
1436 .get_frame_number = hcd_get_frame_number,
1437 .submit_urb = hcd_submit_urb,
1438 .unlink_urb = hcd_unlink_urb,
1439 .buffer_alloc = hcd_buffer_alloc,
1440 .buffer_free = hcd_buffer_free,
1441 .disable = hcd_endpoint_disable,
1442 #ifdef CONFIG_USB_SUSPEND
1443 .hub_suspend = hcd_hub_suspend,
1444 .hub_resume = hcd_hub_resume,
1448 /*-------------------------------------------------------------------------*/
1451 * usb_hcd_giveback_urb - return URB from HCD to device driver
1452 * @hcd: host controller returning the URB
1453 * @urb: urb being returned to the USB device driver.
1454 * @regs: pt_regs, passed down to the URB completion handler
1455 * Context: in_interrupt()
1457 * This hands the URB from HCD to its USB device driver, using its
1458 * completion function. The HCD has freed all per-urb resources
1459 * (and is done using urb->hcpriv). It also released all HCD locks;
1460 * the device driver won't cause problems if it frees, modifies,
1461 * or resubmits this URB.
1463 void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs)
1467 // NOTE: a generic device/urb monitoring hook would go here.
1468 // hcd_monitor_hook(MONITOR_URB_FINISH, urb, dev)
1469 // It would catch exit/unlink paths for all urbs.
1471 /* lower level hcd code should use *_dma exclusively */
1472 if (hcd->self.controller->dma_mask) {
1473 if (usb_pipecontrol (urb->pipe)
1474 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1475 dma_unmap_single (hcd->self.controller, urb->setup_dma,
1476 sizeof (struct usb_ctrlrequest),
1478 if (urb->transfer_buffer_length != 0
1479 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
1480 dma_unmap_single (hcd->self.controller,
1482 urb->transfer_buffer_length,
1483 usb_pipein (urb->pipe)
1488 /* pass ownership to the completion handler */
1489 urb->complete (urb, regs);
1490 atomic_dec (&urb->use_count);
1491 if (unlikely (urb->reject))
1492 wake_up (&usb_kill_urb_queue);
1495 EXPORT_SYMBOL (usb_hcd_giveback_urb);
1497 /*-------------------------------------------------------------------------*/
1500 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
1501 * @irq: the IRQ being raised
1502 * @__hcd: pointer to the HCD whose IRQ is beinng signaled
1503 * @r: saved hardware registers
1505 * When registering a USB bus through the HCD framework code, use this
1506 * to handle interrupts. The PCI glue layer does so automatically; only
1507 * bus glue for non-PCI system busses will need to use this.
1509 irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs * r)
1511 struct usb_hcd *hcd = __hcd;
1512 int start = hcd->state;
1514 if (start == USB_STATE_HALT)
1516 if (hcd->driver->irq (hcd, r) == IRQ_NONE)
1520 if (hcd->state != start && hcd->state == USB_STATE_HALT)
1524 EXPORT_SYMBOL (usb_hcd_irq);
1526 /*-------------------------------------------------------------------------*/
1529 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
1530 * @hcd: pointer to the HCD representing the controller
1532 * This is called by bus glue to report a USB host controller that died
1533 * while operations may still have been pending. It's called automatically
1534 * by the PCI glue, so only glue for non-PCI busses should need to call it.
1536 void usb_hc_died (struct usb_hcd *hcd)
1538 dev_err (hcd->self.controller, "HC died; cleaning up\n");
1540 /* make khubd clean up old urbs and devices */
1541 usb_set_device_state(hcd->self.root_hub, USB_STATE_NOTATTACHED);
1542 mod_timer(&hcd->rh_timer, jiffies);
1545 /*-------------------------------------------------------------------------*/
1547 static void hcd_release (struct usb_bus *bus)
1549 struct usb_hcd *hcd;
1551 hcd = container_of(bus, struct usb_hcd, self);
1556 * usb_create_hcd - create and initialize an HCD structure
1557 * @driver: HC driver that will use this hcd
1558 * Context: !in_interrupt()
1560 * Allocate a struct usb_hcd, with extra space at the end for the
1561 * HC driver's private data. Initialize the generic members of the
1564 * If memory is unavailable, returns NULL.
1566 struct usb_hcd *usb_create_hcd (const struct hc_driver *driver)
1568 struct usb_hcd *hcd;
1570 hcd = kcalloc(1, sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
1574 usb_bus_init(&hcd->self);
1575 hcd->self.op = &usb_hcd_operations;
1576 hcd->self.hcpriv = hcd;
1577 hcd->self.release = &hcd_release;
1579 init_timer(&hcd->rh_timer);
1581 hcd->driver = driver;
1582 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
1583 "USB Host Controller";
1584 hcd->state = USB_STATE_HALT;
1588 EXPORT_SYMBOL (usb_create_hcd);
1590 void usb_put_hcd (struct usb_hcd *hcd)
1592 usb_bus_put(&hcd->self);
1594 EXPORT_SYMBOL (usb_put_hcd);