ehci-hcd.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  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/vmalloc.h>
  26. #include <linux/errno.h>
  27. #include <linux/init.h>
  28. #include <linux/timer.h>
  29. #include <linux/ktime.h>
  30. #include <linux/list.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/usb.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/debugfs.h>
  36. #include <linux/slab.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; handshake %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. /* If the EHCI debug controller is active, special care must be
  209. * taken before and after a host controller reset */
  210. if (ehci->debug && !dbgp_reset_prep())
  211. ehci->debug = NULL;
  212. command |= CMD_RESET;
  213. dbg_cmd (ehci, "reset", command);
  214. ehci_writel(ehci, command, &ehci->regs->command);
  215. ehci_to_hcd(ehci)->state = HC_STATE_HALT;
  216. ehci->next_statechange = jiffies;
  217. retval = handshake (ehci, &ehci->regs->command,
  218. CMD_RESET, 0, 250 * 1000);
  219. if (ehci->has_hostpc) {
  220. ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
  221. (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX));
  222. ehci_writel(ehci, TXFIFO_DEFAULT,
  223. (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
  224. }
  225. if (retval)
  226. return retval;
  227. if (ehci_is_TDI(ehci))
  228. tdi_reset (ehci);
  229. if (ehci->debug)
  230. dbgp_external_startup();
  231. return retval;
  232. }
  233. /* idle the controller (from running) */
  234. static void ehci_quiesce (struct ehci_hcd *ehci)
  235. {
  236. u32 temp;
  237. #ifdef DEBUG
  238. if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
  239. BUG ();
  240. #endif
  241. /* wait for any schedule enables/disables to take effect */
  242. temp = ehci_readl(ehci, &ehci->regs->command) << 10;
  243. temp &= STS_ASS | STS_PSS;
  244. if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
  245. STS_ASS | STS_PSS, temp, 16 * 125))
  246. return;
  247. /* then disable anything that's still active */
  248. temp = ehci_readl(ehci, &ehci->regs->command);
  249. temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
  250. ehci_writel(ehci, temp, &ehci->regs->command);
  251. /* hardware can take 16 microframes to turn off ... */
  252. handshake_on_error_set_halt(ehci, &ehci->regs->status,
  253. STS_ASS | STS_PSS, 0, 16 * 125);
  254. }
  255. /*-------------------------------------------------------------------------*/
  256. static void end_unlink_async(struct ehci_hcd *ehci);
  257. static void ehci_work(struct ehci_hcd *ehci);
  258. #include "ehci-hub.c"
  259. #include "ehci-mem.c"
  260. #include "ehci-q.c"
  261. #include "ehci-sched.c"
  262. /*-------------------------------------------------------------------------*/
  263. static void ehci_iaa_watchdog(unsigned long param)
  264. {
  265. struct ehci_hcd *ehci = (struct ehci_hcd *) param;
  266. unsigned long flags;
  267. spin_lock_irqsave (&ehci->lock, flags);
  268. /* Lost IAA irqs wedge things badly; seen first with a vt8235.
  269. * So we need this watchdog, but must protect it against both
  270. * (a) SMP races against real IAA firing and retriggering, and
  271. * (b) clean HC shutdown, when IAA watchdog was pending.
  272. */
  273. if (ehci->reclaim
  274. && !timer_pending(&ehci->iaa_watchdog)
  275. && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
  276. u32 cmd, status;
  277. /* If we get here, IAA is *REALLY* late. It's barely
  278. * conceivable that the system is so busy that CMD_IAAD
  279. * is still legitimately set, so let's be sure it's
  280. * clear before we read STS_IAA. (The HC should clear
  281. * CMD_IAAD when it sets STS_IAA.)
  282. */
  283. cmd = ehci_readl(ehci, &ehci->regs->command);
  284. if (cmd & CMD_IAAD)
  285. ehci_writel(ehci, cmd & ~CMD_IAAD,
  286. &ehci->regs->command);
  287. /* If IAA is set here it either legitimately triggered
  288. * before we cleared IAAD above (but _way_ late, so we'll
  289. * still count it as lost) ... or a silicon erratum:
  290. * - VIA seems to set IAA without triggering the IRQ;
  291. * - IAAD potentially cleared without setting IAA.
  292. */
  293. status = ehci_readl(ehci, &ehci->regs->status);
  294. if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
  295. COUNT (ehci->stats.lost_iaa);
  296. ehci_writel(ehci, STS_IAA, &ehci->regs->status);
  297. }
  298. ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
  299. status, cmd);
  300. end_unlink_async(ehci);
  301. }
  302. spin_unlock_irqrestore(&ehci->lock, flags);
  303. }
  304. static void ehci_watchdog(unsigned long param)
  305. {
  306. struct ehci_hcd *ehci = (struct ehci_hcd *) param;
  307. unsigned long flags;
  308. spin_lock_irqsave(&ehci->lock, flags);
  309. /* stop async processing after it's idled a bit */
  310. if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
  311. start_unlink_async (ehci, ehci->async);
  312. /* ehci could run by timer, without IRQs ... */
  313. ehci_work (ehci);
  314. spin_unlock_irqrestore (&ehci->lock, flags);
  315. }
  316. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  317. * The firmware seems to think that powering off is a wakeup event!
  318. * This routine turns off remote wakeup and everything else, on all ports.
  319. */
  320. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  321. {
  322. int port = HCS_N_PORTS(ehci->hcs_params);
  323. while (port--)
  324. ehci_writel(ehci, PORT_RWC_BITS,
  325. &ehci->regs->port_status[port]);
  326. }
  327. /*
  328. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  329. * Should be called with ehci->lock held.
  330. */
  331. static void ehci_silence_controller(struct ehci_hcd *ehci)
  332. {
  333. ehci_halt(ehci);
  334. ehci_turn_off_all_ports(ehci);
  335. /* make BIOS/etc use companion controller during reboot */
  336. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  337. /* unblock posted writes */
  338. ehci_readl(ehci, &ehci->regs->configured_flag);
  339. }
  340. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  341. * This forcibly disables dma and IRQs, helping kexec and other cases
  342. * where the next system software may expect clean state.
  343. */
  344. static void ehci_shutdown(struct usb_hcd *hcd)
  345. {
  346. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  347. del_timer_sync(&ehci->watchdog);
  348. del_timer_sync(&ehci->iaa_watchdog);
  349. spin_lock_irq(&ehci->lock);
  350. ehci_silence_controller(ehci);
  351. spin_unlock_irq(&ehci->lock);
  352. }
  353. static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
  354. {
  355. unsigned port;
  356. if (!HCS_PPC (ehci->hcs_params))
  357. return;
  358. ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
  359. for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
  360. (void) ehci_hub_control(ehci_to_hcd(ehci),
  361. is_on ? SetPortFeature : ClearPortFeature,
  362. USB_PORT_FEAT_POWER,
  363. port--, NULL, 0);
  364. /* Flush those writes */
  365. ehci_readl(ehci, &ehci->regs->command);
  366. msleep(20);
  367. }
  368. /*-------------------------------------------------------------------------*/
  369. /*
  370. * ehci_work is called from some interrupts, timers, and so on.
  371. * it calls driver completion functions, after dropping ehci->lock.
  372. */
  373. static void ehci_work (struct ehci_hcd *ehci)
  374. {
  375. timer_action_done (ehci, TIMER_IO_WATCHDOG);
  376. /* another CPU may drop ehci->lock during a schedule scan while
  377. * it reports urb completions. this flag guards against bogus
  378. * attempts at re-entrant schedule scanning.
  379. */
  380. if (ehci->scanning)
  381. return;
  382. ehci->scanning = 1;
  383. scan_async (ehci);
  384. if (ehci->next_uframe != -1)
  385. scan_periodic (ehci);
  386. ehci->scanning = 0;
  387. /* the IO watchdog guards against hardware or driver bugs that
  388. * misplace IRQs, and should let us run completely without IRQs.
  389. * such lossage has been observed on both VT6202 and VT8235.
  390. */
  391. if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
  392. (ehci->async->qh_next.ptr != NULL ||
  393. ehci->periodic_sched != 0))
  394. timer_action (ehci, TIMER_IO_WATCHDOG);
  395. }
  396. /*
  397. * Called when the ehci_hcd module is removed.
  398. */
  399. static void ehci_stop (struct usb_hcd *hcd)
  400. {
  401. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  402. ehci_dbg (ehci, "stop\n");
  403. /* no more interrupts ... */
  404. del_timer_sync (&ehci->watchdog);
  405. del_timer_sync(&ehci->iaa_watchdog);
  406. spin_lock_irq(&ehci->lock);
  407. if (HC_IS_RUNNING (hcd->state))
  408. ehci_quiesce (ehci);
  409. ehci_silence_controller(ehci);
  410. ehci_reset (ehci);
  411. spin_unlock_irq(&ehci->lock);
  412. remove_companion_file(ehci);
  413. remove_debug_files (ehci);
  414. /* root hub is shut down separately (first, when possible) */
  415. spin_lock_irq (&ehci->lock);
  416. if (ehci->async)
  417. ehci_work (ehci);
  418. spin_unlock_irq (&ehci->lock);
  419. ehci_mem_cleanup (ehci);
  420. #ifdef EHCI_STATS
  421. ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
  422. ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
  423. ehci->stats.lost_iaa);
  424. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  425. ehci->stats.complete, ehci->stats.unlink);
  426. #endif
  427. dbg_status (ehci, "ehci_stop completed",
  428. ehci_readl(ehci, &ehci->regs->status));
  429. }
  430. /* one-time init, only for memory state */
  431. static int ehci_init(struct usb_hcd *hcd)
  432. {
  433. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  434. u32 temp;
  435. int retval;
  436. u32 hcc_params;
  437. struct ehci_qh_hw *hw;
  438. spin_lock_init(&ehci->lock);
  439. /*
  440. * keep io watchdog by default, those good HCDs could turn off it later
  441. */
  442. ehci->need_io_watchdog = 1;
  443. init_timer(&ehci->watchdog);
  444. ehci->watchdog.function = ehci_watchdog;
  445. ehci->watchdog.data = (unsigned long) ehci;
  446. init_timer(&ehci->iaa_watchdog);
  447. ehci->iaa_watchdog.function = ehci_iaa_watchdog;
  448. ehci->iaa_watchdog.data = (unsigned long) ehci;
  449. /*
  450. * hw default: 1K periodic list heads, one per frame.
  451. * periodic_size can shrink by USBCMD update if hcc_params allows.
  452. */
  453. ehci->periodic_size = DEFAULT_I_TDPS;
  454. INIT_LIST_HEAD(&ehci->cached_itd_list);
  455. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  456. return retval;
  457. /* controllers may cache some of the periodic schedule ... */
  458. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  459. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  460. ehci->i_thresh = 2 + 8;
  461. else // N microframes cached
  462. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  463. ehci->reclaim = NULL;
  464. ehci->next_uframe = -1;
  465. ehci->clock_frame = -1;
  466. /*
  467. * dedicate a qh for the async ring head, since we couldn't unlink
  468. * a 'real' qh without stopping the async schedule [4.8]. use it
  469. * as the 'reclamation list head' too.
  470. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  471. * from automatically advancing to the next td after short reads.
  472. */
  473. ehci->async->qh_next.qh = NULL;
  474. hw = ehci->async->hw;
  475. hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  476. hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  477. hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  478. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  479. ehci->async->qh_state = QH_STATE_LINKED;
  480. hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  481. /* clear interrupt enables, set irq latency */
  482. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  483. log2_irq_thresh = 0;
  484. temp = 1 << (16 + log2_irq_thresh);
  485. if (HCC_CANPARK(hcc_params)) {
  486. /* HW default park == 3, on hardware that supports it (like
  487. * NVidia and ALI silicon), maximizes throughput on the async
  488. * schedule by avoiding QH fetches between transfers.
  489. *
  490. * With fast usb storage devices and NForce2, "park" seems to
  491. * make problems: throughput reduction (!), data errors...
  492. */
  493. if (park) {
  494. park = min(park, (unsigned) 3);
  495. temp |= CMD_PARK;
  496. temp |= park << 8;
  497. }
  498. ehci_dbg(ehci, "park %d\n", park);
  499. }
  500. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  501. /* periodic schedule size can be smaller than default */
  502. temp &= ~(3 << 2);
  503. temp |= (EHCI_TUNE_FLS << 2);
  504. switch (EHCI_TUNE_FLS) {
  505. case 0: ehci->periodic_size = 1024; break;
  506. case 1: ehci->periodic_size = 512; break;
  507. case 2: ehci->periodic_size = 256; break;
  508. default: BUG();
  509. }
  510. }
  511. ehci->command = temp;
  512. /* Accept arbitrarily long scatter-gather lists */
  513. hcd->self.sg_tablesize = ~0;
  514. return 0;
  515. }
  516. /* start HC running; it's halted, ehci_init() has been run (once) */
  517. static int ehci_run (struct usb_hcd *hcd)
  518. {
  519. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  520. int retval;
  521. u32 temp;
  522. u32 hcc_params;
  523. hcd->uses_new_polling = 1;
  524. hcd->poll_rh = 0;
  525. /* EHCI spec section 4.1 */
  526. if ((retval = ehci_reset(ehci)) != 0) {
  527. ehci_mem_cleanup(ehci);
  528. return retval;
  529. }
  530. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  531. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  532. /*
  533. * hcc_params controls whether ehci->regs->segment must (!!!)
  534. * be used; it constrains QH/ITD/SITD and QTD locations.
  535. * pci_pool consistent memory always uses segment zero.
  536. * streaming mappings for I/O buffers, like pci_map_single(),
  537. * can return segments above 4GB, if the device allows.
  538. *
  539. * NOTE: the dma mask is visible through dma_supported(), so
  540. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  541. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  542. * host side drivers though.
  543. */
  544. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  545. if (HCC_64BIT_ADDR(hcc_params)) {
  546. ehci_writel(ehci, 0, &ehci->regs->segment);
  547. #if 0
  548. // this is deeply broken on almost all architectures
  549. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  550. ehci_info(ehci, "enabled 64bit DMA\n");
  551. #endif
  552. }
  553. // Philips, Intel, and maybe others need CMD_RUN before the
  554. // root hub will detect new devices (why?); NEC doesn't
  555. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  556. ehci->command |= CMD_RUN;
  557. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  558. dbg_cmd (ehci, "init", ehci->command);
  559. /*
  560. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  561. * are explicitly handed to companion controller(s), so no TT is
  562. * involved with the root hub. (Except where one is integrated,
  563. * and there's no companion controller unless maybe for USB OTG.)
  564. *
  565. * Turning on the CF flag will transfer ownership of all ports
  566. * from the companions to the EHCI controller. If any of the
  567. * companions are in the middle of a port reset at the time, it
  568. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  569. * guarantees that no resets are in progress. After we set CF,
  570. * a short delay lets the hardware catch up; new resets shouldn't
  571. * be started before the port switching actions could complete.
  572. */
  573. down_write(&ehci_cf_port_reset_rwsem);
  574. hcd->state = HC_STATE_RUNNING;
  575. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  576. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  577. msleep(5);
  578. up_write(&ehci_cf_port_reset_rwsem);
  579. ehci->last_periodic_enable = ktime_get_real();
  580. temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
  581. ehci_info (ehci,
  582. "USB %x.%x started, EHCI %x.%02x%s\n",
  583. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  584. temp >> 8, temp & 0xff,
  585. ignore_oc ? ", overcurrent ignored" : "");
  586. ehci_writel(ehci, INTR_MASK,
  587. &ehci->regs->intr_enable); /* Turn On Interrupts */
  588. /* GRR this is run-once init(), being done every time the HC starts.
  589. * So long as they're part of class devices, we can't do it init()
  590. * since the class device isn't created that early.
  591. */
  592. create_debug_files(ehci);
  593. create_companion_file(ehci);
  594. return 0;
  595. }
  596. /*-------------------------------------------------------------------------*/
  597. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  598. {
  599. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  600. u32 status, masked_status, pcd_status = 0, cmd;
  601. int bh;
  602. spin_lock (&ehci->lock);
  603. status = ehci_readl(ehci, &ehci->regs->status);
  604. /* e.g. cardbus physical eject */
  605. if (status == ~(u32) 0) {
  606. ehci_dbg (ehci, "device removed\n");
  607. goto dead;
  608. }
  609. masked_status = status & INTR_MASK;
  610. if (!masked_status) { /* irq sharing? */
  611. spin_unlock(&ehci->lock);
  612. return IRQ_NONE;
  613. }
  614. /* clear (just) interrupts */
  615. ehci_writel(ehci, masked_status, &ehci->regs->status);
  616. cmd = ehci_readl(ehci, &ehci->regs->command);
  617. bh = 0;
  618. #ifdef VERBOSE_DEBUG
  619. /* unrequested/ignored: Frame List Rollover */
  620. dbg_status (ehci, "irq", status);
  621. #endif
  622. /* INT, ERR, and IAA interrupt rates can be throttled */
  623. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  624. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  625. if (likely ((status & STS_ERR) == 0))
  626. COUNT (ehci->stats.normal);
  627. else
  628. COUNT (ehci->stats.error);
  629. bh = 1;
  630. }
  631. /* complete the unlinking of some qh [4.15.2.3] */
  632. if (status & STS_IAA) {
  633. /* guard against (alleged) silicon errata */
  634. if (cmd & CMD_IAAD) {
  635. ehci_writel(ehci, cmd & ~CMD_IAAD,
  636. &ehci->regs->command);
  637. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  638. }
  639. if (ehci->reclaim) {
  640. COUNT(ehci->stats.reclaim);
  641. end_unlink_async(ehci);
  642. } else
  643. ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
  644. }
  645. /* remote wakeup [4.3.1] */
  646. if (status & STS_PCD) {
  647. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  648. /* kick root hub later */
  649. pcd_status = status;
  650. /* resume root hub? */
  651. if (!(cmd & CMD_RUN))
  652. usb_hcd_resume_root_hub(hcd);
  653. while (i--) {
  654. int pstatus = ehci_readl(ehci,
  655. &ehci->regs->port_status [i]);
  656. if (pstatus & PORT_OWNER)
  657. continue;
  658. if (!(test_bit(i, &ehci->suspended_ports) &&
  659. ((pstatus & PORT_RESUME) ||
  660. !(pstatus & PORT_SUSPEND)) &&
  661. (pstatus & PORT_PE) &&
  662. ehci->reset_done[i] == 0))
  663. continue;
  664. /* start 20 msec resume signaling from this port,
  665. * and make khubd collect PORT_STAT_C_SUSPEND to
  666. * stop that signaling. Use 5 ms extra for safety,
  667. * like usb_port_resume() does.
  668. */
  669. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  670. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  671. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  672. }
  673. }
  674. /* PCI errors [4.15.2.4] */
  675. if (unlikely ((status & STS_FATAL) != 0)) {
  676. ehci_err(ehci, "fatal error\n");
  677. dbg_cmd(ehci, "fatal", cmd);
  678. dbg_status(ehci, "fatal", status);
  679. ehci_halt(ehci);
  680. dead:
  681. ehci_reset(ehci);
  682. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  683. /* generic layer kills/unlinks all urbs, then
  684. * uses ehci_stop to clean up the rest
  685. */
  686. bh = 1;
  687. }
  688. if (bh)
  689. ehci_work (ehci);
  690. spin_unlock (&ehci->lock);
  691. if (pcd_status)
  692. usb_hcd_poll_rh_status(hcd);
  693. return IRQ_HANDLED;
  694. }
  695. /*-------------------------------------------------------------------------*/
  696. /*
  697. * non-error returns are a promise to giveback() the urb later
  698. * we drop ownership so next owner (or urb unlink) can get it
  699. *
  700. * urb + dev is in hcd.self.controller.urb_list
  701. * we're queueing TDs onto software and hardware lists
  702. *
  703. * hcd-specific init for hcpriv hasn't been done yet
  704. *
  705. * NOTE: control, bulk, and interrupt share the same code to append TDs
  706. * to a (possibly active) QH, and the same QH scanning code.
  707. */
  708. static int ehci_urb_enqueue (
  709. struct usb_hcd *hcd,
  710. struct urb *urb,
  711. gfp_t mem_flags
  712. ) {
  713. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  714. struct list_head qtd_list;
  715. INIT_LIST_HEAD (&qtd_list);
  716. switch (usb_pipetype (urb->pipe)) {
  717. case PIPE_CONTROL:
  718. /* qh_completions() code doesn't handle all the fault cases
  719. * in multi-TD control transfers. Even 1KB is rare anyway.
  720. */
  721. if (urb->transfer_buffer_length > (16 * 1024))
  722. return -EMSGSIZE;
  723. /* FALLTHROUGH */
  724. /* case PIPE_BULK: */
  725. default:
  726. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  727. return -ENOMEM;
  728. return submit_async(ehci, urb, &qtd_list, mem_flags);
  729. case PIPE_INTERRUPT:
  730. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  731. return -ENOMEM;
  732. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  733. case PIPE_ISOCHRONOUS:
  734. if (urb->dev->speed == USB_SPEED_HIGH)
  735. return itd_submit (ehci, urb, mem_flags);
  736. else
  737. return sitd_submit (ehci, urb, mem_flags);
  738. }
  739. }
  740. static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
  741. {
  742. /* failfast */
  743. if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
  744. end_unlink_async(ehci);
  745. /* If the QH isn't linked then there's nothing we can do
  746. * unless we were called during a giveback, in which case
  747. * qh_completions() has to deal with it.
  748. */
  749. if (qh->qh_state != QH_STATE_LINKED) {
  750. if (qh->qh_state == QH_STATE_COMPLETING)
  751. qh->needs_rescan = 1;
  752. return;
  753. }
  754. /* defer till later if busy */
  755. if (ehci->reclaim) {
  756. struct ehci_qh *last;
  757. for (last = ehci->reclaim;
  758. last->reclaim;
  759. last = last->reclaim)
  760. continue;
  761. qh->qh_state = QH_STATE_UNLINK_WAIT;
  762. last->reclaim = qh;
  763. /* start IAA cycle */
  764. } else
  765. start_unlink_async (ehci, qh);
  766. }
  767. /* remove from hardware lists
  768. * completions normally happen asynchronously
  769. */
  770. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  771. {
  772. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  773. struct ehci_qh *qh;
  774. unsigned long flags;
  775. int rc;
  776. spin_lock_irqsave (&ehci->lock, flags);
  777. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  778. if (rc)
  779. goto done;
  780. switch (usb_pipetype (urb->pipe)) {
  781. // case PIPE_CONTROL:
  782. // case PIPE_BULK:
  783. default:
  784. qh = (struct ehci_qh *) urb->hcpriv;
  785. if (!qh)
  786. break;
  787. switch (qh->qh_state) {
  788. case QH_STATE_LINKED:
  789. case QH_STATE_COMPLETING:
  790. unlink_async(ehci, qh);
  791. break;
  792. case QH_STATE_UNLINK:
  793. case QH_STATE_UNLINK_WAIT:
  794. /* already started */
  795. break;
  796. case QH_STATE_IDLE:
  797. /* QH might be waiting for a Clear-TT-Buffer */
  798. qh_completions(ehci, qh);
  799. break;
  800. }
  801. break;
  802. case PIPE_INTERRUPT:
  803. qh = (struct ehci_qh *) urb->hcpriv;
  804. if (!qh)
  805. break;
  806. switch (qh->qh_state) {
  807. case QH_STATE_LINKED:
  808. case QH_STATE_COMPLETING:
  809. intr_deschedule (ehci, qh);
  810. break;
  811. case QH_STATE_IDLE:
  812. qh_completions (ehci, qh);
  813. break;
  814. default:
  815. ehci_dbg (ehci, "bogus qh %p state %d\n",
  816. qh, qh->qh_state);
  817. goto done;
  818. }
  819. break;
  820. case PIPE_ISOCHRONOUS:
  821. // itd or sitd ...
  822. // wait till next completion, do it then.
  823. // completion irqs can wait up to 1024 msec,
  824. break;
  825. }
  826. done:
  827. spin_unlock_irqrestore (&ehci->lock, flags);
  828. return rc;
  829. }
  830. /*-------------------------------------------------------------------------*/
  831. // bulk qh holds the data toggle
  832. static void
  833. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  834. {
  835. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  836. unsigned long flags;
  837. struct ehci_qh *qh, *tmp;
  838. /* ASSERT: any requests/urbs are being unlinked */
  839. /* ASSERT: nobody can be submitting urbs for this any more */
  840. rescan:
  841. spin_lock_irqsave (&ehci->lock, flags);
  842. qh = ep->hcpriv;
  843. if (!qh)
  844. goto done;
  845. /* endpoints can be iso streams. for now, we don't
  846. * accelerate iso completions ... so spin a while.
  847. */
  848. if (qh->hw == NULL) {
  849. ehci_vdbg (ehci, "iso delay\n");
  850. goto idle_timeout;
  851. }
  852. if (!HC_IS_RUNNING (hcd->state))
  853. qh->qh_state = QH_STATE_IDLE;
  854. switch (qh->qh_state) {
  855. case QH_STATE_LINKED:
  856. case QH_STATE_COMPLETING:
  857. for (tmp = ehci->async->qh_next.qh;
  858. tmp && tmp != qh;
  859. tmp = tmp->qh_next.qh)
  860. continue;
  861. /* periodic qh self-unlinks on empty */
  862. if (!tmp)
  863. goto nogood;
  864. unlink_async (ehci, qh);
  865. /* FALL THROUGH */
  866. case QH_STATE_UNLINK: /* wait for hw to finish? */
  867. case QH_STATE_UNLINK_WAIT:
  868. idle_timeout:
  869. spin_unlock_irqrestore (&ehci->lock, flags);
  870. schedule_timeout_uninterruptible(1);
  871. goto rescan;
  872. case QH_STATE_IDLE: /* fully unlinked */
  873. if (qh->clearing_tt)
  874. goto idle_timeout;
  875. if (list_empty (&qh->qtd_list)) {
  876. qh_put (qh);
  877. break;
  878. }
  879. /* else FALL THROUGH */
  880. default:
  881. nogood:
  882. /* caller was supposed to have unlinked any requests;
  883. * that's not our job. just leak this memory.
  884. */
  885. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  886. qh, ep->desc.bEndpointAddress, qh->qh_state,
  887. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  888. break;
  889. }
  890. ep->hcpriv = NULL;
  891. done:
  892. spin_unlock_irqrestore (&ehci->lock, flags);
  893. return;
  894. }
  895. static void
  896. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  897. {
  898. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  899. struct ehci_qh *qh;
  900. int eptype = usb_endpoint_type(&ep->desc);
  901. int epnum = usb_endpoint_num(&ep->desc);
  902. int is_out = usb_endpoint_dir_out(&ep->desc);
  903. unsigned long flags;
  904. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  905. return;
  906. spin_lock_irqsave(&ehci->lock, flags);
  907. qh = ep->hcpriv;
  908. /* For Bulk and Interrupt endpoints we maintain the toggle state
  909. * in the hardware; the toggle bits in udev aren't used at all.
  910. * When an endpoint is reset by usb_clear_halt() we must reset
  911. * the toggle bit in the QH.
  912. */
  913. if (qh) {
  914. usb_settoggle(qh->dev, epnum, is_out, 0);
  915. if (!list_empty(&qh->qtd_list)) {
  916. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  917. } else if (qh->qh_state == QH_STATE_LINKED ||
  918. qh->qh_state == QH_STATE_COMPLETING) {
  919. /* The toggle value in the QH can't be updated
  920. * while the QH is active. Unlink it now;
  921. * re-linking will call qh_refresh().
  922. */
  923. if (eptype == USB_ENDPOINT_XFER_BULK)
  924. unlink_async(ehci, qh);
  925. else
  926. intr_deschedule(ehci, qh);
  927. }
  928. }
  929. spin_unlock_irqrestore(&ehci->lock, flags);
  930. }
  931. static int ehci_get_frame (struct usb_hcd *hcd)
  932. {
  933. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  934. return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
  935. ehci->periodic_size;
  936. }
  937. /*-------------------------------------------------------------------------*/
  938. MODULE_DESCRIPTION(DRIVER_DESC);
  939. MODULE_AUTHOR (DRIVER_AUTHOR);
  940. MODULE_LICENSE ("GPL");
  941. #ifdef CONFIG_PCI
  942. #include "ehci-pci.c"
  943. #define PCI_DRIVER ehci_pci_driver
  944. #endif
  945. #ifdef CONFIG_USB_EHCI_FSL
  946. #include "ehci-fsl.c"
  947. #define PLATFORM_DRIVER ehci_fsl_driver
  948. #endif
  949. #ifdef CONFIG_USB_EHCI_MXC
  950. #include "ehci-mxc.c"
  951. #define PLATFORM_DRIVER ehci_mxc_driver
  952. #endif
  953. #ifdef CONFIG_SOC_AU1200
  954. #include "ehci-au1xxx.c"
  955. #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
  956. #endif
  957. #ifdef CONFIG_ARCH_OMAP3
  958. #include "ehci-omap.c"
  959. #define PLATFORM_DRIVER ehci_hcd_omap_driver
  960. #endif
  961. #ifdef CONFIG_PPC_PS3
  962. #include "ehci-ps3.c"
  963. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  964. #endif
  965. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  966. #include "ehci-ppc-of.c"
  967. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  968. #endif
  969. #ifdef CONFIG_XPS_USB_HCD_XILINX
  970. #include "ehci-xilinx-of.c"
  971. #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  972. #endif
  973. #ifdef CONFIG_PLAT_ORION
  974. #include "ehci-orion.c"
  975. #define PLATFORM_DRIVER ehci_orion_driver
  976. #endif
  977. #ifdef CONFIG_ARCH_IXP4XX
  978. #include "ehci-ixp4xx.c"
  979. #define PLATFORM_DRIVER ixp4xx_ehci_driver
  980. #endif
  981. #ifdef CONFIG_USB_W90X900_EHCI
  982. #include "ehci-w90x900.c"
  983. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  984. #endif
  985. #ifdef CONFIG_ARCH_AT91
  986. #include "ehci-atmel.c"
  987. #define PLATFORM_DRIVER ehci_atmel_driver
  988. #endif
  989. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  990. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
  991. #error "missing bus glue for ehci-hcd"
  992. #endif
  993. static int __init ehci_hcd_init(void)
  994. {
  995. int retval = 0;
  996. if (usb_disabled())
  997. return -ENODEV;
  998. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  999. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1000. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1001. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1002. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1003. " before uhci_hcd and ohci_hcd, not after\n");
  1004. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1005. hcd_name,
  1006. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1007. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1008. #ifdef DEBUG
  1009. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1010. if (!ehci_debug_root) {
  1011. retval = -ENOENT;
  1012. goto err_debug;
  1013. }
  1014. #endif
  1015. #ifdef PLATFORM_DRIVER
  1016. retval = platform_driver_register(&PLATFORM_DRIVER);
  1017. if (retval < 0)
  1018. goto clean0;
  1019. #endif
  1020. #ifdef PCI_DRIVER
  1021. retval = pci_register_driver(&PCI_DRIVER);
  1022. if (retval < 0)
  1023. goto clean1;
  1024. #endif
  1025. #ifdef PS3_SYSTEM_BUS_DRIVER
  1026. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1027. if (retval < 0)
  1028. goto clean2;
  1029. #endif
  1030. #ifdef OF_PLATFORM_DRIVER
  1031. retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
  1032. if (retval < 0)
  1033. goto clean3;
  1034. #endif
  1035. return retval;
  1036. #ifdef OF_PLATFORM_DRIVER
  1037. /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */
  1038. clean3:
  1039. #endif
  1040. #ifdef PS3_SYSTEM_BUS_DRIVER
  1041. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1042. clean2:
  1043. #endif
  1044. #ifdef PCI_DRIVER
  1045. pci_unregister_driver(&PCI_DRIVER);
  1046. clean1:
  1047. #endif
  1048. #ifdef PLATFORM_DRIVER
  1049. platform_driver_unregister(&PLATFORM_DRIVER);
  1050. clean0:
  1051. #endif
  1052. #ifdef DEBUG
  1053. debugfs_remove(ehci_debug_root);
  1054. ehci_debug_root = NULL;
  1055. err_debug:
  1056. #endif
  1057. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1058. return retval;
  1059. }
  1060. module_init(ehci_hcd_init);
  1061. static void __exit ehci_hcd_cleanup(void)
  1062. {
  1063. #ifdef OF_PLATFORM_DRIVER
  1064. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1065. #endif
  1066. #ifdef PLATFORM_DRIVER
  1067. platform_driver_unregister(&PLATFORM_DRIVER);
  1068. #endif
  1069. #ifdef PCI_DRIVER
  1070. pci_unregister_driver(&PCI_DRIVER);
  1071. #endif
  1072. #ifdef PS3_SYSTEM_BUS_DRIVER
  1073. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1074. #endif
  1075. #ifdef DEBUG
  1076. debugfs_remove(ehci_debug_root);
  1077. #endif
  1078. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1079. }
  1080. module_exit(ehci_hcd_cleanup);