ehci-hcd.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. /*
  2. * Enhanced Host Controller Interface (EHCI) driver for USB.
  3. *
  4. * Maintainer: Alan Stern <stern@rowland.harvard.edu>
  5. *
  6. * Copyright (c) 2000-2004 by David Brownell
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/pci.h>
  24. #include <linux/dmapool.h>
  25. #include <linux/kernel.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/sched.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/errno.h>
  31. #include <linux/init.h>
  32. #include <linux/hrtimer.h>
  33. #include <linux/list.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/usb.h>
  36. #include <linux/usb/hcd.h>
  37. #include <linux/moduleparam.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/slab.h>
  41. #include <asm/byteorder.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #include <asm/unaligned.h>
  45. #if defined(CONFIG_PPC_PS3)
  46. #include <asm/firmware.h>
  47. #endif
  48. /*-------------------------------------------------------------------------*/
  49. /*
  50. * EHCI hc_driver implementation ... experimental, incomplete.
  51. * Based on the final 1.0 register interface specification.
  52. *
  53. * USB 2.0 shows up in upcoming www.pcmcia.org technology.
  54. * First was PCMCIA, like ISA; then CardBus, which is PCI.
  55. * Next comes "CardBay", using USB 2.0 signals.
  56. *
  57. * Contains additional contributions by Brad Hards, Rory Bolt, and others.
  58. * Special thanks to Intel and VIA for providing host controllers to
  59. * test this driver on, and Cypress (including In-System Design) for
  60. * providing early devices for those host controllers to talk to!
  61. */
  62. #define DRIVER_AUTHOR "David Brownell"
  63. #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
  64. static const char hcd_name [] = "ehci_hcd";
  65. #undef VERBOSE_DEBUG
  66. #undef EHCI_URB_TRACE
  67. /* magic numbers that can affect system performance */
  68. #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
  69. #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
  70. #define EHCI_TUNE_RL_TT 0
  71. #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
  72. #define EHCI_TUNE_MULT_TT 1
  73. /*
  74. * Some drivers think it's safe to schedule isochronous transfers more than
  75. * 256 ms into the future (partly as a result of an old bug in the scheduling
  76. * code). In an attempt to avoid trouble, we will use a minimum scheduling
  77. * length of 512 frames instead of 256.
  78. */
  79. #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
  80. /* Initial IRQ latency: faster than hw default */
  81. static int log2_irq_thresh = 0; // 0 to 6
  82. module_param (log2_irq_thresh, int, S_IRUGO);
  83. MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
  84. /* initial park setting: slower than hw default */
  85. static unsigned park = 0;
  86. module_param (park, uint, S_IRUGO);
  87. MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
  88. /* for flakey hardware, ignore overcurrent indicators */
  89. static bool ignore_oc = 0;
  90. module_param (ignore_oc, bool, S_IRUGO);
  91. MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
  92. #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  93. /*-------------------------------------------------------------------------*/
  94. #include "ehci.h"
  95. #include "pci-quirks.h"
  96. /*
  97. * The MosChip MCS9990 controller updates its microframe counter
  98. * a little before the frame counter, and occasionally we will read
  99. * the invalid intermediate value. Avoid problems by checking the
  100. * microframe number (the low-order 3 bits); if they are 0 then
  101. * re-read the register to get the correct value.
  102. */
  103. static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
  104. {
  105. unsigned uf;
  106. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  107. if (unlikely((uf & 7) == 0))
  108. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  109. return uf;
  110. }
  111. static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
  112. {
  113. if (ehci->frame_index_bug)
  114. return ehci_moschip_read_frame_index(ehci);
  115. return ehci_readl(ehci, &ehci->regs->frame_index);
  116. }
  117. #include "ehci-dbg.c"
  118. /*-------------------------------------------------------------------------*/
  119. /*
  120. * ehci_handshake - spin reading hc until handshake completes or fails
  121. * @ptr: address of hc register to be read
  122. * @mask: bits to look at in result of read
  123. * @done: value of those bits when handshake succeeds
  124. * @usec: timeout in microseconds
  125. *
  126. * Returns negative errno, or zero on success
  127. *
  128. * Success happens when the "mask" bits have the specified value (hardware
  129. * handshake done). There are two failure modes: "usec" have passed (major
  130. * hardware flakeout), or the register reads as all-ones (hardware removed).
  131. *
  132. * That last failure should_only happen in cases like physical cardbus eject
  133. * before driver shutdown. But it also seems to be caused by bugs in cardbus
  134. * bridge shutdown: shutting down the bridge before the devices using it.
  135. */
  136. int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr,
  137. u32 mask, u32 done, int usec)
  138. {
  139. u32 result;
  140. do {
  141. result = ehci_readl(ehci, ptr);
  142. if (result == ~(u32)0) /* card removed */
  143. return -ENODEV;
  144. result &= mask;
  145. if (result == done)
  146. return 0;
  147. udelay (1);
  148. usec--;
  149. } while (usec > 0);
  150. return -ETIMEDOUT;
  151. }
  152. EXPORT_SYMBOL_GPL(ehci_handshake);
  153. /* check TDI/ARC silicon is in host mode */
  154. static int tdi_in_host_mode (struct ehci_hcd *ehci)
  155. {
  156. u32 tmp;
  157. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  158. return (tmp & 3) == USBMODE_CM_HC;
  159. }
  160. /*
  161. * Force HC to halt state from unknown (EHCI spec section 2.3).
  162. * Must be called with interrupts enabled and the lock not held.
  163. */
  164. static int ehci_halt (struct ehci_hcd *ehci)
  165. {
  166. u32 temp;
  167. spin_lock_irq(&ehci->lock);
  168. /* disable any irqs left enabled by previous code */
  169. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  170. if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
  171. spin_unlock_irq(&ehci->lock);
  172. return 0;
  173. }
  174. /*
  175. * This routine gets called during probe before ehci->command
  176. * has been initialized, so we can't rely on its value.
  177. */
  178. ehci->command &= ~CMD_RUN;
  179. temp = ehci_readl(ehci, &ehci->regs->command);
  180. temp &= ~(CMD_RUN | CMD_IAAD);
  181. ehci_writel(ehci, temp, &ehci->regs->command);
  182. spin_unlock_irq(&ehci->lock);
  183. synchronize_irq(ehci_to_hcd(ehci)->irq);
  184. return ehci_handshake(ehci, &ehci->regs->status,
  185. STS_HALT, STS_HALT, 16 * 125);
  186. }
  187. /* put TDI/ARC silicon into EHCI mode */
  188. static void tdi_reset (struct ehci_hcd *ehci)
  189. {
  190. u32 tmp;
  191. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  192. tmp |= USBMODE_CM_HC;
  193. /* The default byte access to MMR space is LE after
  194. * controller reset. Set the required endian mode
  195. * for transfer buffers to match the host microprocessor
  196. */
  197. if (ehci_big_endian_mmio(ehci))
  198. tmp |= USBMODE_BE;
  199. ehci_writel(ehci, tmp, &ehci->regs->usbmode);
  200. }
  201. /*
  202. * Reset a non-running (STS_HALT == 1) controller.
  203. * Must be called with interrupts enabled and the lock not held.
  204. */
  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(ehci_to_hcd(ehci)))
  212. ehci->debug = NULL;
  213. command |= CMD_RESET;
  214. dbg_cmd (ehci, "reset", command);
  215. ehci_writel(ehci, command, &ehci->regs->command);
  216. ehci->rh_state = EHCI_RH_HALTED;
  217. ehci->next_statechange = jiffies;
  218. retval = ehci_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. &ehci->regs->usbmode_ex);
  223. ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
  224. }
  225. if (retval)
  226. return retval;
  227. if (ehci_is_TDI(ehci))
  228. tdi_reset (ehci);
  229. if (ehci->debug)
  230. dbgp_external_startup(ehci_to_hcd(ehci));
  231. ehci->port_c_suspend = ehci->suspended_ports =
  232. ehci->resuming_ports = 0;
  233. return retval;
  234. }
  235. /*
  236. * Idle the controller (turn off the schedules).
  237. * Must be called with interrupts enabled and the lock not held.
  238. */
  239. static void ehci_quiesce (struct ehci_hcd *ehci)
  240. {
  241. u32 temp;
  242. if (ehci->rh_state != EHCI_RH_RUNNING)
  243. return;
  244. /* wait for any schedule enables/disables to take effect */
  245. temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
  246. ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp,
  247. 16 * 125);
  248. /* then disable anything that's still active */
  249. spin_lock_irq(&ehci->lock);
  250. ehci->command &= ~(CMD_ASE | CMD_PSE);
  251. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  252. spin_unlock_irq(&ehci->lock);
  253. /* hardware can take 16 microframes to turn off ... */
  254. ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0,
  255. 16 * 125);
  256. }
  257. /*-------------------------------------------------------------------------*/
  258. static void end_unlink_async(struct ehci_hcd *ehci);
  259. static void unlink_empty_async(struct ehci_hcd *ehci);
  260. static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
  261. static void ehci_work(struct ehci_hcd *ehci);
  262. static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  263. static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  264. #include "ehci-timer.c"
  265. #include "ehci-hub.c"
  266. #include "ehci-mem.c"
  267. #include "ehci-q.c"
  268. #include "ehci-sched.c"
  269. #include "ehci-sysfs.c"
  270. /*-------------------------------------------------------------------------*/
  271. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  272. * The firmware seems to think that powering off is a wakeup event!
  273. * This routine turns off remote wakeup and everything else, on all ports.
  274. */
  275. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  276. {
  277. int port = HCS_N_PORTS(ehci->hcs_params);
  278. while (port--)
  279. ehci_writel(ehci, PORT_RWC_BITS,
  280. &ehci->regs->port_status[port]);
  281. }
  282. /*
  283. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  284. * Must be called with interrupts enabled and the lock not held.
  285. */
  286. static void ehci_silence_controller(struct ehci_hcd *ehci)
  287. {
  288. ehci_halt(ehci);
  289. spin_lock_irq(&ehci->lock);
  290. ehci->rh_state = EHCI_RH_HALTED;
  291. ehci_turn_off_all_ports(ehci);
  292. /* make BIOS/etc use companion controller during reboot */
  293. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  294. /* unblock posted writes */
  295. ehci_readl(ehci, &ehci->regs->configured_flag);
  296. spin_unlock_irq(&ehci->lock);
  297. }
  298. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  299. * This forcibly disables dma and IRQs, helping kexec and other cases
  300. * where the next system software may expect clean state.
  301. */
  302. static void ehci_shutdown(struct usb_hcd *hcd)
  303. {
  304. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  305. spin_lock_irq(&ehci->lock);
  306. ehci->shutdown = true;
  307. ehci->rh_state = EHCI_RH_STOPPING;
  308. ehci->enabled_hrtimer_events = 0;
  309. spin_unlock_irq(&ehci->lock);
  310. ehci_silence_controller(ehci);
  311. hrtimer_cancel(&ehci->hrtimer);
  312. }
  313. /*-------------------------------------------------------------------------*/
  314. /*
  315. * ehci_work is called from some interrupts, timers, and so on.
  316. * it calls driver completion functions, after dropping ehci->lock.
  317. */
  318. static void ehci_work (struct ehci_hcd *ehci)
  319. {
  320. /* another CPU may drop ehci->lock during a schedule scan while
  321. * it reports urb completions. this flag guards against bogus
  322. * attempts at re-entrant schedule scanning.
  323. */
  324. if (ehci->scanning) {
  325. ehci->need_rescan = true;
  326. return;
  327. }
  328. ehci->scanning = true;
  329. rescan:
  330. ehci->need_rescan = false;
  331. if (ehci->async_count)
  332. scan_async(ehci);
  333. if (ehci->intr_count > 0)
  334. scan_intr(ehci);
  335. if (ehci->isoc_count > 0)
  336. scan_isoc(ehci);
  337. if (ehci->need_rescan)
  338. goto rescan;
  339. ehci->scanning = false;
  340. /* the IO watchdog guards against hardware or driver bugs that
  341. * misplace IRQs, and should let us run completely without IRQs.
  342. * such lossage has been observed on both VT6202 and VT8235.
  343. */
  344. turn_on_io_watchdog(ehci);
  345. }
  346. /*
  347. * Called when the ehci_hcd module is removed.
  348. */
  349. static void ehci_stop (struct usb_hcd *hcd)
  350. {
  351. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  352. ehci_dbg (ehci, "stop\n");
  353. /* no more interrupts ... */
  354. spin_lock_irq(&ehci->lock);
  355. ehci->enabled_hrtimer_events = 0;
  356. spin_unlock_irq(&ehci->lock);
  357. ehci_quiesce(ehci);
  358. ehci_silence_controller(ehci);
  359. ehci_reset (ehci);
  360. hrtimer_cancel(&ehci->hrtimer);
  361. remove_sysfs_files(ehci);
  362. remove_debug_files (ehci);
  363. /* root hub is shut down separately (first, when possible) */
  364. spin_lock_irq (&ehci->lock);
  365. end_free_itds(ehci);
  366. spin_unlock_irq (&ehci->lock);
  367. ehci_mem_cleanup (ehci);
  368. if (ehci->amd_pll_fix == 1)
  369. usb_amd_dev_put();
  370. #ifdef EHCI_STATS
  371. ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
  372. ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
  373. ehci->stats.lost_iaa);
  374. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  375. ehci->stats.complete, ehci->stats.unlink);
  376. #endif
  377. dbg_status (ehci, "ehci_stop completed",
  378. ehci_readl(ehci, &ehci->regs->status));
  379. }
  380. /* one-time init, only for memory state */
  381. static int ehci_init(struct usb_hcd *hcd)
  382. {
  383. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  384. u32 temp;
  385. int retval;
  386. u32 hcc_params;
  387. struct ehci_qh_hw *hw;
  388. spin_lock_init(&ehci->lock);
  389. /*
  390. * keep io watchdog by default, those good HCDs could turn off it later
  391. */
  392. ehci->need_io_watchdog = 1;
  393. hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  394. ehci->hrtimer.function = ehci_hrtimer_func;
  395. ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  396. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  397. /*
  398. * by default set standard 80% (== 100 usec/uframe) max periodic
  399. * bandwidth as required by USB 2.0
  400. */
  401. ehci->uframe_periodic_max = 100;
  402. /*
  403. * hw default: 1K periodic list heads, one per frame.
  404. * periodic_size can shrink by USBCMD update if hcc_params allows.
  405. */
  406. ehci->periodic_size = DEFAULT_I_TDPS;
  407. INIT_LIST_HEAD(&ehci->async_unlink);
  408. INIT_LIST_HEAD(&ehci->async_idle);
  409. INIT_LIST_HEAD(&ehci->intr_unlink);
  410. INIT_LIST_HEAD(&ehci->intr_qh_list);
  411. INIT_LIST_HEAD(&ehci->cached_itd_list);
  412. INIT_LIST_HEAD(&ehci->cached_sitd_list);
  413. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  414. /* periodic schedule size can be smaller than default */
  415. switch (EHCI_TUNE_FLS) {
  416. case 0: ehci->periodic_size = 1024; break;
  417. case 1: ehci->periodic_size = 512; break;
  418. case 2: ehci->periodic_size = 256; break;
  419. default: BUG();
  420. }
  421. }
  422. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  423. return retval;
  424. /* controllers may cache some of the periodic schedule ... */
  425. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  426. ehci->i_thresh = 0;
  427. else // N microframes cached
  428. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  429. /*
  430. * dedicate a qh for the async ring head, since we couldn't unlink
  431. * a 'real' qh without stopping the async schedule [4.8]. use it
  432. * as the 'reclamation list head' too.
  433. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  434. * from automatically advancing to the next td after short reads.
  435. */
  436. ehci->async->qh_next.qh = NULL;
  437. hw = ehci->async->hw;
  438. hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  439. hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  440. #if defined(CONFIG_PPC_PS3)
  441. hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
  442. #endif
  443. hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  444. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  445. ehci->async->qh_state = QH_STATE_LINKED;
  446. hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  447. /* clear interrupt enables, set irq latency */
  448. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  449. log2_irq_thresh = 0;
  450. temp = 1 << (16 + log2_irq_thresh);
  451. if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
  452. ehci->has_ppcd = 1;
  453. ehci_dbg(ehci, "enable per-port change event\n");
  454. temp |= CMD_PPCEE;
  455. }
  456. if (HCC_CANPARK(hcc_params)) {
  457. /* HW default park == 3, on hardware that supports it (like
  458. * NVidia and ALI silicon), maximizes throughput on the async
  459. * schedule by avoiding QH fetches between transfers.
  460. *
  461. * With fast usb storage devices and NForce2, "park" seems to
  462. * make problems: throughput reduction (!), data errors...
  463. */
  464. if (park) {
  465. park = min(park, (unsigned) 3);
  466. temp |= CMD_PARK;
  467. temp |= park << 8;
  468. }
  469. ehci_dbg(ehci, "park %d\n", park);
  470. }
  471. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  472. /* periodic schedule size can be smaller than default */
  473. temp &= ~(3 << 2);
  474. temp |= (EHCI_TUNE_FLS << 2);
  475. }
  476. ehci->command = temp;
  477. /* Accept arbitrarily long scatter-gather lists */
  478. if (!(hcd->driver->flags & HCD_LOCAL_MEM))
  479. hcd->self.sg_tablesize = ~0;
  480. return 0;
  481. }
  482. /* start HC running; it's halted, ehci_init() has been run (once) */
  483. static int ehci_run (struct usb_hcd *hcd)
  484. {
  485. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  486. u32 temp;
  487. u32 hcc_params;
  488. hcd->uses_new_polling = 1;
  489. /* EHCI spec section 4.1 */
  490. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  491. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  492. /*
  493. * hcc_params controls whether ehci->regs->segment must (!!!)
  494. * be used; it constrains QH/ITD/SITD and QTD locations.
  495. * pci_pool consistent memory always uses segment zero.
  496. * streaming mappings for I/O buffers, like pci_map_single(),
  497. * can return segments above 4GB, if the device allows.
  498. *
  499. * NOTE: the dma mask is visible through dma_supported(), so
  500. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  501. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  502. * host side drivers though.
  503. */
  504. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  505. if (HCC_64BIT_ADDR(hcc_params)) {
  506. ehci_writel(ehci, 0, &ehci->regs->segment);
  507. #if 0
  508. // this is deeply broken on almost all architectures
  509. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  510. ehci_info(ehci, "enabled 64bit DMA\n");
  511. #endif
  512. }
  513. // Philips, Intel, and maybe others need CMD_RUN before the
  514. // root hub will detect new devices (why?); NEC doesn't
  515. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  516. ehci->command |= CMD_RUN;
  517. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  518. dbg_cmd (ehci, "init", ehci->command);
  519. /*
  520. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  521. * are explicitly handed to companion controller(s), so no TT is
  522. * involved with the root hub. (Except where one is integrated,
  523. * and there's no companion controller unless maybe for USB OTG.)
  524. *
  525. * Turning on the CF flag will transfer ownership of all ports
  526. * from the companions to the EHCI controller. If any of the
  527. * companions are in the middle of a port reset at the time, it
  528. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  529. * guarantees that no resets are in progress. After we set CF,
  530. * a short delay lets the hardware catch up; new resets shouldn't
  531. * be started before the port switching actions could complete.
  532. */
  533. down_write(&ehci_cf_port_reset_rwsem);
  534. ehci->rh_state = EHCI_RH_RUNNING;
  535. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  536. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  537. msleep(5);
  538. up_write(&ehci_cf_port_reset_rwsem);
  539. ehci->last_periodic_enable = ktime_get_real();
  540. temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  541. ehci_info (ehci,
  542. "USB %x.%x started, EHCI %x.%02x%s\n",
  543. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  544. temp >> 8, temp & 0xff,
  545. ignore_oc ? ", overcurrent ignored" : "");
  546. ehci_writel(ehci, INTR_MASK,
  547. &ehci->regs->intr_enable); /* Turn On Interrupts */
  548. /* GRR this is run-once init(), being done every time the HC starts.
  549. * So long as they're part of class devices, we can't do it init()
  550. * since the class device isn't created that early.
  551. */
  552. create_debug_files(ehci);
  553. create_sysfs_files(ehci);
  554. return 0;
  555. }
  556. int ehci_setup(struct usb_hcd *hcd)
  557. {
  558. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  559. int retval;
  560. ehci->regs = (void __iomem *)ehci->caps +
  561. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  562. dbg_hcs_params(ehci, "reset");
  563. dbg_hcc_params(ehci, "reset");
  564. /* cache this readonly data; minimize chip reads */
  565. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  566. ehci->sbrn = HCD_USB2;
  567. /* data structure init */
  568. retval = ehci_init(hcd);
  569. if (retval)
  570. return retval;
  571. retval = ehci_halt(ehci);
  572. if (retval)
  573. return retval;
  574. ehci_reset(ehci);
  575. return 0;
  576. }
  577. EXPORT_SYMBOL_GPL(ehci_setup);
  578. /*-------------------------------------------------------------------------*/
  579. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  580. {
  581. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  582. u32 status, masked_status, pcd_status = 0, cmd;
  583. int bh;
  584. spin_lock (&ehci->lock);
  585. status = ehci_readl(ehci, &ehci->regs->status);
  586. /* e.g. cardbus physical eject */
  587. if (status == ~(u32) 0) {
  588. ehci_dbg (ehci, "device removed\n");
  589. goto dead;
  590. }
  591. /*
  592. * We don't use STS_FLR, but some controllers don't like it to
  593. * remain on, so mask it out along with the other status bits.
  594. */
  595. masked_status = status & (INTR_MASK | STS_FLR);
  596. /* Shared IRQ? */
  597. if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
  598. spin_unlock(&ehci->lock);
  599. return IRQ_NONE;
  600. }
  601. /* clear (just) interrupts */
  602. ehci_writel(ehci, masked_status, &ehci->regs->status);
  603. cmd = ehci_readl(ehci, &ehci->regs->command);
  604. bh = 0;
  605. #ifdef VERBOSE_DEBUG
  606. /* unrequested/ignored: Frame List Rollover */
  607. dbg_status (ehci, "irq", status);
  608. #endif
  609. /* INT, ERR, and IAA interrupt rates can be throttled */
  610. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  611. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  612. if (likely ((status & STS_ERR) == 0))
  613. COUNT (ehci->stats.normal);
  614. else
  615. COUNT (ehci->stats.error);
  616. bh = 1;
  617. }
  618. /* complete the unlinking of some qh [4.15.2.3] */
  619. if (status & STS_IAA) {
  620. /* Turn off the IAA watchdog */
  621. ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
  622. /*
  623. * Mild optimization: Allow another IAAD to reset the
  624. * hrtimer, if one occurs before the next expiration.
  625. * In theory we could always cancel the hrtimer, but
  626. * tests show that about half the time it will be reset
  627. * for some other event anyway.
  628. */
  629. if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
  630. ++ehci->next_hrtimer_event;
  631. /* guard against (alleged) silicon errata */
  632. if (cmd & CMD_IAAD)
  633. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  634. if (ehci->iaa_in_progress)
  635. COUNT(ehci->stats.iaa);
  636. end_unlink_async(ehci);
  637. }
  638. /* remote wakeup [4.3.1] */
  639. if (status & STS_PCD) {
  640. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  641. u32 ppcd = ~0;
  642. /* kick root hub later */
  643. pcd_status = status;
  644. /* resume root hub? */
  645. if (ehci->rh_state == EHCI_RH_SUSPENDED)
  646. usb_hcd_resume_root_hub(hcd);
  647. /* get per-port change detect bits */
  648. if (ehci->has_ppcd)
  649. ppcd = status >> 16;
  650. while (i--) {
  651. int pstatus;
  652. /* leverage per-port change bits feature */
  653. if (!(ppcd & (1 << i)))
  654. continue;
  655. pstatus = ehci_readl(ehci,
  656. &ehci->regs->port_status[i]);
  657. if (pstatus & PORT_OWNER)
  658. continue;
  659. if (!(test_bit(i, &ehci->suspended_ports) &&
  660. ((pstatus & PORT_RESUME) ||
  661. !(pstatus & PORT_SUSPEND)) &&
  662. (pstatus & PORT_PE) &&
  663. ehci->reset_done[i] == 0))
  664. continue;
  665. /* start 20 msec resume signaling from this port,
  666. * and make khubd collect PORT_STAT_C_SUSPEND to
  667. * stop that signaling. Use 5 ms extra for safety,
  668. * like usb_port_resume() does.
  669. */
  670. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  671. set_bit(i, &ehci->resuming_ports);
  672. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  673. usb_hcd_start_port_resume(&hcd->self, i);
  674. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  675. }
  676. }
  677. /* PCI errors [4.15.2.4] */
  678. if (unlikely ((status & STS_FATAL) != 0)) {
  679. ehci_err(ehci, "fatal error\n");
  680. dbg_cmd(ehci, "fatal", cmd);
  681. dbg_status(ehci, "fatal", status);
  682. dead:
  683. usb_hc_died(hcd);
  684. /* Don't let the controller do anything more */
  685. ehci->shutdown = true;
  686. ehci->rh_state = EHCI_RH_STOPPING;
  687. ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
  688. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  689. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  690. ehci_handle_controller_death(ehci);
  691. /* Handle completions when the controller stops */
  692. bh = 0;
  693. }
  694. if (bh)
  695. ehci_work (ehci);
  696. spin_unlock (&ehci->lock);
  697. if (pcd_status)
  698. usb_hcd_poll_rh_status(hcd);
  699. return IRQ_HANDLED;
  700. }
  701. /*-------------------------------------------------------------------------*/
  702. /*
  703. * non-error returns are a promise to giveback() the urb later
  704. * we drop ownership so next owner (or urb unlink) can get it
  705. *
  706. * urb + dev is in hcd.self.controller.urb_list
  707. * we're queueing TDs onto software and hardware lists
  708. *
  709. * hcd-specific init for hcpriv hasn't been done yet
  710. *
  711. * NOTE: control, bulk, and interrupt share the same code to append TDs
  712. * to a (possibly active) QH, and the same QH scanning code.
  713. */
  714. static int ehci_urb_enqueue (
  715. struct usb_hcd *hcd,
  716. struct urb *urb,
  717. gfp_t mem_flags
  718. ) {
  719. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  720. struct list_head qtd_list;
  721. INIT_LIST_HEAD (&qtd_list);
  722. switch (usb_pipetype (urb->pipe)) {
  723. case PIPE_CONTROL:
  724. /* qh_completions() code doesn't handle all the fault cases
  725. * in multi-TD control transfers. Even 1KB is rare anyway.
  726. */
  727. if (urb->transfer_buffer_length > (16 * 1024))
  728. return -EMSGSIZE;
  729. /* FALLTHROUGH */
  730. /* case PIPE_BULK: */
  731. default:
  732. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  733. return -ENOMEM;
  734. return submit_async(ehci, urb, &qtd_list, mem_flags);
  735. case PIPE_INTERRUPT:
  736. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  737. return -ENOMEM;
  738. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  739. case PIPE_ISOCHRONOUS:
  740. if (urb->dev->speed == USB_SPEED_HIGH)
  741. return itd_submit (ehci, urb, mem_flags);
  742. else
  743. return sitd_submit (ehci, urb, mem_flags);
  744. }
  745. }
  746. /* remove from hardware lists
  747. * completions normally happen asynchronously
  748. */
  749. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  750. {
  751. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  752. struct ehci_qh *qh;
  753. unsigned long flags;
  754. int rc;
  755. spin_lock_irqsave (&ehci->lock, flags);
  756. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  757. if (rc)
  758. goto done;
  759. if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  760. /*
  761. * We don't expedite dequeue for isochronous URBs.
  762. * Just wait until they complete normally or their
  763. * time slot expires.
  764. */
  765. } else {
  766. qh = (struct ehci_qh *) urb->hcpriv;
  767. qh->exception = 1;
  768. switch (qh->qh_state) {
  769. case QH_STATE_LINKED:
  770. if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
  771. start_unlink_intr(ehci, qh);
  772. else
  773. start_unlink_async(ehci, qh);
  774. break;
  775. case QH_STATE_COMPLETING:
  776. qh->dequeue_during_giveback = 1;
  777. break;
  778. case QH_STATE_UNLINK:
  779. case QH_STATE_UNLINK_WAIT:
  780. /* already started */
  781. break;
  782. case QH_STATE_IDLE:
  783. /* QH might be waiting for a Clear-TT-Buffer */
  784. qh_completions(ehci, qh);
  785. break;
  786. }
  787. }
  788. done:
  789. spin_unlock_irqrestore (&ehci->lock, flags);
  790. return rc;
  791. }
  792. /*-------------------------------------------------------------------------*/
  793. // bulk qh holds the data toggle
  794. static void
  795. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  796. {
  797. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  798. unsigned long flags;
  799. struct ehci_qh *qh, *tmp;
  800. /* ASSERT: any requests/urbs are being unlinked */
  801. /* ASSERT: nobody can be submitting urbs for this any more */
  802. rescan:
  803. spin_lock_irqsave (&ehci->lock, flags);
  804. qh = ep->hcpriv;
  805. if (!qh)
  806. goto done;
  807. /* endpoints can be iso streams. for now, we don't
  808. * accelerate iso completions ... so spin a while.
  809. */
  810. if (qh->hw == NULL) {
  811. struct ehci_iso_stream *stream = ep->hcpriv;
  812. if (!list_empty(&stream->td_list))
  813. goto idle_timeout;
  814. /* BUG_ON(!list_empty(&stream->free_list)); */
  815. kfree(stream);
  816. goto done;
  817. }
  818. qh->exception = 1;
  819. if (ehci->rh_state < EHCI_RH_RUNNING)
  820. qh->qh_state = QH_STATE_IDLE;
  821. switch (qh->qh_state) {
  822. case QH_STATE_LINKED:
  823. case QH_STATE_COMPLETING:
  824. for (tmp = ehci->async->qh_next.qh;
  825. tmp && tmp != qh;
  826. tmp = tmp->qh_next.qh)
  827. continue;
  828. /* periodic qh self-unlinks on empty, and a COMPLETING qh
  829. * may already be unlinked.
  830. */
  831. if (tmp)
  832. start_unlink_async(ehci, qh);
  833. /* FALL THROUGH */
  834. case QH_STATE_UNLINK: /* wait for hw to finish? */
  835. case QH_STATE_UNLINK_WAIT:
  836. idle_timeout:
  837. spin_unlock_irqrestore (&ehci->lock, flags);
  838. schedule_timeout_uninterruptible(1);
  839. goto rescan;
  840. case QH_STATE_IDLE: /* fully unlinked */
  841. if (qh->clearing_tt)
  842. goto idle_timeout;
  843. if (list_empty (&qh->qtd_list)) {
  844. qh_destroy(ehci, qh);
  845. break;
  846. }
  847. /* else FALL THROUGH */
  848. default:
  849. /* caller was supposed to have unlinked any requests;
  850. * that's not our job. just leak this memory.
  851. */
  852. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  853. qh, ep->desc.bEndpointAddress, qh->qh_state,
  854. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  855. break;
  856. }
  857. done:
  858. ep->hcpriv = NULL;
  859. spin_unlock_irqrestore (&ehci->lock, flags);
  860. }
  861. static void
  862. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  863. {
  864. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  865. struct ehci_qh *qh;
  866. int eptype = usb_endpoint_type(&ep->desc);
  867. int epnum = usb_endpoint_num(&ep->desc);
  868. int is_out = usb_endpoint_dir_out(&ep->desc);
  869. unsigned long flags;
  870. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  871. return;
  872. spin_lock_irqsave(&ehci->lock, flags);
  873. qh = ep->hcpriv;
  874. /* For Bulk and Interrupt endpoints we maintain the toggle state
  875. * in the hardware; the toggle bits in udev aren't used at all.
  876. * When an endpoint is reset by usb_clear_halt() we must reset
  877. * the toggle bit in the QH.
  878. */
  879. if (qh) {
  880. usb_settoggle(qh->dev, epnum, is_out, 0);
  881. if (!list_empty(&qh->qtd_list)) {
  882. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  883. } else {
  884. /* The toggle value in the QH can't be updated
  885. * while the QH is active. Unlink it now;
  886. * re-linking will call qh_refresh().
  887. */
  888. qh->exception = 1;
  889. if (eptype == USB_ENDPOINT_XFER_BULK)
  890. start_unlink_async(ehci, qh);
  891. else
  892. start_unlink_intr(ehci, qh);
  893. }
  894. }
  895. spin_unlock_irqrestore(&ehci->lock, flags);
  896. }
  897. static int ehci_get_frame (struct usb_hcd *hcd)
  898. {
  899. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  900. return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
  901. }
  902. /*-------------------------------------------------------------------------*/
  903. #ifdef CONFIG_PM
  904. /* suspend/resume, section 4.3 */
  905. /* These routines handle the generic parts of controller suspend/resume */
  906. int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  907. {
  908. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  909. if (time_before(jiffies, ehci->next_statechange))
  910. msleep(10);
  911. /*
  912. * Root hub was already suspended. Disable IRQ emission and
  913. * mark HW unaccessible. The PM and USB cores make sure that
  914. * the root hub is either suspended or stopped.
  915. */
  916. ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
  917. spin_lock_irq(&ehci->lock);
  918. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  919. (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  920. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  921. spin_unlock_irq(&ehci->lock);
  922. return 0;
  923. }
  924. EXPORT_SYMBOL_GPL(ehci_suspend);
  925. /* Returns 0 if power was preserved, 1 if power was lost */
  926. int ehci_resume(struct usb_hcd *hcd, bool hibernated)
  927. {
  928. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  929. if (time_before(jiffies, ehci->next_statechange))
  930. msleep(100);
  931. /* Mark hardware accessible again as we are back to full power by now */
  932. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  933. if (ehci->shutdown)
  934. return 0; /* Controller is dead */
  935. /*
  936. * If CF is still set and we aren't resuming from hibernation
  937. * then we maintained suspend power.
  938. * Just undo the effect of ehci_suspend().
  939. */
  940. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  941. !hibernated) {
  942. int mask = INTR_MASK;
  943. ehci_prepare_ports_for_controller_resume(ehci);
  944. spin_lock_irq(&ehci->lock);
  945. if (ehci->shutdown)
  946. goto skip;
  947. if (!hcd->self.root_hub->do_remote_wakeup)
  948. mask &= ~STS_PCD;
  949. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  950. ehci_readl(ehci, &ehci->regs->intr_enable);
  951. skip:
  952. spin_unlock_irq(&ehci->lock);
  953. return 0;
  954. }
  955. /*
  956. * Else reset, to cope with power loss or resume from hibernation
  957. * having let the firmware kick in during reboot.
  958. */
  959. usb_root_hub_lost_power(hcd->self.root_hub);
  960. (void) ehci_halt(ehci);
  961. (void) ehci_reset(ehci);
  962. spin_lock_irq(&ehci->lock);
  963. if (ehci->shutdown)
  964. goto skip;
  965. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  966. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  967. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  968. ehci->rh_state = EHCI_RH_SUSPENDED;
  969. spin_unlock_irq(&ehci->lock);
  970. return 1;
  971. }
  972. EXPORT_SYMBOL_GPL(ehci_resume);
  973. #endif
  974. /*-------------------------------------------------------------------------*/
  975. /*
  976. * Generic structure: This gets copied for platform drivers so that
  977. * individual entries can be overridden as needed.
  978. */
  979. static const struct hc_driver ehci_hc_driver = {
  980. .description = hcd_name,
  981. .product_desc = "EHCI Host Controller",
  982. .hcd_priv_size = sizeof(struct ehci_hcd),
  983. /*
  984. * generic hardware linkage
  985. */
  986. .irq = ehci_irq,
  987. .flags = HCD_MEMORY | HCD_USB2,
  988. /*
  989. * basic lifecycle operations
  990. */
  991. .reset = ehci_setup,
  992. .start = ehci_run,
  993. .stop = ehci_stop,
  994. .shutdown = ehci_shutdown,
  995. /*
  996. * managing i/o requests and associated device resources
  997. */
  998. .urb_enqueue = ehci_urb_enqueue,
  999. .urb_dequeue = ehci_urb_dequeue,
  1000. .endpoint_disable = ehci_endpoint_disable,
  1001. .endpoint_reset = ehci_endpoint_reset,
  1002. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  1003. /*
  1004. * scheduling support
  1005. */
  1006. .get_frame_number = ehci_get_frame,
  1007. /*
  1008. * root hub support
  1009. */
  1010. .hub_status_data = ehci_hub_status_data,
  1011. .hub_control = ehci_hub_control,
  1012. .bus_suspend = ehci_bus_suspend,
  1013. .bus_resume = ehci_bus_resume,
  1014. .relinquish_port = ehci_relinquish_port,
  1015. .port_handed_over = ehci_port_handed_over,
  1016. };
  1017. void ehci_init_driver(struct hc_driver *drv,
  1018. const struct ehci_driver_overrides *over)
  1019. {
  1020. /* Copy the generic table to drv and then apply the overrides */
  1021. *drv = ehci_hc_driver;
  1022. if (over) {
  1023. drv->hcd_priv_size += over->extra_priv_size;
  1024. if (over->reset)
  1025. drv->reset = over->reset;
  1026. }
  1027. }
  1028. EXPORT_SYMBOL_GPL(ehci_init_driver);
  1029. /*-------------------------------------------------------------------------*/
  1030. MODULE_DESCRIPTION(DRIVER_DESC);
  1031. MODULE_AUTHOR (DRIVER_AUTHOR);
  1032. MODULE_LICENSE ("GPL");
  1033. #ifdef CONFIG_USB_EHCI_FSL
  1034. #include "ehci-fsl.c"
  1035. #define PLATFORM_DRIVER ehci_fsl_driver
  1036. #endif
  1037. #ifdef CONFIG_USB_EHCI_SH
  1038. #include "ehci-sh.c"
  1039. #define PLATFORM_DRIVER ehci_hcd_sh_driver
  1040. #endif
  1041. #ifdef CONFIG_PPC_PS3
  1042. #include "ehci-ps3.c"
  1043. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  1044. #endif
  1045. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  1046. #include "ehci-ppc-of.c"
  1047. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  1048. #endif
  1049. #ifdef CONFIG_XPS_USB_HCD_XILINX
  1050. #include "ehci-xilinx-of.c"
  1051. #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  1052. #endif
  1053. #ifdef CONFIG_USB_W90X900_EHCI
  1054. #include "ehci-w90x900.c"
  1055. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  1056. #endif
  1057. #ifdef CONFIG_USB_OCTEON_EHCI
  1058. #include "ehci-octeon.c"
  1059. #define PLATFORM_DRIVER ehci_octeon_driver
  1060. #endif
  1061. #ifdef CONFIG_TILE_USB
  1062. #include "ehci-tilegx.c"
  1063. #define PLATFORM_DRIVER ehci_hcd_tilegx_driver
  1064. #endif
  1065. #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
  1066. #include "ehci-pmcmsp.c"
  1067. #define PLATFORM_DRIVER ehci_hcd_msp_driver
  1068. #endif
  1069. #ifdef CONFIG_SPARC_LEON
  1070. #include "ehci-grlib.c"
  1071. #define PLATFORM_DRIVER ehci_grlib_driver
  1072. #endif
  1073. #ifdef CONFIG_USB_EHCI_MV
  1074. #include "ehci-mv.c"
  1075. #define PLATFORM_DRIVER ehci_mv_driver
  1076. #endif
  1077. #ifdef CONFIG_MIPS_SEAD3
  1078. #include "ehci-sead3.c"
  1079. #define PLATFORM_DRIVER ehci_hcd_sead3_driver
  1080. #endif
  1081. static int __init ehci_hcd_init(void)
  1082. {
  1083. int retval = 0;
  1084. if (usb_disabled())
  1085. return -ENODEV;
  1086. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1087. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1088. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1089. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1090. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1091. " before uhci_hcd and ohci_hcd, not after\n");
  1092. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1093. hcd_name,
  1094. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1095. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1096. #ifdef DEBUG
  1097. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1098. if (!ehci_debug_root) {
  1099. retval = -ENOENT;
  1100. goto err_debug;
  1101. }
  1102. #endif
  1103. #ifdef PLATFORM_DRIVER
  1104. retval = platform_driver_register(&PLATFORM_DRIVER);
  1105. if (retval < 0)
  1106. goto clean0;
  1107. #endif
  1108. #ifdef PS3_SYSTEM_BUS_DRIVER
  1109. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1110. if (retval < 0)
  1111. goto clean2;
  1112. #endif
  1113. #ifdef OF_PLATFORM_DRIVER
  1114. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1115. if (retval < 0)
  1116. goto clean3;
  1117. #endif
  1118. #ifdef XILINX_OF_PLATFORM_DRIVER
  1119. retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
  1120. if (retval < 0)
  1121. goto clean4;
  1122. #endif
  1123. return retval;
  1124. #ifdef XILINX_OF_PLATFORM_DRIVER
  1125. /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
  1126. clean4:
  1127. #endif
  1128. #ifdef OF_PLATFORM_DRIVER
  1129. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1130. clean3:
  1131. #endif
  1132. #ifdef PS3_SYSTEM_BUS_DRIVER
  1133. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1134. clean2:
  1135. #endif
  1136. #ifdef PLATFORM_DRIVER
  1137. platform_driver_unregister(&PLATFORM_DRIVER);
  1138. clean0:
  1139. #endif
  1140. #ifdef DEBUG
  1141. debugfs_remove(ehci_debug_root);
  1142. ehci_debug_root = NULL;
  1143. err_debug:
  1144. #endif
  1145. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1146. return retval;
  1147. }
  1148. module_init(ehci_hcd_init);
  1149. static void __exit ehci_hcd_cleanup(void)
  1150. {
  1151. #ifdef XILINX_OF_PLATFORM_DRIVER
  1152. platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
  1153. #endif
  1154. #ifdef OF_PLATFORM_DRIVER
  1155. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1156. #endif
  1157. #ifdef PLATFORM_DRIVER
  1158. platform_driver_unregister(&PLATFORM_DRIVER);
  1159. #endif
  1160. #ifdef PS3_SYSTEM_BUS_DRIVER
  1161. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1162. #endif
  1163. #ifdef DEBUG
  1164. debugfs_remove(ehci_debug_root);
  1165. #endif
  1166. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1167. }
  1168. module_exit(ehci_hcd_cleanup);