ehci-hcd.c 40 KB

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