ehci-hcd.c 38 KB

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