ehci-hcd.c 34 KB

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