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.
26 #include <linux/config.h>
28 #ifdef CONFIG_USB_DEBUG
32 #include <linux/module.h>
33 #include <linux/version.h>
34 #include <linux/kernel.h>
35 #include <linux/slab.h>
36 #include <linux/completion.h>
37 #include <linux/uts.h> /* for UTS_SYSNAME */
38 #include <linux/pci.h> /* for hcd->pdev and dma addressing */
39 #include <linux/dma-mapping.h>
40 #include <asm/byteorder.h>
42 #include <linux/usb.h>
44 #include "../usb_wrapper.h"
50 // #define USB_BANDWIDTH_MESSAGES
52 /*-------------------------------------------------------------------------*/
55 * USB Host Controller Driver framework
57 * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing
58 * HCD-specific behaviors/bugs.
60 * This does error checks, tracks devices and urbs, and delegates to a
61 * "hc_driver" only for code (and data) that really needs to know about
62 * hardware differences. That includes root hub registers, i/o queues,
63 * and so on ... but as little else as possible.
65 * Shared code includes most of the "root hub" code (these are emulated,
66 * though each HC's hardware works differently) and PCI glue, plus request
67 * tracking overhead. The HCD code should only block on spinlocks or on
68 * hardware handshaking; blocking on software events (such as other kernel
69 * threads releasing resources, or completing actions) is all generic.
71 * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
72 * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
73 * only by the hub driver ... and that neither should be seen or used by
74 * usb client device drivers.
76 * Contributors of ideas or unattributed patches include: David Brownell,
77 * Roman Weissgaerber, Rory Bolt, Greg Kroah-Hartman, ...
80 * 2002-02-21 Pull in most of the usb_bus support from usb.c; some
81 * associated cleanup. "usb_hcd" still != "usb_bus".
82 * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
85 /*-------------------------------------------------------------------------*/
87 /* host controllers we manage */
88 LIST_HEAD (usb_bus_list
);
89 EXPORT_SYMBOL_GPL (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 */
100 EXPORT_SYMBOL_GPL (usb_bus_list_lock
);
102 /* used when updating hcd data */
103 static spinlock_t hcd_data_lock
;// = SPIN_LOCK_UNLOCKED;
105 /*-------------------------------------------------------------------------*/
108 * Sharable chunks of root hub code.
111 /*-------------------------------------------------------------------------*/
113 #define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff)
114 #define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff)
116 /* usb 2.0 root hub device descriptor */
117 static const u8 usb2_rh_dev_descriptor
[18] = {
118 0x12, /* __u8 bLength; */
119 0x01, /* __u8 bDescriptorType; Device */
120 0x00, 0x02, /* __u16 bcdUSB; v2.0 */
122 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
123 0x00, /* __u8 bDeviceSubClass; */
124 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/
125 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
127 0x00, 0x00, /* __u16 idVendor; */
128 0x00, 0x00, /* __u16 idProduct; */
129 KERNEL_VER
, KERNEL_REL
, /* __u16 bcdDevice */
131 0x03, /* __u8 iManufacturer; */
132 0x02, /* __u8 iProduct; */
133 0x01, /* __u8 iSerialNumber; */
134 0x01 /* __u8 bNumConfigurations; */
137 /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
139 /* usb 1.1 root hub device descriptor */
140 static const u8 usb11_rh_dev_descriptor
[18] = {
141 0x12, /* __u8 bLength; */
142 0x01, /* __u8 bDescriptorType; Device */
143 0x10, 0x01, /* __u16 bcdUSB; v1.1 */
145 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
146 0x00, /* __u8 bDeviceSubClass; */
147 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */
148 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
150 0x00, 0x00, /* __u16 idVendor; */
151 0x00, 0x00, /* __u16 idProduct; */
152 KERNEL_VER
, KERNEL_REL
, /* __u16 bcdDevice */
154 0x03, /* __u8 iManufacturer; */
155 0x02, /* __u8 iProduct; */
156 0x01, /* __u8 iSerialNumber; */
157 0x01 /* __u8 bNumConfigurations; */
161 /*-------------------------------------------------------------------------*/
163 /* Configuration descriptors for our root hubs */
165 static const u8 fs_rh_config_descriptor
[] = {
167 /* one configuration */
168 0x09, /* __u8 bLength; */
169 0x02, /* __u8 bDescriptorType; Configuration */
170 0x19, 0x00, /* __u16 wTotalLength; */
171 0x01, /* __u8 bNumInterfaces; (1) */
172 0x01, /* __u8 bConfigurationValue; */
173 0x00, /* __u8 iConfiguration; */
174 0x40, /* __u8 bmAttributes;
179 0x00, /* __u8 MaxPower; */
182 * USB 2.0, single TT organization (mandatory):
183 * one interface, protocol 0
185 * USB 2.0, multiple TT organization (optional):
186 * two interfaces, protocols 1 (like single TT)
187 * and 2 (multiple TT mode) ... config is
193 0x09, /* __u8 if_bLength; */
194 0x04, /* __u8 if_bDescriptorType; Interface */
195 0x00, /* __u8 if_bInterfaceNumber; */
196 0x00, /* __u8 if_bAlternateSetting; */
197 0x01, /* __u8 if_bNumEndpoints; */
198 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
199 0x00, /* __u8 if_bInterfaceSubClass; */
200 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
201 0x00, /* __u8 if_iInterface; */
203 /* one endpoint (status change endpoint) */
204 0x07, /* __u8 ep_bLength; */
205 0x05, /* __u8 ep_bDescriptorType; Endpoint */
206 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
207 0x03, /* __u8 ep_bmAttributes; Interrupt */
208 0x02, 0x00, /* __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
209 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
212 static const u8 hs_rh_config_descriptor
[] = {
214 /* one configuration */
215 0x09, /* __u8 bLength; */
216 0x02, /* __u8 bDescriptorType; Configuration */
217 0x19, 0x00, /* __u16 wTotalLength; */
218 0x01, /* __u8 bNumInterfaces; (1) */
219 0x01, /* __u8 bConfigurationValue; */
220 0x00, /* __u8 iConfiguration; */
221 0x40, /* __u8 bmAttributes;
226 0x00, /* __u8 MaxPower; */
229 * USB 2.0, single TT organization (mandatory):
230 * one interface, protocol 0
232 * USB 2.0, multiple TT organization (optional):
233 * two interfaces, protocols 1 (like single TT)
234 * and 2 (multiple TT mode) ... config is
240 0x09, /* __u8 if_bLength; */
241 0x04, /* __u8 if_bDescriptorType; Interface */
242 0x00, /* __u8 if_bInterfaceNumber; */
243 0x00, /* __u8 if_bAlternateSetting; */
244 0x01, /* __u8 if_bNumEndpoints; */
245 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
246 0x00, /* __u8 if_bInterfaceSubClass; */
247 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
248 0x00, /* __u8 if_iInterface; */
250 /* one endpoint (status change endpoint) */
251 0x07, /* __u8 ep_bLength; */
252 0x05, /* __u8 ep_bDescriptorType; Endpoint */
253 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
254 0x03, /* __u8 ep_bmAttributes; Interrupt */
255 0x02, 0x00, /* __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
256 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
259 /*-------------------------------------------------------------------------*/
262 * helper routine for returning string descriptors in UTF-16LE
263 * input can actually be ISO-8859-1; ASCII is its 7-bit subset
265 static int ascii2utf (char *s
, u8
*utf
, int utfmax
)
269 for (retval
= 0; *s
&& utfmax
> 1; utfmax
-= 2, retval
+= 2) {
277 * rh_string - provides manufacturer, product and serial strings for root hub
278 * @id: the string ID number (1: serial number, 2: product, 3: vendor)
279 * @hcd: the host controller for this root hub
280 * @type: string describing our driver
281 * @data: return packet in UTF-16 LE
282 * @len: length of the return packet
284 * Produces either a manufacturer, product or serial number string for the
285 * virtual root hub device.
287 static int rh_string (
297 *data
++ = 4; *data
++ = 3; /* 4 bytes string data */
298 *data
++ = 0x09; *data
++ = 0x04; /* MSFT-speak for "en-us" */
302 } else if (id
== 1) {
303 strcpy (buf
, hcd
->self
.bus_name
);
305 // product description
306 } else if (id
== 2) {
307 strcpy (buf
, hcd
->product_desc
);
309 // id 3 == vendor description
310 } else if (id
== 3) {
311 sprintf (buf
, "%s %s %s", UTS_SYSNAME
, UTS_RELEASE
,
314 // unsupported IDs --> "protocol stall"
318 data
[0] = 2 * (strlen (buf
) + 1);
319 data
[1] = 3; /* type == string */
320 return 2 + ascii2utf (buf
, data
+ 2, len
- 2);
324 /* Root hub control transfers execute synchronously */
325 static int rh_call_control (struct usb_hcd
*hcd
, struct urb
*urb
)
327 struct usb_ctrlrequest
*cmd
= (struct usb_ctrlrequest
*) urb
->setup_packet
;
328 u16 typeReq
, wValue
, wIndex
, wLength
;
330 u8
*ubuf
= urb
->transfer_buffer
;
332 //unsigned long flags;
334 typeReq
= (cmd
->bRequestType
<< 8) | cmd
->bRequest
;
335 wValue
= le16_to_cpu (cmd
->wValue
);
336 wIndex
= le16_to_cpu (cmd
->wIndex
);
337 wLength
= le16_to_cpu (cmd
->wLength
);
339 if (wLength
> urb
->transfer_buffer_length
)
342 /* set up for success */
344 urb
->actual_length
= wLength
;
347 /* DEVICE REQUESTS */
349 case DeviceRequest
| USB_REQ_GET_STATUS
:
350 // DEVICE_REMOTE_WAKEUP
351 ubuf
[0] = 1; // selfpowered
354 case DeviceOutRequest
| USB_REQ_CLEAR_FEATURE
:
355 case DeviceOutRequest
| USB_REQ_SET_FEATURE
:
356 dev_dbg (hcd
->controller
, "no device features yet yet\n");
358 case DeviceRequest
| USB_REQ_GET_CONFIGURATION
:
361 case DeviceOutRequest
| USB_REQ_SET_CONFIGURATION
:
363 case DeviceRequest
| USB_REQ_GET_DESCRIPTOR
:
364 switch (wValue
& 0xff00) {
365 case USB_DT_DEVICE
<< 8:
366 if (hcd
->driver
->flags
& HCD_USB2
)
367 bufp
= usb2_rh_dev_descriptor
;
368 else if (hcd
->driver
->flags
& HCD_USB11
)
369 bufp
= usb11_rh_dev_descriptor
;
374 case USB_DT_CONFIG
<< 8:
375 if (hcd
->driver
->flags
& HCD_USB2
) {
376 bufp
= hs_rh_config_descriptor
;
377 len
= sizeof hs_rh_config_descriptor
;
379 bufp
= fs_rh_config_descriptor
;
380 len
= sizeof fs_rh_config_descriptor
;
383 case USB_DT_STRING
<< 8:
384 urb
->actual_length
= rh_string (
392 case DeviceRequest
| USB_REQ_GET_INTERFACE
:
395 case DeviceOutRequest
| USB_REQ_SET_INTERFACE
:
397 case DeviceOutRequest
| USB_REQ_SET_ADDRESS
:
398 // wValue == urb->dev->devaddr
399 dev_dbg (hcd
->controller
, "root hub device address %d\n",
403 /* INTERFACE REQUESTS (no defined feature/status flags) */
405 /* ENDPOINT REQUESTS */
407 case EndpointRequest
| USB_REQ_GET_STATUS
:
408 // ENDPOINT_HALT flag
412 case EndpointOutRequest
| USB_REQ_CLEAR_FEATURE
:
413 case EndpointOutRequest
| USB_REQ_SET_FEATURE
:
414 dev_dbg (hcd
->controller
, "no endpoint features yet\n");
417 /* CLASS REQUESTS (and errors) */
420 /* non-generic request */
421 urb
->status
= hcd
->driver
->hub_control (hcd
,
422 typeReq
, wValue
, wIndex
,
426 /* "protocol stall" on error */
427 urb
->status
= -EPIPE
;
428 dev_dbg (hcd
->controller
, "unsupported hub control message (maxchild %d)\n",
432 urb
->actual_length
= 0;
433 dev_dbg (hcd
->controller
, "CTRL: TypeReq=0x%x val=0x%x idx=0x%x len=%d ==> %d\n",
434 typeReq
, wValue
, wIndex
, wLength
, urb
->status
);
437 if (urb
->transfer_buffer_length
< len
)
438 len
= urb
->transfer_buffer_length
;
439 urb
->actual_length
= len
;
440 // always USB_DIR_IN, toward host
441 memcpy (ubuf
, bufp
, len
);
444 /* any errors get returned through the urb completion */
445 local_irq_save (flags
);
446 usb_hcd_giveback_urb (hcd
, urb
, NULL
);
447 local_irq_restore (flags
);
451 /*-------------------------------------------------------------------------*/
454 * Root Hub interrupt transfers are synthesized with a timer.
455 * Completions are called in_interrupt() but not in_irq().
458 static void rh_report_status (unsigned long ptr
);
460 static int rh_status_urb (struct usb_hcd
*hcd
, struct urb
*urb
)
462 int len
= 1 + (urb
->dev
->maxchild
/ 8);
464 /* rh_timer protected by hcd_data_lock */
465 if (hcd
->rh_timer
.data
466 || urb
->status
!= -EINPROGRESS
467 || urb
->transfer_buffer_length
< len
) {
468 dev_dbg (hcd
->controller
,
469 "not queuing rh status urb, stat %d\n",
474 init_timer (&hcd
->rh_timer
);
476 hcd
->rh_timer
.function
= rh_report_status
;
477 hcd
->rh_timer
.data
= (unsigned long) urb
;
478 /* USB 2.0 spec says 256msec; this is close enough */
479 hcd
->rh_timer
.expires
= HZ
/4;
480 add_timer (&hcd
->rh_timer
);
481 urb
->hcpriv
= hcd
; /* nonzero to indicate it's queued */
487 static void rh_report_status (unsigned long ptr
)
492 //unsigned long flags;
494 urb
= (struct urb
*) ptr
;
495 local_irq_save (flags
);
496 spin_lock (&urb
->lock
);
498 /* do nothing if the hc is gone or the urb's been unlinked */
500 || urb
->status
!= -EINPROGRESS
501 || (hcd
= urb
->dev
->bus
->hcpriv
) == 0
502 || !HCD_IS_RUNNING (hcd
->state
)) {
503 spin_unlock (&urb
->lock
);
504 local_irq_restore (flags
);
508 length
= hcd
->driver
->hub_status_data (hcd
, urb
->transfer_buffer
);
510 /* complete the status urb, or retrigger the timer */
511 spin_lock (&hcd_data_lock
);
513 hcd
->rh_timer
.data
= 0;
514 urb
->actual_length
= length
;
518 mod_timer (&hcd
->rh_timer
, HZ
/4);
519 spin_unlock (&hcd_data_lock
);
520 spin_unlock (&urb
->lock
);
522 /* local irqs are always blocked in completions */
524 usb_hcd_giveback_urb (hcd
, urb
, NULL
);
525 local_irq_restore (flags
);
528 /*-------------------------------------------------------------------------*/
530 static int rh_urb_enqueue (struct usb_hcd
*hcd
, struct urb
*urb
)
532 if (usb_pipeint (urb
->pipe
)) {
536 spin_lock_irqsave (&hcd_data_lock
, flags
);
537 retval
= rh_status_urb (hcd
, urb
);
538 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
541 if (usb_pipecontrol (urb
->pipe
))
542 return rh_call_control (hcd
, urb
);
547 /*-------------------------------------------------------------------------*/
549 void usb_rh_status_dequeue (struct usb_hcd
*hcd
, struct urb
*urb
)
551 //unsigned long flags;
553 /* note: always a synchronous unlink */
554 del_timer_sync (&hcd
->rh_timer
);
555 hcd
->rh_timer
.data
= 0;
557 local_irq_save (flags
);
559 usb_hcd_giveback_urb (hcd
, urb
, NULL
);
560 local_irq_restore (flags
);
563 /*-------------------------------------------------------------------------*/
565 /* exported only within usbcore */
566 void usb_bus_get (struct usb_bus
*bus
)
568 atomic_inc (&bus
->refcnt
);
571 /* exported only within usbcore */
572 void usb_bus_put (struct usb_bus
*bus
)
574 if (atomic_dec_and_test (&bus
->refcnt
))
578 /*-------------------------------------------------------------------------*/
581 * usb_bus_init - shared initialization code
582 * @bus: the bus structure being initialized
584 * This code is used to initialize a usb_bus structure, memory for which is
585 * separately managed.
587 void STDCALL
usb_bus_init (struct usb_bus
*bus
)
589 memset (&bus
->devmap
, 0, sizeof(struct usb_devmap
));
591 bus
->devnum_next
= 1;
593 bus
->root_hub
= NULL
;
596 bus
->bandwidth_allocated
= 0;
597 bus
->bandwidth_int_reqs
= 0;
598 bus
->bandwidth_isoc_reqs
= 0;
600 INIT_LIST_HEAD (&bus
->bus_list
);
602 atomic_set (&bus
->refcnt
, 1);
606 * usb_alloc_bus - creates a new USB host controller structure
607 * @op: pointer to a struct usb_operations that this bus structure should use
608 * Context: !in_interrupt()
610 * Creates a USB host controller bus structure with the specified
611 * usb_operations and initializes all the necessary internal objects.
613 * If no memory is available, NULL is returned.
615 * The caller should call usb_free_bus() when it is finished with the structure.
617 struct usb_bus STDCALL
*usb_alloc_bus (struct usb_operations
*op
)
621 bus
= kmalloc (sizeof *bus
, GFP_KERNEL
);
630 * usb_free_bus - frees the memory used by a bus structure
631 * @bus: pointer to the bus to free
633 * To be invoked by a HCD, only as the last step of decoupling from
634 * hardware. It is an error to call this if the reference count is
635 * anything but one. That would indicate that some system component
636 * did not correctly shut down, and thought the hardware was still
639 void STDCALL
usb_free_bus (struct usb_bus
*bus
)
643 if (atomic_read (&bus
->refcnt
) != 1)
644 err ("usb_free_bus #%d, count != 1", bus
->busnum
);
648 /*-------------------------------------------------------------------------*/
651 * usb_register_bus - registers the USB host controller with the usb core
652 * @bus: pointer to the bus to register
653 * Context: !in_interrupt()
655 * Assigns a bus number, and links the controller into usbcore data
656 * structures so that it can be seen by scanning the bus list.
658 void STDCALL
usb_register_bus(struct usb_bus
*bus
)
662 down (&usb_bus_list_lock
);
663 busnum
= find_next_zero_bit (busmap
.busmap
, USB_MAXBUS
, 1);
664 if (busnum
< USB_MAXBUS
) {
665 set_bit (busnum
, busmap
.busmap
);
666 bus
->busnum
= busnum
;
668 warn ("too many buses");
672 /* Add it to the list of buses */
673 list_add (&bus
->bus_list
, &usb_bus_list
);
674 up (&usb_bus_list_lock
);
678 dev_info (bus
->controller
, "new USB bus registered, assigned bus number %d\n", bus
->busnum
);
682 * usb_deregister_bus - deregisters the USB host controller
683 * @bus: pointer to the bus to deregister
684 * Context: !in_interrupt()
686 * Recycles the bus number, and unlinks the controller from usbcore data
687 * structures so that it won't be seen by scanning the bus list.
689 void STDCALL
usb_deregister_bus (struct usb_bus
*bus
)
691 dev_info (bus
->controller
, "USB bus %d deregistered\n", bus
->busnum
);
694 * NOTE: make sure that all the devices are removed by the
695 * controller code, as well as having it call this when cleaning
698 down (&usb_bus_list_lock
);
699 list_del (&bus
->bus_list
);
700 up (&usb_bus_list_lock
);
702 usbfs_remove_bus (bus
);
704 clear_bit (bus
->busnum
, busmap
.busmap
);
710 * usb_register_root_hub - called by HCD to register its root hub
711 * @usb_dev: the usb root hub device to be registered.
712 * @parent_dev: the parent device of this root hub.
714 * The USB host controller calls this function to register the root hub
715 * properly with the USB subsystem. It sets up the device properly in
716 * the driverfs tree, and then calls usb_new_device() to register the
719 int STDCALL
usb_register_root_hub (struct usb_device
*usb_dev
, struct device
*parent_dev
)
723 sprintf (&usb_dev
->dev
.bus_id
[0], "usb%d", usb_dev
->bus
->busnum
);
724 usb_dev
->state
= USB_STATE_DEFAULT
;
725 retval
= usb_new_device (usb_dev
, parent_dev
);
727 dev_err (parent_dev
, "can't register root hub for %s, %d\n",
728 usb_dev
->dev
.bus_id
, retval
);
733 /*-------------------------------------------------------------------------*/
736 * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
737 * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
738 * @is_input: true iff the transaction sends data to the host
739 * @isoc: true for isochronous transactions, false for interrupt ones
740 * @bytecount: how many bytes in the transaction.
742 * Returns approximate bus time in nanoseconds for a periodic transaction.
743 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
744 * scheduled in software, this function is only used for such scheduling.
746 long STDCALL
usb_calc_bus_time (int speed
, int is_input
, int isoc
, int bytecount
)
751 case USB_SPEED_LOW
: /* INTR only */
753 tmp
= (67667L * (31L + 10L * BitTime (bytecount
))) / 1000L;
754 return (64060L + (2 * BW_HUB_LS_SETUP
) + BW_HOST_DELAY
+ tmp
);
756 tmp
= (66700L * (31L + 10L * BitTime (bytecount
))) / 1000L;
757 return (64107L + (2 * BW_HUB_LS_SETUP
) + BW_HOST_DELAY
+ tmp
);
759 case USB_SPEED_FULL
: /* ISOC or INTR */
761 tmp
= (8354L * (31L + 10L * BitTime (bytecount
))) / 1000L;
762 return (((is_input
) ? 7268L : 6265L) + BW_HOST_DELAY
+ tmp
);
764 tmp
= (8354L * (31L + 10L * BitTime (bytecount
))) / 1000L;
765 return (9107L + BW_HOST_DELAY
+ tmp
);
767 case USB_SPEED_HIGH
: /* ISOC or INTR */
768 // FIXME adjust for input vs output
770 tmp
= HS_USECS (bytecount
);
772 tmp
= HS_USECS_ISO (bytecount
);
775 dbg ("bogus device speed!");
781 * usb_check_bandwidth():
783 * old_alloc is from host_controller->bandwidth_allocated in microseconds;
784 * bustime is from calc_bus_time(), but converted to microseconds.
786 * returns <bustime in us> if successful,
787 * or -ENOSPC if bandwidth request fails.
790 * This initial implementation does not use Endpoint.bInterval
791 * in managing bandwidth allocation.
792 * It probably needs to be expanded to use Endpoint.bInterval.
793 * This can be done as a later enhancement (correction).
795 * This will also probably require some kind of
796 * frame allocation tracking...meaning, for example,
797 * that if multiple drivers request interrupts every 10 USB frames,
798 * they don't all have to be allocated at
799 * frame numbers N, N+10, N+20, etc. Some of them could be at
800 * N+11, N+21, N+31, etc., and others at
801 * N+12, N+22, N+32, etc.
803 * Similarly for isochronous transfers...
805 * Individual HCDs can schedule more directly ... this logic
806 * is not correct for high speed transfers.
808 int STDCALL
usb_check_bandwidth (struct usb_device
*dev
, struct urb
*urb
)
810 unsigned int pipe
= urb
->pipe
;
812 int is_in
= usb_pipein (pipe
);
813 int is_iso
= usb_pipeisoc (pipe
);
814 int old_alloc
= dev
->bus
->bandwidth_allocated
;
818 bustime
= NS_TO_US (usb_calc_bus_time (dev
->speed
, is_in
, is_iso
,
819 usb_maxpacket (dev
, pipe
, !is_in
)));
821 bustime
/= urb
->number_of_packets
;
823 new_alloc
= old_alloc
+ (int) bustime
;
824 if (new_alloc
> FRAME_TIME_MAX_USECS_ALLOC
) {
827 #ifdef CONFIG_USB_BANDWIDTH
832 dev_dbg (&dev
->dev
, "usb_check_bandwidth %sFAILED: %d + %ld = %d usec\n",
833 mode
, old_alloc
, bustime
, new_alloc
);
835 #ifdef CONFIG_USB_BANDWIDTH
836 bustime
= -ENOSPC
; /* report error */
845 * usb_claim_bandwidth - records bandwidth for a periodic transfer
846 * @dev: source/target of request
847 * @urb: request (urb->dev == dev)
848 * @bustime: bandwidth consumed, in (average) microseconds per frame
849 * @isoc: true iff the request is isochronous
851 * Bus bandwidth reservations are recorded purely for diagnostic purposes.
852 * HCDs are expected not to overcommit periodic bandwidth, and to record such
853 * reservations whenever endpoints are added to the periodic schedule.
855 * FIXME averaging per-frame is suboptimal. Better to sum over the HCD's
856 * entire periodic schedule ... 32 frames for OHCI, 1024 for UHCI, settable
857 * for EHCI (256/512/1024 frames, default 1024) and have the bus expose how
858 * large its periodic schedule is.
860 void STDCALL
usb_claim_bandwidth (struct usb_device
*dev
, struct urb
*urb
, int bustime
, int isoc
)
862 dev
->bus
->bandwidth_allocated
+= bustime
;
864 dev
->bus
->bandwidth_isoc_reqs
++;
866 dev
->bus
->bandwidth_int_reqs
++;
867 urb
->bandwidth
= bustime
;
869 #ifdef USB_BANDWIDTH_MESSAGES
870 dev_dbg (&dev
->dev
, "bandwidth alloc increased by %d (%s) to %d for %d requesters\n",
872 isoc
? "ISOC" : "INTR",
873 dev
->bus
->bandwidth_allocated
,
874 dev
->bus
->bandwidth_int_reqs
+ dev
->bus
->bandwidth_isoc_reqs
);
880 * usb_release_bandwidth - reverses effect of usb_claim_bandwidth()
881 * @dev: source/target of request
882 * @urb: request (urb->dev == dev)
883 * @isoc: true iff the request is isochronous
885 * This records that previously allocated bandwidth has been released.
886 * Bandwidth is released when endpoints are removed from the host controller's
889 void STDCALL
usb_release_bandwidth (struct usb_device
*dev
, struct urb
*urb
, int isoc
)
891 dev
->bus
->bandwidth_allocated
-= urb
->bandwidth
;
893 dev
->bus
->bandwidth_isoc_reqs
--;
895 dev
->bus
->bandwidth_int_reqs
--;
897 #ifdef USB_BANDWIDTH_MESSAGES
898 dev_dbg (&dev
->dev
, "bandwidth alloc reduced by %d (%s) to %d for %d requesters\n",
900 isoc
? "ISOC" : "INTR",
901 dev
->bus
->bandwidth_allocated
,
902 dev
->bus
->bandwidth_int_reqs
+ dev
->bus
->bandwidth_isoc_reqs
);
908 /*-------------------------------------------------------------------------*/
911 * Generic HC operations.
914 /*-------------------------------------------------------------------------*/
916 /* called from khubd, or root hub init threads for hcd-private init */
917 static int hcd_alloc_dev (struct usb_device
*udev
)
923 if (!udev
|| udev
->hcpriv
)
925 if (!udev
->bus
|| !udev
->bus
->hcpriv
)
927 hcd
= udev
->bus
->hcpriv
;
928 if (hcd
->state
== USB_STATE_QUIESCING
)
931 dev
= (struct hcd_dev
*) kmalloc (sizeof *dev
, GFP_KERNEL
);
934 memset (dev
, 0, sizeof *dev
);
936 INIT_LIST_HEAD (&dev
->dev_list
);
937 INIT_LIST_HEAD (&dev
->urb_list
);
939 spin_lock_irqsave (&hcd_data_lock
, flags
);
940 list_add (&dev
->dev_list
, &hcd
->dev_list
);
941 // refcount is implicit
943 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
948 /*-------------------------------------------------------------------------*/
950 static void urb_unlink (struct urb
*urb
)
953 struct usb_device
*dev
;
955 /* Release any periodic transfer bandwidth */
957 usb_release_bandwidth (urb
->dev
, urb
,
958 usb_pipeisoc (urb
->pipe
));
960 /* clear all state linking urb to this dev (and hcd) */
962 spin_lock_irqsave (&hcd_data_lock
, flags
);
963 list_del_init (&urb
->urb_list
);
965 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
970 /* may be called in any context with a valid urb->dev usecount
971 * caller surrenders "ownership" of urb
972 * expects usb_submit_urb() to have sanity checked and conditioned all
975 static int hcd_submit_urb (struct urb
*urb
, int mem_flags
)
978 struct usb_hcd
*hcd
= urb
->dev
->bus
->hcpriv
;
979 struct hcd_dev
*dev
= urb
->dev
->hcpriv
;
985 //printk("submit_urb %p, # %i, t %i\n",urb,urb->dev->devnum,usb_pipetype(urb->pipe));
987 * FIXME: make urb timeouts be generic, keeping the HCD cores
988 * as simple as possible.
991 // NOTE: a generic device/urb monitoring hook would go here.
992 // hcd_monitor_hook(MONITOR_URB_SUBMIT, urb)
993 // It would catch submission paths for all urbs.
996 * Atomically queue the urb, first to our records, then to the HCD.
997 * Access to urb->status is controlled by urb->lock ... changes on
998 * i/o completion (normal or fault) or unlinking.
1001 // FIXME: verify that quiescing hc works right (RH cleans up)
1003 spin_lock_irqsave (&hcd_data_lock
, flags
);
1004 if (HCD_IS_RUNNING (hcd
->state
) && hcd
->state
!= USB_STATE_QUIESCING
) {
1005 usb_get_dev (urb
->dev
);
1006 list_add_tail (&urb
->urb_list
, &dev
->urb_list
);
1009 INIT_LIST_HEAD (&urb
->urb_list
);
1010 status
= -ESHUTDOWN
;
1012 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
1016 /* increment urb's reference count as part of giving it to the HCD
1017 * (which now controls it). HCD guarantees that it either returns
1018 * an error or calls giveback(), but not both.
1021 urb
= usb_get_urb (urb
);
1022 if (urb
->dev
== hcd
->self
.root_hub
) {
1023 /* NOTE: requirement on hub callers (usbfs and the hub
1024 * driver, for now) that URBs' urb->transfer_buffer be
1025 * valid and usb_buffer_{sync,unmap}() not be needed, since
1026 * they could clobber root hub response data.
1028 urb
->transfer_flags
|= URB_NO_DMA_MAP
;
1029 status
= rh_urb_enqueue (hcd
, urb
);
1033 /* lower level hcd code should use *_dma exclusively,
1034 * unless it uses pio or talks to another transport.
1036 if (!(urb
->transfer_flags
& URB_NO_DMA_MAP
)
1037 && hcd
->controller
->dma_mask
) {
1038 if (usb_pipecontrol (urb
->pipe
))
1039 urb
->setup_dma
= dma_map_single (
1042 sizeof (struct usb_ctrlrequest
),
1044 if (urb
->transfer_buffer_length
!= 0)
1045 urb
->transfer_dma
= dma_map_single (
1047 urb
->transfer_buffer
,
1048 urb
->transfer_buffer_length
,
1049 usb_pipein (urb
->pipe
)
1054 status
= hcd
->driver
->urb_enqueue (hcd
, urb
, mem_flags
);
1065 /*-------------------------------------------------------------------------*/
1067 /* called in any context */
1068 static int hcd_get_frame_number (struct usb_device
*udev
)
1070 struct usb_hcd
*hcd
= (struct usb_hcd
*)udev
->bus
->hcpriv
;
1071 return hcd
->driver
->get_frame_number (hcd
);
1074 /*-------------------------------------------------------------------------*/
1076 /* this makes the hcd giveback() the urb more quickly, by kicking it
1077 * off hardware queues (which may take a while) and returning it as
1078 * soon as practical. we've already set up the urb's return status,
1079 * but we can't know if the callback completed already.
1082 unlink1 (struct usb_hcd
*hcd
, struct urb
*urb
)
1084 if (urb
== (struct urb
*) hcd
->rh_timer
.data
)
1085 usb_rh_status_dequeue (hcd
, urb
);
1089 /* failures "should" be harmless */
1090 value
= hcd
->driver
->urb_dequeue (hcd
, urb
);
1092 dev_dbg (hcd
->controller
,
1093 "dequeue %p --> %d\n",
1098 struct completion_splice
{ // modified urb context:
1099 /* did we complete? */
1100 struct completion done
;
1102 /* original urb data */
1103 usb_complete_t complete
;
1107 static void unlink_complete (struct urb
*urb
, struct pt_regs
*regs
)
1109 struct completion_splice
*splice
;
1111 splice
= (struct completion_splice
*) urb
->context
;
1113 /* issue original completion call */
1114 urb
->complete
= splice
->complete
;
1115 urb
->context
= splice
->context
;
1116 urb
->complete (urb
, regs
);
1118 /* then let the synchronous unlink call complete */
1119 complete (&splice
->done
);
1123 * called in any context; note ASYNC_UNLINK restrictions
1125 * caller guarantees urb won't be recycled till both unlink()
1126 * and the urb's completion function return
1128 static int hcd_unlink_urb (struct urb
*urb
)
1130 struct hcd_dev
*dev
;
1131 struct usb_hcd
*hcd
= 0;
1132 struct device
*sys
= 0;
1133 unsigned long flags
;
1134 struct completion_splice splice
;
1141 * we contend for urb->status with the hcd core,
1142 * which changes it while returning the urb.
1144 * Caller guaranteed that the urb pointer hasn't been freed, and
1145 * that it was submitted. But as a rule it can't know whether or
1146 * not it's already been unlinked ... so we respect the reversed
1147 * lock sequence needed for the usb_hcd_giveback_urb() code paths
1148 * (urb lock, then hcd_data_lock) in case some other CPU is now
1151 spin_lock_irqsave (&urb
->lock
, flags
);
1152 spin_lock (&hcd_data_lock
);
1154 if (!urb
->dev
|| !urb
->dev
->bus
) {
1159 dev
= urb
->dev
->hcpriv
;
1160 sys
= &urb
->dev
->dev
;
1161 hcd
= urb
->dev
->bus
->hcpriv
;
1172 /* Any status except -EINPROGRESS means something already started to
1173 * unlink this URB from the hardware. So there's no more work to do.
1175 * FIXME use better explicit urb state
1177 if (urb
->status
!= -EINPROGRESS
) {
1182 /* maybe set up to block until the urb's completion fires. the
1183 * lower level hcd code is always async, locking on urb->status
1184 * updates; an intercepted completion unblocks us.
1186 if (!(urb
->transfer_flags
& URB_ASYNC_UNLINK
)) {
1187 if (in_interrupt ()) {
1188 dev_dbg (hcd
->controller
, "non-async unlink in_interrupt");
1189 retval
= -EWOULDBLOCK
;
1192 /* synchronous unlink: block till we see the completion */
1193 init_completion (&splice
.done
);
1194 splice
.complete
= urb
->complete
;
1195 splice
.context
= urb
->context
;
1196 urb
->complete
= unlink_complete
;
1197 urb
->context
= &splice
;
1198 urb
->status
= -ENOENT
;
1200 /* asynchronous unlink */
1201 urb
->status
= -ECONNRESET
;
1203 spin_unlock (&hcd_data_lock
);
1204 spin_unlock_irqrestore (&urb
->lock
, flags
);
1206 // FIXME remove splicing, so this becomes unlink1 (hcd, urb);
1207 if (urb
== (struct urb
*) hcd
->rh_timer
.data
) {
1208 usb_rh_status_dequeue (hcd
, urb
);
1211 retval
= hcd
->driver
->urb_dequeue (hcd
, urb
);
1213 /* hcds shouldn't really fail these calls, but... */
1215 dev_dbg (sys
, "dequeue %p --> %d\n", urb
, retval
);
1216 if (!(urb
->transfer_flags
& URB_ASYNC_UNLINK
)) {
1217 spin_lock_irqsave (&urb
->lock
, flags
);
1218 urb
->complete
= splice
.complete
;
1219 urb
->context
= splice
.context
;
1220 spin_unlock_irqrestore (&urb
->lock
, flags
);
1226 /* block till giveback, if needed */
1227 if (urb
->transfer_flags
& URB_ASYNC_UNLINK
)
1228 return -EINPROGRESS
;
1230 wait_for_completion (&splice
.done
);
1234 spin_unlock (&hcd_data_lock
);
1235 spin_unlock_irqrestore (&urb
->lock
, flags
);
1237 if (retval
&& sys
&& sys
->driver
)
1238 dev_dbg (sys
, "hcd_unlink_urb %p fail %d\n", urb
, retval
);
1242 /*-------------------------------------------------------------------------*/
1244 /* disables the endpoint: cancels any pending urbs, then synchronizes with
1245 * the hcd to make sure all endpoint state is gone from hardware. use for
1246 * set_configuration, set_interface, driver removal, physical disconnect.
1248 * example: a qh stored in hcd_dev.ep[], holding state related to endpoint
1249 * type, maxpacket size, toggle, halt status, and scheduling.
1251 static void hcd_endpoint_disable (struct usb_device
*udev
, int endpoint
)
1253 unsigned long flags
;
1254 struct hcd_dev
*dev
;
1255 struct usb_hcd
*hcd
;
1257 unsigned epnum
= endpoint
& USB_ENDPOINT_NUMBER_MASK
;
1260 hcd
= udev
->bus
->hcpriv
;
1263 /* (re)block new requests, as best we can */
1264 if (endpoint
& USB_DIR_IN
) {
1265 usb_endpoint_halt (udev
, epnum
, 0);
1266 udev
->epmaxpacketin
[epnum
] = 0;
1268 usb_endpoint_halt (udev
, epnum
, 1);
1269 udev
->epmaxpacketout
[epnum
] = 0;
1272 /* then kill any current requests */
1273 spin_lock_irqsave (&hcd_data_lock
, flags
);
1274 list_for_each_entry (urb
, &dev
->urb_list
, urb_list
) {
1275 int tmp
= urb
->pipe
;
1277 /* ignore urbs for other endpoints */
1278 if (usb_pipeendpoint (tmp
) != epnum
)
1280 if ((tmp
^ endpoint
) & USB_DIR_IN
)
1283 /* another cpu may be in hcd, spinning on hcd_data_lock
1284 * to giveback() this urb. the races here should be
1285 * small, but a full fix needs a new "can't submit"
1288 if (urb
->status
!= -EINPROGRESS
)
1291 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
1293 spin_lock_irqsave (&urb
->lock
, flags
);
1295 if (tmp
== -EINPROGRESS
)
1296 urb
->status
= -ESHUTDOWN
;
1297 spin_unlock_irqrestore (&urb
->lock
, flags
);
1299 /* kick hcd unless it's already returning this */
1300 if (tmp
== -EINPROGRESS
) {
1303 dev_dbg (hcd
->controller
,
1304 "shutdown urb %p pipe %08x ep%d%s%s\n",
1305 urb
, tmp
, usb_pipeendpoint (tmp
),
1306 (tmp
& USB_DIR_IN
) ? "in" : "out",
1308 switch (usb_pipetype (tmp
)) { \
1309 case PIPE_CONTROL
: s
= ""; break; \
1310 case PIPE_BULK
: s
= "-bulk"; break; \
1311 case PIPE_INTERRUPT
: s
= "-intr"; break; \
1312 default: s
= "-iso"; break; \
1317 /* list contents may have changed */
1320 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
1322 /* synchronize with the hardware, so old configuration state
1323 * clears out immediately (and will be freed).
1326 if (hcd
->driver
->endpoint_disable
)
1327 hcd
->driver
->endpoint_disable (hcd
, dev
, endpoint
);
1330 /*-------------------------------------------------------------------------*/
1332 /* called by khubd, rmmod, apmd, or other thread for hcd-private cleanup.
1333 * we're guaranteed that the device is fully quiesced. also, that each
1334 * endpoint has been hcd_endpoint_disabled.
1337 static int hcd_free_dev (struct usb_device
*udev
)
1339 struct hcd_dev
*dev
;
1340 struct usb_hcd
*hcd
;
1341 unsigned long flags
;
1343 if (!udev
|| !udev
->hcpriv
)
1346 if (!udev
->bus
|| !udev
->bus
->hcpriv
)
1349 // should udev->devnum == -1 ??
1352 hcd
= udev
->bus
->hcpriv
;
1354 /* device driver problem with refcounts? */
1355 if (!list_empty (&dev
->urb_list
)) {
1356 dev_dbg (hcd
->controller
, "free busy dev, %s devnum %d (bug!)\n",
1357 hcd
->self
.bus_name
, udev
->devnum
);
1361 spin_lock_irqsave (&hcd_data_lock
, flags
);
1362 list_del (&dev
->dev_list
);
1363 udev
->hcpriv
= NULL
;
1364 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
1371 * usb_hcd_operations - adapts usb_bus framework to HCD framework (bus glue)
1373 * When registering a USB bus through the HCD framework code, use this
1374 * usb_operations vector. The PCI glue layer does so automatically; only
1375 * bus glue for non-PCI system busses will need to use this.
1377 struct usb_operations usb_hcd_operations
= {
1378 .allocate
= hcd_alloc_dev
,
1379 .get_frame_number
= hcd_get_frame_number
,
1380 .submit_urb
= hcd_submit_urb
,
1381 .unlink_urb
= hcd_unlink_urb
,
1382 .deallocate
= hcd_free_dev
,
1383 .buffer_alloc
= hcd_buffer_alloc
,
1384 .buffer_free
= hcd_buffer_free
,
1385 .disable
= hcd_endpoint_disable
,
1387 EXPORT_SYMBOL (usb_hcd_operations
);
1389 /*-------------------------------------------------------------------------*/
1392 * usb_hcd_giveback_urb - return URB from HCD to device driver
1393 * @hcd: host controller returning the URB
1394 * @urb: urb being returned to the USB device driver.
1395 * @regs: pt_regs, passed down to the URB completion handler
1396 * Context: in_interrupt()
1398 * This hands the URB from HCD to its USB device driver, using its
1399 * completion function. The HCD has freed all per-urb resources
1400 * (and is done using urb->hcpriv). It also released all HCD locks;
1401 * the device driver won't cause problems if it frees, modifies,
1402 * or resubmits this URB.
1404 void STDCALL
usb_hcd_giveback_urb (struct usb_hcd
*hcd
, struct urb
*urb
, struct pt_regs
*regs
)
1408 // NOTE: a generic device/urb monitoring hook would go here.
1409 // hcd_monitor_hook(MONITOR_URB_FINISH, urb, dev)
1410 // It would catch exit/unlink paths for all urbs.
1412 /* lower level hcd code should use *_dma exclusively */
1413 if (!(urb
->transfer_flags
& URB_NO_DMA_MAP
)) {
1414 if (usb_pipecontrol (urb
->pipe
))
1415 pci_unmap_single (hcd
->pdev
, urb
->setup_dma
,
1416 sizeof (struct usb_ctrlrequest
),
1418 if (urb
->transfer_buffer_length
!= 0)
1419 pci_unmap_single (hcd
->pdev
, urb
->transfer_dma
,
1420 urb
->transfer_buffer_length
,
1421 usb_pipein (urb
->pipe
)
1422 ? PCI_DMA_FROMDEVICE
1423 : PCI_DMA_TODEVICE
);
1426 /* pass ownership to the completion handler */
1427 urb
->complete (urb
, regs
);
1431 /*-------------------------------------------------------------------------*/
1434 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
1435 * @irq: the IRQ being raised
1436 * @__hcd: pointer to the HCD whose IRQ is beinng signaled
1437 * @r: saved hardware registers
1439 * When registering a USB bus through the HCD framework code, use this
1440 * to handle interrupts. The PCI glue layer does so automatically; only
1441 * bus glue for non-PCI system busses will need to use this.
1443 irqreturn_t
usb_hcd_irq (int irq
, void *__hcd
, struct pt_regs
* r
)
1445 struct usb_hcd
*hcd
= __hcd
;
1446 int start
= hcd
->state
;
1448 if (unlikely (hcd
->state
== USB_STATE_HALT
)) /* irq sharing? */
1451 hcd
->driver
->irq (hcd
, r
);
1452 if (hcd
->state
!= start
&& hcd
->state
== USB_STATE_HALT
)
1457 /*-------------------------------------------------------------------------*/
1459 static void hcd_panic (void *_hcd
)
1461 struct usb_hcd
*hcd
= _hcd
;
1462 hcd
->driver
->stop (hcd
);
1466 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
1467 * @hcd: pointer to the HCD representing the controller
1469 * This is called by bus glue to report a USB host controller that died
1470 * while operations may still have been pending. It's called automatically
1471 * by the PCI glue, so only glue for non-PCI busses should need to call it.
1473 void STDCALL
usb_hc_died (struct usb_hcd
*hcd
)
1475 struct list_head
*devlist
, *urblist
;
1476 struct hcd_dev
*dev
;
1478 unsigned long flags
;
1480 /* flag every pending urb as done */
1481 spin_lock_irqsave (&hcd_data_lock
, flags
);
1482 list_for_each (devlist
, &hcd
->dev_list
) {
1483 dev
= list_entry (devlist
, struct hcd_dev
, dev_list
);
1484 list_for_each (urblist
, &dev
->urb_list
) {
1485 urb
= list_entry (urblist
, struct urb
, urb_list
);
1486 dev_dbg (hcd
->controller
, "shutdown %s urb %p pipe %x, current status %d\n",
1487 hcd
->self
.bus_name
, urb
, urb
->pipe
, urb
->status
);
1488 if (urb
->status
== -EINPROGRESS
)
1489 urb
->status
= -ESHUTDOWN
;
1492 urb
= (struct urb
*) hcd
->rh_timer
.data
;
1494 urb
->status
= -ESHUTDOWN
;
1495 spin_unlock_irqrestore (&hcd_data_lock
, flags
);
1497 /* hcd->stop() needs a task context */
1498 INIT_WORK (&hcd
->work
, hcd_panic
, hcd
);
1499 (void) schedule_work (&hcd
->work
);