blob: 2e704fa3cedfb70a6e88e8f48d2994c86a889bff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2004 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#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>
Ming Lei3c04e202008-09-18 23:06:21 +080026#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/timer.h>
Oliver Neukumee4ecb82009-11-27 15:17:59 +010030#include <linux/ktime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/list.h>
32#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/usb.h>
Eric Lescouet27729aa2010-04-24 23:21:52 +020034#include <linux/usb/hcd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/moduleparam.h>
36#include <linux/dma-mapping.h>
Tony Jones694cc202007-09-11 14:07:31 -070037#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Alek Duaa4d8342010-06-04 15:47:54 +080039#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/byteorder.h>
42#include <asm/io.h>
43#include <asm/irq.h>
44#include <asm/system.h>
45#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
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!
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#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
David Brownell9776afc2008-02-01 11:42:05 -080069#undef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#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
Alan Stern07d29b62007-12-11 16:05:30 -050084#define EHCI_IAA_MSECS 10 /* arbitrary */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
86#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
David Brownellb9638012008-06-03 22:21:55 -070087#define EHCI_SHRINK_FRAMES 5 /* async qh unlink delay */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
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
David Brownell93f1a472006-11-16 23:34:58 -080099/* 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
Alek Du48f24972010-06-04 15:47:55 +0800104/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#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
Alan Sternbc298472009-02-11 14:26:38 -0500118static 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:
Alek Du403dbd32009-07-13 17:30:41 +0800135 if (!ehci->need_io_watchdog)
136 return;
Alan Sternbc298472009-02-11 14:26:38 -0500137 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/*
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 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100173static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
174 u32 mask, u32 done, int usec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 u32 result;
177
178 do {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100179 result = ehci_readl(ehci, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 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{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100194 u32 temp = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
David Brownell72f30b62005-09-27 10:19:39 -0700196 /* disable any irqs left enabled by previous code */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100197 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
David Brownell72f30b62005-09-27 10:19:39 -0700198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if ((temp & STS_HALT) != 0)
200 return 0;
201
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100202 temp = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 temp &= ~CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100204 ehci_writel(ehci, temp, &ehci->regs->command);
205 return handshake (ehci, &ehci->regs->status,
206 STS_HALT, STS_HALT, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
David Brownell0bcfeb32008-08-26 14:43:46 -0700209static 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;
Ozan Çağlayan65cb76b2009-10-13 08:37:09 +0300218 ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n",
David Brownell0bcfeb32008-08-26 14:43:46 -0700219 ptr, mask, done, error);
220 }
221
222 return error;
223}
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225/* 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
Vladimir Barinovd23a1372007-05-23 20:07:48 +0400231 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100232 tmp = ehci_readl(ehci, reg_ptr);
Vladimir Barinovd23a1372007-05-23 20:07:48 +0400233 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;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100240 ehci_writel(ehci, tmp, reg_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
243/* reset a non-running (STS_HALT == 1) controller */
244static int ehci_reset (struct ehci_hcd *ehci)
245{
246 int retval;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100247 u32 command = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Jason Wessel8d053c72009-08-20 15:39:54 -0500249 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 command |= CMD_RESET;
255 dbg_cmd (ehci, "reset", command);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100256 ehci_writel(ehci, command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
258 ehci->next_statechange = jiffies;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100259 retval = handshake (ehci, &ehci->regs->command,
260 CMD_RESET, 0, 250 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Alek Du331ac6b2009-07-13 12:41:20 +0800262 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (retval)
269 return retval;
270
271 if (ehci_is_TDI(ehci))
272 tdi_reset (ehci);
273
Jason Wessel8d053c72009-08-20 15:39:54 -0500274 if (ehci->debug)
275 dbgp_external_startup();
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 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 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100291 temp = ehci_readl(ehci, &ehci->regs->command) << 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 temp &= STS_ASS | STS_PSS;
Karsten Wiesec765d4c2008-02-16 13:44:42 -0800293 if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
294 STS_ASS | STS_PSS, temp, 16 * 125))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* then disable anything that's still active */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100298 temp = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100300 ehci_writel(ehci, temp, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 /* hardware can take 16 microframes to turn off ... */
Karsten Wiesec765d4c2008-02-16 13:44:42 -0800303 handshake_on_error_set_halt(ehci, &ehci->regs->status,
304 STS_ASS | STS_PSS, 0, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
307/*-------------------------------------------------------------------------*/
308
Alan Stern07d29b62007-12-11 16:05:30 -0500309static void end_unlink_async(struct ehci_hcd *ehci);
David Howells7d12e782006-10-05 14:55:46 +0100310static void ehci_work(struct ehci_hcd *ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312#include "ehci-hub.c"
Alek Du48f24972010-06-04 15:47:55 +0800313#include "ehci-lpm.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#include "ehci-mem.c"
315#include "ehci-q.c"
316#include "ehci-sched.c"
317
318/*-------------------------------------------------------------------------*/
319
Alan Stern07d29b62007-12-11 16:05:30 -0500320static void ehci_iaa_watchdog(unsigned long param)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
323 unsigned long flags;
324
325 spin_lock_irqsave (&ehci->lock, flags);
326
David Brownelle82cc122008-03-07 13:49:42 -0800327 /* 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;
Alan Stern07d29b62007-12-11 16:05:30 -0500336
David Brownelle82cc122008-03-07 13:49:42 -0800337 /* 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)) {
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700356 COUNT (ehci->stats.lost_iaa);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100357 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700358 }
David Brownelle82cc122008-03-07 13:49:42 -0800359
360 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
361 status, cmd);
Alan Stern07d29b62007-12-11 16:05:30 -0500362 end_unlink_async(ehci);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700363 }
364
Alan Stern07d29b62007-12-11 16:05:30 -0500365 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
David Brownell26f953f2006-09-18 17:03:16 -0700377 start_unlink_async (ehci, ehci->async);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 /* ehci could run by timer, without IRQs ... */
David Howells7d12e782006-10-05 14:55:46 +0100380 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 spin_unlock_irqrestore (&ehci->lock, flags);
383}
384
Alan Stern89037952007-02-13 14:55:27 -0500385/* 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
Sarah Sharp21da84a2008-04-08 14:30:18 -0700398/*
399 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
400 * Should be called with ehci->lock held.
David Brownell72f30b62005-09-27 10:19:39 -0700401 */
Sarah Sharp21da84a2008-04-08 14:30:18 -0700402static void ehci_silence_controller(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Sarah Sharp21da84a2008-04-08 14:30:18 -0700404 ehci_halt(ehci);
Alan Stern89037952007-02-13 14:55:27 -0500405 ehci_turn_off_all_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 /* make BIOS/etc use companion controller during reboot */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100408 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
Alan Stern89037952007-02-13 14:55:27 -0500409
410 /* unblock posted writes */
411 ehci_readl(ehci, &ehci->regs->configured_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Sarah Sharp21da84a2008-04-08 14:30:18 -0700414/* 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
David Brownell56c1e262005-04-09 09:00:29 -0700430static 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);
Alan Stern383975d2007-05-04 11:52:40 -0400443 /* Flush those writes */
444 ehci_readl(ehci, &ehci->regs->command);
David Brownell56c1e262005-04-09 09:00:29 -0700445 msleep(20);
446}
447
Matt Porter7ff71d62005-09-22 22:31:15 -0700448/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Matt Porter7ff71d62005-09-22 22:31:15 -0700450/*
451 * ehci_work is called from some interrupts, timers, and so on.
452 * it calls driver completion functions, after dropping ehci->lock.
453 */
David Howells7d12e782006-10-05 14:55:46 +0100454static void ehci_work (struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Matt Porter7ff71d62005-09-22 22:31:15 -0700456 timer_action_done (ehci, TIMER_IO_WATCHDOG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Matt Porter7ff71d62005-09-22 22:31:15 -0700458 /* 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;
David Howells7d12e782006-10-05 14:55:46 +0100465 scan_async (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700466 if (ehci->next_uframe != -1)
David Howells7d12e782006-10-05 14:55:46 +0100467 scan_periodic (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700468 ehci->scanning = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Matt Porter7ff71d62005-09-22 22:31:15 -0700470 /* 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Sarah Sharp21da84a2008-04-08 14:30:18 -0700480/*
481 * Called when the ehci_hcd module is removed.
482 */
Matt Porter7ff71d62005-09-22 22:31:15 -0700483static void ehci_stop (struct usb_hcd *hcd)
484{
485 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
486
487 ehci_dbg (ehci, "stop\n");
488
Matt Porter7ff71d62005-09-22 22:31:15 -0700489 /* no more interrupts ... */
490 del_timer_sync (&ehci->watchdog);
Alan Stern07d29b62007-12-11 16:05:30 -0500491 del_timer_sync(&ehci->iaa_watchdog);
Matt Porter7ff71d62005-09-22 22:31:15 -0700492
493 spin_lock_irq(&ehci->lock);
494 if (HC_IS_RUNNING (hcd->state))
495 ehci_quiesce (ehci);
496
Sarah Sharp21da84a2008-04-08 14:30:18 -0700497 ehci_silence_controller(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700498 ehci_reset (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700499 spin_unlock_irq(&ehci->lock);
500
Alan Stern57e06c12007-01-16 11:59:45 -0500501 remove_companion_file(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700502 remove_debug_files (ehci);
503
504 /* root hub is shut down separately (first, when possible) */
505 spin_lock_irq (&ehci->lock);
506 if (ehci->async)
David Howells7d12e782006-10-05 14:55:46 +0100507 ehci_work (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700508 spin_unlock_irq (&ehci->lock);
509 ehci_mem_cleanup (ehci);
510
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);
517#endif
518
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100519 dbg_status (ehci, "ehci_stop completed",
520 ehci_readl(ehci, &ehci->regs->status));
Matt Porter7ff71d62005-09-22 22:31:15 -0700521}
522
David Brownell18807522005-11-23 15:45:37 -0800523/* one-time init, only for memory state */
524static int ehci_init(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
David Brownell18807522005-11-23 15:45:37 -0800526 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 int retval;
529 u32 hcc_params;
Alek Du3807e262009-07-14 07:23:29 +0800530 struct ehci_qh_hw *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
David Brownell18807522005-11-23 15:45:37 -0800532 spin_lock_init(&ehci->lock);
533
Alek Du403dbd32009-07-13 17:30:41 +0800534 /*
535 * keep io watchdog by default, those good HCDs could turn off it later
536 */
537 ehci->need_io_watchdog = 1;
David Brownell18807522005-11-23 15:45:37 -0800538 init_timer(&ehci->watchdog);
539 ehci->watchdog.function = ehci_watchdog;
540 ehci->watchdog.data = (unsigned long) ehci;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Alan Stern07d29b62007-12-11 16:05:30 -0500542 init_timer(&ehci->iaa_watchdog);
543 ehci->iaa_watchdog.function = ehci_iaa_watchdog;
544 ehci->iaa_watchdog.data = (unsigned long) ehci;
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 /*
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;
Karsten Wiese9aa09d22009-02-08 16:07:58 -0800551 INIT_LIST_HEAD(&ehci->cached_itd_list);
Alan Stern0e5f2312010-04-08 16:56:37 -0400552 INIT_LIST_HEAD(&ehci->cached_sitd_list);
David Brownell18807522005-11-23 15:45:37 -0800553 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 return retval;
555
556 /* controllers may cache some of the periodic schedule ... */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100557 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell53bd6a62006-08-30 14:50:06 -0700558 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
Sarah Sharpdccd5742009-10-27 10:55:05 -0700559 ehci->i_thresh = 2 + 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 else // N microframes cached
David Brownell18807522005-11-23 15:45:37 -0800561 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 ehci->reclaim = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 ehci->next_uframe = -1;
Karsten Wiese9aa09d22009-02-08 16:07:58 -0800565 ehci->clock_frame = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 /*
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 */
David Brownell18807522005-11-23 15:45:37 -0800574 ehci->async->qh_next.qh = NULL;
Alek Du3807e262009-07-14 07:23:29 +0800575 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);
David Brownell18807522005-11-23 15:45:37 -0800580 ehci->async->qh_state = QH_STATE_LINKED;
Alek Du3807e262009-07-14 07:23:29 +0800581 hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
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);
Alek Du5a9cdf32010-06-04 15:47:56 +0800587 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 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) {
David Brownell18807522005-11-23 15:45:37 -0800601 park = min(park, (unsigned) 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 temp |= CMD_PARK;
603 temp |= park << 8;
604 }
David Brownell18807522005-11-23 15:45:37 -0800605 ehci_dbg(ehci, "park %d\n", park);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
David Brownell18807522005-11-23 15:45:37 -0800607 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /* 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;
David Brownell18807522005-11-23 15:45:37 -0800615 default: BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
617 }
Alek Du48f24972010-06-04 15:47:55 +0800618 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 }
David Brownell18807522005-11-23 15:45:37 -0800629 ehci->command = temp;
630
Alan Stern40f8db82009-11-06 12:29:40 -0500631 /* Accept arbitrarily long scatter-gather lists */
Andrea Righi4307a282010-06-28 16:56:45 +0200632 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
633 hcd->self.sg_tablesize = ~0;
David Brownell18807522005-11-23 15:45:37 -0800634 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
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200645 hcd->uses_new_polling = 1;
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200646
David Brownell18807522005-11-23 15:45:37 -0800647 /* EHCI spec section 4.1 */
648 if ((retval = ehci_reset(ehci)) != 0) {
David Brownell18807522005-11-23 15:45:37 -0800649 ehci_mem_cleanup(ehci);
650 return retval;
651 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100652 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
653 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
David Brownell18807522005-11-23 15:45:37 -0800654
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 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100667 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell18807522005-11-23 15:45:37 -0800668 if (HCC_64BIT_ADDR(hcc_params)) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100669 ehci_writel(ehci, 0, &ehci->regs->segment);
David Brownell18807522005-11-23 15:45:37 -0800670#if 0
671// this is deeply broken on almost all architectures
Yang Hongyang6a355282009-04-06 19:01:13 -0700672 if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
David Brownell18807522005-11-23 15:45:37 -0800673 ehci_info(ehci, "enabled 64bit DMA\n");
674#endif
675 }
676
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 // Philips, Intel, and maybe others need CMD_RUN before the
679 // root hub will detect new devices (why?); NEC doesn't
David Brownell18807522005-11-23 15:45:37 -0800680 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
681 ehci->command |= CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100682 ehci_writel(ehci, ehci->command, &ehci->regs->command);
David Brownell18807522005-11-23 15:45:37 -0800683 dbg_cmd (ehci, "init", ehci->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /*
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.)
Alan Stern32fe0192007-10-10 16:27:07 -0400690 *
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
David Brownell1cb52652007-11-13 16:22:30 -0800695 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 */
Alan Stern32fe0192007-10-10 16:27:07 -0400699 down_write(&ehci_cf_port_reset_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 hcd->state = HC_STATE_RUNNING;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100701 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
702 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
David Brownell1cb52652007-11-13 16:22:30 -0800703 msleep(5);
Alan Stern32fe0192007-10-10 16:27:07 -0400704 up_write(&ehci_cf_port_reset_rwsem);
Oliver Neukumee4ecb82009-11-27 15:17:59 +0100705 ehci->last_periodic_enable = ktime_get_real();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100707 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 ehci_info (ehci,
Alan Stern2b70f072008-10-02 11:47:15 -0400709 "USB %x.%x started, EHCI %x.%02x%s\n",
Matt Porter7ff71d62005-09-22 22:31:15 -0700710 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
Alan Stern2b70f072008-10-02 11:47:15 -0400711 temp >> 8, temp & 0xff,
David Brownell93f1a472006-11-16 23:34:58 -0800712 ignore_oc ? ", overcurrent ignored" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100714 ehci_writel(ehci, INTR_MASK,
715 &ehci->regs->intr_enable); /* Turn On Interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
David Brownell18807522005-11-23 15:45:37 -0800717 /* 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);
Alan Stern57e06c12007-01-16 11:59:45 -0500722 create_companion_file(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 return 0;
725}
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727/*-------------------------------------------------------------------------*/
728
David Howells7d12e782006-10-05 14:55:46 +0100729static irqreturn_t ehci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Alan Stern67b2e022008-11-12 17:04:53 -0500732 u32 status, masked_status, pcd_status = 0, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 int bh;
734
735 spin_lock (&ehci->lock);
736
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100737 status = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 /* e.g. cardbus physical eject */
740 if (status == ~(u32) 0) {
741 ehci_dbg (ehci, "device removed\n");
742 goto dead;
743 }
744
Alan Stern67b2e022008-11-12 17:04:53 -0500745 masked_status = status & INTR_MASK;
746 if (!masked_status) { /* irq sharing? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 spin_unlock(&ehci->lock);
748 return IRQ_NONE;
749 }
750
751 /* clear (just) interrupts */
Alan Stern67b2e022008-11-12 17:04:53 -0500752 ehci_writel(ehci, masked_status, &ehci->regs->status);
David Brownelle82cc122008-03-07 13:49:42 -0800753 cmd = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 bh = 0;
755
David Brownell9776afc2008-02-01 11:42:05 -0800756#ifdef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 /* 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) {
David Brownelle82cc122008-03-07 13:49:42 -0800774 /* 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
786
787 /* remote wakeup [4.3.1] */
David Brownelld97cc2f2005-12-22 17:05:18 -0800788 if (status & STS_PCD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 unsigned i = HCS_N_PORTS (ehci->hcs_params);
Alek Du5a9cdf32010-06-04 15:47:56 +0800790 u32 ppcd = 0;
David Brownelld1b18422008-03-05 23:37:52 -0800791
792 /* kick root hub later */
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200793 pcd_status = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 /* resume root hub? */
Alan Sterneafe5b92008-10-06 11:25:53 -0400796 if (!(cmd & CMD_RUN))
Alan Stern8c033562006-11-09 14:42:16 -0500797 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Alek Du5a9cdf32010-06-04 15:47:56 +0800799 /* get per-port change detect bits */
800 if (ehci->has_ppcd)
801 ppcd = status >> 16;
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 while (i--) {
Alek Du5a9cdf32010-06-04 15:47:56 +0800804 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]);
David Brownellb972b682006-06-30 02:34:42 -0700811
812 if (pstatus & PORT_OWNER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 continue;
Alan Sterneafe5b92008-10-06 11:25:53 -0400814 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))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 continue;
820
821 /* start 20 msec resume signaling from this port,
822 * and make khubd collect PORT_STAT_C_SUSPEND to
Alan Stern49d0f072010-01-08 11:18:38 -0500823 * stop that signaling. Use 5 ms extra for safety,
824 * like usb_port_resume() does.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 */
Alan Stern49d0f072010-01-08 11:18:38 -0500826 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
Alan Stern61e8b852007-04-09 11:52:31 -0400828 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 }
830 }
831
832 /* PCI errors [4.15.2.4] */
833 if (unlikely ((status & STS_FATAL) != 0)) {
Alan Stern67b2e022008-11-12 17:04:53 -0500834 ehci_err(ehci, "fatal error\n");
Alan Sterneafe5b92008-10-06 11:25:53 -0400835 dbg_cmd(ehci, "fatal", cmd);
836 dbg_status(ehci, "fatal", status);
Alan Stern67b2e022008-11-12 17:04:53 -0500837 ehci_halt(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838dead:
Alan Stern67b2e022008-11-12 17:04:53 -0500839 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846
847 if (bh)
David Howells7d12e782006-10-05 14:55:46 +0100848 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 spin_unlock (&ehci->lock);
David Brownelld1b18422008-03-05 23:37:52 -0800850 if (pcd_status)
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200851 usb_hcd_poll_rh_status(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400872 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873) {
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)) {
David Brownell25b70a82008-03-04 15:11:07 -0800880 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: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 default:
889 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
890 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400891 return submit_async(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 case PIPE_INTERRUPT:
894 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
895 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400896 return intr_submit(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
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{
Alan Stern07d29b62007-12-11 16:05:30 -0500908 /* failfast */
David Brownelle82cc122008-03-07 13:49:42 -0800909 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
Alan Stern07d29b62007-12-11 16:05:30 -0500910 end_unlink_async(ehci);
911
Alan Stern3a444942009-08-19 12:22:06 -0400912 /* 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 }
Alan Stern07d29b62007-12-11 16:05:30 -0500921
922 /* defer till later if busy */
Alan Stern3a444942009-08-19 12:22:06 -0400923 if (ehci->reclaim) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 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
Alan Stern07d29b62007-12-11 16:05:30 -0500933 /* start IAA cycle */
934 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 start_unlink_async (ehci, qh);
936}
937
938/* remove from hardware lists
939 * completions normally happen asynchronously
940 */
941
Alan Sterne9df41c2007-08-08 11:48:02 -0400942static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
944 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
945 struct ehci_qh *qh;
946 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400947 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949 spin_lock_irqsave (&ehci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400950 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
951 if (rc)
952 goto done;
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 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;
Alan Stern07d29b62007-12-11 16:05:30 -0500961 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:
Alan Stern7a0f0d92009-07-31 10:40:22 -0400971 /* QH might be waiting for a Clear-TT-Buffer */
972 qh_completions(ehci, qh);
Alan Stern07d29b62007-12-11 16:05:30 -0500973 break;
974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 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:
Alan Sterna448c9d2009-08-19 12:22:44 -0400983 case QH_STATE_COMPLETING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 intr_deschedule (ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -0400985 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 case QH_STATE_IDLE:
David Howells7d12e782006-10-05 14:55:46 +0100987 qh_completions (ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 break;
989 default:
990 ehci_dbg (ehci, "bogus qh %p state %d\n",
991 qh, qh->qh_state);
992 goto done;
993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 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);
Alan Sterne9df41c2007-08-08 11:48:02 -04001005 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
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 */
Clemens Ladisch1082f572010-03-01 17:18:56 +01001031 if (qh->hw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 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:
Alan Stern3a444942009-08-19 12:22:06 -04001040 case QH_STATE_COMPLETING:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 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? */
Alan Stern07d29b62007-12-11 16:05:30 -05001051 case QH_STATE_UNLINK_WAIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052idle_timeout:
1053 spin_unlock_irqrestore (&ehci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -07001054 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 goto rescan;
1056 case QH_STATE_IDLE: /* fully unlinked */
Alan Stern914b7012009-06-29 10:47:30 -04001057 if (qh->clearing_tt)
1058 goto idle_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 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
Alan Sternb18ffd42009-05-27 18:21:56 -04001080static 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);
Alan Sterna455212d2009-06-11 14:56:22 -04001086 int epnum = usb_endpoint_num(&ep->desc);
1087 int is_out = usb_endpoint_dir_out(&ep->desc);
1088 unsigned long flags;
Alan Sternb18ffd42009-05-27 18:21:56 -04001089
1090 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1091 return;
1092
Alan Sterna455212d2009-06-11 14:56:22 -04001093 spin_lock_irqsave(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001094 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) {
Alan Sterna455212d2009-06-11 14:56:22 -04001102 usb_settoggle(qh->dev, epnum, is_out, 0);
Alan Sternb18ffd42009-05-27 18:21:56 -04001103 if (!list_empty(&qh->qtd_list)) {
1104 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
Alan Stern3a444942009-08-19 12:22:06 -04001105 } else if (qh->qh_state == QH_STATE_LINKED ||
1106 qh->qh_state == QH_STATE_COMPLETING) {
Alan Sterna455212d2009-06-11 14:56:22 -04001107
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().
Alan Sternb18ffd42009-05-27 18:21:56 -04001111 */
Alan Sterna448c9d2009-08-19 12:22:44 -04001112 if (eptype == USB_ENDPOINT_XFER_BULK)
Alan Sterna455212d2009-06-11 14:56:22 -04001113 unlink_async(ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -04001114 else
Alan Sterna455212d2009-06-11 14:56:22 -04001115 intr_deschedule(ehci, qh);
Alan Sternb18ffd42009-05-27 18:21:56 -04001116 }
1117 }
Alan Sterna455212d2009-06-11 14:56:22 -04001118 spin_unlock_irqrestore(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001119}
1120
Matt Porter7ff71d62005-09-22 22:31:15 -07001121static int ehci_get_frame (struct usb_hcd *hcd)
1122{
1123 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001124 return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
1125 ehci->periodic_size;
Matt Porter7ff71d62005-09-22 22:31:15 -07001126}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128/*-------------------------------------------------------------------------*/
1129
Alan Stern2b70f072008-10-02 11:47:15 -04001130MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131MODULE_AUTHOR (DRIVER_AUTHOR);
1132MODULE_LICENSE ("GPL");
1133
Matt Porter7ff71d62005-09-22 22:31:15 -07001134#ifdef CONFIG_PCI
1135#include "ehci-pci.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001136#define PCI_DRIVER ehci_pci_driver
Matt Porter7ff71d62005-09-22 22:31:15 -07001137#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Li Yangba029782007-05-11 17:09:55 +08001139#ifdef CONFIG_USB_EHCI_FSL
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001140#include "ehci-fsl.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001141#define PLATFORM_DRIVER ehci_fsl_driver
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001142#endif
1143
Daniel Mack7e8d5cd2009-10-28 01:14:59 +01001144#ifdef CONFIG_USB_EHCI_MXC
1145#include "ehci-mxc.c"
1146#define PLATFORM_DRIVER ehci_mxc_driver
1147#endif
1148
Ralf Baechledfbaa7d2006-06-03 23:58:55 +01001149#ifdef CONFIG_SOC_AU1200
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001150#include "ehci-au1xxx.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001151#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001152#endif
1153
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001154#ifdef CONFIG_ARCH_OMAP3
Felipe Balbi54ab2b02009-10-14 11:44:14 +03001155#include "ehci-omap.c"
1156#define PLATFORM_DRIVER ehci_hcd_omap_driver
1157#endif
1158
Geoff Levandad75a412007-01-15 20:11:47 -08001159#ifdef CONFIG_PPC_PS3
1160#include "ehci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001161#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
Geoff Levandad75a412007-01-15 20:11:47 -08001162#endif
1163
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001164#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
Julie Zhu08d3c182009-09-21 16:08:19 -06001169#ifdef CONFIG_XPS_USB_HCD_XILINX
1170#include "ehci-xilinx-of.c"
Grant Likely1f23b2d2010-06-02 13:53:17 -06001171#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
Julie Zhu08d3c182009-09-21 16:08:19 -06001172#endif
1173
Lennert Buytenhek705a7522008-03-27 14:51:40 -04001174#ifdef CONFIG_PLAT_ORION
Tzachi Perelsteine96ffe22007-12-01 11:07:04 -05001175#include "ehci-orion.c"
1176#define PLATFORM_DRIVER ehci_orion_driver
1177#endif
1178
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08001179#ifdef CONFIG_ARCH_IXP4XX
1180#include "ehci-ixp4xx.c"
1181#define PLATFORM_DRIVER ixp4xx_ehci_driver
1182#endif
1183
Wan ZongShun586dfc82009-06-13 09:14:28 +08001184#ifdef CONFIG_USB_W90X900_EHCI
1185#include "ehci-w90x900.c"
1186#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1187#endif
1188
Nicolas Ferre501c9c02009-07-27 14:47:40 -07001189#ifdef CONFIG_ARCH_AT91
1190#include "ehci-atmel.c"
1191#define PLATFORM_DRIVER ehci_atmel_driver
1192#endif
1193
Geoff Levandad75a412007-01-15 20:11:47 -08001194#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
Grant Likely1f23b2d2010-06-02 13:53:17 -06001195 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1196 !defined(XILINX_OF_PLATFORM_DRIVER)
Matt Porter7ff71d62005-09-22 22:31:15 -07001197#error "missing bus glue for ehci-hcd"
1198#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001199
1200static int __init ehci_hcd_init(void)
1201{
1202 int retval = 0;
1203
Alan Stern2b70f072008-10-02 11:47:15 -04001204 if (usb_disabled())
1205 return -ENODEV;
1206
1207 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Alan Stern9beeee62008-10-02 11:48:13 -04001208 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
Kumar Gala01cced22006-04-11 10:07:16 -05001214 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
Tony Jones694cc202007-09-11 14:07:31 -07001219#ifdef DEBUG
Greg Kroah-Hartman08f4e582009-04-24 15:13:18 -07001220 ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
Alan Stern9beeee62008-10-02 11:48:13 -04001221 if (!ehci_debug_root) {
1222 retval = -ENOENT;
1223 goto err_debug;
1224 }
Tony Jones694cc202007-09-11 14:07:31 -07001225#endif
1226
Kumar Gala01cced22006-04-11 10:07:16 -05001227#ifdef PLATFORM_DRIVER
1228 retval = platform_driver_register(&PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001229 if (retval < 0)
1230 goto clean0;
Kumar Gala01cced22006-04-11 10:07:16 -05001231#endif
1232
1233#ifdef PCI_DRIVER
1234 retval = pci_register_driver(&PCI_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001235 if (retval < 0)
1236 goto clean1;
Geoff Levandad75a412007-01-15 20:11:47 -08001237#endif
1238
1239#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001240 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001241 if (retval < 0)
1242 goto clean2;
Kumar Gala01cced22006-04-11 10:07:16 -05001243#endif
1244
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001245#ifdef OF_PLATFORM_DRIVER
1246 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1247 if (retval < 0)
1248 goto clean3;
1249#endif
Grant Likely1f23b2d2010-06-02 13:53:17 -06001250
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
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001256 return retval;
1257
Grant Likely1f23b2d2010-06-02 13:53:17 -06001258#ifdef XILINX_OF_PLATFORM_DRIVER
1259 /* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */
1260clean4:
1261#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001262#ifdef OF_PLATFORM_DRIVER
Grant Likely1f23b2d2010-06-02 13:53:17 -06001263 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001264clean3:
1265#endif
1266#ifdef PS3_SYSTEM_BUS_DRIVER
1267 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1268clean2:
1269#endif
1270#ifdef PCI_DRIVER
1271 pci_unregister_driver(&PCI_DRIVER);
1272clean1:
1273#endif
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;
Alan Stern9beeee62008-10-02 11:48:13 -04001281err_debug:
Linus Torvaldsa9b61482008-10-20 14:23:29 -07001282#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001283 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001284 return retval;
1285}
1286module_init(ehci_hcd_init);
1287
1288static void __exit ehci_hcd_cleanup(void)
1289{
Grant Likely1f23b2d2010-06-02 13:53:17 -06001290#ifdef XILINX_OF_PLATFORM_DRIVER
1291 of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
1292#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001293#ifdef OF_PLATFORM_DRIVER
1294 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1295#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001296#ifdef PLATFORM_DRIVER
1297 platform_driver_unregister(&PLATFORM_DRIVER);
1298#endif
1299#ifdef PCI_DRIVER
1300 pci_unregister_driver(&PCI_DRIVER);
1301#endif
Geoff Levandad75a412007-01-15 20:11:47 -08001302#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001303 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -08001304#endif
Tony Jones694cc202007-09-11 14:07:31 -07001305#ifdef DEBUG
1306 debugfs_remove(ehci_debug_root);
1307#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001308 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001309}
1310module_exit(ehci_hcd_cleanup);
1311