ehci-hcd.c 39 KB

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