ChangeSet 1.1002.3.2, 2003/02/20 10:17:28-08:00, david-b@pacbell.net [PATCH] USB: ohci-hcd, more portable diagnostics This is the rest of the work to make the driver not care which version of the OS it's using, so the difference between the 2.5 and 2.5 versions can just be a small patch with stuff that has a real need to be different. drivers/usb/host/ohci-dbg.c | 71 ++++++++++++++++++++++---------------------- drivers/usb/host/ohci-hcd.c | 28 ++++++++--------- drivers/usb/host/ohci-hub.c | 7 +--- drivers/usb/host/ohci-mem.c | 2 - drivers/usb/host/ohci-pci.c | 29 +++++++++-------- drivers/usb/host/ohci-q.c | 12 ++----- 6 files changed, 73 insertions(+), 76 deletions(-) diff -Nru a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c --- a/drivers/usb/host/ohci-dbg.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-dbg.c Fri Feb 28 14:52:05 2003 @@ -72,9 +72,9 @@ #endif } -static void ohci_dump_intr_mask (struct device *dev, char *label, __u32 mask) +static void ohci_dump_intr_mask (struct ohci_hcd *ohci, char *label, __u32 mask) { - dev_dbg (dev, "%s: 0x%08x%s%s%s%s%s%s%s%s%s\n", + ohci_dbg (ohci, "%s: 0x%08x%s%s%s%s%s%s%s%s%s\n", label, mask, (mask & OHCI_INTR_MIE) ? " MIE" : "", @@ -89,10 +89,10 @@ ); } -static void maybe_print_eds (struct device *dev, char *label, __u32 value) +static void maybe_print_eds (struct ohci_hcd *ohci, char *label, __u32 value) { if (value) - dev_dbg (dev, "%s %08x\n", label, value); + ohci_dbg (ohci, "%s %08x\n", label, value); } static char *hcfs2string (int state) @@ -110,16 +110,16 @@ static void ohci_dump_status (struct ohci_hcd *controller) { struct ohci_regs *regs = controller->regs; - struct device *dev = controller->hcd.controller; __u32 temp; temp = readl (®s->revision) & 0xff; - dev_dbg (dev, "OHCI %d.%d, %s legacy support registers\n", + ohci_dbg (controller, "OHCI %d.%d, %s legacy support registers\n", 0x03 & (temp >> 4), (temp & 0x0f), (temp & 0x10) ? "with" : "NO"); temp = readl (®s->control); - dev_dbg (dev, "control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n", temp, + ohci_dbg (controller, + "control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n", temp, (temp & OHCI_CTRL_RWE) ? " RWE" : "", (temp & OHCI_CTRL_RWC) ? " RWC" : "", (temp & OHCI_CTRL_IR) ? " IR" : "", @@ -132,7 +132,7 @@ ); temp = readl (®s->cmdstatus); - dev_dbg (dev, "cmdstatus: 0x%08x SOC=%d%s%s%s%s\n", temp, + ohci_dbg (controller, "cmdstatus: 0x%08x SOC=%d%s%s%s%s\n", temp, (temp & OHCI_SOC) >> 16, (temp & OHCI_OCR) ? " OCR" : "", (temp & OHCI_BLF) ? " BLF" : "", @@ -140,20 +140,19 @@ (temp & OHCI_HCR) ? " HCR" : "" ); - ohci_dump_intr_mask (dev, "intrstatus", readl (®s->intrstatus)); - ohci_dump_intr_mask (dev, "intrenable", readl (®s->intrenable)); + ohci_dump_intr_mask (controller, "intrstatus", readl (®s->intrstatus)); + ohci_dump_intr_mask (controller, "intrenable", readl (®s->intrenable)); // intrdisable always same as intrenable - // ohci_dump_intr_mask (dev, "intrdisable", readl (®s->intrdisable)); - maybe_print_eds (dev, "ed_periodcurrent", readl (®s->ed_periodcurrent)); + maybe_print_eds (controller, "ed_periodcurrent", readl (®s->ed_periodcurrent)); - maybe_print_eds (dev, "ed_controlhead", readl (®s->ed_controlhead)); - maybe_print_eds (dev, "ed_controlcurrent", readl (®s->ed_controlcurrent)); + maybe_print_eds (controller, "ed_controlhead", readl (®s->ed_controlhead)); + maybe_print_eds (controller, "ed_controlcurrent", readl (®s->ed_controlcurrent)); - maybe_print_eds (dev, "ed_bulkhead", readl (®s->ed_bulkhead)); - maybe_print_eds (dev, "ed_bulkcurrent", readl (®s->ed_bulkcurrent)); + maybe_print_eds (controller, "ed_bulkhead", readl (®s->ed_bulkhead)); + maybe_print_eds (controller, "ed_bulkcurrent", readl (®s->ed_bulkcurrent)); - maybe_print_eds (dev, "donehead", readl (®s->donehead)); + maybe_print_eds (controller, "donehead", readl (®s->donehead)); } static void ohci_dump_roothub (struct ohci_hcd *controller, int verbose) @@ -166,7 +165,7 @@ ndp = (temp & RH_A_NDP); if (verbose) { - dev_dbg (controller->hcd.controller, + ohci_dbg (controller, "roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d\n", temp, ((temp & RH_A_POTPGT) >> 24) & 0xff, (temp & RH_A_NOCP) ? " NOCP" : "", @@ -177,14 +176,14 @@ ndp ); temp = roothub_b (controller); - dev_dbg (controller->hcd.controller, + ohci_dbg (controller, "roothub.b: %08x PPCM=%04x DR=%04x\n", temp, (temp & RH_B_PPCM) >> 16, (temp & RH_B_DR) ); temp = roothub_status (controller); - dev_dbg (controller->hcd.controller, + ohci_dbg (controller, "roothub.status: %08x%s%s%s%s%s%s\n", temp, (temp & RH_HS_CRWE) ? " CRWE" : "", @@ -204,13 +203,12 @@ static void ohci_dump (struct ohci_hcd *controller, int verbose) { - dev_dbg (controller->hcd.controller, - "OHCI controller state\n"); + ohci_dbg (controller, "OHCI controller state\n"); // dumps some of the state we know about ohci_dump_status (controller); if (controller->hcca) - dev_dbg (controller->hcd.controller, + ohci_dbg (controller, "hcca frame #%04x\n", controller->hcca->frame_no); ohci_dump_roothub (controller, 1); } @@ -218,11 +216,11 @@ static const char data0 [] = "DATA0"; static const char data1 [] = "DATA1"; -static void ohci_dump_td (char *label, struct td *td) +static void ohci_dump_td (struct ohci_hcd *ohci, char *label, struct td *td) { u32 tmp = le32_to_cpup (&td->hwINFO); - dbg ("%s td %p%s; urb %p index %d; hw next td %08x", + ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x", label, td, (tmp & TD_DONE) ? " (DONE)" : "", td->urb, td->index, @@ -243,28 +241,28 @@ case TD_DP_OUT: pid = "OUT"; break; default: pid = "(bad pid)"; break; } - dbg (" info %08x CC=%x %s DI=%d %s %s", tmp, + ohci_dbg (ohci, " info %08x CC=%x %s DI=%d %s %s", tmp, TD_CC_GET(tmp), /* EC, */ toggle, (tmp & TD_DI) >> 21, pid, (tmp & TD_R) ? "R" : ""); cbp = le32_to_cpup (&td->hwCBP); be = le32_to_cpup (&td->hwBE); - dbg (" cbp %08x be %08x (len %d)", cbp, be, + ohci_dbg (ohci, " cbp %08x be %08x (len %d)", cbp, be, cbp ? (be + 1 - cbp) : 0); } else { unsigned i; - dbg (" info %08x CC=%x FC=%d DI=%d SF=%04x", tmp, + ohci_dbg (ohci, " info %08x CC=%x FC=%d DI=%d SF=%04x", tmp, TD_CC_GET(tmp), (tmp >> 24) & 0x07, (tmp & TD_DI) >> 21, tmp & 0x0000ffff); - dbg (" bp0 %08x be %08x", + ohci_dbg (ohci, " bp0 %08x be %08x", le32_to_cpup (&td->hwCBP) & ~0x0fff, le32_to_cpup (&td->hwBE)); for (i = 0; i < MAXPSW; i++) { u16 psw = le16_to_cpup (&td->hwPSW [i]); int cc = (psw >> 12) & 0x0f; - dbg (" psw [%d] = %2x, CC=%x %s=%d", i, + ohci_dbg (ohci, " psw [%d] = %2x, CC=%x %s=%d", i, psw, cc, (cc >= 0x0e) ? "OFFSET" : "SIZE", psw & 0x0fff); @@ -279,8 +277,9 @@ u32 tmp = ed->hwINFO; char *type = ""; - dbg ("%s: %s, ed %p state 0x%x type %s; next ed %08x", - ohci->hcd.self.bus_name, label, + ohci_dbg (ohci, + "%s, ed %p state 0x%x type %s; next ed %08x\n", + label, ed, ed->state, edstring (ed->type), le32_to_cpup (&ed->hwNextED)); switch (tmp & (ED_IN|ED_OUT)) { @@ -288,7 +287,8 @@ case ED_IN: type = "-IN"; break; /* else from TDs ... control */ } - dbg (" info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d", le32_to_cpu (tmp), + ohci_dbg (ohci, + " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d", le32_to_cpu (tmp), 0x03ff & (le32_to_cpu (tmp) >> 16), (tmp & ED_DEQUEUE) ? " DQ" : "", (tmp & ED_ISO) ? " ISO" : "", @@ -297,7 +297,8 @@ 0x000f & (le32_to_cpu (tmp) >> 7), type, 0x007f & le32_to_cpu (tmp)); - dbg (" tds: head %08x %s%s tail %08x%s", + ohci_dbg (ohci, + " tds: head %08x %s%s tail %08x%s", tmp = le32_to_cpup (&ed->hwHeadP), (ed->hwHeadP & ED_C) ? data1 : data0, (ed->hwHeadP & ED_H) ? " HALT" : "", @@ -312,7 +313,7 @@ list_for_each (tmp, &ed->td_list) { struct td *td; td = list_entry (tmp, struct td, td_list); - ohci_dump_td (" ->", td); + ohci_dump_td (ohci, " ->", td); } } } diff -Nru a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c --- a/drivers/usb/host/ohci-hcd.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-hcd.c Fri Feb 28 14:52:05 2003 @@ -334,9 +334,11 @@ td_free (ohci, ed->dummy); break; default: - err ("%s-%s ed %p (#%d) not unlinked; disconnect() bug? %d", - ohci->hcd.self.bus_name, udev->devpath, ed, - i, ed->state); + ohci_err (ohci, + "dev %s ep%d-%s linked; disconnect() bug?\n", + udev->devpath, + (i >> 1) & 0x0f, (i & 1) ? "out" : "in"); + /* ED_OPER: some driver disconnect() is broken, * it didn't even start its unlinks much less wait * for their completions. @@ -356,8 +358,10 @@ #ifdef DEBUG /* a driver->disconnect() returned before its unlinks completed? */ if (in_interrupt ()) { - warn ("disconnect() bug for dev usb-%s-%s ep 0x%x", - ohci->hcd.self.bus_name, udev->devpath, i); + ohci_warn (ohci, + "driver disconnect() bug %s ep%d-%s\n", + udev->devpath, + (i >> 1) & 0x0f, (i & 1) ? "out" : "in"); } #endif @@ -428,7 +432,7 @@ temp = 30; /* ... allow extra time */ while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) { if (--temp == 0) { - dev_err (ohci->hcd.controller, "USB HC reset timed out!"); + ohci_err (ohci, "USB HC reset timed out!\n"); return -1; } udelay (1); @@ -485,7 +489,7 @@ */ if ((readl (&ohci->regs->fminterval) & 0x3fff0000) == 0 || !readl (&ohci->regs->periodicstart)) { - err ("%s init err", ohci->hcd.self.bus_name); + ohci_err (ohci, "init err\n"); return -EOVERFLOW; } @@ -564,7 +568,7 @@ /* cardbus/... hardware gone before remove() */ } else if ((ints = readl (®s->intrstatus)) == ~(u32)0) { disable (ohci); - dbg ("%s device removed!", hcd->self.bus_name); + ohci_dbg (ohci, "device removed!\n"); return; /* interrupt for some other device? */ @@ -572,13 +576,9 @@ return; } - - // dbg ("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); - if (ints & OHCI_INTR_UE) { disable (ohci); - err ("OHCI Unrecoverable Error, %s disabled", - hcd->self.bus_name); + ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); // e.g. due to PCI Master/Target Abort ohci_dump (ohci, 1); @@ -613,7 +613,7 @@ { struct ohci_hcd *ohci = hcd_to_ohci (hcd); - dev_dbg (hcd->controller, "stop %s controller%s\n", + ohci_dbg (ohci, "stop %s controller%s\n", hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS), ohci->disabled ? " (disabled)" : "" ); diff -Nru a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c --- a/drivers/usb/host/ohci-hub.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-hub.c Fri Feb 28 14:52:05 2003 @@ -40,7 +40,7 @@ /*-------------------------------------------------------------------------*/ #define dbg_port(hc,label,num,value) \ - dev_dbg (hc->hcd.controller, \ + ohci_dbg (hc, \ "%s roothub.portstatus [%d] " \ "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \ label, num, temp, \ @@ -75,9 +75,8 @@ if (ports > MAX_ROOT_PORTS) { if (ohci->disabled) return -ESHUTDOWN; - err ("%s bogus NDP=%d, rereads as NDP=%d", - hcd->self.bus_name, ports, - readl (&ohci->regs->roothub.a) & RH_A_NDP); + ohci_err (ohci, "bogus NDP=%d, rereads as NDP=%d\n", + ports, readl (&ohci->regs->roothub.a) & RH_A_NDP); /* retry later; "should not happen" */ return 0; } diff -Nru a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c --- a/drivers/usb/host/ohci-mem.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-mem.c Fri Feb 28 14:52:05 2003 @@ -116,7 +116,7 @@ if (*prev) *prev = td->td_hash; else - dev_dbg (hc->hcd.controller, "bad hash for td %p\n", td); + ohci_dbg (hc, "bad hash for td %p\n", td); pci_pool_free (hc->td_cache, td, td->td_dma); } diff -Nru a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c --- a/drivers/usb/host/ohci-pci.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-pci.c Fri Feb 28 14:52:05 2003 @@ -96,7 +96,7 @@ } if (hc_start (ohci) < 0) { - err ("can't start %s", ohci->hcd.self.bus_name); + ohci_err (ohci, "can't start\n"); ohci_stop (hcd); return -EBUSY; } @@ -116,13 +116,13 @@ u16 cmd; if ((ohci->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_OPER) { - dbg ("can't suspend %s (state is %s)", hcd->self.bus_name, + ohci_dbg (ohci, "can't suspend (state is %s)\n", hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS)); return -EIO; } /* act as if usb suspend can always be used */ - dbg ("%s: suspend to %d", hcd->self.bus_name, state); + ohci_dbg (ohci, "suspend to %d\n", state); ohci->sleeping = 1; /* First stop processing */ @@ -157,16 +157,16 @@ switch (readl (&ohci->regs->control) & OHCI_CTRL_HCFS) { case OHCI_USB_RESET: - dbg ("%s suspend->reset ?", hcd->self.bus_name); + ohci_dbg (ohci, "suspend->reset ?\n"); break; case OHCI_USB_RESUME: - dbg ("%s suspend->resume ?", hcd->self.bus_name); + ohci_dbg (ohci, "suspend->resume ?\n"); break; case OHCI_USB_OPER: - dbg ("%s suspend->operational ?", hcd->self.bus_name); + ohci_dbg (ohci, "suspend->operational ?\n"); break; case OHCI_USB_SUSPEND: - dbg ("%s suspended", hcd->self.bus_name); + ohci_dbg (ohci, "suspended\n"); break; } @@ -223,13 +223,13 @@ switch (temp) { case OHCI_USB_RESET: // lost power - info ("USB restart: %s", hcd->self.bus_name); + ohci_info (ohci, "USB restart\n"); retval = hc_restart (ohci); break; case OHCI_USB_SUSPEND: // host wakeup case OHCI_USB_RESUME: // remote wakeup - info ("USB continue: %s from %s wakeup", hcd->self.bus_name, + ohci_info (ohci, "USB continue from %s wakeup\n", (temp == OHCI_USB_SUSPEND) ? "host" : "remote"); ohci->hc_control = OHCI_USB_RESUME; @@ -242,7 +242,7 @@ temp = readl (&ohci->regs->control); temp = ohci->hc_control & OHCI_CTRL_HCFS; if (temp != OHCI_USB_RESUME) { - err ("controller %s won't resume", hcd->self.bus_name); + ohci_err (ohci, "controller won't resume\n"); ohci->disabled = 1; retval = -EIO; break; @@ -288,11 +288,12 @@ writel (OHCI_BLF | OHCI_CLF, &ohci->regs->cmdstatus); // ohci_dump_status (ohci); -dbg ("sleeping = %d, disabled = %d", ohci->sleeping, ohci->disabled); +ohci_dbg (ohci, "sleeping = %d, disabled = %d\n", + ohci->sleeping, ohci->disabled); break; default: - warn ("odd PCI resume for %s", hcd->self.bus_name); + ohci_warn (ohci, "odd PCI resume\n"); } return retval; } @@ -383,11 +384,11 @@ static int __init ohci_hcd_pci_init (void) { - dbg (DRIVER_INFO " (PCI)"); + printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name); if (usb_disabled()) return -ENODEV; - dbg ("block sizes: ed %d td %d", + printk (KERN_DEBUG "%s: block sizes: ed %d td %d\n", hcd_name, sizeof (struct ed), sizeof (struct td)); return pci_module_init (&ohci_pci_driver); } diff -Nru a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c --- a/drivers/usb/host/ohci-q.c Fri Feb 28 14:52:05 2003 +++ b/drivers/usb/host/ohci-q.c Fri Feb 28 14:52:05 2003 @@ -110,12 +110,9 @@ { unsigned i; -#ifdef OHCI_VERBOSE_DEBUG - dbg ("%s: link %sed %p branch %d [%dus.], interval %d", - ohci->hcd.self.bus_name, + ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n", (ed->hwINFO & ED_ISO) ? "iso " : "", ed, ed->branch, ed->load, ed->interval); -#endif for (i = ed->branch; i < NUM_INTS; i += ed->interval) { struct ed **prev = &ohci->periodic [i]; @@ -206,7 +203,7 @@ default: branch = balance (ohci, ed->interval, ed->load); if (branch < 0) { - dev_dbg (ohci->hcd.controller, + ohci_dbg (ohci, "ERR %d, interval %d msecs, load %d\n", branch, ed->interval, ed->load); // FIXME if there are TDs queued, fail them! @@ -787,7 +784,7 @@ } /* help for troubleshooting: */ - dev_dbg (&urb->dev->dev, + ohci_dbg (ohci, "urb %p usb-%s-%s ep-%d-%s cc %d --> status %d\n", urb, urb->dev->bus->bus_name, urb->dev->devpath, @@ -821,8 +818,7 @@ td = dma_to_td (ohci, td_dma); if (!td) { - err ("%s bad entry %8x", - ohci->hcd.self.bus_name, td_dma); + ohci_err (ohci, "bad entry %8x\n", td_dma); break; }