11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) 2000-2004 by David Brownell 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 51da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 61da177e4SLinus Torvalds * Free Software Foundation; either version 2 of the License, or (at your 71da177e4SLinus Torvalds * option) any later version. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 101da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 111da177e4SLinus Torvalds * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121da177e4SLinus Torvalds * for more details. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 151da177e4SLinus Torvalds * along with this program; if not, write to the Free Software Foundation, 161da177e4SLinus Torvalds * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <linux/module.h> 201da177e4SLinus Torvalds #include <linux/pci.h> 211da177e4SLinus Torvalds #include <linux/dmapool.h> 221da177e4SLinus Torvalds #include <linux/kernel.h> 231da177e4SLinus Torvalds #include <linux/delay.h> 241da177e4SLinus Torvalds #include <linux/ioport.h> 251da177e4SLinus Torvalds #include <linux/sched.h> 261da177e4SLinus Torvalds #include <linux/slab.h> 271da177e4SLinus Torvalds #include <linux/errno.h> 281da177e4SLinus Torvalds #include <linux/init.h> 291da177e4SLinus Torvalds #include <linux/timer.h> 301da177e4SLinus Torvalds #include <linux/list.h> 311da177e4SLinus Torvalds #include <linux/interrupt.h> 321da177e4SLinus Torvalds #include <linux/reboot.h> 331da177e4SLinus Torvalds #include <linux/usb.h> 341da177e4SLinus Torvalds #include <linux/moduleparam.h> 351da177e4SLinus Torvalds #include <linux/dma-mapping.h> 36694cc208STony Jones #include <linux/debugfs.h> 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include "../core/hcd.h" 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds #include <asm/byteorder.h> 411da177e4SLinus Torvalds #include <asm/io.h> 421da177e4SLinus Torvalds #include <asm/irq.h> 431da177e4SLinus Torvalds #include <asm/system.h> 441da177e4SLinus Torvalds #include <asm/unaligned.h> 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /* 491da177e4SLinus Torvalds * EHCI hc_driver implementation ... experimental, incomplete. 501da177e4SLinus Torvalds * Based on the final 1.0 register interface specification. 511da177e4SLinus Torvalds * 521da177e4SLinus Torvalds * USB 2.0 shows up in upcoming www.pcmcia.org technology. 531da177e4SLinus Torvalds * First was PCMCIA, like ISA; then CardBus, which is PCI. 541da177e4SLinus Torvalds * Next comes "CardBay", using USB 2.0 signals. 551da177e4SLinus Torvalds * 561da177e4SLinus Torvalds * Contains additional contributions by Brad Hards, Rory Bolt, and others. 571da177e4SLinus Torvalds * Special thanks to Intel and VIA for providing host controllers to 581da177e4SLinus Torvalds * test this driver on, and Cypress (including In-System Design) for 591da177e4SLinus Torvalds * providing early devices for those host controllers to talk to! 601da177e4SLinus Torvalds * 611da177e4SLinus Torvalds * HISTORY: 621da177e4SLinus Torvalds * 631da177e4SLinus Torvalds * 2004-05-10 Root hub and PCI suspend/resume support; remote wakeup. (db) 641da177e4SLinus Torvalds * 2004-02-24 Replace pci_* with generic dma_* API calls (dsaxena@plexity.net) 651da177e4SLinus Torvalds * 2003-12-29 Rewritten high speed iso transfer support (by Michal Sojka, 661da177e4SLinus Torvalds * <sojkam@centrum.cz>, updates by DB). 671da177e4SLinus Torvalds * 681da177e4SLinus Torvalds * 2002-11-29 Correct handling for hw async_next register. 691da177e4SLinus Torvalds * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared; 701da177e4SLinus Torvalds * only scheduling is different, no arbitrary limitations. 711da177e4SLinus Torvalds * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support, 721da177e4SLinus Torvalds * clean up HC run state handshaking. 731da177e4SLinus Torvalds * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts 741da177e4SLinus Torvalds * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other 751da177e4SLinus Torvalds * missing pieces: enabling 64bit dma, handoff from BIOS/SMM. 761da177e4SLinus Torvalds * 2002-05-07 Some error path cleanups to report better errors; wmb(); 771da177e4SLinus Torvalds * use non-CVS version id; better iso bandwidth claim. 781da177e4SLinus Torvalds * 2002-04-19 Control/bulk/interrupt submit no longer uses giveback() on 791da177e4SLinus Torvalds * errors in submit path. Bugfixes to interrupt scheduling/processing. 801da177e4SLinus Torvalds * 2002-03-05 Initial high-speed ISO support; reduce ITD memory; shift 811da177e4SLinus Torvalds * more checking to generic hcd framework (db). Make it work with 821da177e4SLinus Torvalds * Philips EHCI; reduce PCI traffic; shorten IRQ path (Rory Bolt). 831da177e4SLinus Torvalds * 2002-01-14 Minor cleanup; version synch. 841da177e4SLinus Torvalds * 2002-01-08 Fix roothub handoff of FS/LS to companion controllers. 851da177e4SLinus Torvalds * 2002-01-04 Control/Bulk queuing behaves. 861da177e4SLinus Torvalds * 871da177e4SLinus Torvalds * 2001-12-12 Initial patch version for Linux 2.5.1 kernel. 881da177e4SLinus Torvalds * 2001-June Works with usb-storage and NEC EHCI on 2.4 891da177e4SLinus Torvalds */ 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds #define DRIVER_VERSION "10 Dec 2004" 921da177e4SLinus Torvalds #define DRIVER_AUTHOR "David Brownell" 931da177e4SLinus Torvalds #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver" 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds static const char hcd_name [] = "ehci_hcd"; 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds #undef EHCI_VERBOSE_DEBUG 991da177e4SLinus Torvalds #undef EHCI_URB_TRACE 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #ifdef DEBUG 1021da177e4SLinus Torvalds #define EHCI_STATS 1031da177e4SLinus Torvalds #endif 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* magic numbers that can affect system performance */ 1061da177e4SLinus Torvalds #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ 1071da177e4SLinus Torvalds #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ 1081da177e4SLinus Torvalds #define EHCI_TUNE_RL_TT 0 1091da177e4SLinus Torvalds #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 1101da177e4SLinus Torvalds #define EHCI_TUNE_MULT_TT 1 1111da177e4SLinus Torvalds #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 1121da177e4SLinus Torvalds 11307d29b63SAlan Stern #define EHCI_IAA_MSECS 10 /* arbitrary */ 1141da177e4SLinus Torvalds #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 1151da177e4SLinus Torvalds #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ 1161da177e4SLinus Torvalds #define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds /* Initial IRQ latency: faster than hw default */ 1191da177e4SLinus Torvalds static int log2_irq_thresh = 0; // 0 to 6 1201da177e4SLinus Torvalds module_param (log2_irq_thresh, int, S_IRUGO); 1211da177e4SLinus Torvalds MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes"); 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds /* initial park setting: slower than hw default */ 1241da177e4SLinus Torvalds static unsigned park = 0; 1251da177e4SLinus Torvalds module_param (park, uint, S_IRUGO); 1261da177e4SLinus Torvalds MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets"); 1271da177e4SLinus Torvalds 12893f1a47cSDavid Brownell /* for flakey hardware, ignore overcurrent indicators */ 12993f1a47cSDavid Brownell static int ignore_oc = 0; 13093f1a47cSDavid Brownell module_param (ignore_oc, bool, S_IRUGO); 13193f1a47cSDavid Brownell MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 13293f1a47cSDavid Brownell 1331da177e4SLinus Torvalds #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds #include "ehci.h" 1381da177e4SLinus Torvalds #include "ehci-dbg.c" 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds /* 1431da177e4SLinus Torvalds * handshake - spin reading hc until handshake completes or fails 1441da177e4SLinus Torvalds * @ptr: address of hc register to be read 1451da177e4SLinus Torvalds * @mask: bits to look at in result of read 1461da177e4SLinus Torvalds * @done: value of those bits when handshake succeeds 1471da177e4SLinus Torvalds * @usec: timeout in microseconds 1481da177e4SLinus Torvalds * 1491da177e4SLinus Torvalds * Returns negative errno, or zero on success 1501da177e4SLinus Torvalds * 1511da177e4SLinus Torvalds * Success happens when the "mask" bits have the specified value (hardware 1521da177e4SLinus Torvalds * handshake done). There are two failure modes: "usec" have passed (major 1531da177e4SLinus Torvalds * hardware flakeout), or the register reads as all-ones (hardware removed). 1541da177e4SLinus Torvalds * 1551da177e4SLinus Torvalds * That last failure should_only happen in cases like physical cardbus eject 1561da177e4SLinus Torvalds * before driver shutdown. But it also seems to be caused by bugs in cardbus 1571da177e4SLinus Torvalds * bridge shutdown: shutting down the bridge before the devices using it. 1581da177e4SLinus Torvalds */ 159083522d7SBenjamin Herrenschmidt static int handshake (struct ehci_hcd *ehci, void __iomem *ptr, 160083522d7SBenjamin Herrenschmidt u32 mask, u32 done, int usec) 1611da177e4SLinus Torvalds { 1621da177e4SLinus Torvalds u32 result; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds do { 165083522d7SBenjamin Herrenschmidt result = ehci_readl(ehci, ptr); 1661da177e4SLinus Torvalds if (result == ~(u32)0) /* card removed */ 1671da177e4SLinus Torvalds return -ENODEV; 1681da177e4SLinus Torvalds result &= mask; 1691da177e4SLinus Torvalds if (result == done) 1701da177e4SLinus Torvalds return 0; 1711da177e4SLinus Torvalds udelay (1); 1721da177e4SLinus Torvalds usec--; 1731da177e4SLinus Torvalds } while (usec > 0); 1741da177e4SLinus Torvalds return -ETIMEDOUT; 1751da177e4SLinus Torvalds } 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds /* force HC to halt state from unknown (EHCI spec section 2.3) */ 1781da177e4SLinus Torvalds static int ehci_halt (struct ehci_hcd *ehci) 1791da177e4SLinus Torvalds { 180083522d7SBenjamin Herrenschmidt u32 temp = ehci_readl(ehci, &ehci->regs->status); 1811da177e4SLinus Torvalds 18272f30b6fSDavid Brownell /* disable any irqs left enabled by previous code */ 183083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->intr_enable); 18472f30b6fSDavid Brownell 1851da177e4SLinus Torvalds if ((temp & STS_HALT) != 0) 1861da177e4SLinus Torvalds return 0; 1871da177e4SLinus Torvalds 188083522d7SBenjamin Herrenschmidt temp = ehci_readl(ehci, &ehci->regs->command); 1891da177e4SLinus Torvalds temp &= ~CMD_RUN; 190083522d7SBenjamin Herrenschmidt ehci_writel(ehci, temp, &ehci->regs->command); 191083522d7SBenjamin Herrenschmidt return handshake (ehci, &ehci->regs->status, 192083522d7SBenjamin Herrenschmidt STS_HALT, STS_HALT, 16 * 125); 1931da177e4SLinus Torvalds } 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds /* put TDI/ARC silicon into EHCI mode */ 1961da177e4SLinus Torvalds static void tdi_reset (struct ehci_hcd *ehci) 1971da177e4SLinus Torvalds { 1981da177e4SLinus Torvalds u32 __iomem *reg_ptr; 1991da177e4SLinus Torvalds u32 tmp; 2001da177e4SLinus Torvalds 201d23a1377SVladimir Barinov reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); 202083522d7SBenjamin Herrenschmidt tmp = ehci_readl(ehci, reg_ptr); 203d23a1377SVladimir Barinov tmp |= USBMODE_CM_HC; 204d23a1377SVladimir Barinov /* The default byte access to MMR space is LE after 205d23a1377SVladimir Barinov * controller reset. Set the required endian mode 206d23a1377SVladimir Barinov * for transfer buffers to match the host microprocessor 207d23a1377SVladimir Barinov */ 208d23a1377SVladimir Barinov if (ehci_big_endian_mmio(ehci)) 209d23a1377SVladimir Barinov tmp |= USBMODE_BE; 210083522d7SBenjamin Herrenschmidt ehci_writel(ehci, tmp, reg_ptr); 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds /* reset a non-running (STS_HALT == 1) controller */ 2141da177e4SLinus Torvalds static int ehci_reset (struct ehci_hcd *ehci) 2151da177e4SLinus Torvalds { 2161da177e4SLinus Torvalds int retval; 217083522d7SBenjamin Herrenschmidt u32 command = ehci_readl(ehci, &ehci->regs->command); 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds command |= CMD_RESET; 2201da177e4SLinus Torvalds dbg_cmd (ehci, "reset", command); 221083522d7SBenjamin Herrenschmidt ehci_writel(ehci, command, &ehci->regs->command); 2221da177e4SLinus Torvalds ehci_to_hcd(ehci)->state = HC_STATE_HALT; 2231da177e4SLinus Torvalds ehci->next_statechange = jiffies; 224083522d7SBenjamin Herrenschmidt retval = handshake (ehci, &ehci->regs->command, 225083522d7SBenjamin Herrenschmidt CMD_RESET, 0, 250 * 1000); 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds if (retval) 2281da177e4SLinus Torvalds return retval; 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds if (ehci_is_TDI(ehci)) 2311da177e4SLinus Torvalds tdi_reset (ehci); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds return retval; 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds /* idle the controller (from running) */ 2371da177e4SLinus Torvalds static void ehci_quiesce (struct ehci_hcd *ehci) 2381da177e4SLinus Torvalds { 2391da177e4SLinus Torvalds u32 temp; 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds #ifdef DEBUG 2421da177e4SLinus Torvalds if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) 2431da177e4SLinus Torvalds BUG (); 2441da177e4SLinus Torvalds #endif 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds /* wait for any schedule enables/disables to take effect */ 247083522d7SBenjamin Herrenschmidt temp = ehci_readl(ehci, &ehci->regs->command) << 10; 2481da177e4SLinus Torvalds temp &= STS_ASS | STS_PSS; 249083522d7SBenjamin Herrenschmidt if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS, 2501da177e4SLinus Torvalds temp, 16 * 125) != 0) { 2511da177e4SLinus Torvalds ehci_to_hcd(ehci)->state = HC_STATE_HALT; 2521da177e4SLinus Torvalds return; 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds /* then disable anything that's still active */ 256083522d7SBenjamin Herrenschmidt temp = ehci_readl(ehci, &ehci->regs->command); 2571da177e4SLinus Torvalds temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE); 258083522d7SBenjamin Herrenschmidt ehci_writel(ehci, temp, &ehci->regs->command); 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* hardware can take 16 microframes to turn off ... */ 261083522d7SBenjamin Herrenschmidt if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS, 2621da177e4SLinus Torvalds 0, 16 * 125) != 0) { 2631da177e4SLinus Torvalds ehci_to_hcd(ehci)->state = HC_STATE_HALT; 2641da177e4SLinus Torvalds return; 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds } 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 2691da177e4SLinus Torvalds 27007d29b63SAlan Stern static void end_unlink_async(struct ehci_hcd *ehci); 2717d12e780SDavid Howells static void ehci_work(struct ehci_hcd *ehci); 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds #include "ehci-hub.c" 2741da177e4SLinus Torvalds #include "ehci-mem.c" 2751da177e4SLinus Torvalds #include "ehci-q.c" 2761da177e4SLinus Torvalds #include "ehci-sched.c" 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 2791da177e4SLinus Torvalds 28007d29b63SAlan Stern static void ehci_iaa_watchdog(unsigned long param) 28107d29b63SAlan Stern { 28207d29b63SAlan Stern struct ehci_hcd *ehci = (struct ehci_hcd *) param; 28307d29b63SAlan Stern unsigned long flags; 28407d29b63SAlan Stern 28507d29b63SAlan Stern spin_lock_irqsave (&ehci->lock, flags); 28607d29b63SAlan Stern 287*e82cc128SDavid Brownell /* Lost IAA irqs wedge things badly; seen first with a vt8235. 288*e82cc128SDavid Brownell * So we need this watchdog, but must protect it against both 289*e82cc128SDavid Brownell * (a) SMP races against real IAA firing and retriggering, and 290*e82cc128SDavid Brownell * (b) clean HC shutdown, when IAA watchdog was pending. 291*e82cc128SDavid Brownell */ 292*e82cc128SDavid Brownell if (ehci->reclaim 293*e82cc128SDavid Brownell && !timer_pending(&ehci->iaa_watchdog) 294*e82cc128SDavid Brownell && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 295*e82cc128SDavid Brownell u32 cmd, status; 296*e82cc128SDavid Brownell 297*e82cc128SDavid Brownell /* If we get here, IAA is *REALLY* late. It's barely 298*e82cc128SDavid Brownell * conceivable that the system is so busy that CMD_IAAD 299*e82cc128SDavid Brownell * is still legitimately set, so let's be sure it's 300*e82cc128SDavid Brownell * clear before we read STS_IAA. (The HC should clear 301*e82cc128SDavid Brownell * CMD_IAAD when it sets STS_IAA.) 302*e82cc128SDavid Brownell */ 30307d29b63SAlan Stern cmd = ehci_readl(ehci, &ehci->regs->command); 304*e82cc128SDavid Brownell if (cmd & CMD_IAAD) 305*e82cc128SDavid Brownell ehci_writel(ehci, cmd & ~CMD_IAAD, 306*e82cc128SDavid Brownell &ehci->regs->command); 30707d29b63SAlan Stern 308*e82cc128SDavid Brownell /* If IAA is set here it either legitimately triggered 309*e82cc128SDavid Brownell * before we cleared IAAD above (but _way_ late, so we'll 310*e82cc128SDavid Brownell * still count it as lost) ... or a silicon erratum: 311*e82cc128SDavid Brownell * - VIA seems to set IAA without triggering the IRQ; 312*e82cc128SDavid Brownell * - IAAD potentially cleared without setting IAA. 313*e82cc128SDavid Brownell */ 314*e82cc128SDavid Brownell status = ehci_readl(ehci, &ehci->regs->status); 315*e82cc128SDavid Brownell if ((status & STS_IAA) || !(cmd & CMD_IAAD)) { 31607d29b63SAlan Stern COUNT (ehci->stats.lost_iaa); 31707d29b63SAlan Stern ehci_writel(ehci, STS_IAA, &ehci->regs->status); 31807d29b63SAlan Stern } 319*e82cc128SDavid Brownell 320*e82cc128SDavid Brownell ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n", 321*e82cc128SDavid Brownell status, cmd); 32207d29b63SAlan Stern end_unlink_async(ehci); 32307d29b63SAlan Stern } 32407d29b63SAlan Stern 32507d29b63SAlan Stern spin_unlock_irqrestore(&ehci->lock, flags); 32607d29b63SAlan Stern } 32707d29b63SAlan Stern 3281da177e4SLinus Torvalds static void ehci_watchdog(unsigned long param) 3291da177e4SLinus Torvalds { 3301da177e4SLinus Torvalds struct ehci_hcd *ehci = (struct ehci_hcd *) param; 3311da177e4SLinus Torvalds unsigned long flags; 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds spin_lock_irqsave(&ehci->lock, flags); 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds /* stop async processing after it's idled a bit */ 3361da177e4SLinus Torvalds if (test_bit (TIMER_ASYNC_OFF, &ehci->actions)) 3371da177e4SLinus Torvalds start_unlink_async (ehci, ehci->async); 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds /* ehci could run by timer, without IRQs ... */ 3407d12e780SDavid Howells ehci_work (ehci); 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds spin_unlock_irqrestore (&ehci->lock, flags); 3431da177e4SLinus Torvalds } 3441da177e4SLinus Torvalds 3458903795aSAlan Stern /* On some systems, leaving remote wakeup enabled prevents system shutdown. 3468903795aSAlan Stern * The firmware seems to think that powering off is a wakeup event! 3478903795aSAlan Stern * This routine turns off remote wakeup and everything else, on all ports. 3488903795aSAlan Stern */ 3498903795aSAlan Stern static void ehci_turn_off_all_ports(struct ehci_hcd *ehci) 3508903795aSAlan Stern { 3518903795aSAlan Stern int port = HCS_N_PORTS(ehci->hcs_params); 3528903795aSAlan Stern 3538903795aSAlan Stern while (port--) 3548903795aSAlan Stern ehci_writel(ehci, PORT_RWC_BITS, 3558903795aSAlan Stern &ehci->regs->port_status[port]); 3568903795aSAlan Stern } 3578903795aSAlan Stern 35864a21d02SAleksey Gorelov /* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 35972f30b6fSDavid Brownell * This forcibly disables dma and IRQs, helping kexec and other cases 36072f30b6fSDavid Brownell * where the next system software may expect clean state. 36172f30b6fSDavid Brownell */ 36264a21d02SAleksey Gorelov static void 36364a21d02SAleksey Gorelov ehci_shutdown (struct usb_hcd *hcd) 3641da177e4SLinus Torvalds { 3651da177e4SLinus Torvalds struct ehci_hcd *ehci; 3661da177e4SLinus Torvalds 36764a21d02SAleksey Gorelov ehci = hcd_to_ehci (hcd); 36872f30b6fSDavid Brownell (void) ehci_halt (ehci); 3698903795aSAlan Stern ehci_turn_off_all_ports(ehci); 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds /* make BIOS/etc use companion controller during reboot */ 372083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->configured_flag); 3738903795aSAlan Stern 3748903795aSAlan Stern /* unblock posted writes */ 3758903795aSAlan Stern ehci_readl(ehci, &ehci->regs->configured_flag); 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 37856c1e26dSDavid Brownell static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 37956c1e26dSDavid Brownell { 38056c1e26dSDavid Brownell unsigned port; 38156c1e26dSDavid Brownell 38256c1e26dSDavid Brownell if (!HCS_PPC (ehci->hcs_params)) 38356c1e26dSDavid Brownell return; 38456c1e26dSDavid Brownell 38556c1e26dSDavid Brownell ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down"); 38656c1e26dSDavid Brownell for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) 38756c1e26dSDavid Brownell (void) ehci_hub_control(ehci_to_hcd(ehci), 38856c1e26dSDavid Brownell is_on ? SetPortFeature : ClearPortFeature, 38956c1e26dSDavid Brownell USB_PORT_FEAT_POWER, 39056c1e26dSDavid Brownell port--, NULL, 0); 391383975d7SAlan Stern /* Flush those writes */ 392383975d7SAlan Stern ehci_readl(ehci, &ehci->regs->command); 39356c1e26dSDavid Brownell msleep(20); 39456c1e26dSDavid Brownell } 39556c1e26dSDavid Brownell 3967ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/ 3971da177e4SLinus Torvalds 3987ff71d6aSMatt Porter /* 3997ff71d6aSMatt Porter * ehci_work is called from some interrupts, timers, and so on. 4007ff71d6aSMatt Porter * it calls driver completion functions, after dropping ehci->lock. 4017ff71d6aSMatt Porter */ 4027d12e780SDavid Howells static void ehci_work (struct ehci_hcd *ehci) 4037ff71d6aSMatt Porter { 4047ff71d6aSMatt Porter timer_action_done (ehci, TIMER_IO_WATCHDOG); 4051da177e4SLinus Torvalds 4067ff71d6aSMatt Porter /* another CPU may drop ehci->lock during a schedule scan while 4077ff71d6aSMatt Porter * it reports urb completions. this flag guards against bogus 4087ff71d6aSMatt Porter * attempts at re-entrant schedule scanning. 4097ff71d6aSMatt Porter */ 4107ff71d6aSMatt Porter if (ehci->scanning) 4117ff71d6aSMatt Porter return; 4127ff71d6aSMatt Porter ehci->scanning = 1; 4137d12e780SDavid Howells scan_async (ehci); 4147ff71d6aSMatt Porter if (ehci->next_uframe != -1) 4157d12e780SDavid Howells scan_periodic (ehci); 4167ff71d6aSMatt Porter ehci->scanning = 0; 4177ff71d6aSMatt Porter 4187ff71d6aSMatt Porter /* the IO watchdog guards against hardware or driver bugs that 4197ff71d6aSMatt Porter * misplace IRQs, and should let us run completely without IRQs. 4207ff71d6aSMatt Porter * such lossage has been observed on both VT6202 and VT8235. 4217ff71d6aSMatt Porter */ 4227ff71d6aSMatt Porter if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && 4237ff71d6aSMatt Porter (ehci->async->qh_next.ptr != NULL || 4247ff71d6aSMatt Porter ehci->periodic_sched != 0)) 4257ff71d6aSMatt Porter timer_action (ehci, TIMER_IO_WATCHDOG); 4267ff71d6aSMatt Porter } 4277ff71d6aSMatt Porter 4287ff71d6aSMatt Porter static void ehci_stop (struct usb_hcd *hcd) 4291da177e4SLinus Torvalds { 4301da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci (hcd); 4311da177e4SLinus Torvalds 4327ff71d6aSMatt Porter ehci_dbg (ehci, "stop\n"); 4331da177e4SLinus Torvalds 4347ff71d6aSMatt Porter /* Turn off port power on all root hub ports. */ 43556c1e26dSDavid Brownell ehci_port_power (ehci, 0); 4361da177e4SLinus Torvalds 4377ff71d6aSMatt Porter /* no more interrupts ... */ 4387ff71d6aSMatt Porter del_timer_sync (&ehci->watchdog); 43907d29b63SAlan Stern del_timer_sync(&ehci->iaa_watchdog); 4401da177e4SLinus Torvalds 4417ff71d6aSMatt Porter spin_lock_irq(&ehci->lock); 4427ff71d6aSMatt Porter if (HC_IS_RUNNING (hcd->state)) 4437ff71d6aSMatt Porter ehci_quiesce (ehci); 4441da177e4SLinus Torvalds 4457ff71d6aSMatt Porter ehci_reset (ehci); 446083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->intr_enable); 4477ff71d6aSMatt Porter spin_unlock_irq(&ehci->lock); 4487ff71d6aSMatt Porter 4497ff71d6aSMatt Porter /* let companion controllers work when we aren't */ 450083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->configured_flag); 4517ff71d6aSMatt Porter 45257e06c11SAlan Stern remove_companion_file(ehci); 4537ff71d6aSMatt Porter remove_debug_files (ehci); 4547ff71d6aSMatt Porter 4557ff71d6aSMatt Porter /* root hub is shut down separately (first, when possible) */ 4567ff71d6aSMatt Porter spin_lock_irq (&ehci->lock); 4577ff71d6aSMatt Porter if (ehci->async) 4587d12e780SDavid Howells ehci_work (ehci); 4597ff71d6aSMatt Porter spin_unlock_irq (&ehci->lock); 4607ff71d6aSMatt Porter ehci_mem_cleanup (ehci); 4617ff71d6aSMatt Porter 4627ff71d6aSMatt Porter #ifdef EHCI_STATS 4637ff71d6aSMatt Porter ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", 4647ff71d6aSMatt Porter ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, 4657ff71d6aSMatt Porter ehci->stats.lost_iaa); 4667ff71d6aSMatt Porter ehci_dbg (ehci, "complete %ld unlink %ld\n", 4677ff71d6aSMatt Porter ehci->stats.complete, ehci->stats.unlink); 4681da177e4SLinus Torvalds #endif 4697ff71d6aSMatt Porter 470083522d7SBenjamin Herrenschmidt dbg_status (ehci, "ehci_stop completed", 471083522d7SBenjamin Herrenschmidt ehci_readl(ehci, &ehci->regs->status)); 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 47418807521SDavid Brownell /* one-time init, only for memory state */ 47518807521SDavid Brownell static int ehci_init(struct usb_hcd *hcd) 4761da177e4SLinus Torvalds { 4771da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci(hcd); 4781da177e4SLinus Torvalds u32 temp; 4791da177e4SLinus Torvalds int retval; 4801da177e4SLinus Torvalds u32 hcc_params; 4811da177e4SLinus Torvalds 48218807521SDavid Brownell spin_lock_init(&ehci->lock); 48318807521SDavid Brownell 4841da177e4SLinus Torvalds init_timer(&ehci->watchdog); 4851da177e4SLinus Torvalds ehci->watchdog.function = ehci_watchdog; 4861da177e4SLinus Torvalds ehci->watchdog.data = (unsigned long) ehci; 4871da177e4SLinus Torvalds 48807d29b63SAlan Stern init_timer(&ehci->iaa_watchdog); 48907d29b63SAlan Stern ehci->iaa_watchdog.function = ehci_iaa_watchdog; 49007d29b63SAlan Stern ehci->iaa_watchdog.data = (unsigned long) ehci; 49107d29b63SAlan Stern 4921da177e4SLinus Torvalds /* 4931da177e4SLinus Torvalds * hw default: 1K periodic list heads, one per frame. 4941da177e4SLinus Torvalds * periodic_size can shrink by USBCMD update if hcc_params allows. 4951da177e4SLinus Torvalds */ 4961da177e4SLinus Torvalds ehci->periodic_size = DEFAULT_I_TDPS; 49718807521SDavid Brownell if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0) 4981da177e4SLinus Torvalds return retval; 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds /* controllers may cache some of the periodic schedule ... */ 501083522d7SBenjamin Herrenschmidt hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); 5021da177e4SLinus Torvalds if (HCC_ISOC_CACHE(hcc_params)) // full frame cache 5031da177e4SLinus Torvalds ehci->i_thresh = 8; 5041da177e4SLinus Torvalds else // N microframes cached 5051da177e4SLinus Torvalds ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds ehci->reclaim = NULL; 5081da177e4SLinus Torvalds ehci->next_uframe = -1; 5091da177e4SLinus Torvalds 5101da177e4SLinus Torvalds /* 5111da177e4SLinus Torvalds * dedicate a qh for the async ring head, since we couldn't unlink 5121da177e4SLinus Torvalds * a 'real' qh without stopping the async schedule [4.8]. use it 5131da177e4SLinus Torvalds * as the 'reclamation list head' too. 5141da177e4SLinus Torvalds * its dummy is used in hw_alt_next of many tds, to prevent the qh 5151da177e4SLinus Torvalds * from automatically advancing to the next td after short reads. 5161da177e4SLinus Torvalds */ 5171da177e4SLinus Torvalds ehci->async->qh_next.qh = NULL; 5186dbd682bSStefan Roese ehci->async->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); 5196dbd682bSStefan Roese ehci->async->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); 5206dbd682bSStefan Roese ehci->async->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); 5216dbd682bSStefan Roese ehci->async->hw_qtd_next = EHCI_LIST_END(ehci); 5221da177e4SLinus Torvalds ehci->async->qh_state = QH_STATE_LINKED; 5236dbd682bSStefan Roese ehci->async->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds /* clear interrupt enables, set irq latency */ 5261da177e4SLinus Torvalds if (log2_irq_thresh < 0 || log2_irq_thresh > 6) 5271da177e4SLinus Torvalds log2_irq_thresh = 0; 5281da177e4SLinus Torvalds temp = 1 << (16 + log2_irq_thresh); 5291da177e4SLinus Torvalds if (HCC_CANPARK(hcc_params)) { 5301da177e4SLinus Torvalds /* HW default park == 3, on hardware that supports it (like 5311da177e4SLinus Torvalds * NVidia and ALI silicon), maximizes throughput on the async 5321da177e4SLinus Torvalds * schedule by avoiding QH fetches between transfers. 5331da177e4SLinus Torvalds * 5341da177e4SLinus Torvalds * With fast usb storage devices and NForce2, "park" seems to 5351da177e4SLinus Torvalds * make problems: throughput reduction (!), data errors... 5361da177e4SLinus Torvalds */ 5371da177e4SLinus Torvalds if (park) { 5381da177e4SLinus Torvalds park = min(park, (unsigned) 3); 5391da177e4SLinus Torvalds temp |= CMD_PARK; 5401da177e4SLinus Torvalds temp |= park << 8; 5411da177e4SLinus Torvalds } 54218807521SDavid Brownell ehci_dbg(ehci, "park %d\n", park); 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds if (HCC_PGM_FRAMELISTLEN(hcc_params)) { 5451da177e4SLinus Torvalds /* periodic schedule size can be smaller than default */ 5461da177e4SLinus Torvalds temp &= ~(3 << 2); 5471da177e4SLinus Torvalds temp |= (EHCI_TUNE_FLS << 2); 5481da177e4SLinus Torvalds switch (EHCI_TUNE_FLS) { 5491da177e4SLinus Torvalds case 0: ehci->periodic_size = 1024; break; 5501da177e4SLinus Torvalds case 1: ehci->periodic_size = 512; break; 5511da177e4SLinus Torvalds case 2: ehci->periodic_size = 256; break; 5521da177e4SLinus Torvalds default: BUG(); 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds } 55518807521SDavid Brownell ehci->command = temp; 55618807521SDavid Brownell 55718807521SDavid Brownell return 0; 55818807521SDavid Brownell } 55918807521SDavid Brownell 56018807521SDavid Brownell /* start HC running; it's halted, ehci_init() has been run (once) */ 56118807521SDavid Brownell static int ehci_run (struct usb_hcd *hcd) 56218807521SDavid Brownell { 56318807521SDavid Brownell struct ehci_hcd *ehci = hcd_to_ehci (hcd); 56418807521SDavid Brownell int retval; 56518807521SDavid Brownell u32 temp; 56618807521SDavid Brownell u32 hcc_params; 56718807521SDavid Brownell 5681d619f12SMarcelo Tosatti hcd->uses_new_polling = 1; 5691d619f12SMarcelo Tosatti hcd->poll_rh = 0; 5701d619f12SMarcelo Tosatti 57118807521SDavid Brownell /* EHCI spec section 4.1 */ 57218807521SDavid Brownell if ((retval = ehci_reset(ehci)) != 0) { 57318807521SDavid Brownell ehci_mem_cleanup(ehci); 57418807521SDavid Brownell return retval; 57518807521SDavid Brownell } 576083522d7SBenjamin Herrenschmidt ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); 577083522d7SBenjamin Herrenschmidt ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); 57818807521SDavid Brownell 57918807521SDavid Brownell /* 58018807521SDavid Brownell * hcc_params controls whether ehci->regs->segment must (!!!) 58118807521SDavid Brownell * be used; it constrains QH/ITD/SITD and QTD locations. 58218807521SDavid Brownell * pci_pool consistent memory always uses segment zero. 58318807521SDavid Brownell * streaming mappings for I/O buffers, like pci_map_single(), 58418807521SDavid Brownell * can return segments above 4GB, if the device allows. 58518807521SDavid Brownell * 58618807521SDavid Brownell * NOTE: the dma mask is visible through dma_supported(), so 58718807521SDavid Brownell * drivers can pass this info along ... like NETIF_F_HIGHDMA, 58818807521SDavid Brownell * Scsi_Host.highmem_io, and so forth. It's readonly to all 58918807521SDavid Brownell * host side drivers though. 59018807521SDavid Brownell */ 591083522d7SBenjamin Herrenschmidt hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); 59218807521SDavid Brownell if (HCC_64BIT_ADDR(hcc_params)) { 593083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->segment); 59418807521SDavid Brownell #if 0 59518807521SDavid Brownell // this is deeply broken on almost all architectures 59618807521SDavid Brownell if (!dma_set_mask(hcd->self.controller, DMA_64BIT_MASK)) 59718807521SDavid Brownell ehci_info(ehci, "enabled 64bit DMA\n"); 59818807521SDavid Brownell #endif 59918807521SDavid Brownell } 60018807521SDavid Brownell 60118807521SDavid Brownell 6021da177e4SLinus Torvalds // Philips, Intel, and maybe others need CMD_RUN before the 6031da177e4SLinus Torvalds // root hub will detect new devices (why?); NEC doesn't 60418807521SDavid Brownell ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); 60518807521SDavid Brownell ehci->command |= CMD_RUN; 606083522d7SBenjamin Herrenschmidt ehci_writel(ehci, ehci->command, &ehci->regs->command); 60718807521SDavid Brownell dbg_cmd (ehci, "init", ehci->command); 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds /* 6101da177e4SLinus Torvalds * Start, enabling full USB 2.0 functionality ... usb 1.1 devices 6111da177e4SLinus Torvalds * are explicitly handed to companion controller(s), so no TT is 6121da177e4SLinus Torvalds * involved with the root hub. (Except where one is integrated, 6131da177e4SLinus Torvalds * and there's no companion controller unless maybe for USB OTG.) 61432fe0198SAlan Stern * 61532fe0198SAlan Stern * Turning on the CF flag will transfer ownership of all ports 61632fe0198SAlan Stern * from the companions to the EHCI controller. If any of the 61732fe0198SAlan Stern * companions are in the middle of a port reset at the time, it 61832fe0198SAlan Stern * could cause trouble. Write-locking ehci_cf_port_reset_rwsem 6191cb52658SDavid Brownell * guarantees that no resets are in progress. After we set CF, 6201cb52658SDavid Brownell * a short delay lets the hardware catch up; new resets shouldn't 6211cb52658SDavid Brownell * be started before the port switching actions could complete. 6221da177e4SLinus Torvalds */ 62332fe0198SAlan Stern down_write(&ehci_cf_port_reset_rwsem); 6241da177e4SLinus Torvalds hcd->state = HC_STATE_RUNNING; 625083522d7SBenjamin Herrenschmidt ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 626083522d7SBenjamin Herrenschmidt ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 6271cb52658SDavid Brownell msleep(5); 62832fe0198SAlan Stern up_write(&ehci_cf_port_reset_rwsem); 6291da177e4SLinus Torvalds 630083522d7SBenjamin Herrenschmidt temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); 6311da177e4SLinus Torvalds ehci_info (ehci, 63293f1a47cSDavid Brownell "USB %x.%x started, EHCI %x.%02x, driver %s%s\n", 6337ff71d6aSMatt Porter ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), 63493f1a47cSDavid Brownell temp >> 8, temp & 0xff, DRIVER_VERSION, 63593f1a47cSDavid Brownell ignore_oc ? ", overcurrent ignored" : ""); 6361da177e4SLinus Torvalds 637083522d7SBenjamin Herrenschmidt ehci_writel(ehci, INTR_MASK, 638083522d7SBenjamin Herrenschmidt &ehci->regs->intr_enable); /* Turn On Interrupts */ 6391da177e4SLinus Torvalds 64018807521SDavid Brownell /* GRR this is run-once init(), being done every time the HC starts. 64118807521SDavid Brownell * So long as they're part of class devices, we can't do it init() 64218807521SDavid Brownell * since the class device isn't created that early. 64318807521SDavid Brownell */ 6441da177e4SLinus Torvalds create_debug_files(ehci); 64557e06c11SAlan Stern create_companion_file(ehci); 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds return 0; 6481da177e4SLinus Torvalds } 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 6511da177e4SLinus Torvalds 6527d12e780SDavid Howells static irqreturn_t ehci_irq (struct usb_hcd *hcd) 6531da177e4SLinus Torvalds { 6541da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci (hcd); 655*e82cc128SDavid Brownell u32 status, pcd_status = 0, cmd; 6561da177e4SLinus Torvalds int bh; 6571da177e4SLinus Torvalds 6581da177e4SLinus Torvalds spin_lock (&ehci->lock); 6591da177e4SLinus Torvalds 660083522d7SBenjamin Herrenschmidt status = ehci_readl(ehci, &ehci->regs->status); 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds /* e.g. cardbus physical eject */ 6631da177e4SLinus Torvalds if (status == ~(u32) 0) { 6641da177e4SLinus Torvalds ehci_dbg (ehci, "device removed\n"); 6651da177e4SLinus Torvalds goto dead; 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds status &= INTR_MASK; 6691da177e4SLinus Torvalds if (!status) { /* irq sharing? */ 6701da177e4SLinus Torvalds spin_unlock(&ehci->lock); 6711da177e4SLinus Torvalds return IRQ_NONE; 6721da177e4SLinus Torvalds } 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds /* clear (just) interrupts */ 675083522d7SBenjamin Herrenschmidt ehci_writel(ehci, status, &ehci->regs->status); 676*e82cc128SDavid Brownell cmd = ehci_readl(ehci, &ehci->regs->command); 6771da177e4SLinus Torvalds bh = 0; 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds #ifdef EHCI_VERBOSE_DEBUG 6801da177e4SLinus Torvalds /* unrequested/ignored: Frame List Rollover */ 6811da177e4SLinus Torvalds dbg_status (ehci, "irq", status); 6821da177e4SLinus Torvalds #endif 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds /* INT, ERR, and IAA interrupt rates can be throttled */ 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds /* normal [4.15.1.2] or error [4.15.1.1] completion */ 6871da177e4SLinus Torvalds if (likely ((status & (STS_INT|STS_ERR)) != 0)) { 6881da177e4SLinus Torvalds if (likely ((status & STS_ERR) == 0)) 6891da177e4SLinus Torvalds COUNT (ehci->stats.normal); 6901da177e4SLinus Torvalds else 6911da177e4SLinus Torvalds COUNT (ehci->stats.error); 6921da177e4SLinus Torvalds bh = 1; 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds /* complete the unlinking of some qh [4.15.2.3] */ 6961da177e4SLinus Torvalds if (status & STS_IAA) { 697*e82cc128SDavid Brownell /* guard against (alleged) silicon errata */ 698*e82cc128SDavid Brownell if (cmd & CMD_IAAD) { 699*e82cc128SDavid Brownell ehci_writel(ehci, cmd & ~CMD_IAAD, 700*e82cc128SDavid Brownell &ehci->regs->command); 701*e82cc128SDavid Brownell ehci_dbg(ehci, "IAA with IAAD still set?\n"); 702*e82cc128SDavid Brownell } 703*e82cc128SDavid Brownell if (ehci->reclaim) { 7041da177e4SLinus Torvalds COUNT(ehci->stats.reclaim); 70507d29b63SAlan Stern end_unlink_async(ehci); 706*e82cc128SDavid Brownell } else 707*e82cc128SDavid Brownell ehci_dbg(ehci, "IAA with nothing to reclaim?\n"); 7081da177e4SLinus Torvalds } 7091da177e4SLinus Torvalds 7101da177e4SLinus Torvalds /* remote wakeup [4.3.1] */ 711d97cc2f2SDavid Brownell if (status & STS_PCD) { 7121da177e4SLinus Torvalds unsigned i = HCS_N_PORTS (ehci->hcs_params); 7131d619f12SMarcelo Tosatti pcd_status = status; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds /* resume root hub? */ 716083522d7SBenjamin Herrenschmidt if (!(ehci_readl(ehci, &ehci->regs->command) & CMD_RUN)) 7178c03356aSAlan Stern usb_hcd_resume_root_hub(hcd); 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds while (i--) { 720083522d7SBenjamin Herrenschmidt int pstatus = ehci_readl(ehci, 721083522d7SBenjamin Herrenschmidt &ehci->regs->port_status [i]); 722b972b68cSDavid Brownell 723b972b68cSDavid Brownell if (pstatus & PORT_OWNER) 7241da177e4SLinus Torvalds continue; 725b972b68cSDavid Brownell if (!(pstatus & PORT_RESUME) 7261da177e4SLinus Torvalds || ehci->reset_done [i] != 0) 7271da177e4SLinus Torvalds continue; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds /* start 20 msec resume signaling from this port, 7301da177e4SLinus Torvalds * and make khubd collect PORT_STAT_C_SUSPEND to 7311da177e4SLinus Torvalds * stop that signaling. 7321da177e4SLinus Torvalds */ 7331da177e4SLinus Torvalds ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); 7341da177e4SLinus Torvalds ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); 73561e8b858SAlan Stern mod_timer(&hcd->rh_timer, ehci->reset_done[i]); 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds } 7381da177e4SLinus Torvalds 7391da177e4SLinus Torvalds /* PCI errors [4.15.2.4] */ 7401da177e4SLinus Torvalds if (unlikely ((status & STS_FATAL) != 0)) { 7411da177e4SLinus Torvalds /* bogus "fatal" IRQs appear on some chips... why? */ 742083522d7SBenjamin Herrenschmidt status = ehci_readl(ehci, &ehci->regs->status); 743083522d7SBenjamin Herrenschmidt dbg_cmd (ehci, "fatal", ehci_readl(ehci, 744083522d7SBenjamin Herrenschmidt &ehci->regs->command)); 7451da177e4SLinus Torvalds dbg_status (ehci, "fatal", status); 7461da177e4SLinus Torvalds if (status & STS_HALT) { 7471da177e4SLinus Torvalds ehci_err (ehci, "fatal error\n"); 7481da177e4SLinus Torvalds dead: 7491da177e4SLinus Torvalds ehci_reset (ehci); 750083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->configured_flag); 7511da177e4SLinus Torvalds /* generic layer kills/unlinks all urbs, then 7521da177e4SLinus Torvalds * uses ehci_stop to clean up the rest 7531da177e4SLinus Torvalds */ 7541da177e4SLinus Torvalds bh = 1; 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds } 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds if (bh) 7597d12e780SDavid Howells ehci_work (ehci); 7601da177e4SLinus Torvalds spin_unlock (&ehci->lock); 7611d619f12SMarcelo Tosatti if (pcd_status & STS_PCD) 7621d619f12SMarcelo Tosatti usb_hcd_poll_rh_status(hcd); 7631da177e4SLinus Torvalds return IRQ_HANDLED; 7641da177e4SLinus Torvalds } 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds /* 7691da177e4SLinus Torvalds * non-error returns are a promise to giveback() the urb later 7701da177e4SLinus Torvalds * we drop ownership so next owner (or urb unlink) can get it 7711da177e4SLinus Torvalds * 7721da177e4SLinus Torvalds * urb + dev is in hcd.self.controller.urb_list 7731da177e4SLinus Torvalds * we're queueing TDs onto software and hardware lists 7741da177e4SLinus Torvalds * 7751da177e4SLinus Torvalds * hcd-specific init for hcpriv hasn't been done yet 7761da177e4SLinus Torvalds * 7771da177e4SLinus Torvalds * NOTE: control, bulk, and interrupt share the same code to append TDs 7781da177e4SLinus Torvalds * to a (possibly active) QH, and the same QH scanning code. 7791da177e4SLinus Torvalds */ 7801da177e4SLinus Torvalds static int ehci_urb_enqueue ( 7811da177e4SLinus Torvalds struct usb_hcd *hcd, 7821da177e4SLinus Torvalds struct urb *urb, 78355016f10SAl Viro gfp_t mem_flags 7841da177e4SLinus Torvalds ) { 7851da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci (hcd); 7861da177e4SLinus Torvalds struct list_head qtd_list; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds INIT_LIST_HEAD (&qtd_list); 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds switch (usb_pipetype (urb->pipe)) { 7911da177e4SLinus Torvalds // case PIPE_CONTROL: 7921da177e4SLinus Torvalds // case PIPE_BULK: 7931da177e4SLinus Torvalds default: 7941da177e4SLinus Torvalds if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 7951da177e4SLinus Torvalds return -ENOMEM; 796e9df41c5SAlan Stern return submit_async(ehci, urb, &qtd_list, mem_flags); 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds case PIPE_INTERRUPT: 7991da177e4SLinus Torvalds if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 8001da177e4SLinus Torvalds return -ENOMEM; 801e9df41c5SAlan Stern return intr_submit(ehci, urb, &qtd_list, mem_flags); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds case PIPE_ISOCHRONOUS: 8041da177e4SLinus Torvalds if (urb->dev->speed == USB_SPEED_HIGH) 8051da177e4SLinus Torvalds return itd_submit (ehci, urb, mem_flags); 8061da177e4SLinus Torvalds else 8071da177e4SLinus Torvalds return sitd_submit (ehci, urb, mem_flags); 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds 8111da177e4SLinus Torvalds static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 8121da177e4SLinus Torvalds { 81307d29b63SAlan Stern /* failfast */ 814*e82cc128SDavid Brownell if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) 81507d29b63SAlan Stern end_unlink_async(ehci); 81607d29b63SAlan Stern 81707d29b63SAlan Stern /* if it's not linked then there's nothing to do */ 81807d29b63SAlan Stern if (qh->qh_state != QH_STATE_LINKED) 81907d29b63SAlan Stern ; 82007d29b63SAlan Stern 82107d29b63SAlan Stern /* defer till later if busy */ 82207d29b63SAlan Stern else if (ehci->reclaim) { 8231da177e4SLinus Torvalds struct ehci_qh *last; 8241da177e4SLinus Torvalds 8251da177e4SLinus Torvalds for (last = ehci->reclaim; 8261da177e4SLinus Torvalds last->reclaim; 8271da177e4SLinus Torvalds last = last->reclaim) 8281da177e4SLinus Torvalds continue; 8291da177e4SLinus Torvalds qh->qh_state = QH_STATE_UNLINK_WAIT; 8301da177e4SLinus Torvalds last->reclaim = qh; 8311da177e4SLinus Torvalds 83207d29b63SAlan Stern /* start IAA cycle */ 83307d29b63SAlan Stern } else 8341da177e4SLinus Torvalds start_unlink_async (ehci, qh); 8351da177e4SLinus Torvalds } 8361da177e4SLinus Torvalds 8371da177e4SLinus Torvalds /* remove from hardware lists 8381da177e4SLinus Torvalds * completions normally happen asynchronously 8391da177e4SLinus Torvalds */ 8401da177e4SLinus Torvalds 841e9df41c5SAlan Stern static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 8421da177e4SLinus Torvalds { 8431da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci (hcd); 8441da177e4SLinus Torvalds struct ehci_qh *qh; 8451da177e4SLinus Torvalds unsigned long flags; 846e9df41c5SAlan Stern int rc; 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds spin_lock_irqsave (&ehci->lock, flags); 849e9df41c5SAlan Stern rc = usb_hcd_check_unlink_urb(hcd, urb, status); 850e9df41c5SAlan Stern if (rc) 851e9df41c5SAlan Stern goto done; 852e9df41c5SAlan Stern 8531da177e4SLinus Torvalds switch (usb_pipetype (urb->pipe)) { 8541da177e4SLinus Torvalds // case PIPE_CONTROL: 8551da177e4SLinus Torvalds // case PIPE_BULK: 8561da177e4SLinus Torvalds default: 8571da177e4SLinus Torvalds qh = (struct ehci_qh *) urb->hcpriv; 8581da177e4SLinus Torvalds if (!qh) 8591da177e4SLinus Torvalds break; 86007d29b63SAlan Stern switch (qh->qh_state) { 86107d29b63SAlan Stern case QH_STATE_LINKED: 86207d29b63SAlan Stern case QH_STATE_COMPLETING: 8631da177e4SLinus Torvalds unlink_async(ehci, qh); 8641da177e4SLinus Torvalds break; 86507d29b63SAlan Stern case QH_STATE_UNLINK: 86607d29b63SAlan Stern case QH_STATE_UNLINK_WAIT: 86707d29b63SAlan Stern /* already started */ 86807d29b63SAlan Stern break; 86907d29b63SAlan Stern case QH_STATE_IDLE: 87007d29b63SAlan Stern WARN_ON(1); 87107d29b63SAlan Stern break; 87207d29b63SAlan Stern } 87307d29b63SAlan Stern break; 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds case PIPE_INTERRUPT: 8761da177e4SLinus Torvalds qh = (struct ehci_qh *) urb->hcpriv; 8771da177e4SLinus Torvalds if (!qh) 8781da177e4SLinus Torvalds break; 8791da177e4SLinus Torvalds switch (qh->qh_state) { 8801da177e4SLinus Torvalds case QH_STATE_LINKED: 8811da177e4SLinus Torvalds intr_deschedule (ehci, qh); 8821da177e4SLinus Torvalds /* FALL THROUGH */ 8831da177e4SLinus Torvalds case QH_STATE_IDLE: 8847d12e780SDavid Howells qh_completions (ehci, qh); 8851da177e4SLinus Torvalds break; 8861da177e4SLinus Torvalds default: 8871da177e4SLinus Torvalds ehci_dbg (ehci, "bogus qh %p state %d\n", 8881da177e4SLinus Torvalds qh, qh->qh_state); 8891da177e4SLinus Torvalds goto done; 8901da177e4SLinus Torvalds } 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds /* reschedule QH iff another request is queued */ 8931da177e4SLinus Torvalds if (!list_empty (&qh->qtd_list) 8941da177e4SLinus Torvalds && HC_IS_RUNNING (hcd->state)) { 895e1a49142SDavid Brownell rc = qh_schedule(ehci, qh); 8961da177e4SLinus Torvalds 897e1a49142SDavid Brownell /* An error here likely indicates handshake failure 898e1a49142SDavid Brownell * or no space left in the schedule. Neither fault 899e1a49142SDavid Brownell * should happen often ... 900e1a49142SDavid Brownell * 901e1a49142SDavid Brownell * FIXME kill the now-dysfunctional queued urbs 902e1a49142SDavid Brownell */ 903e1a49142SDavid Brownell if (rc != 0) 904e1a49142SDavid Brownell ehci_err(ehci, 905e1a49142SDavid Brownell "can't reschedule qh %p, err %d", 906e1a49142SDavid Brownell qh, rc); 9071da177e4SLinus Torvalds } 9081da177e4SLinus Torvalds break; 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds case PIPE_ISOCHRONOUS: 9111da177e4SLinus Torvalds // itd or sitd ... 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds // wait till next completion, do it then. 9141da177e4SLinus Torvalds // completion irqs can wait up to 1024 msec, 9151da177e4SLinus Torvalds break; 9161da177e4SLinus Torvalds } 9171da177e4SLinus Torvalds done: 9181da177e4SLinus Torvalds spin_unlock_irqrestore (&ehci->lock, flags); 919e9df41c5SAlan Stern return rc; 9201da177e4SLinus Torvalds } 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 9231da177e4SLinus Torvalds 9241da177e4SLinus Torvalds // bulk qh holds the data toggle 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds static void 9271da177e4SLinus Torvalds ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) 9281da177e4SLinus Torvalds { 9291da177e4SLinus Torvalds struct ehci_hcd *ehci = hcd_to_ehci (hcd); 9301da177e4SLinus Torvalds unsigned long flags; 9311da177e4SLinus Torvalds struct ehci_qh *qh, *tmp; 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds /* ASSERT: any requests/urbs are being unlinked */ 9341da177e4SLinus Torvalds /* ASSERT: nobody can be submitting urbs for this any more */ 9351da177e4SLinus Torvalds 9361da177e4SLinus Torvalds rescan: 9371da177e4SLinus Torvalds spin_lock_irqsave (&ehci->lock, flags); 9381da177e4SLinus Torvalds qh = ep->hcpriv; 9391da177e4SLinus Torvalds if (!qh) 9401da177e4SLinus Torvalds goto done; 9411da177e4SLinus Torvalds 9421da177e4SLinus Torvalds /* endpoints can be iso streams. for now, we don't 9431da177e4SLinus Torvalds * accelerate iso completions ... so spin a while. 9441da177e4SLinus Torvalds */ 9451da177e4SLinus Torvalds if (qh->hw_info1 == 0) { 9461da177e4SLinus Torvalds ehci_vdbg (ehci, "iso delay\n"); 9471da177e4SLinus Torvalds goto idle_timeout; 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds 9501da177e4SLinus Torvalds if (!HC_IS_RUNNING (hcd->state)) 9511da177e4SLinus Torvalds qh->qh_state = QH_STATE_IDLE; 9521da177e4SLinus Torvalds switch (qh->qh_state) { 9531da177e4SLinus Torvalds case QH_STATE_LINKED: 9541da177e4SLinus Torvalds for (tmp = ehci->async->qh_next.qh; 9551da177e4SLinus Torvalds tmp && tmp != qh; 9561da177e4SLinus Torvalds tmp = tmp->qh_next.qh) 9571da177e4SLinus Torvalds continue; 9581da177e4SLinus Torvalds /* periodic qh self-unlinks on empty */ 9591da177e4SLinus Torvalds if (!tmp) 9601da177e4SLinus Torvalds goto nogood; 9611da177e4SLinus Torvalds unlink_async (ehci, qh); 9621da177e4SLinus Torvalds /* FALL THROUGH */ 9631da177e4SLinus Torvalds case QH_STATE_UNLINK: /* wait for hw to finish? */ 96407d29b63SAlan Stern case QH_STATE_UNLINK_WAIT: 9651da177e4SLinus Torvalds idle_timeout: 9661da177e4SLinus Torvalds spin_unlock_irqrestore (&ehci->lock, flags); 96722c43863SNishanth Aravamudan schedule_timeout_uninterruptible(1); 9681da177e4SLinus Torvalds goto rescan; 9691da177e4SLinus Torvalds case QH_STATE_IDLE: /* fully unlinked */ 9701da177e4SLinus Torvalds if (list_empty (&qh->qtd_list)) { 9711da177e4SLinus Torvalds qh_put (qh); 9721da177e4SLinus Torvalds break; 9731da177e4SLinus Torvalds } 9741da177e4SLinus Torvalds /* else FALL THROUGH */ 9751da177e4SLinus Torvalds default: 9761da177e4SLinus Torvalds nogood: 9771da177e4SLinus Torvalds /* caller was supposed to have unlinked any requests; 9781da177e4SLinus Torvalds * that's not our job. just leak this memory. 9791da177e4SLinus Torvalds */ 9801da177e4SLinus Torvalds ehci_err (ehci, "qh %p (#%02x) state %d%s\n", 9811da177e4SLinus Torvalds qh, ep->desc.bEndpointAddress, qh->qh_state, 9821da177e4SLinus Torvalds list_empty (&qh->qtd_list) ? "" : "(has tds)"); 9831da177e4SLinus Torvalds break; 9841da177e4SLinus Torvalds } 9851da177e4SLinus Torvalds ep->hcpriv = NULL; 9861da177e4SLinus Torvalds done: 9871da177e4SLinus Torvalds spin_unlock_irqrestore (&ehci->lock, flags); 9881da177e4SLinus Torvalds return; 9891da177e4SLinus Torvalds } 9901da177e4SLinus Torvalds 9917ff71d6aSMatt Porter static int ehci_get_frame (struct usb_hcd *hcd) 9927ff71d6aSMatt Porter { 9937ff71d6aSMatt Porter struct ehci_hcd *ehci = hcd_to_ehci (hcd); 994083522d7SBenjamin Herrenschmidt return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) % 995083522d7SBenjamin Herrenschmidt ehci->periodic_size; 9967ff71d6aSMatt Porter } 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 9991da177e4SLinus Torvalds 10001da177e4SLinus Torvalds #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC 10011da177e4SLinus Torvalds 10021da177e4SLinus Torvalds MODULE_DESCRIPTION (DRIVER_INFO); 10031da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR); 10041da177e4SLinus Torvalds MODULE_LICENSE ("GPL"); 10051da177e4SLinus Torvalds 10067ff71d6aSMatt Porter #ifdef CONFIG_PCI 10077ff71d6aSMatt Porter #include "ehci-pci.c" 100801cced25SKumar Gala #define PCI_DRIVER ehci_pci_driver 10097ff71d6aSMatt Porter #endif 10101da177e4SLinus Torvalds 1011ba02978aSLi Yang #ifdef CONFIG_USB_EHCI_FSL 101280cb9aeeSRandy Vinson #include "ehci-fsl.c" 101301cced25SKumar Gala #define PLATFORM_DRIVER ehci_fsl_driver 101480cb9aeeSRandy Vinson #endif 101580cb9aeeSRandy Vinson 1016dfbaa7d8SRalf Baechle #ifdef CONFIG_SOC_AU1200 101776fa9a24SJordan Crouse #include "ehci-au1xxx.c" 101801cced25SKumar Gala #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver 101976fa9a24SJordan Crouse #endif 102076fa9a24SJordan Crouse 1021ad75a410SGeoff Levand #ifdef CONFIG_PPC_PS3 1022ad75a410SGeoff Levand #include "ehci-ps3.c" 10237a4eb7fdSGeoff Levand #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver 1024ad75a410SGeoff Levand #endif 1025ad75a410SGeoff Levand 1026da0e8fb0SValentine Barshak #if defined(CONFIG_440EPX) && !defined(CONFIG_PPC_MERGE) 1027fc65a15fSStefan Roese #include "ehci-ppc-soc.c" 1028fc65a15fSStefan Roese #define PLATFORM_DRIVER ehci_ppc_soc_driver 1029fc65a15fSStefan Roese #endif 1030fc65a15fSStefan Roese 1031da0e8fb0SValentine Barshak #ifdef CONFIG_USB_EHCI_HCD_PPC_OF 1032da0e8fb0SValentine Barshak #include "ehci-ppc-of.c" 1033da0e8fb0SValentine Barshak #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver 1034da0e8fb0SValentine Barshak #endif 1035da0e8fb0SValentine Barshak 1036e96ffe2fSTzachi Perelstein #ifdef CONFIG_ARCH_ORION 1037e96ffe2fSTzachi Perelstein #include "ehci-orion.c" 1038e96ffe2fSTzachi Perelstein #define PLATFORM_DRIVER ehci_orion_driver 1039e96ffe2fSTzachi Perelstein #endif 1040e96ffe2fSTzachi Perelstein 104191bc4d31SVladimir Barinov #ifdef CONFIG_ARCH_IXP4XX 104291bc4d31SVladimir Barinov #include "ehci-ixp4xx.c" 104391bc4d31SVladimir Barinov #define PLATFORM_DRIVER ixp4xx_ehci_driver 104491bc4d31SVladimir Barinov #endif 104591bc4d31SVladimir Barinov 1046ad75a410SGeoff Levand #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1047c6dd2e61SAnton Vorontsov !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) 10487ff71d6aSMatt Porter #error "missing bus glue for ehci-hcd" 10497ff71d6aSMatt Porter #endif 105001cced25SKumar Gala 105101cced25SKumar Gala static int __init ehci_hcd_init(void) 105201cced25SKumar Gala { 105301cced25SKumar Gala int retval = 0; 105401cced25SKumar Gala 105501cced25SKumar Gala pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", 105601cced25SKumar Gala hcd_name, 105701cced25SKumar Gala sizeof(struct ehci_qh), sizeof(struct ehci_qtd), 105801cced25SKumar Gala sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); 105901cced25SKumar Gala 1060694cc208STony Jones #ifdef DEBUG 1061694cc208STony Jones ehci_debug_root = debugfs_create_dir("ehci", NULL); 1062694cc208STony Jones if (!ehci_debug_root) 1063694cc208STony Jones return -ENOENT; 1064694cc208STony Jones #endif 1065694cc208STony Jones 106601cced25SKumar Gala #ifdef PLATFORM_DRIVER 106701cced25SKumar Gala retval = platform_driver_register(&PLATFORM_DRIVER); 1068da0e8fb0SValentine Barshak if (retval < 0) 1069da0e8fb0SValentine Barshak goto clean0; 107001cced25SKumar Gala #endif 107101cced25SKumar Gala 107201cced25SKumar Gala #ifdef PCI_DRIVER 107301cced25SKumar Gala retval = pci_register_driver(&PCI_DRIVER); 1074da0e8fb0SValentine Barshak if (retval < 0) 1075da0e8fb0SValentine Barshak goto clean1; 1076ad75a410SGeoff Levand #endif 1077ad75a410SGeoff Levand 1078ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER 10797a4eb7fdSGeoff Levand retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); 1080da0e8fb0SValentine Barshak if (retval < 0) 1081da0e8fb0SValentine Barshak goto clean2; 1082da0e8fb0SValentine Barshak #endif 1083da0e8fb0SValentine Barshak 1084da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER 1085da0e8fb0SValentine Barshak retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); 1086da0e8fb0SValentine Barshak if (retval < 0) 1087da0e8fb0SValentine Barshak goto clean3; 1088da0e8fb0SValentine Barshak #endif 1089da0e8fb0SValentine Barshak return retval; 1090da0e8fb0SValentine Barshak 1091da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER 1092da0e8fb0SValentine Barshak /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */ 1093da0e8fb0SValentine Barshak clean3: 1094da0e8fb0SValentine Barshak #endif 1095da0e8fb0SValentine Barshak #ifdef PS3_SYSTEM_BUS_DRIVER 1096da0e8fb0SValentine Barshak ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1097da0e8fb0SValentine Barshak clean2: 1098da0e8fb0SValentine Barshak #endif 1099da0e8fb0SValentine Barshak #ifdef PCI_DRIVER 1100da0e8fb0SValentine Barshak pci_unregister_driver(&PCI_DRIVER); 1101da0e8fb0SValentine Barshak clean1: 1102da0e8fb0SValentine Barshak #endif 1103da0e8fb0SValentine Barshak #ifdef PLATFORM_DRIVER 1104da0e8fb0SValentine Barshak platform_driver_unregister(&PLATFORM_DRIVER); 1105da0e8fb0SValentine Barshak clean0: 1106da0e8fb0SValentine Barshak #endif 1107694cc208STony Jones #ifdef DEBUG 1108694cc208STony Jones debugfs_remove(ehci_debug_root); 1109694cc208STony Jones ehci_debug_root = NULL; 1110694cc208STony Jones #endif 111101cced25SKumar Gala return retval; 111201cced25SKumar Gala } 111301cced25SKumar Gala module_init(ehci_hcd_init); 111401cced25SKumar Gala 111501cced25SKumar Gala static void __exit ehci_hcd_cleanup(void) 111601cced25SKumar Gala { 1117da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER 1118da0e8fb0SValentine Barshak of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1119da0e8fb0SValentine Barshak #endif 112001cced25SKumar Gala #ifdef PLATFORM_DRIVER 112101cced25SKumar Gala platform_driver_unregister(&PLATFORM_DRIVER); 112201cced25SKumar Gala #endif 112301cced25SKumar Gala #ifdef PCI_DRIVER 112401cced25SKumar Gala pci_unregister_driver(&PCI_DRIVER); 112501cced25SKumar Gala #endif 1126ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER 11277a4eb7fdSGeoff Levand ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1128ad75a410SGeoff Levand #endif 1129694cc208STony Jones #ifdef DEBUG 1130694cc208STony Jones debugfs_remove(ehci_debug_root); 1131694cc208STony Jones #endif 113201cced25SKumar Gala } 113301cced25SKumar Gala module_exit(ehci_hcd_cleanup); 113401cced25SKumar Gala 1135