ehci-hcd.c 34 KB

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