ehci-hcd.c 35 KB

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