ehci-hcd.c 38 KB

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