2 * Universal Host Controller Interface driver for USB.
4 * (C) Copyright 1999 Linus Torvalds
5 * (C) Copyright 1999-2000 Johannes Erdfelt, jerdfelt@sventech.com
6 * (C) Copyright 1999 Randy Dunlap
7 * (C) Copyright 1999 Georg Acher, acher@in.tum.de
8 * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
9 * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
10 * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
12 * Intel documents this fairly well, and as far as I know there
13 * are no royalties or anything like that, but even so there are
14 * people who decided that they want to do the same thing in a
15 * completely different way.
17 * WARNING! The USB documentation is downright evil. Most of it
18 * is just crap, written by a committee. You're better off ignoring
19 * most of it, the important stuff is:
20 * - the low-level protocol (fairly simple but lots of small details)
21 * - working around the horridness of the rest
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/kernel.h>
27 #include <linux/delay.h>
28 #include <linux/ioport.h>
29 #include <linux/sched.h>
30 #include <linux/malloc.h>
31 #include <linux/smp_lock.h>
32 #include <linux/errno.h>
33 #include <linux/unistd.h>
34 #include <linux/interrupt.h>
35 #include <linux/spinlock.h>
37 #include <linux/usb.h>
39 #include <asm/uaccess.h>
42 #include <asm/system.h>
45 #include "uhci-debug.h"
48 static int handle_pm_event(struct pm_dev
*dev
, pm_request_t rqst
, void *data
);
51 MODULE_PARM(debug
, "i");
52 MODULE_PARM_DESC(debug
, "Debug level");
54 static kmem_cache_t
*uhci_td_cachep
;
55 static kmem_cache_t
*uhci_qh_cachep
;
56 static kmem_cache_t
*uhci_up_cachep
; /* urb_priv */
58 static LIST_HEAD(uhci_list
);
60 static int rh_submit_urb(struct urb
*urb
);
61 static int rh_unlink_urb(struct urb
*urb
);
62 static int uhci_get_current_frame_number(struct usb_device
*dev
);
63 static int uhci_unlink_generic(struct urb
*urb
);
64 static int uhci_unlink_urb(struct urb
*urb
);
66 #define min(a,b) (((a)<(b))?(a):(b))
68 /* If a transfer is still active after this much time, turn off FSBR */
69 #define IDLE_TIMEOUT (HZ / 20) /* 50 ms */
72 * Only the USB core should call uhci_alloc_dev and uhci_free_dev
74 static int uhci_alloc_dev(struct usb_device
*dev
)
79 static int uhci_free_dev(struct usb_device
*dev
)
81 struct uhci
*uhci
= (struct uhci
*)dev
->bus
->hcpriv
;
82 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
85 /* Walk through the entire URB list and forcefully remove any */
86 /* URBs that are still active for that device */
87 nested_lock(&uhci
->urblist_lock
, flags
);
90 struct urb
*u
= list_entry(tmp
, struct urb
, urb_list
);
97 nested_unlock(&uhci
->urblist_lock
, flags
);
102 static void uhci_add_urb_list(struct uhci
*uhci
, struct urb
*urb
)
106 nested_lock(&uhci
->urblist_lock
, flags
);
107 list_add(&urb
->urb_list
, &uhci
->urb_list
);
108 nested_unlock(&uhci
->urblist_lock
, flags
);
111 static void uhci_remove_urb_list(struct uhci
*uhci
, struct urb
*urb
)
115 nested_lock(&uhci
->urblist_lock
, flags
);
116 if (!list_empty(&urb
->urb_list
)) {
117 list_del(&urb
->urb_list
);
118 INIT_LIST_HEAD(&urb
->urb_list
);
120 nested_unlock(&uhci
->urblist_lock
, flags
);
123 void uhci_set_next_interrupt(struct uhci
*uhci
)
127 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
128 uhci
->skel_term_td
.status
|= TD_CTRL_IOC
;
129 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
132 void uhci_clear_next_interrupt(struct uhci
*uhci
)
136 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
137 uhci
->skel_term_td
.status
&= ~TD_CTRL_IOC
;
138 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
141 static struct uhci_td
*uhci_alloc_td(struct usb_device
*dev
)
145 td
= kmem_cache_alloc(uhci_td_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
149 td
->link
= UHCI_PTR_TERM
;
153 td
->nexttd
= td
->prevtd
= NULL
;
155 INIT_LIST_HEAD(&td
->list
);
157 usb_inc_dev_use(dev
);
162 static void inline uhci_fill_td(struct uhci_td
*td
, __u32 status
,
163 __u32 info
, __u32 buffer
)
170 static void uhci_insert_td(struct uhci
*uhci
, struct uhci_td
*skeltd
, struct uhci_td
*td
)
174 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
176 /* Fix the linked list pointers */
177 td
->nexttd
= skeltd
->nexttd
;
180 skeltd
->nexttd
->prevtd
= td
;
183 td
->link
= skeltd
->link
;
184 skeltd
->link
= virt_to_bus(td
);
186 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
190 * We insert Isochronous transfers directly into the frame list at the
192 * The layout looks as follows:
193 * frame list pointer -> iso td's (if any) ->
194 * periodic interrupt td (if frame 0) -> irq td's -> control qh -> bulk qh
197 static void uhci_insert_td_frame_list(struct uhci
*uhci
, struct uhci_td
*td
, unsigned framenum
)
200 struct uhci_td
*nexttd
;
202 framenum
%= UHCI_NUMFRAMES
;
204 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
206 td
->frameptr
= &uhci
->fl
->frame
[framenum
];
207 td
->link
= uhci
->fl
->frame
[framenum
];
208 if (!(td
->link
& (UHCI_PTR_TERM
| UHCI_PTR_QH
))) {
209 nexttd
= (struct uhci_td
*)uhci_ptr_to_virt(td
->link
);
212 nexttd
->frameptr
= NULL
;
214 uhci
->fl
->frame
[framenum
] = virt_to_bus(td
);
216 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
219 static void uhci_remove_td(struct uhci
*uhci
, struct uhci_td
*td
)
223 /* If it's not inserted, don't remove it */
224 if (!td
->frameptr
&& !td
->prevtd
&& !td
->nexttd
)
227 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
229 *(td
->frameptr
) = td
->link
;
231 td
->nexttd
->frameptr
= td
->frameptr
;
232 td
->nexttd
->prevtd
= NULL
;
238 td
->prevtd
->nexttd
= td
->nexttd
;
239 td
->prevtd
->link
= td
->link
;
242 td
->nexttd
->prevtd
= td
->prevtd
;
243 td
->prevtd
= td
->nexttd
= NULL
;
245 td
->link
= UHCI_PTR_TERM
;
246 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
250 * Inserts a td into qh list at the top.
252 static void uhci_insert_tds_in_qh(struct uhci_qh
*qh
, struct urb
*urb
, int breadth
)
254 struct list_head
*tmp
, *head
;
255 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
256 struct uhci_td
*td
, *prevtd
;
266 td
= list_entry(tmp
, struct uhci_td
, list
);
268 /* Add the first TD to the QH element pointer */
269 qh
->element
= virt_to_bus(td
) | (breadth
? 0 : UHCI_PTR_DEPTH
);
273 /* Then link the rest of the TD's */
275 while (tmp
!= head
) {
276 td
= list_entry(tmp
, struct uhci_td
, list
);
280 prevtd
->link
= virt_to_bus(td
) | (breadth
? 0 : UHCI_PTR_DEPTH
);
285 prevtd
->link
= UHCI_PTR_TERM
;
288 static void uhci_free_td(struct uhci_td
*td
)
290 if (!list_empty(&td
->list
))
291 dbg("td is still in URB list!");
294 usb_dec_dev_use(td
->dev
);
296 kmem_cache_free(uhci_td_cachep
, td
);
299 static struct uhci_qh
*uhci_alloc_qh(struct usb_device
*dev
)
303 qh
= kmem_cache_alloc(uhci_qh_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
307 qh
->element
= UHCI_PTR_TERM
;
308 qh
->link
= UHCI_PTR_TERM
;
311 qh
->prevqh
= qh
->nextqh
= NULL
;
313 INIT_LIST_HEAD(&qh
->remove_list
);
315 usb_inc_dev_use(dev
);
320 static void uhci_free_qh(struct uhci_qh
*qh
)
323 usb_dec_dev_use(qh
->dev
);
325 kmem_cache_free(uhci_qh_cachep
, qh
);
328 static void uhci_insert_qh(struct uhci
*uhci
, struct uhci_qh
*skelqh
, struct uhci_qh
*qh
)
332 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
334 /* Fix the linked list pointers */
335 qh
->nextqh
= skelqh
->nextqh
;
338 skelqh
->nextqh
->prevqh
= qh
;
341 qh
->link
= skelqh
->link
;
342 skelqh
->link
= virt_to_bus(qh
) | UHCI_PTR_QH
;
344 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
347 static void uhci_remove_qh(struct uhci
*uhci
, struct uhci_qh
*qh
)
352 /* If the QH isn't queued, then we don't need to delay unlink it */
353 delayed
= (qh
->prevqh
|| qh
->nextqh
);
355 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
357 qh
->prevqh
->nextqh
= qh
->nextqh
;
358 qh
->prevqh
->link
= qh
->link
;
361 qh
->nextqh
->prevqh
= qh
->prevqh
;
362 qh
->prevqh
= qh
->nextqh
= NULL
;
363 qh
->element
= qh
->link
= UHCI_PTR_TERM
;
364 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
367 spin_lock_irqsave(&uhci
->qh_remove_lock
, flags
);
369 /* Check to see if the remove list is empty */
370 /* Set the IOC bit to force an interrupt so we can remove the QH */
371 if (list_empty(&uhci
->qh_remove_list
))
372 uhci_set_next_interrupt(uhci
);
375 list_add(&qh
->remove_list
, &uhci
->qh_remove_list
);
377 spin_unlock_irqrestore(&uhci
->qh_remove_lock
, flags
);
382 static spinlock_t uhci_append_urb_lock
= SPIN_LOCK_UNLOCKED
;
384 /* This function will append one URB's QH to another URB's QH. This is for */
385 /* USB_QUEUE_BULK support */
386 static void uhci_append_queued_urb(struct uhci
*uhci
, struct urb
*eurb
, struct urb
*urb
)
388 struct urb_priv
*eurbp
, *urbp
, *furbp
, *lurbp
;
389 struct list_head
*tmp
;
390 struct uhci_td
*td
, *ltd
;
393 eurbp
= eurb
->hcpriv
;
396 spin_lock_irqsave(&uhci_append_urb_lock
, flags
);
398 /* Find the beginning URB in the queue */
400 struct list_head
*head
= &eurbp
->urb_queue_list
;
403 while (tmp
!= head
) {
404 struct urb_priv
*turbp
=
405 list_entry(tmp
, struct urb_priv
, urb_queue_list
);
413 tmp
= &eurbp
->urb_queue_list
;
415 furbp
= list_entry(tmp
, struct urb_priv
, urb_queue_list
);
417 tmp
= furbp
->urb_queue_list
.prev
;
418 lurbp
= list_entry(tmp
, struct urb_priv
, urb_queue_list
);
420 /* Add this one to the end */
421 list_add_tail(&urbp
->urb_queue_list
, &furbp
->urb_queue_list
);
423 /* Grab the last TD from the last URB */
424 ltd
= list_entry(lurbp
->list
.prev
, struct uhci_td
, list
);
426 /* Grab the first TD from the first URB */
427 td
= list_entry(urbp
->list
.next
, struct uhci_td
, list
);
429 /* No breadth since this will only be called for bulk transfers */
430 ltd
->link
= virt_to_bus(td
);
432 spin_unlock_irqrestore(&uhci_append_urb_lock
, flags
);
435 static void uhci_delete_queued_urb(struct uhci
*uhci
, struct urb
*urb
)
437 struct urb_priv
*urbp
, *nurbp
;
442 spin_lock_irqsave(&uhci_append_urb_lock
, flags
);
444 nurbp
= list_entry(urbp
->urb_queue_list
.next
, struct urb_priv
,
448 /* We're the head, so just insert the QH for the next URB */
449 uhci_insert_qh(uhci
, &uhci
->skel_bulk_qh
, nurbp
->qh
);
452 struct urb_priv
*purbp
;
455 /* We're somewhere in the middle (or end). A bit trickier */
456 /* than the head scenario */
457 purbp
= list_entry(urbp
->urb_queue_list
.prev
, struct urb_priv
,
460 ptd
= list_entry(purbp
->list
.prev
, struct uhci_td
, list
);
462 /* Close the gap between the two */
463 ptd
->link
= virt_to_bus(list_entry(nurbp
->list
.next
,
464 struct uhci_td
, list
));
466 /* The next URB happens to be the beggining, so */
467 /* we're the last, end the chain */
468 ptd
->link
= UHCI_PTR_TERM
;
472 list_del(&urbp
->urb_queue_list
);
474 spin_unlock_irqrestore(&uhci_append_urb_lock
, flags
);
477 struct urb_priv
*uhci_alloc_urb_priv(struct urb
*urb
)
479 struct urb_priv
*urbp
;
481 urbp
= kmem_cache_alloc(uhci_up_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
485 memset((void *)urbp
, 0, sizeof(*urbp
));
487 urbp
->inserttime
= jiffies
;
490 INIT_LIST_HEAD(&urbp
->list
);
491 INIT_LIST_HEAD(&urbp
->urb_queue_list
);
495 usb_inc_dev_use(urb
->dev
);
500 static void uhci_add_td_to_urb(struct urb
*urb
, struct uhci_td
*td
)
502 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
506 list_add_tail(&td
->list
, &urbp
->list
);
509 static void uhci_remove_td_from_urb(struct urb
*urb
, struct uhci_td
*td
)
511 urb
= NULL
; /* No warnings */
513 if (list_empty(&td
->list
))
517 INIT_LIST_HEAD(&td
->list
);
522 static void uhci_destroy_urb_priv(struct urb
*urb
)
524 struct list_head
*tmp
, *head
;
525 struct urb_priv
*urbp
;
530 spin_lock_irqsave(&urb
->lock
, flags
);
532 urbp
= (struct urb_priv
*)urb
->hcpriv
;
536 if (!urb
->dev
|| !urb
->dev
->bus
|| !urb
->dev
->bus
->hcpriv
)
539 uhci
= urb
->dev
->bus
->hcpriv
;
543 while (tmp
!= head
) {
544 td
= list_entry(tmp
, struct uhci_td
, list
);
548 uhci_remove_td_from_urb(urb
, td
);
550 uhci_remove_td(uhci
, td
);
556 kmem_cache_free(uhci_up_cachep
, urbp
);
558 usb_dec_dev_use(urb
->dev
);
561 spin_unlock_irqrestore(&urb
->lock
, flags
);
564 static void uhci_inc_fsbr(struct uhci
*uhci
, struct urb
*urb
)
567 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
572 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
577 uhci
->skel_term_qh
.link
= virt_to_bus(&uhci
->skel_hs_control_qh
) | UHCI_PTR_QH
;
580 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
583 static void uhci_dec_fsbr(struct uhci
*uhci
, struct urb
*urb
)
586 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
591 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
596 uhci
->skel_term_qh
.link
= UHCI_PTR_TERM
;
599 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
603 * Map status to standard result codes
605 * <status> is (td->status & 0xFE0000) [a.k.a. uhci_status_bits(td->status)]
606 * <dir_out> is True for output TDs and False for input TDs.
608 static int uhci_map_status(int status
, int dir_out
)
612 if (status
& TD_CTRL_BITSTUFF
) /* Bitstuff error */
614 if (status
& TD_CTRL_CRCTIMEO
) { /* CRC/Timeout */
620 if (status
& TD_CTRL_NAK
) /* NAK */
622 if (status
& TD_CTRL_BABBLE
) /* Babble */
624 if (status
& TD_CTRL_DBUFERR
) /* Buffer error */
626 if (status
& TD_CTRL_STALLED
) /* Stalled */
628 if (status
& TD_CTRL_ACTIVE
) /* Active */
637 static int uhci_submit_control(struct urb
*urb
)
639 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
640 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
643 unsigned long destination
, status
;
644 int maxsze
= usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
));
645 int len
= urb
->transfer_buffer_length
;
646 unsigned char *data
= urb
->transfer_buffer
;
648 /* The "pipe" thing contains the destination in bits 8--18 */
649 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | USB_PID_SETUP
;
652 status
= (urb
->pipe
& TD_CTRL_LS
) | TD_CTRL_ACTIVE
| (3 << 27);
655 * Build the TD for the control request
657 td
= uhci_alloc_td(urb
->dev
);
661 uhci_add_td_to_urb(urb
, td
);
662 uhci_fill_td(td
, status
, destination
| (7 << 21),
663 virt_to_bus(urb
->setup_packet
));
666 * If direction is "send", change the frame from SETUP (0x2D)
667 * to OUT (0xE1). Else change it from SETUP to IN (0x69).
669 destination
^= (USB_PID_SETUP
^ usb_packetid(urb
->pipe
));
671 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
))
672 status
|= TD_CTRL_SPD
;
675 * Build the DATA TD's
683 td
= uhci_alloc_td(urb
->dev
);
687 /* Alternate Data0/1 (start with Data1) */
688 destination
^= 1 << TD_TOKEN_TOGGLE
;
690 uhci_add_td_to_urb(urb
, td
);
691 uhci_fill_td(td
, status
, destination
| ((pktsze
- 1) << 21),
699 * Build the final TD for control status
701 td
= uhci_alloc_td(urb
->dev
);
706 * It's IN if the pipe is an output pipe or we're not expecting
709 destination
&= ~TD_PID
;
710 if (usb_pipeout(urb
->pipe
) || !urb
->transfer_buffer_length
)
711 destination
|= USB_PID_IN
;
713 destination
|= USB_PID_OUT
;
715 destination
|= 1 << TD_TOKEN_TOGGLE
; /* End in Data1 */
717 status
&= ~TD_CTRL_SPD
;
719 uhci_add_td_to_urb(urb
, td
);
720 uhci_fill_td(td
, status
| TD_CTRL_IOC
,
721 destination
| (UHCI_NULL_DATA_SIZE
<< 21), 0);
723 qh
= uhci_alloc_qh(urb
->dev
);
727 /* Low speed or small transfers gets a different queue and treatment */
728 if (urb
->pipe
& TD_CTRL_LS
) {
729 uhci_insert_tds_in_qh(qh
, urb
, 0);
730 uhci_insert_qh(uhci
, &uhci
->skel_ls_control_qh
, qh
);
732 uhci_insert_tds_in_qh(qh
, urb
, 1);
733 uhci_insert_qh(uhci
, &uhci
->skel_hs_control_qh
, qh
);
734 uhci_inc_fsbr(uhci
, urb
);
739 uhci_add_urb_list(uhci
, urb
);
741 usb_inc_dev_use(urb
->dev
);
746 static int usb_control_retrigger_status(struct urb
*urb
);
748 static int uhci_result_control(struct urb
*urb
)
750 struct list_head
*tmp
, *head
;
751 struct urb_priv
*urbp
= urb
->hcpriv
;
760 if (head
->next
== head
)
763 if (urbp
->short_control_packet
) {
769 td
= list_entry(tmp
, struct uhci_td
, list
);
771 /* The first TD is the SETUP phase, check the status, but skip */
773 status
= uhci_status_bits(td
->status
);
774 if (status
& TD_CTRL_ACTIVE
)
780 urb
->actual_length
= 0;
782 /* The rest of the TD's (but the last) are data */
784 while (tmp
!= head
&& tmp
->next
!= head
) {
785 td
= list_entry(tmp
, struct uhci_td
, list
);
789 if (urbp
->fsbr_timeout
&& (td
->status
& TD_CTRL_IOC
) &&
790 !(td
->status
& TD_CTRL_ACTIVE
)) {
791 uhci_inc_fsbr(urb
->dev
->bus
->hcpriv
, urb
);
792 urbp
->fsbr_timeout
= 0;
793 td
->status
&= ~TD_CTRL_IOC
;
796 status
= uhci_status_bits(td
->status
);
797 if (status
& TD_CTRL_ACTIVE
)
800 urb
->actual_length
+= uhci_actual_length(td
->status
);
805 /* Check to see if we received a short packet */
806 if (uhci_actual_length(td
->status
) < uhci_expected_length(td
->info
)) {
807 if (urb
->transfer_flags
& USB_DISABLE_SPD
) {
812 if (uhci_packetid(td
->info
) == USB_PID_IN
)
813 return usb_control_retrigger_status(urb
);
820 td
= list_entry(tmp
, struct uhci_td
, list
);
822 /* Control status phase */
823 status
= uhci_status_bits(td
->status
);
825 #ifdef I_HAVE_BUGGY_APC_BACKUPS
826 /* APC BackUPS Pro kludge */
827 /* It tries to send all of the descriptor instead of the amount */
829 if (td
->status
& TD_CTRL_IOC
&& /* IOC is masked out by uhci_status_bits */
830 status
& TD_CTRL_ACTIVE
&&
831 status
& TD_CTRL_NAK
)
835 if (status
& TD_CTRL_ACTIVE
)
844 ret
= uhci_map_status(status
, uhci_packetout(td
->info
));
846 /* endpoint has stalled - mark it halted */
847 usb_endpoint_halt(urb
->dev
, uhci_endpoint(td
->info
),
848 uhci_packetout(td
->info
));
851 if (debug
&& ret
!= -EPIPE
) {
852 /* Some debugging code */
853 dbg("uhci_result_control() failed with status %x", status
);
855 /* Print the chain for debugging purposes */
856 uhci_show_urb_queue(urb
);
862 static int usb_control_retrigger_status(struct urb
*urb
)
864 struct list_head
*tmp
, *head
;
865 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
866 struct uhci
*uhci
= urb
->dev
->bus
->hcpriv
;
868 urbp
->short_control_packet
= 1;
870 /* Create a new QH to avoid pointer overwriting problems */
871 uhci_remove_qh(uhci
, urbp
->qh
);
873 /* Delete all of the TD's except for the status TD at the end */
876 while (tmp
!= head
&& tmp
->next
!= head
) {
877 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
881 uhci_remove_td_from_urb(urb
, td
);
883 uhci_remove_td(uhci
, td
);
888 urbp
->qh
= uhci_alloc_qh(urb
->dev
);
890 err("unable to allocate new QH for control retrigger");
894 /* One TD, who cares about Breadth first? */
895 uhci_insert_tds_in_qh(urbp
->qh
, urb
, 0);
897 /* Low speed or small transfers gets a different queue and treatment */
898 if (urb
->pipe
& TD_CTRL_LS
)
899 uhci_insert_qh(uhci
, &uhci
->skel_ls_control_qh
, urbp
->qh
);
901 uhci_insert_qh(uhci
, &uhci
->skel_hs_control_qh
, urbp
->qh
);
907 * Interrupt transfers
909 static int uhci_submit_interrupt(struct urb
*urb
)
912 unsigned long destination
, status
;
913 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
915 if (urb
->transfer_buffer_length
> usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
)))
918 /* The "pipe" thing contains the destination in bits 8--18 */
919 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
921 status
= (urb
->pipe
& TD_CTRL_LS
) | TD_CTRL_ACTIVE
| TD_CTRL_IOC
;
923 td
= uhci_alloc_td(urb
->dev
);
927 destination
|= (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
);
928 destination
|= ((urb
->transfer_buffer_length
- 1) << 21);
930 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
));
932 uhci_add_td_to_urb(urb
, td
);
933 uhci_fill_td(td
, status
, destination
,
934 virt_to_bus(urb
->transfer_buffer
));
936 uhci_insert_td(uhci
, &uhci
->skeltd
[__interval_to_skel(urb
->interval
)], td
);
938 uhci_add_urb_list(uhci
, urb
);
943 static int uhci_result_interrupt(struct urb
*urb
)
945 struct list_head
*tmp
, *head
;
946 struct urb_priv
*urbp
= urb
->hcpriv
;
954 urb
->actual_length
= 0;
958 while (tmp
!= head
) {
959 td
= list_entry(tmp
, struct uhci_td
, list
);
963 if (urbp
->fsbr_timeout
&& (td
->status
& TD_CTRL_IOC
) &&
964 !(td
->status
& TD_CTRL_ACTIVE
)) {
965 uhci_inc_fsbr(urb
->dev
->bus
->hcpriv
, urb
);
966 urbp
->fsbr_timeout
= 0;
967 td
->status
&= ~TD_CTRL_IOC
;
970 status
= uhci_status_bits(td
->status
);
971 if (status
& TD_CTRL_ACTIVE
)
974 urb
->actual_length
+= uhci_actual_length(td
->status
);
979 if (uhci_actual_length(td
->status
) < uhci_expected_length(td
->info
)) {
980 usb_settoggle(urb
->dev
, uhci_endpoint(td
->info
),
981 uhci_packetout(td
->info
),
982 uhci_toggle(td
->info
) ^ 1);
984 if (urb
->transfer_flags
& USB_DISABLE_SPD
) {
995 ret
= uhci_map_status(status
, uhci_packetout(td
->info
));
997 /* endpoint has stalled - mark it halted */
998 usb_endpoint_halt(urb
->dev
, uhci_endpoint(td
->info
),
999 uhci_packetout(td
->info
));
1002 if (debug
&& ret
!= -EPIPE
) {
1003 /* Some debugging code */
1004 dbg("uhci_result_interrupt/bulk() failed with status %x",
1007 /* Print the chain for debugging purposes */
1009 uhci_show_urb_queue(urb
);
1017 static void uhci_reset_interrupt(struct urb
*urb
)
1019 struct list_head
*tmp
;
1020 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1026 tmp
= urbp
->list
.next
;
1027 td
= list_entry(tmp
, struct uhci_td
, list
);
1031 td
->status
= (td
->status
& 0x2F000000) | TD_CTRL_ACTIVE
| TD_CTRL_IOC
;
1032 td
->info
&= ~(1 << TD_TOKEN_TOGGLE
);
1033 td
->info
|= (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
);
1034 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
));
1036 urb
->status
= -EINPROGRESS
;
1042 static int uhci_submit_bulk(struct urb
*urb
, struct urb
*eurb
)
1046 unsigned long destination
, status
;
1047 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1048 int maxsze
= usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
));
1049 int len
= urb
->transfer_buffer_length
;
1050 unsigned char *data
= urb
->transfer_buffer
;
1051 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1056 /* Can't have low speed bulk transfers */
1057 if (urb
->pipe
& TD_CTRL_LS
)
1060 /* The "pipe" thing contains the destination in bits 8--18 */
1061 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
1064 status
= TD_CTRL_ACTIVE
| (3 << TD_CTRL_C_ERR_SHIFT
);
1066 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
))
1067 status
|= TD_CTRL_SPD
;
1070 * Build the DATA TD's
1072 do { /* Allow zero length packets */
1075 if (pktsze
> maxsze
)
1078 td
= uhci_alloc_td(urb
->dev
);
1082 uhci_add_td_to_urb(urb
, td
);
1083 uhci_fill_td(td
, status
, destination
| ((pktsze
- 1) << 21) |
1084 (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
1085 usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
),
1092 td
->status
|= TD_CTRL_IOC
;
1094 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
1095 usb_pipeout(urb
->pipe
));
1098 qh
= uhci_alloc_qh(urb
->dev
);
1104 /* Always assume depth first */
1105 uhci_insert_tds_in_qh(qh
, urb
, 1);
1107 if (urb
->transfer_flags
& USB_QUEUE_BULK
&& eurb
) {
1109 uhci_append_queued_urb(uhci
, eurb
, urb
);
1111 uhci_insert_qh(uhci
, &uhci
->skel_bulk_qh
, qh
);
1113 uhci_add_urb_list(uhci
, urb
);
1115 uhci_inc_fsbr(uhci
, urb
);
1117 return -EINPROGRESS
;
1120 /* We can use the result interrupt since they're identical */
1121 #define uhci_result_bulk uhci_result_interrupt
1124 * Isochronous transfers
1126 static int isochronous_find_limits(struct urb
*urb
, unsigned int *start
, unsigned int *end
)
1128 struct urb
*last_urb
= NULL
;
1129 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1130 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1132 unsigned long flags
;
1134 nested_lock(&uhci
->urblist_lock
, flags
);
1136 while (tmp
!= head
) {
1137 struct urb
*u
= list_entry(tmp
, struct urb
, urb_list
);
1141 /* look for pending URB's with identical pipe handle */
1142 if ((urb
->pipe
== u
->pipe
) && (urb
->dev
== u
->dev
) &&
1143 (u
->status
== -EINPROGRESS
) && (u
!= urb
)) {
1145 *start
= u
->start_frame
;
1151 *end
= (last_urb
->start_frame
+ last_urb
->number_of_packets
) & 1023;
1154 ret
= -1; /* no previous urb found */
1156 nested_unlock(&uhci
->urblist_lock
, flags
);
1161 static int isochronous_find_start(struct urb
*urb
)
1164 unsigned int start
= 0, end
= 0;
1166 if (urb
->number_of_packets
> 900) /* 900? Why? */
1169 limits
= isochronous_find_limits(urb
, &start
, &end
);
1171 if (urb
->transfer_flags
& USB_ISO_ASAP
) {
1175 curframe
= uhci_get_current_frame_number(urb
->dev
) % UHCI_NUMFRAMES
;
1176 urb
->start_frame
= (curframe
+ 10) % UHCI_NUMFRAMES
;
1178 urb
->start_frame
= end
;
1180 urb
->start_frame
%= UHCI_NUMFRAMES
;
1181 /* FIXME: Sanity check */
1187 static int uhci_submit_isochronous(struct urb
*urb
)
1190 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1191 int i
, ret
, framenum
;
1192 int status
, destination
;
1194 status
= TD_CTRL_ACTIVE
| TD_CTRL_IOS
;
1195 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
1197 ret
= isochronous_find_start(urb
);
1201 framenum
= urb
->start_frame
;
1202 for (i
= 0; i
< urb
->number_of_packets
; i
++, framenum
++) {
1203 if (!urb
->iso_frame_desc
[i
].length
)
1206 td
= uhci_alloc_td(urb
->dev
);
1210 uhci_add_td_to_urb(urb
, td
);
1211 uhci_fill_td(td
, status
, destination
| ((urb
->iso_frame_desc
[i
].length
- 1) << 21),
1212 virt_to_bus(urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
));
1214 if (i
+ 1 >= urb
->number_of_packets
)
1215 td
->status
|= TD_CTRL_IOC
;
1217 uhci_insert_td_frame_list(uhci
, td
, framenum
);
1220 uhci_add_urb_list(uhci
, urb
);
1222 return -EINPROGRESS
;
1225 static int uhci_result_isochronous(struct urb
*urb
)
1227 struct list_head
*tmp
, *head
;
1228 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1235 urb
->actual_length
= 0;
1240 while (tmp
!= head
) {
1241 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
1246 if (td
->status
& TD_CTRL_ACTIVE
)
1247 return -EINPROGRESS
;
1249 actlength
= uhci_actual_length(td
->status
);
1250 urb
->iso_frame_desc
[i
].actual_length
= actlength
;
1251 urb
->actual_length
+= actlength
;
1253 status
= uhci_map_status(uhci_status_bits(td
->status
), usb_pipeout(urb
->pipe
));
1254 urb
->iso_frame_desc
[i
].status
= status
;
1266 static struct urb
*uhci_find_urb_ep(struct uhci
*uhci
, struct urb
*urb
)
1268 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1269 unsigned long flags
;
1270 struct urb
*u
= NULL
;
1272 if (usb_pipeisoc(urb
->pipe
))
1275 nested_lock(&uhci
->urblist_lock
, flags
);
1277 while (tmp
!= head
) {
1278 u
= list_entry(tmp
, struct urb
, urb_list
);
1282 if (u
->dev
== urb
->dev
&&
1283 u
->pipe
== urb
->pipe
)
1289 nested_unlock(&uhci
->urblist_lock
, flags
);
1294 static int uhci_submit_urb(struct urb
*urb
)
1298 unsigned long flags
;
1305 if (!urb
->dev
|| !urb
->dev
->bus
|| !urb
->dev
->bus
->hcpriv
)
1308 uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1310 /* Short circuit the virtual root hub */
1311 if (usb_pipedevice(urb
->pipe
) == uhci
->rh
.devnum
)
1312 return rh_submit_urb(urb
);
1314 u
= uhci_find_urb_ep(uhci
, urb
);
1315 if (u
&& !(urb
->transfer_flags
& USB_QUEUE_BULK
))
1318 spin_lock_irqsave(&urb
->lock
, flags
);
1320 if (!uhci_alloc_urb_priv(urb
)) {
1321 spin_unlock_irqrestore(&urb
->lock
, flags
);
1325 switch (usb_pipetype(urb
->pipe
)) {
1327 ret
= uhci_submit_control(urb
);
1329 case PIPE_INTERRUPT
:
1330 if (urb
->bandwidth
== 0) { /* not yet checked/allocated */
1331 bustime
= usb_check_bandwidth (urb
->dev
, urb
);
1335 ret
= uhci_submit_interrupt(urb
);
1336 if (ret
== -EINPROGRESS
)
1337 usb_claim_bandwidth (urb
->dev
, urb
, bustime
, 0);
1339 } else { /* bandwidth is already set */
1340 ret
= uhci_submit_interrupt(urb
);
1344 ret
= uhci_submit_bulk(urb
, u
);
1346 case PIPE_ISOCHRONOUS
:
1347 if (urb
->bandwidth
== 0) { /* not yet checked/allocated */
1348 if (urb
->number_of_packets
<= 0) {
1352 bustime
= usb_check_bandwidth (urb
->dev
, urb
);
1358 ret
= uhci_submit_isochronous(urb
);
1359 if (ret
== -EINPROGRESS
)
1360 usb_claim_bandwidth (urb
->dev
, urb
, bustime
, 1);
1361 } else { /* bandwidth is already set */
1362 ret
= uhci_submit_isochronous(urb
);
1369 spin_unlock_irqrestore(&urb
->lock
, flags
);
1371 if (ret
== -EINPROGRESS
)
1374 uhci_unlink_generic(urb
);
1380 * Return the result of a transfer
1382 * Must be called with urblist_lock acquired
1384 static void uhci_transfer_result(struct urb
*urb
)
1387 int proceed
= 0, is_ring
= 0;
1389 unsigned long flags
;
1391 spin_lock_irqsave(&urb
->lock
, flags
);
1393 switch (usb_pipetype(urb
->pipe
)) {
1395 ret
= uhci_result_control(urb
);
1397 case PIPE_INTERRUPT
:
1398 ret
= uhci_result_interrupt(urb
);
1401 ret
= uhci_result_bulk(urb
);
1403 case PIPE_ISOCHRONOUS
:
1404 ret
= uhci_result_isochronous(urb
);
1410 spin_unlock_irqrestore(&urb
->lock
, flags
);
1412 if (ret
== -EINPROGRESS
)
1415 switch (usb_pipetype(urb
->pipe
)) {
1418 case PIPE_ISOCHRONOUS
:
1419 /* Release bandwidth for Interrupt or Isoc. transfers */
1420 /* Spinlock needed ? */
1422 usb_release_bandwidth (urb
->dev
, urb
, 1);
1423 uhci_unlink_generic(urb
);
1425 case PIPE_INTERRUPT
:
1426 /* Interrupts are an exception */
1429 uhci_reset_interrupt(urb
);
1431 /* Release bandwidth for Interrupt or Isoc. transfers */
1432 /* Spinlock needed ? */
1434 usb_release_bandwidth (urb
->dev
, urb
, 0);
1435 uhci_unlink_generic(urb
);
1437 return; /* <-- Note the return */
1443 if (turb
->status
!= -EINPROGRESS
) {
1449 } while (turb
&& turb
!= urb
&& turb
!= urb
->next
);
1451 if (turb
== urb
|| turb
== urb
->next
)
1455 if (urb
->complete
&& (!proceed
|| (urb
->transfer_flags
& USB_URB_EARLY_COMPLETE
))) {
1457 if (!proceed
&& is_ring
)
1458 uhci_submit_urb(urb
);
1461 if (proceed
&& urb
->next
) {
1464 if (turb
->status
!= -EINPROGRESS
&&
1465 uhci_submit_urb(turb
) != 0)
1468 } while (turb
&& turb
!= urb
->next
);
1470 if (urb
->complete
&& !(urb
->transfer_flags
& USB_URB_EARLY_COMPLETE
))
1475 static int uhci_unlink_generic(struct urb
*urb
)
1477 struct urb_priv
*urbp
= urb
->hcpriv
;
1478 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1483 uhci_dec_fsbr(uhci
, urb
); /* Safe since it checks */
1485 uhci_remove_urb_list(uhci
, urb
);
1488 /* The interrupt loop will reclaim the QH's */
1489 uhci_remove_qh(uhci
, urbp
->qh
);
1491 if (!list_empty(&urbp
->urb_queue_list
))
1492 uhci_delete_queued_urb(uhci
, urb
);
1494 uhci_destroy_urb_priv(urb
);
1499 static int uhci_unlink_urb(struct urb
*urb
)
1503 unsigned long flags
;
1508 if (!urb
->dev
|| !urb
->dev
->bus
)
1511 uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1513 /* Short circuit the virtual root hub */
1514 if (usb_pipedevice(urb
->pipe
) == uhci
->rh
.devnum
)
1515 return rh_unlink_urb(urb
);
1517 /* Release bandwidth for Interrupt or Isoc. transfers */
1518 /* Spinlock needed ? */
1519 if (urb
->bandwidth
) {
1520 switch (usb_pipetype(urb
->pipe
)) {
1521 case PIPE_INTERRUPT
:
1522 usb_release_bandwidth (urb
->dev
, urb
, 0);
1524 case PIPE_ISOCHRONOUS
:
1525 usb_release_bandwidth (urb
->dev
, urb
, 1);
1532 if (urb
->status
== -EINPROGRESS
) {
1533 uhci_unlink_generic(urb
);
1535 if (urb
->transfer_flags
& USB_ASYNC_UNLINK
) {
1536 urb
->status
= -ECONNABORTED
;
1538 spin_lock_irqsave(&uhci
->urb_remove_lock
, flags
);
1540 /* Check to see if the remove list is empty */
1541 if (list_empty(&uhci
->urb_remove_list
))
1542 uhci_set_next_interrupt(uhci
);
1544 list_add(&urb
->urb_list
, &uhci
->urb_remove_list
);
1546 spin_unlock_irqrestore(&uhci
->urb_remove_lock
, flags
);
1548 urb
->status
= -ENOENT
;
1550 if (in_interrupt()) { /* wait at least 1 frame */
1551 static int errorcount
= 10;
1554 dbg("uhci_unlink_urb called from interrupt for urb %p", urb
);
1557 schedule_timeout(1+1*HZ
/1000);
1567 static int uhci_fsbr_timeout(struct uhci
*uhci
, struct urb
*urb
)
1569 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1570 struct list_head
*head
, *tmp
;
1572 uhci_dec_fsbr(uhci
, urb
);
1574 /* There is a race with updating IOC in here, but it's not worth */
1575 /* trying to fix since this is merely an optimization. The only */
1576 /* time we'd lose is if the status of the packet got updated */
1577 /* and we'd be turning on FSBR next frame anyway, so it's a wash */
1578 urbp
->fsbr_timeout
= 1;
1582 while (tmp
!= head
) {
1583 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
1587 if (td
->status
& TD_CTRL_ACTIVE
) {
1588 td
->status
|= TD_CTRL_IOC
;
1597 * uhci_get_current_frame_number()
1599 * returns the current frame number for a USB bus/controller.
1601 static int uhci_get_current_frame_number(struct usb_device
*dev
)
1603 struct uhci
*uhci
= (struct uhci
*)dev
->bus
->hcpriv
;
1605 return inw(uhci
->io_addr
+ USBFRNUM
);
1608 struct usb_operations uhci_device_operations
= {
1611 uhci_get_current_frame_number
,
1616 /* -------------------------------------------------------------------
1618 ------------------------------------------------------------------- */
1620 static __u8 root_hub_dev_des
[] =
1622 0x12, /* __u8 bLength; */
1623 0x01, /* __u8 bDescriptorType; Device */
1624 0x00, /* __u16 bcdUSB; v1.0 */
1626 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1627 0x00, /* __u8 bDeviceSubClass; */
1628 0x00, /* __u8 bDeviceProtocol; */
1629 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1630 0x00, /* __u16 idVendor; */
1632 0x00, /* __u16 idProduct; */
1634 0x00, /* __u16 bcdDevice; */
1636 0x00, /* __u8 iManufacturer; */
1637 0x02, /* __u8 iProduct; */
1638 0x01, /* __u8 iSerialNumber; */
1639 0x01 /* __u8 bNumConfigurations; */
1643 /* Configuration descriptor */
1644 static __u8 root_hub_config_des
[] =
1646 0x09, /* __u8 bLength; */
1647 0x02, /* __u8 bDescriptorType; Configuration */
1648 0x19, /* __u16 wTotalLength; */
1650 0x01, /* __u8 bNumInterfaces; */
1651 0x01, /* __u8 bConfigurationValue; */
1652 0x00, /* __u8 iConfiguration; */
1653 0x40, /* __u8 bmAttributes;
1654 Bit 7: Bus-powered, 6: Self-powered,
1655 Bit 5 Remote-wakeup, 4..0: resvd */
1656 0x00, /* __u8 MaxPower; */
1659 0x09, /* __u8 if_bLength; */
1660 0x04, /* __u8 if_bDescriptorType; Interface */
1661 0x00, /* __u8 if_bInterfaceNumber; */
1662 0x00, /* __u8 if_bAlternateSetting; */
1663 0x01, /* __u8 if_bNumEndpoints; */
1664 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1665 0x00, /* __u8 if_bInterfaceSubClass; */
1666 0x00, /* __u8 if_bInterfaceProtocol; */
1667 0x00, /* __u8 if_iInterface; */
1670 0x07, /* __u8 ep_bLength; */
1671 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1672 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1673 0x03, /* __u8 ep_bmAttributes; Interrupt */
1674 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
1676 0xff /* __u8 ep_bInterval; 255 ms */
1679 static __u8 root_hub_hub_des
[] =
1681 0x09, /* __u8 bLength; */
1682 0x29, /* __u8 bDescriptorType; Hub-descriptor */
1683 0x02, /* __u8 bNbrPorts; */
1684 0x00, /* __u16 wHubCharacteristics; */
1686 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
1687 0x00, /* __u8 bHubContrCurrent; 0 mA */
1688 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
1689 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
1692 /*-------------------------------------------------------------------------*/
1693 /* prepare Interrupt pipe transaction data; HUB INTERRUPT ENDPOINT */
1694 static int rh_send_irq(struct urb
*urb
)
1697 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1698 unsigned int io_addr
= uhci
->io_addr
;
1701 for (i
= 0; i
< uhci
->rh
.numports
; i
++) {
1702 data
|= ((inw(io_addr
+ USBPORTSC1
+ i
* 2) & 0xa) > 0 ? (1 << (i
+ 1)) : 0);
1703 len
= (i
+ 1) / 8 + 1;
1706 *(__u16
*) urb
->transfer_buffer
= cpu_to_le16(data
);
1707 urb
->actual_length
= len
;
1708 urb
->status
= USB_ST_NOERROR
;
1710 if ((data
> 0) && (uhci
->rh
.send
!= 0)) {
1711 dbg("root-hub INT complete: port1: %x port2: %x data: %x",
1712 inw(io_addr
+ USBPORTSC1
), inw(io_addr
+ USBPORTSC2
), data
);
1716 return USB_ST_NOERROR
;
1719 /*-------------------------------------------------------------------------*/
1720 /* Virtual Root Hub INTs are polled by this timer every "interval" ms */
1721 static int rh_init_int_timer(struct urb
*urb
);
1723 static void rh_int_timer_do(unsigned long ptr
)
1725 struct urb
*urb
= (struct urb
*)ptr
;
1726 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1727 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1728 struct urb_priv
*urbp
;
1730 unsigned long flags
;
1732 if (uhci
->rh
.send
) {
1733 len
= rh_send_irq(urb
);
1735 urb
->actual_length
= len
;
1741 nested_lock(&uhci
->urblist_lock
, flags
);
1743 while (tmp
!= head
) {
1744 struct urb
*u
= list_entry(tmp
, urb_t
, urb_list
);
1748 urbp
= (struct urb_priv
*)u
->hcpriv
;
1750 /* Check if the FSBR timed out */
1751 if (urbp
->fsbr
&& time_after(urbp
->inserttime
+ IDLE_TIMEOUT
, jiffies
))
1752 uhci_fsbr_timeout(uhci
, u
);
1754 /* Check if the URB timed out */
1755 if (u
->timeout
&& time_after(u
->timeout
, jiffies
)) {
1756 u
->transfer_flags
|= USB_ASYNC_UNLINK
| USB_TIMEOUT_KILLED
;
1761 nested_unlock(&uhci
->urblist_lock
, flags
);
1763 rh_init_int_timer(urb
);
1766 /*-------------------------------------------------------------------------*/
1767 /* Root Hub INTs are polled by this timer */
1768 static int rh_init_int_timer(struct urb
*urb
)
1770 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1772 uhci
->rh
.interval
= urb
->interval
;
1773 init_timer(&uhci
->rh
.rh_int_timer
);
1774 uhci
->rh
.rh_int_timer
.function
= rh_int_timer_do
;
1775 uhci
->rh
.rh_int_timer
.data
= (unsigned long)urb
;
1776 uhci
->rh
.rh_int_timer
.expires
= jiffies
+ (HZ
* (urb
->interval
< 30 ? 30 : urb
->interval
)) / 1000;
1777 add_timer(&uhci
->rh
.rh_int_timer
);
1782 /*-------------------------------------------------------------------------*/
1783 #define OK(x) len = (x); break
1785 #define CLR_RH_PORTSTAT(x) \
1786 status = inw(io_addr + USBPORTSC1 + 2 * (wIndex-1)); \
1787 status = (status & 0xfff5) & ~(x); \
1788 outw(status, io_addr + USBPORTSC1 + 2 * (wIndex-1))
1790 #define SET_RH_PORTSTAT(x) \
1791 status = inw(io_addr + USBPORTSC1 + 2 * (wIndex-1)); \
1792 status = (status & 0xfff5) | (x); \
1793 outw(status, io_addr + USBPORTSC1 + 2 * (wIndex-1))
1796 /*-------------------------------------------------------------------------*/
1797 /*************************
1798 ** Root Hub Control Pipe
1799 *************************/
1801 static int rh_submit_urb(struct urb
*urb
)
1803 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1804 unsigned int pipe
= urb
->pipe
;
1805 devrequest
*cmd
= (devrequest
*)urb
->setup_packet
;
1806 void *data
= urb
->transfer_buffer
;
1807 int leni
= urb
->transfer_buffer_length
;
1810 int stat
= USB_ST_NOERROR
;
1812 unsigned int io_addr
= uhci
->io_addr
;
1819 if (usb_pipetype(pipe
) == PIPE_INTERRUPT
) {
1822 uhci
->rh
.interval
= urb
->interval
;
1823 rh_init_int_timer(urb
);
1825 return USB_ST_NOERROR
;
1828 bmRType_bReq
= cmd
->requesttype
| cmd
->request
<< 8;
1829 wValue
= le16_to_cpu(cmd
->value
);
1830 wIndex
= le16_to_cpu(cmd
->index
);
1831 wLength
= le16_to_cpu(cmd
->length
);
1833 for (i
= 0; i
< 8; i
++)
1834 uhci
->rh
.c_p_r
[i
] = 0;
1836 switch (bmRType_bReq
) {
1837 /* Request Destination:
1838 without flags: Device,
1839 RH_INTERFACE: interface,
1840 RH_ENDPOINT: endpoint,
1841 RH_CLASS means HUB here,
1842 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1846 *(__u16
*)data
= cpu_to_le16(1);
1848 case RH_GET_STATUS
| RH_INTERFACE
:
1849 *(__u16
*)data
= cpu_to_le16(0);
1851 case RH_GET_STATUS
| RH_ENDPOINT
:
1852 *(__u16
*)data
= cpu_to_le16(0);
1854 case RH_GET_STATUS
| RH_CLASS
:
1855 *(__u32
*)data
= cpu_to_le32(0);
1856 OK(4); /* hub power */
1857 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
1858 status
= inw(io_addr
+ USBPORTSC1
+ 2 * (wIndex
- 1));
1859 cstatus
= ((status
& USBPORTSC_CSC
) >> (1 - 0)) |
1860 ((status
& USBPORTSC_PEC
) >> (3 - 1)) |
1861 (uhci
->rh
.c_p_r
[wIndex
- 1] << (0 + 4));
1862 status
= (status
& USBPORTSC_CCS
) |
1863 ((status
& USBPORTSC_PE
) >> (2 - 1)) |
1864 ((status
& USBPORTSC_SUSP
) >> (12 - 2)) |
1865 ((status
& USBPORTSC_PR
) >> (9 - 4)) |
1866 (1 << 8) | /* power on */
1867 ((status
& USBPORTSC_LSDA
) << (-8 + 9));
1869 *(__u16
*)data
= cpu_to_le16(status
);
1870 *(__u16
*)(data
+ 2) = cpu_to_le16(cstatus
);
1872 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
1874 case RH_ENDPOINT_STALL
:
1878 case RH_CLEAR_FEATURE
| RH_CLASS
:
1880 case RH_C_HUB_OVER_CURRENT
:
1881 OK(0); /* hub power over current */
1884 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
1886 case RH_PORT_ENABLE
:
1887 CLR_RH_PORTSTAT(USBPORTSC_PE
);
1889 case RH_PORT_SUSPEND
:
1890 CLR_RH_PORTSTAT(USBPORTSC_SUSP
);
1893 OK(0); /* port power */
1894 case RH_C_PORT_CONNECTION
:
1895 SET_RH_PORTSTAT(USBPORTSC_CSC
);
1897 case RH_C_PORT_ENABLE
:
1898 SET_RH_PORTSTAT(USBPORTSC_PEC
);
1900 case RH_C_PORT_SUSPEND
:
1901 /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
1903 case RH_C_PORT_OVER_CURRENT
:
1904 OK(0); /* port power over current */
1905 case RH_C_PORT_RESET
:
1906 uhci
->rh
.c_p_r
[wIndex
- 1] = 0;
1910 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
1912 case RH_PORT_SUSPEND
:
1913 SET_RH_PORTSTAT(USBPORTSC_SUSP
);
1916 SET_RH_PORTSTAT(USBPORTSC_PR
);
1917 wait_ms(50); /* USB v1.1 7.1.7.3 */
1918 uhci
->rh
.c_p_r
[wIndex
- 1] = 1;
1919 CLR_RH_PORTSTAT(USBPORTSC_PR
);
1921 SET_RH_PORTSTAT(USBPORTSC_PE
);
1923 SET_RH_PORTSTAT(0xa);
1926 OK(0); /* port power ** */
1927 case RH_PORT_ENABLE
:
1928 SET_RH_PORTSTAT(USBPORTSC_PE
);
1932 case RH_SET_ADDRESS
:
1933 uhci
->rh
.devnum
= wValue
;
1935 case RH_GET_DESCRIPTOR
:
1936 switch ((wValue
& 0xff00) >> 8) {
1937 case 0x01: /* device descriptor */
1938 len
= min(leni
, min(sizeof(root_hub_dev_des
), wLength
));
1939 memcpy(data
, root_hub_dev_des
, len
);
1941 case 0x02: /* configuration descriptor */
1942 len
= min(leni
, min(sizeof(root_hub_config_des
), wLength
));
1943 memcpy (data
, root_hub_config_des
, len
);
1945 case 0x03: /* string descriptors */
1946 len
= usb_root_hub_string (wValue
& 0xff,
1947 uhci
->io_addr
, "UHCI-alt",
1950 OK (min (leni
, len
));
1955 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1956 root_hub_hub_des
[2] = uhci
->rh
.numports
;
1957 len
= min(leni
, min(sizeof(root_hub_hub_des
), wLength
));
1958 memcpy(data
, root_hub_hub_des
, len
);
1960 case RH_GET_CONFIGURATION
:
1961 *(__u8
*)data
= 0x01;
1963 case RH_SET_CONFIGURATION
:
1965 case RH_GET_INTERFACE
| RH_INTERFACE
:
1966 *(__u8
*)data
= 0x00;
1968 case RH_SET_INTERFACE
| RH_INTERFACE
:
1974 urb
->actual_length
= len
;
1979 return USB_ST_NOERROR
;
1981 /*-------------------------------------------------------------------------*/
1983 static int rh_unlink_urb(struct urb
*urb
)
1985 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1987 if (uhci
->rh
.urb
== urb
) {
1989 del_timer(&uhci
->rh
.rh_int_timer
);
1993 /*-------------------------------------------------------------------*/
1995 void uhci_free_pending_qhs(struct uhci
*uhci
)
1997 struct list_head
*tmp
, *head
;
1998 unsigned long flags
;
2000 /* Free any pending QH's */
2001 spin_lock_irqsave(&uhci
->qh_remove_lock
, flags
);
2002 head
= &uhci
->qh_remove_list
;
2004 while (tmp
!= head
) {
2005 struct uhci_qh
*qh
= list_entry(tmp
, struct uhci_qh
, remove_list
);
2009 list_del(&qh
->remove_list
);
2013 spin_unlock_irqrestore(&uhci
->qh_remove_lock
, flags
);
2016 static void uhci_interrupt(int irq
, void *__uhci
, struct pt_regs
*regs
)
2018 struct uhci
*uhci
= __uhci
;
2019 unsigned int io_addr
= uhci
->io_addr
;
2020 unsigned short status
;
2021 unsigned long flags
;
2022 struct list_head
*tmp
, *head
;
2025 * Read the interrupt status, and write it back to clear the
2028 status
= inw(io_addr
+ USBSTS
);
2029 if (!status
) /* shared interrupt, not mine */
2031 outw(status
, io_addr
+ USBSTS
);
2033 if (status
& ~(USBSTS_USBINT
| USBSTS_ERROR
)) {
2034 if (status
& USBSTS_RD
)
2035 printk(KERN_INFO
"uhci: resume detected, not implemented\n");
2036 if (status
& USBSTS_HSE
)
2037 printk(KERN_ERR
"uhci: host system error, PCI problems?\n");
2038 if (status
& USBSTS_HCPE
)
2039 printk(KERN_ERR
"uhci: host controller process error. something bad happened\n");
2040 if (status
& USBSTS_HCH
) {
2041 printk(KERN_ERR
"uhci: host controller halted. very bad\n");
2042 /* FIXME: Reset the controller, fix the offending TD */
2046 uhci_free_pending_qhs(uhci
);
2048 spin_lock(&uhci
->urb_remove_lock
);
2049 head
= &uhci
->urb_remove_list
;
2051 while (tmp
!= head
) {
2052 struct urb
*urb
= list_entry(tmp
, struct urb
, urb_list
);
2056 list_del(&urb
->urb_list
);
2061 spin_unlock(&uhci
->urb_remove_lock
);
2063 uhci_clear_next_interrupt(uhci
);
2065 /* Walk the list of pending TD's to see which ones completed */
2066 nested_lock(&uhci
->urblist_lock
, flags
);
2067 head
= &uhci
->urb_list
;
2069 while (tmp
!= head
) {
2070 struct urb
*urb
= list_entry(tmp
, struct urb
, urb_list
);
2074 /* Checks the status and does all of the magic necessary */
2075 uhci_transfer_result(urb
);
2077 nested_unlock(&uhci
->urblist_lock
, flags
);
2080 static void reset_hc(struct uhci
*uhci
)
2082 unsigned int io_addr
= uhci
->io_addr
;
2084 /* Global reset for 50ms */
2085 outw(USBCMD_GRESET
, io_addr
+ USBCMD
);
2087 outw(0, io_addr
+ USBCMD
);
2091 static void start_hc(struct uhci
*uhci
)
2093 unsigned int io_addr
= uhci
->io_addr
;
2097 * Reset the HC - this will force us to get a
2098 * new notification of any already connected
2099 * ports due to the virtual disconnect that it
2102 outw(USBCMD_HCRESET
, io_addr
+ USBCMD
);
2103 while (inw(io_addr
+ USBCMD
) & USBCMD_HCRESET
) {
2105 printk(KERN_ERR
"uhci: USBCMD_HCRESET timed out!\n");
2110 /* Turn on all interrupts */
2111 outw(USBINTR_TIMEOUT
| USBINTR_RESUME
| USBINTR_IOC
| USBINTR_SP
,
2114 /* Start at frame 0 */
2115 outw(0, io_addr
+ USBFRNUM
);
2116 outl(virt_to_bus(uhci
->fl
), io_addr
+ USBFLBASEADD
);
2118 /* Run and mark it configured with a 64-byte max packet */
2119 outw(USBCMD_RS
| USBCMD_CF
| USBCMD_MAXP
, io_addr
+ USBCMD
);
2123 * Allocate a frame list, and then setup the skeleton
2125 * The hardware doesn't really know any difference
2126 * in the queues, but the order does matter for the
2127 * protocols higher up. The order is:
2129 * - any isochronous events handled before any
2130 * of the queues. We don't do that here, because
2131 * we'll create the actual TD entries on demand.
2132 * - The first queue is the "interrupt queue".
2133 * - The second queue is the "control queue", split into low and high speed
2134 * - The third queue is "bulk data".
2136 static struct uhci
*alloc_uhci(unsigned int io_addr
, unsigned int io_size
)
2140 struct usb_bus
*bus
;
2142 uhci
= kmalloc(sizeof(*uhci
), GFP_KERNEL
);
2146 memset(uhci
, 0, sizeof(*uhci
));
2149 uhci
->io_addr
= io_addr
;
2150 uhci
->io_size
= io_size
;
2152 spin_lock_init(&uhci
->qh_remove_lock
);
2153 INIT_LIST_HEAD(&uhci
->qh_remove_list
);
2155 spin_lock_init(&uhci
->urb_remove_lock
);
2156 INIT_LIST_HEAD(&uhci
->urb_remove_list
);
2158 nested_init(&uhci
->urblist_lock
);
2159 INIT_LIST_HEAD(&uhci
->urb_list
);
2161 spin_lock_init(&uhci
->framelist_lock
);
2163 /* We need exactly one page (per UHCI specs), how convenient */
2164 /* We assume that one page is atleast 4k (1024 frames * 4 bytes) */
2165 uhci
->fl
= (void *)__get_free_page(GFP_KERNEL
);
2169 bus
= usb_alloc_bus(&uhci_device_operations
);
2176 /* Initialize the root hub */
2178 /* UHCI specs says devices must have 2 ports, but goes on to say */
2179 /* they may have more but give no way to determine how many they */
2180 /* have. However, according to the UHCI spec, Bit 7 is always set */
2181 /* to 1. So we try to use this to our advantage */
2182 for (port
= 0; port
< (io_size
- 0x10) / 2; port
++) {
2183 unsigned int portstatus
;
2185 portstatus
= inw(io_addr
+ 0x10 + (port
* 2));
2186 if (!(portstatus
& 0x0080))
2190 info("detected %d ports", port
);
2192 /* This is experimental so anything less than 2 or greater than 8 is */
2193 /* something weird and we'll ignore it */
2194 if (port
< 2 || port
> 8) {
2195 info("port count misdetected? forcing to 2 ports");
2199 uhci
->rh
.numports
= port
;
2202 * 9 Interrupt queues; link int2 to int1, int4 to int2, etc
2203 * then link int1 to control and control to bulk
2205 for (i
= 1; i
< 9; i
++) {
2206 struct uhci_td
*td
= &uhci
->skeltd
[i
];
2208 uhci_fill_td(td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2209 td
->link
= virt_to_bus(&uhci
->skeltd
[i
- 1]);
2213 uhci_fill_td(&uhci
->skel_int1_td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2214 uhci
->skel_int1_td
.link
= virt_to_bus(&uhci
->skel_ls_control_qh
) | UHCI_PTR_QH
;
2216 uhci
->skel_ls_control_qh
.link
= virt_to_bus(&uhci
->skel_hs_control_qh
) | UHCI_PTR_QH
;
2217 uhci
->skel_ls_control_qh
.element
= UHCI_PTR_TERM
;
2219 uhci
->skel_hs_control_qh
.link
= virt_to_bus(&uhci
->skel_bulk_qh
) | UHCI_PTR_QH
;
2220 uhci
->skel_hs_control_qh
.element
= UHCI_PTR_TERM
;
2222 uhci
->skel_bulk_qh
.link
= virt_to_bus(&uhci
->skel_term_qh
) | UHCI_PTR_QH
;
2223 uhci
->skel_bulk_qh
.element
= UHCI_PTR_TERM
;
2225 /* This dummy TD is to work around a bug in Intel PIIX controllers */
2226 uhci_fill_td(&uhci
->skel_term_td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2227 uhci
->skel_term_td
.link
= UHCI_PTR_TERM
;
2229 uhci
->skel_term_qh
.link
= UHCI_PTR_TERM
;
2230 uhci
->skel_term_qh
.element
= virt_to_bus(&uhci
->skel_term_td
);
2233 * Fill the frame list: make all entries point to
2234 * the proper interrupt queue.
2236 * This is probably silly, but it's a simple way to
2237 * scatter the interrupt queues in a way that gives
2238 * us a reasonable dynamic range for irq latencies.
2240 for (i
= 0; i
< 1024; i
++) {
2241 struct uhci_td
*irq
= &uhci
->skel_int1_td
;
2264 /* Only place we don't use the frame list routines */
2265 uhci
->fl
->frame
[i
] = virt_to_bus(irq
);
2274 free_page((unsigned long)uhci
->fl
);
2282 * De-allocate all resources..
2284 static void release_uhci(struct uhci
*uhci
)
2286 if (uhci
->irq
>= 0) {
2287 free_irq(uhci
->irq
, uhci
);
2292 free_page((unsigned long)uhci
->fl
);
2296 usb_free_bus(uhci
->bus
);
2300 int uhci_start_root_hub(struct uhci
*uhci
)
2302 struct usb_device
*dev
;
2304 dev
= usb_alloc_dev(NULL
, uhci
->bus
);
2308 uhci
->bus
->root_hub
= dev
;
2311 if (usb_new_device(dev
) != 0) {
2321 * If we've successfully found a UHCI, now is the time to increment the
2322 * module usage count, and return success..
2324 static int setup_uhci(struct pci_dev
*dev
, int irq
, unsigned int io_addr
, unsigned int io_size
)
2328 char buf
[8], *bufp
= buf
;
2331 sprintf(buf
, "%d", irq
);
2333 bufp
= __irq_itoa(irq
);
2335 printk(KERN_INFO __FILE__
": USB UHCI at I/O 0x%x, IRQ %s\n",
2338 uhci
= alloc_uhci(io_addr
, io_size
);
2342 INIT_LIST_HEAD(&uhci
->uhci_list
);
2343 list_add(&uhci
->uhci_list
, &uhci_list
);
2345 request_region(uhci
->io_addr
, io_size
, "usb-uhci");
2349 usb_register_bus(uhci
->bus
);
2353 if (request_irq(irq
, uhci_interrupt
, SA_SHIRQ
, "usb-uhci", uhci
) == 0) {
2356 if (!uhci_start_root_hub(uhci
)) {
2357 struct pm_dev
*pmdev
;
2359 pmdev
= pm_register(PM_PCI_DEV
,
2368 /* Couldn't allocate IRQ if we got here */
2369 list_del(&uhci
->uhci_list
);
2370 INIT_LIST_HEAD(&uhci
->uhci_list
);
2373 release_region(uhci
->io_addr
, uhci
->io_size
);
2379 static int found_uhci(struct pci_dev
*dev
)
2383 /* disable legacy emulation */
2384 pci_write_config_word(dev
, USBLEGSUP
, USBLEGSUP_DEFAULT
);
2386 if (pci_enable_device(dev
) < 0)
2390 err("found UHCI device with no IRQ assigned. check BIOS settings!");
2394 /* Search for the IO base address.. */
2395 for (i
= 0; i
< 6; i
++) {
2396 unsigned int io_addr
= pci_resource_start(dev
, i
);
2397 unsigned int io_size
= pci_resource_len(dev
, i
);
2400 if (!(pci_resource_flags(dev
, i
) & IORESOURCE_IO
))
2403 /* Is it already in use? */
2404 if (check_region(io_addr
, io_size
))
2407 return setup_uhci(dev
, dev
->irq
, io_addr
, io_size
);
2413 static int handle_pm_event(struct pm_dev
*dev
, pm_request_t rqst
, void *data
)
2415 struct uhci
*uhci
= dev
->data
;
2431 struct pci_dev
*dev
;
2436 /* We throw all of the TD's and QH's into a kmem cache */
2437 /* TD's and QH's need to be 16 byte aligned and SLAB_HWCACHE_ALIGN */
2438 /* does this for us */
2439 uhci_td_cachep
= kmem_cache_create("uhci_td",
2440 sizeof(struct uhci_td
), 0,
2441 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2443 if (!uhci_td_cachep
)
2446 uhci_qh_cachep
= kmem_cache_create("uhci_qh",
2447 sizeof(struct uhci_qh
), 0,
2448 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2450 if (!uhci_qh_cachep
)
2453 uhci_up_cachep
= kmem_cache_create("uhci_urb_priv",
2454 sizeof(struct urb_priv
), 0, 0, NULL
, NULL
);
2456 if (!uhci_up_cachep
)
2462 dev
= pci_find_class(PCI_CLASS_SERIAL_USB
<< 8, dev
);
2466 /* Is it the UHCI programming interface? */
2467 pci_read_config_byte(dev
, PCI_CLASS_PROG
, &type
);
2472 retval
= found_uhci(dev
);
2475 /* We only want to return an error code if ther was an error */
2476 /* and we didn't find a UHCI controller */
2477 if (retval
&& list_empty(&uhci_list
))
2483 if (kmem_cache_destroy(uhci_up_cachep
))
2484 printk(KERN_INFO
"uhci: not all urb_priv's were freed\n");
2487 if (kmem_cache_destroy(uhci_qh_cachep
))
2488 printk(KERN_INFO
"uhci: not all QH's were freed\n");
2491 if (kmem_cache_destroy(uhci_td_cachep
))
2492 printk(KERN_INFO
"uhci: not all TD's were freed\n");
2498 void uhci_cleanup(void)
2500 struct list_head
*tmp
, *head
= &uhci_list
;
2503 while (tmp
!= head
) {
2504 struct uhci
*uhci
= list_entry(tmp
, struct uhci
, uhci_list
);
2508 list_del(&uhci
->uhci_list
);
2509 INIT_LIST_HEAD(&uhci
->uhci_list
);
2511 if (uhci
->bus
->root_hub
)
2512 usb_disconnect(&uhci
->bus
->root_hub
);
2514 usb_deregister_bus(uhci
->bus
);
2517 release_region(uhci
->io_addr
, uhci
->io_size
);
2519 uhci_free_pending_qhs(uhci
);
2524 if (kmem_cache_destroy(uhci_up_cachep
))
2525 printk(KERN_INFO
"uhci: not all urb_priv's were freed\n");
2527 if (kmem_cache_destroy(uhci_qh_cachep
))
2528 printk(KERN_INFO
"uhci: not all QH's were freed\n");
2530 if (kmem_cache_destroy(uhci_td_cachep
))
2531 printk(KERN_INFO
"uhci: not all TD's were freed\n");
2535 int init_module(void)
2540 void cleanup_module(void)
2542 pm_unregister_all(handle_pm_event
);
2546 MODULE_AUTHOR("Linus Torvalds, Johannes Erdfelt, Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber");
2547 MODULE_DESCRIPTION("USB Universal Host Controller Interface driver");