ehci-hcd.c 37 KB

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