ehci-hcd.c 39 KB

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