ehci-hcd.c 39 KB

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