ehci-hcd.c 37 KB

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