1 diff -Nru a/drivers/usb/hcd/ehci-dbg.c b/drivers/usb/hcd/ehci-dbg.c
2 --- a/drivers/usb/hcd/ehci-dbg.c Mon Oct 21 22:14:31 2002
3 +++ b/drivers/usb/hcd/ehci-dbg.c Mon Oct 21 22:14:31 2002
6 - * Copyright (c) 2001 by David Brownell
7 + * Copyright (c) 2001-2002 by David Brownell
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
15 -/* check the values in the HCSPARAMS register - host controller structural parameters */
16 -/* see EHCI 0.95 Spec, Table 2-4 for each value */
17 +/* check the values in the HCSPARAMS register
18 + * (host controller _Structural_ parameters)
19 + * see EHCI spec, Table 2-4 for each value
21 static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
23 u32 params = readl (&ehci->caps->hcs_params);
27 dbg ("%s: %s portroute %s",
28 - ehci->hcd.bus_name, label,
29 + hcd_to_bus (&ehci->hcd)->bus_name, label,
37 -/* check the values in the HCCPARAMS register - host controller capability parameters */
38 -/* see EHCI 0.95 Spec, Table 2-5 for each value */
39 +/* check the values in the HCCPARAMS register
40 + * (host controller _Capability_ parameters)
41 + * see EHCI Spec, Table 2-5 for each value
43 static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
45 u32 params = readl (&ehci->caps->hcc_params);
47 if (HCC_EXT_CAPS (params)) {
48 // EHCI 0.96 ... could interpret these (legacy?)
49 - dbg ("%s extended capabilities at pci %d",
50 + dbg ("%s extended capabilities at pci %2x",
51 label, HCC_EXT_CAPS (params));
53 if (HCC_ISOC_CACHE (params)) {
54 - dbg ("%s hcc_params 0x%04x caching frame %s%s%s",
55 + dbg ("%s hcc_params %04x caching frame %s%s%s",
57 HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
58 HCC_CANPARK (params) ? " park" : "",
59 HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
61 - dbg ("%s hcc_params 0x%04x caching %d uframes %s%s%s",
62 + dbg ("%s hcc_params %04x caching %d uframes %s%s%s",
65 HCC_ISOC_THRES (params),
71 -static void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
72 +static void __attribute__((__unused__))
73 +dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
75 dbg ("%s %p info1 %x info2 %x hw_curr %x qtd_next %x", label,
76 qh, qh->hw_info1, qh->hw_info2,
77 @@ -117,63 +121,462 @@
83 +static int __attribute__((__unused__))
84 +dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
86 + return snprintf (buf, len,
87 + "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
88 + label, label [0] ? " " : "", status,
89 + (status & STS_ASS) ? " Async" : "",
90 + (status & STS_PSS) ? " Periodic" : "",
91 + (status & STS_RECL) ? " Recl" : "",
92 + (status & STS_HALT) ? " Halt" : "",
93 + (status & STS_IAA) ? " IAA" : "",
94 + (status & STS_FATAL) ? " FATAL" : "",
95 + (status & STS_FLR) ? " FLR" : "",
96 + (status & STS_PCD) ? " PCD" : "",
97 + (status & STS_ERR) ? " ERR" : "",
98 + (status & STS_INT) ? " INT" : ""
102 +static int __attribute__((__unused__))
103 +dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
105 + return snprintf (buf, len,
106 + "%s%sintrenable %02x%s%s%s%s%s%s",
107 + label, label [0] ? " " : "", enable,
108 + (enable & STS_IAA) ? " IAA" : "",
109 + (enable & STS_FATAL) ? " FATAL" : "",
110 + (enable & STS_FLR) ? " FLR" : "",
111 + (enable & STS_PCD) ? " PCD" : "",
112 + (enable & STS_ERR) ? " ERR" : "",
113 + (enable & STS_INT) ? " INT" : ""
117 static const char *const fls_strings [] =
118 { "1024", "512", "256", "??" };
120 +static int dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
122 + return snprintf (buf, len,
123 + "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
124 + label, label [0] ? " " : "", command,
125 + (command & CMD_PARK) ? "park" : "(park)",
126 + CMD_PARK_CNT (command),
127 + (command >> 16) & 0x3f,
128 + (command & CMD_LRESET) ? " LReset" : "",
129 + (command & CMD_IAAD) ? " IAAD" : "",
130 + (command & CMD_ASE) ? " Async" : "",
131 + (command & CMD_PSE) ? " Periodic" : "",
132 + fls_strings [(command >> 2) & 0x3],
133 + (command & CMD_RESET) ? " Reset" : "",
134 + (command & CMD_RUN) ? "RUN" : "HALT"
139 +dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
143 + /* signaling state */
144 + switch (status & (3 << 10)) {
145 + case 0 << 10: sig = "se0"; break;
146 + case 1 << 10: sig = "k"; break; /* low speed */
147 + case 2 << 10: sig = "j"; break;
148 + default: sig = "?"; break;
151 + return snprintf (buf, len,
152 + "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s",
153 + label, label [0] ? " " : "", port, status,
154 + (status & PORT_POWER) ? " POWER" : "",
155 + (status & PORT_OWNER) ? " OWNER" : "",
157 + (status & PORT_RESET) ? " RESET" : "",
158 + (status & PORT_SUSPEND) ? " SUSPEND" : "",
159 + (status & PORT_RESUME) ? " RESUME" : "",
160 + (status & PORT_OCC) ? " OCC" : "",
161 + (status & PORT_OC) ? " OC" : "",
162 + (status & PORT_PEC) ? " PEC" : "",
163 + (status & PORT_PE) ? " PE" : "",
164 + (status & PORT_CSC) ? " CSC" : "",
165 + (status & PORT_CONNECT) ? " CONNECT" : ""
171 -static inline void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) {}
173 +static inline void __attribute__((__unused__))
174 +dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
177 +static inline int __attribute__((__unused__))
178 +dbg_status_buf (char *buf, unsigned len, char *label, u32 status)
181 +static inline int __attribute__((__unused__))
182 +dbg_command_buf (char *buf, unsigned len, char *label, u32 command)
185 +static inline int __attribute__((__unused__))
186 +dbg_intr_buf (char *buf, unsigned len, char *label, u32 enable)
189 +static inline int __attribute__((__unused__))
190 +dbg_port_buf (char *buf, unsigned len, char *label, int port, u32 status)
195 /* functions have the "wrong" filename when they're output... */
196 +#define dbg_status(ehci, label, status) { \
198 + dbg_status_buf (_buf, sizeof _buf, label, status); \
199 + dbg ("%s", _buf); \
202 +#define dbg_cmd(ehci, label, command) { \
204 + dbg_command_buf (_buf, sizeof _buf, label, command); \
205 + dbg ("%s", _buf); \
208 +#define dbg_port(hcd, label, port, status) { \
210 + dbg_port_buf (_buf, sizeof _buf, label, port, status); \
211 + dbg ("%s", _buf); \
214 +/*-------------------------------------------------------------------------*/
216 +#ifdef STUB_DEBUG_FILES
218 +static inline void create_debug_files (struct ehci_hcd *bus) { }
219 +static inline void remove_debug_files (struct ehci_hcd *bus) { }
223 +/* troubleshooting help: expose state in driverfs */
225 +#define speed_char(info1) ({ char tmp; \
226 + switch (info1 & (3 << 12)) { \
227 + case 0 << 12: tmp = 'f'; break; \
228 + case 1 << 12: tmp = 'l'; break; \
229 + case 2 << 12: tmp = 'h'; break; \
230 + default: tmp = '?'; break; \
233 +static void qh_lines (struct ehci_qh *qh, char **nextp, unsigned *sizep)
236 + struct list_head *entry;
237 + struct ehci_qtd *td;
239 + unsigned size = *sizep;
240 + char *next = *nextp;
242 + scratch = cpu_to_le32p (&qh->hw_info1);
243 + temp = snprintf (next, size, "qh/%p dev%d %cs ep%d %08x %08x",
244 + qh, scratch & 0x007f,
245 + speed_char (scratch),
246 + (scratch >> 8) & 0x000f,
247 + scratch, cpu_to_le32p (&qh->hw_info2));
251 + list_for_each (entry, &qh->qtd_list) {
252 + td = list_entry (entry, struct ehci_qtd,
254 + scratch = cpu_to_le32p (&td->hw_token);
255 + temp = snprintf (next, size,
256 + "\n\ttd/%p %s len=%d %08x urb %p",
258 + switch ((scratch>>8)&0x03) {
259 + case 0: tmp = "out"; break;
260 + case 1: tmp = "in"; break;
261 + case 2: tmp = "setup"; break;
262 + default: tmp = "?"; break;
264 + (scratch >> 16) & 0x7fff,
271 + temp = snprintf (next, size, "\n");
272 + *sizep = size - temp;
273 + *nextp = next + temp;
277 +show_async (struct device *dev, char *buf, size_t count, loff_t off)
279 + struct pci_dev *pdev;
280 + struct ehci_hcd *ehci;
281 + unsigned long flags;
282 + unsigned temp, size;
284 + struct ehci_qh *qh;
289 + pdev = container_of (dev, struct pci_dev, dev);
290 + ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
294 + /* dumps a snapshot of the async schedule.
295 + * usually empty except for long-term bulk reads, or head.
296 + * one QH per line, and TDs we know about
298 + spin_lock_irqsave (&ehci->lock, flags);
302 + qh_lines (qh, &next, &size);
303 + } while ((qh = qh->qh_next.qh) != ehci->async);
305 + if (ehci->reclaim) {
306 + temp = snprintf (next, size, "\nreclaim =\n");
310 + qh_lines (ehci->reclaim, &next, &size);
312 + spin_unlock_irqrestore (&ehci->lock, flags);
314 + return count - size;
316 +static DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
318 +#define DBG_SCHED_LIMIT 64
321 +show_periodic (struct device *dev, char *buf, size_t count, loff_t off)
323 + struct pci_dev *pdev;
324 + struct ehci_hcd *ehci;
325 + unsigned long flags;
326 + union ehci_shadow p, *seen;
327 + unsigned temp, size, seen_count;
333 + if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
337 + pdev = container_of (dev, struct pci_dev, dev);
338 + ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
342 + temp = snprintf (next, size, "size = %d\n", ehci->periodic_size);
346 + /* dump a snapshot of the periodic schedule.
347 + * iso changes, interrupt usually doesn't.
349 + spin_lock_irqsave (&ehci->lock, flags);
350 + for (i = 0; i < ehci->periodic_size; i++) {
351 + p = ehci->pshadow [i];
354 + tag = Q_NEXT_TYPE (ehci->periodic [i]);
356 + temp = snprintf (next, size, "%4d: ", i);
363 + temp = snprintf (next, size, " qh%d/%p",
364 + p.qh->period, p.qh);
367 + for (temp = 0; temp < seen_count; temp++) {
368 + if (seen [temp].ptr == p.ptr)
371 + /* show more info the first time around */
372 + if (temp == seen_count) {
373 + u32 scratch = cpu_to_le32p (
376 + temp = snprintf (next, size,
377 + " (%cs dev%d ep%d [%d/%d] %d)",
378 + speed_char (scratch),
380 + (scratch >> 8) & 0x000f,
381 + p.qh->usecs, p.qh->c_usecs,
384 + /* FIXME TD info too */
386 + if (seen_count < DBG_SCHED_LIMIT)
387 + seen [seen_count++].qh = p.qh;
390 + tag = Q_NEXT_TYPE (p.qh->hw_next);
394 + temp = snprintf (next, size,
395 + " fstn-%8x/%p", p.fstn->hw_prev,
397 + tag = Q_NEXT_TYPE (p.fstn->hw_next);
398 + p = p.fstn->fstn_next;
401 + temp = snprintf (next, size,
403 + tag = Q_NEXT_TYPE (p.itd->hw_next);
404 + p = p.itd->itd_next;
407 + temp = snprintf (next, size,
408 + " sitd/%p", p.sitd);
409 + tag = Q_NEXT_TYPE (p.sitd->hw_next);
410 + p = p.sitd->sitd_next;
417 + temp = snprintf (next, size, "\n");
421 + spin_unlock_irqrestore (&ehci->lock, flags);
424 + return count - size;
426 +static DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
428 +#undef DBG_SCHED_LIMIT
431 +show_registers (struct device *dev, char *buf, size_t count, loff_t off)
433 + struct pci_dev *pdev;
434 + struct ehci_hcd *ehci;
435 + unsigned long flags;
436 + unsigned temp, size, i;
437 + char *next, scratch [80];
438 + static char fmt [] = "%*s\n";
439 + static char label [] = "";
444 + pdev = container_of (dev, struct pci_dev, dev);
445 + ehci = container_of (pci_get_drvdata (pdev), struct ehci_hcd, hcd);
450 + spin_lock_irqsave (&ehci->lock, flags);
452 + /* Capability Registers */
453 + i = readw (&ehci->caps->hci_version);
454 + temp = snprintf (next, size, "EHCI %x.%02x, hcd state %d\n",
455 + i >> 8, i & 0x0ff, ehci->hcd.state);
459 + // FIXME interpret both types of params
460 + i = readl (&ehci->caps->hcs_params);
461 + temp = snprintf (next, size, "structural params 0x%08x\n", i);
465 + i = readl (&ehci->caps->hcc_params);
466 + temp = snprintf (next, size, "capability params 0x%08x\n", i);
470 + /* Operational Registers */
471 + temp = dbg_status_buf (scratch, sizeof scratch, label,
472 + readl (&ehci->regs->status));
473 + temp = snprintf (next, size, fmt, temp, scratch);
477 + temp = dbg_command_buf (scratch, sizeof scratch, label,
478 + readl (&ehci->regs->command));
479 + temp = snprintf (next, size, fmt, temp, scratch);
483 + temp = dbg_intr_buf (scratch, sizeof scratch, label,
484 + readl (&ehci->regs->intr_enable));
485 + temp = snprintf (next, size, fmt, temp, scratch);
489 + temp = snprintf (next, size, "uframe %04x\n",
490 + readl (&ehci->regs->frame_index));
494 + for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) {
495 + temp = dbg_port_buf (scratch, sizeof scratch, label, i,
496 + readl (&ehci->regs->port_status [i]));
497 + temp = snprintf (next, size, fmt, temp, scratch);
502 + if (ehci->reclaim) {
503 + temp = snprintf (next, size, "reclaim qh %p%s\n",
505 + ehci->reclaim_ready ? " ready" : "");
511 + temp = snprintf (next, size, "irq normal %ld err %ld reclaim %ld\n",
512 + ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim);
516 + temp = snprintf (next, size, "complete %ld unlink %ld qpatch %ld\n",
517 + ehci->stats.complete, ehci->stats.unlink, ehci->stats.qpatch);
522 + spin_unlock_irqrestore (&ehci->lock, flags);
524 + return count - size;
526 +static DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
528 +static inline void create_debug_files (struct ehci_hcd *bus)
530 + device_create_file (&bus->hcd.pdev->dev, &dev_attr_async);
531 + device_create_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
532 + device_create_file (&bus->hcd.pdev->dev, &dev_attr_registers);
535 +static inline void remove_debug_files (struct ehci_hcd *bus)
537 + device_remove_file (&bus->hcd.pdev->dev, &dev_attr_async);
538 + device_remove_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
539 + device_remove_file (&bus->hcd.pdev->dev, &dev_attr_registers);
542 -#define dbg_status(ehci, label, status) \
543 - dbg ("%s status 0x%x%s%s%s%s%s%s%s%s%s%s", \
545 - (status & STS_ASS) ? " Async" : "", \
546 - (status & STS_PSS) ? " Periodic" : "", \
547 - (status & STS_RECL) ? " Recl" : "", \
548 - (status & STS_HALT) ? " Halt" : "", \
549 - (status & STS_IAA) ? " IAA" : "", \
550 - (status & STS_FATAL) ? " FATAL" : "", \
551 - (status & STS_FLR) ? " FLR" : "", \
552 - (status & STS_PCD) ? " PCD" : "", \
553 - (status & STS_ERR) ? " ERR" : "", \
554 - (status & STS_INT) ? " INT" : "" \
557 -#define dbg_cmd(ehci, label, command) \
558 - dbg ("%s %x cmd %s=%d ithresh=%d%s%s%s%s period=%s%s %s", \
560 - (command & CMD_PARK) ? "park" : "(park)", \
561 - CMD_PARK_CNT (command), \
562 - (command >> 16) & 0x3f, \
563 - (command & CMD_LRESET) ? " LReset" : "", \
564 - (command & CMD_IAAD) ? " IAAD" : "", \
565 - (command & CMD_ASE) ? " Async" : "", \
566 - (command & CMD_PSE) ? " Periodic" : "", \
567 - fls_strings [(command >> 2) & 0x3], \
568 - (command & CMD_RESET) ? " Reset" : "", \
569 - (command & CMD_RUN) ? "RUN" : "HALT" \
572 -#define dbg_port(hcd, label, port, status) \
573 - dbg ("%s port %d status 0x%x%s%s speed=%d%s%s%s%s%s%s%s%s%s", \
574 - label, port, status, \
575 - (status & PORT_OWNER) ? " OWNER" : "", \
576 - (status & PORT_POWER) ? " POWER" : "", \
577 - (status >> 10) & 3, \
578 - (status & PORT_RESET) ? " RESET" : "", \
579 - (status & PORT_SUSPEND) ? " SUSPEND" : "", \
580 - (status & PORT_RESUME) ? " RESUME" : "", \
581 - (status & PORT_OCC) ? " OCC" : "", \
582 - (status & PORT_OC) ? " OC" : "", \
583 - (status & PORT_PEC) ? " PEC" : "", \
584 - (status & PORT_PE) ? " PE" : "", \
585 - (status & PORT_CSC) ? " CSC" : "", \
586 - (status & PORT_CONNECT) ? " CONNECT" : "" \
588 +#endif /* STUB_DEBUG_FILES */
590 diff -Nru a/drivers/usb/hcd/ehci-hcd.c b/drivers/usb/hcd/ehci-hcd.c
591 --- a/drivers/usb/hcd/ehci-hcd.c Mon Oct 21 22:14:31 2002
592 +++ b/drivers/usb/hcd/ehci-hcd.c Mon Oct 21 22:14:31 2002
596 #include <linux/usb.h>
598 +#include <linux/version.h>
599 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,32)
602 +#include "../core/hcd.h"
605 #include <asm/byteorder.h>
608 #include <asm/system.h>
609 #include <asm/unaligned.h>
612 -//#define KERN_DEBUG ""
614 /*-------------------------------------------------------------------------*/
617 * EHCI hc_driver implementation ... experimental, incomplete.
618 * Based on the final 1.0 register interface specification.
620 - * There are lots of things to help out with here ... notably
621 - * everything "periodic", and of course testing with all sorts
622 - * of usb 2.0 devices and configurations.
624 * USB 2.0 shows up in upcoming www.pcmcia.org technology.
625 * First was PCMCIA, like ISA; then CardBus, which is PCI.
626 * Next comes "CardBay", using USB 2.0 signals.
628 - * Contains additional contributions by:
632 + * Contains additional contributions by: Brad Hards, Rory Bolt, and more.
633 + * Special thanks to Intel and VIA for providing host controllers to
634 + * test this driver on, and Cypress (including In-System Design) for
635 + * providing early devices for those host controllers to talk to!
639 + * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared;
640 + * only scheduling is different, no arbitrary limitations.
641 + * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support,
642 + * clean up HC run state handshaking.
643 + * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts
644 + * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other
645 + * missing pieces: enabling 64bit dma, handoff from BIOS/SMM.
646 * 2002-05-07 Some error path cleanups to report better errors; wmb();
647 * use non-CVS version id; better iso bandwidth claim.
648 * 2002-04-19 Control/bulk/interrupt submit no longer uses giveback() on
650 * 2001-June Works with usb-storage and NEC EHCI on 2.4
653 -#define DRIVER_VERSION "2002-May-07"
654 +#define DRIVER_VERSION "2002-Sep-23"
655 #define DRIVER_AUTHOR "David Brownell"
656 #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
658 +static const char hcd_name [] = "ehci-hcd";
661 // #define EHCI_VERBOSE_DEBUG
662 // #define have_split_iso
668 +#define INTR_AUTOMAGIC /* to be removed later in 2.5 */
670 /* magic numbers that can affect system performance */
671 #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
672 #define EHCI_TUNE_RL_HS 0 /* nak throttle; see 4.9 */
673 @@ -100,11 +115,20 @@
674 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
675 #define EHCI_TUNE_MULT_TT 1
677 +#define EHCI_WATCHDOG_JIFFIES (HZ/100) /* arbitrary; ~10 msec */
678 +#define EHCI_ASYNC_JIFFIES (HZ/3) /* async idle timeout */
680 /* Initial IRQ latency: lower than default */
681 static int log2_irq_thresh = 0; // 0 to 6
682 MODULE_PARM (log2_irq_thresh, "i");
683 MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
685 +/* allow irqs at least every N URB completions */
686 +static int max_completions = 16;
687 +MODULE_PARM (max_completions, "i");
688 +MODULE_PARM_DESC (max_completions,
689 + "limit for urb completions called with irqs disenabled");
691 #define INTR_MASK (STS_IAA | STS_FATAL | STS_ERR | STS_INT)
693 /*-------------------------------------------------------------------------*/
694 @@ -115,42 +139,105 @@
695 /*-------------------------------------------------------------------------*/
698 + * handshake - spin reading hc until handshake completes or fails
699 + * @ptr: address of hc register to be read
700 + * @mask: bits to look at in result of read
701 + * @done: value of those bits when handshake succeeds
702 + * @usec: timeout in microseconds
704 + * Returns negative errno, or zero on success
706 + * Success happens when the "mask" bits have the specified value (hardware
707 + * handshake done). There are two failure modes: "usec" have passed (major
708 + * hardware flakeout), or the register reads as all-ones (hardware removed).
710 + * That last failure should_only happen in cases like physical cardbus eject
711 + * before driver shutdown. But it also seems to be caused by bugs in cardbus
712 + * bridge shutdown: shutting down the bridge before the devices using it.
714 +static int handshake (u32 *ptr, u32 mask, u32 done, int usec)
719 + result = readl (ptr);
720 + if (result == ~(u32)0) /* card removed */
723 + if (result == done)
727 + } while (usec > 0);
732 * hc states include: unknown, halted, ready, running
733 * transitional states are messy just now
734 * trying to avoid "running" unless urbs are active
735 * a "ready" hc can be finishing prefetched work
738 -/* halt a non-running controller */
739 -static void ehci_reset (struct ehci_hcd *ehci)
740 +/* force HC to halt state from unknown (EHCI spec section 2.3) */
741 +static int ehci_halt (struct ehci_hcd *ehci)
743 + u32 temp = readl (&ehci->regs->status);
745 + if ((temp & STS_HALT) != 0)
748 + temp = readl (&ehci->regs->command);
750 + writel (temp, &ehci->regs->command);
751 + return handshake (&ehci->regs->status, STS_HALT, STS_HALT, 16 * 125);
754 +/* reset a non-running (STS_HALT == 1) controller */
755 +static int ehci_reset (struct ehci_hcd *ehci)
757 u32 command = readl (&ehci->regs->command);
759 command |= CMD_RESET;
760 dbg_cmd (ehci, "reset", command);
761 writel (command, &ehci->regs->command);
762 - while (readl (&ehci->regs->command) & CMD_RESET)
764 ehci->hcd.state = USB_STATE_HALT;
765 + return handshake (&ehci->regs->command, CMD_RESET, 0, 250);
768 /* idle the controller (from running) */
769 static void ehci_ready (struct ehci_hcd *ehci)
775 if (!HCD_IS_RUNNING (ehci->hcd.state))
779 - while (!(readl (&ehci->regs->status) & (STS_ASS | STS_PSS)))
781 - command = readl (&ehci->regs->command);
782 - command &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
783 - writel (command, &ehci->regs->command);
784 + /* wait for any schedule enables/disables to take effect */
788 + if (ehci->next_uframe != -1)
790 + if (handshake (&ehci->regs->status, STS_ASS | STS_PSS,
791 + temp, 16 * 125) != 0) {
792 + ehci->hcd.state = USB_STATE_HALT;
796 + /* then disable anything that's still active */
797 + temp = readl (&ehci->regs->command);
798 + temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
799 + writel (temp, &ehci->regs->command);
801 - // hardware can take 16 microframes to turn off ...
802 + /* hardware can take 16 microframes to turn off ... */
803 + if (handshake (&ehci->regs->status, STS_ASS | STS_PSS,
804 + 0, 16 * 125) != 0) {
805 + ehci->hcd.state = USB_STATE_HALT;
808 ehci->hcd.state = USB_STATE_READY;
813 static void ehci_tasklet (unsigned long param);
815 +static void ehci_irq (struct usb_hcd *hcd);
817 +static void ehci_watchdog (unsigned long param)
819 + struct ehci_hcd *ehci = (struct ehci_hcd *) param;
820 + unsigned long flags;
822 + spin_lock_irqsave (&ehci->lock, flags);
823 + /* guard against lost IAA, which wedges everything */
824 + ehci_irq (&ehci->hcd);
825 + /* unlink the last qh after it's idled a while */
826 + if (ehci->async_idle) {
827 + start_unlink_async (ehci, ehci->async);
828 + ehci->async_idle = 0;
830 + spin_unlock_irqrestore (&ehci->lock, flags);
833 +/* EHCI 0.96 (and later) section 5.1 says how to kick BIOS/SMM/...
834 + * off the controller (maybe it can boot from highspeed USB disks).
836 +static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
838 + if (cap & (1 << 16)) {
841 + /* request handoff to OS */
843 + pci_write_config_dword (ehci->hcd.pdev, where, cap);
845 + /* and wait a while for it to happen */
849 + pci_read_config_dword (ehci->hcd.pdev, where, &cap);
850 + } while ((cap & (1 << 16)) && msec);
851 + if (cap & (1 << 16)) {
852 + info ("BIOS handoff failed (%d, %04x)", where, cap);
855 + dbg ("BIOS handoff succeeded");
857 + dbg ("BIOS handoff not needed");
861 /* called by khubd or root hub init threads */
863 static int ehci_start (struct usb_hcd *hcd)
864 @@ -172,14 +305,11 @@
865 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
867 struct usb_device *udev;
868 + struct usb_bus *bus;
873 - // FIXME: given EHCI 0.96 or later, and a controller with
874 - // the USBLEGSUP/USBLEGCTLSTS extended capability, make sure
875 - // the BIOS doesn't still own this controller.
877 spin_lock_init (&ehci->lock);
879 ehci->caps = (struct ehci_caps *) hcd->regs;
881 dbg_hcs_params (ehci, "ehci_start");
882 dbg_hcc_params (ehci, "ehci_start");
884 + hcc_params = readl (&ehci->caps->hcc_params);
886 + /* EHCI 0.96 and later may have "extended capabilities" */
887 + temp = HCC_EXT_CAPS (hcc_params);
891 + pci_read_config_dword (ehci->hcd.pdev, temp, &cap);
892 + dbg ("capability %04x at %02x", cap, temp);
893 + switch (cap & 0xff) {
894 + case 1: /* BIOS/SMM/... handoff */
895 + if (bios_handoff (ehci, temp, cap) != 0)
896 + return -EOPNOTSUPP;
898 + case 0: /* illegal reserved capability */
899 + warn ("illegal capability!");
902 + default: /* unknown */
905 + temp = (cap >> 8) & 0xff;
908 /* cache this readonly data; minimize PCI reads */
909 ehci->hcs_params = readl (&ehci->caps->hcs_params);
911 + /* force HC to halt state */
912 + if ((retval = ehci_halt (ehci)) != 0)
916 * hw default: 1K periodic list heads, one per frame.
917 * periodic_size can shrink by USBCMD update if hcc_params allows.
919 ehci->periodic_size = DEFAULT_I_TDPS;
920 if ((retval = ehci_mem_init (ehci, SLAB_KERNEL)) < 0)
922 - hcc_params = readl (&ehci->caps->hcc_params);
924 /* controllers may cache some of the periodic schedule ... */
925 if (HCC_ISOC_CACHE (hcc_params)) // full frame cache
927 /* controller state: unknown --> reset */
929 /* EHCI spec section 4.1 */
930 - // FIXME require STS_HALT before reset...
932 + if ((retval = ehci_reset (ehci)) != 0) {
933 + ehci_mem_cleanup (ehci);
936 writel (INTR_MASK, &ehci->regs->intr_enable);
937 writel (ehci->periodic_dma, &ehci->regs->frame_list);
939 @@ -221,23 +380,25 @@
940 * hcc_params controls whether ehci->regs->segment must (!!!)
941 * be used; it constrains QH/ITD/SITD and QTD locations.
942 * pci_pool consistent memory always uses segment zero.
943 + * streaming mappings for I/O buffers, like pci_map_single(),
944 + * can return segments above 4GB, if the device allows.
946 + * NOTE: layered drivers can't yet tell when we enable that,
947 + * so they can't pass this info along (like NETIF_F_HIGHDMA)
948 + * (or like Scsi_Host.highmem_io) ... usb_bus.flags?
950 if (HCC_64BIT_ADDR (hcc_params)) {
951 writel (0, &ehci->regs->segment);
953 - * FIXME Enlarge pci_set_dma_mask() when possible. The DMA
954 - * mapping API spec now says that'll affect only single shot
955 - * mappings, and the pci_pool data will stay safe in seg 0.
956 - * That's what we want: no extra copies for USB transfers.
958 - info ("restricting 64bit DMA mappings to segment 0 ...");
959 + if (!pci_set_dma_mask (ehci->hcd.pdev, 0xffffffffffffffffULL))
960 + info ("enabled 64bit PCI DMA (DAC)");
963 /* clear interrupt enables, set irq latency */
964 temp = readl (&ehci->regs->command) & 0xff;
965 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
966 - log2_irq_thresh = 0;
967 + log2_irq_thresh = 0;
968 temp |= 1 << (16 + log2_irq_thresh);
969 + // if hc can park (ehci >= 0.96), default is 3 packets per async QH
970 // keeping default periodic framelist size
971 temp &= ~(CMD_IAAD | CMD_ASE | CMD_PSE),
972 // Philips, Intel, and maybe others need CMD_RUN before the
974 ehci->tasklet.func = ehci_tasklet;
975 ehci->tasklet.data = (unsigned long) ehci;
977 + init_timer (&ehci->watchdog);
978 + ehci->watchdog.function = ehci_watchdog;
979 + ehci->watchdog.data = (unsigned long) ehci;
981 /* wire up the root hub */
982 - hcd->bus->root_hub = udev = usb_alloc_dev (NULL, hcd->bus);
983 + bus = hcd_to_bus (hcd);
984 + bus->root_hub = udev = usb_alloc_dev (NULL, bus);
987 ehci_mem_cleanup (ehci);
988 @@ -271,11 +437,10 @@
989 /* PCI Serial Bus Release Number is at 0x60 offset */
990 pci_read_config_byte (hcd->pdev, 0x60, &tempbyte);
991 temp = readw (&ehci->caps->hci_version);
992 - info ("USB %x.%x support enabled, EHCI rev %x.%2x",
993 - ((tempbyte & 0xf0)>>4),
997 + info ("USB %x.%x support enabled, EHCI rev %x.%02x, %s %s",
998 + ((tempbyte & 0xf0)>>4), (tempbyte & 0x0f),
999 + temp >> 8, temp & 0xff,
1000 + hcd_name, DRIVER_VERSION);
1003 * From here on, khubd concurrently accesses the root
1004 @@ -286,19 +451,18 @@
1007 udev->speed = USB_SPEED_HIGH;
1008 - if (usb_new_device (udev) != 0) {
1009 + if (hcd_register_root (hcd) != 0) {
1010 if (hcd->state == USB_STATE_RUNNING)
1012 - while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))
1015 - // usb_disconnect (udev);
1016 - hcd->bus->root_hub = 0;
1017 + bus->root_hub = 0;
1018 usb_free_dev (udev);
1023 + create_debug_files (ehci);
1028 @@ -308,20 +472,34 @@
1030 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1032 - dbg ("%s: stop", hcd->bus_name);
1033 + dbg ("%s: stop", hcd_to_bus (hcd)->bus_name);
1035 + /* no more interrupts ... */
1036 if (hcd->state == USB_STATE_RUNNING)
1038 - while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))
1040 + if (in_interrupt ()) /* should not happen!! */
1041 + err ("stopped %s!", RUN_CONTEXT);
1043 + del_timer_sync (&ehci->watchdog);
1046 - // root hub is shut down separately (first, when possible)
1047 - scan_async (ehci);
1048 - if (ehci->next_uframe != -1)
1049 - scan_periodic (ehci);
1050 + /* let companion controllers work when we aren't */
1051 + writel (0, &ehci->regs->configured_flag);
1053 + remove_debug_files (ehci);
1055 + /* root hub is shut down separately (first, when possible) */
1056 + tasklet_disable (&ehci->tasklet);
1057 + ehci_tasklet ((unsigned long) ehci);
1058 ehci_mem_cleanup (ehci);
1061 + dbg ("irq normal %ld err %ld reclaim %ld",
1062 + ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim);
1063 + dbg ("complete %ld unlink %ld qpatch %ld",
1064 + ehci->stats.complete, ehci->stats.unlink, ehci->stats.qpatch);
1067 dbg_status (ehci, "ehci_stop completed", readl (&ehci->regs->status));
1074 - dbg ("%s: suspend to %d", hcd->bus_name, state);
1075 + dbg ("%s: suspend to %d", hcd_to_bus (hcd)->bus_name, state);
1077 ports = HCS_N_PORTS (ehci->hcs_params);
1079 @@ -360,15 +538,13 @@
1080 if ((temp & PORT_PE) == 0
1081 || (temp & PORT_OWNER) != 0)
1083 -dbg ("%s: suspend port %d", hcd->bus_name, i);
1084 +dbg ("%s: suspend port %d", hcd_to_bus (hcd)->bus_name, i);
1085 temp |= PORT_SUSPEND;
1086 writel (temp, &ehci->regs->port_status [i]);
1089 if (hcd->state == USB_STATE_RUNNING)
1091 - while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))
1093 writel (readl (&ehci->regs->command) & ~CMD_RUN, &ehci->regs->command);
1095 // save pci FLADJ value
1100 - dbg ("%s: resume", hcd->bus_name);
1101 + dbg ("%s: resume", hcd_to_bus (hcd)->bus_name);
1103 ports = HCS_N_PORTS (ehci->hcs_params);
1106 if ((temp & PORT_PE) == 0
1107 || (temp & PORT_SUSPEND) != 0)
1109 -dbg ("%s: resume port %d", hcd->bus_name, i);
1110 +dbg ("%s: resume port %d", hcd_to_bus (hcd)->bus_name, i);
1111 temp |= PORT_RESUME;
1112 writel (temp, &ehci->regs->port_status [i]);
1113 readl (&ehci->regs->command); /* unblock posted writes */
1114 @@ -429,11 +605,15 @@
1116 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
1118 + spin_lock_irq (&ehci->lock);
1120 if (ehci->reclaim_ready)
1121 end_unlink_async (ehci);
1123 if (ehci->next_uframe != -1)
1124 scan_periodic (ehci);
1126 + spin_unlock_irq (&ehci->lock);
1128 // FIXME: when nothing is connected to the root hub,
1129 // turn off the RUN bit so the host can C3 "sleep" power
1130 @@ -444,6 +624,12 @@
1131 u32 status = readl (&ehci->regs->status);
1134 + /* e.g. cardbus physical eject */
1135 + if (status == ~(u32) 0) {
1136 + dbg ("%s: device removed!", hcd_to_bus (hcd)->bus_name);
1140 status &= INTR_MASK;
1141 if (!status) /* irq sharing? */
1143 @@ -461,21 +647,30 @@
1144 /* INT, ERR, and IAA interrupt rates can be throttled */
1146 /* normal [4.15.1.2] or error [4.15.1.1] completion */
1147 - if (likely ((status & (STS_INT|STS_ERR)) != 0))
1148 + if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
1149 + if (likely ((status & STS_ERR) == 0))
1150 + COUNT (ehci->stats.normal);
1152 + COUNT (ehci->stats.error);
1156 /* complete the unlinking of some qh [4.15.2.3] */
1157 if (status & STS_IAA) {
1158 + COUNT (ehci->stats.reclaim);
1159 ehci->reclaim_ready = 1;
1163 /* PCI errors [4.15.2.4] */
1164 if (unlikely ((status & STS_FATAL) != 0)) {
1165 - err ("%s: fatal error, state %x", hcd->bus_name, hcd->state);
1166 + err ("%s: fatal error, state %x",
1167 + hcd_to_bus (hcd)->bus_name, hcd->state);
1170 - // generic layer kills/unlinks all urbs
1171 - // then tasklet cleans up the rest
1172 + /* generic layer kills/unlinks all urbs, then
1173 + * uses ehci_stop to clean up the rest
1180 * hcd-specific init for hcpriv hasn't been done yet
1182 - * NOTE: EHCI queues control and bulk requests transparently, like OHCI.
1183 + * NOTE: control, bulk, and interrupt share the same code to append TDs
1184 + * to a (possibly active) QH, and the same QH scanning code.
1186 static int ehci_urb_enqueue (
1187 struct usb_hcd *hcd,
1188 @@ -507,10 +703,11 @@
1190 urb->transfer_flags &= ~EHCI_STATE_UNLINK;
1191 INIT_LIST_HEAD (&qtd_list);
1192 - switch (usb_pipetype (urb->pipe)) {
1194 - case PIPE_CONTROL:
1196 + switch (usb_pipetype (urb->pipe)) {
1197 + // case PIPE_CONTROL:
1198 + // case PIPE_BULK:
1200 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
1202 return submit_async (ehci, urb, &qtd_list, mem_flags);
1204 dbg ("no split iso support yet");
1206 #endif /* have_split_iso */
1208 - default: /* can't happen */
1213 @@ -546,15 +740,22 @@
1214 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv;
1215 unsigned long flags;
1217 - dbg ("%s urb_dequeue %p qh state %d",
1218 - hcd->bus_name, urb, qh->qh_state);
1219 + dbg ("%s urb_dequeue %p qh %p state %d",
1220 + hcd_to_bus (hcd)->bus_name, urb, qh, qh->qh_state);
1222 switch (usb_pipetype (urb->pipe)) {
1223 - case PIPE_CONTROL:
1225 + // case PIPE_CONTROL:
1226 + // case PIPE_BULK:
1228 spin_lock_irqsave (&ehci->lock, flags);
1229 if (ehci->reclaim) {
1230 -dbg ("dq: reclaim busy, %s", RUN_CONTEXT);
1231 + dbg ("dq %p: reclaim = %p, %s",
1232 + qh, ehci->reclaim, RUN_CONTEXT);
1233 + if (qh == ehci->reclaim) {
1234 + /* unlinking qh for another queued urb? */
1235 + spin_unlock_irqrestore (&ehci->lock, flags);
1238 if (in_interrupt ()) {
1239 spin_unlock_irqrestore (&ehci->lock, flags);
1241 @@ -564,25 +765,43 @@
1242 && ehci->hcd.state != USB_STATE_HALT
1244 spin_unlock_irqrestore (&ehci->lock, flags);
1245 -// yeech ... this could spin for up to two frames!
1246 -dbg ("wait for dequeue: state %d, reclaim %p, hcd state %d",
1247 - qh->qh_state, ehci->reclaim, ehci->hcd.state
1250 + /* let pending unlinks complete */
1252 spin_lock_irqsave (&ehci->lock, flags);
1255 if (qh->qh_state == QH_STATE_LINKED)
1256 start_unlink_async (ehci, qh);
1257 spin_unlock_irqrestore (&ehci->lock, flags);
1261 case PIPE_INTERRUPT:
1262 - intr_deschedule (ehci, urb->start_frame, qh, urb->interval);
1263 - if (ehci->hcd.state == USB_STATE_HALT)
1264 - urb->status = -ESHUTDOWN;
1265 - qh_completions (ehci, qh, 1);
1267 + spin_lock_irqsave (&ehci->lock, flags);
1268 + if (qh->qh_state == QH_STATE_LINKED) {
1269 + /* messy, can spin or block a microframe ... */
1270 + intr_deschedule (ehci, qh, 1);
1271 + /* qh_state == IDLE */
1273 + qh_completions (ehci, qh);
1275 + /* reschedule QH iff another request is queued */
1276 + if (!list_empty (&qh->qtd_list)
1277 + && HCD_IS_RUNNING (ehci->hcd.state)) {
1280 + status = qh_schedule (ehci, qh);
1281 + spin_unlock_irqrestore (&ehci->lock, flags);
1283 + if (status != 0) {
1284 + // shouldn't happen often, but ...
1285 + // FIXME kill those tds' urbs
1286 + err ("can't reschedule qh %p, err %d",
1291 + spin_unlock_irqrestore (&ehci->lock, flags);
1294 case PIPE_ISOCHRONOUS:
1297 // wait till next completion, do it then.
1298 // completion irqs can wait up to 1024 msec,
1299 urb->transfer_flags |= EHCI_STATE_UNLINK;
1307 /*-------------------------------------------------------------------------*/
1308 @@ -609,42 +825,67 @@
1310 unsigned long flags;
1312 + /* ASSERT: no requests/urbs are still linked (so no TDs) */
1313 /* ASSERT: nobody can be submitting urbs for this any more */
1315 - dbg ("%s: free_config devnum %d", hcd->bus_name, udev->devnum);
1316 + dbg ("%s: free_config devnum %d",
1317 + hcd_to_bus (hcd)->bus_name, udev->devnum);
1319 spin_lock_irqsave (&ehci->lock, flags);
1320 for (i = 0; i < 32; i++) {
1325 /* dev->ep never has ITDs or SITDs */
1326 qh = (struct ehci_qh *) dev->ep [i];
1327 - vdbg ("free_config, ep 0x%02x qh %p", i, qh);
1328 - if (!list_empty (&qh->qtd_list)) {
1329 - dbg ("ep 0x%02x qh %p not empty!", i, qh);
1331 + /* detect/report non-recoverable errors */
1332 + if (in_interrupt ())
1333 + why = "disconnect() didn't";
1334 + else if ((qh->hw_info2 & cpu_to_le32 (0xffff)) != 0
1335 + && qh->qh_state != QH_STATE_IDLE)
1336 + why = "(active periodic)";
1340 + err ("dev %s-%s ep %d-%s error: %s",
1341 + hcd_to_bus (hcd)->bus_name,
1343 + i & 0xf, (i & 0x10) ? "IN" : "OUT",
1349 - /* wait_ms() won't spin here -- we're a thread */
1351 + if (qh->qh_state == QH_STATE_IDLE)
1353 + dbg ("free_config, async ep 0x%02x qh %p", i, qh);
1355 + /* scan_async() empties the ring as it does its work,
1356 + * using IAA, but doesn't (yet?) turn it off. if it
1357 + * doesn't empty this qh, likely it's the last entry.
1359 while (qh->qh_state == QH_STATE_LINKED
1361 && ehci->hcd.state != USB_STATE_HALT
1363 spin_unlock_irqrestore (&ehci->lock, flags);
1364 + /* wait_ms() won't spin, we're a thread;
1365 + * and we know IRQ+tasklet can progress
1368 spin_lock_irqsave (&ehci->lock, flags);
1370 - if (qh->qh_state == QH_STATE_LINKED) {
1371 + if (qh->qh_state == QH_STATE_LINKED)
1372 start_unlink_async (ehci, qh);
1373 - while (qh->qh_state != QH_STATE_IDLE) {
1374 - spin_unlock_irqrestore (&ehci->lock,
1377 - spin_lock_irqsave (&ehci->lock, flags);
1379 + while (qh->qh_state != QH_STATE_IDLE
1380 + && ehci->hcd.state != USB_STATE_HALT) {
1381 + spin_unlock_irqrestore (&ehci->lock, flags);
1383 + spin_lock_irqsave (&ehci->lock, flags);
1389 @@ -654,50 +895,48 @@
1391 /*-------------------------------------------------------------------------*/
1393 -static const char hcd_name [] = "ehci-hcd";
1395 static const struct hc_driver ehci_driver = {
1396 - description: hcd_name,
1397 + .description = hcd_name,
1400 * generic hardware linkage
1403 - flags: HCD_MEMORY | HCD_USB2,
1405 + .flags = HCD_MEMORY | HCD_USB2,
1408 * basic lifecycle operations
1410 - start: ehci_start,
1411 + .start = ehci_start,
1413 - suspend: ehci_suspend,
1414 - resume: ehci_resume,
1415 + .suspend = ehci_suspend,
1416 + .resume = ehci_resume,
1419 + .stop = ehci_stop,
1422 * memory lifecycle (except per-request)
1424 - hcd_alloc: ehci_hcd_alloc,
1425 - hcd_free: ehci_hcd_free,
1426 + .hcd_alloc = ehci_hcd_alloc,
1427 + .hcd_free = ehci_hcd_free,
1430 * managing i/o requests and associated device resources
1432 - urb_enqueue: ehci_urb_enqueue,
1433 - urb_dequeue: ehci_urb_dequeue,
1434 - free_config: ehci_free_config,
1435 + .urb_enqueue = ehci_urb_enqueue,
1436 + .urb_dequeue = ehci_urb_dequeue,
1437 + .free_config = ehci_free_config,
1440 * scheduling support
1442 - get_frame_number: ehci_get_frame,
1443 + .get_frame_number = ehci_get_frame,
1448 - hub_status_data: ehci_hub_status_data,
1449 - hub_control: ehci_hub_control,
1450 + .hub_status_data = ehci_hub_status_data,
1451 + .hub_control = ehci_hub_control,
1454 /*-------------------------------------------------------------------------*/
1455 @@ -709,15 +948,15 @@
1457 /* handle any USB 2.0 EHCI controller */
1459 - class: ((PCI_CLASS_SERIAL_USB << 8) | 0x20),
1461 - driver_data: (unsigned long) &ehci_driver,
1462 + .class = ((PCI_CLASS_SERIAL_USB << 8) | 0x20),
1464 + .driver_data = (unsigned long) &ehci_driver,
1466 /* no matter who makes it */
1467 - vendor: PCI_ANY_ID,
1468 - device: PCI_ANY_ID,
1469 - subvendor: PCI_ANY_ID,
1470 - subdevice: PCI_ANY_ID,
1471 + .vendor = PCI_ANY_ID,
1472 + .device = PCI_ANY_ID,
1473 + .subvendor = PCI_ANY_ID,
1474 + .subdevice = PCI_ANY_ID,
1476 }, { /* end: all zeroes */ }
1478 @@ -725,21 +964,20 @@
1480 /* pci driver glue; this is a "new style" PCI driver module */
1481 static struct pci_driver ehci_pci_driver = {
1482 - name: (char *) hcd_name,
1483 - id_table: pci_ids,
1484 + .name = (char *) hcd_name,
1485 + .id_table = pci_ids,
1487 - probe: usb_hcd_pci_probe,
1488 - remove: usb_hcd_pci_remove,
1489 + .probe = usb_hcd_pci_probe,
1490 + .remove = usb_hcd_pci_remove,
1493 - suspend: usb_hcd_pci_suspend,
1494 - resume: usb_hcd_pci_resume,
1495 + .suspend = usb_hcd_pci_suspend,
1496 + .resume = usb_hcd_pci_resume,
1500 #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
1503 MODULE_DESCRIPTION (DRIVER_INFO);
1504 MODULE_AUTHOR (DRIVER_AUTHOR);
1505 MODULE_LICENSE ("GPL");
1506 diff -Nru a/drivers/usb/hcd/ehci-hub.c b/drivers/usb/hcd/ehci-hub.c
1507 --- a/drivers/usb/hcd/ehci-hub.c Mon Oct 21 22:14:31 2002
1508 +++ b/drivers/usb/hcd/ehci-hub.c Mon Oct 21 22:14:31 2002
1510 /* if reset finished and it's still not enabled -- handoff */
1511 if (!(port_status & PORT_PE)) {
1512 dbg ("%s port %d full speed, give to companion, 0x%x",
1513 - ehci->hcd.bus_name, index + 1, port_status);
1514 + hcd_to_bus (&ehci->hcd)->bus_name,
1515 + index + 1, port_status);
1517 // what happens if HCS_N_CC(params) == 0 ?
1518 port_status |= PORT_OWNER;
1519 writel (port_status, &ehci->regs->port_status [index]);
1522 - dbg ("%s port %d high speed", ehci->hcd.bus_name, index + 1);
1523 + dbg ("%s port %d high speed",
1524 + hcd_to_bus (&ehci->hcd)->bus_name,
1531 /* whoever resets must GetPortStatus to complete it!! */
1532 if ((temp & PORT_RESET)
1533 - && jiffies > ehci->reset_done [wIndex]) {
1534 + && time_after (jiffies,
1535 + ehci->reset_done [wIndex])) {
1536 status |= 1 << USB_PORT_FEAT_C_RESET;
1538 /* force reset to complete */
1539 @@ -310,11 +314,13 @@
1540 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1541 && PORT_USB11 (temp)) {
1542 dbg ("%s port %d low speed, give to companion",
1543 - hcd->bus_name, wIndex + 1);
1544 + hcd_to_bus (&ehci->hcd)->bus_name,
1548 vdbg ("%s port %d reset",
1549 - hcd->bus_name, wIndex + 1);
1550 + hcd_to_bus (&ehci->hcd)->bus_name,
1555 diff -Nru a/drivers/usb/hcd/ehci-q.c b/drivers/usb/hcd/ehci-q.c
1556 --- a/drivers/usb/hcd/ehci-q.c Mon Oct 21 22:14:31 2002
1557 +++ b/drivers/usb/hcd/ehci-q.c Mon Oct 21 22:14:31 2002
1559 * Control, bulk, and interrupt traffic all use "qh" lists. They list "qtd"
1560 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
1561 * buffers needed for the larger number). We use one QH per endpoint, queue
1562 - * multiple (bulk or control) urbs per endpoint. URBs may need several qtds.
1563 - * A scheduled interrupt qh always (for now) has one qtd, one urb.
1564 + * multiple urbs (all three types) per endpoint. URBs may need several qtds.
1566 * ISO traffic uses "ISO TD" (itd, and sitd) records, and (along with
1567 * interrupts) needs careful scheduling. Performance improvements can be
1569 qtd_fill (struct ehci_qtd *qtd, dma_addr_t buf, size_t len, int token)
1574 /* one buffer entry per 4K ... first might be short or unaligned */
1575 - qtd->hw_buf [0] = cpu_to_le32 (buf);
1576 + qtd->hw_buf [0] = cpu_to_le32 ((u32)addr);
1577 + qtd->hw_buf_hi [0] = cpu_to_le32 ((u32)(addr >> 32));
1578 count = 0x1000 - (buf & 0x0fff); /* rest of that page */
1579 if (likely (len < count)) /* ... iff needed */
1583 /* per-qtd limit: from 16K to 20K (best alignment) */
1584 for (i = 1; count < len && i < 5; i++) {
1587 qtd->hw_buf [i] = cpu_to_le32 ((u32)addr);
1588 qtd->hw_buf_hi [i] = cpu_to_le32 ((u32)(addr >> 32));
1590 @@ -144,97 +145,106 @@
1591 usb_pipeendpoint (pipe),
1592 usb_pipeout (pipe));
1593 if (urb->dev->tt && !usb_pipeint (pipe)) {
1594 -err ("must CLEAR_TT_BUFFER, hub port %d%s addr %d ep %d",
1595 - urb->dev->ttport, /* devpath */
1596 - urb->dev->tt->multi ? "" : " (all-ports TT)",
1597 - urb->dev->devnum, usb_pipeendpoint (urb->pipe));
1598 - // FIXME something (khubd?) should make the hub
1599 - // CLEAR_TT_BUFFER ASAP, it's blocking other
1600 - // fs/ls requests... hub_tt_clear_buffer() ?
1602 + struct usb_device *tt = urb->dev->tt->hub;
1603 + dbg ("clear tt %s-%s p%d buffer, a%d ep%d",
1604 + tt->bus->bus_name, tt->devpath,
1605 + urb->dev->ttport, urb->dev->devnum,
1606 + usb_pipeendpoint (pipe));
1608 + usb_hub_tt_clear_buffer (urb->dev, pipe);
1614 -static void ehci_urb_complete (
1615 - struct ehci_hcd *ehci,
1619 - if (urb->transfer_buffer_length && usb_pipein (urb->pipe))
1620 - pci_dma_sync_single (ehci->hcd.pdev, addr,
1621 - urb->transfer_buffer_length,
1622 - PCI_DMA_FROMDEVICE);
1623 +static void ehci_urb_done (struct ehci_hcd *ehci, struct urb *urb)
1625 +#ifdef INTR_AUTOMAGIC
1626 + struct urb *resubmit = 0;
1627 + struct usb_device *dev = 0;
1629 - /* cleanse status if we saw no error */
1630 - if (likely (urb->status == -EINPROGRESS)) {
1631 - if (urb->actual_length != urb->transfer_buffer_length
1632 - && (urb->transfer_flags & USB_DISABLE_SPD))
1633 - urb->status = -EREMOTEIO;
1637 + static int ehci_urb_enqueue (struct usb_hcd *, struct urb *, int);
1640 - /* only report unlinks once */
1641 - if (likely (urb->status != -ENOENT && urb->status != -ENOTCONN))
1642 - urb->complete (urb);
1644 + if (likely (urb->hcpriv != 0)) {
1645 + struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv;
1647 -/* urb->lock ignored from here on (hcd is done with urb) */
1648 + /* S-mask in a QH means it's an interrupt urb */
1649 + if ((qh->hw_info2 & cpu_to_le32 (0x00ff)) != 0) {
1651 -static void ehci_urb_done (
1652 - struct ehci_hcd *ehci,
1656 - if (urb->transfer_buffer_length)
1657 - pci_unmap_single (ehci->hcd.pdev,
1659 - urb->transfer_buffer_length,
1660 - usb_pipein (urb->pipe)
1661 - ? PCI_DMA_FROMDEVICE
1662 - : PCI_DMA_TODEVICE);
1663 - if (likely (urb->hcpriv != 0)) {
1664 - qh_put (ehci, (struct ehci_qh *) urb->hcpriv);
1665 + /* ... update hc-wide periodic stats (for usbfs) */
1666 + hcd_to_bus (&ehci->hcd)->bandwidth_int_reqs--;
1668 +#ifdef INTR_AUTOMAGIC
1669 + if (!((urb->status == -ENOENT)
1670 + || (urb->status == -ECONNRESET))) {
1671 + resubmit = usb_get_urb (urb);
1676 + qh_put (ehci, qh);
1680 if (likely (urb->status == -EINPROGRESS)) {
1681 if (urb->actual_length != urb->transfer_buffer_length
1682 - && (urb->transfer_flags & USB_DISABLE_SPD))
1683 + && (urb->transfer_flags & URB_SHORT_NOT_OK))
1684 urb->status = -EREMOTEIO;
1689 - /* hand off urb ownership */
1690 + if (likely (urb->status == 0))
1691 + COUNT (ehci->stats.complete);
1692 + else if (urb->status == -ECONNRESET || urb->status == -ENOENT)
1693 + COUNT (ehci->stats.unlink);
1695 + COUNT (ehci->stats.error);
1697 + /* complete() can reenter this HCD */
1698 + spin_unlock (&ehci->lock);
1699 usb_hcd_giveback_urb (&ehci->hcd, urb);
1701 +#ifdef INTR_AUTOMAGIC
1702 + if (resubmit && ((urb->status == -ENOENT)
1703 + || (urb->status == -ECONNRESET))) {
1704 + usb_put_urb (resubmit);
1707 + // device drivers will soon be doing something like this
1711 + resubmit->dev = dev;
1712 + status = SUBMIT_URB (resubmit, SLAB_KERNEL);
1714 + err ("can't resubmit interrupt urb %p: status %d",
1715 + resubmit, status);
1716 + usb_put_urb (resubmit);
1720 + spin_lock (&ehci->lock);
1725 - * Process completed qtds for a qh, issuing completions if needed.
1726 - * When freeing: frees qtds, unmaps buf, returns URB to driver.
1727 - * When not freeing (queued periodic qh): retain qtds, mapping, and urb.
1728 - * Races up to qh->hw_current; returns number of urb completions.
1729 + * Process and free completed qtds for a qh, returning URBs to drivers.
1730 + * Chases up to qh->hw_current. Returns number of completions called,
1731 + * indicating how much "real" work we did.
1735 - struct ehci_hcd *ehci,
1736 - struct ehci_qh *qh,
1740 +qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
1742 struct ehci_qtd *qtd, *last;
1743 struct list_head *next, *qtd_list = &qh->qtd_list;
1744 int unlink = 0, halted = 0;
1745 - unsigned long flags;
1747 + unsigned count = 0;
1749 - spin_lock_irqsave (&ehci->lock, flags);
1750 - if (unlikely (list_empty (qtd_list))) {
1751 - spin_unlock_irqrestore (&ehci->lock, flags);
1754 + if (unlikely (list_empty (qtd_list)))
1757 /* scan QTDs till end of list, or we reach an active one */
1758 for (qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list),
1759 @@ -248,16 +258,8 @@
1760 /* clean up any state from previous QTD ...*/
1762 if (likely (last->urb != urb)) {
1763 - /* complete() can reenter this HCD */
1764 - spin_unlock_irqrestore (&ehci->lock, flags);
1765 - if (likely (freeing != 0))
1766 - ehci_urb_done (ehci, last->buf_dma,
1769 - ehci_urb_complete (ehci, last->buf_dma,
1771 - spin_lock_irqsave (&ehci->lock, flags);
1773 + ehci_urb_done (ehci, last->urb);
1777 /* qh overlays can have HC's old cached copies of
1778 @@ -267,10 +269,10 @@
1779 && last->hw_next != qh->hw_qtd_next) {
1780 qh->hw_alt_next = last->hw_alt_next;
1781 qh->hw_qtd_next = last->hw_next;
1782 + COUNT (ehci->stats.qpatch);
1785 - if (likely (freeing != 0))
1786 - ehci_qtd_free (ehci, last);
1787 + ehci_qtd_free (ehci, last);
1790 next = qtd->qtd_list.next;
1791 @@ -285,9 +287,17 @@
1792 || (ehci->hcd.state == USB_STATE_HALT)
1793 || (qh->qh_state == QH_STATE_IDLE);
1795 + // FIXME Remove the automagic unlink mode.
1796 + // Drivers can now clean up safely; it's their job.
1798 + // FIXME Removing it should fix the short read scenarios
1799 + // with "huge" urb data (more than one 16+KByte td) with
1800 + // the short read someplace other than the last data TD.
1801 + // Except the control case: 'retrigger' status ACKs.
1803 /* fault: unlink the rest, since this qtd saw an error? */
1804 if (unlikely ((token & QTD_STS_HALT) != 0)) {
1805 - freeing = unlink = 1;
1807 /* status copied below */
1809 /* QH halts only because of fault (above) or unlink (here). */
1810 @@ -295,13 +305,14 @@
1812 /* unlinking everything because of HC shutdown? */
1813 if (ehci->hcd.state == USB_STATE_HALT) {
1814 - freeing = unlink = 1;
1817 /* explicit unlink, maybe starting here? */
1818 } else if (qh->qh_state == QH_STATE_IDLE
1819 && (urb->status == -ECONNRESET
1820 + || urb->status == -ESHUTDOWN
1821 || urb->status == -ENOENT)) {
1822 - freeing = unlink = 1;
1825 /* QH halted to unlink urbs _after_ this? */
1826 } else if (!unlink && (token & QTD_STS_ACTIVE) != 0) {
1829 /* unlink the rest? once we start unlinking, after
1830 * a fault or explicit unlink, we unlink all later
1831 - * urbs. usb spec requires that.
1832 + * urbs. usb spec requires that for faults...
1834 if (unlink && urb->status == -EINPROGRESS)
1835 urb->status = -ECONNRESET;
1836 @@ -329,31 +340,7 @@
1837 qtd_copy_status (urb, qtd->length, token);
1838 spin_unlock (&urb->lock);
1841 - * NOTE: this won't work right with interrupt urbs that
1842 - * need multiple qtds ... only the first scan of qh->qtd_list
1843 - * starts at the right qtd, yet multiple scans could happen
1844 - * for transfers that are scheduled across multiple uframes.
1845 - * (Such schedules are not currently allowed!)
1847 - if (likely (freeing != 0))
1848 - list_del (&qtd->qtd_list);
1850 - /* restore everything the HC could change
1851 - * from an interrupt QTD
1853 - qtd->hw_token = (qtd->hw_token
1854 - & __constant_cpu_to_le32 (0x8300))
1855 - | cpu_to_le32 (qtd->length << 16)
1856 - | __constant_cpu_to_le32 (QTD_STS_ACTIVE
1857 - | (EHCI_TUNE_CERR << 10));
1858 - qtd->hw_buf [0] &= ~__constant_cpu_to_le32 (0x0fff);
1860 - /* this offset, and the length above,
1861 - * are likely wrong on QTDs #2..N
1863 - qtd->hw_buf [0] |= cpu_to_le32 (0x0fff & qtd->buf_dma);
1865 + list_del (&qtd->qtd_list);
1868 if (urb->status == -EINPROGRESS)
1869 @@ -364,31 +351,22 @@
1870 urb, urb->status, qtd, token,
1871 urb->actual_length);
1875 - /* SETUP for control urb? */
1876 - if (unlikely (QTD_PID (token) == 2))
1877 - pci_unmap_single (ehci->hcd.pdev,
1878 - qtd->buf_dma, sizeof (devrequest),
1879 - PCI_DMA_TODEVICE);
1880 + /* last urb's completion might still need calling */
1881 + if (likely (last != 0)) {
1882 + ehci_urb_done (ehci, last->urb);
1884 + ehci_qtd_free (ehci, last);
1887 - /* patch up list head? */
1888 + /* reactivate queue after error and driver's cleanup */
1889 if (unlikely (halted && !list_empty (qtd_list))) {
1890 qh_update (qh, list_entry (qtd_list->next,
1891 struct ehci_qtd, qtd_list));
1893 - spin_unlock_irqrestore (&ehci->lock, flags);
1895 - /* last urb's completion might still need calling */
1896 - if (likely (last != 0)) {
1897 - if (likely (freeing != 0)) {
1898 - ehci_urb_done (ehci, last->buf_dma, last->urb);
1899 - ehci_qtd_free (ehci, last);
1901 - ehci_urb_complete (ehci, last->buf_dma, last->urb);
1908 /*-------------------------------------------------------------------------*/
1909 @@ -403,35 +381,12 @@
1910 struct list_head *qtd_list
1912 struct list_head *entry, *temp;
1915 list_for_each_safe (entry, temp, qtd_list) {
1916 struct ehci_qtd *qtd;
1918 qtd = list_entry (entry, struct ehci_qtd, qtd_list);
1919 list_del (&qtd->qtd_list);
1920 - if (unmapped != 2) {
1924 - /* for ctrl unmap twice: SETUP and DATA;
1925 - * else (bulk, intr) just once: DATA
1927 - if (!unmapped++ && usb_pipecontrol (urb->pipe)) {
1928 - direction = PCI_DMA_TODEVICE;
1929 - size = sizeof (devrequest);
1931 - direction = usb_pipein (urb->pipe)
1932 - ? PCI_DMA_FROMDEVICE
1933 - : PCI_DMA_TODEVICE;
1934 - size = qtd->urb->transfer_buffer_length;
1938 - pci_unmap_single (ehci->hcd.pdev,
1942 ehci_qtd_free (ehci, qtd);
1948 struct ehci_qtd *qtd, *qtd_prev;
1949 - dma_addr_t buf, map_buf;
1952 + int is_input, status_patch = 0;
1956 @@ -466,17 +422,8 @@
1957 /* for split transactions, SplitXState initialized to zero */
1959 if (usb_pipecontrol (urb->pipe)) {
1960 - /* control request data is passed in the "setup" pid */
1961 - qtd->buf_dma = pci_map_single (
1963 - urb->setup_packet,
1964 - sizeof (devrequest),
1965 - PCI_DMA_TODEVICE);
1966 - if (unlikely (!qtd->buf_dma))
1970 - qtd_fill (qtd, qtd->buf_dma, sizeof (devrequest),
1971 + qtd_fill (qtd, urb->setup_dma, sizeof (struct usb_ctrlrequest),
1972 token | (2 /* "setup" */ << 8));
1974 /* ... and always at least one more pid */
1975 @@ -488,29 +435,26 @@
1977 qtd_prev->hw_next = QTD_NEXT (qtd->qtd_dma);
1978 list_add_tail (&qtd->qtd_list, head);
1980 + if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
1985 * data transfer stage: buffer setup
1987 len = urb->transfer_buffer_length;
1988 - if (likely (len > 0)) {
1989 - buf = map_buf = pci_map_single (ehci->hcd.pdev,
1990 - urb->transfer_buffer, len,
1991 - usb_pipein (urb->pipe)
1992 - ? PCI_DMA_FROMDEVICE
1993 - : PCI_DMA_TODEVICE);
1994 - if (unlikely (!buf))
1997 - buf = map_buf = 0;
1998 + is_input = usb_pipein (urb->pipe);
1999 + if (likely (len > 0))
2000 + buf = urb->transfer_dma;
2004 - if (!buf || usb_pipein (urb->pipe))
2005 + if (!buf || is_input)
2006 token |= (1 /* "in" */ << 8);
2007 /* else it's already initted to "out" pid (0 << 8) */
2009 - maxpacket = usb_maxpacket (urb->dev, urb->pipe,
2010 - usb_pipeout (urb->pipe));
2011 + maxpacket = usb_maxpacket (urb->dev, urb->pipe, !is_input) & 0x03ff;
2014 * buffer gets wrapped in one or more qtds;
2019 - qtd->buf_dma = map_buf;
2020 this_qtd_len = qtd_fill (qtd, buf, len, token);
2021 len -= this_qtd_len;
2022 buf += this_qtd_len;
2023 @@ -572,6 +515,19 @@
2027 + /* if we're permitting a short control read, we want the hardware to
2028 + * just continue after short data and send the status ack. it can do
2029 + * that on the last data packet (typically the only one). for other
2030 + * packets, software fixup is needed (in qh_completions).
2032 + if (status_patch) {
2033 + struct ehci_qtd *prev;
2035 + prev = list_entry (qtd->qtd_list.prev,
2036 + struct ehci_qtd, qtd_list);
2037 + prev->hw_alt_next = QTD_NEXT (qtd->qtd_dma);
2040 /* by default, enable interrupt on urb completion */
2041 if (likely (!(urb->transfer_flags & URB_NO_INTERRUPT)))
2042 qtd->hw_token |= __constant_cpu_to_le32 (QTD_IOC);
2043 @@ -606,6 +562,11 @@
2044 // That'd mean updating how usbcore talks to HCDs. (2.5?)
2047 +// high bandwidth multiplier, as encoded in highspeed endpoint descriptors
2048 +#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
2049 +// ... and packet size, for any kind of endpoint descriptor
2050 +#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x03ff)
2053 * Each QH holds a qtd list; a QH is used for everything except iso.
2057 struct ehci_qh *qh = ehci_qh_alloc (ehci, flags);
2058 u32 info1 = 0, info2 = 0;
2059 + int is_input, type;
2064 @@ -633,6 +596,53 @@
2065 info1 |= usb_pipeendpoint (urb->pipe) << 8;
2066 info1 |= usb_pipedevice (urb->pipe) << 0;
2068 + is_input = usb_pipein (urb->pipe);
2069 + type = usb_pipetype (urb->pipe);
2070 + maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
2072 + /* Compute interrupt scheduling parameters just once, and save.
2073 + * - allowing for high bandwidth, how many nsec/uframe are used?
2074 + * - split transactions need a second CSPLIT uframe; same question
2075 + * - splits also need a schedule gap (for full/low speed I/O)
2076 + * - qh has a polling interval
2078 + * For control/bulk requests, the HC or TT handles these.
2080 + if (type == PIPE_INTERRUPT) {
2081 + qh->usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0,
2082 + hb_mult (maxp) * max_packet (maxp));
2083 + qh->start = NO_FRAME;
2085 + if (urb->dev->speed == USB_SPEED_HIGH) {
2089 + /* FIXME handle HS periods of less than 1 frame. */
2090 + qh->period = urb->interval >> 3;
2091 + if (qh->period < 1) {
2092 + dbg ("intr period %d uframes, NYET!",
2098 + /* gap is f(FS/LS transfer times) */
2099 + qh->gap_uf = 1 + usb_calc_bus_time (urb->dev->speed,
2100 + is_input, 0, maxp) / (125 * 1000);
2102 + /* FIXME this just approximates SPLIT/CSPLIT times */
2103 + if (is_input) { // SPLIT, gap, CSPLIT+DATA
2104 + qh->c_usecs = qh->usecs + HS_USECS (0);
2105 + qh->usecs = HS_USECS (1);
2106 + } else { // SPLIT+DATA, gap, CSPLIT
2107 + qh->usecs += HS_USECS (1);
2108 + qh->c_usecs = HS_USECS (0);
2111 + qh->period = urb->interval;
2116 switch (urb->dev->speed) {
2118 @@ -642,67 +652,62 @@
2119 case USB_SPEED_FULL:
2120 /* EPS 0 means "full" */
2121 info1 |= (EHCI_TUNE_RL_TT << 28);
2122 - if (usb_pipecontrol (urb->pipe)) {
2123 + if (type == PIPE_CONTROL) {
2124 info1 |= (1 << 27); /* for TT */
2125 info1 |= 1 << 14; /* toggle from qtd */
2127 - info1 |= usb_maxpacket (urb->dev, urb->pipe,
2128 - usb_pipeout (urb->pipe)) << 16;
2129 + info1 |= maxp << 16;
2131 info2 |= (EHCI_TUNE_MULT_TT << 30);
2132 info2 |= urb->dev->ttport << 23;
2133 info2 |= urb->dev->tt->hub->devnum << 16;
2135 - /* NOTE: if (usb_pipeint (urb->pipe)) { scheduler sets c-mask }
2136 - * ... and a 0.96 scheduler might use FSTN nodes too
2138 + /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */
2142 case USB_SPEED_HIGH: /* no TT involved */
2143 info1 |= (2 << 12); /* EPS "high" */
2144 info1 |= (EHCI_TUNE_RL_HS << 28);
2145 - if (usb_pipecontrol (urb->pipe)) {
2146 + if (type == PIPE_CONTROL) {
2147 info1 |= 64 << 16; /* usb2 fixed maxpacket */
2148 info1 |= 1 << 14; /* toggle from qtd */
2149 info2 |= (EHCI_TUNE_MULT_HS << 30);
2150 - } else if (usb_pipebulk (urb->pipe)) {
2151 + } else if (type == PIPE_BULK) {
2152 info1 |= 512 << 16; /* usb2 fixed maxpacket */
2153 info2 |= (EHCI_TUNE_MULT_HS << 30);
2156 - temp = usb_maxpacket (urb->dev, urb->pipe,
2157 - usb_pipeout (urb->pipe));
2158 - info1 |= (temp & 0x3ff) << 16; /* maxpacket */
2159 - /* HS intr can be "high bandwidth" */
2160 - temp = 1 + ((temp >> 11) & 0x03);
2161 - info2 |= temp << 30; /* mult */
2162 + } else { /* PIPE_INTERRUPT */
2163 + info1 |= max_packet (maxp) << 16;
2164 + info2 |= hb_mult (maxp) << 30;
2171 + dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed);
2175 - /* NOTE: if (usb_pipeint (urb->pipe)) { scheduler sets s-mask } */
2176 + /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
2178 qh->qh_state = QH_STATE_IDLE;
2179 qh->hw_info1 = cpu_to_le32 (info1);
2180 qh->hw_info2 = cpu_to_le32 (info2);
2182 /* initialize sw and hw queues with these qtds */
2183 - list_splice (qtd_list, &qh->qtd_list);
2184 - qh_update (qh, list_entry (qtd_list->next, struct ehci_qtd, qtd_list));
2185 + if (!list_empty (qtd_list)) {
2186 + list_splice (qtd_list, &qh->qtd_list);
2187 + qh_update (qh, list_entry (qtd_list->next, struct ehci_qtd, qtd_list));
2189 + qh->hw_qtd_next = qh->hw_alt_next = EHCI_LIST_END;
2192 /* initialize data toggle state */
2193 - if (!usb_pipecontrol (urb->pipe))
2194 - clear_toggle (urb->dev,
2195 - usb_pipeendpoint (urb->pipe),
2196 - usb_pipeout (urb->pipe),
2198 + clear_toggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, qh);
2206 /*-------------------------------------------------------------------------*/
2209 u32 cmd = readl (&ehci->regs->command);
2211 /* in case a clear of CMD_ASE didn't take yet */
2212 - while (readl (&ehci->regs->status) & STS_ASS)
2214 + (void) handshake (&ehci->regs->status, STS_ASS, 0, 150);
2216 qh->hw_info1 |= __constant_cpu_to_le32 (QH_HEAD); /* [4.8] */
2217 qh->qh_next.qh = qh;
2218 @@ -743,58 +745,58 @@
2220 qh->qh_state = QH_STATE_LINKED;
2221 /* qtd completions reported later by interrupt */
2223 + ehci->async_idle = 0;
2226 /*-------------------------------------------------------------------------*/
2231 + * For control/bulk/interrupt, return QH with these TDs appended.
2232 + * Allocates and initializes the QH if necessary.
2233 + * Returns null if it can't allocate a QH it needs to.
2234 + * If the QH has TDs (urbs) already, that's great.
2236 +static struct ehci_qh *qh_append_tds (
2237 struct ehci_hcd *ehci,
2239 struct list_head *qtd_list,
2242 - struct ehci_qtd *qtd;
2243 - struct hcd_dev *dev;
2245 - unsigned long flags;
2250 struct ehci_qh *qh = 0;
2252 - qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
2253 - dev = (struct hcd_dev *)urb->dev->hcpriv;
2254 - epnum = usb_pipeendpoint (urb->pipe);
2255 - if (usb_pipein (urb->pipe))
2258 - vdbg ("%s: submit_async urb %p len %d ep %d-%s qtd %p [qh %p]",
2259 - ehci->hcd.bus_name, urb, urb->transfer_buffer_length,
2260 - epnum & 0x0f, (epnum & 0x10) ? "in" : "out",
2261 - qtd, dev ? dev->ep [epnum] : (void *)~0);
2263 - spin_lock_irqsave (&ehci->lock, flags);
2265 - qh = (struct ehci_qh *) dev->ep [epnum];
2266 + qh = (struct ehci_qh *) *ptr;
2267 if (likely (qh != 0)) {
2268 - u32 hw_next = QTD_NEXT (qtd->qtd_dma);
2269 + struct ehci_qtd *qtd;
2271 + if (unlikely (list_empty (qtd_list)))
2274 + qtd = list_entry (qtd_list->next, struct ehci_qtd,
2277 /* maybe patch the qh used for set_address */
2278 if (unlikely (epnum == 0
2279 && le32_to_cpu (qh->hw_info1 & 0x7f) == 0))
2280 qh->hw_info1 |= cpu_to_le32 (usb_pipedevice(urb->pipe));
2282 - /* is an URB is queued to this qh already? */
2283 - if (unlikely (!list_empty (&qh->qtd_list))) {
2284 + /* append to tds already queued to this qh? */
2285 + if (unlikely (!list_empty (&qh->qtd_list) && qtd)) {
2286 struct ehci_qtd *last_qtd;
2290 /* update the last qtd's "next" pointer */
2291 // dbg_qh ("non-empty qh", ehci, qh);
2292 last_qtd = list_entry (qh->qtd_list.prev,
2293 struct ehci_qtd, qtd_list);
2294 + hw_next = QTD_NEXT (qtd->qtd_dma);
2295 last_qtd->hw_next = hw_next;
2297 /* previous urb allows short rx? maybe optimize. */
2298 - if (!(last_qtd->urb->transfer_flags & USB_DISABLE_SPD)
2299 + if (!(last_qtd->urb->transfer_flags & URB_SHORT_NOT_OK)
2300 && (epnum & 0x10)) {
2301 // only the last QTD for now
2302 last_qtd->hw_alt_next = hw_next;
2304 * Interrupt code must cope with case of HC having it
2305 * cached, and clobbering these updates.
2306 * ... complicates getting rid of extra interrupts!
2307 + * (Or: use dummy td, so cache always stays valid.)
2309 if (qh->hw_current == cpu_to_le32 (last_qtd->qtd_dma)) {
2311 @@ -824,31 +827,62 @@
2314 /* usb_clear_halt() means qh data toggle gets reset */
2315 - if (usb_pipebulk (urb->pipe)
2316 - && unlikely (!usb_gettoggle (urb->dev,
2317 + if (unlikely (!usb_gettoggle (urb->dev,
2319 !(epnum & 0x10)))) {
2320 clear_toggle (urb->dev,
2321 epnum & 0x0f, !(epnum & 0x10), qh);
2323 - qh_update (qh, qtd);
2325 + qh_update (qh, qtd);
2327 list_splice (qtd_list, qh->qtd_list.prev);
2330 /* can't sleep here, we have ehci->lock... */
2331 qh = ehci_qh_make (ehci, urb, qtd_list, SLAB_ATOMIC);
2332 - if (likely (qh != 0)) {
2333 - // dbg_qh ("new qh", ehci, qh);
2334 - dev->ep [epnum] = qh;
2336 + // if (qh) dbg_qh ("new qh", ehci, qh);
2340 + urb->hcpriv = qh_get (qh);
2344 +/*-------------------------------------------------------------------------*/
2348 + struct ehci_hcd *ehci,
2350 + struct list_head *qtd_list,
2353 + struct ehci_qtd *qtd;
2354 + struct hcd_dev *dev;
2356 + unsigned long flags;
2357 + struct ehci_qh *qh = 0;
2359 + qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
2360 + dev = (struct hcd_dev *)urb->dev->hcpriv;
2361 + epnum = usb_pipeendpoint (urb->pipe);
2362 + if (usb_pipein (urb->pipe) && !usb_pipecontrol (urb->pipe))
2365 + vdbg ("%s: submit_async urb %p len %d ep %d-%s qtd %p [qh %p]",
2366 + hcd_to_bus (&ehci->hcd)->bus_name,
2367 + urb, urb->transfer_buffer_length,
2368 + epnum & 0x0f, (epnum & 0x10) ? "in" : "out",
2369 + qtd, dev ? dev->ep [epnum] : (void *)~0);
2371 + spin_lock_irqsave (&ehci->lock, flags);
2372 + qh = qh_append_tds (ehci, urb, qtd_list, epnum, &dev->ep [epnum]);
2374 /* Control/bulk operations through TTs don't need scheduling,
2375 * the HC and TT handle it when the TT has a buffer ready.
2377 if (likely (qh != 0)) {
2378 - urb->hcpriv = qh_get (qh);
2379 if (likely (qh->qh_state == QH_STATE_IDLE))
2380 qh_link_async (ehci, qh_get (qh));
2382 @@ -869,16 +903,16 @@
2384 struct ehci_qh *qh = ehci->reclaim;
2386 + del_timer (&ehci->watchdog);
2388 qh->qh_state = QH_STATE_IDLE;
2390 qh_put (ehci, qh); // refcount from reclaim
2392 ehci->reclaim_ready = 0;
2394 - qh_completions (ehci, qh, 1);
2395 + qh_completions (ehci, qh);
2397 - // unlink any urb should now unlink all following urbs, so that
2398 - // relinking only happens for urbs before the unlinked ones.
2399 if (!list_empty (&qh->qtd_list)
2400 && HCD_IS_RUNNING (ehci->hcd.state))
2401 qh_link_async (ehci, qh);
2403 qh_put (ehci, qh); // refcount from async list
2407 /* makes sure the async qh will become idle */
2408 /* caller must own ehci->lock */
2410 @@ -916,13 +949,14 @@
2411 if (unlikely (qh == ehci->async && qh->qh_next.qh == qh)) {
2412 /* can't get here without STS_ASS set */
2413 if (ehci->hcd.state != USB_STATE_HALT) {
2414 - if (cmd & CMD_PSE)
2415 - writel (cmd & ~CMD_ASE, &ehci->regs->command);
2417 - ehci_ready (ehci);
2418 - while (readl (&ehci->regs->status) & STS_ASS)
2421 + writel (cmd & ~CMD_ASE, &ehci->regs->command);
2422 + (void) handshake (&ehci->regs->status, STS_ASS, 0, 150);
2424 + // one VT8235 system wants to die with STS_FATAL
2425 + // unless this qh is leaked here. others seem ok...
2427 + dbg_qh ("async/off", ehci, qh);
2430 qh->qh_next.qh = ehci->async = 0;
2432 @@ -940,10 +974,6 @@
2434 while (prev->qh_next.qh != qh && prev->qh_next.qh != ehci->async)
2435 prev = prev->qh_next.qh;
2437 - if (prev->qh_next.qh != qh)
2441 if (qh->hw_info1 & __constant_cpu_to_le32 (QH_HEAD)) {
2443 @@ -957,48 +987,63 @@
2445 writel (cmd, &ehci->regs->command);
2446 /* posted write need not be known to HC yet ... */
2448 + mod_timer (&ehci->watchdog, jiffies + EHCI_WATCHDOG_JIFFIES);
2451 /*-------------------------------------------------------------------------*/
2453 -static void scan_async (struct ehci_hcd *ehci)
2455 +scan_async (struct ehci_hcd *ehci)
2458 - unsigned long flags;
2461 - spin_lock_irqsave (&ehci->lock, flags);
2465 if (likely (qh != 0)) {
2467 /* clean any finished work for this qh */
2468 if (!list_empty (&qh->qtd_list)) {
2469 // dbg_qh ("scan_async", ehci, qh);
2471 - spin_unlock_irqrestore (&ehci->lock, flags);
2473 /* concurrent unlink could happen here */
2474 - qh_completions (ehci, qh, 1);
2476 - spin_lock_irqsave (&ehci->lock, flags);
2477 + count += qh_completions (ehci, qh);
2481 - /* unlink idle entries (reduces PCI usage) */
2482 + /* unlink idle entries, reducing HC PCI usage as
2483 + * well as HCD schedule-scanning costs. removing
2484 + * the last qh is deferred, since it's costly.
2486 + * FIXME don't unlink idle entries so quickly; it
2487 + * can penalize (common) half duplex protocols.
2489 if (list_empty (&qh->qtd_list) && !ehci->reclaim) {
2490 if (qh->qh_next.qh != qh) {
2491 // dbg ("irq/empty");
2492 start_unlink_async (ehci, qh);
2494 - // FIXME: arrange to stop
2495 - // after it's been idle a while.
2496 + } else if (!timer_pending (&ehci->watchdog)) {
2497 + /* can't use IAA for last entry */
2498 + ehci->async_idle = 1;
2499 + mod_timer (&ehci->watchdog,
2500 + jiffies + EHCI_ASYNC_JIFFIES);
2504 + /* keep latencies down: let any irqs in */
2505 + if (count > max_completions) {
2506 + spin_unlock_irq (&ehci->lock);
2508 + spin_lock_irq (&ehci->lock);
2512 qh = qh->qh_next.qh;
2513 if (!qh) /* unlinked? */
2515 } while (qh != ehci->async);
2518 - spin_unlock_irqrestore (&ehci->lock, flags);
2520 diff -Nru a/drivers/usb/hcd/ehci-sched.c b/drivers/usb/hcd/ehci-sched.c
2521 --- a/drivers/usb/hcd/ehci-sched.c Mon Oct 21 22:14:31 2002
2522 +++ b/drivers/usb/hcd/ehci-sched.c Mon Oct 21 22:14:31 2002
2524 * or with "USB On The Go" additions to USB 2.0 ...)
2528 - * Ceiling microseconds (typical) for that many bytes at high speed
2529 - * ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed
2530 - * to preallocate bandwidth)
2532 -#define EHCI_HOST_DELAY 5 /* nsec, guess */
2533 -#define HS_USECS(bytes) NS_TO_US ( ((55 * 8 * 2083)/1000) \
2534 - + ((2083UL * (3167 + BitTime (bytes)))/1000) \
2535 - + EHCI_HOST_DELAY)
2536 -#define HS_USECS_ISO(bytes) NS_TO_US ( ((long)(38 * 8 * 2.083)) \
2537 - + ((2083UL * (3167 + BitTime (bytes)))/1000) \
2538 - + EHCI_HOST_DELAY)
2540 static int ehci_get_frame (struct usb_hcd *hcd);
2542 /*-------------------------------------------------------------------------*/
2544 /* is it in the S-mask? */
2545 if (q->qh->hw_info2 & cpu_to_le32 (1 << uframe))
2546 usecs += q->qh->usecs;
2547 + /* ... or C-mask? */
2548 + if (q->qh->hw_info2 & cpu_to_le32 (1 << (8 + uframe)))
2549 + usecs += q->qh->c_usecs;
2550 q = &q->qh->qh_next;
2553 @@ -181,15 +171,19 @@
2555 /*-------------------------------------------------------------------------*/
2557 -static void enable_periodic (struct ehci_hcd *ehci)
2558 +static int enable_periodic (struct ehci_hcd *ehci)
2563 /* did clearing PSE did take effect yet?
2564 * takes effect only at frame boundaries...
2566 - while (readl (&ehci->regs->status) & STS_PSS)
2568 + status = handshake (&ehci->regs->status, STS_PSS, 0, 9 * 125);
2569 + if (status != 0) {
2570 + ehci->hcd.state = USB_STATE_HALT;
2574 cmd = readl (&ehci->regs->command) | CMD_PSE;
2575 writel (cmd, &ehci->regs->command);
2576 @@ -199,80 +193,104 @@
2577 /* make sure tasklet scans these */
2578 ehci->next_uframe = readl (&ehci->regs->frame_index)
2579 % (ehci->periodic_size << 3);
2583 -static void disable_periodic (struct ehci_hcd *ehci)
2584 +static int disable_periodic (struct ehci_hcd *ehci)
2589 /* did setting PSE not take effect yet?
2590 * takes effect only at frame boundaries...
2592 - while (!(readl (&ehci->regs->status) & STS_PSS))
2594 + status = handshake (&ehci->regs->status, STS_PSS, STS_PSS, 9 * 125);
2595 + if (status != 0) {
2596 + ehci->hcd.state = USB_STATE_HALT;
2600 cmd = readl (&ehci->regs->command) & ~CMD_PSE;
2601 writel (cmd, &ehci->regs->command);
2602 /* posted write ... */
2604 ehci->next_uframe = -1;
2608 /*-------------------------------------------------------------------------*/
2610 +// FIXME microframe periods not yet handled
2612 static void intr_deschedule (
2613 struct ehci_hcd *ehci,
2619 - unsigned long flags;
2621 - period >>= 3; // FIXME microframe periods not handled yet
2623 - spin_lock_irqsave (&ehci->lock, flags);
2625 + unsigned frame = qh->start;
2628 periodic_unlink (ehci, frame, qh);
2631 + frame += qh->period;
2632 } while (frame < ehci->periodic_size);
2634 qh->qh_state = QH_STATE_UNLINK;
2635 qh->qh_next.ptr = 0;
2636 - ehci->periodic_urbs--;
2637 + ehci->periodic_sched--;
2639 /* maybe turn off periodic schedule */
2640 - if (!ehci->periodic_urbs)
2641 - disable_periodic (ehci);
2643 + if (!ehci->periodic_sched)
2644 + status = disable_periodic (ehci);
2647 vdbg ("periodic schedule still enabled");
2649 - spin_unlock_irqrestore (&ehci->lock, flags);
2653 * If the hc may be looking at this qh, then delay a uframe
2654 * (yeech!) to be sure it's done.
2655 * No other threads may be mucking with this qh.
2657 - if (((ehci_get_frame (&ehci->hcd) - frame) % period) == 0)
2659 + if (((ehci_get_frame (&ehci->hcd) - frame) % qh->period) == 0) {
2662 + qh->hw_next = EHCI_LIST_END;
2664 + /* we may not be IDLE yet, but if the qh is empty
2665 + * the race is very short. then if qh also isn't
2666 + * rescheduled soon, it won't matter. otherwise...
2668 + vdbg ("intr_deschedule...");
2671 + qh->hw_next = EHCI_LIST_END;
2673 qh->qh_state = QH_STATE_IDLE;
2674 - qh->hw_next = EHCI_LIST_END;
2676 - vdbg ("descheduled qh %p, per = %d frame = %d count = %d, urbs = %d",
2677 - qh, period, frame,
2678 - atomic_read (&qh->refcount), ehci->periodic_urbs);
2679 + /* update per-qh bandwidth utilization (for usbfs) */
2680 + hcd_to_bus (&ehci->hcd)->bandwidth_allocated -=
2681 + (qh->usecs + qh->c_usecs) / qh->period;
2683 + dbg ("descheduled qh %p, period = %d frame = %d count = %d, urbs = %d",
2684 + qh, qh->period, frame,
2685 + atomic_read (&qh->refcount), ehci->periodic_sched);
2688 static int check_period (
2689 struct ehci_hcd *ehci,
2696 + /* complete split running into next frame?
2697 + * given FSTN support, we could sometimes check...
2703 * 80% periodic == 100 usec/uframe available
2704 * convert "usecs we need" to "max already claimed"
2707 // FIXME delete when intr_submit handles non-empty queues
2708 // this gives us a one intr/frame limit (vs N/uframe)
2709 +// ... and also lets us avoid tracking split transactions
2710 +// that might collide at a given TT/hub.
2711 if (ehci->pshadow [frame].ptr)
2714 @@ -298,226 +318,203 @@
2718 -static int intr_submit (
2719 - struct ehci_hcd *ehci,
2721 - struct list_head *qtd_list,
2724 - unsigned epnum, period;
2725 - unsigned short usecs;
2726 - unsigned long flags;
2727 - struct ehci_qh *qh;
2728 - struct hcd_dev *dev;
2730 +static int check_intr_schedule (
2731 + struct ehci_hcd *ehci,
2734 + const struct ehci_qh *qh,
2738 + int retval = -ENOSPC;
2740 - /* get endpoint and transfer data */
2741 - epnum = usb_pipeendpoint (urb->pipe);
2742 - if (usb_pipein (urb->pipe))
2744 - if (urb->dev->speed != USB_SPEED_HIGH) {
2745 - dbg ("no intr/tt scheduling yet");
2747 + if (!check_period (ehci, frame, uframe, qh->period, qh->usecs))
2749 + if (!qh->c_usecs) {
2751 + *c_maskp = cpu_to_le32 (0);
2756 - * NOTE: current completion/restart logic doesn't handle more than
2757 - * one qtd in a periodic qh ... 16-20 KB/urb is pretty big for this.
2758 - * such big requests need many periods to transfer.
2759 + /* This is a split transaction; check the bandwidth available for
2760 + * the completion too. Check both worst and best case gaps: worst
2761 + * case is SPLIT near uframe end, and CSPLIT near start ... best is
2762 + * vice versa. Difference can be almost two uframe times, but we
2763 + * reserve unnecessary bandwidth (waste it) this way. (Actually
2764 + * even better cases exist, like immediate device NAK.)
2766 - * FIXME want to change hcd core submit model to expect queuing
2767 - * for all transfer types ... not just ISO and (with flag) BULK.
2768 - * that means: getting rid of this check; handling the "interrupt
2769 - * urb already queued" case below like bulk queuing is handled (no
2770 - * errors possible!); and completly getting rid of that annoying
2771 - * qh restart logic. simpler/smaller overall, and more flexible.
2772 + * FIXME don't even bother unless we know this TT is idle in that
2773 + * range of uframes ... for now, check_period() allows only one
2774 + * interrupt transfer per frame, so needn't check "TT busy" status
2775 + * when scheduling a split (QH, SITD, or FSTN).
2777 + * FIXME ehci 0.96 and above can use FSTNs
2779 - if (unlikely (qtd_list->next != qtd_list->prev)) {
2780 - dbg ("only one intr qtd per urb allowed");
2782 + if (!check_period (ehci, frame, uframe + qh->gap_uf + 1,
2783 + qh->period, qh->c_usecs))
2787 - usecs = HS_USECS (urb->transfer_buffer_length);
2789 - /* FIXME handle HS periods of less than 1 frame. */
2790 - period = urb->interval >> 3;
2792 - dbg ("intr period %d uframes, NYET!", urb->interval);
2794 + if (!check_period (ehci, frame, uframe + qh->gap_uf,
2795 + qh->period, qh->c_usecs))
2799 - spin_lock_irqsave (&ehci->lock, flags);
2801 - /* get the qh (must be empty and idle) */
2802 - dev = (struct hcd_dev *)urb->dev->hcpriv;
2803 - qh = (struct ehci_qh *) dev->ep [epnum];
2805 - /* only allow one queued interrupt urb per EP */
2806 - if (unlikely (qh->qh_state != QH_STATE_IDLE
2807 - || !list_empty (&qh->qtd_list))) {
2808 - dbg ("interrupt urb already queued");
2811 - /* maybe reset hardware's data toggle in the qh */
2812 - if (unlikely (!usb_gettoggle (urb->dev, epnum & 0x0f,
2813 - !(epnum & 0x10)))) {
2815 - __constant_cpu_to_le32 (QTD_TOGGLE);
2816 - usb_settoggle (urb->dev, epnum & 0x0f,
2817 - !(epnum & 0x10), 1);
2819 - /* trust the QH was set up as interrupt ... */
2820 - list_splice (qtd_list, &qh->qtd_list);
2821 - qh_update (qh, list_entry (qtd_list->next,
2822 - struct ehci_qtd, qtd_list));
2823 - qtd_list = &qh->qtd_list;
2826 - /* can't sleep here, we have ehci->lock... */
2827 - qh = ehci_qh_make (ehci, urb, qtd_list, SLAB_ATOMIC);
2828 - if (likely (qh != 0)) {
2829 - // dbg ("new INTR qh %p", qh);
2830 - dev->ep [epnum] = qh;
2831 - qtd_list = &qh->qtd_list;
2835 + *c_maskp = cpu_to_le32 (0x03 << (8 + uframe + qh->gap_uf));
2841 - /* Schedule this periodic QH. */
2842 - if (likely (status == 0)) {
2843 - unsigned frame = period;
2844 +static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
2849 + unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
2851 - qh->hw_next = EHCI_LIST_END;
2852 - qh->usecs = usecs;
2853 + qh->hw_next = EHCI_LIST_END;
2854 + frame = qh->start;
2856 - urb->hcpriv = qh_get (qh);
2857 + /* reuse the previous schedule slots, if we can */
2858 + if (frame < qh->period) {
2859 + uframe = ffs (le32_to_cpup (&qh->hw_info2) & 0x00ff);
2860 + status = check_intr_schedule (ehci, frame, --uframe,
2868 - /* pick a set of schedule slots, link the QH into them */
2869 + /* else scan the schedule to find a group of slots such that all
2870 + * uframes have enough periodic bandwidth available.
2873 + frame = qh->period - 1;
2877 - /* pick a set of slots such that all uframes have
2878 - * enough periodic bandwidth available.
2880 - * FIXME for TT splits, need uframes for start and end.
2881 - * FSTNs can put end into next frame (uframes 0 or 1).
2884 for (uframe = 0; uframe < 8; uframe++) {
2885 - if (check_period (ehci, frame, uframe,
2886 - period, usecs) != 0)
2887 + status = check_intr_schedule (ehci,
2888 + frame, uframe, qh,
2895 + } while (status && --frame);
2898 + qh->start = frame;
2900 + /* reset S-frame and (maybe) C-frame masks */
2901 + qh->hw_info2 &= ~0xffff;
2902 + qh->hw_info2 |= cpu_to_le32 (1 << uframe) | c_mask;
2904 + dbg ("reused previous qh %p schedule", qh);
2906 + /* stuff into the periodic schedule */
2907 + qh->qh_state = QH_STATE_LINKED;
2908 + dbg ("scheduled qh %p usecs %d/%d period %d.0 starting %d.%d (gap %d)",
2909 + qh, qh->usecs, qh->c_usecs,
2910 + qh->period, frame, uframe, qh->gap_uf);
2912 + if (unlikely (ehci->pshadow [frame].ptr != 0)) {
2914 - /* QH will run once each period, starting there */
2915 - urb->start_frame = frame;
2918 - /* set S-frame mask */
2919 - qh->hw_info2 |= cpu_to_le32 (1 << uframe);
2920 - // dbg_qh ("Schedule INTR qh", ehci, qh);
2922 - /* stuff into the periodic schedule */
2923 - qh->qh_state = QH_STATE_LINKED;
2924 - vdbg ("qh %p usecs %d period %d starting %d.%d",
2925 - qh, qh->usecs, period, frame, uframe);
2927 - if (unlikely (ehci->pshadow [frame].ptr != 0)) {
2928 // FIXME -- just link toward the end, before any qh with a shorter period,
2929 -// AND handle it already being (implicitly) linked into this frame
2930 -// AS WELL AS updating the check_period() logic
2933 - ehci->pshadow [frame].qh = qh_get (qh);
2934 - ehci->periodic [frame] =
2935 - QH_NEXT (qh->qh_dma);
2939 - } while (frame < ehci->periodic_size);
2941 - /* update bandwidth utilization records (for usbfs) */
2942 - usb_claim_bandwidth (urb->dev, urb, usecs/period, 0);
2944 - /* maybe enable periodic schedule processing */
2945 - if (!ehci->periodic_urbs++)
2946 - enable_periodic (ehci);
2948 +// AND accomodate it already having been linked here (after some other qh)
2949 +// AS WELL AS updating the schedule checking logic
2953 + ehci->pshadow [frame].qh = qh_get (qh);
2954 + ehci->periodic [frame] =
2955 + QH_NEXT (qh->qh_dma);
2958 + frame += qh->period;
2959 + } while (frame < ehci->periodic_size);
2961 + /* update per-qh bandwidth for usbfs */
2962 + hcd_to_bus (&ehci->hcd)->bandwidth_allocated +=
2963 + (qh->usecs + qh->c_usecs) / qh->period;
2965 + /* maybe enable periodic schedule processing */
2966 + if (!ehci->periodic_sched++)
2967 + status = enable_periodic (ehci);
2973 +static int intr_submit (
2974 + struct ehci_hcd *ehci,
2976 + struct list_head *qtd_list,
2980 + unsigned long flags;
2981 + struct ehci_qh *qh;
2982 + struct hcd_dev *dev;
2985 + struct list_head empty;
2987 + /* get endpoint and transfer/schedule data */
2988 + epnum = usb_pipeendpoint (urb->pipe);
2989 + is_input = usb_pipein (urb->pipe);
2993 + spin_lock_irqsave (&ehci->lock, flags);
2994 + dev = (struct hcd_dev *)urb->dev->hcpriv;
2996 + /* get qh and force any scheduling errors */
2997 + INIT_LIST_HEAD (&empty);
2998 + qh = qh_append_tds (ehci, urb, &empty, epnum, &dev->ep [epnum]);
3003 - spin_unlock_irqrestore (&ehci->lock, flags);
3004 + if (qh->qh_state == QH_STATE_IDLE) {
3005 + if ((status = qh_schedule (ehci, qh)) != 0)
3009 + /* then queue the urb's tds to the qh */
3010 + qh = qh_append_tds (ehci, urb, qtd_list, epnum, &dev->ep [epnum]);
3013 + /* ... update usbfs periodic stats */
3014 + hcd_to_bus (&ehci->hcd)->bandwidth_int_reqs++;
3017 + spin_unlock_irqrestore (&ehci->lock, flags);
3019 qtd_list_free (ehci, urb, qtd_list);
3024 -static unsigned long
3027 struct ehci_hcd *ehci,
3029 - struct ehci_qh *qh,
3030 - unsigned long flags /* caller owns ehci->lock ... */
3031 + struct ehci_qh *qh
3033 - struct ehci_qtd *qtd;
3038 /* nothing to report? */
3039 if (likely ((qh->hw_token & __constant_cpu_to_le32 (QTD_STS_ACTIVE))
3043 if (unlikely (list_empty (&qh->qtd_list))) {
3044 dbg ("intr qh %p no TDs?", qh);
3049 - qtd = list_entry (qh->qtd_list.next, struct ehci_qtd, qtd_list);
3051 - unlinking = (urb->status == -ENOENT) || (urb->status == -ECONNRESET);
3053 - /* call any completions, after patching for reactivation */
3054 - spin_unlock_irqrestore (&ehci->lock, flags);
3055 - /* NOTE: currently restricted to one qtd per qh! */
3056 - if (qh_completions (ehci, qh, 0) == 0)
3058 - spin_lock_irqsave (&ehci->lock, flags);
3059 + /* handle any completions */
3060 + count = qh_completions (ehci, qh);
3062 - /* never reactivate requests that were unlinked ... */
3063 - if (likely (urb != 0)) {
3065 - || urb->status == -ECONNRESET
3066 - || urb->status == -ENOENT
3067 - // || (urb->dev == null)
3068 - || ehci->hcd.state == USB_STATE_HALT)
3070 - // FIXME look at all those unlink cases ... we always
3071 - // need exactly one completion that reports unlink.
3072 - // the one above might not have been it!
3075 - /* normally reactivate */
3076 - if (likely (urb != 0)) {
3077 - if (usb_pipeout (urb->pipe))
3078 - pci_dma_sync_single (ehci->hcd.pdev,
3080 - urb->transfer_buffer_length,
3081 - PCI_DMA_TODEVICE);
3082 - urb->status = -EINPROGRESS;
3083 - urb->actual_length = 0;
3084 + if (unlikely (list_empty (&qh->qtd_list)))
3085 + intr_deschedule (ehci, qh, 0);
3087 - /* patch qh and restart */
3088 - qh_update (qh, qtd);
3094 /*-------------------------------------------------------------------------*/
3095 @@ -527,11 +524,6 @@
3097 struct ehci_itd *first_itd = urb->hcpriv;
3099 - pci_unmap_single (ehci->hcd.pdev,
3100 - first_itd->buf_dma, urb->transfer_buffer_length,
3101 - usb_pipein (urb->pipe)
3102 - ? PCI_DMA_FROMDEVICE
3103 - : PCI_DMA_TODEVICE);
3104 while (!list_empty (&first_itd->itd_list)) {
3105 struct ehci_itd *itd;
3109 unsigned i, epnum, maxp, multi;
3113 itd->hw_next = EHCI_LIST_END;
3116 * as encoded in the ep descriptor's maxpacket field
3118 epnum = usb_pipeendpoint (urb->pipe);
3119 - if (usb_pipein (urb->pipe)) {
3120 + is_input = usb_pipein (urb->pipe);
3122 maxp = urb->dev->epmaxpacketin [epnum];
3126 urb->iso_frame_desc [index].length);
3129 - itd->usecs = HS_USECS_ISO (length);
3130 + itd->usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 1, length);
3132 /* "plus" info in low order bits of buffer pointers */
3133 itd->hw_bufp [0] |= cpu_to_le32 ((epnum << 8) | urb->dev->devnum);
3134 @@ -625,16 +619,7 @@
3136 struct ehci_itd *first_itd, *itd;
3138 - dma_addr_t buf_dma, itd_dma;
3140 - /* set up one dma mapping for this urb */
3141 - buf_dma = pci_map_single (ehci->hcd.pdev,
3142 - urb->transfer_buffer, urb->transfer_buffer_length,
3143 - usb_pipein (urb->pipe)
3144 - ? PCI_DMA_FROMDEVICE
3145 - : PCI_DMA_TODEVICE);
3148 + dma_addr_t itd_dma;
3150 /* allocate/init ITDs */
3151 for (frame_index = 0, first_itd = 0;
3153 memset (itd, 0, sizeof *itd);
3154 itd->itd_dma = itd_dma;
3156 - status = itd_fill (ehci, itd, urb, frame_index, buf_dma);
3157 + status = itd_fill (ehci, itd, urb, frame_index,
3158 + urb->transfer_dma);
3164 /* calculate the legal range [start,max) */
3165 now = readl (&ehci->regs->frame_index) + 1; /* next uframe */
3166 - if (!ehci->periodic_urbs)
3167 + if (!ehci->periodic_sched)
3168 now += 8; /* startup delay */
3171 @@ -857,8 +843,12 @@
3172 usb_claim_bandwidth (urb->dev, urb, usecs, 1);
3174 /* maybe enable periodic schedule processing */
3175 - if (!ehci->periodic_urbs++)
3176 - enable_periodic (ehci);
3177 + if (!ehci->periodic_sched++) {
3178 + if ((status = enable_periodic (ehci)) != 0) {
3179 + // FIXME deschedule right away
3180 + err ("itd_schedule, enable = %d", status);
3186 @@ -873,15 +863,14 @@
3188 #define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR)
3190 -static unsigned long
3193 struct ehci_hcd *ehci,
3194 struct ehci_itd *itd,
3196 - unsigned long flags
3199 struct urb *urb = itd->urb;
3200 - iso_packet_descriptor_t *desc;
3201 + struct usb_iso_packet_descriptor *desc;
3204 /* update status for this uframe's transfers */
3207 /* handle completion now? */
3208 if ((itd->index + 1) != urb->number_of_packets)
3213 * Always give the urb back to the driver ... expect it to submit
3214 @@ -931,16 +920,17 @@
3215 if (urb->status == -EINPROGRESS)
3218 - spin_unlock_irqrestore (&ehci->lock, flags);
3219 + /* complete() can reenter this HCD */
3220 + spin_unlock (&ehci->lock);
3221 usb_hcd_giveback_urb (&ehci->hcd, urb);
3222 - spin_lock_irqsave (&ehci->lock, flags);
3223 + spin_lock (&ehci->lock);
3225 /* defer stopping schedule; completion can submit */
3226 - ehci->periodic_urbs--;
3227 - if (!ehci->periodic_urbs)
3228 - disable_periodic (ehci);
3229 + ehci->periodic_sched--;
3230 + if (!ehci->periodic_sched)
3231 + (void) disable_periodic (ehci);
3237 /*-------------------------------------------------------------------------*/
3238 @@ -978,130 +964,21 @@
3240 * "Split ISO TDs" ... used for USB 1.1 devices going through
3241 * the TTs in USB 2.0 hubs.
3243 + * FIXME not yet implemented
3247 -sitd_free (struct ehci_hcd *ehci, struct ehci_sitd *sitd)
3249 - pci_pool_free (ehci->sitd_pool, sitd, sitd->sitd_dma);
3252 -static struct ehci_sitd *
3254 - struct ehci_hcd *ehci,
3256 - unsigned index, // urb->iso_frame_desc [index]
3257 - unsigned uframe, // scheduled start
3258 - dma_addr_t dma, // mapped transfer buffer
3261 - struct ehci_sitd *sitd;
3264 - sitd = pci_pool_alloc (ehci->sitd_pool, mem_flags, &dma);
3268 - length = urb->iso_frame_desc [index].length;
3269 - dma += urb->iso_frame_desc [index].offset;
3272 - // FIXME: do the rest!
3274 - sitd_free (ehci, sitd);
3281 -sitd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
3285 - ptr = cpu_to_le32 (sitd->sitd_dma | 2); // type 2 == sitd
3286 - if (ehci->pshadow [frame].ptr) {
3287 - if (!sitd->sitd_next.ptr) {
3288 - sitd->sitd_next = ehci->pshadow [frame];
3289 - sitd->hw_next = ehci->periodic [frame];
3290 - } else if (sitd->sitd_next.ptr != ehci->pshadow [frame].ptr) {
3291 - dbg ("frame %d sitd link goof", frame);
3295 - ehci->pshadow [frame].sitd = sitd;
3296 - ehci->periodic [frame] = ptr;
3299 -static unsigned long
3301 - struct ehci_hcd *ehci,
3302 - struct ehci_sitd *sitd,
3303 - unsigned long flags
3305 - // FIXME -- implement!
3307 - dbg ("NYI -- sitd_complete");
3311 -/*-------------------------------------------------------------------------*/
3313 -static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags)
3315 - // struct ehci_sitd *first_sitd = 0;
3316 - unsigned frame_index;
3319 - dbg ("NYI -- sitd_submit");
3321 - // FIXME -- implement!
3323 - // FIXME: setup one big dma mapping
3326 - for (frame_index = 0;
3327 - frame_index < urb->number_of_packets;
3329 - struct ehci_sitd *sitd;
3332 - // FIXME: use real arguments, schedule this!
3335 - sitd = sitd_make (ehci, urb, frame_index,
3336 - uframe, dma, mem_flags);
3341 - list_add_tail (&sitd->sitd_list,
3342 - &first_sitd->sitd_list);
3344 - first_sitd = sitd;
3347 - // FIXME: clean everything up
3351 - // if we have a first sitd, then
3352 - // store them all into the periodic schedule!
3353 - // urb->hcpriv = first sitd in sitd_list
3357 #endif /* have_split_iso */
3359 /*-------------------------------------------------------------------------*/
3361 -static void scan_periodic (struct ehci_hcd *ehci)
3363 +scan_periodic (struct ehci_hcd *ehci)
3365 unsigned frame, clock, now_uframe, mod;
3366 - unsigned long flags;
3367 + unsigned count = 0;
3369 mod = ehci->periodic_size << 3;
3370 - spin_lock_irqsave (&ehci->lock, flags);
3373 * When running, scan from last scan point up to "now"
3374 @@ -1122,6 +999,14 @@
3378 + /* keep latencies down: let any irqs in */
3379 + if (count > max_completions) {
3380 + spin_unlock_irq (&ehci->lock);
3383 + spin_lock_irq (&ehci->lock);
3387 /* scan schedule to _before_ current frame index */
3389 @@ -1145,8 +1030,8 @@
3390 last = (q.qh->hw_next == EHCI_LIST_END);
3391 temp = q.qh->qh_next;
3392 type = Q_NEXT_TYPE (q.qh->hw_next);
3393 - flags = intr_complete (ehci, frame,
3394 - qh_get (q.qh), flags);
3395 + count += intr_complete (ehci, frame,
3397 qh_put (ehci, q.qh);
3400 @@ -1178,8 +1063,8 @@
3401 type = Q_NEXT_TYPE (*hw_p);
3403 /* might free q.itd ... */
3404 - flags = itd_complete (ehci,
3405 - temp.itd, uf, flags);
3406 + count += itd_complete (ehci,
3411 @@ -1195,7 +1080,7 @@
3412 #ifdef have_split_iso
3414 last = (q.sitd->hw_next == EHCI_LIST_END);
3415 - flags = sitd_complete (ehci, q.sitd, flags);
3416 + sitd_complete (ehci, q.sitd);
3417 type = Q_NEXT_TYPE (q.sitd->hw_next);
3419 // FIXME unlink SITD after split completes
3420 @@ -1241,5 +1126,4 @@
3422 frame = (frame + 1) % ehci->periodic_size;
3424 - spin_unlock_irqrestore (&ehci->lock, flags);
3426 diff -Nru a/drivers/usb/hcd/ehci.h b/drivers/usb/hcd/ehci.h
3427 --- a/drivers/usb/hcd/ehci.h Mon Oct 21 22:14:31 2002
3428 +++ b/drivers/usb/hcd/ehci.h Mon Oct 21 22:14:31 2002
3431 /* definitions used for the EHCI driver */
3433 +/* statistics can be kept for for tuning/monitoring */
3434 +struct ehci_stats {
3436 + unsigned long normal;
3437 + unsigned long error;
3438 + unsigned long reclaim;
3440 + /* termination of urbs from core */
3441 + unsigned long complete;
3442 + unsigned long unlink;
3444 + /* qhs patched to recover from td queueing race
3445 + * (can avoid by using 'dummy td', allowing fewer irqs)
3447 + unsigned long qpatch;
3450 /* ehci_hcd->lock guards shared data against other CPUs:
3451 * ehci_hcd: async, reclaim, periodic (and shadow), ...
3454 /* async schedule support */
3455 struct ehci_qh *async;
3456 struct ehci_qh *reclaim;
3457 - int reclaim_ready;
3458 + int reclaim_ready : 1,
3461 /* periodic schedule support */
3462 #define DEFAULT_I_TDPS 1024 /* some HCs can do less */
3465 union ehci_shadow *pshadow; /* mirror hw periodic table */
3466 int next_uframe; /* scan periodic, start here */
3467 - unsigned periodic_urbs; /* how many urbs scheduled? */
3468 + unsigned periodic_sched; /* periodic activity count */
3470 /* deferred work from IRQ, etc */
3471 struct tasklet_struct tasklet;
3473 struct pci_pool *qtd_pool; /* one or more per qh */
3474 struct pci_pool *itd_pool; /* itd per iso urb */
3475 struct pci_pool *sitd_pool; /* sitd per split iso urb */
3477 + struct timer_list watchdog;
3480 + struct ehci_stats stats;
3481 +# define COUNT(x) do { (x)++; } while (0)
3483 +# define COUNT(x) do {} while (0)
3487 /* unwrap an HCD pointer to get an EHCI_HCD pointer */
3488 -#define hcd_to_ehci(hcd_ptr) list_entry(hcd_ptr, struct ehci_hcd, hcd)
3489 +#define hcd_to_ehci(hcd_ptr) container_of(hcd_ptr, struct ehci_hcd, hcd)
3491 /* NOTE: urb->transfer_flags expected to not use this bit !!! */
3492 #define EHCI_STATE_UNLINK 0x8000 /* urb being unlinked */
3495 /* dma same in urb's qtds, except 1st control qtd (setup buffer) */
3496 struct urb *urb; /* qtd's urb */
3497 - dma_addr_t buf_dma; /* buffer address */
3498 size_t length; /* length of buffer */
3499 } __attribute__ ((aligned (32)));
3501 @@ -287,15 +313,20 @@
3502 struct list_head qtd_list; /* sw qtd list */
3505 - unsigned short usecs; /* intr bandwidth */
3509 #define QH_STATE_LINKED 1 /* HC sees this */
3510 #define QH_STATE_UNLINK 2 /* HC may still see this */
3511 #define QH_STATE_IDLE 3 /* HC doesn't see this */
3513 -#ifdef EHCI_SOFT_RETRIES
3516 + /* periodic schedule info */
3517 + u8 usecs; /* intr bandwidth */
3518 + u8 gap_uf; /* uframes split/csplit gap */
3519 + u8 c_usecs; /* ... split completion bw */
3520 + unsigned short period; /* polling interval */
3521 + unsigned short start; /* where polling starts */
3522 +#define NO_FRAME ((unsigned short)~0) /* pick new start */
3524 } __attribute__ ((aligned (32)));
3526 /*-------------------------------------------------------------------------*/
3528 union ehci_shadow sitd_next; /* ptr to periodic q entry */
3530 dma_addr_t buf_dma; /* buffer address */
3532 + unsigned short usecs; /* start bandwidth */
3533 + unsigned short c_usecs; /* completion bandwidth */
3534 } __attribute__ ((aligned (32)));
3536 /*-------------------------------------------------------------------------*/
3537 @@ -381,5 +415,40 @@
3538 dma_addr_t fstn_dma;
3539 union ehci_shadow fstn_next; /* ptr to periodic q entry */
3540 } __attribute__ ((aligned (32)));
3542 +/*-------------------------------------------------------------------------*/
3544 +#include <linux/version.h>
3545 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,32)
3547 +#define SUBMIT_URB(urb,mem_flags) usb_submit_urb(urb)
3548 +#define STUB_DEBUG_FILES
3550 +static inline int hcd_register_root (struct usb_hcd *hcd)
3552 + return usb_new_device (hcd_to_bus (hcd)->root_hub);
3555 +#else /* LINUX_VERSION_CODE */
3557 +// hcd_to_bus() eventually moves to hcd.h on 2.5 too
3558 +static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
3559 + { return &hcd->self; }
3560 +// ... as does hcd_register_root()
3561 +static inline int hcd_register_root (struct usb_hcd *hcd)
3563 + return usb_register_root_hub (
3564 + hcd_to_bus (hcd)->root_hub, &hcd->pdev->dev);
3567 +#define SUBMIT_URB(urb,mem_flags) usb_submit_urb(urb,mem_flags)
3570 +#define STUB_DEBUG_FILES
3573 +#endif /* LINUX_VERSION_CODE */
3575 +/*-------------------------------------------------------------------------*/
3577 #endif /* __LINUX_EHCI_HCD_H */
3578 diff -Nru a/drivers/usb/hcd.c b/drivers/usb/hcd.c
3579 --- a/drivers/usb/hcd.c Mon Oct 21 22:14:31 2002
3580 +++ b/drivers/usb/hcd.c Mon Oct 21 22:14:31 2002
3584 } else if (id == 1) {
3585 - strcpy (buf, hcd->bus_name);
3586 + strcpy (buf, hcd->bus->bus_name);
3588 // product description
3589 } else if (id == 2) {
3591 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
3592 // wValue == urb->dev->devaddr
3593 dbg ("%s root hub device address %d",
3594 - hcd->bus_name, wValue);
3595 + hcd->bus->bus_name, wValue);
3598 /* INTERFACE REQUESTS (no defined feature/status flags) */
3600 && rh_status_urb (hcd, urb) != 0) {
3601 /* another driver snuck in? */
3602 dbg ("%s, can't resubmit roothub status urb?",
3604 + hcd->bus->bus_name);
3605 spin_unlock_irqrestore (&hcd_data_lock, flags);
3611 // FIXME simpler: make "bus" be that data, not pointer to it.
3613 bus = usb_alloc_bus (&hcd_operations);
3615 dbg ("usb_alloc_bus fail");
3620 - hcd->bus_name = dev->slot_name;
3621 + bus->bus_name = dev->slot_name;
3622 hcd->product_desc = dev->name;
3623 bus->hcpriv = (void *) hcd;
3625 @@ -739,14 +739,14 @@
3626 hcd = pci_get_drvdata(dev);
3629 - info ("remove: %s, state %x", hcd->bus_name, hcd->state);
3630 + info ("remove: %s, state %x", hcd->bus->bus_name, hcd->state);
3632 if (in_interrupt ()) BUG ();
3634 hub = hcd->bus->root_hub;
3635 hcd->state = USB_STATE_QUIESCING;
3637 - dbg ("%s: roothub graceful disconnect", hcd->bus_name);
3638 + dbg ("%s: roothub graceful disconnect", hcd->bus->bus_name);
3639 usb_disconnect (&hub);
3640 // usb_disconnect (&hcd->bus->root_hub);
3645 hcd = pci_get_drvdata(dev);
3646 - info ("suspend %s to state %d", hcd->bus_name, state);
3647 + info ("suspend %s to state %d", hcd->bus->bus_name, state);
3649 pci_save_state (dev, hcd->pci_state);
3651 @@ -846,12 +846,12 @@
3654 hcd = pci_get_drvdata(dev);
3655 - info ("resume %s", hcd->bus_name);
3656 + info ("resume %s", hcd->bus->bus_name);
3658 /* guard against multiple resumes (APM bug?) */
3659 atomic_inc (&hcd->resume_count);
3660 if (atomic_read (&hcd->resume_count) != 1) {
3661 - err ("concurrent PCI resumes for %s", hcd->bus_name);
3662 + err ("concurrent PCI resumes for %s", hcd->bus->bus_name);
3668 retval = hcd->driver->resume (hcd);
3669 if (!HCD_IS_RUNNING (hcd->state)) {
3670 - dbg ("resume %s failure, retval %d", hcd->bus_name, retval);
3671 + dbg ("resume %s failure, retval %d",
3672 + hcd->bus->bus_name, retval);
3674 // FIXME: recover, reset etc.
3677 list_for_each (urblist, &dev->urb_list) {
3678 urb = list_entry (urblist, struct urb, urb_list);
3679 dbg ("shutdown %s urb %p pipe %x, current status %d",
3680 - hcd->bus_name, urb, urb->pipe, urb->status);
3681 + hcd->bus->bus_name,
3682 + urb, urb->pipe, urb->status);
3683 if (urb->status == -EINPROGRESS)
3684 urb->status = -ESHUTDOWN;
3686 @@ -1186,16 +1186,26 @@
3690 + // NOTE: 2.5 does this if !URB_NO_DMA_MAP transfer flag
3691 + if (usb_pipecontrol (urb->pipe))
3692 + urb->setup_dma = pci_map_single (
3694 + urb->setup_packet,
3695 + sizeof (struct usb_ctrlrequest),
3696 + PCI_DMA_TODEVICE);
3697 + if (urb->transfer_buffer_length != 0)
3698 + urb->transfer_dma = pci_map_single (
3700 + urb->transfer_buffer,
3701 + urb->transfer_buffer_length,
3702 + usb_pipein (urb->pipe)
3703 + ? PCI_DMA_FROMDEVICE
3704 + : PCI_DMA_TODEVICE);
3706 if (urb->dev == hcd->bus->root_hub)
3707 status = rh_urb_enqueue (hcd, urb);
3709 status = hcd->driver->urb_enqueue (hcd, urb, mem_flags);
3710 - /* urb->dev got nulled if hcd called giveback for us
3711 - * NOTE: ref to urb->dev is a race without (2.5) refcounting,
3712 - * unless driver only returns status when it didn't giveback
3714 - if (status && urb->dev)
3719 @@ -1282,25 +1292,25 @@
3723 - /* For non-periodic transfers, any status except -EINPROGRESS means
3724 - * the HCD has already started to unlink this URB from the hardware.
3725 - * In that case, there's no more work to do.
3726 + /* Any status except -EINPROGRESS means the HCD has already started
3727 + * to return this URB to the driver. In that case, there's no
3728 + * more work for us to do.
3730 - * For periodic transfers, this is the only way to trigger unlinking
3731 - * from the hardware. Since we (currently) overload urb->status to
3732 - * tell the driver to unlink, error status might get clobbered ...
3733 - * unless that transfer hasn't yet restarted. One such case is when
3734 - * the URB gets unlinked from its completion handler.
3735 + * There's much magic because of "automagic resubmit" of interrupt
3736 + * transfers, stopped only by explicit unlinking. We won't issue
3737 + * an "it's unlinked" callback more than once, but device drivers
3738 + * can need to retry (SMP, -EAGAIN) an unlink request as well as
3739 + * fake out the "not yet completed" state (set -EINPROGRESS) if
3740 + * unlinking from complete(). Automagic eventually vanishes.
3742 * FIXME use an URB_UNLINKED flag to match URB_TIMEOUT_KILLED
3744 - switch (usb_pipetype (urb->pipe)) {
3745 - case PIPE_CONTROL:
3747 - if (urb->status != -EINPROGRESS) {
3748 + if (urb->status != -EINPROGRESS) {
3749 + if (usb_pipetype (urb->pipe) == PIPE_INTERRUPT)
3758 /* maybe set up to block on completion notification */
3759 @@ -1340,7 +1350,7 @@
3760 && HCD_IS_RUNNING (hcd->state)
3762 dbg ("%s: wait for giveback urb %p",
3763 - hcd->bus_name, urb);
3764 + hcd->bus->bus_name, urb);
3765 wait_for_completion (&splice.done);
3766 } else if ((urb->transfer_flags & USB_ASYNC_UNLINK) && retval == 0) {
3767 return -EINPROGRESS;
3768 @@ -1352,7 +1362,7 @@
3771 dbg ("%s: hcd_unlink_urb fail %d",
3772 - hcd ? hcd->bus_name : "(no bus?)",
3773 + hcd ? hcd->bus->bus_name : "(no bus?)",
3777 @@ -1385,7 +1395,7 @@
3778 /* device driver problem with refcounts? */
3779 if (!list_empty (&dev->urb_list)) {
3780 dbg ("free busy dev, %s devnum %d (bug!)",
3781 - hcd->bus_name, udev->devnum);
3782 + hcd->bus->bus_name, udev->devnum);
3786 @@ -1460,6 +1470,18 @@
3787 dbg ("giveback urb %p status %d len %d",
3788 urb, urb->status, urb->actual_length);
3790 + // NOTE: 2.5 does this if !URB_NO_DMA_MAP transfer flag
3791 + if (usb_pipecontrol (urb->pipe))
3792 + pci_unmap_single (hcd->pdev, urb->setup_dma,
3793 + sizeof (struct usb_ctrlrequest),
3794 + PCI_DMA_TODEVICE);
3795 + if (urb->transfer_buffer_length != 0)
3796 + pci_unmap_single (hcd->pdev, urb->transfer_dma,
3797 + urb->transfer_buffer_length,
3798 + usb_pipein (urb->pipe)
3799 + ? PCI_DMA_FROMDEVICE
3800 + : PCI_DMA_TODEVICE);
3802 /* pass ownership to the completion handler */
3803 urb->complete (urb);
3805 diff -Nru a/drivers/usb/hcd.h b/drivers/usb/hcd.h
3806 --- a/drivers/usb/hcd.h Mon Oct 21 22:14:31 2002
3807 +++ b/drivers/usb/hcd.h Mon Oct 21 22:14:31 2002
3809 struct usb_bus *bus; /* hcd is-a bus */
3810 struct list_head hcd_list;
3812 - const char *bus_name;
3813 const char *product_desc;
3814 const char *description; /* "ehci-hcd" etc */