ehci-hcd.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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/hrtimer.h>
  33. #include <linux/list.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/usb.h>
  36. #include <linux/usb/hcd.h>
  37. #include <linux/moduleparam.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/slab.h>
  41. #include <asm/byteorder.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #include <asm/unaligned.h>
  45. #if defined(CONFIG_PPC_PS3)
  46. #include <asm/firmware.h>
  47. #endif
  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. /* magic numbers that can affect system performance */
  68. #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
  69. #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
  70. #define EHCI_TUNE_RL_TT 0
  71. #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
  72. #define EHCI_TUNE_MULT_TT 1
  73. /*
  74. * Some drivers think it's safe to schedule isochronous transfers more than
  75. * 256 ms into the future (partly as a result of an old bug in the scheduling
  76. * code). In an attempt to avoid trouble, we will use a minimum scheduling
  77. * length of 512 frames instead of 256.
  78. */
  79. #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
  80. /* Initial IRQ latency: faster than hw default */
  81. static int log2_irq_thresh = 0; // 0 to 6
  82. module_param (log2_irq_thresh, int, S_IRUGO);
  83. MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
  84. /* initial park setting: slower than hw default */
  85. static unsigned park = 0;
  86. module_param (park, uint, S_IRUGO);
  87. MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
  88. /* for flakey hardware, ignore overcurrent indicators */
  89. static bool ignore_oc = 0;
  90. module_param (ignore_oc, bool, S_IRUGO);
  91. MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
  92. #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  93. /*-------------------------------------------------------------------------*/
  94. #include "ehci.h"
  95. #include "pci-quirks.h"
  96. /*
  97. * The MosChip MCS9990 controller updates its microframe counter
  98. * a little before the frame counter, and occasionally we will read
  99. * the invalid intermediate value. Avoid problems by checking the
  100. * microframe number (the low-order 3 bits); if they are 0 then
  101. * re-read the register to get the correct value.
  102. */
  103. static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
  104. {
  105. unsigned uf;
  106. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  107. if (unlikely((uf & 7) == 0))
  108. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  109. return uf;
  110. }
  111. static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
  112. {
  113. if (ehci->frame_index_bug)
  114. return ehci_moschip_read_frame_index(ehci);
  115. return ehci_readl(ehci, &ehci->regs->frame_index);
  116. }
  117. #include "ehci-dbg.c"
  118. /*-------------------------------------------------------------------------*/
  119. /*
  120. * handshake - spin reading hc until handshake completes or fails
  121. * @ptr: address of hc register to be read
  122. * @mask: bits to look at in result of read
  123. * @done: value of those bits when handshake succeeds
  124. * @usec: timeout in microseconds
  125. *
  126. * Returns negative errno, or zero on success
  127. *
  128. * Success happens when the "mask" bits have the specified value (hardware
  129. * handshake done). There are two failure modes: "usec" have passed (major
  130. * hardware flakeout), or the register reads as all-ones (hardware removed).
  131. *
  132. * That last failure should_only happen in cases like physical cardbus eject
  133. * before driver shutdown. But it also seems to be caused by bugs in cardbus
  134. * bridge shutdown: shutting down the bridge before the devices using it.
  135. */
  136. static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
  137. u32 mask, u32 done, int usec)
  138. {
  139. u32 result;
  140. do {
  141. result = ehci_readl(ehci, ptr);
  142. if (result == ~(u32)0) /* card removed */
  143. return -ENODEV;
  144. result &= mask;
  145. if (result == done)
  146. return 0;
  147. udelay (1);
  148. usec--;
  149. } while (usec > 0);
  150. return -ETIMEDOUT;
  151. }
  152. /* check TDI/ARC silicon is in host mode */
  153. static int tdi_in_host_mode (struct ehci_hcd *ehci)
  154. {
  155. u32 tmp;
  156. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  157. return (tmp & 3) == USBMODE_CM_HC;
  158. }
  159. /*
  160. * Force HC to halt state from unknown (EHCI spec section 2.3).
  161. * Must be called with interrupts enabled and the lock not held.
  162. */
  163. static int ehci_halt (struct ehci_hcd *ehci)
  164. {
  165. u32 temp;
  166. spin_lock_irq(&ehci->lock);
  167. /* disable any irqs left enabled by previous code */
  168. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  169. if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
  170. spin_unlock_irq(&ehci->lock);
  171. return 0;
  172. }
  173. /*
  174. * This routine gets called during probe before ehci->command
  175. * has been initialized, so we can't rely on its value.
  176. */
  177. ehci->command &= ~CMD_RUN;
  178. temp = ehci_readl(ehci, &ehci->regs->command);
  179. temp &= ~(CMD_RUN | CMD_IAAD);
  180. ehci_writel(ehci, temp, &ehci->regs->command);
  181. spin_unlock_irq(&ehci->lock);
  182. synchronize_irq(ehci_to_hcd(ehci)->irq);
  183. return handshake(ehci, &ehci->regs->status,
  184. STS_HALT, STS_HALT, 16 * 125);
  185. }
  186. /* put TDI/ARC silicon into EHCI mode */
  187. static void tdi_reset (struct ehci_hcd *ehci)
  188. {
  189. u32 tmp;
  190. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  191. tmp |= USBMODE_CM_HC;
  192. /* The default byte access to MMR space is LE after
  193. * controller reset. Set the required endian mode
  194. * for transfer buffers to match the host microprocessor
  195. */
  196. if (ehci_big_endian_mmio(ehci))
  197. tmp |= USBMODE_BE;
  198. ehci_writel(ehci, tmp, &ehci->regs->usbmode);
  199. }
  200. /*
  201. * Reset a non-running (STS_HALT == 1) controller.
  202. * Must be called with interrupts enabled and the lock not held.
  203. */
  204. static int ehci_reset (struct ehci_hcd *ehci)
  205. {
  206. int retval;
  207. u32 command = ehci_readl(ehci, &ehci->regs->command);
  208. /* If the EHCI debug controller is active, special care must be
  209. * taken before and after a host controller reset */
  210. if (ehci->debug && !dbgp_reset_prep(ehci_to_hcd(ehci)))
  211. ehci->debug = NULL;
  212. command |= CMD_RESET;
  213. dbg_cmd (ehci, "reset", command);
  214. ehci_writel(ehci, command, &ehci->regs->command);
  215. ehci->rh_state = EHCI_RH_HALTED;
  216. ehci->next_statechange = jiffies;
  217. retval = handshake (ehci, &ehci->regs->command,
  218. CMD_RESET, 0, 250 * 1000);
  219. if (ehci->has_hostpc) {
  220. ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
  221. &ehci->regs->usbmode_ex);
  222. ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
  223. }
  224. if (retval)
  225. return retval;
  226. if (ehci_is_TDI(ehci))
  227. tdi_reset (ehci);
  228. if (ehci->debug)
  229. dbgp_external_startup(ehci_to_hcd(ehci));
  230. ehci->port_c_suspend = ehci->suspended_ports =
  231. ehci->resuming_ports = 0;
  232. return retval;
  233. }
  234. /*
  235. * Idle the controller (turn off the schedules).
  236. * Must be called with interrupts enabled and the lock not held.
  237. */
  238. static void ehci_quiesce (struct ehci_hcd *ehci)
  239. {
  240. u32 temp;
  241. if (ehci->rh_state != EHCI_RH_RUNNING)
  242. return;
  243. /* wait for any schedule enables/disables to take effect */
  244. temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
  245. handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp, 16 * 125);
  246. /* then disable anything that's still active */
  247. spin_lock_irq(&ehci->lock);
  248. ehci->command &= ~(CMD_ASE | CMD_PSE);
  249. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  250. spin_unlock_irq(&ehci->lock);
  251. /* hardware can take 16 microframes to turn off ... */
  252. handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0, 16 * 125);
  253. }
  254. /*-------------------------------------------------------------------------*/
  255. static void end_unlink_async(struct ehci_hcd *ehci);
  256. static void unlink_empty_async(struct ehci_hcd *ehci);
  257. static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
  258. static void ehci_work(struct ehci_hcd *ehci);
  259. static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  260. static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  261. #include "ehci-timer.c"
  262. #include "ehci-hub.c"
  263. #include "ehci-mem.c"
  264. #include "ehci-q.c"
  265. #include "ehci-sched.c"
  266. #include "ehci-sysfs.c"
  267. /*-------------------------------------------------------------------------*/
  268. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  269. * The firmware seems to think that powering off is a wakeup event!
  270. * This routine turns off remote wakeup and everything else, on all ports.
  271. */
  272. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  273. {
  274. int port = HCS_N_PORTS(ehci->hcs_params);
  275. while (port--)
  276. ehci_writel(ehci, PORT_RWC_BITS,
  277. &ehci->regs->port_status[port]);
  278. }
  279. /*
  280. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  281. * Must be called with interrupts enabled and the lock not held.
  282. */
  283. static void ehci_silence_controller(struct ehci_hcd *ehci)
  284. {
  285. ehci_halt(ehci);
  286. spin_lock_irq(&ehci->lock);
  287. ehci->rh_state = EHCI_RH_HALTED;
  288. ehci_turn_off_all_ports(ehci);
  289. /* make BIOS/etc use companion controller during reboot */
  290. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  291. /* unblock posted writes */
  292. ehci_readl(ehci, &ehci->regs->configured_flag);
  293. spin_unlock_irq(&ehci->lock);
  294. }
  295. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  296. * This forcibly disables dma and IRQs, helping kexec and other cases
  297. * where the next system software may expect clean state.
  298. */
  299. static void ehci_shutdown(struct usb_hcd *hcd)
  300. {
  301. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  302. spin_lock_irq(&ehci->lock);
  303. ehci->shutdown = true;
  304. ehci->rh_state = EHCI_RH_STOPPING;
  305. ehci->enabled_hrtimer_events = 0;
  306. spin_unlock_irq(&ehci->lock);
  307. ehci_silence_controller(ehci);
  308. hrtimer_cancel(&ehci->hrtimer);
  309. }
  310. /*-------------------------------------------------------------------------*/
  311. /*
  312. * ehci_work is called from some interrupts, timers, and so on.
  313. * it calls driver completion functions, after dropping ehci->lock.
  314. */
  315. static void ehci_work (struct ehci_hcd *ehci)
  316. {
  317. /* another CPU may drop ehci->lock during a schedule scan while
  318. * it reports urb completions. this flag guards against bogus
  319. * attempts at re-entrant schedule scanning.
  320. */
  321. if (ehci->scanning) {
  322. ehci->need_rescan = true;
  323. return;
  324. }
  325. ehci->scanning = true;
  326. rescan:
  327. ehci->need_rescan = false;
  328. if (ehci->async_count)
  329. scan_async(ehci);
  330. if (ehci->intr_count > 0)
  331. scan_intr(ehci);
  332. if (ehci->isoc_count > 0)
  333. scan_isoc(ehci);
  334. if (ehci->need_rescan)
  335. goto rescan;
  336. ehci->scanning = false;
  337. /* the IO watchdog guards against hardware or driver bugs that
  338. * misplace IRQs, and should let us run completely without IRQs.
  339. * such lossage has been observed on both VT6202 and VT8235.
  340. */
  341. turn_on_io_watchdog(ehci);
  342. }
  343. /*
  344. * Called when the ehci_hcd module is removed.
  345. */
  346. static void ehci_stop (struct usb_hcd *hcd)
  347. {
  348. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  349. ehci_dbg (ehci, "stop\n");
  350. /* no more interrupts ... */
  351. spin_lock_irq(&ehci->lock);
  352. ehci->enabled_hrtimer_events = 0;
  353. spin_unlock_irq(&ehci->lock);
  354. ehci_quiesce(ehci);
  355. ehci_silence_controller(ehci);
  356. ehci_reset (ehci);
  357. hrtimer_cancel(&ehci->hrtimer);
  358. remove_sysfs_files(ehci);
  359. remove_debug_files (ehci);
  360. /* root hub is shut down separately (first, when possible) */
  361. spin_lock_irq (&ehci->lock);
  362. end_free_itds(ehci);
  363. spin_unlock_irq (&ehci->lock);
  364. ehci_mem_cleanup (ehci);
  365. if (ehci->amd_pll_fix == 1)
  366. usb_amd_dev_put();
  367. #ifdef EHCI_STATS
  368. ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
  369. ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
  370. ehci->stats.lost_iaa);
  371. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  372. ehci->stats.complete, ehci->stats.unlink);
  373. #endif
  374. dbg_status (ehci, "ehci_stop completed",
  375. ehci_readl(ehci, &ehci->regs->status));
  376. }
  377. /* one-time init, only for memory state */
  378. static int ehci_init(struct usb_hcd *hcd)
  379. {
  380. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  381. u32 temp;
  382. int retval;
  383. u32 hcc_params;
  384. struct ehci_qh_hw *hw;
  385. spin_lock_init(&ehci->lock);
  386. /*
  387. * keep io watchdog by default, those good HCDs could turn off it later
  388. */
  389. ehci->need_io_watchdog = 1;
  390. hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  391. ehci->hrtimer.function = ehci_hrtimer_func;
  392. ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  393. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  394. /*
  395. * by default set standard 80% (== 100 usec/uframe) max periodic
  396. * bandwidth as required by USB 2.0
  397. */
  398. ehci->uframe_periodic_max = 100;
  399. /*
  400. * hw default: 1K periodic list heads, one per frame.
  401. * periodic_size can shrink by USBCMD update if hcc_params allows.
  402. */
  403. ehci->periodic_size = DEFAULT_I_TDPS;
  404. INIT_LIST_HEAD(&ehci->async_unlink);
  405. INIT_LIST_HEAD(&ehci->async_idle);
  406. INIT_LIST_HEAD(&ehci->intr_unlink);
  407. INIT_LIST_HEAD(&ehci->intr_qh_list);
  408. INIT_LIST_HEAD(&ehci->cached_itd_list);
  409. INIT_LIST_HEAD(&ehci->cached_sitd_list);
  410. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  411. /* periodic schedule size can be smaller than default */
  412. switch (EHCI_TUNE_FLS) {
  413. case 0: ehci->periodic_size = 1024; break;
  414. case 1: ehci->periodic_size = 512; break;
  415. case 2: ehci->periodic_size = 256; break;
  416. default: BUG();
  417. }
  418. }
  419. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  420. return retval;
  421. /* controllers may cache some of the periodic schedule ... */
  422. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  423. ehci->i_thresh = 0;
  424. else // N microframes cached
  425. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  426. /*
  427. * dedicate a qh for the async ring head, since we couldn't unlink
  428. * a 'real' qh without stopping the async schedule [4.8]. use it
  429. * as the 'reclamation list head' too.
  430. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  431. * from automatically advancing to the next td after short reads.
  432. */
  433. ehci->async->qh_next.qh = NULL;
  434. hw = ehci->async->hw;
  435. hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  436. hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  437. #if defined(CONFIG_PPC_PS3)
  438. hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
  439. #endif
  440. hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  441. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  442. ehci->async->qh_state = QH_STATE_LINKED;
  443. hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  444. /* clear interrupt enables, set irq latency */
  445. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  446. log2_irq_thresh = 0;
  447. temp = 1 << (16 + log2_irq_thresh);
  448. if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
  449. ehci->has_ppcd = 1;
  450. ehci_dbg(ehci, "enable per-port change event\n");
  451. temp |= CMD_PPCEE;
  452. }
  453. if (HCC_CANPARK(hcc_params)) {
  454. /* HW default park == 3, on hardware that supports it (like
  455. * NVidia and ALI silicon), maximizes throughput on the async
  456. * schedule by avoiding QH fetches between transfers.
  457. *
  458. * With fast usb storage devices and NForce2, "park" seems to
  459. * make problems: throughput reduction (!), data errors...
  460. */
  461. if (park) {
  462. park = min(park, (unsigned) 3);
  463. temp |= CMD_PARK;
  464. temp |= park << 8;
  465. }
  466. ehci_dbg(ehci, "park %d\n", park);
  467. }
  468. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  469. /* periodic schedule size can be smaller than default */
  470. temp &= ~(3 << 2);
  471. temp |= (EHCI_TUNE_FLS << 2);
  472. }
  473. ehci->command = temp;
  474. /* Accept arbitrarily long scatter-gather lists */
  475. if (!(hcd->driver->flags & HCD_LOCAL_MEM))
  476. hcd->self.sg_tablesize = ~0;
  477. return 0;
  478. }
  479. /* start HC running; it's halted, ehci_init() has been run (once) */
  480. static int ehci_run (struct usb_hcd *hcd)
  481. {
  482. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  483. u32 temp;
  484. u32 hcc_params;
  485. hcd->uses_new_polling = 1;
  486. /* EHCI spec section 4.1 */
  487. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  488. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  489. /*
  490. * hcc_params controls whether ehci->regs->segment must (!!!)
  491. * be used; it constrains QH/ITD/SITD and QTD locations.
  492. * pci_pool consistent memory always uses segment zero.
  493. * streaming mappings for I/O buffers, like pci_map_single(),
  494. * can return segments above 4GB, if the device allows.
  495. *
  496. * NOTE: the dma mask is visible through dma_supported(), so
  497. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  498. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  499. * host side drivers though.
  500. */
  501. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  502. if (HCC_64BIT_ADDR(hcc_params)) {
  503. ehci_writel(ehci, 0, &ehci->regs->segment);
  504. #if 0
  505. // this is deeply broken on almost all architectures
  506. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  507. ehci_info(ehci, "enabled 64bit DMA\n");
  508. #endif
  509. }
  510. // Philips, Intel, and maybe others need CMD_RUN before the
  511. // root hub will detect new devices (why?); NEC doesn't
  512. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  513. ehci->command |= CMD_RUN;
  514. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  515. dbg_cmd (ehci, "init", ehci->command);
  516. /*
  517. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  518. * are explicitly handed to companion controller(s), so no TT is
  519. * involved with the root hub. (Except where one is integrated,
  520. * and there's no companion controller unless maybe for USB OTG.)
  521. *
  522. * Turning on the CF flag will transfer ownership of all ports
  523. * from the companions to the EHCI controller. If any of the
  524. * companions are in the middle of a port reset at the time, it
  525. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  526. * guarantees that no resets are in progress. After we set CF,
  527. * a short delay lets the hardware catch up; new resets shouldn't
  528. * be started before the port switching actions could complete.
  529. */
  530. down_write(&ehci_cf_port_reset_rwsem);
  531. ehci->rh_state = EHCI_RH_RUNNING;
  532. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  533. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  534. msleep(5);
  535. up_write(&ehci_cf_port_reset_rwsem);
  536. ehci->last_periodic_enable = ktime_get_real();
  537. temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  538. ehci_info (ehci,
  539. "USB %x.%x started, EHCI %x.%02x%s\n",
  540. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  541. temp >> 8, temp & 0xff,
  542. ignore_oc ? ", overcurrent ignored" : "");
  543. ehci_writel(ehci, INTR_MASK,
  544. &ehci->regs->intr_enable); /* Turn On Interrupts */
  545. /* GRR this is run-once init(), being done every time the HC starts.
  546. * So long as they're part of class devices, we can't do it init()
  547. * since the class device isn't created that early.
  548. */
  549. create_debug_files(ehci);
  550. create_sysfs_files(ehci);
  551. return 0;
  552. }
  553. int ehci_setup(struct usb_hcd *hcd)
  554. {
  555. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  556. int retval;
  557. ehci->regs = (void __iomem *)ehci->caps +
  558. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  559. dbg_hcs_params(ehci, "reset");
  560. dbg_hcc_params(ehci, "reset");
  561. /* cache this readonly data; minimize chip reads */
  562. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  563. ehci->sbrn = HCD_USB2;
  564. /* data structure init */
  565. retval = ehci_init(hcd);
  566. if (retval)
  567. return retval;
  568. retval = ehci_halt(ehci);
  569. if (retval)
  570. return retval;
  571. ehci_reset(ehci);
  572. return 0;
  573. }
  574. EXPORT_SYMBOL_GPL(ehci_setup);
  575. /*-------------------------------------------------------------------------*/
  576. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  577. {
  578. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  579. u32 status, masked_status, pcd_status = 0, cmd;
  580. int bh;
  581. spin_lock (&ehci->lock);
  582. status = ehci_readl(ehci, &ehci->regs->status);
  583. /* e.g. cardbus physical eject */
  584. if (status == ~(u32) 0) {
  585. ehci_dbg (ehci, "device removed\n");
  586. goto dead;
  587. }
  588. /*
  589. * We don't use STS_FLR, but some controllers don't like it to
  590. * remain on, so mask it out along with the other status bits.
  591. */
  592. masked_status = status & (INTR_MASK | STS_FLR);
  593. /* Shared IRQ? */
  594. if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
  595. spin_unlock(&ehci->lock);
  596. return IRQ_NONE;
  597. }
  598. /* clear (just) interrupts */
  599. ehci_writel(ehci, masked_status, &ehci->regs->status);
  600. cmd = ehci_readl(ehci, &ehci->regs->command);
  601. bh = 0;
  602. #ifdef VERBOSE_DEBUG
  603. /* unrequested/ignored: Frame List Rollover */
  604. dbg_status (ehci, "irq", status);
  605. #endif
  606. /* INT, ERR, and IAA interrupt rates can be throttled */
  607. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  608. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  609. if (likely ((status & STS_ERR) == 0))
  610. COUNT (ehci->stats.normal);
  611. else
  612. COUNT (ehci->stats.error);
  613. bh = 1;
  614. }
  615. /* complete the unlinking of some qh [4.15.2.3] */
  616. if (status & STS_IAA) {
  617. /* Turn off the IAA watchdog */
  618. ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
  619. /*
  620. * Mild optimization: Allow another IAAD to reset the
  621. * hrtimer, if one occurs before the next expiration.
  622. * In theory we could always cancel the hrtimer, but
  623. * tests show that about half the time it will be reset
  624. * for some other event anyway.
  625. */
  626. if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
  627. ++ehci->next_hrtimer_event;
  628. /* guard against (alleged) silicon errata */
  629. if (cmd & CMD_IAAD)
  630. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  631. if (ehci->iaa_in_progress)
  632. COUNT(ehci->stats.iaa);
  633. end_unlink_async(ehci);
  634. }
  635. /* remote wakeup [4.3.1] */
  636. if (status & STS_PCD) {
  637. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  638. u32 ppcd = ~0;
  639. /* kick root hub later */
  640. pcd_status = status;
  641. /* resume root hub? */
  642. if (ehci->rh_state == EHCI_RH_SUSPENDED)
  643. usb_hcd_resume_root_hub(hcd);
  644. /* get per-port change detect bits */
  645. if (ehci->has_ppcd)
  646. ppcd = status >> 16;
  647. while (i--) {
  648. int pstatus;
  649. /* leverage per-port change bits feature */
  650. if (!(ppcd & (1 << i)))
  651. continue;
  652. pstatus = ehci_readl(ehci,
  653. &ehci->regs->port_status[i]);
  654. if (pstatus & PORT_OWNER)
  655. continue;
  656. if (!(test_bit(i, &ehci->suspended_ports) &&
  657. ((pstatus & PORT_RESUME) ||
  658. !(pstatus & PORT_SUSPEND)) &&
  659. (pstatus & PORT_PE) &&
  660. ehci->reset_done[i] == 0))
  661. continue;
  662. /* start 20 msec resume signaling from this port,
  663. * and make khubd collect PORT_STAT_C_SUSPEND to
  664. * stop that signaling. Use 5 ms extra for safety,
  665. * like usb_port_resume() does.
  666. */
  667. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  668. set_bit(i, &ehci->resuming_ports);
  669. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  670. usb_hcd_start_port_resume(&hcd->self, i);
  671. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  672. }
  673. }
  674. /* PCI errors [4.15.2.4] */
  675. if (unlikely ((status & STS_FATAL) != 0)) {
  676. ehci_err(ehci, "fatal error\n");
  677. dbg_cmd(ehci, "fatal", cmd);
  678. dbg_status(ehci, "fatal", status);
  679. dead:
  680. usb_hc_died(hcd);
  681. /* Don't let the controller do anything more */
  682. ehci->shutdown = true;
  683. ehci->rh_state = EHCI_RH_STOPPING;
  684. ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
  685. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  686. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  687. ehci_handle_controller_death(ehci);
  688. /* Handle completions when the controller stops */
  689. bh = 0;
  690. }
  691. if (bh)
  692. ehci_work (ehci);
  693. spin_unlock (&ehci->lock);
  694. if (pcd_status)
  695. usb_hcd_poll_rh_status(hcd);
  696. return IRQ_HANDLED;
  697. }
  698. /*-------------------------------------------------------------------------*/
  699. /*
  700. * non-error returns are a promise to giveback() the urb later
  701. * we drop ownership so next owner (or urb unlink) can get it
  702. *
  703. * urb + dev is in hcd.self.controller.urb_list
  704. * we're queueing TDs onto software and hardware lists
  705. *
  706. * hcd-specific init for hcpriv hasn't been done yet
  707. *
  708. * NOTE: control, bulk, and interrupt share the same code to append TDs
  709. * to a (possibly active) QH, and the same QH scanning code.
  710. */
  711. static int ehci_urb_enqueue (
  712. struct usb_hcd *hcd,
  713. struct urb *urb,
  714. gfp_t mem_flags
  715. ) {
  716. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  717. struct list_head qtd_list;
  718. INIT_LIST_HEAD (&qtd_list);
  719. switch (usb_pipetype (urb->pipe)) {
  720. case PIPE_CONTROL:
  721. /* qh_completions() code doesn't handle all the fault cases
  722. * in multi-TD control transfers. Even 1KB is rare anyway.
  723. */
  724. if (urb->transfer_buffer_length > (16 * 1024))
  725. return -EMSGSIZE;
  726. /* FALLTHROUGH */
  727. /* case PIPE_BULK: */
  728. default:
  729. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  730. return -ENOMEM;
  731. return submit_async(ehci, urb, &qtd_list, mem_flags);
  732. case PIPE_INTERRUPT:
  733. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  734. return -ENOMEM;
  735. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  736. case PIPE_ISOCHRONOUS:
  737. if (urb->dev->speed == USB_SPEED_HIGH)
  738. return itd_submit (ehci, urb, mem_flags);
  739. else
  740. return sitd_submit (ehci, urb, mem_flags);
  741. }
  742. }
  743. /* remove from hardware lists
  744. * completions normally happen asynchronously
  745. */
  746. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  747. {
  748. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  749. struct ehci_qh *qh;
  750. unsigned long flags;
  751. int rc;
  752. spin_lock_irqsave (&ehci->lock, flags);
  753. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  754. if (rc)
  755. goto done;
  756. if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  757. /*
  758. * We don't expedite dequeue for isochronous URBs.
  759. * Just wait until they complete normally or their
  760. * time slot expires.
  761. */
  762. } else {
  763. qh = (struct ehci_qh *) urb->hcpriv;
  764. qh->exception = 1;
  765. switch (qh->qh_state) {
  766. case QH_STATE_LINKED:
  767. if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
  768. start_unlink_intr(ehci, qh);
  769. else
  770. start_unlink_async(ehci, qh);
  771. break;
  772. case QH_STATE_COMPLETING:
  773. qh->dequeue_during_giveback = 1;
  774. break;
  775. case QH_STATE_UNLINK:
  776. case QH_STATE_UNLINK_WAIT:
  777. /* already started */
  778. break;
  779. case QH_STATE_IDLE:
  780. /* QH might be waiting for a Clear-TT-Buffer */
  781. qh_completions(ehci, qh);
  782. break;
  783. }
  784. }
  785. done:
  786. spin_unlock_irqrestore (&ehci->lock, flags);
  787. return rc;
  788. }
  789. /*-------------------------------------------------------------------------*/
  790. // bulk qh holds the data toggle
  791. static void
  792. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  793. {
  794. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  795. unsigned long flags;
  796. struct ehci_qh *qh, *tmp;
  797. /* ASSERT: any requests/urbs are being unlinked */
  798. /* ASSERT: nobody can be submitting urbs for this any more */
  799. rescan:
  800. spin_lock_irqsave (&ehci->lock, flags);
  801. qh = ep->hcpriv;
  802. if (!qh)
  803. goto done;
  804. /* endpoints can be iso streams. for now, we don't
  805. * accelerate iso completions ... so spin a while.
  806. */
  807. if (qh->hw == NULL) {
  808. struct ehci_iso_stream *stream = ep->hcpriv;
  809. if (!list_empty(&stream->td_list))
  810. goto idle_timeout;
  811. /* BUG_ON(!list_empty(&stream->free_list)); */
  812. kfree(stream);
  813. goto done;
  814. }
  815. qh->exception = 1;
  816. if (ehci->rh_state < EHCI_RH_RUNNING)
  817. qh->qh_state = QH_STATE_IDLE;
  818. switch (qh->qh_state) {
  819. case QH_STATE_LINKED:
  820. case QH_STATE_COMPLETING:
  821. for (tmp = ehci->async->qh_next.qh;
  822. tmp && tmp != qh;
  823. tmp = tmp->qh_next.qh)
  824. continue;
  825. /* periodic qh self-unlinks on empty, and a COMPLETING qh
  826. * may already be unlinked.
  827. */
  828. if (tmp)
  829. start_unlink_async(ehci, qh);
  830. /* FALL THROUGH */
  831. case QH_STATE_UNLINK: /* wait for hw to finish? */
  832. case QH_STATE_UNLINK_WAIT:
  833. idle_timeout:
  834. spin_unlock_irqrestore (&ehci->lock, flags);
  835. schedule_timeout_uninterruptible(1);
  836. goto rescan;
  837. case QH_STATE_IDLE: /* fully unlinked */
  838. if (qh->clearing_tt)
  839. goto idle_timeout;
  840. if (list_empty (&qh->qtd_list)) {
  841. qh_destroy(ehci, qh);
  842. break;
  843. }
  844. /* else FALL THROUGH */
  845. default:
  846. /* caller was supposed to have unlinked any requests;
  847. * that's not our job. just leak this memory.
  848. */
  849. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  850. qh, ep->desc.bEndpointAddress, qh->qh_state,
  851. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  852. break;
  853. }
  854. done:
  855. ep->hcpriv = NULL;
  856. spin_unlock_irqrestore (&ehci->lock, flags);
  857. }
  858. static void
  859. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  860. {
  861. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  862. struct ehci_qh *qh;
  863. int eptype = usb_endpoint_type(&ep->desc);
  864. int epnum = usb_endpoint_num(&ep->desc);
  865. int is_out = usb_endpoint_dir_out(&ep->desc);
  866. unsigned long flags;
  867. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  868. return;
  869. spin_lock_irqsave(&ehci->lock, flags);
  870. qh = ep->hcpriv;
  871. /* For Bulk and Interrupt endpoints we maintain the toggle state
  872. * in the hardware; the toggle bits in udev aren't used at all.
  873. * When an endpoint is reset by usb_clear_halt() we must reset
  874. * the toggle bit in the QH.
  875. */
  876. if (qh) {
  877. usb_settoggle(qh->dev, epnum, is_out, 0);
  878. if (!list_empty(&qh->qtd_list)) {
  879. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  880. } else {
  881. /* The toggle value in the QH can't be updated
  882. * while the QH is active. Unlink it now;
  883. * re-linking will call qh_refresh().
  884. */
  885. qh->exception = 1;
  886. if (eptype == USB_ENDPOINT_XFER_BULK)
  887. start_unlink_async(ehci, qh);
  888. else
  889. start_unlink_intr(ehci, qh);
  890. }
  891. }
  892. spin_unlock_irqrestore(&ehci->lock, flags);
  893. }
  894. static int ehci_get_frame (struct usb_hcd *hcd)
  895. {
  896. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  897. return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
  898. }
  899. /*-------------------------------------------------------------------------*/
  900. #ifdef CONFIG_PM
  901. /* suspend/resume, section 4.3 */
  902. /* These routines handle the generic parts of controller suspend/resume */
  903. int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  904. {
  905. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  906. if (time_before(jiffies, ehci->next_statechange))
  907. msleep(10);
  908. /*
  909. * Root hub was already suspended. Disable IRQ emission and
  910. * mark HW unaccessible. The PM and USB cores make sure that
  911. * the root hub is either suspended or stopped.
  912. */
  913. ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
  914. spin_lock_irq(&ehci->lock);
  915. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  916. (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  917. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  918. spin_unlock_irq(&ehci->lock);
  919. return 0;
  920. }
  921. EXPORT_SYMBOL_GPL(ehci_suspend);
  922. /* Returns 0 if power was preserved, 1 if power was lost */
  923. int ehci_resume(struct usb_hcd *hcd, bool hibernated)
  924. {
  925. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  926. if (time_before(jiffies, ehci->next_statechange))
  927. msleep(100);
  928. /* Mark hardware accessible again as we are back to full power by now */
  929. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  930. if (ehci->shutdown)
  931. return 0; /* Controller is dead */
  932. /*
  933. * If CF is still set and we aren't resuming from hibernation
  934. * then we maintained suspend power.
  935. * Just undo the effect of ehci_suspend().
  936. */
  937. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  938. !hibernated) {
  939. int mask = INTR_MASK;
  940. ehci_prepare_ports_for_controller_resume(ehci);
  941. spin_lock_irq(&ehci->lock);
  942. if (ehci->shutdown)
  943. goto skip;
  944. if (!hcd->self.root_hub->do_remote_wakeup)
  945. mask &= ~STS_PCD;
  946. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  947. ehci_readl(ehci, &ehci->regs->intr_enable);
  948. skip:
  949. spin_unlock_irq(&ehci->lock);
  950. return 0;
  951. }
  952. /*
  953. * Else reset, to cope with power loss or resume from hibernation
  954. * having let the firmware kick in during reboot.
  955. */
  956. usb_root_hub_lost_power(hcd->self.root_hub);
  957. (void) ehci_halt(ehci);
  958. (void) ehci_reset(ehci);
  959. spin_lock_irq(&ehci->lock);
  960. if (ehci->shutdown)
  961. goto skip;
  962. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  963. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  964. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  965. ehci->rh_state = EHCI_RH_SUSPENDED;
  966. spin_unlock_irq(&ehci->lock);
  967. return 1;
  968. }
  969. EXPORT_SYMBOL_GPL(ehci_resume);
  970. #endif
  971. /*-------------------------------------------------------------------------*/
  972. /*
  973. * Generic structure: This gets copied for platform drivers so that
  974. * individual entries can be overridden as needed.
  975. */
  976. static const struct hc_driver ehci_hc_driver = {
  977. .description = hcd_name,
  978. .product_desc = "EHCI Host Controller",
  979. .hcd_priv_size = sizeof(struct ehci_hcd),
  980. /*
  981. * generic hardware linkage
  982. */
  983. .irq = ehci_irq,
  984. .flags = HCD_MEMORY | HCD_USB2,
  985. /*
  986. * basic lifecycle operations
  987. */
  988. .reset = ehci_setup,
  989. .start = ehci_run,
  990. .stop = ehci_stop,
  991. .shutdown = ehci_shutdown,
  992. /*
  993. * managing i/o requests and associated device resources
  994. */
  995. .urb_enqueue = ehci_urb_enqueue,
  996. .urb_dequeue = ehci_urb_dequeue,
  997. .endpoint_disable = ehci_endpoint_disable,
  998. .endpoint_reset = ehci_endpoint_reset,
  999. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  1000. /*
  1001. * scheduling support
  1002. */
  1003. .get_frame_number = ehci_get_frame,
  1004. /*
  1005. * root hub support
  1006. */
  1007. .hub_status_data = ehci_hub_status_data,
  1008. .hub_control = ehci_hub_control,
  1009. .bus_suspend = ehci_bus_suspend,
  1010. .bus_resume = ehci_bus_resume,
  1011. .relinquish_port = ehci_relinquish_port,
  1012. .port_handed_over = ehci_port_handed_over,
  1013. };
  1014. void ehci_init_driver(struct hc_driver *drv,
  1015. const struct ehci_driver_overrides *over)
  1016. {
  1017. /* Copy the generic table to drv and then apply the overrides */
  1018. *drv = ehci_hc_driver;
  1019. if (over) {
  1020. drv->hcd_priv_size += over->extra_priv_size;
  1021. if (over->reset)
  1022. drv->reset = over->reset;
  1023. }
  1024. }
  1025. EXPORT_SYMBOL_GPL(ehci_init_driver);
  1026. /*-------------------------------------------------------------------------*/
  1027. MODULE_DESCRIPTION(DRIVER_DESC);
  1028. MODULE_AUTHOR (DRIVER_AUTHOR);
  1029. MODULE_LICENSE ("GPL");
  1030. #ifdef CONFIG_USB_EHCI_FSL
  1031. #include "ehci-fsl.c"
  1032. #define PLATFORM_DRIVER ehci_fsl_driver
  1033. #endif
  1034. #ifdef CONFIG_USB_EHCI_SH
  1035. #include "ehci-sh.c"
  1036. #define PLATFORM_DRIVER ehci_hcd_sh_driver
  1037. #endif
  1038. #ifdef CONFIG_PPC_PS3
  1039. #include "ehci-ps3.c"
  1040. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  1041. #endif
  1042. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  1043. #include "ehci-ppc-of.c"
  1044. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  1045. #endif
  1046. #ifdef CONFIG_XPS_USB_HCD_XILINX
  1047. #include "ehci-xilinx-of.c"
  1048. #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  1049. #endif
  1050. #ifdef CONFIG_USB_W90X900_EHCI
  1051. #include "ehci-w90x900.c"
  1052. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  1053. #endif
  1054. #ifdef CONFIG_USB_OCTEON_EHCI
  1055. #include "ehci-octeon.c"
  1056. #define PLATFORM_DRIVER ehci_octeon_driver
  1057. #endif
  1058. #ifdef CONFIG_TILE_USB
  1059. #include "ehci-tilegx.c"
  1060. #define PLATFORM_DRIVER ehci_hcd_tilegx_driver
  1061. #endif
  1062. #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
  1063. #include "ehci-pmcmsp.c"
  1064. #define PLATFORM_DRIVER ehci_hcd_msp_driver
  1065. #endif
  1066. #ifdef CONFIG_USB_EHCI_TEGRA
  1067. #include "ehci-tegra.c"
  1068. #define PLATFORM_DRIVER tegra_ehci_driver
  1069. #endif
  1070. #ifdef CONFIG_SPARC_LEON
  1071. #include "ehci-grlib.c"
  1072. #define PLATFORM_DRIVER ehci_grlib_driver
  1073. #endif
  1074. #ifdef CONFIG_USB_EHCI_MV
  1075. #include "ehci-mv.c"
  1076. #define PLATFORM_DRIVER ehci_mv_driver
  1077. #endif
  1078. #ifdef CONFIG_MIPS_SEAD3
  1079. #include "ehci-sead3.c"
  1080. #define PLATFORM_DRIVER ehci_hcd_sead3_driver
  1081. #endif
  1082. #if !IS_ENABLED(CONFIG_USB_EHCI_PCI) && \
  1083. !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \
  1084. !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \
  1085. !IS_ENABLED(CONFIG_USB_EHCI_MXC) && \
  1086. !IS_ENABLED(CONFIG_USB_EHCI_HCD_OMAP) && \
  1087. !IS_ENABLED(CONFIG_USB_EHCI_HCD_ORION) && \
  1088. !IS_ENABLED(CONFIG_USB_EHCI_HCD_SPEAR) && \
  1089. !IS_ENABLED(CONFIG_USB_EHCI_S5P) && \
  1090. !IS_ENABLED(CONFIG_USB_EHCI_HCD_AT91) && \
  1091. !IS_ENABLED(CONFIG_USB_EHCI_MSM) && \
  1092. !defined(PLATFORM_DRIVER) && \
  1093. !defined(PS3_SYSTEM_BUS_DRIVER) && \
  1094. !defined(OF_PLATFORM_DRIVER) && \
  1095. !defined(XILINX_OF_PLATFORM_DRIVER)
  1096. #error "missing bus glue for ehci-hcd"
  1097. #endif
  1098. static int __init ehci_hcd_init(void)
  1099. {
  1100. int retval = 0;
  1101. if (usb_disabled())
  1102. return -ENODEV;
  1103. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1104. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1105. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1106. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1107. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1108. " before uhci_hcd and ohci_hcd, not after\n");
  1109. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1110. hcd_name,
  1111. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1112. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1113. #ifdef DEBUG
  1114. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1115. if (!ehci_debug_root) {
  1116. retval = -ENOENT;
  1117. goto err_debug;
  1118. }
  1119. #endif
  1120. #ifdef PLATFORM_DRIVER
  1121. retval = platform_driver_register(&PLATFORM_DRIVER);
  1122. if (retval < 0)
  1123. goto clean0;
  1124. #endif
  1125. #ifdef PS3_SYSTEM_BUS_DRIVER
  1126. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1127. if (retval < 0)
  1128. goto clean2;
  1129. #endif
  1130. #ifdef OF_PLATFORM_DRIVER
  1131. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1132. if (retval < 0)
  1133. goto clean3;
  1134. #endif
  1135. #ifdef XILINX_OF_PLATFORM_DRIVER
  1136. retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
  1137. if (retval < 0)
  1138. goto clean4;
  1139. #endif
  1140. return retval;
  1141. #ifdef XILINX_OF_PLATFORM_DRIVER
  1142. /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
  1143. clean4:
  1144. #endif
  1145. #ifdef OF_PLATFORM_DRIVER
  1146. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1147. clean3:
  1148. #endif
  1149. #ifdef PS3_SYSTEM_BUS_DRIVER
  1150. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1151. clean2:
  1152. #endif
  1153. #ifdef PLATFORM_DRIVER
  1154. platform_driver_unregister(&PLATFORM_DRIVER);
  1155. clean0:
  1156. #endif
  1157. #ifdef DEBUG
  1158. debugfs_remove(ehci_debug_root);
  1159. ehci_debug_root = NULL;
  1160. err_debug:
  1161. #endif
  1162. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1163. return retval;
  1164. }
  1165. module_init(ehci_hcd_init);
  1166. static void __exit ehci_hcd_cleanup(void)
  1167. {
  1168. #ifdef XILINX_OF_PLATFORM_DRIVER
  1169. platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
  1170. #endif
  1171. #ifdef OF_PLATFORM_DRIVER
  1172. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1173. #endif
  1174. #ifdef PLATFORM_DRIVER
  1175. platform_driver_unregister(&PLATFORM_DRIVER);
  1176. #endif
  1177. #ifdef PS3_SYSTEM_BUS_DRIVER
  1178. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1179. #endif
  1180. #ifdef DEBUG
  1181. debugfs_remove(ehci_debug_root);
  1182. #endif
  1183. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1184. }
  1185. module_exit(ehci_hcd_cleanup);