ehci-hcd.c 39 KB

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