ehci-hcd.c 34 KB

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