ehci-hcd.c 36 KB

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