blob: baf9b648bb1f4c464d2f89d65d9297d9979a1bd3 [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);
587 if (HCC_CANPARK(hcc_params)) {
588 /* HW default park == 3, on hardware that supports it (like
589 * NVidia and ALI silicon), maximizes throughput on the async
590 * schedule by avoiding QH fetches between transfers.
591 *
592 * With fast usb storage devices and NForce2, "park" seems to
593 * make problems: throughput reduction (!), data errors...
594 */
595 if (park) {
David Brownell18807522005-11-23 15:45:37 -0800596 park = min(park, (unsigned) 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 temp |= CMD_PARK;
598 temp |= park << 8;
599 }
David Brownell18807522005-11-23 15:45:37 -0800600 ehci_dbg(ehci, "park %d\n", park);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
David Brownell18807522005-11-23 15:45:37 -0800602 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 /* periodic schedule size can be smaller than default */
604 temp &= ~(3 << 2);
605 temp |= (EHCI_TUNE_FLS << 2);
606 switch (EHCI_TUNE_FLS) {
607 case 0: ehci->periodic_size = 1024; break;
608 case 1: ehci->periodic_size = 512; break;
609 case 2: ehci->periodic_size = 256; break;
David Brownell18807522005-11-23 15:45:37 -0800610 default: BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612 }
Alek Du48f24972010-06-04 15:47:55 +0800613 if (HCC_LPM(hcc_params)) {
614 /* support link power management EHCI 1.1 addendum */
615 ehci_dbg(ehci, "support lpm\n");
616 ehci->has_lpm = 1;
617 if (hird > 0xf) {
618 ehci_dbg(ehci, "hird %d invalid, use default 0",
619 hird);
620 hird = 0;
621 }
622 temp |= hird << 24;
623 }
David Brownell18807522005-11-23 15:45:37 -0800624 ehci->command = temp;
625
Alan Stern40f8db82009-11-06 12:29:40 -0500626 /* Accept arbitrarily long scatter-gather lists */
627 hcd->self.sg_tablesize = ~0;
David Brownell18807522005-11-23 15:45:37 -0800628 return 0;
629}
630
631/* start HC running; it's halted, ehci_init() has been run (once) */
632static int ehci_run (struct usb_hcd *hcd)
633{
634 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
635 int retval;
636 u32 temp;
637 u32 hcc_params;
638
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200639 hcd->uses_new_polling = 1;
640 hcd->poll_rh = 0;
641
David Brownell18807522005-11-23 15:45:37 -0800642 /* EHCI spec section 4.1 */
643 if ((retval = ehci_reset(ehci)) != 0) {
David Brownell18807522005-11-23 15:45:37 -0800644 ehci_mem_cleanup(ehci);
645 return retval;
646 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100647 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
648 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
David Brownell18807522005-11-23 15:45:37 -0800649
650 /*
651 * hcc_params controls whether ehci->regs->segment must (!!!)
652 * be used; it constrains QH/ITD/SITD and QTD locations.
653 * pci_pool consistent memory always uses segment zero.
654 * streaming mappings for I/O buffers, like pci_map_single(),
655 * can return segments above 4GB, if the device allows.
656 *
657 * NOTE: the dma mask is visible through dma_supported(), so
658 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
659 * Scsi_Host.highmem_io, and so forth. It's readonly to all
660 * host side drivers though.
661 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100662 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell18807522005-11-23 15:45:37 -0800663 if (HCC_64BIT_ADDR(hcc_params)) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100664 ehci_writel(ehci, 0, &ehci->regs->segment);
David Brownell18807522005-11-23 15:45:37 -0800665#if 0
666// this is deeply broken on almost all architectures
Yang Hongyang6a355282009-04-06 19:01:13 -0700667 if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
David Brownell18807522005-11-23 15:45:37 -0800668 ehci_info(ehci, "enabled 64bit DMA\n");
669#endif
670 }
671
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 // Philips, Intel, and maybe others need CMD_RUN before the
674 // root hub will detect new devices (why?); NEC doesn't
David Brownell18807522005-11-23 15:45:37 -0800675 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
676 ehci->command |= CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100677 ehci_writel(ehci, ehci->command, &ehci->regs->command);
David Brownell18807522005-11-23 15:45:37 -0800678 dbg_cmd (ehci, "init", ehci->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /*
681 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
682 * are explicitly handed to companion controller(s), so no TT is
683 * involved with the root hub. (Except where one is integrated,
684 * and there's no companion controller unless maybe for USB OTG.)
Alan Stern32fe0192007-10-10 16:27:07 -0400685 *
686 * Turning on the CF flag will transfer ownership of all ports
687 * from the companions to the EHCI controller. If any of the
688 * companions are in the middle of a port reset at the time, it
689 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
David Brownell1cb52652007-11-13 16:22:30 -0800690 * guarantees that no resets are in progress. After we set CF,
691 * a short delay lets the hardware catch up; new resets shouldn't
692 * be started before the port switching actions could complete.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 */
Alan Stern32fe0192007-10-10 16:27:07 -0400694 down_write(&ehci_cf_port_reset_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 hcd->state = HC_STATE_RUNNING;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100696 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
697 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
David Brownell1cb52652007-11-13 16:22:30 -0800698 msleep(5);
Alan Stern32fe0192007-10-10 16:27:07 -0400699 up_write(&ehci_cf_port_reset_rwsem);
Oliver Neukumee4ecb82009-11-27 15:17:59 +0100700 ehci->last_periodic_enable = ktime_get_real();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100702 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 ehci_info (ehci,
Alan Stern2b70f072008-10-02 11:47:15 -0400704 "USB %x.%x started, EHCI %x.%02x%s\n",
Matt Porter7ff71d62005-09-22 22:31:15 -0700705 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
Alan Stern2b70f072008-10-02 11:47:15 -0400706 temp >> 8, temp & 0xff,
David Brownell93f1a472006-11-16 23:34:58 -0800707 ignore_oc ? ", overcurrent ignored" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100709 ehci_writel(ehci, INTR_MASK,
710 &ehci->regs->intr_enable); /* Turn On Interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
David Brownell18807522005-11-23 15:45:37 -0800712 /* GRR this is run-once init(), being done every time the HC starts.
713 * So long as they're part of class devices, we can't do it init()
714 * since the class device isn't created that early.
715 */
716 create_debug_files(ehci);
Alan Stern57e06c12007-01-16 11:59:45 -0500717 create_companion_file(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 return 0;
720}
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722/*-------------------------------------------------------------------------*/
723
David Howells7d12e782006-10-05 14:55:46 +0100724static irqreturn_t ehci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Alan Stern67b2e022008-11-12 17:04:53 -0500727 u32 status, masked_status, pcd_status = 0, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 int bh;
729
730 spin_lock (&ehci->lock);
731
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100732 status = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 /* e.g. cardbus physical eject */
735 if (status == ~(u32) 0) {
736 ehci_dbg (ehci, "device removed\n");
737 goto dead;
738 }
739
Alan Stern67b2e022008-11-12 17:04:53 -0500740 masked_status = status & INTR_MASK;
741 if (!masked_status) { /* irq sharing? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 spin_unlock(&ehci->lock);
743 return IRQ_NONE;
744 }
745
746 /* clear (just) interrupts */
Alan Stern67b2e022008-11-12 17:04:53 -0500747 ehci_writel(ehci, masked_status, &ehci->regs->status);
David Brownelle82cc122008-03-07 13:49:42 -0800748 cmd = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 bh = 0;
750
David Brownell9776afc2008-02-01 11:42:05 -0800751#ifdef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /* unrequested/ignored: Frame List Rollover */
753 dbg_status (ehci, "irq", status);
754#endif
755
756 /* INT, ERR, and IAA interrupt rates can be throttled */
757
758 /* normal [4.15.1.2] or error [4.15.1.1] completion */
759 if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
760 if (likely ((status & STS_ERR) == 0))
761 COUNT (ehci->stats.normal);
762 else
763 COUNT (ehci->stats.error);
764 bh = 1;
765 }
766
767 /* complete the unlinking of some qh [4.15.2.3] */
768 if (status & STS_IAA) {
David Brownelle82cc122008-03-07 13:49:42 -0800769 /* guard against (alleged) silicon errata */
770 if (cmd & CMD_IAAD) {
771 ehci_writel(ehci, cmd & ~CMD_IAAD,
772 &ehci->regs->command);
773 ehci_dbg(ehci, "IAA with IAAD still set?\n");
774 }
775 if (ehci->reclaim) {
776 COUNT(ehci->stats.reclaim);
777 end_unlink_async(ehci);
778 } else
779 ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 }
781
782 /* remote wakeup [4.3.1] */
David Brownelld97cc2f2005-12-22 17:05:18 -0800783 if (status & STS_PCD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 unsigned i = HCS_N_PORTS (ehci->hcs_params);
David Brownelld1b18422008-03-05 23:37:52 -0800785
786 /* kick root hub later */
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200787 pcd_status = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 /* resume root hub? */
Alan Sterneafe5b92008-10-06 11:25:53 -0400790 if (!(cmd & CMD_RUN))
Alan Stern8c033562006-11-09 14:42:16 -0500791 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100794 int pstatus = ehci_readl(ehci,
795 &ehci->regs->port_status [i]);
David Brownellb972b682006-06-30 02:34:42 -0700796
797 if (pstatus & PORT_OWNER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 continue;
Alan Sterneafe5b92008-10-06 11:25:53 -0400799 if (!(test_bit(i, &ehci->suspended_ports) &&
800 ((pstatus & PORT_RESUME) ||
801 !(pstatus & PORT_SUSPEND)) &&
802 (pstatus & PORT_PE) &&
803 ehci->reset_done[i] == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 continue;
805
806 /* start 20 msec resume signaling from this port,
807 * and make khubd collect PORT_STAT_C_SUSPEND to
Alan Stern49d0f072010-01-08 11:18:38 -0500808 * stop that signaling. Use 5 ms extra for safety,
809 * like usb_port_resume() does.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
Alan Stern49d0f072010-01-08 11:18:38 -0500811 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
Alan Stern61e8b852007-04-09 11:52:31 -0400813 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815 }
816
817 /* PCI errors [4.15.2.4] */
818 if (unlikely ((status & STS_FATAL) != 0)) {
Alan Stern67b2e022008-11-12 17:04:53 -0500819 ehci_err(ehci, "fatal error\n");
Alan Sterneafe5b92008-10-06 11:25:53 -0400820 dbg_cmd(ehci, "fatal", cmd);
821 dbg_status(ehci, "fatal", status);
Alan Stern67b2e022008-11-12 17:04:53 -0500822 ehci_halt(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823dead:
Alan Stern67b2e022008-11-12 17:04:53 -0500824 ehci_reset(ehci);
825 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
826 /* generic layer kills/unlinks all urbs, then
827 * uses ehci_stop to clean up the rest
828 */
829 bh = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
831
832 if (bh)
David Howells7d12e782006-10-05 14:55:46 +0100833 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 spin_unlock (&ehci->lock);
David Brownelld1b18422008-03-05 23:37:52 -0800835 if (pcd_status)
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200836 usb_hcd_poll_rh_status(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return IRQ_HANDLED;
838}
839
840/*-------------------------------------------------------------------------*/
841
842/*
843 * non-error returns are a promise to giveback() the urb later
844 * we drop ownership so next owner (or urb unlink) can get it
845 *
846 * urb + dev is in hcd.self.controller.urb_list
847 * we're queueing TDs onto software and hardware lists
848 *
849 * hcd-specific init for hcpriv hasn't been done yet
850 *
851 * NOTE: control, bulk, and interrupt share the same code to append TDs
852 * to a (possibly active) QH, and the same QH scanning code.
853 */
854static int ehci_urb_enqueue (
855 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400857 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858) {
859 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
860 struct list_head qtd_list;
861
862 INIT_LIST_HEAD (&qtd_list);
863
864 switch (usb_pipetype (urb->pipe)) {
David Brownell25b70a82008-03-04 15:11:07 -0800865 case PIPE_CONTROL:
866 /* qh_completions() code doesn't handle all the fault cases
867 * in multi-TD control transfers. Even 1KB is rare anyway.
868 */
869 if (urb->transfer_buffer_length > (16 * 1024))
870 return -EMSGSIZE;
871 /* FALLTHROUGH */
872 /* case PIPE_BULK: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 default:
874 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
875 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400876 return submit_async(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 case PIPE_INTERRUPT:
879 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
880 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400881 return intr_submit(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 case PIPE_ISOCHRONOUS:
884 if (urb->dev->speed == USB_SPEED_HIGH)
885 return itd_submit (ehci, urb, mem_flags);
886 else
887 return sitd_submit (ehci, urb, mem_flags);
888 }
889}
890
891static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
892{
Alan Stern07d29b62007-12-11 16:05:30 -0500893 /* failfast */
David Brownelle82cc122008-03-07 13:49:42 -0800894 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
Alan Stern07d29b62007-12-11 16:05:30 -0500895 end_unlink_async(ehci);
896
Alan Stern3a444942009-08-19 12:22:06 -0400897 /* If the QH isn't linked then there's nothing we can do
898 * unless we were called during a giveback, in which case
899 * qh_completions() has to deal with it.
900 */
901 if (qh->qh_state != QH_STATE_LINKED) {
902 if (qh->qh_state == QH_STATE_COMPLETING)
903 qh->needs_rescan = 1;
904 return;
905 }
Alan Stern07d29b62007-12-11 16:05:30 -0500906
907 /* defer till later if busy */
Alan Stern3a444942009-08-19 12:22:06 -0400908 if (ehci->reclaim) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 struct ehci_qh *last;
910
911 for (last = ehci->reclaim;
912 last->reclaim;
913 last = last->reclaim)
914 continue;
915 qh->qh_state = QH_STATE_UNLINK_WAIT;
916 last->reclaim = qh;
917
Alan Stern07d29b62007-12-11 16:05:30 -0500918 /* start IAA cycle */
919 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 start_unlink_async (ehci, qh);
921}
922
923/* remove from hardware lists
924 * completions normally happen asynchronously
925 */
926
Alan Sterne9df41c2007-08-08 11:48:02 -0400927static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
929 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
930 struct ehci_qh *qh;
931 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400932 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 spin_lock_irqsave (&ehci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400935 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
936 if (rc)
937 goto done;
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 switch (usb_pipetype (urb->pipe)) {
940 // case PIPE_CONTROL:
941 // case PIPE_BULK:
942 default:
943 qh = (struct ehci_qh *) urb->hcpriv;
944 if (!qh)
945 break;
Alan Stern07d29b62007-12-11 16:05:30 -0500946 switch (qh->qh_state) {
947 case QH_STATE_LINKED:
948 case QH_STATE_COMPLETING:
949 unlink_async(ehci, qh);
950 break;
951 case QH_STATE_UNLINK:
952 case QH_STATE_UNLINK_WAIT:
953 /* already started */
954 break;
955 case QH_STATE_IDLE:
Alan Stern7a0f0d92009-07-31 10:40:22 -0400956 /* QH might be waiting for a Clear-TT-Buffer */
957 qh_completions(ehci, qh);
Alan Stern07d29b62007-12-11 16:05:30 -0500958 break;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 break;
961
962 case PIPE_INTERRUPT:
963 qh = (struct ehci_qh *) urb->hcpriv;
964 if (!qh)
965 break;
966 switch (qh->qh_state) {
967 case QH_STATE_LINKED:
Alan Sterna448c9d2009-08-19 12:22:44 -0400968 case QH_STATE_COMPLETING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 intr_deschedule (ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -0400970 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 case QH_STATE_IDLE:
David Howells7d12e782006-10-05 14:55:46 +0100972 qh_completions (ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 break;
974 default:
975 ehci_dbg (ehci, "bogus qh %p state %d\n",
976 qh, qh->qh_state);
977 goto done;
978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 break;
980
981 case PIPE_ISOCHRONOUS:
982 // itd or sitd ...
983
984 // wait till next completion, do it then.
985 // completion irqs can wait up to 1024 msec,
986 break;
987 }
988done:
989 spin_unlock_irqrestore (&ehci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400990 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
993/*-------------------------------------------------------------------------*/
994
995// bulk qh holds the data toggle
996
997static void
998ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
999{
1000 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1001 unsigned long flags;
1002 struct ehci_qh *qh, *tmp;
1003
1004 /* ASSERT: any requests/urbs are being unlinked */
1005 /* ASSERT: nobody can be submitting urbs for this any more */
1006
1007rescan:
1008 spin_lock_irqsave (&ehci->lock, flags);
1009 qh = ep->hcpriv;
1010 if (!qh)
1011 goto done;
1012
1013 /* endpoints can be iso streams. for now, we don't
1014 * accelerate iso completions ... so spin a while.
1015 */
Clemens Ladisch1082f572010-03-01 17:18:56 +01001016 if (qh->hw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 ehci_vdbg (ehci, "iso delay\n");
1018 goto idle_timeout;
1019 }
1020
1021 if (!HC_IS_RUNNING (hcd->state))
1022 qh->qh_state = QH_STATE_IDLE;
1023 switch (qh->qh_state) {
1024 case QH_STATE_LINKED:
Alan Stern3a444942009-08-19 12:22:06 -04001025 case QH_STATE_COMPLETING:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 for (tmp = ehci->async->qh_next.qh;
1027 tmp && tmp != qh;
1028 tmp = tmp->qh_next.qh)
1029 continue;
1030 /* periodic qh self-unlinks on empty */
1031 if (!tmp)
1032 goto nogood;
1033 unlink_async (ehci, qh);
1034 /* FALL THROUGH */
1035 case QH_STATE_UNLINK: /* wait for hw to finish? */
Alan Stern07d29b62007-12-11 16:05:30 -05001036 case QH_STATE_UNLINK_WAIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037idle_timeout:
1038 spin_unlock_irqrestore (&ehci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -07001039 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 goto rescan;
1041 case QH_STATE_IDLE: /* fully unlinked */
Alan Stern914b7012009-06-29 10:47:30 -04001042 if (qh->clearing_tt)
1043 goto idle_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (list_empty (&qh->qtd_list)) {
1045 qh_put (qh);
1046 break;
1047 }
1048 /* else FALL THROUGH */
1049 default:
1050nogood:
1051 /* caller was supposed to have unlinked any requests;
1052 * that's not our job. just leak this memory.
1053 */
1054 ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
1055 qh, ep->desc.bEndpointAddress, qh->qh_state,
1056 list_empty (&qh->qtd_list) ? "" : "(has tds)");
1057 break;
1058 }
1059 ep->hcpriv = NULL;
1060done:
1061 spin_unlock_irqrestore (&ehci->lock, flags);
1062 return;
1063}
1064
Alan Sternb18ffd42009-05-27 18:21:56 -04001065static void
1066ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1067{
1068 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1069 struct ehci_qh *qh;
1070 int eptype = usb_endpoint_type(&ep->desc);
Alan Sterna455212d2009-06-11 14:56:22 -04001071 int epnum = usb_endpoint_num(&ep->desc);
1072 int is_out = usb_endpoint_dir_out(&ep->desc);
1073 unsigned long flags;
Alan Sternb18ffd42009-05-27 18:21:56 -04001074
1075 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1076 return;
1077
Alan Sterna455212d2009-06-11 14:56:22 -04001078 spin_lock_irqsave(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001079 qh = ep->hcpriv;
1080
1081 /* For Bulk and Interrupt endpoints we maintain the toggle state
1082 * in the hardware; the toggle bits in udev aren't used at all.
1083 * When an endpoint is reset by usb_clear_halt() we must reset
1084 * the toggle bit in the QH.
1085 */
1086 if (qh) {
Alan Sterna455212d2009-06-11 14:56:22 -04001087 usb_settoggle(qh->dev, epnum, is_out, 0);
Alan Sternb18ffd42009-05-27 18:21:56 -04001088 if (!list_empty(&qh->qtd_list)) {
1089 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
Alan Stern3a444942009-08-19 12:22:06 -04001090 } else if (qh->qh_state == QH_STATE_LINKED ||
1091 qh->qh_state == QH_STATE_COMPLETING) {
Alan Sterna455212d2009-06-11 14:56:22 -04001092
1093 /* The toggle value in the QH can't be updated
1094 * while the QH is active. Unlink it now;
1095 * re-linking will call qh_refresh().
Alan Sternb18ffd42009-05-27 18:21:56 -04001096 */
Alan Sterna448c9d2009-08-19 12:22:44 -04001097 if (eptype == USB_ENDPOINT_XFER_BULK)
Alan Sterna455212d2009-06-11 14:56:22 -04001098 unlink_async(ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -04001099 else
Alan Sterna455212d2009-06-11 14:56:22 -04001100 intr_deschedule(ehci, qh);
Alan Sternb18ffd42009-05-27 18:21:56 -04001101 }
1102 }
Alan Sterna455212d2009-06-11 14:56:22 -04001103 spin_unlock_irqrestore(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001104}
1105
Matt Porter7ff71d62005-09-22 22:31:15 -07001106static int ehci_get_frame (struct usb_hcd *hcd)
1107{
1108 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001109 return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
1110 ehci->periodic_size;
Matt Porter7ff71d62005-09-22 22:31:15 -07001111}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113/*-------------------------------------------------------------------------*/
1114
Alan Stern2b70f072008-10-02 11:47:15 -04001115MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116MODULE_AUTHOR (DRIVER_AUTHOR);
1117MODULE_LICENSE ("GPL");
1118
Matt Porter7ff71d62005-09-22 22:31:15 -07001119#ifdef CONFIG_PCI
1120#include "ehci-pci.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001121#define PCI_DRIVER ehci_pci_driver
Matt Porter7ff71d62005-09-22 22:31:15 -07001122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Li Yangba029782007-05-11 17:09:55 +08001124#ifdef CONFIG_USB_EHCI_FSL
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001125#include "ehci-fsl.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001126#define PLATFORM_DRIVER ehci_fsl_driver
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001127#endif
1128
Daniel Mack7e8d5cd2009-10-28 01:14:59 +01001129#ifdef CONFIG_USB_EHCI_MXC
1130#include "ehci-mxc.c"
1131#define PLATFORM_DRIVER ehci_mxc_driver
1132#endif
1133
Ralf Baechledfbaa7d2006-06-03 23:58:55 +01001134#ifdef CONFIG_SOC_AU1200
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001135#include "ehci-au1xxx.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001136#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001137#endif
1138
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001139#ifdef CONFIG_ARCH_OMAP3
Felipe Balbi54ab2b02009-10-14 11:44:14 +03001140#include "ehci-omap.c"
1141#define PLATFORM_DRIVER ehci_hcd_omap_driver
1142#endif
1143
Geoff Levandad75a412007-01-15 20:11:47 -08001144#ifdef CONFIG_PPC_PS3
1145#include "ehci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001146#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
Geoff Levandad75a412007-01-15 20:11:47 -08001147#endif
1148
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001149#ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1150#include "ehci-ppc-of.c"
1151#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1152#endif
1153
Julie Zhu08d3c182009-09-21 16:08:19 -06001154#ifdef CONFIG_XPS_USB_HCD_XILINX
1155#include "ehci-xilinx-of.c"
Grant Likely1f23b2d2010-06-02 13:53:17 -06001156#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
Julie Zhu08d3c182009-09-21 16:08:19 -06001157#endif
1158
Lennert Buytenhek705a7522008-03-27 14:51:40 -04001159#ifdef CONFIG_PLAT_ORION
Tzachi Perelsteine96ffe22007-12-01 11:07:04 -05001160#include "ehci-orion.c"
1161#define PLATFORM_DRIVER ehci_orion_driver
1162#endif
1163
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08001164#ifdef CONFIG_ARCH_IXP4XX
1165#include "ehci-ixp4xx.c"
1166#define PLATFORM_DRIVER ixp4xx_ehci_driver
1167#endif
1168
Wan ZongShun586dfc82009-06-13 09:14:28 +08001169#ifdef CONFIG_USB_W90X900_EHCI
1170#include "ehci-w90x900.c"
1171#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1172#endif
1173
Nicolas Ferre501c9c02009-07-27 14:47:40 -07001174#ifdef CONFIG_ARCH_AT91
1175#include "ehci-atmel.c"
1176#define PLATFORM_DRIVER ehci_atmel_driver
1177#endif
1178
Geoff Levandad75a412007-01-15 20:11:47 -08001179#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
Grant Likely1f23b2d2010-06-02 13:53:17 -06001180 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1181 !defined(XILINX_OF_PLATFORM_DRIVER)
Matt Porter7ff71d62005-09-22 22:31:15 -07001182#error "missing bus glue for ehci-hcd"
1183#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001184
1185static int __init ehci_hcd_init(void)
1186{
1187 int retval = 0;
1188
Alan Stern2b70f072008-10-02 11:47:15 -04001189 if (usb_disabled())
1190 return -ENODEV;
1191
1192 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Alan Stern9beeee62008-10-02 11:48:13 -04001193 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1194 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
1195 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
1196 printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
1197 " before uhci_hcd and ohci_hcd, not after\n");
1198
Kumar Gala01cced22006-04-11 10:07:16 -05001199 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1200 hcd_name,
1201 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
1202 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
1203
Tony Jones694cc202007-09-11 14:07:31 -07001204#ifdef DEBUG
Greg Kroah-Hartman08f4e582009-04-24 15:13:18 -07001205 ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
Alan Stern9beeee62008-10-02 11:48:13 -04001206 if (!ehci_debug_root) {
1207 retval = -ENOENT;
1208 goto err_debug;
1209 }
Tony Jones694cc202007-09-11 14:07:31 -07001210#endif
1211
Kumar Gala01cced22006-04-11 10:07:16 -05001212#ifdef PLATFORM_DRIVER
1213 retval = platform_driver_register(&PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001214 if (retval < 0)
1215 goto clean0;
Kumar Gala01cced22006-04-11 10:07:16 -05001216#endif
1217
1218#ifdef PCI_DRIVER
1219 retval = pci_register_driver(&PCI_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001220 if (retval < 0)
1221 goto clean1;
Geoff Levandad75a412007-01-15 20:11:47 -08001222#endif
1223
1224#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001225 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001226 if (retval < 0)
1227 goto clean2;
Kumar Gala01cced22006-04-11 10:07:16 -05001228#endif
1229
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001230#ifdef OF_PLATFORM_DRIVER
1231 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1232 if (retval < 0)
1233 goto clean3;
1234#endif
Grant Likely1f23b2d2010-06-02 13:53:17 -06001235
1236#ifdef XILINX_OF_PLATFORM_DRIVER
1237 retval = of_register_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
1238 if (retval < 0)
1239 goto clean4;
1240#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001241 return retval;
1242
Grant Likely1f23b2d2010-06-02 13:53:17 -06001243#ifdef XILINX_OF_PLATFORM_DRIVER
1244 /* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */
1245clean4:
1246#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001247#ifdef OF_PLATFORM_DRIVER
Grant Likely1f23b2d2010-06-02 13:53:17 -06001248 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001249clean3:
1250#endif
1251#ifdef PS3_SYSTEM_BUS_DRIVER
1252 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1253clean2:
1254#endif
1255#ifdef PCI_DRIVER
1256 pci_unregister_driver(&PCI_DRIVER);
1257clean1:
1258#endif
1259#ifdef PLATFORM_DRIVER
1260 platform_driver_unregister(&PLATFORM_DRIVER);
1261clean0:
1262#endif
1263#ifdef DEBUG
1264 debugfs_remove(ehci_debug_root);
1265 ehci_debug_root = NULL;
Alan Stern9beeee62008-10-02 11:48:13 -04001266err_debug:
Linus Torvaldsa9b61482008-10-20 14:23:29 -07001267#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001268 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001269 return retval;
1270}
1271module_init(ehci_hcd_init);
1272
1273static void __exit ehci_hcd_cleanup(void)
1274{
Grant Likely1f23b2d2010-06-02 13:53:17 -06001275#ifdef XILINX_OF_PLATFORM_DRIVER
1276 of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
1277#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001278#ifdef OF_PLATFORM_DRIVER
1279 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1280#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001281#ifdef PLATFORM_DRIVER
1282 platform_driver_unregister(&PLATFORM_DRIVER);
1283#endif
1284#ifdef PCI_DRIVER
1285 pci_unregister_driver(&PCI_DRIVER);
1286#endif
Geoff Levandad75a412007-01-15 20:11:47 -08001287#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001288 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -08001289#endif
Tony Jones694cc202007-09-11 14:07:31 -07001290#ifdef DEBUG
1291 debugfs_remove(ehci_debug_root);
1292#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001293 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001294}
1295module_exit(ehci_hcd_cleanup);
1296