2 * Universal Host Controller Interface driver for USB (take II).
4 * (c) 1999-2001 Georg Acher, acher@in.tum.de (executive slave) (base guitar)
5 * Deti Fliegl, deti@fliegl.de (executive slave) (lead voice)
6 * Thomas Sailer, sailer@ife.ee.ethz.ch (chief consultant) (cheer leader)
7 * Roman Weissgaerber, weissg@vienna.at (virt root hub) (studio porter)
8 * (c) 2000 Yggdrasil Computing, Inc. (port of new PCI interface support
9 * from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
10 * (C) 2000 David Brownell, david-b@pacbell.net (usb-ohci.c)
12 * HW-initalization based on material of
14 * (C) Copyright 1999 Linus Torvalds
15 * (C) Copyright 1999 Johannes Erdfelt
16 * (C) Copyright 1999 Randy Dunlap
17 * (C) Copyright 1999 Gregory P. Smith
19 * $Id: usb-uhci.c,v 1.1.1.1 2005/04/11 02:50:41 jack Exp $
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/kernel.h>
26 #include <linux/delay.h>
27 #include <linux/ioport.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
30 #include <linux/smp_lock.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/interrupt.h> /* for in_interrupt() */
34 #include <linux/init.h>
35 #include <linux/version.h>
37 #include <linux/timer.h>
39 #include <asm/uaccess.h>
42 #include <asm/system.h>
44 /* This enables more detailed sanity checks in submit_iso */
45 //#define ISO_SANITY_CHECK
47 /* This enables debug printks */
50 /* This enables all symbols to be exported, to ease debugging oopses */
51 //#define DEBUG_SYMBOLS
53 /* This enables an extra UHCI slab for memory debugging */
56 #define VERSTR "$Revision: 1.1.1.1 $ time " __TIME__ " " __DATE__
58 #include <linux/usb.h>
60 #include "usb-uhci-debug.h"
67 #define DRIVER_VERSION "v1.275"
68 #define DRIVER_AUTHOR "Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber"
69 #define DRIVER_DESC "USB Universal Host Controller Interface driver"
73 #define dbg(format, arg...) do {} while (0)
81 #define _static static
84 #define queue_dbg dbg //err
85 #define async_dbg dbg //err
88 static kmem_cache_t *urb_priv_kmem;
91 #define SLAB_FLAG (in_interrupt () || current->state != TASK_RUNNING ? SLAB_ATOMIC : SLAB_NOIO)
92 #define KMALLOC_FLAG (in_interrupt () || current->state != TASK_RUNNING ? GFP_ATOMIC : GFP_NOIO)
94 /* CONFIG_USB_UHCI_HIGH_BANDWITH turns on Full Speed Bandwidth
95 * Reclamation: feature that puts loop on descriptor loop when
96 * there's some transfer going on. With FSBR, USB performance
97 * is optimal, but PCI can be slowed down up-to 5 times, slowing down
98 * system performance (eg. framebuffer devices).
100 #define CONFIG_USB_UHCI_HIGH_BANDWIDTH
102 /* *_DEPTH_FIRST puts descriptor in depth-first mode. This has
103 * somehow similar effect to FSBR (higher speed), but does not
104 * slow PCI down. OTOH USB performace is slightly slower than
105 * in FSBR case and single device could hog whole USB, starving
108 #define USE_CTRL_DEPTH_FIRST 0 // 0: Breadth first, 1: Depth first
109 #define USE_BULK_DEPTH_FIRST 0 // 0: Breadth first, 1: Depth first
111 /* Turning off both CONFIG_USB_UHCI_HIGH_BANDWITH and *_DEPTH_FIRST
112 * will lead to <64KB/sec performance over USB for bulk transfers targeting
113 * one device's endpoint. You probably do not want to do that.
116 // stop bandwidth reclamation after (roughly) 50ms
117 #define IDLE_TIMEOUT (HZ/20)
119 // Suppress HC interrupt error messages for 5s
120 #define ERROR_SUPPRESSION_TIME (HZ*5)
122 _static int rh_submit_urb (struct urb *urb);
123 _static int rh_unlink_urb (struct urb *urb);
124 _static int delete_qh (uhci_t *s, uhci_desc_t *qh);
125 _static int process_transfer (uhci_t *s, struct urb *urb, int mode);
126 _static int process_interrupt (uhci_t *s, struct urb *urb);
127 _static int process_iso (uhci_t *s, struct urb *urb, int force);
129 // How much URBs with ->next are walked
130 #define MAX_NEXT_COUNT 2048
132 static uhci_t *devs = NULL;
134 /* used by userspace UHCI data structure dumper */
135 uhci_t **uhci_devices = &devs;
137 /*-------------------------------------------------------------------*/
138 // Cleans up collected QHs, but not more than 100 in one go
139 void clean_descs(uhci_t *s, int force)
143 int now=UHCI_GET_CURRENT_FRAME(s), n=0;
147 while (q != &s->free_desc && (force || n<100)) {
148 qh = list_entry (q, uhci_desc_t, horizontal);
149 q=qh->horizontal.prev;
151 if ((qh->last_used!=now) || force)
156 /*-------------------------------------------------------------------*/
157 _static void uhci_switch_timer_int(uhci_t *s)
160 if (!list_empty(&s->urb_unlinked))
161 set_td_ioc(s->td1ms);
163 clr_td_ioc(s->td1ms);
166 set_td_ioc(s->td32ms);
168 clr_td_ioc(s->td32ms);
171 /*-------------------------------------------------------------------*/
172 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
173 _static void enable_desc_loop(uhci_t *s, struct urb *urb)
177 if (urb->transfer_flags & USB_NO_FSBR)
180 spin_lock_irqsave (&s->qh_lock, flags);
181 s->chain_end->hw.qh.head&=cpu_to_le32(~UHCI_PTR_TERM);
184 ((urb_priv_t*)urb->hcpriv)->use_loop=1;
185 spin_unlock_irqrestore (&s->qh_lock, flags);
187 /*-------------------------------------------------------------------*/
188 _static void disable_desc_loop(uhci_t *s, struct urb *urb)
192 if (urb->transfer_flags & USB_NO_FSBR)
195 spin_lock_irqsave (&s->qh_lock, flags);
196 if (((urb_priv_t*)urb->hcpriv)->use_loop) {
199 if (!s->loop_usage) {
200 s->chain_end->hw.qh.head|=cpu_to_le32(UHCI_PTR_TERM);
203 ((urb_priv_t*)urb->hcpriv)->use_loop=0;
205 spin_unlock_irqrestore (&s->qh_lock, flags);
208 /*-------------------------------------------------------------------*/
209 _static void queue_urb_unlocked (uhci_t *s, struct urb *urb)
211 struct list_head *p=&urb->urb_list;
212 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
215 type=usb_pipetype (urb->pipe);
217 if ((type == PIPE_BULK) || (type == PIPE_CONTROL))
218 enable_desc_loop(s, urb);
221 urb->status = -EINPROGRESS;
222 ((urb_priv_t*)urb->hcpriv)->started=jiffies;
223 list_add (p, &s->urb_list);
226 uhci_switch_timer_int(s);
228 /*-------------------------------------------------------------------*/
229 _static void queue_urb (uhci_t *s, struct urb *urb)
231 unsigned long flags=0;
233 spin_lock_irqsave (&s->urb_list_lock, flags);
234 queue_urb_unlocked(s,urb);
235 spin_unlock_irqrestore (&s->urb_list_lock, flags);
237 /*-------------------------------------------------------------------*/
238 _static void dequeue_urb (uhci_t *s, struct urb *urb)
240 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
243 type=usb_pipetype (urb->pipe);
245 if ((type == PIPE_BULK) || (type == PIPE_CONTROL))
246 disable_desc_loop(s, urb);
249 list_del (&urb->urb_list);
250 if (urb->timeout && s->timeout_urbs)
254 /*-------------------------------------------------------------------*/
255 _static int alloc_td (uhci_t *s, uhci_desc_t ** new, int flags)
257 dma_addr_t dma_handle;
259 *new = pci_pool_alloc(s->desc_pool, GFP_DMA | GFP_ATOMIC, &dma_handle);
262 memset (*new, 0, sizeof (uhci_desc_t));
263 (*new)->dma_addr = dma_handle;
264 set_td_link((*new), UHCI_PTR_TERM | (flags & UHCI_PTR_BITS)); // last by default
265 (*new)->type = TD_TYPE;
267 INIT_LIST_HEAD (&(*new)->vertical);
268 INIT_LIST_HEAD (&(*new)->horizontal);
272 /*-------------------------------------------------------------------*/
273 // append a qh to td.link physically, the SW linkage is not affected
274 _static void append_qh(uhci_t *s, uhci_desc_t *td, uhci_desc_t* qh, int flags)
278 spin_lock_irqsave (&s->td_lock, xxx);
280 set_td_link(td, qh->dma_addr | (flags & UHCI_PTR_DEPTH) | UHCI_PTR_QH);
283 spin_unlock_irqrestore (&s->td_lock, xxx);
285 /*-------------------------------------------------------------------*/
286 /* insert td at last position in td-list of qh (vertical) */
287 _static int insert_td (uhci_t *s, uhci_desc_t *qh, uhci_desc_t* new, int flags)
292 spin_lock_irqsave (&s->td_lock, xxx);
294 list_add_tail (&new->vertical, &qh->vertical);
296 prev = list_entry (new->vertical.prev, uhci_desc_t, vertical);
299 // virgin qh without any tds
300 set_qh_element(qh, new->dma_addr | UHCI_PTR_TERM);
303 // already tds inserted, implicitely remove TERM bit of prev
304 set_td_link(prev, new->dma_addr | (flags & UHCI_PTR_DEPTH));
307 spin_unlock_irqrestore (&s->td_lock, xxx);
311 /*-------------------------------------------------------------------*/
312 /* insert new_td after td (horizontal) */
313 _static int insert_td_horizontal (uhci_t *s, uhci_desc_t *td, uhci_desc_t* new)
318 spin_lock_irqsave (&s->td_lock, flags);
320 next = list_entry (td->horizontal.next, uhci_desc_t, horizontal);
321 list_add (&new->horizontal, &td->horizontal);
322 new->hw.td.link = td->hw.td.link;
323 set_td_link(td, new->dma_addr);
325 spin_unlock_irqrestore (&s->td_lock, flags);
329 /*-------------------------------------------------------------------*/
330 _static int unlink_td (uhci_t *s, uhci_desc_t *element, int phys_unlink)
332 uhci_desc_t *next, *prev;
336 spin_lock_irqsave (&s->td_lock, flags);
338 next = list_entry (element->vertical.next, uhci_desc_t, vertical);
340 if (next == element) {
342 prev = list_entry (element->horizontal.prev, uhci_desc_t, horizontal);
345 prev = list_entry (element->vertical.prev, uhci_desc_t, vertical);
348 // really remove HW linking
349 if (prev->type == TD_TYPE)
350 prev->hw.td.link = element->hw.td.link;
352 prev->hw.qh.element = element->hw.td.link;
358 list_del (&element->vertical);
360 list_del (&element->horizontal);
362 spin_unlock_irqrestore (&s->td_lock, flags);
367 /*-------------------------------------------------------------------*/
368 _static int delete_desc (uhci_t *s, uhci_desc_t *element)
370 pci_pool_free(s->desc_pool, element, element->dma_addr);
373 /*-------------------------------------------------------------------*/
374 // Allocates qh element
375 _static int alloc_qh (uhci_t *s, uhci_desc_t ** new)
377 dma_addr_t dma_handle;
379 *new = pci_pool_alloc(s->desc_pool, GFP_DMA | GFP_ATOMIC, &dma_handle);
382 memset (*new, 0, sizeof (uhci_desc_t));
383 (*new)->dma_addr = dma_handle;
384 set_qh_head(*new, UHCI_PTR_TERM);
385 set_qh_element(*new, UHCI_PTR_TERM);
386 (*new)->type = QH_TYPE;
389 INIT_LIST_HEAD (&(*new)->horizontal);
390 INIT_LIST_HEAD (&(*new)->vertical);
392 dbg("Allocated qh @ %p", *new);
396 /*-------------------------------------------------------------------*/
397 // inserts new qh before/after the qh at pos
398 // flags: 0: insert before pos, 1: insert after pos (for low speed transfers)
399 _static int insert_qh (uhci_t *s, uhci_desc_t *pos, uhci_desc_t *new, int order)
404 spin_lock_irqsave (&s->qh_lock, flags);
407 // (OLD) (POS) -> (OLD) (NEW) (POS)
408 old = list_entry (pos->horizontal.prev, uhci_desc_t, horizontal);
409 list_add_tail (&new->horizontal, &pos->horizontal);
410 set_qh_head(new, MAKE_QH_ADDR (pos)) ;
411 if (!(old->hw.qh.head & cpu_to_le32(UHCI_PTR_TERM)))
412 set_qh_head(old, MAKE_QH_ADDR (new)) ;
415 // (POS) (OLD) -> (POS) (NEW) (OLD)
416 old = list_entry (pos->horizontal.next, uhci_desc_t, horizontal);
417 list_add (&new->horizontal, &pos->horizontal);
418 set_qh_head(new, MAKE_QH_ADDR (old));
419 set_qh_head(pos, MAKE_QH_ADDR (new)) ;
424 spin_unlock_irqrestore (&s->qh_lock, flags);
429 /*-------------------------------------------------------------------*/
430 _static int unlink_qh (uhci_t *s, uhci_desc_t *element)
435 spin_lock_irqsave (&s->qh_lock, flags);
437 prev = list_entry (element->horizontal.prev, uhci_desc_t, horizontal);
438 prev->hw.qh.head = element->hw.qh.head;
440 dbg("unlink qh %p, pqh %p, nxqh %p, to %08x", element, prev,
441 list_entry (element->horizontal.next, uhci_desc_t, horizontal),le32_to_cpu(element->hw.qh.head) &~15);
443 list_del(&element->horizontal);
446 spin_unlock_irqrestore (&s->qh_lock, flags);
450 /*-------------------------------------------------------------------*/
451 _static int delete_qh (uhci_t *s, uhci_desc_t *qh)
456 list_del (&qh->horizontal);
458 while ((p = qh->vertical.next) != &qh->vertical) {
459 td = list_entry (p, uhci_desc_t, vertical);
460 dbg("unlink td @ %p",td);
461 unlink_td (s, td, 0); // no physical unlink
469 /*-------------------------------------------------------------------*/
470 _static void clean_td_chain (uhci_t *s, uhci_desc_t *td)
478 while ((p = td->horizontal.next) != &td->horizontal) {
479 td1 = list_entry (p, uhci_desc_t, horizontal);
480 delete_desc (s, td1);
486 /*-------------------------------------------------------------------*/
487 _static void fill_td (uhci_desc_t *td, int status, int info, __u32 buffer)
489 td->hw.td.status = cpu_to_le32(status);
490 td->hw.td.info = cpu_to_le32(info);
491 td->hw.td.buffer = cpu_to_le32(buffer);
493 /*-------------------------------------------------------------------*/
494 // Removes ALL qhs in chain (paranoia!)
495 _static void cleanup_skel (uhci_t *s)
507 unlink_td(s,s->td32ms,1);
508 delete_desc(s, s->td32ms);
511 for (n = 0; n < 8; n++) {
512 td = s->int_chain[n];
513 clean_td_chain (s, td);
517 for (n = 0; n < 1024; n++) {
519 clean_td_chain (s, td);
525 pci_free_consistent(s->uhci_pci, PAGE_SIZE,
526 s->framelist, s->framelist_dma);
528 if (s->control_chain) {
529 // completed init_skel?
531 uhci_desc_t *qh, *qh1;
533 qh = s->control_chain;
534 while ((p = qh->horizontal.next) != &qh->horizontal) {
535 qh1 = list_entry (p, uhci_desc_t, horizontal);
542 if (s->ls_control_chain)
543 delete_desc (s, s->ls_control_chain);
544 if (s->control_chain)
545 delete_desc (s, s->control_chain);
547 delete_desc (s, s->bulk_chain);
549 delete_desc (s, s->chain_end);
553 pci_pool_destroy(s->desc_pool);
557 dbg("cleanup_skel finished");
559 /*-------------------------------------------------------------------*/
560 // allocates framelist and qh-skeletons
561 // only HW-links provide continous linking, SW-links stay in their domain (ISO/INT)
562 _static int init_skel (uhci_t *s)
565 uhci_desc_t *qh, *td;
569 s->framelist = pci_alloc_consistent(s->uhci_pci, PAGE_SIZE,
575 memset (s->framelist, 0, 4096);
577 dbg("creating descriptor pci_pool");
579 s->desc_pool = pci_pool_create("uhci_desc", s->uhci_pci,
580 sizeof(uhci_desc_t), 16, 0,
581 GFP_DMA | GFP_ATOMIC);
583 goto init_skel_cleanup;
585 dbg("allocating iso desc pointer list");
586 s->iso_td = (uhci_desc_t **) kmalloc (1024 * sizeof (uhci_desc_t*), GFP_KERNEL);
589 goto init_skel_cleanup;
591 s->ls_control_chain = NULL;
592 s->control_chain = NULL;
593 s->bulk_chain = NULL;
596 dbg("allocating iso descs");
597 for (n = 0; n < 1024; n++) {
598 // allocate skeleton iso/irq-tds
599 if (alloc_td (s, &td, 0))
600 goto init_skel_cleanup;
603 s->framelist[n] = cpu_to_le32((__u32) td->dma_addr);
606 dbg("allocating qh: chain_end");
607 if (alloc_qh (s, &qh))
608 goto init_skel_cleanup;
612 if (alloc_td (s, &td, 0))
613 goto init_skel_cleanup;
615 fill_td (td, 0 * TD_CTRL_IOC, 0, 0); // generate 1ms interrupt (enabled on demand)
616 insert_td (s, qh, td, 0);
617 qh->hw.qh.element &= cpu_to_le32(~UHCI_PTR_TERM); // remove TERM bit
620 dbg("allocating qh: bulk_chain");
621 if (alloc_qh (s, &qh))
622 goto init_skel_cleanup;
624 insert_qh (s, s->chain_end, qh, 0);
627 dbg("allocating qh: control_chain");
628 ret = alloc_qh (s, &qh);
630 goto init_skel_cleanup;
632 insert_qh (s, s->bulk_chain, qh, 0);
633 s->control_chain = qh;
635 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
636 // disabled reclamation loop
637 set_qh_head(s->chain_end, s->control_chain->dma_addr | UHCI_PTR_QH | UHCI_PTR_TERM);
640 dbg("allocating qh: ls_control_chain");
641 if (alloc_qh (s, &qh))
642 goto init_skel_cleanup;
644 insert_qh (s, s->control_chain, qh, 0);
645 s->ls_control_chain = qh;
647 for (n = 0; n < 8; n++)
650 dbg("allocating skeleton INT-TDs");
652 for (n = 0; n < 8; n++) {
655 if (alloc_td (s, &td, 0))
656 goto init_skel_cleanup;
658 s->int_chain[n] = td;
660 set_td_link(s->int_chain[0], s->ls_control_chain->dma_addr | UHCI_PTR_QH);
663 set_td_link(s->int_chain[n], s->int_chain[0]->dma_addr);
667 dbg("Linking skeleton INT-TDs");
669 for (n = 0; n < 1024; n++) {
670 // link all iso-tds to the interrupt chains
672 dbg("framelist[%i]=%x",n,le32_to_cpu(s->framelist[n]));
674 ((uhci_desc_t*) s->iso_td[n])->hw.td.link = cpu_to_le32(s->int_chain[0]->dma_addr);
676 for (o = 1, m = 2; m <= 128; o++, m += m)
677 if ((n & (m - 1)) == ((m - 1) / 2))
678 set_td_link(((uhci_desc_t*) s->iso_td[n]), s->int_chain[o]->dma_addr);
681 if (alloc_td (s, &td, 0))
682 goto init_skel_cleanup;
684 fill_td (td, 0 * TD_CTRL_IOC, 0, 0); // generate 32ms interrupt (activated later)
687 insert_td_horizontal (s, s->int_chain[5], td);
690 //uhci_show_queue(s->control_chain);
691 dbg("init_skel exit");
699 /*-------------------------------------------------------------------*/
701 // assembles QHs und TDs for control, bulk and iso
702 /*-------------------------------------------------------------------*/
703 _static int uhci_submit_control_urb (struct urb *urb)
705 uhci_desc_t *qh, *td;
706 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
707 urb_priv_t *urb_priv = urb->hcpriv;
708 unsigned long destination, status;
709 int maxsze = usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe));
712 int depth_first=USE_CTRL_DEPTH_FIRST; // UHCI descriptor chasing method
714 dbg("uhci_submit_control start");
715 if (alloc_qh (s, &qh)) // alloc qh for this request
718 if (alloc_td (s, &td, UHCI_PTR_DEPTH * depth_first)) // get td for setup stage
724 /* The "pipe" thing contains the destination in bits 8--18 */
725 destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP;
728 status = (urb->pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE |
729 (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD) | (3 << 27);
731 /* Build the TD for the control request, try forever, 8 bytes of data */
732 fill_td (td, status, destination | (7 << 21), urb_priv->setup_packet_dma);
734 insert_td (s, qh, td, 0); // queue 'setup stage'-td in qh
737 char *sp=urb->setup_packet;
738 dbg("SETUP to pipe %x: %x %x %x %x %x %x %x %x", urb->pipe,
739 sp[0],sp[1],sp[2],sp[3],sp[4],sp[5],sp[6],sp[7]);
744 len = urb->transfer_buffer_length;
745 data = urb->transfer_buffer;
747 /* If direction is "send", change the frame from SETUP (0x2D)
748 to OUT (0xE1). Else change it from SETUP to IN (0x69). */
750 destination = (urb->pipe & PIPE_DEVEP_MASK) | (usb_pipeout (urb->pipe)?USB_PID_OUT:USB_PID_IN);
755 if (alloc_td (s, &td, UHCI_PTR_DEPTH * depth_first))
756 goto fail_unmap_enomem;
761 destination ^= 1 << TD_TOKEN_TOGGLE; // toggle DATA0/1
763 // Status, pktsze bytes of data
764 fill_td (td, status, destination | ((pktsze - 1) << 21),
765 urb_priv->transfer_buffer_dma + (data - (char *)urb->transfer_buffer));
767 insert_td (s, qh, td, UHCI_PTR_DEPTH * depth_first); // queue 'data stage'-td in qh
773 /* Build the final TD for control status */
774 /* It's only IN if the pipe is out AND we aren't expecting data */
776 destination &= ~UHCI_PID;
778 if (usb_pipeout (urb->pipe) || (urb->transfer_buffer_length == 0))
779 destination |= USB_PID_IN;
781 destination |= USB_PID_OUT;
783 destination |= 1 << TD_TOKEN_TOGGLE; /* End in Data1 */
785 if (alloc_td (s, &td, UHCI_PTR_DEPTH))
786 goto fail_unmap_enomem;
788 status &=~TD_CTRL_SPD;
790 /* no limit on errors on final packet , 0 bytes of data */
791 fill_td (td, status | TD_CTRL_IOC, destination | (UHCI_NULL_DATA_SIZE << 21),
794 insert_td (s, qh, td, UHCI_PTR_DEPTH * depth_first); // queue status td
796 list_add (&qh->desc_list, &urb_priv->desc_list);
798 queue_urb (s, urb); // queue before inserting in desc chain
800 qh->hw.qh.element &= cpu_to_le32(~UHCI_PTR_TERM);
802 //uhci_show_queue(qh);
803 /* Start it up... put low speed first */
804 if (urb->pipe & TD_CTRL_LS)
805 insert_qh (s, s->control_chain, qh, 0);
807 insert_qh (s, s->bulk_chain, qh, 0);
809 dbg("uhci_submit_control end");
816 /*-------------------------------------------------------------------*/
817 // For queued bulk transfers, two additional QH helpers are allocated (nqh, bqh)
818 // Due to the linking with other bulk urbs, it has to be locked with urb_list_lock!
820 _static int uhci_submit_bulk_urb (struct urb *urb, struct urb *bulk_urb)
822 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
823 urb_priv_t *urb_priv = urb->hcpriv, *upriv, *bpriv=NULL;
824 uhci_desc_t *qh, *td, *nqh=NULL, *bqh=NULL, *first_td=NULL;
825 unsigned long destination, status;
827 unsigned int pipe = urb->pipe;
828 int maxsze = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe));
830 int depth_first=USE_BULK_DEPTH_FIRST; // UHCI descriptor chasing method
832 if (usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)))
835 queue_dbg("uhci_submit_bulk_urb: urb %p, old %p, pipe %08x, len %i",
836 urb,bulk_urb,urb->pipe,urb->transfer_buffer_length);
838 upriv = (urb_priv_t*)urb->hcpriv;
841 if (alloc_qh (s, &qh)) // get qh for this request
844 if (urb->transfer_flags & USB_QUEUE_BULK) {
845 if (alloc_qh(s, &nqh)) // placeholder for clean unlink
850 upriv->next_qh = nqh;
851 queue_dbg("new next qh %p",nqh);
855 bpriv = (urb_priv_t*)bulk_urb->hcpriv;
856 qh = bpriv->bottom_qh; // re-use bottom qh and next qh
857 nqh = bpriv->next_qh;
859 upriv->prev_queued_urb=bulk_urb;
862 if (urb->transfer_flags & USB_QUEUE_BULK) {
863 if (alloc_qh (s, &bqh)) // "bottom" QH
871 set_qh_element(bqh, UHCI_PTR_TERM);
872 set_qh_head(bqh, nqh->dma_addr | UHCI_PTR_QH); // element
873 upriv->bottom_qh = bqh;
875 queue_dbg("uhci_submit_bulk: qh %p bqh %p nqh %p",qh, bqh, nqh);
877 /* The "pipe" thing contains the destination in bits 8--18. */
878 destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe);
881 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE |
882 ((urb->transfer_flags & USB_DISABLE_SPD) ? 0 : TD_CTRL_SPD) | (3 << 27);
884 /* Build the TDs for the bulk request */
885 len = urb->transfer_buffer_length;
886 data = urb->transfer_buffer;
888 do { // TBD: Really allow zero-length packets?
891 if (alloc_td (s, &td, UHCI_PTR_DEPTH * depth_first))
900 // pktsze bytes of data
901 info = destination | (((pktsze - 1)&UHCI_NULL_DATA_SIZE) << 21) |
902 (usb_gettoggle (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)) << TD_TOKEN_TOGGLE);
904 fill_td (td, status, info,
905 urb_priv->transfer_buffer_dma + (data - (char *)urb->transfer_buffer));
909 // Use USB_ZERO_PACKET to finish bulk OUTs always with a zero length packet
910 last = (len == 0 && (usb_pipein(pipe) || pktsze < maxsze || !(urb->transfer_flags & USB_ZERO_PACKET)));
913 set_td_ioc(td); // last one generates INT
915 insert_td (s, qh, td, UHCI_PTR_DEPTH * depth_first);
918 usb_dotoggle (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
922 if (bulk_urb && bpriv) // everything went OK, link with old bulk URB
923 bpriv->next_queued_urb=urb;
925 list_add (&qh->desc_list, &urb_priv->desc_list);
927 if (urb->transfer_flags & USB_QUEUE_BULK)
928 append_qh(s, td, bqh, UHCI_PTR_DEPTH * depth_first);
930 queue_urb_unlocked (s, urb);
932 if (urb->transfer_flags & USB_QUEUE_BULK)
933 set_qh_element(qh, first_td->dma_addr);
935 qh->hw.qh.element &= cpu_to_le32(~UHCI_PTR_TERM); // arm QH
937 if (!bulk_urb) { // new bulk queue
938 if (urb->transfer_flags & USB_QUEUE_BULK) {
939 spin_lock (&s->td_lock); // both QHs in one go
940 insert_qh (s, s->chain_end, qh, 0); // Main QH
941 insert_qh (s, s->chain_end, nqh, 0); // Helper QH
942 spin_unlock (&s->td_lock);
945 insert_qh (s, s->chain_end, qh, 0);
948 //uhci_show_queue(s->bulk_chain);
949 //dbg("uhci_submit_bulk_urb: exit\n");
952 /*-------------------------------------------------------------------*/
953 _static void uhci_clean_iso_step1(uhci_t *s, urb_priv_t *urb_priv)
958 for (p = urb_priv->desc_list.next; p != &urb_priv->desc_list; p = p->next) {
959 td = list_entry (p, uhci_desc_t, desc_list);
960 unlink_td (s, td, 1);
963 /*-------------------------------------------------------------------*/
964 _static void uhci_clean_iso_step2(uhci_t *s, urb_priv_t *urb_priv)
969 while ((p = urb_priv->desc_list.next) != &urb_priv->desc_list) {
970 td = list_entry (p, uhci_desc_t, desc_list);
975 /*-------------------------------------------------------------------*/
976 /* mode: CLEAN_TRANSFER_NO_DELETION: unlink but no deletion mark (step 1 of async_unlink)
977 CLEAN_TRANSFER_REGULAR: regular (unlink/delete-mark)
978 CLEAN_TRANSFER_DELETION_MARK: deletion mark for QH (step 2 of async_unlink)
979 looks a bit complicated because of all the bulk queueing goodies
982 _static void uhci_clean_transfer (uhci_t *s, struct urb *urb, uhci_desc_t *qh, int mode)
984 uhci_desc_t *bqh, *nqh, *prevqh, *prevtd;
986 urb_priv_t *priv=(urb_priv_t*)urb->hcpriv;
988 now=UHCI_GET_CURRENT_FRAME(s);
992 if (!priv->next_queued_urb) { // no more appended bulk queues
994 queue_dbg("uhci_clean_transfer: No more bulks for urb %p, qh %p, bqh %p, nqh %p", urb, qh, bqh, priv->next_qh);
996 if (priv->prev_queued_urb && mode != CLEAN_TRANSFER_DELETION_MARK) { // qh not top of the queue
998 urb_priv_t* ppriv=(urb_priv_t*)priv->prev_queued_urb->hcpriv;
1000 spin_lock_irqsave (&s->qh_lock, flags);
1001 prevqh = list_entry (ppriv->desc_list.next, uhci_desc_t, desc_list);
1002 prevtd = list_entry (prevqh->vertical.prev, uhci_desc_t, vertical);
1003 set_td_link(prevtd, priv->bottom_qh->dma_addr | UHCI_PTR_QH); // skip current qh
1005 queue_dbg("uhci_clean_transfer: relink pqh %p, ptd %p",prevqh, prevtd);
1006 spin_unlock_irqrestore (&s->qh_lock, flags);
1008 ppriv->bottom_qh = priv->bottom_qh;
1009 ppriv->next_queued_urb = NULL;
1011 else { // queue is dead, qh is top of the queue
1013 if (mode != CLEAN_TRANSFER_DELETION_MARK)
1014 unlink_qh(s, qh); // remove qh from horizontal chain
1016 if (bqh) { // remove remainings of bulk queue
1019 if (mode != CLEAN_TRANSFER_DELETION_MARK)
1020 unlink_qh(s, nqh); // remove nqh from horizontal chain
1022 if (mode != CLEAN_TRANSFER_NO_DELETION) { // add helper QHs to free desc list
1023 nqh->last_used = bqh->last_used = now;
1024 list_add_tail (&nqh->horizontal, &s->free_desc);
1025 list_add_tail (&bqh->horizontal, &s->free_desc);
1030 else { // there are queued urbs following
1032 queue_dbg("uhci_clean_transfer: urb %p, prevurb %p, nexturb %p, qh %p, bqh %p, nqh %p",
1033 urb, priv->prev_queued_urb, priv->next_queued_urb, qh, bqh, priv->next_qh);
1035 if (mode != CLEAN_TRANSFER_DELETION_MARK) { // no work for cleanup at unlink-completion
1037 unsigned long flags;
1039 nurb = priv->next_queued_urb;
1040 spin_lock_irqsave (&s->qh_lock, flags);
1042 if (!priv->prev_queued_urb) { // top QH
1044 prevqh = list_entry (qh->horizontal.prev, uhci_desc_t, horizontal);
1045 set_qh_head(prevqh, bqh->dma_addr | UHCI_PTR_QH);
1046 list_del (&qh->horizontal); // remove this qh form horizontal chain
1047 list_add (&bqh->horizontal, &prevqh->horizontal); // insert next bqh in horizontal chain
1049 else { // intermediate QH
1050 urb_priv_t* ppriv=(urb_priv_t*)priv->prev_queued_urb->hcpriv;
1051 urb_priv_t* npriv=(urb_priv_t*)nurb->hcpriv;
1054 bnqh = list_entry (npriv->desc_list.next, uhci_desc_t, desc_list);
1055 ppriv->bottom_qh = bnqh;
1056 ppriv->next_queued_urb = nurb;
1057 prevqh = list_entry (ppriv->desc_list.next, uhci_desc_t, desc_list);
1058 set_qh_head(prevqh, bqh->dma_addr | UHCI_PTR_QH);
1062 ((urb_priv_t*)nurb->hcpriv)->prev_queued_urb=priv->prev_queued_urb;
1063 spin_unlock_irqrestore (&s->qh_lock, flags);
1067 if (mode != CLEAN_TRANSFER_NO_DELETION) {
1068 qh->last_used = now;
1069 list_add_tail (&qh->horizontal, &s->free_desc); // mark qh for later deletion/kfree
1072 /*-------------------------------------------------------------------*/
1073 // Release bandwidth for Interrupt or Isoc. transfers
1074 _static void uhci_release_bandwidth(struct urb *urb)
1076 if (urb->bandwidth) {
1077 switch (usb_pipetype(urb->pipe)) {
1078 case PIPE_INTERRUPT:
1079 usb_release_bandwidth (urb->dev, urb, 0);
1081 case PIPE_ISOCHRONOUS:
1082 usb_release_bandwidth (urb->dev, urb, 1);
1090 _static void uhci_urb_dma_sync(uhci_t *s, struct urb *urb, urb_priv_t *urb_priv)
1092 if (urb_priv->setup_packet_dma)
1093 pci_dma_sync_single(s->uhci_pci, urb_priv->setup_packet_dma,
1094 sizeof(struct usb_ctrlrequest), PCI_DMA_TODEVICE);
1096 if (urb_priv->transfer_buffer_dma)
1097 pci_dma_sync_single(s->uhci_pci, urb_priv->transfer_buffer_dma,
1098 urb->transfer_buffer_length,
1099 usb_pipein(urb->pipe) ?
1100 PCI_DMA_FROMDEVICE :
1104 _static void uhci_urb_dma_unmap(uhci_t *s, struct urb *urb, urb_priv_t *urb_priv)
1106 if (urb_priv->setup_packet_dma) {
1107 pci_unmap_single(s->uhci_pci, urb_priv->setup_packet_dma,
1108 sizeof(struct usb_ctrlrequest), PCI_DMA_TODEVICE);
1109 urb_priv->setup_packet_dma = 0;
1111 if (urb_priv->transfer_buffer_dma) {
1112 pci_unmap_single(s->uhci_pci, urb_priv->transfer_buffer_dma,
1113 urb->transfer_buffer_length,
1114 usb_pipein(urb->pipe) ?
1115 PCI_DMA_FROMDEVICE :
1117 urb_priv->transfer_buffer_dma = 0;
1120 /*-------------------------------------------------------------------*/
1121 /* needs urb_list_lock!
1122 mode: UNLINK_ASYNC_STORE_URB: unlink and move URB into unlinked list
1123 UNLINK_ASYNC_DONT_STORE: unlink, don't move URB into unlinked list
1125 _static int uhci_unlink_urb_async (uhci_t *s,struct urb *urb, int mode)
1128 urb_priv_t *urb_priv;
1130 async_dbg("unlink_urb_async called %p",urb);
1132 if ((urb->status == -EINPROGRESS) ||
1133 ((usb_pipetype (urb->pipe) == PIPE_INTERRUPT) && ((urb_priv_t*)urb->hcpriv)->flags))
1135 ((urb_priv_t*)urb->hcpriv)->started = ~0; // mark
1136 dequeue_urb (s, urb);
1138 if (mode==UNLINK_ASYNC_STORE_URB)
1139 list_add_tail (&urb->urb_list, &s->urb_unlinked); // store urb
1141 uhci_switch_timer_int(s);
1142 s->unlink_urb_done = 1;
1143 uhci_release_bandwidth(urb);
1145 urb->status = -ECONNABORTED; // mark urb as "waiting to be killed"
1146 urb_priv = (urb_priv_t*)urb->hcpriv;
1148 switch (usb_pipetype (urb->pipe)) {
1149 case PIPE_INTERRUPT:
1150 usb_dotoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe));
1152 case PIPE_ISOCHRONOUS:
1153 uhci_clean_iso_step1 (s, urb_priv);
1158 qh = list_entry (urb_priv->desc_list.next, uhci_desc_t, desc_list);
1159 uhci_clean_transfer (s, urb, qh, CLEAN_TRANSFER_NO_DELETION);
1162 ((urb_priv_t*)urb->hcpriv)->started = UHCI_GET_CURRENT_FRAME(s);
1163 return -EINPROGRESS; // completion will follow
1166 return 0; // URB already dead
1168 /*-------------------------------------------------------------------*/
1169 // kills an urb by unlinking descriptors and waiting for at least one frame
1170 _static int uhci_unlink_urb_sync (uhci_t *s, struct urb *urb)
1173 urb_priv_t *urb_priv;
1174 unsigned long flags=0;
1175 struct usb_device *usb_dev;
1177 spin_lock_irqsave (&s->urb_list_lock, flags);
1179 if (urb->status == -EINPROGRESS) {
1181 // move descriptors out of the running chains, dequeue urb
1182 uhci_unlink_urb_async(s, urb, UNLINK_ASYNC_DONT_STORE);
1184 urb_priv = urb->hcpriv;
1185 urb->status = -ENOENT; // prevent from double deletion after unlock
1186 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1189 switch (usb_pipetype (urb->pipe)) {
1191 case PIPE_INTERRUPT:
1192 case PIPE_ISOCHRONOUS:
1194 uhci_clean_iso_step2(s, urb_priv);
1199 qh = list_entry (urb_priv->desc_list.next, uhci_desc_t, desc_list);
1200 uhci_clean_transfer(s, urb, qh, CLEAN_TRANSFER_DELETION_MARK);
1203 urb->status = -ENOENT; // mark urb as killed
1205 uhci_urb_dma_unmap(s, urb, urb->hcpriv);
1208 kmem_cache_free (urb_priv_kmem, urb->hcpriv);
1210 kfree (urb->hcpriv);
1213 if (urb->complete) {
1214 dbg("unlink_urb: calling completion");
1216 urb->complete ((struct urb *) urb);
1218 usb_dec_dev_use (usb_dev);
1221 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1225 /*-------------------------------------------------------------------*/
1226 // async unlink_urb completion/cleanup work
1227 // has to be protected by urb_list_lock!
1228 // features: if set in transfer_flags, the resulting status of the killed
1229 // transaction is not overwritten
1231 _static void uhci_cleanup_unlink(uhci_t *s, int force)
1233 struct list_head *q;
1235 struct usb_device *dev;
1237 urb_priv_t *urb_priv;
1239 q=s->urb_unlinked.next;
1240 now=UHCI_GET_CURRENT_FRAME(s);
1242 while (q != &s->urb_unlinked) {
1244 urb = list_entry (q, struct urb, urb_list);
1246 urb_priv = (urb_priv_t*)urb->hcpriv;
1247 q = urb->urb_list.next;
1249 if (!urb_priv) // avoid crash when URB is corrupted
1252 if (force || ((urb_priv->started != ~0) && (urb_priv->started != now))) {
1253 async_dbg("async cleanup %p",urb);
1254 type=usb_pipetype (urb->pipe);
1256 switch (type) { // process descriptors
1258 process_transfer (s, urb, CLEAN_TRANSFER_DELETION_MARK); // don't unlink (already done)
1261 if (!s->avoid_bulk.counter)
1262 process_transfer (s, urb, CLEAN_TRANSFER_DELETION_MARK); // don't unlink (already done)
1266 case PIPE_ISOCHRONOUS:
1267 process_iso (s, urb, PROCESS_ISO_FORCE); // force, don't unlink
1269 case PIPE_INTERRUPT:
1270 process_interrupt (s, urb);
1274 if (!(urb->transfer_flags & USB_TIMEOUT_KILLED))
1275 urb->status = -ECONNRESET; // mark as asynchronously killed
1277 dev = urb->dev; // completion may destroy all...
1278 urb_priv = urb->hcpriv;
1279 list_del (&urb->urb_list);
1281 uhci_urb_dma_sync(s, urb, urb_priv);
1282 if (urb->complete) {
1283 spin_unlock(&s->urb_list_lock);
1285 urb->complete ((struct urb *) urb);
1286 spin_lock(&s->urb_list_lock);
1289 if (!(urb->transfer_flags & USB_TIMEOUT_KILLED))
1290 urb->status = -ENOENT; // now the urb is really dead
1293 case PIPE_ISOCHRONOUS:
1294 case PIPE_INTERRUPT:
1295 uhci_clean_iso_step2(s, urb_priv);
1299 uhci_urb_dma_unmap(s, urb, urb_priv);
1301 usb_dec_dev_use (dev);
1303 kmem_cache_free (urb_priv_kmem, urb_priv);
1312 /*-------------------------------------------------------------------*/
1313 _static int uhci_unlink_urb (struct urb *urb)
1316 unsigned long flags=0;
1317 dbg("uhci_unlink_urb called for %p",urb);
1318 if (!urb || !urb->dev) // you never know...
1321 s = (uhci_t*) urb->dev->bus->hcpriv;
1323 if (usb_pipedevice (urb->pipe) == s->rh.devnum)
1324 return rh_unlink_urb (urb);
1329 if (urb->transfer_flags & USB_ASYNC_UNLINK) {
1331 spin_lock_irqsave (&s->urb_list_lock, flags);
1333 uhci_release_bandwidth(urb);
1334 ret = uhci_unlink_urb_async(s, urb, UNLINK_ASYNC_STORE_URB);
1336 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1340 return uhci_unlink_urb_sync(s, urb);
1342 /*-------------------------------------------------------------------*/
1343 // In case of ASAP iso transfer, search the URB-list for already queued URBs
1344 // for this EP and calculate the earliest start frame for the new
1345 // URB (easy seamless URB continuation!)
1346 _static int find_iso_limits (struct urb *urb, unsigned int *start, unsigned int *end)
1348 struct urb *u, *last_urb = NULL;
1349 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
1350 struct list_head *p;
1352 unsigned long flags;
1354 spin_lock_irqsave (&s->urb_list_lock, flags);
1357 for (; p != &s->urb_list; p = p->prev) {
1358 u = list_entry (p, struct urb, urb_list);
1359 // look for pending URBs with identical pipe handle
1360 // works only because iso doesn't toggle the data bit!
1361 if ((urb->pipe == u->pipe) && (urb->dev == u->dev) && (u->status == -EINPROGRESS)) {
1363 *start = u->start_frame;
1369 *end = (last_urb->start_frame + last_urb->number_of_packets) & 1023;
1373 spin_unlock_irqrestore(&s->urb_list_lock, flags);
1377 /*-------------------------------------------------------------------*/
1378 // adjust start_frame according to scheduling constraints (ASAP etc)
1380 _static int iso_find_start (struct urb *urb)
1382 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
1384 unsigned int start_limit = 0, stop_limit = 0, queued_size;
1387 now = UHCI_GET_CURRENT_FRAME (s) & 1023;
1389 if ((unsigned) urb->number_of_packets > 900)
1392 limits = find_iso_limits (urb, &start_limit, &stop_limit);
1393 queued_size = (stop_limit - start_limit) & 1023;
1395 if (urb->transfer_flags & USB_ISO_ASAP) {
1398 // 10ms setup should be enough //FIXME!
1399 urb->start_frame = (now + 10) & 1023;
1402 urb->start_frame = stop_limit; //seamless linkage
1404 if (((now - urb->start_frame) & 1023) <= (unsigned) urb->number_of_packets) {
1405 info("iso_find_start: gap in seamless isochronous scheduling");
1406 dbg("iso_find_start: now %u start_frame %u number_of_packets %u pipe 0x%08x",
1407 now, urb->start_frame, urb->number_of_packets, urb->pipe);
1408 urb->start_frame = (now + 5) & 1023; // 5ms setup should be enough //FIXME!
1413 urb->start_frame &= 1023;
1414 if (((now - urb->start_frame) & 1023) < (unsigned) urb->number_of_packets) {
1415 dbg("iso_find_start: now between start_frame and end");
1420 /* check if either start_frame or start_frame+number_of_packets-1 lies between start_limit and stop_limit */
1424 if (((urb->start_frame - start_limit) & 1023) < queued_size ||
1425 ((urb->start_frame + urb->number_of_packets - 1 - start_limit) & 1023) < queued_size) {
1426 dbg("iso_find_start: start_frame %u number_of_packets %u start_limit %u stop_limit %u",
1427 urb->start_frame, urb->number_of_packets, start_limit, stop_limit);
1433 /*-------------------------------------------------------------------*/
1434 // submits USB interrupt (ie. polling ;-)
1435 // ASAP-flag set implicitely
1436 // if period==0, the transfer is only done once
1438 _static int uhci_submit_int_urb (struct urb *urb)
1440 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
1441 urb_priv_t *urb_priv = urb->hcpriv;
1444 int status, destination;
1446 unsigned int pipe = urb->pipe;
1448 if (urb->interval < 0 || urb->interval >= 256)
1451 if (urb->interval == 0)
1454 for (nint = 0, n = 1; nint <= 8; nint++, n += n) // round interval down to 2^n
1456 if (urb->interval < n) {
1457 urb->interval = n / 2;
1464 dbg("Rounded interval to %i, chain %i", urb->interval, nint);
1466 urb->start_frame = UHCI_GET_CURRENT_FRAME (s) & 1023; // remember start frame, just in case...
1468 urb->number_of_packets = 1;
1470 // INT allows only one packet
1471 if (urb->transfer_buffer_length > usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe)))
1474 if (alloc_td (s, &td, UHCI_PTR_DEPTH))
1477 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_IOC |
1478 (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD) | (3 << 27);
1480 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid (urb->pipe) |
1481 (((urb->transfer_buffer_length - 1) & 0x7ff) << 21);
1484 info = destination | (usb_gettoggle (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)) << TD_TOKEN_TOGGLE);
1486 fill_td (td, status, info, urb_priv->transfer_buffer_dma);
1487 list_add_tail (&td->desc_list, &urb_priv->desc_list);
1491 insert_td_horizontal (s, s->int_chain[nint], td); // store in INT-TDs
1493 usb_dotoggle (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
1497 /*-------------------------------------------------------------------*/
1498 _static int uhci_submit_iso_urb (struct urb *urb)
1500 uhci_t *s = (uhci_t*) urb->dev->bus->hcpriv;
1501 urb_priv_t *urb_priv = urb->hcpriv;
1502 #ifdef ISO_SANITY_CHECK
1504 int maxsze = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe));
1507 uhci_desc_t *td, **tdm;
1508 int status, destination;
1509 unsigned long flags;
1511 __save_flags(flags);
1512 __cli(); // Disable IRQs to schedule all ISO-TDs in time
1513 ret = iso_find_start (urb); // adjusts urb->start_frame for later use
1518 tdm = (uhci_desc_t **) kmalloc (urb->number_of_packets * sizeof (uhci_desc_t*), KMALLOC_FLAG);
1525 memset(tdm, 0, urb->number_of_packets * sizeof (uhci_desc_t*));
1527 // First try to get all TDs. Cause: Removing already inserted TDs can only be done
1528 // racefree in three steps: unlink TDs, wait one frame, delete TDs.
1529 // So, this solutions seems simpler...
1531 for (n = 0; n < urb->number_of_packets; n++) {
1532 dbg("n:%d urb->iso_frame_desc[n].length:%d", n, urb->iso_frame_desc[n].length);
1533 if (!urb->iso_frame_desc[n].length)
1534 continue; // allows ISO striping by setting length to zero in iso_descriptor
1537 #ifdef ISO_SANITY_CHECK
1538 if(urb->iso_frame_desc[n].length > maxsze) {
1540 err("submit_iso: urb->iso_frame_desc[%d].length(%d)>%d",n , urb->iso_frame_desc[n].length, maxsze);
1545 if (alloc_td (s, &td, UHCI_PTR_DEPTH)) {
1546 int i; // Cleanup allocated TDs
1548 for (i = 0; i < n; n++)
1550 delete_desc(s, tdm[i]);
1558 status = TD_CTRL_ACTIVE | TD_CTRL_IOS;
1560 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid (urb->pipe);
1562 // Queue all allocated TDs
1563 for (n = 0; n < urb->number_of_packets; n++) {
1569 status |= TD_CTRL_IOC;
1573 fill_td (td, status, destination | (((urb->iso_frame_desc[n].length - 1) & 0x7ff) << 21),
1574 urb_priv->transfer_buffer_dma + urb->iso_frame_desc[n].offset);
1575 list_add_tail (&td->desc_list, &urb_priv->desc_list);
1577 insert_td_horizontal (s, s->iso_td[(urb->start_frame + n) & 1023], td); // store in iso-tds
1581 dbg("ISO-INT# %i, start %i, now %i", urb->number_of_packets, urb->start_frame, UHCI_GET_CURRENT_FRAME (s) & 1023);
1585 __restore_flags(flags);
1588 /*-------------------------------------------------------------------*/
1589 // returns: 0 (no transfer queued), urb* (this urb already queued)
1591 _static struct urb* search_dev_ep (uhci_t *s, struct urb *urb)
1593 struct list_head *p;
1595 unsigned int mask = usb_pipecontrol(urb->pipe) ? (~USB_DIR_IN) : (~0);
1597 dbg("search_dev_ep:");
1601 for (; p != &s->urb_list; p = p->next) {
1602 tmp = list_entry (p, struct urb, urb_list);
1603 dbg("urb: %p", tmp);
1604 // we can accept this urb if it is not queued at this time
1605 // or if non-iso transfer requests should be scheduled for the same device and pipe
1606 if ((!usb_pipeisoc(urb->pipe) && (tmp->dev == urb->dev) && !((tmp->pipe ^ urb->pipe) & mask)) ||
1608 return tmp; // found another urb already queued for processing
1614 /*-------------------------------------------------------------------*/
1615 _static int uhci_submit_urb (struct urb *urb)
1618 urb_priv_t *urb_priv;
1620 unsigned long flags;
1621 struct urb *queued_urb=NULL;
1624 if (!urb->dev || !urb->dev->bus)
1627 s = (uhci_t*) urb->dev->bus->hcpriv;
1628 //dbg("submit_urb: %p type %d",urb,usb_pipetype(urb->pipe));
1633 type = usb_pipetype (urb->pipe);
1635 if (usb_pipedevice (urb->pipe) == s->rh.devnum)
1636 return rh_submit_urb (urb); /* virtual root hub */
1639 if (usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe)) <= 0) {
1640 err("uhci_submit_urb: pipesize for pipe %x is zero", urb->pipe);
1644 if (urb->transfer_buffer_length < 0 && type != PIPE_ISOCHRONOUS) {
1645 err("uhci_submit_urb: Negative transfer length for urb %p", urb);
1649 usb_inc_dev_use (urb->dev);
1651 spin_lock_irqsave (&s->urb_list_lock, flags);
1653 queued_urb = search_dev_ep (s, urb); // returns already queued urb for that pipe
1657 queue_dbg("found bulk urb %p\n", queued_urb);
1659 if (( type != PIPE_BULK) ||
1660 ((type == PIPE_BULK) &&
1661 (!(urb->transfer_flags & USB_QUEUE_BULK) || !(queued_urb->transfer_flags & USB_QUEUE_BULK)))) {
1662 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1663 usb_dec_dev_use (urb->dev);
1664 err("ENXIO %08x, flags %x, urb %p, burb %p",urb->pipe,urb->transfer_flags,urb,queued_urb);
1665 return -ENXIO; // urb already queued
1670 urb_priv = kmem_cache_alloc(urb_priv_kmem, SLAB_FLAG);
1672 urb_priv = kmalloc (sizeof (urb_priv_t), KMALLOC_FLAG);
1675 usb_dec_dev_use (urb->dev);
1676 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1680 memset(urb_priv, 0, sizeof(urb_priv_t));
1681 urb->hcpriv = urb_priv;
1682 INIT_LIST_HEAD (&urb_priv->desc_list);
1684 dbg("submit_urb: scheduling %p", urb);
1686 if (type == PIPE_CONTROL)
1687 urb_priv->setup_packet_dma = pci_map_single(s->uhci_pci, urb->setup_packet,
1688 sizeof(struct usb_ctrlrequest), PCI_DMA_TODEVICE);
1690 if (urb->transfer_buffer_length)
1691 urb_priv->transfer_buffer_dma = pci_map_single(s->uhci_pci,
1692 urb->transfer_buffer,
1693 urb->transfer_buffer_length,
1694 usb_pipein(urb->pipe) ?
1695 PCI_DMA_FROMDEVICE :
1698 if (type == PIPE_BULK) {
1701 while (((urb_priv_t*)queued_urb->hcpriv)->next_queued_urb) // find last queued bulk
1702 queued_urb=((urb_priv_t*)queued_urb->hcpriv)->next_queued_urb;
1704 ((urb_priv_t*)queued_urb->hcpriv)->next_queued_urb=urb;
1706 atomic_inc (&s->avoid_bulk);
1707 ret = uhci_submit_bulk_urb (urb, queued_urb);
1708 atomic_dec (&s->avoid_bulk);
1709 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1712 spin_unlock_irqrestore (&s->urb_list_lock, flags);
1714 case PIPE_ISOCHRONOUS:
1715 if (urb->bandwidth == 0) { /* not yet checked/allocated */
1716 if (urb->number_of_packets <= 0) {
1721 bustime = usb_check_bandwidth (urb->dev, urb);
1725 ret = uhci_submit_iso_urb(urb);
1727 usb_claim_bandwidth (urb->dev, urb, bustime, 1);
1729 } else { /* bandwidth is already set */
1730 ret = uhci_submit_iso_urb(urb);
1733 case PIPE_INTERRUPT:
1734 if (urb->bandwidth == 0) { /* not yet checked/allocated */
1735 bustime = usb_check_bandwidth (urb->dev, urb);
1739 ret = uhci_submit_int_urb(urb);
1741 usb_claim_bandwidth (urb->dev, urb, bustime, 0);
1743 } else { /* bandwidth is already set */
1744 ret = uhci_submit_int_urb(urb);
1748 ret = uhci_submit_control_urb (urb);
1755 dbg("submit_urb: scheduled with ret: %d", ret);
1758 uhci_urb_dma_unmap(s, urb, urb_priv);
1759 usb_dec_dev_use (urb->dev);
1761 kmem_cache_free(urb_priv_kmem, urb_priv);
1771 // Checks for URB timeout and removes bandwidth reclamation if URB idles too long
1772 _static void uhci_check_timeouts(uhci_t *s)
1774 struct list_head *p,*p2;
1778 p = s->urb_list.prev;
1780 while (p != &s->urb_list) {
1785 urb = list_entry (p2, struct urb, urb_list);
1786 type = usb_pipetype (urb->pipe);
1788 hcpriv = (urb_priv_t*)urb->hcpriv;
1790 if ( urb->timeout && time_after(jiffies, hcpriv->started + urb->timeout)) {
1791 urb->transfer_flags |= USB_TIMEOUT_KILLED | USB_ASYNC_UNLINK;
1792 async_dbg("uhci_check_timeout: timeout for %p",urb);
1793 uhci_unlink_urb_async(s, urb, UNLINK_ASYNC_STORE_URB);
1795 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
1796 else if (((type == PIPE_BULK) || (type == PIPE_CONTROL)) &&
1797 (hcpriv->use_loop) && time_after(jiffies, hcpriv->started + IDLE_TIMEOUT))
1798 disable_desc_loop(s, urb);
1802 s->timeout_check=jiffies;
1805 /*-------------------------------------------------------------------
1807 -------------------------------------------------------------------*/
1809 _static __u8 root_hub_dev_des[] =
1811 0x12, /* __u8 bLength; */
1812 0x01, /* __u8 bDescriptorType; Device */
1813 0x00, /* __u16 bcdUSB; v1.0 */
1815 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1816 0x00, /* __u8 bDeviceSubClass; */
1817 0x00, /* __u8 bDeviceProtocol; */
1818 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1819 0x00, /* __u16 idVendor; */
1821 0x00, /* __u16 idProduct; */
1823 0x00, /* __u16 bcdDevice; */
1825 0x00, /* __u8 iManufacturer; */
1826 0x02, /* __u8 iProduct; */
1827 0x01, /* __u8 iSerialNumber; */
1828 0x01 /* __u8 bNumConfigurations; */
1832 /* Configuration descriptor */
1833 _static __u8 root_hub_config_des[] =
1835 0x09, /* __u8 bLength; */
1836 0x02, /* __u8 bDescriptorType; Configuration */
1837 0x19, /* __u16 wTotalLength; */
1839 0x01, /* __u8 bNumInterfaces; */
1840 0x01, /* __u8 bConfigurationValue; */
1841 0x00, /* __u8 iConfiguration; */
1842 0x40, /* __u8 bmAttributes;
1843 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
1844 0x00, /* __u8 MaxPower; */
1847 0x09, /* __u8 if_bLength; */
1848 0x04, /* __u8 if_bDescriptorType; Interface */
1849 0x00, /* __u8 if_bInterfaceNumber; */
1850 0x00, /* __u8 if_bAlternateSetting; */
1851 0x01, /* __u8 if_bNumEndpoints; */
1852 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1853 0x00, /* __u8 if_bInterfaceSubClass; */
1854 0x00, /* __u8 if_bInterfaceProtocol; */
1855 0x00, /* __u8 if_iInterface; */
1858 0x07, /* __u8 ep_bLength; */
1859 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1860 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1861 0x03, /* __u8 ep_bmAttributes; Interrupt */
1862 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
1864 0xff /* __u8 ep_bInterval; 255 ms */
1868 _static __u8 root_hub_hub_des[] =
1870 0x09, /* __u8 bLength; */
1871 0x29, /* __u8 bDescriptorType; Hub-descriptor */
1872 0x02, /* __u8 bNbrPorts; */
1873 0x00, /* __u16 wHubCharacteristics; */
1875 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
1876 0x00, /* __u8 bHubContrCurrent; 0 mA */
1877 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
1878 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
1881 /*-------------------------------------------------------------------------*/
1882 /* prepare Interrupt pipe transaction data; HUB INTERRUPT ENDPOINT */
1883 _static int rh_send_irq (struct urb *urb)
1887 uhci_t *uhci = urb->dev->bus->hcpriv;
1888 unsigned int io_addr = uhci->io_addr;
1891 for (i = 0; i < uhci->rh.numports; i++) {
1892 data |= ((inw (io_addr + USBPORTSC1 + i * 2) & 0xa) > 0 ? (1 << (i + 1)) : 0);
1893 len = (i + 1) / 8 + 1;
1896 *(__u16 *) urb->transfer_buffer = cpu_to_le16 (data);
1897 urb->actual_length = len;
1900 if ((data > 0) && (uhci->rh.send != 0)) {
1901 dbg("Root-Hub INT complete: port1: %x port2: %x data: %x",
1902 inw (io_addr + USBPORTSC1), inw (io_addr + USBPORTSC2), data);
1903 urb->complete (urb);
1908 /*-------------------------------------------------------------------------*/
1909 /* Virtual Root Hub INTs are polled by this timer every "intervall" ms */
1910 _static int rh_init_int_timer (struct urb *urb);
1912 _static void rh_int_timer_do (unsigned long ptr)
1915 struct urb *urb = (struct urb*) ptr;
1916 uhci_t *uhci = urb->dev->bus->hcpriv;
1918 if (uhci->rh.send) {
1919 len = rh_send_irq (urb);
1921 urb->actual_length = len;
1923 urb->complete (urb);
1926 rh_init_int_timer (urb);
1929 /*-------------------------------------------------------------------------*/
1930 /* Root Hub INTs are polled by this timer, polling interval 20ms */
1932 _static int rh_init_int_timer (struct urb *urb)
1934 uhci_t *uhci = urb->dev->bus->hcpriv;
1936 uhci->rh.interval = urb->interval;
1937 init_timer (&uhci->rh.rh_int_timer);
1938 uhci->rh.rh_int_timer.function = rh_int_timer_do;
1939 uhci->rh.rh_int_timer.data = (unsigned long) urb;
1940 uhci->rh.rh_int_timer.expires = jiffies + (HZ * 20) / 1000;
1941 add_timer (&uhci->rh.rh_int_timer);
1946 /*-------------------------------------------------------------------------*/
1947 #define OK(x) len = (x); break
1949 #define CLR_RH_PORTSTAT(x) \
1950 status = inw(io_addr+USBPORTSC1+2*(wIndex-1)); \
1951 status = (status & 0xfff5) & ~(x); \
1952 outw(status, io_addr+USBPORTSC1+2*(wIndex-1))
1954 #define SET_RH_PORTSTAT(x) \
1955 status = inw(io_addr+USBPORTSC1+2*(wIndex-1)); \
1956 status = (status & 0xfff5) | (x); \
1957 outw(status, io_addr+USBPORTSC1+2*(wIndex-1))
1960 /*-------------------------------------------------------------------------*/
1962 ** Root Hub Control Pipe
1963 *************************/
1966 _static int rh_submit_urb (struct urb *urb)
1968 struct usb_device *usb_dev = urb->dev;
1969 uhci_t *uhci = usb_dev->bus->hcpriv;
1970 unsigned int pipe = urb->pipe;
1971 struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *) urb->setup_packet;
1972 void *data = urb->transfer_buffer;
1973 int leni = urb->transfer_buffer_length;
1978 unsigned int io_addr = uhci->io_addr;
1986 if (usb_pipetype (pipe) == PIPE_INTERRUPT) {
1987 dbg("Root-Hub submit IRQ: every %d ms", urb->interval);
1990 uhci->rh.interval = urb->interval;
1991 rh_init_int_timer (urb);
1997 bmRType_bReq = cmd->bRequestType | cmd->bRequest << 8;
1998 wValue = le16_to_cpu (cmd->wValue);
1999 wIndex = le16_to_cpu (cmd->wIndex);
2000 wLength = le16_to_cpu (cmd->wLength);
2002 for (i = 0; i < 8; i++)
2003 uhci->rh.c_p_r[i] = 0;
2005 dbg("Root-Hub: adr: %2x cmd(%1x): %04x %04x %04x %04x",
2006 uhci->rh.devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
2008 switch (bmRType_bReq) {
2009 /* Request Destination:
2010 without flags: Device,
2011 RH_INTERFACE: interface,
2012 RH_ENDPOINT: endpoint,
2013 RH_CLASS means HUB here,
2014 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
2018 *(__u16 *) data = cpu_to_le16 (1);
2020 case RH_GET_STATUS | RH_INTERFACE:
2021 *(__u16 *) data = cpu_to_le16 (0);
2023 case RH_GET_STATUS | RH_ENDPOINT:
2024 *(__u16 *) data = cpu_to_le16 (0);
2026 case RH_GET_STATUS | RH_CLASS:
2027 *(__u32 *) data = cpu_to_le32 (0);
2028 OK (4); /* hub power ** */
2029 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
2030 status = inw (io_addr + USBPORTSC1 + 2 * (wIndex - 1));
2031 cstatus = ((status & USBPORTSC_CSC) >> (1 - 0)) |
2032 ((status & USBPORTSC_PEC) >> (3 - 1)) |
2033 (uhci->rh.c_p_r[wIndex - 1] << (0 + 4));
2034 status = (status & USBPORTSC_CCS) |
2035 ((status & USBPORTSC_PE) >> (2 - 1)) |
2036 ((status & USBPORTSC_SUSP) >> (12 - 2)) |
2037 ((status & USBPORTSC_PR) >> (9 - 4)) |
2038 (1 << 8) | /* power on ** */
2039 ((status & USBPORTSC_LSDA) << (-8 + 9));
2041 *(__u16 *) data = cpu_to_le16 (status);
2042 *(__u16 *) (data + 2) = cpu_to_le16 (cstatus);
2045 case RH_CLEAR_FEATURE | RH_ENDPOINT:
2047 case (RH_ENDPOINT_STALL):
2052 case RH_CLEAR_FEATURE | RH_CLASS:
2054 case (RH_C_HUB_OVER_CURRENT):
2055 OK (0); /* hub power over current ** */
2059 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
2061 case (RH_PORT_ENABLE):
2062 CLR_RH_PORTSTAT (USBPORTSC_PE);
2064 case (RH_PORT_SUSPEND):
2065 CLR_RH_PORTSTAT (USBPORTSC_SUSP);
2067 case (RH_PORT_POWER):
2068 OK (0); /* port power ** */
2069 case (RH_C_PORT_CONNECTION):
2070 SET_RH_PORTSTAT (USBPORTSC_CSC);
2072 case (RH_C_PORT_ENABLE):
2073 SET_RH_PORTSTAT (USBPORTSC_PEC);
2075 case (RH_C_PORT_SUSPEND):
2076 /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
2078 case (RH_C_PORT_OVER_CURRENT):
2079 OK (0); /* port power over current ** */
2080 case (RH_C_PORT_RESET):
2081 uhci->rh.c_p_r[wIndex - 1] = 0;
2086 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
2088 case (RH_PORT_SUSPEND):
2089 SET_RH_PORTSTAT (USBPORTSC_SUSP);
2091 case (RH_PORT_RESET):
2092 SET_RH_PORTSTAT (USBPORTSC_PR);
2094 uhci->rh.c_p_r[wIndex - 1] = 1;
2095 CLR_RH_PORTSTAT (USBPORTSC_PR);
2097 SET_RH_PORTSTAT (USBPORTSC_PE);
2099 SET_RH_PORTSTAT (0xa);
2101 case (RH_PORT_POWER):
2102 OK (0); /* port power ** */
2103 case (RH_PORT_ENABLE):
2104 SET_RH_PORTSTAT (USBPORTSC_PE);
2109 case RH_SET_ADDRESS:
2110 uhci->rh.devnum = wValue;
2113 case RH_GET_DESCRIPTOR:
2114 switch ((wValue & 0xff00) >> 8) {
2115 case (0x01): /* device descriptor */
2116 len = min_t(unsigned int, leni,
2118 sizeof (root_hub_dev_des), wLength));
2119 memcpy (data, root_hub_dev_des, len);
2121 case (0x02): /* configuration descriptor */
2122 len = min_t(unsigned int, leni,
2124 sizeof (root_hub_config_des), wLength));
2125 memcpy (data, root_hub_config_des, len);
2127 case (0x03): /* string descriptors */
2128 len = usb_root_hub_string (wValue & 0xff,
2129 uhci->io_addr, "UHCI",
2132 OK(min_t(int, leni, len));
2138 case RH_GET_DESCRIPTOR | RH_CLASS:
2139 root_hub_hub_des[2] = uhci->rh.numports;
2140 len = min_t(unsigned int, leni,
2141 min_t(unsigned int, sizeof (root_hub_hub_des), wLength));
2142 memcpy (data, root_hub_hub_des, len);
2145 case RH_GET_CONFIGURATION:
2146 *(__u8 *) data = 0x01;
2149 case RH_SET_CONFIGURATION:
2155 dbg("Root-Hub stat port1: %x port2: %x",
2156 inw (io_addr + USBPORTSC1), inw (io_addr + USBPORTSC2));
2158 urb->actual_length = len;
2162 urb->complete (urb);
2165 /*-------------------------------------------------------------------------*/
2167 _static int rh_unlink_urb (struct urb *urb)
2169 uhci_t *uhci = urb->dev->bus->hcpriv;
2171 if (uhci->rh.urb==urb) {
2172 dbg("Root-Hub unlink IRQ");
2174 del_timer (&uhci->rh.rh_int_timer);
2178 /*-------------------------------------------------------------------*/
2181 * Map status to standard result codes
2183 * <status> is (td->status & 0xFE0000) [a.k.a. uhci_status_bits(td->status)
2184 * <dir_out> is True for output TDs and False for input TDs.
2186 _static int uhci_map_status (int status, int dir_out)
2190 if (status & TD_CTRL_BITSTUFF) /* Bitstuff error */
2192 if (status & TD_CTRL_CRCTIMEO) { /* CRC/Timeout */
2198 if (status & TD_CTRL_NAK) /* NAK */
2200 if (status & TD_CTRL_BABBLE) /* Babble */
2202 if (status & TD_CTRL_DBUFERR) /* Buffer error */
2204 if (status & TD_CTRL_STALLED) /* Stalled */
2206 if (status & TD_CTRL_ACTIVE) /* Active */
2213 * Only the USB core should call uhci_alloc_dev and uhci_free_dev
2215 _static int uhci_alloc_dev (struct usb_device *usb_dev)
2220 _static void uhci_unlink_urbs(uhci_t *s, struct usb_device *usb_dev, int remove_all)
2222 unsigned long flags;
2223 struct list_head *p;
2224 struct list_head *p2;
2227 spin_lock_irqsave (&s->urb_list_lock, flags);
2228 p = s->urb_list.prev;
2229 while (p != &s->urb_list) {
2232 urb = list_entry (p2, struct urb, urb_list);
2233 dbg("urb: %p, dev %p, %p", urb, usb_dev,urb->dev);
2235 //urb->transfer_flags |=USB_ASYNC_UNLINK;
2237 if (remove_all || (usb_dev == urb->dev)) {
2238 spin_unlock_irqrestore (&s->urb_list_lock, flags);
2239 warn("forced removing of queued URB %p due to disconnect",urb);
2240 uhci_unlink_urb(urb);
2241 urb->dev = NULL; // avoid further processing of this URB
2242 spin_lock_irqsave (&s->urb_list_lock, flags);
2243 p = s->urb_list.prev;
2246 spin_unlock_irqrestore (&s->urb_list_lock, flags);
2249 _static int uhci_free_dev (struct usb_device *usb_dev)
2254 if(!usb_dev || !usb_dev->bus || !usb_dev->bus->hcpriv)
2257 s=(uhci_t*) usb_dev->bus->hcpriv;
2258 uhci_unlink_urbs(s, usb_dev, 0);
2264 * uhci_get_current_frame_number()
2266 * returns the current frame number for a USB bus/controller.
2268 _static int uhci_get_current_frame_number (struct usb_device *usb_dev)
2270 return UHCI_GET_CURRENT_FRAME ((uhci_t*) usb_dev->bus->hcpriv);
2273 struct usb_operations uhci_device_operations =
2277 uhci_get_current_frame_number,
2282 _static void correct_data_toggles(struct urb *urb)
2284 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe),
2285 !usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe)));
2288 urb_priv_t *priv=urb->hcpriv;
2289 uhci_desc_t *qh = list_entry (priv->desc_list.next, uhci_desc_t, desc_list);
2290 struct list_head *p = qh->vertical.next;
2292 dbg("URB to correct %p\n", urb);
2294 for (; p != &qh->vertical; p = p->next) {
2295 td = list_entry (p, uhci_desc_t, vertical);
2296 td->hw.td.info^=cpu_to_le32(1<<TD_TOKEN_TOGGLE);
2298 urb=priv->next_queued_urb;
2303 * For IN-control transfers, process_transfer gets a bit more complicated,
2304 * since there are devices that return less data (eg. strings) than they
2305 * have announced. This leads to a queue abort due to the short packet,
2306 * the status stage is not executed. If this happens, the status stage
2307 * is manually re-executed.
2308 * mode: PROCESS_TRANSFER_REGULAR: regular (unlink QH)
2309 * PROCESS_TRANSFER_DONT_UNLINK: QHs already unlinked (for async unlink_urb)
2312 _static int process_transfer (uhci_t *s, struct urb *urb, int mode)
2315 urb_priv_t *urb_priv = urb->hcpriv;
2316 struct list_head *qhl = urb_priv->desc_list.next;
2317 uhci_desc_t *qh = list_entry (qhl, uhci_desc_t, desc_list);
2318 struct list_head *p = qh->vertical.next;
2319 uhci_desc_t *desc= list_entry (urb_priv->desc_list.prev, uhci_desc_t, desc_list);
2320 uhci_desc_t *last_desc = list_entry (desc->vertical.prev, uhci_desc_t, vertical);
2321 int data_toggle = usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe)); // save initial data_toggle
2322 int maxlength; // extracted and remapped info from TD
2326 //dbg("process_transfer: urb %p, urb_priv %p, qh %p last_desc %p\n",urb,urb_priv, qh, last_desc);
2328 /* if the status phase has been retriggered and the
2329 queue is empty or the last status-TD is inactive, the retriggered
2330 status stage is completed
2333 if (urb_priv->flags &&
2334 ((qh->hw.qh.element == cpu_to_le32(UHCI_PTR_TERM)) || !is_td_active(desc)))
2335 goto transfer_finished;
2337 urb->actual_length=0;
2339 for (; p != &qh->vertical; p = p->next) {
2340 desc = list_entry (p, uhci_desc_t, vertical);
2342 if (is_td_active(desc)) { // do not process active TDs
2343 if (mode == CLEAN_TRANSFER_DELETION_MARK) // if called from async_unlink
2344 uhci_clean_transfer(s, urb, qh, CLEAN_TRANSFER_DELETION_MARK);
2348 actual_length = uhci_actual_length(le32_to_cpu(desc->hw.td.status)); // extract transfer parameters from TD
2349 maxlength = (((le32_to_cpu(desc->hw.td.info) >> 21) & 0x7ff) + 1) & 0x7ff;
2350 status = uhci_map_status (uhci_status_bits (le32_to_cpu(desc->hw.td.status)), usb_pipeout (urb->pipe));
2352 if (status == -EPIPE) { // see if EP is stalled
2353 // set up stalled condition
2354 usb_endpoint_halt (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe));
2357 if (status && (status != -EPIPE)) { // if any error occurred stop processing of further TDs
2358 // only set ret if status returned an error
2364 else if ((le32_to_cpu(desc->hw.td.info) & 0xff) != USB_PID_SETUP)
2365 urb->actual_length += actual_length;
2367 // got less data than requested
2368 if ( (actual_length < maxlength)) {
2369 if (urb->transfer_flags & USB_DISABLE_SPD) {
2370 status = -EREMOTEIO; // treat as real error
2371 dbg("process_transfer: SPD!!");
2372 break; // exit after this TD because SP was detected
2375 // short read during control-IN: re-start status stage
2376 if ((usb_pipetype (urb->pipe) == PIPE_CONTROL)) {
2377 if (uhci_packetid(le32_to_cpu(last_desc->hw.td.info)) == USB_PID_OUT) {
2379 set_qh_element(qh, last_desc->dma_addr); // re-trigger status stage
2380 dbg("short packet during control transfer, retrigger status stage @ %p",last_desc);
2381 urb_priv->flags = 1; // mark as short control packet
2385 // all other cases: short read is OK
2386 data_toggle = uhci_toggle (le32_to_cpu(desc->hw.td.info));
2392 data_toggle = uhci_toggle (le32_to_cpu(desc->hw.td.info));
2393 queue_dbg("process_transfer: len:%d status:%x mapped:%x toggle:%d", actual_length, le32_to_cpu(desc->hw.td.status),status, data_toggle);
2397 if (usb_pipetype (urb->pipe) == PIPE_BULK ) { /* toggle correction for short bulk transfers (nonqueued/queued) */
2399 urb_priv_t *priv=(urb_priv_t*)urb->hcpriv;
2400 struct urb *next_queued_urb=priv->next_queued_urb;
2402 if (next_queued_urb) {
2403 urb_priv_t *next_priv=(urb_priv_t*)next_queued_urb->hcpriv;
2404 uhci_desc_t *qh = list_entry (next_priv->desc_list.next, uhci_desc_t, desc_list);
2405 uhci_desc_t *first_td=list_entry (qh->vertical.next, uhci_desc_t, vertical);
2407 if (data_toggle == uhci_toggle (le32_to_cpu(first_td->hw.td.info))) {
2408 err("process_transfer: fixed toggle");
2409 correct_data_toggles(next_queued_urb);
2413 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe), !data_toggle);
2418 uhci_clean_transfer(s, urb, qh, mode);
2420 urb->status = status;
2422 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
2423 disable_desc_loop(s,urb);
2426 queue_dbg("process_transfer: (end) urb %p, wanted len %d, len %d status %x err %d",
2427 urb,urb->transfer_buffer_length,urb->actual_length, urb->status, urb->error_count);
2431 _static int process_interrupt (uhci_t *s, struct urb *urb)
2433 int ret = -EINPROGRESS;
2434 urb_priv_t *urb_priv = urb->hcpriv;
2435 struct list_head *p;
2436 uhci_desc_t *desc = list_entry (urb_priv->desc_list.prev, uhci_desc_t, desc_list);
2441 //dbg("urb contains interrupt request");
2443 // Maybe we allow more than one TD later ;-)
2444 while ((p = urb_priv->desc_list.next) != &urb_priv->desc_list) {
2446 desc = list_entry (p, uhci_desc_t, desc_list);
2448 if (is_td_active(desc)) {
2449 // do not process active TDs
2450 //dbg("TD ACT Status @%p %08x",desc,le32_to_cpu(desc->hw.td.status));
2454 if (!(desc->hw.td.status & cpu_to_le32(TD_CTRL_IOC))) {
2455 // do not process one-shot TDs, no recycling
2458 // extract transfer parameters from TD
2460 actual_length = uhci_actual_length(le32_to_cpu(desc->hw.td.status));
2461 status = uhci_map_status (uhci_status_bits (le32_to_cpu(desc->hw.td.status)), usb_pipeout (urb->pipe));
2463 // see if EP is stalled
2464 if (status == -EPIPE) {
2465 // set up stalled condition
2466 usb_endpoint_halt (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe));
2469 // if any error occurred: ignore this td, and continue
2471 //uhci_show_td (desc);
2476 urb->actual_length = actual_length;
2479 uhci_urb_dma_sync(s, urb, urb->hcpriv);
2480 if (urb->complete) {
2481 //dbg("process_interrupt: calling completion, status %i",status);
2482 urb->status = status;
2483 ((urb_priv_t*)urb->hcpriv)->flags=1; // if unlink_urb is called during completion
2485 spin_unlock(&s->urb_list_lock);
2487 urb->complete ((struct urb *) urb);
2489 spin_lock(&s->urb_list_lock);
2491 ((urb_priv_t*)urb->hcpriv)->flags=0;
2494 if ((urb->status != -ECONNABORTED) && (urb->status != ECONNRESET) &&
2495 (urb->status != -ENOENT)) {
2497 urb->status = -EINPROGRESS;
2499 // Recycle INT-TD if interval!=0, else mark TD as one-shot
2500 if (urb->interval) {
2502 desc->hw.td.info &= cpu_to_le32(~(1 << TD_TOKEN_TOGGLE));
2504 ((urb_priv_t*)urb->hcpriv)->started=jiffies;
2505 desc->hw.td.info |= cpu_to_le32((usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe),
2506 usb_pipeout (urb->pipe)) << TD_TOKEN_TOGGLE));
2507 usb_dotoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe));
2509 desc->hw.td.info |= cpu_to_le32((!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe),
2510 usb_pipeout (urb->pipe)) << TD_TOKEN_TOGGLE));
2512 desc->hw.td.status= cpu_to_le32((urb->pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_IOC |
2513 (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD) | (3 << 27));
2517 uhci_unlink_urb_async(s, urb, UNLINK_ASYNC_STORE_URB);
2518 uhci_clean_iso_step2(s, urb_priv);
2519 // correct toggle after unlink
2520 usb_dotoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_pipeout (urb->pipe));
2521 clr_td_ioc(desc); // inactivate TD
2529 // mode: PROCESS_ISO_REGULAR: processing only for done TDs, unlink TDs
2530 // mode: PROCESS_ISO_FORCE: force processing, don't unlink TDs (already unlinked)
2532 _static int process_iso (uhci_t *s, struct urb *urb, int mode)
2536 urb_priv_t *urb_priv = urb->hcpriv;
2537 struct list_head *p = urb_priv->desc_list.next, *p_tmp;
2538 uhci_desc_t *desc = list_entry (urb_priv->desc_list.prev, uhci_desc_t, desc_list);
2540 dbg("urb contains iso request");
2541 if (is_td_active(desc) && mode==PROCESS_ISO_REGULAR)
2542 return -EXDEV; // last TD not finished
2544 urb->error_count = 0;
2545 urb->actual_length = 0;
2547 dbg("process iso urb %p, %li, %i, %i, %i %08x",urb,jiffies,UHCI_GET_CURRENT_FRAME(s),
2548 urb->number_of_packets,mode,le32_to_cpu(desc->hw.td.status));
2550 for (i = 0; p != &urb_priv->desc_list; i++) {
2551 desc = list_entry (p, uhci_desc_t, desc_list);
2553 //uhci_show_td(desc);
2554 if (is_td_active(desc)) {
2555 // means we have completed the last TD, but not the TDs before
2556 desc->hw.td.status &= cpu_to_le32(~TD_CTRL_ACTIVE);
2557 dbg("TD still active (%x)- grrr. paranoia!", le32_to_cpu(desc->hw.td.status));
2559 urb->iso_frame_desc[i].status = ret;
2560 unlink_td (s, desc, 1);
2561 // FIXME: immediate deletion may be dangerous
2565 if (mode == PROCESS_ISO_REGULAR)
2566 unlink_td (s, desc, 1);
2568 if (urb->number_of_packets <= i) {
2569 dbg("urb->number_of_packets (%d)<=(%d)", urb->number_of_packets, i);
2574 urb->iso_frame_desc[i].actual_length = uhci_actual_length(le32_to_cpu(desc->hw.td.status));
2575 urb->iso_frame_desc[i].status = uhci_map_status (uhci_status_bits (le32_to_cpu(desc->hw.td.status)), usb_pipeout (urb->pipe));
2576 urb->actual_length += urb->iso_frame_desc[i].actual_length;
2580 if (urb->iso_frame_desc[i].status != 0) {
2582 urb->status = urb->iso_frame_desc[i].status;
2584 dbg("process_iso: %i: len:%d %08x status:%x",
2585 i, urb->iso_frame_desc[i].actual_length, le32_to_cpu(desc->hw.td.status),urb->iso_frame_desc[i].status);
2590 delete_desc (s, desc);
2593 dbg("process_iso: exit %i (%d), actual_len %i", i, ret,urb->actual_length);
2598 _static int process_urb (uhci_t *s, struct list_head *p)
2603 urb=list_entry (p, struct urb, urb_list);
2604 //dbg("process_urb: found queued urb: %p", urb);
2606 switch (usb_pipetype (urb->pipe)) {
2608 ret = process_transfer (s, urb, CLEAN_TRANSFER_REGULAR);
2611 if (!s->avoid_bulk.counter)
2612 ret = process_transfer (s, urb, CLEAN_TRANSFER_REGULAR);
2616 case PIPE_ISOCHRONOUS:
2617 ret = process_iso (s, urb, PROCESS_ISO_REGULAR);
2619 case PIPE_INTERRUPT:
2620 ret = process_interrupt (s, urb);
2624 if (urb->status != -EINPROGRESS) {
2625 urb_priv_t *urb_priv;
2626 struct usb_device *usb_dev;
2630 /* Release bandwidth for Interrupt or Iso transfers */
2631 if (urb->bandwidth) {
2632 if (usb_pipetype(urb->pipe)==PIPE_ISOCHRONOUS)
2633 usb_release_bandwidth (urb->dev, urb, 1);
2634 else if (usb_pipetype(urb->pipe)==PIPE_INTERRUPT && urb->interval)
2635 usb_release_bandwidth (urb->dev, urb, 0);
2638 dbg("dequeued urb: %p", urb);
2639 dequeue_urb (s, urb);
2641 urb_priv = urb->hcpriv;
2643 uhci_urb_dma_unmap(s, urb, urb_priv);
2646 kmem_cache_free(urb_priv_kmem, urb_priv);
2651 if ((usb_pipetype (urb->pipe) != PIPE_INTERRUPT)) { // process_interrupt does completion on its own
2652 struct urb *next_urb = urb->next;
2654 int contains_killed = 0;
2658 // Find out if the URBs are linked to a ring
2659 while (next_urb != NULL && next_urb != urb && loop_count < MAX_NEXT_COUNT) {
2660 if (next_urb->status == -ENOENT) {// killed URBs break ring structure & resubmission
2661 contains_killed = 1;
2664 next_urb = next_urb->next;
2668 if (loop_count == MAX_NEXT_COUNT)
2669 err("process_urb: Too much linked URBs in ring detection!");
2671 if (next_urb == urb)
2675 // Submit idle/non-killed URBs linked with urb->next
2676 // Stop before the current URB
2678 next_urb = urb->next;
2679 if (next_urb && !contains_killed) {
2681 next_urb = urb->next;
2684 while (next_urb != NULL && next_urb != urb && loop_count < MAX_NEXT_COUNT) {
2685 if (next_urb->status != -EINPROGRESS) {
2687 if (next_urb->status == -ENOENT)
2690 spin_unlock(&s->urb_list_lock);
2692 ret_submit=uhci_submit_urb(next_urb);
2693 spin_lock(&s->urb_list_lock);
2699 next_urb = next_urb->next;
2701 if (loop_count == MAX_NEXT_COUNT)
2702 err("process_urb: Too much linked URBs in resubmission!");
2706 if (urb->complete) {
2707 int was_unlinked = (urb->status == -ENOENT);
2709 spin_unlock(&s->urb_list_lock);
2711 urb->complete ((struct urb *) urb);
2713 // Re-submit the URB if ring-linked
2714 if (is_ring && !was_unlinked && !contains_killed) {
2716 uhci_submit_urb (urb);
2718 spin_lock(&s->urb_list_lock);
2721 usb_dec_dev_use (usb_dev);
2728 _static void uhci_interrupt (int irq, void *__uhci, struct pt_regs *regs)
2731 unsigned int io_addr = s->io_addr;
2732 unsigned short status;
2733 struct list_head *p, *p2;
2734 int restarts, work_done;
2737 * Read the interrupt status, and write it back to clear the
2741 status = inw (io_addr + USBSTS);
2743 if (!status) /* shared interrupt, not mine */
2749 // Avoid too much error messages at a time
2750 if (time_after(jiffies, s->last_error_time + ERROR_SUPPRESSION_TIME)) {
2751 warn("interrupt, status %x, frame# %i", status,
2752 UHCI_GET_CURRENT_FRAME(s));
2753 s->last_error_time = jiffies;
2756 // remove host controller halted state
2757 if ((status&0x20) && (s->running)) {
2758 err("Host controller halted, trying to restart.");
2759 outw (USBCMD_RS | inw(io_addr + USBCMD), io_addr + USBCMD);
2761 //uhci_show_status (s);
2764 * traverse the list in *reverse* direction, because new entries
2765 * may be added at the end.
2766 * also, because process_urb may unlink the current urb,
2767 * we need to advance the list before
2768 * New: check for max. workload and restart count
2771 spin_lock (&s->urb_list_lock);
2777 s->unlink_urb_done=0;
2778 p = s->urb_list.prev;
2780 while (p != &s->urb_list && (work_done < 1024)) {
2784 process_urb (s, p2);
2788 if (s->unlink_urb_done) {
2789 s->unlink_urb_done=0;
2792 if (restarts<16) // avoid endless restarts
2798 if (time_after(jiffies, s->timeout_check + (HZ/30)))
2799 uhci_check_timeouts(s);
2801 clean_descs(s, CLEAN_NOT_FORCED);
2802 uhci_cleanup_unlink(s, CLEAN_NOT_FORCED);
2803 uhci_switch_timer_int(s);
2805 spin_unlock (&s->urb_list_lock);
2807 outw (status, io_addr + USBSTS);
2809 //dbg("uhci_interrupt: done");
2812 _static void reset_hc (uhci_t *s)
2814 unsigned int io_addr = s->io_addr;
2817 /* Global reset for 50ms */
2818 outw (USBCMD_GRESET, io_addr + USBCMD);
2820 outw (0, io_addr + USBCMD);
2824 _static void start_hc (uhci_t *s)
2826 unsigned int io_addr = s->io_addr;
2830 * Reset the HC - this will force us to get a
2831 * new notification of any already connected
2832 * ports due to the virtual disconnect that it
2835 outw (USBCMD_HCRESET, io_addr + USBCMD);
2837 while (inw (io_addr + USBCMD) & USBCMD_HCRESET) {
2839 err("USBCMD_HCRESET timed out!");
2845 /* Turn on all interrupts */
2846 outw (USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, io_addr + USBINTR);
2848 /* Start at frame 0 */
2849 outw (0, io_addr + USBFRNUM);
2850 outl (s->framelist_dma, io_addr + USBFLBASEADD);
2852 /* Run and mark it configured with a 64-byte max packet */
2853 outw (USBCMD_RS | USBCMD_CF | USBCMD_MAXP, io_addr + USBCMD);
2858 /* No __devexit, since it maybe called from alloc_uhci() */
2860 uhci_pci_remove (struct pci_dev *dev)
2862 uhci_t *s = pci_get_drvdata(dev);
2863 struct usb_device *root_hub = s->bus->root_hub;
2865 s->running = 0; // Don't allow submit_urb
2868 usb_disconnect (&root_hub);
2873 uhci_unlink_urbs (s, 0, CLEAN_FORCED); // Forced unlink of remaining URBs
2874 uhci_cleanup_unlink (s, CLEAN_FORCED); // force cleanup of async killed URBs
2876 usb_deregister_bus (s->bus);
2878 release_region (s->io_addr, s->io_size);
2879 free_irq (s->irq, s);
2880 usb_free_bus (s->bus);
2885 _static int __init uhci_start_usb (uhci_t *s)
2887 /* connect the virtual root hub */
2888 struct usb_device *usb_dev;
2890 usb_dev = usb_alloc_dev (NULL, s->bus);
2894 s->bus->root_hub = usb_dev;
2895 usb_connect (usb_dev);
2897 if (usb_new_device (usb_dev) != 0) {
2898 usb_free_dev (usb_dev);
2907 uhci_pci_suspend (struct pci_dev *dev, u32 state)
2909 reset_hc((uhci_t *) pci_get_drvdata(dev));
2914 uhci_pci_resume (struct pci_dev *dev)
2916 start_hc((uhci_t *) pci_get_drvdata(dev));
2921 _static int __devinit alloc_uhci (struct pci_dev *dev, int irq, unsigned int io_addr, unsigned int io_size)
2924 struct usb_bus *bus;
2925 char buf[8], *bufp = buf;
2928 sprintf(buf, "%d", irq);
2930 bufp = __irq_itoa(irq);
2932 printk(KERN_INFO __FILE__ ": USB UHCI at I/O 0x%x, IRQ %s\n",
2935 s = kmalloc (sizeof (uhci_t), GFP_KERNEL);
2939 memset (s, 0, sizeof (uhci_t));
2940 INIT_LIST_HEAD (&s->free_desc);
2941 INIT_LIST_HEAD (&s->urb_list);
2942 INIT_LIST_HEAD (&s->urb_unlinked);
2943 spin_lock_init (&s->urb_list_lock);
2944 spin_lock_init (&s->qh_lock);
2945 spin_lock_init (&s->td_lock);
2946 atomic_set(&s->avoid_bulk, 0);
2948 s->io_addr = io_addr;
2949 s->io_size = io_size;
2952 bus = usb_alloc_bus (&uhci_device_operations);
2959 bus->bus_name = dev->slot_name;
2962 /* UHCI specs says devices must have 2 ports, but goes on to say */
2963 /* they may have more but give no way to determine how many they */
2964 /* have, so default to 2 */
2965 /* According to the UHCI spec, Bit 7 is always set to 1. So we try */
2966 /* to use this to our advantage */
2968 for (s->maxports = 0; s->maxports < (io_size - 0x10) / 2; s->maxports++) {
2969 unsigned int portstatus;
2971 portstatus = inw (io_addr + 0x10 + (s->maxports * 2));
2972 dbg("port %i, adr %x status %x", s->maxports,
2973 io_addr + 0x10 + (s->maxports * 2), portstatus);
2974 if (!(portstatus & 0x0080))
2977 warn("Detected %d ports", s->maxports);
2979 /* This is experimental so anything less than 2 or greater than 8 is */
2980 /* something weird and we'll ignore it */
2981 if (s->maxports < 2 || s->maxports > 8) {
2982 dbg("Port count misdetected, forcing to 2 ports");
2986 s->rh.numports = s->maxports;
2988 if (init_skel (s)) {
2994 request_region (s->io_addr, io_size, MODNAME);
2996 usb_register_bus (s->bus);
3000 if (request_irq (irq, uhci_interrupt, SA_SHIRQ, MODNAME, s)) {
3001 err("request_irq %d failed!",irq);
3004 release_region (s->io_addr, s->io_size);
3011 pci_write_config_word (dev, USBLEGSUP, USBLEGSUP_DEFAULT);
3015 if(uhci_start_usb (s) < 0) {
3016 uhci_pci_remove(dev);
3020 //chain new uhci device into global list
3021 pci_set_drvdata(dev, s);
3027 _static int __devinit
3028 uhci_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
3032 if (pci_enable_device(dev) < 0)
3036 err("found UHCI device with no IRQ assigned. check BIOS settings!");
3040 pci_set_master(dev);
3042 /* Search for the IO base address.. */
3043 for (i = 0; i < 6; i++) {
3045 unsigned int io_addr = pci_resource_start(dev, i);
3046 unsigned int io_size = pci_resource_len(dev, i);
3047 if (!(pci_resource_flags(dev,i) & IORESOURCE_IO))
3050 /* Is it already in use? */
3051 if (check_region (io_addr, io_size))
3053 /* disable legacy emulation */
3054 pci_write_config_word (dev, USBLEGSUP, 0);
3056 return alloc_uhci(dev, dev->irq, io_addr, io_size);
3061 /*-------------------------------------------------------------------------*/
3063 static const struct pci_device_id __devinitdata uhci_pci_ids [] = { {
3065 /* handle any USB UHCI controller */
3066 class: ((PCI_CLASS_SERIAL_USB << 8) | 0x00),
3069 /* no matter who makes it */
3072 subvendor: PCI_ANY_ID,
3073 subdevice: PCI_ANY_ID,
3075 }, { /* end: all zeroes */ }
3078 MODULE_DEVICE_TABLE (pci, uhci_pci_ids);
3080 static struct pci_driver uhci_pci_driver = {
3082 id_table: &uhci_pci_ids [0],
3084 probe: uhci_pci_probe,
3085 remove: uhci_pci_remove,
3088 suspend: uhci_pci_suspend,
3089 resume: uhci_pci_resume,
3094 /*-------------------------------------------------------------------------*/
3096 static int __init uhci_hcd_init (void)
3101 urb_priv_kmem = kmem_cache_create("urb_priv", sizeof(urb_priv_t), 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
3103 if(!urb_priv_kmem) {
3104 err("kmem_cache_create for urb_priv_t failed (out of memory)");
3110 #ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
3111 info("High bandwidth mode enabled");
3114 retval = pci_module_init (&uhci_pci_driver);
3118 if (kmem_cache_destroy(urb_priv_kmem))
3119 err("urb_priv_kmem remained");
3123 info(DRIVER_VERSION ":" DRIVER_DESC);
3128 static void __exit uhci_hcd_cleanup (void)
3130 pci_unregister_driver (&uhci_pci_driver);
3133 if(kmem_cache_destroy(urb_priv_kmem))
3134 err("urb_priv_kmem remained");
3138 module_init (uhci_hcd_init);
3139 module_exit (uhci_hcd_cleanup);
3142 MODULE_AUTHOR( DRIVER_AUTHOR );
3143 MODULE_DESCRIPTION( DRIVER_DESC );
3144 MODULE_LICENSE("GPL");