2 * Universal Host Controller Interface driver for USB.
4 * (C) Copyright 1999 Linus Torvalds
5 * (C) Copyright 1999-2000 Johannes Erdfelt, johannes@erdfelt.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
11 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
12 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
13 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * Intel documents this fairly well, and as far as I know there
17 * are no royalties or anything like that, but even so there are
18 * people who decided that they want to do the same thing in a
19 * completely different way.
21 * WARNING! The USB documentation is downright evil. Most of it
22 * is just crap, written by a committee. You're better off ignoring
23 * most of it, the important stuff is:
24 * - the low-level protocol (fairly simple but lots of small details)
25 * - working around the horridness of the rest
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/ioport.h>
34 #include <linux/sched.h>
35 #include <linux/malloc.h>
36 #include <linux/smp_lock.h>
37 #include <linux/errno.h>
38 #include <linux/unistd.h>
39 #include <linux/interrupt.h>
40 #include <linux/spinlock.h>
42 #include <linux/usb.h>
44 #include <asm/uaccess.h>
47 #include <asm/system.h>
50 #include "uhci-debug.h"
55 MODULE_PARM(debug
, "i");
56 MODULE_PARM_DESC(debug
, "Debug level");
58 static kmem_cache_t
*uhci_td_cachep
;
59 static kmem_cache_t
*uhci_qh_cachep
;
60 static kmem_cache_t
*uhci_up_cachep
; /* urb_priv */
62 static int rh_submit_urb(struct urb
*urb
);
63 static int rh_unlink_urb(struct urb
*urb
);
64 static int uhci_get_current_frame_number(struct usb_device
*dev
);
65 static int uhci_unlink_generic(struct urb
*urb
);
66 static int uhci_unlink_urb(struct urb
*urb
);
68 #define min(a,b) (((a)<(b))?(a):(b))
70 /* If a transfer is still active after this much time, turn off FSBR */
71 #define IDLE_TIMEOUT (HZ / 20) /* 50 ms */
74 * Only the USB core should call uhci_alloc_dev and uhci_free_dev
76 static int uhci_alloc_dev(struct usb_device
*dev
)
81 static int uhci_free_dev(struct usb_device
*dev
)
83 struct uhci
*uhci
= (struct uhci
*)dev
->bus
->hcpriv
;
84 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
87 /* Walk through the entire URB list and forcefully remove any */
88 /* URBs that are still active for that device */
89 nested_lock(&uhci
->urblist_lock
, flags
);
92 struct urb
*u
= list_entry(tmp
, struct urb
, urb_list
);
99 nested_unlock(&uhci
->urblist_lock
, flags
);
104 static void uhci_add_urb_list(struct uhci
*uhci
, struct urb
*urb
)
108 nested_lock(&uhci
->urblist_lock
, flags
);
109 list_add(&urb
->urb_list
, &uhci
->urb_list
);
110 nested_unlock(&uhci
->urblist_lock
, flags
);
113 static void uhci_remove_urb_list(struct uhci
*uhci
, struct urb
*urb
)
117 nested_lock(&uhci
->urblist_lock
, flags
);
118 if (!list_empty(&urb
->urb_list
)) {
119 list_del(&urb
->urb_list
);
120 INIT_LIST_HEAD(&urb
->urb_list
);
122 nested_unlock(&uhci
->urblist_lock
, flags
);
125 void uhci_set_next_interrupt(struct uhci
*uhci
)
129 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
130 uhci
->skel_term_td
.status
|= TD_CTRL_IOC
;
131 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
134 void uhci_clear_next_interrupt(struct uhci
*uhci
)
138 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
139 uhci
->skel_term_td
.status
&= ~TD_CTRL_IOC
;
140 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
143 static struct uhci_td
*uhci_alloc_td(struct usb_device
*dev
)
147 td
= kmem_cache_alloc(uhci_td_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
151 td
->link
= UHCI_PTR_TERM
;
155 td
->nexttd
= td
->prevtd
= NULL
;
157 INIT_LIST_HEAD(&td
->list
);
159 usb_inc_dev_use(dev
);
164 static void inline uhci_fill_td(struct uhci_td
*td
, __u32 status
,
165 __u32 info
, __u32 buffer
)
172 static void uhci_insert_td(struct uhci
*uhci
, struct uhci_td
*skeltd
, struct uhci_td
*td
)
176 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
178 /* Fix the linked list pointers */
179 td
->nexttd
= skeltd
->nexttd
;
182 skeltd
->nexttd
->prevtd
= td
;
185 td
->link
= skeltd
->link
;
186 skeltd
->link
= virt_to_bus(td
);
188 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
192 * We insert Isochronous transfers directly into the frame list at the
194 * The layout looks as follows:
195 * frame list pointer -> iso td's (if any) ->
196 * periodic interrupt td (if frame 0) -> irq td's -> control qh -> bulk qh
199 static void uhci_insert_td_frame_list(struct uhci
*uhci
, struct uhci_td
*td
, unsigned framenum
)
202 struct uhci_td
*nexttd
;
204 framenum
%= UHCI_NUMFRAMES
;
206 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
208 td
->frameptr
= &uhci
->fl
->frame
[framenum
];
209 td
->link
= uhci
->fl
->frame
[framenum
];
210 if (!(td
->link
& (UHCI_PTR_TERM
| UHCI_PTR_QH
))) {
211 nexttd
= (struct uhci_td
*)uhci_ptr_to_virt(td
->link
);
214 nexttd
->frameptr
= NULL
;
216 uhci
->fl
->frame
[framenum
] = virt_to_bus(td
);
218 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
221 static void uhci_remove_td(struct uhci
*uhci
, struct uhci_td
*td
)
225 /* If it's not inserted, don't remove it */
226 if (!td
->frameptr
&& !td
->prevtd
&& !td
->nexttd
)
229 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
231 *(td
->frameptr
) = td
->link
;
233 td
->nexttd
->frameptr
= td
->frameptr
;
234 td
->nexttd
->prevtd
= NULL
;
240 td
->prevtd
->nexttd
= td
->nexttd
;
241 td
->prevtd
->link
= td
->link
;
244 td
->nexttd
->prevtd
= td
->prevtd
;
245 td
->prevtd
= td
->nexttd
= NULL
;
247 td
->link
= UHCI_PTR_TERM
;
248 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
252 * Inserts a td into qh list at the top.
254 static void uhci_insert_tds_in_qh(struct uhci_qh
*qh
, struct urb
*urb
, int breadth
)
256 struct list_head
*tmp
, *head
;
257 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
258 struct uhci_td
*td
, *prevtd
;
268 td
= list_entry(tmp
, struct uhci_td
, list
);
270 /* Add the first TD to the QH element pointer */
271 qh
->element
= virt_to_bus(td
) | (breadth
? 0 : UHCI_PTR_DEPTH
);
275 /* Then link the rest of the TD's */
277 while (tmp
!= head
) {
278 td
= list_entry(tmp
, struct uhci_td
, list
);
282 prevtd
->link
= virt_to_bus(td
) | (breadth
? 0 : UHCI_PTR_DEPTH
);
287 prevtd
->link
= UHCI_PTR_TERM
;
290 static void uhci_free_td(struct uhci_td
*td
)
292 if (!list_empty(&td
->list
))
293 dbg("td is still in URB list!");
296 usb_dec_dev_use(td
->dev
);
298 kmem_cache_free(uhci_td_cachep
, td
);
301 static struct uhci_qh
*uhci_alloc_qh(struct usb_device
*dev
)
305 qh
= kmem_cache_alloc(uhci_qh_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
309 qh
->element
= UHCI_PTR_TERM
;
310 qh
->link
= UHCI_PTR_TERM
;
313 qh
->prevqh
= qh
->nextqh
= NULL
;
315 INIT_LIST_HEAD(&qh
->remove_list
);
317 usb_inc_dev_use(dev
);
322 static void uhci_free_qh(struct uhci_qh
*qh
)
325 usb_dec_dev_use(qh
->dev
);
327 kmem_cache_free(uhci_qh_cachep
, qh
);
330 static void uhci_insert_qh(struct uhci
*uhci
, struct uhci_qh
*skelqh
, struct uhci_qh
*qh
)
334 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
336 /* Fix the linked list pointers */
337 qh
->nextqh
= skelqh
->nextqh
;
340 skelqh
->nextqh
->prevqh
= qh
;
343 qh
->link
= skelqh
->link
;
344 skelqh
->link
= virt_to_bus(qh
) | UHCI_PTR_QH
;
346 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
349 static void uhci_remove_qh(struct uhci
*uhci
, struct uhci_qh
*qh
)
354 /* If the QH isn't queued, then we don't need to delay unlink it */
355 delayed
= (qh
->prevqh
|| qh
->nextqh
);
357 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
359 qh
->prevqh
->nextqh
= qh
->nextqh
;
360 qh
->prevqh
->link
= qh
->link
;
363 qh
->nextqh
->prevqh
= qh
->prevqh
;
364 qh
->prevqh
= qh
->nextqh
= NULL
;
365 qh
->element
= qh
->link
= UHCI_PTR_TERM
;
366 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
369 spin_lock_irqsave(&uhci
->qh_remove_lock
, flags
);
371 /* Check to see if the remove list is empty */
372 /* Set the IOC bit to force an interrupt so we can remove the QH */
373 if (list_empty(&uhci
->qh_remove_list
))
374 uhci_set_next_interrupt(uhci
);
377 list_add(&qh
->remove_list
, &uhci
->qh_remove_list
);
379 spin_unlock_irqrestore(&uhci
->qh_remove_lock
, flags
);
384 static spinlock_t uhci_append_urb_lock
= SPIN_LOCK_UNLOCKED
;
386 /* This function will append one URB's QH to another URB's QH. This is for */
387 /* USB_QUEUE_BULK support */
388 static void uhci_append_queued_urb(struct uhci
*uhci
, struct urb
*eurb
, struct urb
*urb
)
390 struct urb_priv
*eurbp
, *urbp
, *furbp
, *lurbp
;
391 struct list_head
*tmp
;
392 struct uhci_td
*td
, *ltd
;
395 eurbp
= eurb
->hcpriv
;
398 spin_lock_irqsave(&uhci_append_urb_lock
, flags
);
400 /* Find the beginning URB in the queue */
402 struct list_head
*head
= &eurbp
->urb_queue_list
;
405 while (tmp
!= head
) {
406 struct urb_priv
*turbp
=
407 list_entry(tmp
, struct urb_priv
, urb_queue_list
);
415 tmp
= &eurbp
->urb_queue_list
;
417 furbp
= list_entry(tmp
, struct urb_priv
, urb_queue_list
);
419 tmp
= furbp
->urb_queue_list
.prev
;
420 lurbp
= list_entry(tmp
, struct urb_priv
, urb_queue_list
);
422 /* Add this one to the end */
423 list_add_tail(&urbp
->urb_queue_list
, &furbp
->urb_queue_list
);
425 /* Grab the last TD from the last URB */
426 ltd
= list_entry(lurbp
->list
.prev
, struct uhci_td
, list
);
428 /* Grab the first TD from the first URB */
429 td
= list_entry(urbp
->list
.next
, struct uhci_td
, list
);
431 /* No breadth since this will only be called for bulk transfers */
432 ltd
->link
= virt_to_bus(td
);
434 spin_unlock_irqrestore(&uhci_append_urb_lock
, flags
);
437 static void uhci_delete_queued_urb(struct uhci
*uhci
, struct urb
*urb
)
439 struct urb_priv
*urbp
, *nurbp
;
444 spin_lock_irqsave(&uhci_append_urb_lock
, flags
);
446 nurbp
= list_entry(urbp
->urb_queue_list
.next
, struct urb_priv
,
450 /* We're the head, so just insert the QH for the next URB */
451 uhci_insert_qh(uhci
, &uhci
->skel_bulk_qh
, nurbp
->qh
);
454 struct urb_priv
*purbp
;
457 /* We're somewhere in the middle (or end). A bit trickier */
458 /* than the head scenario */
459 purbp
= list_entry(urbp
->urb_queue_list
.prev
, struct urb_priv
,
462 ptd
= list_entry(purbp
->list
.prev
, struct uhci_td
, list
);
464 /* Close the gap between the two */
465 ptd
->link
= virt_to_bus(list_entry(nurbp
->list
.next
,
466 struct uhci_td
, list
));
468 /* The next URB happens to be the beggining, so */
469 /* we're the last, end the chain */
470 ptd
->link
= UHCI_PTR_TERM
;
474 list_del(&urbp
->urb_queue_list
);
476 spin_unlock_irqrestore(&uhci_append_urb_lock
, flags
);
479 struct urb_priv
*uhci_alloc_urb_priv(struct urb
*urb
)
481 struct urb_priv
*urbp
;
483 urbp
= kmem_cache_alloc(uhci_up_cachep
, in_interrupt() ? SLAB_ATOMIC
: SLAB_KERNEL
);
487 memset((void *)urbp
, 0, sizeof(*urbp
));
489 urbp
->inserttime
= jiffies
;
492 INIT_LIST_HEAD(&urbp
->list
);
493 INIT_LIST_HEAD(&urbp
->urb_queue_list
);
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
);
559 spin_unlock_irqrestore(&urb
->lock
, flags
);
562 static void uhci_inc_fsbr(struct uhci
*uhci
, struct urb
*urb
)
565 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
570 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
572 if ((!(urb
->transfer_flags
& USB_NO_FSBR
)) && (!urbp
->fsbr
)) {
575 uhci
->skel_term_qh
.link
= virt_to_bus(&uhci
->skel_hs_control_qh
) | UHCI_PTR_QH
;
578 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
581 static void uhci_dec_fsbr(struct uhci
*uhci
, struct urb
*urb
)
584 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
589 spin_lock_irqsave(&uhci
->framelist_lock
, flags
);
591 if ((!(urb
->transfer_flags
& USB_NO_FSBR
)) && urbp
->fsbr
) {
594 uhci
->skel_term_qh
.link
= UHCI_PTR_TERM
;
597 spin_unlock_irqrestore(&uhci
->framelist_lock
, flags
);
601 * Map status to standard result codes
603 * <status> is (td->status & 0xFE0000) [a.k.a. uhci_status_bits(td->status)]
604 * <dir_out> is True for output TDs and False for input TDs.
606 static int uhci_map_status(int status
, int dir_out
)
610 if (status
& TD_CTRL_BITSTUFF
) /* Bitstuff error */
612 if (status
& TD_CTRL_CRCTIMEO
) { /* CRC/Timeout */
618 if (status
& TD_CTRL_NAK
) /* NAK */
620 if (status
& TD_CTRL_BABBLE
) /* Babble */
622 if (status
& TD_CTRL_DBUFERR
) /* Buffer error */
624 if (status
& TD_CTRL_STALLED
) /* Stalled */
626 if (status
& TD_CTRL_ACTIVE
) /* Active */
635 static int uhci_submit_control(struct urb
*urb
)
637 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
638 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
641 unsigned long destination
, status
;
642 int maxsze
= usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
));
643 int len
= urb
->transfer_buffer_length
;
644 unsigned char *data
= urb
->transfer_buffer
;
646 /* The "pipe" thing contains the destination in bits 8--18 */
647 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | USB_PID_SETUP
;
650 status
= (urb
->pipe
& TD_CTRL_LS
) | TD_CTRL_ACTIVE
| (3 << 27);
653 * Build the TD for the control request
655 td
= uhci_alloc_td(urb
->dev
);
659 uhci_add_td_to_urb(urb
, td
);
660 uhci_fill_td(td
, status
, destination
| (7 << 21),
661 virt_to_bus(urb
->setup_packet
));
664 * If direction is "send", change the frame from SETUP (0x2D)
665 * to OUT (0xE1). Else change it from SETUP to IN (0x69).
667 destination
^= (USB_PID_SETUP
^ usb_packetid(urb
->pipe
));
669 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
))
670 status
|= TD_CTRL_SPD
;
673 * Build the DATA TD's
681 td
= uhci_alloc_td(urb
->dev
);
685 /* Alternate Data0/1 (start with Data1) */
686 destination
^= 1 << TD_TOKEN_TOGGLE
;
688 uhci_add_td_to_urb(urb
, td
);
689 uhci_fill_td(td
, status
, destination
| ((pktsze
- 1) << 21),
697 * Build the final TD for control status
699 td
= uhci_alloc_td(urb
->dev
);
704 * It's IN if the pipe is an output pipe or we're not expecting
707 destination
&= ~TD_PID
;
708 if (usb_pipeout(urb
->pipe
) || !urb
->transfer_buffer_length
)
709 destination
|= USB_PID_IN
;
711 destination
|= USB_PID_OUT
;
713 destination
|= 1 << TD_TOKEN_TOGGLE
; /* End in Data1 */
715 status
&= ~TD_CTRL_SPD
;
717 uhci_add_td_to_urb(urb
, td
);
718 uhci_fill_td(td
, status
| TD_CTRL_IOC
,
719 destination
| (UHCI_NULL_DATA_SIZE
<< 21), 0);
721 qh
= uhci_alloc_qh(urb
->dev
);
725 /* Low speed or small transfers gets a different queue and treatment */
726 if (urb
->pipe
& TD_CTRL_LS
) {
727 uhci_insert_tds_in_qh(qh
, urb
, 0);
728 uhci_insert_qh(uhci
, &uhci
->skel_ls_control_qh
, qh
);
730 uhci_insert_tds_in_qh(qh
, urb
, 1);
731 uhci_insert_qh(uhci
, &uhci
->skel_hs_control_qh
, qh
);
732 uhci_inc_fsbr(uhci
, urb
);
737 uhci_add_urb_list(uhci
, urb
);
742 static int usb_control_retrigger_status(struct urb
*urb
);
744 static int uhci_result_control(struct urb
*urb
)
746 struct list_head
*tmp
, *head
;
747 struct urb_priv
*urbp
= urb
->hcpriv
;
756 if (head
->next
== head
)
759 if (urbp
->short_control_packet
) {
765 td
= list_entry(tmp
, struct uhci_td
, list
);
767 /* The first TD is the SETUP phase, check the status, but skip */
769 status
= uhci_status_bits(td
->status
);
770 if (status
& TD_CTRL_ACTIVE
)
776 urb
->actual_length
= 0;
778 /* The rest of the TD's (but the last) are data */
780 while (tmp
!= head
&& tmp
->next
!= head
) {
781 td
= list_entry(tmp
, struct uhci_td
, list
);
785 if (urbp
->fsbr_timeout
&& (td
->status
& TD_CTRL_IOC
) &&
786 !(td
->status
& TD_CTRL_ACTIVE
)) {
787 uhci_inc_fsbr(urb
->dev
->bus
->hcpriv
, urb
);
788 urbp
->fsbr_timeout
= 0;
789 td
->status
&= ~TD_CTRL_IOC
;
792 status
= uhci_status_bits(td
->status
);
793 if (status
& TD_CTRL_ACTIVE
)
796 urb
->actual_length
+= uhci_actual_length(td
->status
);
801 /* Check to see if we received a short packet */
802 if (uhci_actual_length(td
->status
) < uhci_expected_length(td
->info
)) {
803 if (urb
->transfer_flags
& USB_DISABLE_SPD
) {
808 if (uhci_packetid(td
->info
) == USB_PID_IN
)
809 return usb_control_retrigger_status(urb
);
816 td
= list_entry(tmp
, struct uhci_td
, list
);
818 /* Control status phase */
819 status
= uhci_status_bits(td
->status
);
821 #ifdef I_HAVE_BUGGY_APC_BACKUPS
822 /* APC BackUPS Pro kludge */
823 /* It tries to send all of the descriptor instead of the amount */
825 if (td
->status
& TD_CTRL_IOC
&& /* IOC is masked out by uhci_status_bits */
826 status
& TD_CTRL_ACTIVE
&&
827 status
& TD_CTRL_NAK
)
831 if (status
& TD_CTRL_ACTIVE
)
840 ret
= uhci_map_status(status
, uhci_packetout(td
->info
));
842 /* endpoint has stalled - mark it halted */
843 usb_endpoint_halt(urb
->dev
, uhci_endpoint(td
->info
),
844 uhci_packetout(td
->info
));
847 if (debug
&& ret
!= -EPIPE
) {
848 /* Some debugging code */
849 dbg("uhci_result_control() failed with status %x", status
);
851 /* Print the chain for debugging purposes */
852 uhci_show_urb_queue(urb
);
858 static int usb_control_retrigger_status(struct urb
*urb
)
860 struct list_head
*tmp
, *head
;
861 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
862 struct uhci
*uhci
= urb
->dev
->bus
->hcpriv
;
864 urbp
->short_control_packet
= 1;
866 /* Create a new QH to avoid pointer overwriting problems */
867 uhci_remove_qh(uhci
, urbp
->qh
);
869 /* Delete all of the TD's except for the status TD at the end */
872 while (tmp
!= head
&& tmp
->next
!= head
) {
873 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
877 uhci_remove_td_from_urb(urb
, td
);
879 uhci_remove_td(uhci
, td
);
884 urbp
->qh
= uhci_alloc_qh(urb
->dev
);
886 err("unable to allocate new QH for control retrigger");
890 /* One TD, who cares about Breadth first? */
891 uhci_insert_tds_in_qh(urbp
->qh
, urb
, 0);
893 /* Low speed or small transfers gets a different queue and treatment */
894 if (urb
->pipe
& TD_CTRL_LS
)
895 uhci_insert_qh(uhci
, &uhci
->skel_ls_control_qh
, urbp
->qh
);
897 uhci_insert_qh(uhci
, &uhci
->skel_hs_control_qh
, urbp
->qh
);
903 * Interrupt transfers
905 static int uhci_submit_interrupt(struct urb
*urb
)
908 unsigned long destination
, status
;
909 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
911 if (urb
->transfer_buffer_length
> usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
)))
914 /* The "pipe" thing contains the destination in bits 8--18 */
915 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
917 status
= (urb
->pipe
& TD_CTRL_LS
) | TD_CTRL_ACTIVE
| TD_CTRL_IOC
;
919 td
= uhci_alloc_td(urb
->dev
);
923 destination
|= (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
);
924 destination
|= ((urb
->transfer_buffer_length
- 1) << 21);
926 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
));
928 uhci_add_td_to_urb(urb
, td
);
929 uhci_fill_td(td
, status
, destination
,
930 virt_to_bus(urb
->transfer_buffer
));
932 uhci_insert_td(uhci
, &uhci
->skeltd
[__interval_to_skel(urb
->interval
)], td
);
934 uhci_add_urb_list(uhci
, urb
);
939 static int uhci_result_interrupt(struct urb
*urb
)
941 struct list_head
*tmp
, *head
;
942 struct urb_priv
*urbp
= urb
->hcpriv
;
950 urb
->actual_length
= 0;
954 while (tmp
!= head
) {
955 td
= list_entry(tmp
, struct uhci_td
, list
);
959 if (urbp
->fsbr_timeout
&& (td
->status
& TD_CTRL_IOC
) &&
960 !(td
->status
& TD_CTRL_ACTIVE
)) {
961 uhci_inc_fsbr(urb
->dev
->bus
->hcpriv
, urb
);
962 urbp
->fsbr_timeout
= 0;
963 td
->status
&= ~TD_CTRL_IOC
;
966 status
= uhci_status_bits(td
->status
);
967 if (status
& TD_CTRL_ACTIVE
)
970 urb
->actual_length
+= uhci_actual_length(td
->status
);
975 if (uhci_actual_length(td
->status
) < uhci_expected_length(td
->info
)) {
976 usb_settoggle(urb
->dev
, uhci_endpoint(td
->info
),
977 uhci_packetout(td
->info
),
978 uhci_toggle(td
->info
) ^ 1);
980 if (urb
->transfer_flags
& USB_DISABLE_SPD
) {
991 ret
= uhci_map_status(status
, uhci_packetout(td
->info
));
993 /* endpoint has stalled - mark it halted */
994 usb_endpoint_halt(urb
->dev
, uhci_endpoint(td
->info
),
995 uhci_packetout(td
->info
));
998 if (debug
&& ret
!= -EPIPE
) {
999 /* Some debugging code */
1000 dbg("uhci_result_interrupt/bulk() failed with status %x",
1003 /* Print the chain for debugging purposes */
1005 uhci_show_urb_queue(urb
);
1013 static void uhci_reset_interrupt(struct urb
*urb
)
1015 struct list_head
*tmp
;
1016 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1022 tmp
= urbp
->list
.next
;
1023 td
= list_entry(tmp
, struct uhci_td
, list
);
1027 td
->status
= (td
->status
& 0x2F000000) | TD_CTRL_ACTIVE
| TD_CTRL_IOC
;
1028 td
->info
&= ~(1 << TD_TOKEN_TOGGLE
);
1029 td
->info
|= (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
);
1030 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
));
1032 urb
->status
= -EINPROGRESS
;
1038 static int uhci_submit_bulk(struct urb
*urb
, struct urb
*eurb
)
1042 unsigned long destination
, status
;
1043 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1044 int maxsze
= usb_maxpacket(urb
->dev
, urb
->pipe
, usb_pipeout(urb
->pipe
));
1045 int len
= urb
->transfer_buffer_length
;
1046 unsigned char *data
= urb
->transfer_buffer
;
1047 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1052 /* Can't have low speed bulk transfers */
1053 if (urb
->pipe
& TD_CTRL_LS
)
1056 /* The "pipe" thing contains the destination in bits 8--18 */
1057 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
1060 status
= TD_CTRL_ACTIVE
| (3 << TD_CTRL_C_ERR_SHIFT
);
1062 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
))
1063 status
|= TD_CTRL_SPD
;
1066 * Build the DATA TD's
1068 do { /* Allow zero length packets */
1071 if (pktsze
> maxsze
)
1074 td
= uhci_alloc_td(urb
->dev
);
1078 uhci_add_td_to_urb(urb
, td
);
1079 uhci_fill_td(td
, status
, destination
| ((pktsze
- 1) << 21) |
1080 (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
1081 usb_pipeout(urb
->pipe
)) << TD_TOKEN_TOGGLE
),
1088 td
->status
|= TD_CTRL_IOC
;
1090 usb_dotoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
1091 usb_pipeout(urb
->pipe
));
1094 qh
= uhci_alloc_qh(urb
->dev
);
1100 /* Always assume depth first */
1101 uhci_insert_tds_in_qh(qh
, urb
, 1);
1103 if (urb
->transfer_flags
& USB_QUEUE_BULK
&& eurb
) {
1105 uhci_append_queued_urb(uhci
, eurb
, urb
);
1107 uhci_insert_qh(uhci
, &uhci
->skel_bulk_qh
, qh
);
1109 uhci_add_urb_list(uhci
, urb
);
1111 uhci_inc_fsbr(uhci
, urb
);
1113 return -EINPROGRESS
;
1116 /* We can use the result interrupt since they're identical */
1117 #define uhci_result_bulk uhci_result_interrupt
1120 * Isochronous transfers
1122 static int isochronous_find_limits(struct urb
*urb
, unsigned int *start
, unsigned int *end
)
1124 struct urb
*last_urb
= NULL
;
1125 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1126 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1128 unsigned long flags
;
1130 nested_lock(&uhci
->urblist_lock
, flags
);
1132 while (tmp
!= head
) {
1133 struct urb
*u
= list_entry(tmp
, struct urb
, urb_list
);
1137 /* look for pending URB's with identical pipe handle */
1138 if ((urb
->pipe
== u
->pipe
) && (urb
->dev
== u
->dev
) &&
1139 (u
->status
== -EINPROGRESS
) && (u
!= urb
)) {
1141 *start
= u
->start_frame
;
1147 *end
= (last_urb
->start_frame
+ last_urb
->number_of_packets
) & 1023;
1150 ret
= -1; /* no previous urb found */
1152 nested_unlock(&uhci
->urblist_lock
, flags
);
1157 static int isochronous_find_start(struct urb
*urb
)
1160 unsigned int start
= 0, end
= 0;
1162 if (urb
->number_of_packets
> 900) /* 900? Why? */
1165 limits
= isochronous_find_limits(urb
, &start
, &end
);
1167 if (urb
->transfer_flags
& USB_ISO_ASAP
) {
1171 curframe
= uhci_get_current_frame_number(urb
->dev
) % UHCI_NUMFRAMES
;
1172 urb
->start_frame
= (curframe
+ 10) % UHCI_NUMFRAMES
;
1174 urb
->start_frame
= end
;
1176 urb
->start_frame
%= UHCI_NUMFRAMES
;
1177 /* FIXME: Sanity check */
1183 static int uhci_submit_isochronous(struct urb
*urb
)
1186 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1187 int i
, ret
, framenum
;
1188 int status
, destination
;
1190 status
= TD_CTRL_ACTIVE
| TD_CTRL_IOS
;
1191 destination
= (urb
->pipe
& PIPE_DEVEP_MASK
) | usb_packetid(urb
->pipe
);
1193 ret
= isochronous_find_start(urb
);
1197 framenum
= urb
->start_frame
;
1198 for (i
= 0; i
< urb
->number_of_packets
; i
++, framenum
++) {
1199 if (!urb
->iso_frame_desc
[i
].length
)
1202 td
= uhci_alloc_td(urb
->dev
);
1206 uhci_add_td_to_urb(urb
, td
);
1207 uhci_fill_td(td
, status
, destination
| ((urb
->iso_frame_desc
[i
].length
- 1) << 21),
1208 virt_to_bus(urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
));
1210 if (i
+ 1 >= urb
->number_of_packets
)
1211 td
->status
|= TD_CTRL_IOC
;
1213 uhci_insert_td_frame_list(uhci
, td
, framenum
);
1216 uhci_add_urb_list(uhci
, urb
);
1218 return -EINPROGRESS
;
1221 static int uhci_result_isochronous(struct urb
*urb
)
1223 struct list_head
*tmp
, *head
;
1224 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1231 urb
->actual_length
= 0;
1236 while (tmp
!= head
) {
1237 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
1242 if (td
->status
& TD_CTRL_ACTIVE
)
1243 return -EINPROGRESS
;
1245 actlength
= uhci_actual_length(td
->status
);
1246 urb
->iso_frame_desc
[i
].actual_length
= actlength
;
1247 urb
->actual_length
+= actlength
;
1249 status
= uhci_map_status(uhci_status_bits(td
->status
), usb_pipeout(urb
->pipe
));
1250 urb
->iso_frame_desc
[i
].status
= status
;
1262 static struct urb
*uhci_find_urb_ep(struct uhci
*uhci
, struct urb
*urb
)
1264 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1265 unsigned long flags
;
1266 struct urb
*u
= NULL
;
1268 if (usb_pipeisoc(urb
->pipe
))
1271 nested_lock(&uhci
->urblist_lock
, flags
);
1273 while (tmp
!= head
) {
1274 u
= list_entry(tmp
, struct urb
, urb_list
);
1278 if (u
->dev
== urb
->dev
&&
1279 u
->pipe
== urb
->pipe
)
1285 nested_unlock(&uhci
->urblist_lock
, flags
);
1290 static int uhci_submit_urb(struct urb
*urb
)
1294 unsigned long flags
;
1301 if (!urb
->dev
|| !urb
->dev
->bus
|| !urb
->dev
->bus
->hcpriv
)
1304 uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1306 /* Short circuit the virtual root hub */
1307 if (usb_pipedevice(urb
->pipe
) == uhci
->rh
.devnum
)
1308 return rh_submit_urb(urb
);
1310 u
= uhci_find_urb_ep(uhci
, urb
);
1311 if (u
&& !(urb
->transfer_flags
& USB_QUEUE_BULK
))
1314 usb_inc_dev_use(urb
->dev
);
1315 spin_lock_irqsave(&urb
->lock
, flags
);
1317 if (!uhci_alloc_urb_priv(urb
)) {
1318 spin_unlock_irqrestore(&urb
->lock
, flags
);
1319 usb_dec_dev_use(urb
->dev
);
1324 switch (usb_pipetype(urb
->pipe
)) {
1326 ret
= uhci_submit_control(urb
);
1328 case PIPE_INTERRUPT
:
1329 if (urb
->bandwidth
== 0) { /* not yet checked/allocated */
1330 bustime
= usb_check_bandwidth(urb
->dev
, urb
);
1334 ret
= uhci_submit_interrupt(urb
);
1335 if (ret
== -EINPROGRESS
)
1336 usb_claim_bandwidth(urb
->dev
, urb
, bustime
, 0);
1338 } else /* bandwidth is already set */
1339 ret
= uhci_submit_interrupt(urb
);
1342 ret
= uhci_submit_bulk(urb
, u
);
1344 case PIPE_ISOCHRONOUS
:
1345 if (urb
->bandwidth
== 0) { /* not yet checked/allocated */
1346 if (urb
->number_of_packets
<= 0) {
1350 bustime
= usb_check_bandwidth(urb
->dev
, urb
);
1356 ret
= uhci_submit_isochronous(urb
);
1357 if (ret
== -EINPROGRESS
)
1358 usb_claim_bandwidth(urb
->dev
, urb
, bustime
, 1);
1359 } else /* bandwidth is already set */
1360 ret
= uhci_submit_isochronous(urb
);
1366 spin_unlock_irqrestore(&urb
->lock
, flags
);
1368 if (ret
== -EINPROGRESS
)
1371 uhci_unlink_generic(urb
);
1372 usb_dec_dev_use(urb
->dev
);
1379 * Return the result of a transfer
1381 * Must be called with urblist_lock acquired
1383 static void uhci_transfer_result(struct urb
*urb
)
1385 struct usb_device
*dev
= urb
->dev
;
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 */
1427 if (urb
->interval
) {
1429 uhci_reset_interrupt(urb
);
1433 /* Release bandwidth for Interrupt or Isoc. transfers */
1434 /* Spinlock needed ? */
1436 usb_release_bandwidth(urb
->dev
, urb
, 0);
1437 uhci_unlink_generic(urb
);
1444 if (turb
->status
!= -EINPROGRESS
) {
1450 } while (turb
&& turb
!= urb
&& turb
!= urb
->next
);
1452 if (turb
== urb
|| turb
== urb
->next
)
1456 if (urb
->complete
&& !proceed
) {
1458 if (!proceed
&& is_ring
)
1459 uhci_submit_urb(urb
);
1462 if (proceed
&& urb
->next
) {
1465 if (turb
->status
!= -EINPROGRESS
&&
1466 uhci_submit_urb(turb
) != 0)
1469 } while (turb
&& turb
!= urb
->next
);
1475 /* We decrement the usage count after we're done with everything */
1476 usb_dec_dev_use(dev
);
1479 static int uhci_unlink_generic(struct urb
*urb
)
1481 struct urb_priv
*urbp
= urb
->hcpriv
;
1482 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1487 uhci_dec_fsbr(uhci
, urb
); /* Safe since it checks */
1489 uhci_remove_urb_list(uhci
, urb
);
1492 /* The interrupt loop will reclaim the QH's */
1493 uhci_remove_qh(uhci
, urbp
->qh
);
1495 if (!list_empty(&urbp
->urb_queue_list
))
1496 uhci_delete_queued_urb(uhci
, urb
);
1498 uhci_destroy_urb_priv(urb
);
1505 static int uhci_unlink_urb(struct urb
*urb
)
1509 unsigned long flags
;
1514 if (!urb
->dev
|| !urb
->dev
->bus
)
1517 uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1519 /* Short circuit the virtual root hub */
1520 if (usb_pipedevice(urb
->pipe
) == uhci
->rh
.devnum
)
1521 return rh_unlink_urb(urb
);
1523 /* Release bandwidth for Interrupt or Isoc. transfers */
1524 /* Spinlock needed ? */
1525 if (urb
->bandwidth
) {
1526 switch (usb_pipetype(urb
->pipe
)) {
1527 case PIPE_INTERRUPT
:
1528 usb_release_bandwidth(urb
->dev
, urb
, 0);
1530 case PIPE_ISOCHRONOUS
:
1531 usb_release_bandwidth(urb
->dev
, urb
, 1);
1538 if (urb
->status
== -EINPROGRESS
) {
1539 uhci_unlink_generic(urb
);
1541 if (urb
->transfer_flags
& USB_ASYNC_UNLINK
) {
1542 urb
->status
= -ECONNABORTED
;
1544 spin_lock_irqsave(&uhci
->urb_remove_lock
, flags
);
1546 /* Check to see if the remove list is empty */
1547 if (list_empty(&uhci
->urb_remove_list
))
1548 uhci_set_next_interrupt(uhci
);
1550 list_add(&urb
->urb_list
, &uhci
->urb_remove_list
);
1552 spin_unlock_irqrestore(&uhci
->urb_remove_lock
, flags
);
1554 urb
->status
= -ENOENT
;
1556 if (in_interrupt()) { /* wait at least 1 frame */
1557 static int errorcount
= 10;
1560 dbg("uhci_unlink_urb called from interrupt for urb %p", urb
);
1563 schedule_timeout(1+1*HZ
/1000);
1573 static int uhci_fsbr_timeout(struct uhci
*uhci
, struct urb
*urb
)
1575 struct urb_priv
*urbp
= (struct urb_priv
*)urb
->hcpriv
;
1576 struct list_head
*head
, *tmp
;
1578 uhci_dec_fsbr(uhci
, urb
);
1580 /* There is a race with updating IOC in here, but it's not worth */
1581 /* trying to fix since this is merely an optimization. The only */
1582 /* time we'd lose is if the status of the packet got updated */
1583 /* and we'd be turning on FSBR next frame anyway, so it's a wash */
1584 urbp
->fsbr_timeout
= 1;
1588 while (tmp
!= head
) {
1589 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, list
);
1593 if (td
->status
& TD_CTRL_ACTIVE
) {
1594 td
->status
|= TD_CTRL_IOC
;
1603 * uhci_get_current_frame_number()
1605 * returns the current frame number for a USB bus/controller.
1607 static int uhci_get_current_frame_number(struct usb_device
*dev
)
1609 struct uhci
*uhci
= (struct uhci
*)dev
->bus
->hcpriv
;
1611 return inw(uhci
->io_addr
+ USBFRNUM
);
1614 struct usb_operations uhci_device_operations
= {
1617 uhci_get_current_frame_number
,
1622 /* -------------------------------------------------------------------
1624 ------------------------------------------------------------------- */
1626 static __u8 root_hub_dev_des
[] =
1628 0x12, /* __u8 bLength; */
1629 0x01, /* __u8 bDescriptorType; Device */
1630 0x00, /* __u16 bcdUSB; v1.0 */
1632 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1633 0x00, /* __u8 bDeviceSubClass; */
1634 0x00, /* __u8 bDeviceProtocol; */
1635 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1636 0x00, /* __u16 idVendor; */
1638 0x00, /* __u16 idProduct; */
1640 0x00, /* __u16 bcdDevice; */
1642 0x00, /* __u8 iManufacturer; */
1643 0x02, /* __u8 iProduct; */
1644 0x01, /* __u8 iSerialNumber; */
1645 0x01 /* __u8 bNumConfigurations; */
1649 /* Configuration descriptor */
1650 static __u8 root_hub_config_des
[] =
1652 0x09, /* __u8 bLength; */
1653 0x02, /* __u8 bDescriptorType; Configuration */
1654 0x19, /* __u16 wTotalLength; */
1656 0x01, /* __u8 bNumInterfaces; */
1657 0x01, /* __u8 bConfigurationValue; */
1658 0x00, /* __u8 iConfiguration; */
1659 0x40, /* __u8 bmAttributes;
1660 Bit 7: Bus-powered, 6: Self-powered,
1661 Bit 5 Remote-wakeup, 4..0: resvd */
1662 0x00, /* __u8 MaxPower; */
1665 0x09, /* __u8 if_bLength; */
1666 0x04, /* __u8 if_bDescriptorType; Interface */
1667 0x00, /* __u8 if_bInterfaceNumber; */
1668 0x00, /* __u8 if_bAlternateSetting; */
1669 0x01, /* __u8 if_bNumEndpoints; */
1670 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1671 0x00, /* __u8 if_bInterfaceSubClass; */
1672 0x00, /* __u8 if_bInterfaceProtocol; */
1673 0x00, /* __u8 if_iInterface; */
1676 0x07, /* __u8 ep_bLength; */
1677 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1678 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1679 0x03, /* __u8 ep_bmAttributes; Interrupt */
1680 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
1682 0xff /* __u8 ep_bInterval; 255 ms */
1685 static __u8 root_hub_hub_des
[] =
1687 0x09, /* __u8 bLength; */
1688 0x29, /* __u8 bDescriptorType; Hub-descriptor */
1689 0x02, /* __u8 bNbrPorts; */
1690 0x00, /* __u16 wHubCharacteristics; */
1692 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
1693 0x00, /* __u8 bHubContrCurrent; 0 mA */
1694 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
1695 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
1698 /*-------------------------------------------------------------------------*/
1699 /* prepare Interrupt pipe transaction data; HUB INTERRUPT ENDPOINT */
1700 static int rh_send_irq(struct urb
*urb
)
1703 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1704 unsigned int io_addr
= uhci
->io_addr
;
1707 for (i
= 0; i
< uhci
->rh
.numports
; i
++) {
1708 data
|= ((inw(io_addr
+ USBPORTSC1
+ i
* 2) & 0xa) > 0 ? (1 << (i
+ 1)) : 0);
1709 len
= (i
+ 1) / 8 + 1;
1712 *(__u16
*) urb
->transfer_buffer
= cpu_to_le16(data
);
1713 urb
->actual_length
= len
;
1714 urb
->status
= USB_ST_NOERROR
;
1716 if ((data
> 0) && (uhci
->rh
.send
!= 0)) {
1717 dbg("root-hub INT complete: port1: %x port2: %x data: %x",
1718 inw(io_addr
+ USBPORTSC1
), inw(io_addr
+ USBPORTSC2
), data
);
1722 return USB_ST_NOERROR
;
1725 /*-------------------------------------------------------------------------*/
1726 /* Virtual Root Hub INTs are polled by this timer every "interval" ms */
1727 static int rh_init_int_timer(struct urb
*urb
);
1729 static void rh_int_timer_do(unsigned long ptr
)
1731 struct urb
*urb
= (struct urb
*)ptr
;
1732 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1733 struct list_head
*tmp
, *head
= &uhci
->urb_list
;
1734 struct urb_priv
*urbp
;
1736 unsigned long flags
;
1738 if (uhci
->rh
.send
) {
1739 len
= rh_send_irq(urb
);
1741 urb
->actual_length
= len
;
1747 nested_lock(&uhci
->urblist_lock
, flags
);
1749 while (tmp
!= head
) {
1750 struct urb
*u
= list_entry(tmp
, urb_t
, urb_list
);
1754 urbp
= (struct urb_priv
*)u
->hcpriv
;
1756 /* Check if the FSBR timed out */
1757 if (urbp
->fsbr
&& time_after(urbp
->inserttime
+ IDLE_TIMEOUT
, jiffies
))
1758 uhci_fsbr_timeout(uhci
, u
);
1760 /* Check if the URB timed out */
1761 if (u
->timeout
&& time_after(u
->timeout
, jiffies
)) {
1762 u
->transfer_flags
|= USB_ASYNC_UNLINK
| USB_TIMEOUT_KILLED
;
1767 nested_unlock(&uhci
->urblist_lock
, flags
);
1769 rh_init_int_timer(urb
);
1772 /*-------------------------------------------------------------------------*/
1773 /* Root Hub INTs are polled by this timer */
1774 static int rh_init_int_timer(struct urb
*urb
)
1776 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1778 uhci
->rh
.interval
= urb
->interval
;
1779 init_timer(&uhci
->rh
.rh_int_timer
);
1780 uhci
->rh
.rh_int_timer
.function
= rh_int_timer_do
;
1781 uhci
->rh
.rh_int_timer
.data
= (unsigned long)urb
;
1782 uhci
->rh
.rh_int_timer
.expires
= jiffies
+ (HZ
* (urb
->interval
< 30 ? 30 : urb
->interval
)) / 1000;
1783 add_timer(&uhci
->rh
.rh_int_timer
);
1788 /*-------------------------------------------------------------------------*/
1789 #define OK(x) len = (x); break
1791 #define CLR_RH_PORTSTAT(x) \
1792 status = inw(io_addr + USBPORTSC1 + 2 * (wIndex-1)); \
1793 status = (status & 0xfff5) & ~(x); \
1794 outw(status, io_addr + USBPORTSC1 + 2 * (wIndex-1))
1796 #define SET_RH_PORTSTAT(x) \
1797 status = inw(io_addr + USBPORTSC1 + 2 * (wIndex-1)); \
1798 status = (status & 0xfff5) | (x); \
1799 outw(status, io_addr + USBPORTSC1 + 2 * (wIndex-1))
1802 /*-------------------------------------------------------------------------*/
1803 /*************************
1804 ** Root Hub Control Pipe
1805 *************************/
1807 static int rh_submit_urb(struct urb
*urb
)
1809 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1810 unsigned int pipe
= urb
->pipe
;
1811 devrequest
*cmd
= (devrequest
*)urb
->setup_packet
;
1812 void *data
= urb
->transfer_buffer
;
1813 int leni
= urb
->transfer_buffer_length
;
1816 int stat
= USB_ST_NOERROR
;
1818 unsigned int io_addr
= uhci
->io_addr
;
1825 if (usb_pipetype(pipe
) == PIPE_INTERRUPT
) {
1828 uhci
->rh
.interval
= urb
->interval
;
1829 rh_init_int_timer(urb
);
1831 return USB_ST_NOERROR
;
1834 bmRType_bReq
= cmd
->requesttype
| cmd
->request
<< 8;
1835 wValue
= le16_to_cpu(cmd
->value
);
1836 wIndex
= le16_to_cpu(cmd
->index
);
1837 wLength
= le16_to_cpu(cmd
->length
);
1839 for (i
= 0; i
< 8; i
++)
1840 uhci
->rh
.c_p_r
[i
] = 0;
1842 switch (bmRType_bReq
) {
1843 /* Request Destination:
1844 without flags: Device,
1845 RH_INTERFACE: interface,
1846 RH_ENDPOINT: endpoint,
1847 RH_CLASS means HUB here,
1848 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1852 *(__u16
*)data
= cpu_to_le16(1);
1854 case RH_GET_STATUS
| RH_INTERFACE
:
1855 *(__u16
*)data
= cpu_to_le16(0);
1857 case RH_GET_STATUS
| RH_ENDPOINT
:
1858 *(__u16
*)data
= cpu_to_le16(0);
1860 case RH_GET_STATUS
| RH_CLASS
:
1861 *(__u32
*)data
= cpu_to_le32(0);
1862 OK(4); /* hub power */
1863 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
1864 status
= inw(io_addr
+ USBPORTSC1
+ 2 * (wIndex
- 1));
1865 cstatus
= ((status
& USBPORTSC_CSC
) >> (1 - 0)) |
1866 ((status
& USBPORTSC_PEC
) >> (3 - 1)) |
1867 (uhci
->rh
.c_p_r
[wIndex
- 1] << (0 + 4));
1868 status
= (status
& USBPORTSC_CCS
) |
1869 ((status
& USBPORTSC_PE
) >> (2 - 1)) |
1870 ((status
& USBPORTSC_SUSP
) >> (12 - 2)) |
1871 ((status
& USBPORTSC_PR
) >> (9 - 4)) |
1872 (1 << 8) | /* power on */
1873 ((status
& USBPORTSC_LSDA
) << (-8 + 9));
1875 *(__u16
*)data
= cpu_to_le16(status
);
1876 *(__u16
*)(data
+ 2) = cpu_to_le16(cstatus
);
1878 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
1880 case RH_ENDPOINT_STALL
:
1884 case RH_CLEAR_FEATURE
| RH_CLASS
:
1886 case RH_C_HUB_OVER_CURRENT
:
1887 OK(0); /* hub power over current */
1890 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
1892 case RH_PORT_ENABLE
:
1893 CLR_RH_PORTSTAT(USBPORTSC_PE
);
1895 case RH_PORT_SUSPEND
:
1896 CLR_RH_PORTSTAT(USBPORTSC_SUSP
);
1899 OK(0); /* port power */
1900 case RH_C_PORT_CONNECTION
:
1901 SET_RH_PORTSTAT(USBPORTSC_CSC
);
1903 case RH_C_PORT_ENABLE
:
1904 SET_RH_PORTSTAT(USBPORTSC_PEC
);
1906 case RH_C_PORT_SUSPEND
:
1907 /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
1909 case RH_C_PORT_OVER_CURRENT
:
1910 OK(0); /* port power over current */
1911 case RH_C_PORT_RESET
:
1912 uhci
->rh
.c_p_r
[wIndex
- 1] = 0;
1916 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
1918 case RH_PORT_SUSPEND
:
1919 SET_RH_PORTSTAT(USBPORTSC_SUSP
);
1922 SET_RH_PORTSTAT(USBPORTSC_PR
);
1923 wait_ms(50); /* USB v1.1 7.1.7.3 */
1924 uhci
->rh
.c_p_r
[wIndex
- 1] = 1;
1925 CLR_RH_PORTSTAT(USBPORTSC_PR
);
1927 SET_RH_PORTSTAT(USBPORTSC_PE
);
1929 SET_RH_PORTSTAT(0xa);
1932 OK(0); /* port power ** */
1933 case RH_PORT_ENABLE
:
1934 SET_RH_PORTSTAT(USBPORTSC_PE
);
1938 case RH_SET_ADDRESS
:
1939 uhci
->rh
.devnum
= wValue
;
1941 case RH_GET_DESCRIPTOR
:
1942 switch ((wValue
& 0xff00) >> 8) {
1943 case 0x01: /* device descriptor */
1944 len
= min(leni
, min(sizeof(root_hub_dev_des
), wLength
));
1945 memcpy(data
, root_hub_dev_des
, len
);
1947 case 0x02: /* configuration descriptor */
1948 len
= min(leni
, min(sizeof(root_hub_config_des
), wLength
));
1949 memcpy (data
, root_hub_config_des
, len
);
1951 case 0x03: /* string descriptors */
1952 len
= usb_root_hub_string (wValue
& 0xff,
1953 uhci
->io_addr
, "UHCI-alt",
1956 OK (min (leni
, len
));
1961 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1962 root_hub_hub_des
[2] = uhci
->rh
.numports
;
1963 len
= min(leni
, min(sizeof(root_hub_hub_des
), wLength
));
1964 memcpy(data
, root_hub_hub_des
, len
);
1966 case RH_GET_CONFIGURATION
:
1967 *(__u8
*)data
= 0x01;
1969 case RH_SET_CONFIGURATION
:
1971 case RH_GET_INTERFACE
| RH_INTERFACE
:
1972 *(__u8
*)data
= 0x00;
1974 case RH_SET_INTERFACE
| RH_INTERFACE
:
1980 urb
->actual_length
= len
;
1985 return USB_ST_NOERROR
;
1987 /*-------------------------------------------------------------------------*/
1989 static int rh_unlink_urb(struct urb
*urb
)
1991 struct uhci
*uhci
= (struct uhci
*)urb
->dev
->bus
->hcpriv
;
1993 if (uhci
->rh
.urb
== urb
) {
1995 del_timer(&uhci
->rh
.rh_int_timer
);
1999 /*-------------------------------------------------------------------*/
2001 void uhci_free_pending_qhs(struct uhci
*uhci
)
2003 struct list_head
*tmp
, *head
;
2004 unsigned long flags
;
2006 /* Free any pending QH's */
2007 spin_lock_irqsave(&uhci
->qh_remove_lock
, flags
);
2008 head
= &uhci
->qh_remove_list
;
2010 while (tmp
!= head
) {
2011 struct uhci_qh
*qh
= list_entry(tmp
, struct uhci_qh
, remove_list
);
2015 list_del(&qh
->remove_list
);
2019 spin_unlock_irqrestore(&uhci
->qh_remove_lock
, flags
);
2022 static void uhci_interrupt(int irq
, void *__uhci
, struct pt_regs
*regs
)
2024 struct uhci
*uhci
= __uhci
;
2025 unsigned int io_addr
= uhci
->io_addr
;
2026 unsigned short status
;
2027 unsigned long flags
;
2028 struct list_head
*tmp
, *head
;
2031 * Read the interrupt status, and write it back to clear the
2034 status
= inw(io_addr
+ USBSTS
);
2035 if (!status
) /* shared interrupt, not mine */
2037 outw(status
, io_addr
+ USBSTS
);
2039 if (status
& ~(USBSTS_USBINT
| USBSTS_ERROR
)) {
2040 if (status
& USBSTS_RD
)
2041 printk(KERN_INFO
"uhci: resume detected, not implemented\n");
2042 if (status
& USBSTS_HSE
)
2043 printk(KERN_ERR
"uhci: host system error, PCI problems?\n");
2044 if (status
& USBSTS_HCPE
)
2045 printk(KERN_ERR
"uhci: host controller process error. something bad happened\n");
2046 if (status
& USBSTS_HCH
) {
2047 printk(KERN_ERR
"uhci: host controller halted. very bad\n");
2048 /* FIXME: Reset the controller, fix the offending TD */
2052 uhci_free_pending_qhs(uhci
);
2054 spin_lock(&uhci
->urb_remove_lock
);
2055 head
= &uhci
->urb_remove_list
;
2057 while (tmp
!= head
) {
2058 struct urb
*urb
= list_entry(tmp
, struct urb
, urb_list
);
2062 list_del(&urb
->urb_list
);
2067 spin_unlock(&uhci
->urb_remove_lock
);
2069 uhci_clear_next_interrupt(uhci
);
2071 /* Walk the list of pending TD's to see which ones completed */
2072 nested_lock(&uhci
->urblist_lock
, flags
);
2073 head
= &uhci
->urb_list
;
2075 while (tmp
!= head
) {
2076 struct urb
*urb
= list_entry(tmp
, struct urb
, urb_list
);
2080 /* Checks the status and does all of the magic necessary */
2081 uhci_transfer_result(urb
);
2083 nested_unlock(&uhci
->urblist_lock
, flags
);
2086 static void reset_hc(struct uhci
*uhci
)
2088 unsigned int io_addr
= uhci
->io_addr
;
2090 /* Global reset for 50ms */
2091 outw(USBCMD_GRESET
, io_addr
+ USBCMD
);
2093 outw(0, io_addr
+ USBCMD
);
2097 static void start_hc(struct uhci
*uhci
)
2099 unsigned int io_addr
= uhci
->io_addr
;
2103 * Reset the HC - this will force us to get a
2104 * new notification of any already connected
2105 * ports due to the virtual disconnect that it
2108 outw(USBCMD_HCRESET
, io_addr
+ USBCMD
);
2109 while (inw(io_addr
+ USBCMD
) & USBCMD_HCRESET
) {
2111 printk(KERN_ERR
"uhci: USBCMD_HCRESET timed out!\n");
2116 /* Turn on all interrupts */
2117 outw(USBINTR_TIMEOUT
| USBINTR_RESUME
| USBINTR_IOC
| USBINTR_SP
,
2120 /* Start at frame 0 */
2121 outw(0, io_addr
+ USBFRNUM
);
2122 outl(virt_to_bus(uhci
->fl
), io_addr
+ USBFLBASEADD
);
2124 /* Run and mark it configured with a 64-byte max packet */
2125 outw(USBCMD_RS
| USBCMD_CF
| USBCMD_MAXP
, io_addr
+ USBCMD
);
2129 * Allocate a frame list, and then setup the skeleton
2131 * The hardware doesn't really know any difference
2132 * in the queues, but the order does matter for the
2133 * protocols higher up. The order is:
2135 * - any isochronous events handled before any
2136 * of the queues. We don't do that here, because
2137 * we'll create the actual TD entries on demand.
2138 * - The first queue is the "interrupt queue".
2139 * - The second queue is the "control queue", split into low and high speed
2140 * - The third queue is "bulk data".
2142 static struct uhci
*alloc_uhci(unsigned int io_addr
, unsigned int io_size
)
2146 struct usb_bus
*bus
;
2148 uhci
= kmalloc(sizeof(*uhci
), GFP_KERNEL
);
2152 memset(uhci
, 0, sizeof(*uhci
));
2155 uhci
->io_addr
= io_addr
;
2156 uhci
->io_size
= io_size
;
2158 spin_lock_init(&uhci
->qh_remove_lock
);
2159 INIT_LIST_HEAD(&uhci
->qh_remove_list
);
2161 spin_lock_init(&uhci
->urb_remove_lock
);
2162 INIT_LIST_HEAD(&uhci
->urb_remove_list
);
2164 nested_init(&uhci
->urblist_lock
);
2165 INIT_LIST_HEAD(&uhci
->urb_list
);
2167 spin_lock_init(&uhci
->framelist_lock
);
2169 /* We need exactly one page (per UHCI specs), how convenient */
2170 /* We assume that one page is atleast 4k (1024 frames * 4 bytes) */
2171 uhci
->fl
= (void *)__get_free_page(GFP_KERNEL
);
2175 bus
= usb_alloc_bus(&uhci_device_operations
);
2182 /* Initialize the root hub */
2184 /* UHCI specs says devices must have 2 ports, but goes on to say */
2185 /* they may have more but give no way to determine how many they */
2186 /* have. However, according to the UHCI spec, Bit 7 is always set */
2187 /* to 1. So we try to use this to our advantage */
2188 for (port
= 0; port
< (io_size
- 0x10) / 2; port
++) {
2189 unsigned int portstatus
;
2191 portstatus
= inw(io_addr
+ 0x10 + (port
* 2));
2192 if (!(portstatus
& 0x0080))
2196 info("detected %d ports", port
);
2198 /* This is experimental so anything less than 2 or greater than 8 is */
2199 /* something weird and we'll ignore it */
2200 if (port
< 2 || port
> 8) {
2201 info("port count misdetected? forcing to 2 ports");
2205 uhci
->rh
.numports
= port
;
2208 * 9 Interrupt queues; link int2 to int1, int4 to int2, etc
2209 * then link int1 to control and control to bulk
2211 for (i
= 1; i
< 9; i
++) {
2212 struct uhci_td
*td
= &uhci
->skeltd
[i
];
2214 uhci_fill_td(td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2215 td
->link
= virt_to_bus(&uhci
->skeltd
[i
- 1]);
2219 uhci_fill_td(&uhci
->skel_int1_td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2220 uhci
->skel_int1_td
.link
= virt_to_bus(&uhci
->skel_ls_control_qh
) | UHCI_PTR_QH
;
2222 uhci
->skel_ls_control_qh
.link
= virt_to_bus(&uhci
->skel_hs_control_qh
) | UHCI_PTR_QH
;
2223 uhci
->skel_ls_control_qh
.element
= UHCI_PTR_TERM
;
2225 uhci
->skel_hs_control_qh
.link
= virt_to_bus(&uhci
->skel_bulk_qh
) | UHCI_PTR_QH
;
2226 uhci
->skel_hs_control_qh
.element
= UHCI_PTR_TERM
;
2228 uhci
->skel_bulk_qh
.link
= virt_to_bus(&uhci
->skel_term_qh
) | UHCI_PTR_QH
;
2229 uhci
->skel_bulk_qh
.element
= UHCI_PTR_TERM
;
2231 /* This dummy TD is to work around a bug in Intel PIIX controllers */
2232 uhci_fill_td(&uhci
->skel_term_td
, 0, (UHCI_NULL_DATA_SIZE
<< 21) | (0x7f << 8) | USB_PID_IN
, 0);
2233 uhci
->skel_term_td
.link
= UHCI_PTR_TERM
;
2235 uhci
->skel_term_qh
.link
= UHCI_PTR_TERM
;
2236 uhci
->skel_term_qh
.element
= virt_to_bus(&uhci
->skel_term_td
);
2239 * Fill the frame list: make all entries point to
2240 * the proper interrupt queue.
2242 * This is probably silly, but it's a simple way to
2243 * scatter the interrupt queues in a way that gives
2244 * us a reasonable dynamic range for irq latencies.
2246 for (i
= 0; i
< 1024; i
++) {
2247 struct uhci_td
*irq
= &uhci
->skel_int1_td
;
2270 /* Only place we don't use the frame list routines */
2271 uhci
->fl
->frame
[i
] = virt_to_bus(irq
);
2280 free_page((unsigned long)uhci
->fl
);
2288 * De-allocate all resources..
2290 static void release_uhci(struct uhci
*uhci
)
2292 if (uhci
->irq
>= 0) {
2293 free_irq(uhci
->irq
, uhci
);
2298 free_page((unsigned long)uhci
->fl
);
2302 usb_free_bus(uhci
->bus
);
2306 int uhci_start_root_hub(struct uhci
*uhci
)
2308 struct usb_device
*dev
;
2310 dev
= usb_alloc_dev(NULL
, uhci
->bus
);
2314 uhci
->bus
->root_hub
= dev
;
2317 if (usb_new_device(dev
) != 0) {
2327 * If we've successfully found a UHCI, now is the time to increment the
2328 * module usage count, and return success..
2330 static int setup_uhci(struct pci_dev
*dev
, int irq
, unsigned int io_addr
, unsigned int io_size
)
2334 char buf
[8], *bufp
= buf
;
2337 sprintf(buf
, "%d", irq
);
2339 bufp
= __irq_itoa(irq
);
2341 printk(KERN_INFO __FILE__
": USB UHCI at I/O 0x%x, IRQ %s\n",
2344 uhci
= alloc_uhci(io_addr
, io_size
);
2347 dev
->driver_data
= uhci
;
2349 request_region(uhci
->io_addr
, io_size
, "usb-uhci");
2353 usb_register_bus(uhci
->bus
);
2357 if (request_irq(irq
, uhci_interrupt
, SA_SHIRQ
, "usb-uhci", uhci
) == 0) {
2360 pci_write_config_word(dev
, USBLEGSUP
, USBLEGSUP_DEFAULT
);
2362 if (!uhci_start_root_hub(uhci
))
2366 /* Couldn't allocate IRQ if we got here */
2369 release_region(uhci
->io_addr
, uhci
->io_size
);
2375 static int __devinit
uhci_pci_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
2379 /* disable legacy emulation */
2380 pci_write_config_word(dev
, USBLEGSUP
, 0);
2382 if (pci_enable_device(dev
) < 0)
2386 err("found UHCI device with no IRQ assigned. check BIOS settings!");
2390 /* Search for the IO base address.. */
2391 for (i
= 0; i
< 6; i
++) {
2392 unsigned int io_addr
= pci_resource_start(dev
, i
);
2393 unsigned int io_size
= pci_resource_len(dev
, i
);
2396 if (!(pci_resource_flags(dev
, i
) & IORESOURCE_IO
))
2399 /* Is it already in use? */
2400 if (check_region(io_addr
, io_size
))
2403 return setup_uhci(dev
, dev
->irq
, io_addr
, io_size
);
2409 static void __devexit
uhci_pci_remove(struct pci_dev
*dev
)
2411 struct uhci
*uhci
= dev
->driver_data
;
2413 if (uhci
->bus
->root_hub
)
2414 usb_disconnect(&uhci
->bus
->root_hub
);
2416 usb_deregister_bus(uhci
->bus
);
2419 release_region(uhci
->io_addr
, uhci
->io_size
);
2421 uhci_free_pending_qhs(uhci
);
2426 static void uhci_pci_suspend(struct pci_dev
*dev
)
2428 reset_hc((struct uhci
*) dev
->driver_data
);
2431 static void uhci_pci_resume(struct pci_dev
*dev
)
2433 reset_hc((struct uhci
*) dev
->driver_data
);
2434 start_hc((struct uhci
*) dev
->driver_data
);
2437 /*-------------------------------------------------------------------------*/
2439 static const struct pci_device_id __devinitdata uhci_pci_ids
[] = { {
2441 /* handle any USB UHCI controller */
2442 class: ((PCI_CLASS_SERIAL_USB
<< 8) | 0x00),
2445 /* no matter who makes it */
2448 subvendor
: PCI_ANY_ID
,
2449 subdevice
: PCI_ANY_ID
,
2451 }, { /* end: all zeroes */ }
2454 MODULE_DEVICE_TABLE (pci
, uhci_pci_ids
);
2456 static struct pci_driver uhci_pci_driver
= {
2458 id_table
: &uhci_pci_ids
[0],
2460 probe
: uhci_pci_probe
,
2461 remove
: uhci_pci_remove
,
2464 suspend
: uhci_pci_suspend
,
2465 resume
: uhci_pci_resume
,
2470 static int __init
uhci_hcd_init(void)
2476 /* We throw all of the TD's and QH's into a kmem cache */
2477 /* TD's and QH's need to be 16 byte aligned and SLAB_HWCACHE_ALIGN */
2478 /* does this for us */
2479 uhci_td_cachep
= kmem_cache_create("uhci_td",
2480 sizeof(struct uhci_td
), 0,
2481 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2483 if (!uhci_td_cachep
)
2486 uhci_qh_cachep
= kmem_cache_create("uhci_qh",
2487 sizeof(struct uhci_qh
), 0,
2488 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2490 if (!uhci_qh_cachep
)
2493 uhci_up_cachep
= kmem_cache_create("uhci_urb_priv",
2494 sizeof(struct urb_priv
), 0, 0, NULL
, NULL
);
2496 if (!uhci_up_cachep
)
2499 retval
= pci_module_init (&uhci_pci_driver
);
2506 if (kmem_cache_destroy(uhci_up_cachep
))
2507 printk(KERN_INFO
"uhci: not all urb_priv's were freed\n");
2510 if (kmem_cache_destroy(uhci_qh_cachep
))
2511 printk(KERN_INFO
"uhci: not all QH's were freed\n");
2514 if (kmem_cache_destroy(uhci_td_cachep
))
2515 printk(KERN_INFO
"uhci: not all TD's were freed\n");
2521 static void __exit
uhci_hcd_cleanup (void)
2523 pci_unregister_driver (&uhci_pci_driver
);
2525 if (kmem_cache_destroy(uhci_up_cachep
))
2526 printk(KERN_INFO
"uhci: not all urb_priv's were freed\n");
2528 if (kmem_cache_destroy(uhci_qh_cachep
))
2529 printk(KERN_INFO
"uhci: not all QH's were freed\n");
2531 if (kmem_cache_destroy(uhci_td_cachep
))
2532 printk(KERN_INFO
"uhci: not all TD's were freed\n");
2535 module_init(uhci_hcd_init
);
2536 module_exit(uhci_hcd_cleanup
);
2538 MODULE_AUTHOR("Linus Torvalds, Johannes Erdfelt, Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber");
2539 MODULE_DESCRIPTION("USB Universal Host Controller Interface driver");