USB: EHCI: simplify remainder computations
[deliverable/linux.git] / drivers / usb / host / ehci-hcd.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2000-2004 by David Brownell
53bd6a60 3 *
1da177e4
LT
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
1da177e4
LT
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/dmapool.h>
22#include <linux/kernel.h>
23#include <linux/delay.h>
24#include <linux/ioport.h>
25#include <linux/sched.h>
3c04e20e 26#include <linux/vmalloc.h>
1da177e4
LT
27#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/timer.h>
ee4ecb8a 30#include <linux/ktime.h>
1da177e4
LT
31#include <linux/list.h>
32#include <linux/interrupt.h>
1da177e4 33#include <linux/usb.h>
27729aad 34#include <linux/usb/hcd.h>
1da177e4
LT
35#include <linux/moduleparam.h>
36#include <linux/dma-mapping.h>
694cc208 37#include <linux/debugfs.h>
5a0e3ad6 38#include <linux/slab.h>
aa4d8342 39#include <linux/uaccess.h>
1da177e4 40
1da177e4
LT
41#include <asm/byteorder.h>
42#include <asm/io.h>
43#include <asm/irq.h>
44#include <asm/system.h>
45#include <asm/unaligned.h>
1da177e4
LT
46
47/*-------------------------------------------------------------------------*/
48
49/*
50 * EHCI hc_driver implementation ... experimental, incomplete.
51 * Based on the final 1.0 register interface specification.
52 *
53 * USB 2.0 shows up in upcoming www.pcmcia.org technology.
54 * First was PCMCIA, like ISA; then CardBus, which is PCI.
55 * Next comes "CardBay", using USB 2.0 signals.
56 *
57 * Contains additional contributions by Brad Hards, Rory Bolt, and others.
58 * Special thanks to Intel and VIA for providing host controllers to
59 * test this driver on, and Cypress (including In-System Design) for
60 * providing early devices for those host controllers to talk to!
1da177e4
LT
61 */
62
1da177e4
LT
63#define DRIVER_AUTHOR "David Brownell"
64#define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
65
66static const char hcd_name [] = "ehci_hcd";
67
68
9776afc8 69#undef VERBOSE_DEBUG
1da177e4
LT
70#undef EHCI_URB_TRACE
71
72#ifdef DEBUG
73#define EHCI_STATS
74#endif
75
76/* magic numbers that can affect system performance */
77#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
78#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
79#define EHCI_TUNE_RL_TT 0
80#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
81#define EHCI_TUNE_MULT_TT 1
82#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
83
07d29b63 84#define EHCI_IAA_MSECS 10 /* arbitrary */
1da177e4
LT
85#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
86#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
b9638011 87#define EHCI_SHRINK_FRAMES 5 /* async qh unlink delay */
1da177e4
LT
88
89/* Initial IRQ latency: faster than hw default */
90static int log2_irq_thresh = 0; // 0 to 6
91module_param (log2_irq_thresh, int, S_IRUGO);
92MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
93
94/* initial park setting: slower than hw default */
95static unsigned park = 0;
96module_param (park, uint, S_IRUGO);
97MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
98
93f1a47c
DB
99/* for flakey hardware, ignore overcurrent indicators */
100static int ignore_oc = 0;
101module_param (ignore_oc, bool, S_IRUGO);
102MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
103
48f24970
AD
104/* for link power management(LPM) feature */
105static unsigned int hird;
106module_param(hird, int, S_IRUGO);
107MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
108
1da177e4
LT
109#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
110
111/*-------------------------------------------------------------------------*/
112
113#include "ehci.h"
114#include "ehci-dbg.c"
115
116/*-------------------------------------------------------------------------*/
117
bc29847e
AS
118static void
119timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
120{
121 /* Don't override timeouts which shrink or (later) disable
122 * the async ring; just the I/O watchdog. Note that if a
123 * SHRINK were pending, OFF would never be requested.
124 */
125 if (timer_pending(&ehci->watchdog)
126 && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
127 & ehci->actions))
128 return;
129
130 if (!test_and_set_bit(action, &ehci->actions)) {
131 unsigned long t;
132
133 switch (action) {
134 case TIMER_IO_WATCHDOG:
403dbd36
AD
135 if (!ehci->need_io_watchdog)
136 return;
bc29847e
AS
137 t = EHCI_IO_JIFFIES;
138 break;
139 case TIMER_ASYNC_OFF:
140 t = EHCI_ASYNC_JIFFIES;
141 break;
142 /* case TIMER_ASYNC_SHRINK: */
143 default:
144 /* add a jiffie since we synch against the
145 * 8 KHz uframe counter.
146 */
147 t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
148 break;
149 }
150 mod_timer(&ehci->watchdog, t + jiffies);
151 }
152}
153
154/*-------------------------------------------------------------------------*/
155
1da177e4
LT
156/*
157 * handshake - spin reading hc until handshake completes or fails
158 * @ptr: address of hc register to be read
159 * @mask: bits to look at in result of read
160 * @done: value of those bits when handshake succeeds
161 * @usec: timeout in microseconds
162 *
163 * Returns negative errno, or zero on success
164 *
165 * Success happens when the "mask" bits have the specified value (hardware
166 * handshake done). There are two failure modes: "usec" have passed (major
167 * hardware flakeout), or the register reads as all-ones (hardware removed).
168 *
169 * That last failure should_only happen in cases like physical cardbus eject
170 * before driver shutdown. But it also seems to be caused by bugs in cardbus
171 * bridge shutdown: shutting down the bridge before the devices using it.
172 */
083522d7
BH
173static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
174 u32 mask, u32 done, int usec)
1da177e4
LT
175{
176 u32 result;
177
178 do {
083522d7 179 result = ehci_readl(ehci, ptr);
1da177e4
LT
180 if (result == ~(u32)0) /* card removed */
181 return -ENODEV;
182 result &= mask;
183 if (result == done)
184 return 0;
185 udelay (1);
186 usec--;
187 } while (usec > 0);
188 return -ETIMEDOUT;
189}
190
191/* force HC to halt state from unknown (EHCI spec section 2.3) */
192static int ehci_halt (struct ehci_hcd *ehci)
193{
083522d7 194 u32 temp = ehci_readl(ehci, &ehci->regs->status);
1da177e4 195
72f30b6f 196 /* disable any irqs left enabled by previous code */
083522d7 197 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
72f30b6f 198
1da177e4
LT
199 if ((temp & STS_HALT) != 0)
200 return 0;
201
083522d7 202 temp = ehci_readl(ehci, &ehci->regs->command);
1da177e4 203 temp &= ~CMD_RUN;
083522d7
BH
204 ehci_writel(ehci, temp, &ehci->regs->command);
205 return handshake (ehci, &ehci->regs->status,
206 STS_HALT, STS_HALT, 16 * 125);
1da177e4
LT
207}
208
0bcfeb3e
DB
209static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
210 u32 mask, u32 done, int usec)
211{
212 int error;
213
214 error = handshake(ehci, ptr, mask, done, usec);
215 if (error) {
216 ehci_halt(ehci);
217 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
65cb76ba 218 ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n",
0bcfeb3e
DB
219 ptr, mask, done, error);
220 }
221
222 return error;
223}
224
1da177e4
LT
225/* put TDI/ARC silicon into EHCI mode */
226static void tdi_reset (struct ehci_hcd *ehci)
227{
228 u32 __iomem *reg_ptr;
229 u32 tmp;
230
d23a1377 231 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
083522d7 232 tmp = ehci_readl(ehci, reg_ptr);
d23a1377
VB
233 tmp |= USBMODE_CM_HC;
234 /* The default byte access to MMR space is LE after
235 * controller reset. Set the required endian mode
236 * for transfer buffers to match the host microprocessor
237 */
238 if (ehci_big_endian_mmio(ehci))
239 tmp |= USBMODE_BE;
083522d7 240 ehci_writel(ehci, tmp, reg_ptr);
1da177e4
LT
241}
242
243/* reset a non-running (STS_HALT == 1) controller */
244static int ehci_reset (struct ehci_hcd *ehci)
245{
246 int retval;
083522d7 247 u32 command = ehci_readl(ehci, &ehci->regs->command);
1da177e4 248
8d053c79
JW
249 /* If the EHCI debug controller is active, special care must be
250 * taken before and after a host controller reset */
251 if (ehci->debug && !dbgp_reset_prep())
252 ehci->debug = NULL;
253
1da177e4
LT
254 command |= CMD_RESET;
255 dbg_cmd (ehci, "reset", command);
083522d7 256 ehci_writel(ehci, command, &ehci->regs->command);
1da177e4
LT
257 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
258 ehci->next_statechange = jiffies;
083522d7
BH
259 retval = handshake (ehci, &ehci->regs->command,
260 CMD_RESET, 0, 250 * 1000);
1da177e4 261
331ac6b2
AD
262 if (ehci->has_hostpc) {
263 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
264 (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX));
265 ehci_writel(ehci, TXFIFO_DEFAULT,
266 (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
267 }
1da177e4
LT
268 if (retval)
269 return retval;
270
271 if (ehci_is_TDI(ehci))
272 tdi_reset (ehci);
273
8d053c79
JW
274 if (ehci->debug)
275 dbgp_external_startup();
276
1da177e4
LT
277 return retval;
278}
279
280/* idle the controller (from running) */
281static void ehci_quiesce (struct ehci_hcd *ehci)
282{
283 u32 temp;
284
285#ifdef DEBUG
286 if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
287 BUG ();
288#endif
289
290 /* wait for any schedule enables/disables to take effect */
083522d7 291 temp = ehci_readl(ehci, &ehci->regs->command) << 10;
1da177e4 292 temp &= STS_ASS | STS_PSS;
c765d4ca
KW
293 if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
294 STS_ASS | STS_PSS, temp, 16 * 125))
1da177e4 295 return;
1da177e4
LT
296
297 /* then disable anything that's still active */
083522d7 298 temp = ehci_readl(ehci, &ehci->regs->command);
1da177e4 299 temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
083522d7 300 ehci_writel(ehci, temp, &ehci->regs->command);
1da177e4
LT
301
302 /* hardware can take 16 microframes to turn off ... */
c765d4ca
KW
303 handshake_on_error_set_halt(ehci, &ehci->regs->status,
304 STS_ASS | STS_PSS, 0, 16 * 125);
1da177e4
LT
305}
306
307/*-------------------------------------------------------------------------*/
308
07d29b63 309static void end_unlink_async(struct ehci_hcd *ehci);
7d12e780 310static void ehci_work(struct ehci_hcd *ehci);
1da177e4
LT
311
312#include "ehci-hub.c"
48f24970 313#include "ehci-lpm.c"
1da177e4
LT
314#include "ehci-mem.c"
315#include "ehci-q.c"
316#include "ehci-sched.c"
317
318/*-------------------------------------------------------------------------*/
319
07d29b63 320static void ehci_iaa_watchdog(unsigned long param)
1da177e4
LT
321{
322 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
323 unsigned long flags;
324
325 spin_lock_irqsave (&ehci->lock, flags);
326
e82cc128
DB
327 /* Lost IAA irqs wedge things badly; seen first with a vt8235.
328 * So we need this watchdog, but must protect it against both
329 * (a) SMP races against real IAA firing and retriggering, and
330 * (b) clean HC shutdown, when IAA watchdog was pending.
331 */
332 if (ehci->reclaim
333 && !timer_pending(&ehci->iaa_watchdog)
334 && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
335 u32 cmd, status;
336
337 /* If we get here, IAA is *REALLY* late. It's barely
338 * conceivable that the system is so busy that CMD_IAAD
339 * is still legitimately set, so let's be sure it's
340 * clear before we read STS_IAA. (The HC should clear
341 * CMD_IAAD when it sets STS_IAA.)
342 */
343 cmd = ehci_readl(ehci, &ehci->regs->command);
344 if (cmd & CMD_IAAD)
345 ehci_writel(ehci, cmd & ~CMD_IAAD,
346 &ehci->regs->command);
347
348 /* If IAA is set here it either legitimately triggered
349 * before we cleared IAAD above (but _way_ late, so we'll
350 * still count it as lost) ... or a silicon erratum:
351 * - VIA seems to set IAA without triggering the IRQ;
352 * - IAAD potentially cleared without setting IAA.
353 */
354 status = ehci_readl(ehci, &ehci->regs->status);
355 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
1da177e4 356 COUNT (ehci->stats.lost_iaa);
083522d7 357 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
1da177e4 358 }
e82cc128
DB
359
360 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
361 status, cmd);
07d29b63 362 end_unlink_async(ehci);
1da177e4
LT
363 }
364
07d29b63
AS
365 spin_unlock_irqrestore(&ehci->lock, flags);
366}
367
368static void ehci_watchdog(unsigned long param)
369{
370 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
371 unsigned long flags;
372
373 spin_lock_irqsave(&ehci->lock, flags);
374
375 /* stop async processing after it's idled a bit */
1da177e4 376 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
26f953fd 377 start_unlink_async (ehci, ehci->async);
1da177e4
LT
378
379 /* ehci could run by timer, without IRQs ... */
7d12e780 380 ehci_work (ehci);
1da177e4
LT
381
382 spin_unlock_irqrestore (&ehci->lock, flags);
383}
384
8903795a
AS
385/* On some systems, leaving remote wakeup enabled prevents system shutdown.
386 * The firmware seems to think that powering off is a wakeup event!
387 * This routine turns off remote wakeup and everything else, on all ports.
388 */
389static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
390{
391 int port = HCS_N_PORTS(ehci->hcs_params);
392
393 while (port--)
394 ehci_writel(ehci, PORT_RWC_BITS,
395 &ehci->regs->port_status[port]);
396}
397
21da84a8
SS
398/*
399 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
400 * Should be called with ehci->lock held.
72f30b6f 401 */
21da84a8 402static void ehci_silence_controller(struct ehci_hcd *ehci)
1da177e4 403{
21da84a8 404 ehci_halt(ehci);
8903795a 405 ehci_turn_off_all_ports(ehci);
1da177e4
LT
406
407 /* make BIOS/etc use companion controller during reboot */
083522d7 408 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
8903795a
AS
409
410 /* unblock posted writes */
411 ehci_readl(ehci, &ehci->regs->configured_flag);
1da177e4
LT
412}
413
21da84a8
SS
414/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
415 * This forcibly disables dma and IRQs, helping kexec and other cases
416 * where the next system software may expect clean state.
417 */
418static void ehci_shutdown(struct usb_hcd *hcd)
419{
420 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
421
422 del_timer_sync(&ehci->watchdog);
423 del_timer_sync(&ehci->iaa_watchdog);
424
425 spin_lock_irq(&ehci->lock);
426 ehci_silence_controller(ehci);
427 spin_unlock_irq(&ehci->lock);
428}
429
56c1e26d
DB
430static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
431{
432 unsigned port;
433
434 if (!HCS_PPC (ehci->hcs_params))
435 return;
436
437 ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
438 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
439 (void) ehci_hub_control(ehci_to_hcd(ehci),
440 is_on ? SetPortFeature : ClearPortFeature,
441 USB_PORT_FEAT_POWER,
442 port--, NULL, 0);
383975d7
AS
443 /* Flush those writes */
444 ehci_readl(ehci, &ehci->regs->command);
56c1e26d
DB
445 msleep(20);
446}
447
7ff71d6a 448/*-------------------------------------------------------------------------*/
1da177e4 449
7ff71d6a
MP
450/*
451 * ehci_work is called from some interrupts, timers, and so on.
452 * it calls driver completion functions, after dropping ehci->lock.
453 */
7d12e780 454static void ehci_work (struct ehci_hcd *ehci)
7ff71d6a
MP
455{
456 timer_action_done (ehci, TIMER_IO_WATCHDOG);
7ff71d6a
MP
457
458 /* another CPU may drop ehci->lock during a schedule scan while
459 * it reports urb completions. this flag guards against bogus
460 * attempts at re-entrant schedule scanning.
461 */
462 if (ehci->scanning)
463 return;
464 ehci->scanning = 1;
7d12e780 465 scan_async (ehci);
7ff71d6a 466 if (ehci->next_uframe != -1)
7d12e780 467 scan_periodic (ehci);
7ff71d6a
MP
468 ehci->scanning = 0;
469
470 /* the IO watchdog guards against hardware or driver bugs that
471 * misplace IRQs, and should let us run completely without IRQs.
472 * such lossage has been observed on both VT6202 and VT8235.
473 */
474 if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
475 (ehci->async->qh_next.ptr != NULL ||
476 ehci->periodic_sched != 0))
477 timer_action (ehci, TIMER_IO_WATCHDOG);
478}
1da177e4 479
21da84a8
SS
480/*
481 * Called when the ehci_hcd module is removed.
482 */
7ff71d6a 483static void ehci_stop (struct usb_hcd *hcd)
1da177e4
LT
484{
485 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1da177e4 486
7ff71d6a 487 ehci_dbg (ehci, "stop\n");
1da177e4 488
7ff71d6a
MP
489 /* no more interrupts ... */
490 del_timer_sync (&ehci->watchdog);
07d29b63 491 del_timer_sync(&ehci->iaa_watchdog);
56c1e26d 492
7ff71d6a
MP
493 spin_lock_irq(&ehci->lock);
494 if (HC_IS_RUNNING (hcd->state))
495 ehci_quiesce (ehci);
1da177e4 496
21da84a8 497 ehci_silence_controller(ehci);
7ff71d6a 498 ehci_reset (ehci);
7ff71d6a 499 spin_unlock_irq(&ehci->lock);
1da177e4 500
57e06c11 501 remove_companion_file(ehci);
7ff71d6a 502 remove_debug_files (ehci);
1da177e4 503
7ff71d6a
MP
504 /* root hub is shut down separately (first, when possible) */
505 spin_lock_irq (&ehci->lock);
506 if (ehci->async)
7d12e780 507 ehci_work (ehci);
7ff71d6a
MP
508 spin_unlock_irq (&ehci->lock);
509 ehci_mem_cleanup (ehci);
1da177e4 510
7ff71d6a
MP
511#ifdef EHCI_STATS
512 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
513 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
514 ehci->stats.lost_iaa);
515 ehci_dbg (ehci, "complete %ld unlink %ld\n",
516 ehci->stats.complete, ehci->stats.unlink);
1da177e4 517#endif
1da177e4 518
083522d7
BH
519 dbg_status (ehci, "ehci_stop completed",
520 ehci_readl(ehci, &ehci->regs->status));
1da177e4
LT
521}
522
18807521
DB
523/* one-time init, only for memory state */
524static int ehci_init(struct usb_hcd *hcd)
1da177e4 525{
18807521 526 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1da177e4 527 u32 temp;
1da177e4
LT
528 int retval;
529 u32 hcc_params;
3807e26d 530 struct ehci_qh_hw *hw;
18807521
DB
531
532 spin_lock_init(&ehci->lock);
533
403dbd36
AD
534 /*
535 * keep io watchdog by default, those good HCDs could turn off it later
536 */
537 ehci->need_io_watchdog = 1;
18807521
DB
538 init_timer(&ehci->watchdog);
539 ehci->watchdog.function = ehci_watchdog;
540 ehci->watchdog.data = (unsigned long) ehci;
1da177e4 541
07d29b63
AS
542 init_timer(&ehci->iaa_watchdog);
543 ehci->iaa_watchdog.function = ehci_iaa_watchdog;
544 ehci->iaa_watchdog.data = (unsigned long) ehci;
545
1da177e4
LT
546 /*
547 * hw default: 1K periodic list heads, one per frame.
548 * periodic_size can shrink by USBCMD update if hcc_params allows.
549 */
550 ehci->periodic_size = DEFAULT_I_TDPS;
9aa09d2f 551 INIT_LIST_HEAD(&ehci->cached_itd_list);
0e5f231b 552 INIT_LIST_HEAD(&ehci->cached_sitd_list);
18807521 553 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
1da177e4
LT
554 return retval;
555
556 /* controllers may cache some of the periodic schedule ... */
083522d7 557 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
53bd6a60 558 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
dccd574c 559 ehci->i_thresh = 2 + 8;
1da177e4 560 else // N microframes cached
18807521 561 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
1da177e4
LT
562
563 ehci->reclaim = NULL;
1da177e4 564 ehci->next_uframe = -1;
9aa09d2f 565 ehci->clock_frame = -1;
1da177e4 566
1da177e4
LT
567 /*
568 * dedicate a qh for the async ring head, since we couldn't unlink
569 * a 'real' qh without stopping the async schedule [4.8]. use it
570 * as the 'reclamation list head' too.
571 * its dummy is used in hw_alt_next of many tds, to prevent the qh
572 * from automatically advancing to the next td after short reads.
573 */
18807521 574 ehci->async->qh_next.qh = NULL;
3807e26d
AD
575 hw = ehci->async->hw;
576 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
577 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
578 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
579 hw->hw_qtd_next = EHCI_LIST_END(ehci);
18807521 580 ehci->async->qh_state = QH_STATE_LINKED;
3807e26d 581 hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
1da177e4
LT
582
583 /* clear interrupt enables, set irq latency */
584 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
585 log2_irq_thresh = 0;
586 temp = 1 << (16 + log2_irq_thresh);
5a9cdf33
AD
587 if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
588 ehci->has_ppcd = 1;
589 ehci_dbg(ehci, "enable per-port change event\n");
590 temp |= CMD_PPCEE;
591 }
1da177e4
LT
592 if (HCC_CANPARK(hcc_params)) {
593 /* HW default park == 3, on hardware that supports it (like
594 * NVidia and ALI silicon), maximizes throughput on the async
595 * schedule by avoiding QH fetches between transfers.
596 *
597 * With fast usb storage devices and NForce2, "park" seems to
598 * make problems: throughput reduction (!), data errors...
599 */
600 if (park) {
18807521 601 park = min(park, (unsigned) 3);
1da177e4
LT
602 temp |= CMD_PARK;
603 temp |= park << 8;
604 }
18807521 605 ehci_dbg(ehci, "park %d\n", park);
1da177e4 606 }
18807521 607 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
1da177e4
LT
608 /* periodic schedule size can be smaller than default */
609 temp &= ~(3 << 2);
610 temp |= (EHCI_TUNE_FLS << 2);
611 switch (EHCI_TUNE_FLS) {
612 case 0: ehci->periodic_size = 1024; break;
613 case 1: ehci->periodic_size = 512; break;
614 case 2: ehci->periodic_size = 256; break;
18807521 615 default: BUG();
1da177e4
LT
616 }
617 }
48f24970
AD
618 if (HCC_LPM(hcc_params)) {
619 /* support link power management EHCI 1.1 addendum */
620 ehci_dbg(ehci, "support lpm\n");
621 ehci->has_lpm = 1;
622 if (hird > 0xf) {
623 ehci_dbg(ehci, "hird %d invalid, use default 0",
624 hird);
625 hird = 0;
626 }
627 temp |= hird << 24;
628 }
18807521
DB
629 ehci->command = temp;
630
40f8db8f 631 /* Accept arbitrarily long scatter-gather lists */
4307a28e
AR
632 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
633 hcd->self.sg_tablesize = ~0;
18807521
DB
634 return 0;
635}
636
637/* start HC running; it's halted, ehci_init() has been run (once) */
638static int ehci_run (struct usb_hcd *hcd)
639{
640 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
641 int retval;
642 u32 temp;
643 u32 hcc_params;
644
1d619f12 645 hcd->uses_new_polling = 1;
1d619f12 646
18807521
DB
647 /* EHCI spec section 4.1 */
648 if ((retval = ehci_reset(ehci)) != 0) {
18807521
DB
649 ehci_mem_cleanup(ehci);
650 return retval;
651 }
083522d7
BH
652 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
653 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
18807521
DB
654
655 /*
656 * hcc_params controls whether ehci->regs->segment must (!!!)
657 * be used; it constrains QH/ITD/SITD and QTD locations.
658 * pci_pool consistent memory always uses segment zero.
659 * streaming mappings for I/O buffers, like pci_map_single(),
660 * can return segments above 4GB, if the device allows.
661 *
662 * NOTE: the dma mask is visible through dma_supported(), so
663 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
664 * Scsi_Host.highmem_io, and so forth. It's readonly to all
665 * host side drivers though.
666 */
083522d7 667 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
18807521 668 if (HCC_64BIT_ADDR(hcc_params)) {
083522d7 669 ehci_writel(ehci, 0, &ehci->regs->segment);
18807521
DB
670#if 0
671// this is deeply broken on almost all architectures
6a35528a 672 if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
18807521
DB
673 ehci_info(ehci, "enabled 64bit DMA\n");
674#endif
675 }
676
677
1da177e4
LT
678 // Philips, Intel, and maybe others need CMD_RUN before the
679 // root hub will detect new devices (why?); NEC doesn't
18807521
DB
680 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
681 ehci->command |= CMD_RUN;
083522d7 682 ehci_writel(ehci, ehci->command, &ehci->regs->command);
18807521 683 dbg_cmd (ehci, "init", ehci->command);
1da177e4 684
1da177e4
LT
685 /*
686 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
687 * are explicitly handed to companion controller(s), so no TT is
688 * involved with the root hub. (Except where one is integrated,
689 * and there's no companion controller unless maybe for USB OTG.)
32fe0198
AS
690 *
691 * Turning on the CF flag will transfer ownership of all ports
692 * from the companions to the EHCI controller. If any of the
693 * companions are in the middle of a port reset at the time, it
694 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
1cb52658
DB
695 * guarantees that no resets are in progress. After we set CF,
696 * a short delay lets the hardware catch up; new resets shouldn't
697 * be started before the port switching actions could complete.
1da177e4 698 */
32fe0198 699 down_write(&ehci_cf_port_reset_rwsem);
1da177e4 700 hcd->state = HC_STATE_RUNNING;
083522d7
BH
701 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
702 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1cb52658 703 msleep(5);
32fe0198 704 up_write(&ehci_cf_port_reset_rwsem);
ee4ecb8a 705 ehci->last_periodic_enable = ktime_get_real();
1da177e4 706
083522d7 707 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
1da177e4 708 ehci_info (ehci,
2b70f073 709 "USB %x.%x started, EHCI %x.%02x%s\n",
7ff71d6a 710 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
2b70f073 711 temp >> 8, temp & 0xff,
93f1a47c 712 ignore_oc ? ", overcurrent ignored" : "");
1da177e4 713
083522d7
BH
714 ehci_writel(ehci, INTR_MASK,
715 &ehci->regs->intr_enable); /* Turn On Interrupts */
1da177e4 716
18807521
DB
717 /* GRR this is run-once init(), being done every time the HC starts.
718 * So long as they're part of class devices, we can't do it init()
719 * since the class device isn't created that early.
720 */
721 create_debug_files(ehci);
57e06c11 722 create_companion_file(ehci);
1da177e4
LT
723
724 return 0;
725}
726
1da177e4
LT
727/*-------------------------------------------------------------------------*/
728
7d12e780 729static irqreturn_t ehci_irq (struct usb_hcd *hcd)
1da177e4
LT
730{
731 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
67b2e029 732 u32 status, masked_status, pcd_status = 0, cmd;
1da177e4
LT
733 int bh;
734
735 spin_lock (&ehci->lock);
736
083522d7 737 status = ehci_readl(ehci, &ehci->regs->status);
1da177e4
LT
738
739 /* e.g. cardbus physical eject */
740 if (status == ~(u32) 0) {
741 ehci_dbg (ehci, "device removed\n");
742 goto dead;
743 }
744
67b2e029
AS
745 masked_status = status & INTR_MASK;
746 if (!masked_status) { /* irq sharing? */
1da177e4
LT
747 spin_unlock(&ehci->lock);
748 return IRQ_NONE;
749 }
750
751 /* clear (just) interrupts */
67b2e029 752 ehci_writel(ehci, masked_status, &ehci->regs->status);
e82cc128 753 cmd = ehci_readl(ehci, &ehci->regs->command);
1da177e4
LT
754 bh = 0;
755
9776afc8 756#ifdef VERBOSE_DEBUG
1da177e4
LT
757 /* unrequested/ignored: Frame List Rollover */
758 dbg_status (ehci, "irq", status);
759#endif
760
761 /* INT, ERR, and IAA interrupt rates can be throttled */
762
763 /* normal [4.15.1.2] or error [4.15.1.1] completion */
764 if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
765 if (likely ((status & STS_ERR) == 0))
766 COUNT (ehci->stats.normal);
767 else
768 COUNT (ehci->stats.error);
769 bh = 1;
770 }
771
772 /* complete the unlinking of some qh [4.15.2.3] */
773 if (status & STS_IAA) {
e82cc128
DB
774 /* guard against (alleged) silicon errata */
775 if (cmd & CMD_IAAD) {
776 ehci_writel(ehci, cmd & ~CMD_IAAD,
777 &ehci->regs->command);
778 ehci_dbg(ehci, "IAA with IAAD still set?\n");
779 }
780 if (ehci->reclaim) {
781 COUNT(ehci->stats.reclaim);
782 end_unlink_async(ehci);
783 } else
784 ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
1da177e4
LT
785 }
786
787 /* remote wakeup [4.3.1] */
d97cc2f2 788 if (status & STS_PCD) {
1da177e4 789 unsigned i = HCS_N_PORTS (ehci->hcs_params);
5a9cdf33 790 u32 ppcd = 0;
d1b1842c
DB
791
792 /* kick root hub later */
1d619f12 793 pcd_status = status;
1da177e4
LT
794
795 /* resume root hub? */
eafe5b99 796 if (!(cmd & CMD_RUN))
8c03356a 797 usb_hcd_resume_root_hub(hcd);
1da177e4 798
5a9cdf33
AD
799 /* get per-port change detect bits */
800 if (ehci->has_ppcd)
801 ppcd = status >> 16;
802
1da177e4 803 while (i--) {
5a9cdf33
AD
804 int pstatus;
805
806 /* leverage per-port change bits feature */
807 if (ehci->has_ppcd && !(ppcd & (1 << i)))
808 continue;
809 pstatus = ehci_readl(ehci,
810 &ehci->regs->port_status[i]);
b972b68c
DB
811
812 if (pstatus & PORT_OWNER)
1da177e4 813 continue;
eafe5b99
AS
814 if (!(test_bit(i, &ehci->suspended_ports) &&
815 ((pstatus & PORT_RESUME) ||
816 !(pstatus & PORT_SUSPEND)) &&
817 (pstatus & PORT_PE) &&
818 ehci->reset_done[i] == 0))
1da177e4
LT
819 continue;
820
821 /* start 20 msec resume signaling from this port,
822 * and make khubd collect PORT_STAT_C_SUSPEND to
49d0f078
AS
823 * stop that signaling. Use 5 ms extra for safety,
824 * like usb_port_resume() does.
1da177e4 825 */
49d0f078 826 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
1da177e4 827 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
61e8b858 828 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
1da177e4
LT
829 }
830 }
831
832 /* PCI errors [4.15.2.4] */
833 if (unlikely ((status & STS_FATAL) != 0)) {
67b2e029 834 ehci_err(ehci, "fatal error\n");
eafe5b99
AS
835 dbg_cmd(ehci, "fatal", cmd);
836 dbg_status(ehci, "fatal", status);
67b2e029 837 ehci_halt(ehci);
1da177e4 838dead:
67b2e029
AS
839 ehci_reset(ehci);
840 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
841 /* generic layer kills/unlinks all urbs, then
842 * uses ehci_stop to clean up the rest
843 */
844 bh = 1;
1da177e4
LT
845 }
846
847 if (bh)
7d12e780 848 ehci_work (ehci);
1da177e4 849 spin_unlock (&ehci->lock);
d1b1842c 850 if (pcd_status)
1d619f12 851 usb_hcd_poll_rh_status(hcd);
1da177e4
LT
852 return IRQ_HANDLED;
853}
854
855/*-------------------------------------------------------------------------*/
856
857/*
858 * non-error returns are a promise to giveback() the urb later
859 * we drop ownership so next owner (or urb unlink) can get it
860 *
861 * urb + dev is in hcd.self.controller.urb_list
862 * we're queueing TDs onto software and hardware lists
863 *
864 * hcd-specific init for hcpriv hasn't been done yet
865 *
866 * NOTE: control, bulk, and interrupt share the same code to append TDs
867 * to a (possibly active) QH, and the same QH scanning code.
868 */
869static int ehci_urb_enqueue (
870 struct usb_hcd *hcd,
1da177e4 871 struct urb *urb,
55016f10 872 gfp_t mem_flags
1da177e4
LT
873) {
874 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
875 struct list_head qtd_list;
876
877 INIT_LIST_HEAD (&qtd_list);
878
879 switch (usb_pipetype (urb->pipe)) {
25b70a86
DB
880 case PIPE_CONTROL:
881 /* qh_completions() code doesn't handle all the fault cases
882 * in multi-TD control transfers. Even 1KB is rare anyway.
883 */
884 if (urb->transfer_buffer_length > (16 * 1024))
885 return -EMSGSIZE;
886 /* FALLTHROUGH */
887 /* case PIPE_BULK: */
1da177e4
LT
888 default:
889 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
890 return -ENOMEM;
e9df41c5 891 return submit_async(ehci, urb, &qtd_list, mem_flags);
1da177e4
LT
892
893 case PIPE_INTERRUPT:
894 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
895 return -ENOMEM;
e9df41c5 896 return intr_submit(ehci, urb, &qtd_list, mem_flags);
1da177e4
LT
897
898 case PIPE_ISOCHRONOUS:
899 if (urb->dev->speed == USB_SPEED_HIGH)
900 return itd_submit (ehci, urb, mem_flags);
901 else
902 return sitd_submit (ehci, urb, mem_flags);
903 }
904}
905
906static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
907{
07d29b63 908 /* failfast */
e82cc128 909 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
07d29b63
AS
910 end_unlink_async(ehci);
911
3a44494e
AS
912 /* If the QH isn't linked then there's nothing we can do
913 * unless we were called during a giveback, in which case
914 * qh_completions() has to deal with it.
915 */
916 if (qh->qh_state != QH_STATE_LINKED) {
917 if (qh->qh_state == QH_STATE_COMPLETING)
918 qh->needs_rescan = 1;
919 return;
920 }
07d29b63
AS
921
922 /* defer till later if busy */
3a44494e 923 if (ehci->reclaim) {
1da177e4
LT
924 struct ehci_qh *last;
925
926 for (last = ehci->reclaim;
927 last->reclaim;
928 last = last->reclaim)
929 continue;
930 qh->qh_state = QH_STATE_UNLINK_WAIT;
931 last->reclaim = qh;
932
07d29b63
AS
933 /* start IAA cycle */
934 } else
1da177e4
LT
935 start_unlink_async (ehci, qh);
936}
937
938/* remove from hardware lists
939 * completions normally happen asynchronously
940 */
941
e9df41c5 942static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1da177e4
LT
943{
944 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
945 struct ehci_qh *qh;
946 unsigned long flags;
e9df41c5 947 int rc;
1da177e4
LT
948
949 spin_lock_irqsave (&ehci->lock, flags);
e9df41c5
AS
950 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
951 if (rc)
952 goto done;
953
1da177e4
LT
954 switch (usb_pipetype (urb->pipe)) {
955 // case PIPE_CONTROL:
956 // case PIPE_BULK:
957 default:
958 qh = (struct ehci_qh *) urb->hcpriv;
959 if (!qh)
960 break;
07d29b63
AS
961 switch (qh->qh_state) {
962 case QH_STATE_LINKED:
963 case QH_STATE_COMPLETING:
964 unlink_async(ehci, qh);
965 break;
966 case QH_STATE_UNLINK:
967 case QH_STATE_UNLINK_WAIT:
968 /* already started */
969 break;
970 case QH_STATE_IDLE:
7a0f0d95
AS
971 /* QH might be waiting for a Clear-TT-Buffer */
972 qh_completions(ehci, qh);
07d29b63
AS
973 break;
974 }
1da177e4
LT
975 break;
976
977 case PIPE_INTERRUPT:
978 qh = (struct ehci_qh *) urb->hcpriv;
979 if (!qh)
980 break;
981 switch (qh->qh_state) {
982 case QH_STATE_LINKED:
a448c9d8 983 case QH_STATE_COMPLETING:
1da177e4 984 intr_deschedule (ehci, qh);
a448c9d8 985 break;
1da177e4 986 case QH_STATE_IDLE:
7d12e780 987 qh_completions (ehci, qh);
1da177e4
LT
988 break;
989 default:
990 ehci_dbg (ehci, "bogus qh %p state %d\n",
991 qh, qh->qh_state);
992 goto done;
993 }
1da177e4
LT
994 break;
995
996 case PIPE_ISOCHRONOUS:
997 // itd or sitd ...
998
999 // wait till next completion, do it then.
1000 // completion irqs can wait up to 1024 msec,
1001 break;
1002 }
1003done:
1004 spin_unlock_irqrestore (&ehci->lock, flags);
e9df41c5 1005 return rc;
1da177e4
LT
1006}
1007
1008/*-------------------------------------------------------------------------*/
1009
1010// bulk qh holds the data toggle
1011
1012static void
1013ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1014{
1015 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1016 unsigned long flags;
1017 struct ehci_qh *qh, *tmp;
1018
1019 /* ASSERT: any requests/urbs are being unlinked */
1020 /* ASSERT: nobody can be submitting urbs for this any more */
1021
1022rescan:
1023 spin_lock_irqsave (&ehci->lock, flags);
1024 qh = ep->hcpriv;
1025 if (!qh)
1026 goto done;
1027
1028 /* endpoints can be iso streams. for now, we don't
1029 * accelerate iso completions ... so spin a while.
1030 */
1082f57a 1031 if (qh->hw == NULL) {
1da177e4
LT
1032 ehci_vdbg (ehci, "iso delay\n");
1033 goto idle_timeout;
1034 }
1035
1036 if (!HC_IS_RUNNING (hcd->state))
1037 qh->qh_state = QH_STATE_IDLE;
1038 switch (qh->qh_state) {
1039 case QH_STATE_LINKED:
3a44494e 1040 case QH_STATE_COMPLETING:
1da177e4
LT
1041 for (tmp = ehci->async->qh_next.qh;
1042 tmp && tmp != qh;
1043 tmp = tmp->qh_next.qh)
1044 continue;
1045 /* periodic qh self-unlinks on empty */
1046 if (!tmp)
1047 goto nogood;
1048 unlink_async (ehci, qh);
1049 /* FALL THROUGH */
1050 case QH_STATE_UNLINK: /* wait for hw to finish? */
07d29b63 1051 case QH_STATE_UNLINK_WAIT:
1da177e4
LT
1052idle_timeout:
1053 spin_unlock_irqrestore (&ehci->lock, flags);
22c43863 1054 schedule_timeout_uninterruptible(1);
1da177e4
LT
1055 goto rescan;
1056 case QH_STATE_IDLE: /* fully unlinked */
914b7012
AS
1057 if (qh->clearing_tt)
1058 goto idle_timeout;
1da177e4
LT
1059 if (list_empty (&qh->qtd_list)) {
1060 qh_put (qh);
1061 break;
1062 }
1063 /* else FALL THROUGH */
1064 default:
1065nogood:
1066 /* caller was supposed to have unlinked any requests;
1067 * that's not our job. just leak this memory.
1068 */
1069 ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
1070 qh, ep->desc.bEndpointAddress, qh->qh_state,
1071 list_empty (&qh->qtd_list) ? "" : "(has tds)");
1072 break;
1073 }
1074 ep->hcpriv = NULL;
1075done:
1076 spin_unlock_irqrestore (&ehci->lock, flags);
1077 return;
1078}
1079
b18ffd49
AS
1080static void
1081ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1082{
1083 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1084 struct ehci_qh *qh;
1085 int eptype = usb_endpoint_type(&ep->desc);
a455212d
AS
1086 int epnum = usb_endpoint_num(&ep->desc);
1087 int is_out = usb_endpoint_dir_out(&ep->desc);
1088 unsigned long flags;
b18ffd49
AS
1089
1090 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1091 return;
1092
a455212d 1093 spin_lock_irqsave(&ehci->lock, flags);
b18ffd49
AS
1094 qh = ep->hcpriv;
1095
1096 /* For Bulk and Interrupt endpoints we maintain the toggle state
1097 * in the hardware; the toggle bits in udev aren't used at all.
1098 * When an endpoint is reset by usb_clear_halt() we must reset
1099 * the toggle bit in the QH.
1100 */
1101 if (qh) {
a455212d 1102 usb_settoggle(qh->dev, epnum, is_out, 0);
b18ffd49
AS
1103 if (!list_empty(&qh->qtd_list)) {
1104 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
3a44494e
AS
1105 } else if (qh->qh_state == QH_STATE_LINKED ||
1106 qh->qh_state == QH_STATE_COMPLETING) {
a455212d
AS
1107
1108 /* The toggle value in the QH can't be updated
1109 * while the QH is active. Unlink it now;
1110 * re-linking will call qh_refresh().
b18ffd49 1111 */
a448c9d8 1112 if (eptype == USB_ENDPOINT_XFER_BULK)
a455212d 1113 unlink_async(ehci, qh);
a448c9d8 1114 else
a455212d 1115 intr_deschedule(ehci, qh);
b18ffd49
AS
1116 }
1117 }
a455212d 1118 spin_unlock_irqrestore(&ehci->lock, flags);
b18ffd49
AS
1119}
1120
7ff71d6a
MP
1121static int ehci_get_frame (struct usb_hcd *hcd)
1122{
1123 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
083522d7
BH
1124 return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
1125 ehci->periodic_size;
7ff71d6a 1126}
1da177e4
LT
1127
1128/*-------------------------------------------------------------------------*/
1129
2b70f073 1130MODULE_DESCRIPTION(DRIVER_DESC);
1da177e4
LT
1131MODULE_AUTHOR (DRIVER_AUTHOR);
1132MODULE_LICENSE ("GPL");
1133
7ff71d6a
MP
1134#ifdef CONFIG_PCI
1135#include "ehci-pci.c"
01cced25 1136#define PCI_DRIVER ehci_pci_driver
7ff71d6a 1137#endif
1da177e4 1138
ba02978a 1139#ifdef CONFIG_USB_EHCI_FSL
80cb9aee 1140#include "ehci-fsl.c"
01cced25 1141#define PLATFORM_DRIVER ehci_fsl_driver
80cb9aee
RV
1142#endif
1143
7e8d5cd9
DM
1144#ifdef CONFIG_USB_EHCI_MXC
1145#include "ehci-mxc.c"
1146#define PLATFORM_DRIVER ehci_mxc_driver
1147#endif
1148
dfbaa7d8 1149#ifdef CONFIG_SOC_AU1200
76fa9a24 1150#include "ehci-au1xxx.c"
01cced25 1151#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
76fa9a24
JC
1152#endif
1153
a8eb7ca0 1154#ifdef CONFIG_ARCH_OMAP3
54ab2b02
FB
1155#include "ehci-omap.c"
1156#define PLATFORM_DRIVER ehci_hcd_omap_driver
1157#endif
1158
ad75a410
GL
1159#ifdef CONFIG_PPC_PS3
1160#include "ehci-ps3.c"
7a4eb7fd 1161#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
ad75a410
GL
1162#endif
1163
da0e8fb0
VB
1164#ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1165#include "ehci-ppc-of.c"
1166#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1167#endif
1168
08d3c18e
JZ
1169#ifdef CONFIG_XPS_USB_HCD_XILINX
1170#include "ehci-xilinx-of.c"
1f23b2d9 1171#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
08d3c18e
JZ
1172#endif
1173
705a7521 1174#ifdef CONFIG_PLAT_ORION
e96ffe2f
TP
1175#include "ehci-orion.c"
1176#define PLATFORM_DRIVER ehci_orion_driver
1177#endif
1178
91bc4d31
VB
1179#ifdef CONFIG_ARCH_IXP4XX
1180#include "ehci-ixp4xx.c"
1181#define PLATFORM_DRIVER ixp4xx_ehci_driver
1182#endif
1183
586dfc8c
WZ
1184#ifdef CONFIG_USB_W90X900_EHCI
1185#include "ehci-w90x900.c"
1186#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1187#endif
1188
501c9c08
NF
1189#ifdef CONFIG_ARCH_AT91
1190#include "ehci-atmel.c"
1191#define PLATFORM_DRIVER ehci_atmel_driver
1192#endif
1193
ad75a410 1194#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
1f23b2d9
GL
1195 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1196 !defined(XILINX_OF_PLATFORM_DRIVER)
7ff71d6a
MP
1197#error "missing bus glue for ehci-hcd"
1198#endif
01cced25
KG
1199
1200static int __init ehci_hcd_init(void)
1201{
1202 int retval = 0;
1203
2b70f073
AS
1204 if (usb_disabled())
1205 return -ENODEV;
1206
1207 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
9beeee65
AS
1208 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1209 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
1210 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
1211 printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
1212 " before uhci_hcd and ohci_hcd, not after\n");
1213
01cced25
KG
1214 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1215 hcd_name,
1216 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
1217 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
1218
694cc208 1219#ifdef DEBUG
08f4e586 1220 ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
9beeee65
AS
1221 if (!ehci_debug_root) {
1222 retval = -ENOENT;
1223 goto err_debug;
1224 }
694cc208
TJ
1225#endif
1226
01cced25
KG
1227#ifdef PLATFORM_DRIVER
1228 retval = platform_driver_register(&PLATFORM_DRIVER);
da0e8fb0
VB
1229 if (retval < 0)
1230 goto clean0;
01cced25
KG
1231#endif
1232
1233#ifdef PCI_DRIVER
1234 retval = pci_register_driver(&PCI_DRIVER);
da0e8fb0
VB
1235 if (retval < 0)
1236 goto clean1;
ad75a410
GL
1237#endif
1238
1239#ifdef PS3_SYSTEM_BUS_DRIVER
7a4eb7fd 1240 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
da0e8fb0
VB
1241 if (retval < 0)
1242 goto clean2;
694cc208 1243#endif
da0e8fb0
VB
1244
1245#ifdef OF_PLATFORM_DRIVER
1246 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1247 if (retval < 0)
1248 goto clean3;
1249#endif
1f23b2d9
GL
1250
1251#ifdef XILINX_OF_PLATFORM_DRIVER
1252 retval = of_register_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
1253 if (retval < 0)
1254 goto clean4;
1255#endif
da0e8fb0
VB
1256 return retval;
1257
1f23b2d9
GL
1258#ifdef XILINX_OF_PLATFORM_DRIVER
1259 /* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */
1260clean4:
1261#endif
da0e8fb0 1262#ifdef OF_PLATFORM_DRIVER
1f23b2d9 1263 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
da0e8fb0
VB
1264clean3:
1265#endif
1266#ifdef PS3_SYSTEM_BUS_DRIVER
1267 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1268clean2:
ad75a410
GL
1269#endif
1270#ifdef PCI_DRIVER
da0e8fb0
VB
1271 pci_unregister_driver(&PCI_DRIVER);
1272clean1:
ad75a410 1273#endif
da0e8fb0
VB
1274#ifdef PLATFORM_DRIVER
1275 platform_driver_unregister(&PLATFORM_DRIVER);
1276clean0:
1277#endif
1278#ifdef DEBUG
1279 debugfs_remove(ehci_debug_root);
1280 ehci_debug_root = NULL;
9beeee65 1281err_debug:
a9b6148d 1282#endif
9beeee65 1283 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
01cced25
KG
1284 return retval;
1285}
1286module_init(ehci_hcd_init);
1287
1288static void __exit ehci_hcd_cleanup(void)
1289{
1f23b2d9
GL
1290#ifdef XILINX_OF_PLATFORM_DRIVER
1291 of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
1292#endif
da0e8fb0
VB
1293#ifdef OF_PLATFORM_DRIVER
1294 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1295#endif
01cced25
KG
1296#ifdef PLATFORM_DRIVER
1297 platform_driver_unregister(&PLATFORM_DRIVER);
1298#endif
1299#ifdef PCI_DRIVER
1300 pci_unregister_driver(&PCI_DRIVER);
1301#endif
ad75a410 1302#ifdef PS3_SYSTEM_BUS_DRIVER
7a4eb7fd 1303 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
ad75a410 1304#endif
694cc208
TJ
1305#ifdef DEBUG
1306 debugfs_remove(ehci_debug_root);
1307#endif
9beeee65 1308 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
01cced25
KG
1309}
1310module_exit(ehci_hcd_cleanup);
1311
This page took 0.712856 seconds and 5 git commands to generate.