ehci-hcd.c 37 KB

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