diff options
Diffstat (limited to 'packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch')
| -rw-r--r-- | packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch | 3185 |
1 files changed, 3185 insertions, 0 deletions
diff --git a/packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch b/packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch index e69de29bb2..ca093e1a67 100644 --- a/packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch +++ b/packages/linux/linux-mtx-1-2.4.27/08-usb-nonpci-2.4.24.patch @@ -0,0 +1,3185 @@ +diff -Nurb linux-mips-2.4.27/drivers/usb/host/Config.in linux/drivers/usb/host/Config.in +--- linux-mips-2.4.27/drivers/usb/host/Config.in 2003-11-17 02:07:42.000000000 +0100 ++++ linux/drivers/usb/host/Config.in 2004-11-23 11:24:10.599627448 +0100 +@@ -17,3 +17,4 @@ + dep_tristate ' SL811HS Alternate (x86, StrongARM, isosynchronous mode)' CONFIG_USB_SL811HS_ALT $CONFIG_USB $CONFIG_EXPERIMENTAL + dep_tristate ' SL811HS (x86, StrongARM) support, old driver' CONFIG_USB_SL811HS $CONFIG_USB $CONFIG_EXPERIMENTAL + fi ++dep_tristate ' Non-PCI OHCI support' CONFIG_USB_NON_PCI_OHCI $CONFIG_USB_OHCI +diff -Nurb linux-mips-2.4.27/drivers/usb/host/usb-ohci.c linux/drivers/usb/host/usb-ohci.c +--- linux-mips-2.4.27/drivers/usb/host/usb-ohci.c 2004-04-16 05:14:18.000000000 +0200 ++++ linux/drivers/usb/host/usb-ohci.c 2004-11-23 11:24:10.602626992 +0100 +@@ -2564,6 +2564,7 @@ + hc_release_ohci (ohci); + return ret; + } ++#ifndef CONFIG_USB_NON_PCI_OHCI + ohci->flags = id->driver_data; + + /* Check for NSC87560. We have to look at the bridge (fn1) to identify +@@ -2582,6 +2583,7 @@ + printk (KERN_INFO __FILE__ ": Using NSC SuperIO setup\n"); + if (ohci->flags & OHCI_QUIRK_AMD756) + printk (KERN_INFO __FILE__ ": AMD756 erratum 4 workaround\n"); ++#endif + + if (hc_reset (ohci) < 0) { + hc_release_ohci (ohci); +@@ -2627,8 +2629,10 @@ + int temp; + int i; + ++#ifndef CONFIG_USB_NON_PCI_OHCI + if (ohci->pci_latency) + pci_write_config_byte (ohci->ohci_dev, PCI_LATENCY_TIMER, ohci->pci_latency); ++#endif + + ohci->disabled = 1; + ohci->sleeping = 0; +@@ -2658,6 +2662,7 @@ + + /*-------------------------------------------------------------------------*/ + ++#ifndef CONFIG_USB_NON_PCI_OHCI + /* configured so that an OHCI device is always provided */ + /* always called with process context; sleeping is OK */ + +@@ -2705,6 +2710,88 @@ + } + return status; + } ++#else /* CONFIG_USB_NON_PCI_OHCI */ ++ ++// Boot options ++static int ohci_base=0, ohci_len=0; ++static int ohci_irq=-1; ++ ++MODULE_PARM(ohci_base, "i"); ++MODULE_PARM(ohci_len, "i"); ++MODULE_PARM(ohci_irq, "i"); ++MODULE_PARM_DESC(ohci_base, "IO Base address of OHCI Oper. registers"); ++MODULE_PARM_DESC(ohci_len, "IO length of OHCI Oper. registers"); ++MODULE_PARM_DESC(ohci_irq, "IRQ for OHCI interrupts"); ++ ++// bogus pci_dev ++static struct pci_dev bogus_pcidev; ++ ++static struct pci_driver ohci_pci_driver = { ++ name: "usb-ohci", ++}; ++ ++static int __devinit ++ohci_non_pci_init (void) ++{ ++ void *mem_base; ++ ++ if (!ohci_base || !ohci_len || (ohci_irq < 0)) ++ return -ENODEV; ++ ++ if (!request_mem_region (ohci_base, ohci_len, ohci_pci_driver.name)) { ++ dbg ("controller already in use"); ++ return -EBUSY; ++ } ++ ++ mem_base = ioremap_nocache (ohci_base, ohci_len); ++ if (!mem_base) { ++ err("Error mapping OHCI memory"); ++ return -EFAULT; ++ } ++ ++ /* ++ * Fill in the bogus pci_dev. Only those members actually ++ * dereferenced in this driver are initialized. ++ */ ++ memset(&bogus_pcidev, 0, sizeof(struct pci_dev)); ++ strcpy(bogus_pcidev.name, "non-PCI OHCI"); ++ strcpy(bogus_pcidev.slot_name, "builtin"); ++ bogus_pcidev.resource[0].name = "OHCI Operational Registers"; ++ bogus_pcidev.resource[0].start = ohci_base; ++ bogus_pcidev.resource[0].end = ohci_base + ohci_len; ++ bogus_pcidev.resource[0].flags = 0; ++ bogus_pcidev.irq = ohci_irq; ++ ++ return hc_found_ohci (&bogus_pcidev, bogus_pcidev.irq, mem_base, NULL); ++} ++ ++#ifndef MODULE ++ ++static int __init ++ohci_setup (char* options) ++{ ++ char* this_opt; ++ ++ if (!options || !*options) ++ return 0; ++ ++ for(this_opt=strtok(options,",");this_opt;this_opt=strtok(NULL,",")) { ++ if (!strncmp(this_opt, "base:", 5)) { ++ ohci_base = simple_strtoul(this_opt+5, NULL, 0); ++ } else if (!strncmp(this_opt, "len:", 4)) { ++ ohci_len = simple_strtoul(this_opt+4, NULL, 0); ++ } else if (!strncmp(this_opt, "irq:", 4)) { ++ ohci_irq = simple_strtoul(this_opt+4, NULL, 0); ++ } ++ } ++ return 0; ++} ++ ++__setup("usb_ohci=", ohci_setup); ++ ++#endif /* !MODULE */ ++ ++#endif /* CONFIG_USB_NON_PCI_OHCI */ + + /*-------------------------------------------------------------------------*/ + +@@ -2745,6 +2832,7 @@ + } + + ++#ifndef CONFIG_USB_NON_PCI_OHCI + #ifdef CONFIG_PM + + /*-------------------------------------------------------------------------*/ +@@ -2983,20 +3071,29 @@ + resume: ohci_pci_resume, + #endif /* PM */ + }; ++#endif /* CONFIG_USB_NON_PCI_OHCI */ + + + /*-------------------------------------------------------------------------*/ + + static int __init ohci_hcd_init (void) + { ++#ifndef CONFIG_USB_NON_PCI_OHCI + return pci_module_init (&ohci_pci_driver); ++#else ++ return ohci_non_pci_init(); ++#endif + } + + /*-------------------------------------------------------------------------*/ + + static void __exit ohci_hcd_cleanup (void) + { ++#ifndef CONFIG_USB_NON_PCI_OHCI + pci_unregister_driver (&ohci_pci_driver); ++#else ++ ohci_pci_remove(&bogus_pcidev); ++#endif + } + + module_init (ohci_hcd_init); +diff -Nurb linux-mips-2.4.27/drivers/usb/host/usb-ohci.c.orig linux/drivers/usb/host/usb-ohci.c.orig +--- linux-mips-2.4.27/drivers/usb/host/usb-ohci.c.orig 1970-01-01 01:00:00.000000000 +0100 ++++ linux/drivers/usb/host/usb-ohci.c.orig 2004-11-23 11:21:54.984244120 +0100 +@@ -0,0 +1,3008 @@ ++/* ++ * URB OHCI HCD (Host Controller Driver) for USB. ++ * ++ * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> ++ * (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net> ++ * ++ * [ Initialisation is based on Linus' ] ++ * [ uhci code and gregs ohci fragments ] ++ * [ (C) Copyright 1999 Linus Torvalds ] ++ * [ (C) Copyright 1999 Gregory P. Smith] ++ * ++ * ++ * History: ++ * ++ * 2002/10/22 OHCI_USB_OPER for ALi lockup in IBM i1200 (ALEX <thchou@ali>) ++ * 2002/03/08 interrupt unlink fix (Matt Hughes), better cleanup on ++ * load failure (Matthew Frederickson) ++ * 2002/01/20 async unlink fixes: return -EINPROGRESS (per spec) and ++ * make interrupt unlink-in-completion work (db) ++ * 2001/09/19 USB_ZERO_PACKET support (Jean Tourrilhes) ++ * 2001/07/17 power management and pmac cleanup (Benjamin Herrenschmidt) ++ * 2001/03/24 td/ed hashing to remove bus_to_virt (Steve Longerbeam); ++ pci_map_single (db) ++ * 2001/03/21 td and dev/ed allocation uses new pci_pool API (db) ++ * 2001/03/07 hcca allocation uses pci_alloc_consistent (Steve Longerbeam) ++ * ++ * 2000/09/26 fixed races in removing the private portion of the urb ++ * 2000/09/07 disable bulk and control lists when unlinking the last ++ * endpoint descriptor in order to avoid unrecoverable errors on ++ * the Lucent chips. (rwc@sgi) ++ * 2000/08/29 use bandwidth claiming hooks (thanks Randy!), fix some ++ * urb unlink probs, indentation fixes ++ * 2000/08/11 various oops fixes mostly affecting iso and cleanup from ++ * device unplugs. ++ * 2000/06/28 use PCI hotplug framework, for better power management ++ * and for Cardbus support (David Brownell) ++ * 2000/earlier: fixes for NEC/Lucent chips; suspend/resume handling ++ * when the controller loses power; handle UE; cleanup; ... ++ * ++ * v5.2 1999/12/07 URB 3rd preview, ++ * v5.1 1999/11/30 URB 2nd preview, cpia, (usb-scsi) ++ * v5.0 1999/11/22 URB Technical preview, Paul Mackerras powerbook susp/resume ++ * i386: HUB, Keyboard, Mouse, Printer ++ * ++ * v4.3 1999/10/27 multiple HCs, bulk_request ++ * v4.2 1999/09/05 ISO API alpha, new dev alloc, neg Error-codes ++ * v4.1 1999/08/27 Randy Dunlap's - ISO API first impl. ++ * v4.0 1999/08/18 ++ * v3.0 1999/06/25 ++ * v2.1 1999/05/09 code clean up ++ * v2.0 1999/05/04 ++ * v1.0 1999/04/27 initial release ++ */ ++ ++#include <linux/config.h> ++#include <linux/module.h> ++#include <linux/pci.h> ++#include <linux/kernel.h> ++#include <linux/delay.h> ++#include <linux/ioport.h> ++#include <linux/sched.h> ++#include <linux/slab.h> ++#include <linux/smp_lock.h> ++#include <linux/errno.h> ++#include <linux/init.h> ++#include <linux/timer.h> ++#include <linux/list.h> ++#include <linux/interrupt.h> /* for in_interrupt() */ ++#undef DEBUG ++#include <linux/usb.h> ++ ++#include <asm/io.h> ++#include <asm/irq.h> ++#include <asm/system.h> ++#include <asm/unaligned.h> ++ ++#define OHCI_USE_NPS // force NoPowerSwitching mode ++// #define OHCI_VERBOSE_DEBUG /* not always helpful */ ++ ++#include "usb-ohci.h" ++ ++#include "../hcd.h" ++ ++#ifdef CONFIG_PMAC_PBOOK ++#include <asm/machdep.h> ++#include <asm/pmac_feature.h> ++#include <asm/pci-bridge.h> ++#ifndef CONFIG_PM ++#define CONFIG_PM ++#endif ++#endif ++ ++ ++/* ++ * Version Information ++ */ ++#define DRIVER_VERSION "v5.3" ++#define DRIVER_AUTHOR "Roman Weissgaerber <weissg@vienna.at>, David Brownell" ++#define DRIVER_DESC "USB OHCI Host Controller Driver" ++ ++/* For initializing controller (mask in an HCFS mode too) */ ++#define OHCI_CONTROL_INIT \ ++ (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE ++ ++#define OHCI_UNLINK_TIMEOUT (HZ / 10) ++ ++/*-------------------------------------------------------------------------*/ ++ ++/* AMD-756 (D2 rev) reports corrupt register contents in some cases. ++ * The erratum (#4) description is incorrect. AMD's workaround waits ++ * till some bits (mostly reserved) are clear; ok for all revs. ++ */ ++#define read_roothub(hc, register, mask) ({ \ ++ u32 temp = readl (&hc->regs->roothub.register); \ ++ if (hc->flags & OHCI_QUIRK_AMD756) \ ++ while (temp & mask) \ ++ temp = readl (&hc->regs->roothub.register); \ ++ temp; }) ++ ++static u32 roothub_a (struct ohci *hc) ++ { return read_roothub (hc, a, 0xfc0fe000); } ++static inline u32 roothub_b (struct ohci *hc) ++ { return readl (&hc->regs->roothub.b); } ++static inline u32 roothub_status (struct ohci *hc) ++ { return readl (&hc->regs->roothub.status); } ++static u32 roothub_portstatus (struct ohci *hc, int i) ++ { return read_roothub (hc, portstatus [i], 0xffe0fce0); } ++ ++ ++/*-------------------------------------------------------------------------* ++ * URB support functions ++ *-------------------------------------------------------------------------*/ ++ ++static void ohci_complete_add(struct ohci *ohci, struct urb *urb) ++{ ++ ++ if (urb->hcpriv != NULL) { ++ printk("completing with non-null priv!\n"); ++ return; ++ } ++ ++ if (ohci->complete_tail == NULL) { ++ ohci->complete_head = urb; ++ ohci->complete_tail = urb; ++ } else { ++ ohci->complete_head->hcpriv = urb; ++ ohci->complete_tail = urb; ++ } ++} ++ ++static inline struct urb *ohci_complete_get(struct ohci *ohci) ++{ ++ struct urb *urb; ++ ++ if ((urb = ohci->complete_head) == NULL) ++ return NULL; ++ if (urb == ohci->complete_tail) { ++ ohci->complete_tail = NULL; ++ ohci->complete_head = NULL; ++ } else { ++ ohci->complete_head = urb->hcpriv; ++ } ++ urb->hcpriv = NULL; ++ return urb; ++} ++ ++static inline void ohci_complete(struct ohci *ohci) ++{ ++ struct urb *urb; ++ ++ spin_lock(&ohci->ohci_lock); ++ while ((urb = ohci_complete_get(ohci)) != NULL) { ++ spin_unlock(&ohci->ohci_lock); ++ if (urb->dev) { ++ usb_dec_dev_use (urb->dev); ++ urb->dev = NULL; ++ } ++ if (urb->complete) ++ (*urb->complete)(urb); ++ spin_lock(&ohci->ohci_lock); ++ } ++ spin_unlock(&ohci->ohci_lock); ++} ++ ++/* free HCD-private data associated with this URB */ ++ ++static void urb_free_priv (struct ohci *hc, urb_priv_t * urb_priv) ++{ ++ int i; ++ int last = urb_priv->length - 1; ++ int len; ++ int dir; ++ struct td *td; ++ ++ if (last >= 0) { ++ ++ /* ISOC, BULK, INTR data buffer starts at td 0 ++ * CTRL setup starts at td 0 */ ++ td = urb_priv->td [0]; ++ ++ len = td->urb->transfer_buffer_length, ++ dir = usb_pipeout (td->urb->pipe) ++ ? PCI_DMA_TODEVICE ++ : PCI_DMA_FROMDEVICE; ++ ++ /* unmap CTRL URB setup */ ++ if (usb_pipecontrol (td->urb->pipe)) { ++ pci_unmap_single (hc->ohci_dev, ++ td->data_dma, 8, PCI_DMA_TODEVICE); ++ ++ /* CTRL data buffer starts at td 1 if len > 0 */ ++ if (len && last > 0) ++ td = urb_priv->td [1]; ++ } ++ ++ /* unmap data buffer */ ++ if (len && td->data_dma) ++ pci_unmap_single (hc->ohci_dev, td->data_dma, len, dir); ++ ++ for (i = 0; i <= last; i++) { ++ td = urb_priv->td [i]; ++ if (td) ++ td_free (hc, td); ++ } ++ } ++ ++ kfree (urb_priv); ++} ++ ++static void urb_rm_priv_locked (struct urb * urb) ++{ ++ urb_priv_t * urb_priv = urb->hcpriv; ++ ++ if (urb_priv) { ++ urb->hcpriv = NULL; ++ ++#ifdef DO_TIMEOUTS ++ if (urb->timeout) { ++ list_del (&urb->urb_list); ++ urb->timeout -= jiffies; ++ } ++#endif ++ ++ /* Release int/iso bandwidth */ ++ if (urb->bandwidth) { ++ switch (usb_pipetype(urb->pipe)) { ++ case PIPE_INTERRUPT: ++ usb_release_bandwidth (urb->dev, urb, 0); ++ break; ++ case PIPE_ISOCHRONOUS: ++ usb_release_bandwidth (urb->dev, urb, 1); ++ break; ++ default: ++ break; ++ } ++ } ++ ++ urb_free_priv ((struct ohci *)urb->dev->bus->hcpriv, urb_priv); ++ } else { ++ if (urb->dev != NULL) { ++ err ("Non-null dev at rm_priv time"); ++ // urb->dev = NULL; ++ } ++ } ++} ++ ++/*-------------------------------------------------------------------------*/ ++ ++#ifdef DEBUG ++static int sohci_get_current_frame_number (struct usb_device * dev); ++ ++/* debug| print the main components of an URB ++ * small: 0) header + data packets 1) just header */ ++ ++static void urb_print (struct urb * urb, char * str, int small) ++{ ++ unsigned int pipe= urb->pipe; ++ ++ if (!urb->dev || !urb->dev->bus) { ++ dbg("%s URB: no dev", str); ++ return; ++ } ++ ++#ifndef OHCI_VERBOSE_DEBUG ++ if (urb->status != 0) ++#endif ++ dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,flags:%4x,len:%d/%d,stat:%d(%x)", ++ str, ++ sohci_get_current_frame_number (urb->dev), ++ usb_pipedevice (pipe), ++ usb_pipeendpoint (pipe), ++ usb_pipeout (pipe)? 'O': 'I', ++ usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"): ++ (usb_pipecontrol (pipe)? "CTRL": "BULK"), ++ urb->transfer_flags, ++ urb->actual_length, ++ urb->transfer_buffer_length, ++ urb->status, urb->status); ++#ifdef OHCI_VERBOSE_DEBUG ++ if (!small) { ++ int i, len; ++ ++ if (usb_pipecontrol (pipe)) { ++ printk (KERN_DEBUG __FILE__ ": cmd(8):"); ++ for (i = 0; i < 8 ; i++) ++ printk (" %02x", ((__u8 *) urb->setup_packet) [i]); ++ printk ("\n"); ++ } ++ if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) { ++ printk (KERN_DEBUG __FILE__ ": data(%d/%d):", ++ urb->actual_length, ++ urb->transfer_buffer_length); ++ len = usb_pipeout (pipe)? ++ urb->transfer_buffer_length: urb->actual_length; ++ for (i = 0; i < 16 && i < len; i++) ++ printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]); ++ printk ("%s stat:%d\n", i < len? "...": "", urb->status); ++ } ++ } ++#endif ++} ++ ++/* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/ ++void ep_print_int_eds (ohci_t * ohci, char * str) { ++ int i, j; ++ __u32 * ed_p; ++ for (i= 0; i < 32; i++) { ++ j = 5; ++ ed_p = &(ohci->hcca->int_table [i]); ++ if (*ed_p == 0) ++ continue; ++ printk (KERN_DEBUG __FILE__ ": %s branch int %2d(%2x):", str, i, i); ++ while (*ed_p != 0 && j--) { ++ ed_t *ed = dma_to_ed (ohci, le32_to_cpup(ed_p)); ++ printk (" ed: %4x;", ed->hwINFO); ++ ed_p = &ed->hwNextED; ++ } ++ printk ("\n"); ++ } ++} ++ ++ ++static void ohci_dump_intr_mask (char *label, __u32 mask) ++{ ++ dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s", ++ label, ++ mask, ++ (mask & OHCI_INTR_MIE) ? " MIE" : "", ++ (mask & OHCI_INTR_OC) ? " OC" : "", ++ (mask & OHCI_INTR_RHSC) ? " RHSC" : "", ++ (mask & OHCI_INTR_FNO) ? " FNO" : "", ++ (mask & OHCI_INTR_UE) ? " UE" : "", ++ (mask & OHCI_INTR_RD) ? " RD" : "", ++ (mask & OHCI_INTR_SF) ? " SF" : "", ++ (mask & OHCI_INTR_WDH) ? " WDH" : "", ++ (mask & OHCI_INTR_SO) ? " SO" : "" ++ ); ++} ++ ++static void maybe_print_eds (char *label, __u32 value) ++{ ++ if (value) ++ dbg ("%s %08x", label, value); ++} ++ ++static char *hcfs2string (int state) ++{ ++ switch (state) { ++ case OHCI_USB_RESET: return "reset"; ++ case OHCI_USB_RESUME: return "resume"; ++ case OHCI_USB_OPER: return "operational"; ++ case OHCI_USB_SUSPEND: return "suspend"; ++ } ++ return "?"; ++} ++ ++// dump control and status registers ++static void ohci_dump_status (ohci_t *controller) ++{ ++ struct ohci_regs *regs = controller->regs; ++ __u32 temp; ++ ++ temp = readl (®s->revision) & 0xff; ++ if (temp != 0x10) ++ dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f)); ++ ++ temp = readl (®s->control); ++ dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp, ++ (temp & OHCI_CTRL_RWE) ? " RWE" : "", ++ (temp & OHCI_CTRL_RWC) ? " RWC" : "", ++ (temp & OHCI_CTRL_IR) ? " IR" : "", ++ hcfs2string (temp & OHCI_CTRL_HCFS), ++ (temp & OHCI_CTRL_BLE) ? " BLE" : "", ++ (temp & OHCI_CTRL_CLE) ? " CLE" : "", ++ (temp & OHCI_CTRL_IE) ? " IE" : "", ++ (temp & OHCI_CTRL_PLE) ? " PLE" : "", ++ temp & OHCI_CTRL_CBSR ++ ); ++ ++ temp = readl (®s->cmdstatus); ++ dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp, ++ (temp & OHCI_SOC) >> 16, ++ (temp & OHCI_OCR) ? " OCR" : "", ++ (temp & OHCI_BLF) ? " BLF" : "", ++ (temp & OHCI_CLF) ? " CLF" : "", ++ (temp & OHCI_HCR) ? " HCR" : "" ++ ); ++ ++ ohci_dump_intr_mask ("intrstatus", readl (®s->intrstatus)); ++ ohci_dump_intr_mask ("intrenable", readl (®s->intrenable)); ++ // intrdisable always same as intrenable ++ // ohci_dump_intr_mask ("intrdisable", readl (®s->intrdisable)); ++ ++ maybe_print_eds ("ed_periodcurrent", readl (®s->ed_periodcurrent)); ++ ++ maybe_print_eds ("ed_controlhead", readl (®s->ed_controlhead)); ++ maybe_print_eds ("ed_controlcurrent", readl (®s->ed_controlcurrent)); ++ ++ maybe_print_eds ("ed_bulkhead", readl (®s->ed_bulkhead)); ++ maybe_print_eds ("ed_bulkcurrent", readl (®s->ed_bulkcurrent)); ++ ++ maybe_print_eds ("donehead", readl (®s->donehead)); ++} ++ ++static void ohci_dump_roothub (ohci_t *controller, int verbose) ++{ ++ __u32 temp, ndp, i; ++ ++ temp = roothub_a (controller); ++ if (temp == ~(u32)0) ++ return; ++ ndp = (temp & RH_A_NDP); ++ ++ if (verbose) { ++ dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp, ++ ((temp & RH_A_POTPGT) >> 24) & 0xff, ++ (temp & RH_A_NOCP) ? " NOCP" : "", ++ (temp & RH_A_OCPM) ? " OCPM" : "", ++ (temp & RH_A_DT) ? " DT" : "", ++ (temp & RH_A_NPS) ? " NPS" : "", ++ (temp & RH_A_PSM) ? " PSM" : "", ++ ndp ++ ); ++ temp = roothub_b (controller); ++ dbg ("roothub.b: %08x PPCM=%04x DR=%04x", ++ temp, ++ (temp & RH_B_PPCM) >> 16, ++ (temp & RH_B_DR) ++ ); ++ temp = roothub_status (controller); ++ dbg ("roothub.status: %08x%s%s%s%s%s%s", ++ temp, ++ (temp & RH_HS_CRWE) ? " CRWE" : "", ++ (temp & RH_HS_OCIC) ? " OCIC" : "", ++ (temp & RH_HS_LPSC) ? " LPSC" : "", ++ (temp & RH_HS_DRWE) ? " DRWE" : "", ++ (temp & RH_HS_OCI) ? " OCI" : "", ++ (temp & RH_HS_LPS) ? " LPS" : "" ++ ); ++ } ++ ++ for (i = 0; i < ndp; i++) { ++ temp = roothub_portstatus (controller, i); ++ dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s", ++ i, ++ temp, ++ (temp & RH_PS_PRSC) ? " PRSC" : "", ++ (temp & RH_PS_OCIC) ? " OCIC" : "", ++ (temp & RH_PS_PSSC) ? " PSSC" : "", ++ (temp & RH_PS_PESC) ? " PESC" : "", ++ (temp & RH_PS_CSC) ? " CSC" : "", ++ ++ (temp & RH_PS_LSDA) ? " LSDA" : "", ++ (temp & RH_PS_PPS) ? " PPS" : "", ++ (temp & RH_PS_PRS) ? " PRS" : "", ++ (temp & RH_PS_POCI) ? " POCI" : "", ++ (temp & RH_PS_PSS) ? " PSS" : "", ++ ++ (temp & RH_PS_PES) ? " PES" : "", ++ (temp & RH_PS_CCS) ? " CCS" : "" ++ ); ++ } ++} ++ ++static void ohci_dump (ohci_t *controller, int verbose) ++{ ++ dbg ("OHCI controller usb-%s state", controller->ohci_dev->slot_name); ++ ++ // dumps some of the state we know about ++ ohci_dump_status (controller); ++ if (verbose) ++ ep_print_int_eds (controller, "hcca"); ++ dbg ("hcca frame #%04x", controller->hcca->frame_no); ++ ohci_dump_roothub (controller, 1); ++} ++ ++ ++#endif ++ ++/*-------------------------------------------------------------------------* ++ * Interface functions (URB) ++ *-------------------------------------------------------------------------*/ ++ ++/* return a request to the completion handler */ ++ ++static int sohci_return_urb (struct ohci *hc, struct urb * urb) ++{ ++ urb_priv_t * urb_priv = urb->hcpriv; ++ struct urb * urbt; ++ int i; ++ ++ if (!urb_priv) ++ return -1; /* urb already unlinked */ ++ ++ /* just to be sure */ ++ if (!urb->complete) { ++ urb_rm_priv_locked (urb); ++ ohci_complete_add(hc, urb); /* Just usb_dec_dev_use */ ++ return -1; ++ } ++ ++#ifdef DEBUG ++ urb_print (urb, "RET", usb_pipeout (urb->pipe)); ++#endif ++ ++ switch (usb_pipetype (urb->pipe)) { ++ case PIPE_INTERRUPT: ++ pci_unmap_single (hc->ohci_dev, ++ urb_priv->td [0]->data_dma, ++ urb->transfer_buffer_length, ++ usb_pipeout (urb->pipe) ++ ? PCI_DMA_TODEVICE ++ : PCI_DMA_FROMDEVICE); ++ if (urb->interval) { ++ urb->complete (urb); ++ ++ /* implicitly requeued */ ++ urb->actual_length = 0; ++ urb->status = -EINPROGRESS; ++ td_submit_urb (urb); ++ } else { ++ urb_rm_priv_locked (urb); ++ ohci_complete_add(hc, urb); ++ } ++ break; ++ ++ case PIPE_ISOCHRONOUS: ++ for (urbt = urb->next; urbt && (urbt != urb); urbt = urbt->next); ++ if (urbt) { /* send the reply and requeue URB */ ++ pci_unmap_single (hc->ohci_dev, ++ urb_priv->td [0]->data_dma, ++ urb->transfer_buffer_length, ++ usb_pipeout (urb->pipe) ++ ? PCI_DMA_TODEVICE ++ : PCI_DMA_FROMDEVICE); ++ urb->complete (urb); ++ urb->actual_length = 0; ++ urb->status = USB_ST_URB_PENDING; ++ urb->start_frame = urb_priv->ed->last_iso + 1; ++ if (urb_priv->state != URB_DEL) { ++ for (i = 0; i < urb->number_of_packets; i++) { ++ urb->iso_frame_desc[i].actual_length = 0; ++ urb->iso_frame_desc[i].status = -EXDEV; ++ } ++ td_submit_urb (urb); ++ } ++ ++ } else { /* unlink URB, call complete */ ++ urb_rm_priv_locked (urb); ++ ohci_complete_add(hc, urb); ++ } ++ break; ++ ++ case PIPE_BULK: ++ case PIPE_CONTROL: /* unlink URB, call complete */ ++ urb_rm_priv_locked (urb); ++ ohci_complete_add(hc, urb); ++ break; ++ } ++ return 0; ++} ++ ++/*-------------------------------------------------------------------------*/ ++ ++/* get a transfer request */ ++ ++static int sohci_submit_urb (struct urb * urb) ++{ ++ ohci_t * ohci; ++ ed_t * ed; ++ urb_priv_t * urb_priv; ++ unsigned int pipe = urb->pipe; ++ int maxps = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe)); ++ int i, size = 0; ++ unsigned long flags; ++ int bustime = 0; ++ int mem_flags = GFP_ATOMIC; ++ ++ if (!urb->dev || !urb->dev->bus) ++ return -ENODEV; ++ ++ if (urb->hcpriv) /* urb already in use */ ++ return -EINVAL; ++ ++// if(usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe))) ++// return -EPIPE; ++ ++ usb_inc_dev_use (urb->dev); ++ ohci = (ohci_t *) urb->dev->bus->hcpriv; ++ ++#ifdef DEBUG ++ urb_print (urb, "SUB", usb_pipein (pipe)); ++#endif ++ ++ /* handle a request to the virtual root hub */ ++ if (usb_pipedevice (pipe) == ohci->rh.devnum) ++ return rh_submit_urb (urb); ++ ++ spin_lock_irqsave(&ohci->ohci_lock, flags); ++ ++ /* when controller's hung, permit only roothub cleanup attempts ++ * such as powering down ports */ ++ if (ohci->disabled) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -ESHUTDOWN; ++ } ++ ++ /* every endpoint has a ed, locate and fill it */ ++ if (!(ed = ep_add_ed (urb->dev, pipe, urb->interval, 1, mem_flags))) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -ENOMEM; ++ } ++ ++ /* for the private part of the URB we need the number of TDs (size) */ ++ switch (usb_pipetype (pipe)) { ++ case PIPE_BULK: /* one TD for every 4096 Byte */ ++ size = (urb->transfer_buffer_length - 1) / 4096 + 1; ++ ++ /* If the transfer size is multiple of the pipe mtu, ++ * we may need an extra TD to create a empty frame ++ * Jean II */ ++ if ((urb->transfer_flags & USB_ZERO_PACKET) && ++ usb_pipeout (pipe) && ++ (urb->transfer_buffer_length != 0) && ++ ((urb->transfer_buffer_length % maxps) == 0)) ++ size++; ++ break; ++ case PIPE_ISOCHRONOUS: /* number of packets from URB */ ++ size = urb->number_of_packets; ++ if (size <= 0) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -EINVAL; ++ } ++ for (i = 0; i < urb->number_of_packets; i++) { ++ urb->iso_frame_desc[i].actual_length = 0; ++ urb->iso_frame_desc[i].status = -EXDEV; ++ } ++ break; ++ case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */ ++ size = (urb->transfer_buffer_length == 0)? 2: ++ (urb->transfer_buffer_length - 1) / 4096 + 3; ++ break; ++ case PIPE_INTERRUPT: /* one TD */ ++ size = 1; ++ break; ++ } ++ ++ /* allocate the private part of the URB */ ++ urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (td_t *), ++ GFP_ATOMIC); ++ if (!urb_priv) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -ENOMEM; ++ } ++ memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (td_t *)); ++ ++ /* fill the private part of the URB */ ++ urb_priv->length = size; ++ urb_priv->ed = ed; ++ ++ /* allocate the TDs (updating hash chains) */ ++ for (i = 0; i < size; i++) { ++ urb_priv->td[i] = td_alloc (ohci, SLAB_ATOMIC); ++ if (!urb_priv->td[i]) { ++ urb_priv->length = i; ++ urb_free_priv (ohci, urb_priv); ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -ENOMEM; ++ } ++ } ++ ++ if (ed->state == ED_NEW || (ed->state & ED_DEL)) { ++ urb_free_priv (ohci, urb_priv); ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return -EINVAL; ++ } ++ ++ /* allocate and claim bandwidth if needed; ISO ++ * needs start frame index if it was't provided. ++ */ ++ switch (usb_pipetype (pipe)) { ++ case PIPE_ISOCHRONOUS: ++ if (urb->transfer_flags & USB_ISO_ASAP) { ++ urb->start_frame = ((ed->state == ED_OPER) ++ ? (ed->last_iso + 1) ++ : (le16_to_cpu (ohci->hcca->frame_no) + 10)) & 0xffff; ++ } ++ /* FALLTHROUGH */ ++ case PIPE_INTERRUPT: ++ if (urb->bandwidth == 0) { ++ bustime = usb_check_bandwidth (urb->dev, urb); ++ } ++ if (bustime < 0) { ++ urb_free_priv (ohci, urb_priv); ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ return bustime; ++ } ++ usb_claim_bandwidth (urb->dev, urb, bustime, usb_pipeisoc (urb->pipe)); ++#ifdef DO_TIMEOUTS ++ urb->timeout = 0; ++#endif ++ } ++ ++ urb->actual_length = 0; ++ urb->hcpriv = urb_priv; ++ urb->status = USB_ST_URB_PENDING; ++ ++ /* link the ed into a chain if is not already */ ++ if (ed->state != ED_OPER) ++ ep_link (ohci, ed); ++ ++ /* fill the TDs and link it to the ed */ ++ td_submit_urb (urb); ++ ++#ifdef DO_TIMEOUTS ++ /* maybe add to ordered list of timeouts */ ++ if (urb->timeout) { ++ struct list_head *entry; ++ ++ urb->timeout += jiffies; ++ ++ list_for_each (entry, &ohci->timeout_list) { ++ struct urb *next_urb; ++ ++ next_urb = list_entry (entry, struct urb, urb_list); ++ if (time_after_eq (urb->timeout, next_urb->timeout)) ++ break; ++ } ++ list_add (&urb->urb_list, entry); ++ ++ /* drive timeouts by SF (messy, but works) */ ++ writel (OHCI_INTR_SF, &ohci->regs->intrenable); ++ (void)readl (&ohci->regs->intrdisable); /* PCI posting flush */ ++ } ++#endif ++ ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ ++ return 0; ++} ++ ++/*-------------------------------------------------------------------------*/ ++ ++/* deactivate all TDs and remove the private part of the URB */ ++/* interrupt callers must use async unlink mode */ ++ ++static int sohci_unlink_urb (struct urb * urb) ++{ ++ unsigned long flags; ++ ohci_t * ohci; ++ ++ if (!urb) /* just to be sure */ ++ return -EINVAL; ++ ++ if (!urb->dev || !urb->dev->bus) ++ return -ENODEV; ++ ++ ohci = (ohci_t *) urb->dev->bus->hcpriv; ++ ++#ifdef DEBUG ++ urb_print (urb, "UNLINK", 1); ++#endif ++ ++ /* handle a request to the virtual root hub */ ++ if (usb_pipedevice (urb->pipe) == ohci->rh.devnum) ++ return rh_unlink_urb (urb); ++ ++ spin_lock_irqsave(&ohci->ohci_lock, flags); ++ if (urb->hcpriv && (urb->status == USB_ST_URB_PENDING)) { ++ if (!ohci->disabled) { ++ urb_priv_t * urb_priv; ++ ++ /* interrupt code may not sleep; it must use ++ * async status return to unlink pending urbs. ++ */ ++ if (!(urb->transfer_flags & USB_ASYNC_UNLINK) ++ && in_interrupt ()) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ err ("bug in call from %p; use async!", ++ __builtin_return_address(0)); ++ return -EWOULDBLOCK; ++ } ++ ++ /* flag the urb and its TDs for deletion in some ++ * upcoming SF interrupt delete list processing ++ */ ++ urb_priv = urb->hcpriv; ++ ++ if (!urb_priv || (urb_priv->state == URB_DEL)) { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ return 0; ++ } ++ ++ urb_priv->state = URB_DEL; ++ ep_rm_ed (urb->dev, urb_priv->ed); ++ urb_priv->ed->state |= ED_URB_DEL; ++ ++ if (!(urb->transfer_flags & USB_ASYNC_UNLINK)) { ++ DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup); ++ DECLARE_WAITQUEUE (wait, current); ++ int timeout = OHCI_UNLINK_TIMEOUT; ++ ++ add_wait_queue (&unlink_wakeup, &wait); ++ urb_priv->wait = &unlink_wakeup; ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ ++ /* wait until all TDs are deleted */ ++ set_current_state(TASK_UNINTERRUPTIBLE); ++ while (timeout && (urb->status == USB_ST_URB_PENDING)) { ++ timeout = schedule_timeout (timeout); ++ set_current_state(TASK_UNINTERRUPTIBLE); ++ } ++ set_current_state(TASK_RUNNING); ++ remove_wait_queue (&unlink_wakeup, &wait); ++ if (urb->status == USB_ST_URB_PENDING) { ++ err ("unlink URB timeout"); ++ return -ETIMEDOUT; ++ } ++ ++ usb_dec_dev_use (urb->dev); ++ urb->dev = NULL; ++ if (urb->complete) ++ urb->complete (urb); ++ } else { ++ /* usb_dec_dev_use done in dl_del_list() */ ++ urb->status = -EINPROGRESS; ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ return -EINPROGRESS; ++ } ++ } else { ++ urb_rm_priv_locked (urb); ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ usb_dec_dev_use (urb->dev); ++ urb->dev = NULL; ++ if (urb->transfer_flags & USB_ASYNC_UNLINK) { ++ urb->status = -ECONNRESET; ++ if (urb->complete) ++ urb->complete (urb); ++ } else ++ urb->status = -ENOENT; ++ } ++ } else { ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ } ++ return 0; ++} ++ ++/*-------------------------------------------------------------------------*/ ++ ++/* allocate private data space for a usb device */ ++ ++static int sohci_alloc_dev (struct usb_device *usb_dev) ++{ ++ struct ohci_device * dev; ++ ++ dev = dev_alloc ((struct ohci *) usb_dev->bus->hcpriv, ALLOC_FLAGS); ++ if (!dev) ++ return -ENOMEM; ++ ++ usb_dev->hcpriv = dev; ++ return 0; ++} ++ ++/*-------------------------------------------------------------------------*/ ++ ++/* may be called from interrupt context */ ++/* frees private data space of usb device */ ++ ++static int sohci_free_dev (struct usb_device * usb_dev) ++{ ++ unsigned long flags; ++ int i, cnt = 0; ++ ed_t * ed; ++ struct ohci_device * dev = usb_to_ohci (usb_dev); ++ ohci_t * ohci = usb_dev->bus->hcpriv; ++ ++ if (!dev) ++ return 0; ++ ++ if (usb_dev->devnum >= 0) { ++ ++ /* driver disconnects should have unlinked all urbs ++ * (freeing all the TDs, unlinking EDs) but we need ++ * to defend against bugs that prevent that. ++ */ ++ spin_lock_irqsave(&ohci->ohci_lock, flags); ++ for(i = 0; i < NUM_EDS; i++) { ++ ed = &(dev->ed[i]); ++ if (ed->state != ED_NEW) { ++ if (ed->state == ED_OPER) { ++ /* driver on that interface didn't unlink an urb */ ++ dbg ("driver usb-%s dev %d ed 0x%x unfreed URB", ++ ohci->ohci_dev->slot_name, usb_dev->devnum, i); ++ ep_unlink (ohci, ed); ++ } ++ ep_rm_ed (usb_dev, ed); ++ ed->state = ED_DEL; ++ cnt++; ++ } ++ } ++ spin_unlock_irqrestore(&ohci->ohci_lock, flags); ++ ++ /* if the controller is running, tds for those unlinked ++ * urbs get freed by dl_del_list at the next SF interrupt ++ */ |
