ehci-hcd.c 39 KB

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