ehci-hcd.c 38 KB

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