ehci-hcd.c 39 KB

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