Hi David, Greg,
  I've had this in my tree for a while meaning to send it in.  Changes:

Add driver fs/sysfs 'registers' debug file for OHCI hub when
OHCI_VERBOSE_DEBUG is defined.


This should apply cleanly on top of David's ohci changes from this
week.  If not, let me know, and I'll check my merge again.  I haven't
shown this to David yet, so please wait for his approval before
forwarding to Linus's tree.

Apply with patch -p4

Also, in one of the patches from Feb 19 to ohci-q.c, there are
references to the ohci struct in two ohci_vdbg() calls in td_done(). 
However, I don't think these will build, as ohci isn't defined in that
function.

-- 
Kevin
diff -u /home/cobra/temp/mylinux-2.5/drivers/usb/host/ohci-dbg.c 
/usr/src/linux-bk/drivers/usb/host/ohci-dbg.c
--- /home/cobra/temp/mylinux-2.5/drivers/usb/host/ohci-dbg.c    2003-02-23 
10:56:59.000000000 -0500
+++ /usr/src/linux-bk/drivers/usb/host/ohci-dbg.c       2003-02-22 12:26:11.000000000 
-0500
@@ -72,9 +72,18 @@
 #endif
 }
 
-static void ohci_dump_intr_mask (struct ohci_hcd *ohci, char *label, __u32 mask)
+#define ohci_dbg_sw(ohci, next, size, format, arg...) \
+  { if(next) { \
+    unsigned s_len; s_len = snprintf (*next, *size, format, ## arg ); \
+    *size -= s_len; *next += s_len; \
+  } else { \
+    ohci_dbg(ohci,format, ## arg ); } \
+  }
+
+
+static void ohci_dump_intr_mask (struct ohci_hcd *ohci, char *label, __u32 mask, char 
**next, unsigned *size)
 {
-       ohci_dbg (ohci, "%s: 0x%08x%s%s%s%s%s%s%s%s%s\n",
+       ohci_dbg_sw (ohci, next, size, "%s: 0x%08x%s%s%s%s%s%s%s%s%s\n",
                label,
                mask,
                (mask & OHCI_INTR_MIE) ? " MIE" : "",
@@ -89,10 +98,10 @@
                );
 }
 
-static void maybe_print_eds (struct ohci_hcd *ohci, char *label, __u32 value)
+static void maybe_print_eds (struct ohci_hcd *ohci, char *label, __u32 value, char 
**next, unsigned *size)
 {
        if (value)
-               ohci_dbg (ohci, "%s %08x\n", label, value);
+               ohci_dbg_sw (ohci, next, size, "%s %08x\n", label, value);
 }
 
 static char *hcfs2string (int state)
@@ -106,20 +115,20 @@
        return "?";
 }
 
+
 // dump control and status registers
-static void ohci_dump_status (struct ohci_hcd *controller)
+static void ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned 
*size)
 {
        struct ohci_regs        *regs = controller->regs;
        __u32                   temp;
 
        temp = readl (&regs->revision) & 0xff;
-       ohci_dbg (controller, "OHCI %d.%d, %s legacy support registers\n",
+       ohci_dbg_sw (controller, next, size, "OHCI %d.%d, %s legacy support 
registers\n",
                0x03 & (temp >> 4), (temp & 0x0f),
                (temp & 0x10) ? "with" : "NO");
 
        temp = readl (&regs->control);
-       ohci_dbg (controller,
-               "control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n", temp,
+       ohci_dbg_sw (controller, next, size, "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 +141,7 @@
                );
 
        temp = readl (&regs->cmdstatus);
-       ohci_dbg (controller, "cmdstatus: 0x%08x SOC=%d%s%s%s%s\n", temp,
+       ohci_dbg_sw (controller, next, size, "cmdstatus: 0x%08x SOC=%d%s%s%s%s\n", 
temp,
                (temp & OHCI_SOC) >> 16,
                (temp & OHCI_OCR) ? " OCR" : "",
                (temp & OHCI_BLF) ? " BLF" : "",
@@ -140,22 +149,45 @@
                (temp & OHCI_HCR) ? " HCR" : ""
                );
 
-       ohci_dump_intr_mask (controller, "intrstatus", readl (&regs->intrstatus));
-       ohci_dump_intr_mask (controller, "intrenable", readl (&regs->intrenable));
+       ohci_dump_intr_mask (controller, "intrstatus", readl (&regs->intrstatus), 
next, size);
+       ohci_dump_intr_mask (controller, "intrenable", readl (&regs->intrenable), 
next, size);
        // intrdisable always same as intrenable
+       // ohci_dump_intr_mask (dev, "intrdisable", readl (&regs->intrdisable), next, 
size);
 
-       maybe_print_eds (controller, "ed_periodcurrent", readl 
(&regs->ed_periodcurrent));
+       maybe_print_eds (controller, "ed_periodcurrent", readl 
(&regs->ed_periodcurrent), next, size);
 
-       maybe_print_eds (controller, "ed_controlhead", readl (&regs->ed_controlhead));
-       maybe_print_eds (controller, "ed_controlcurrent", readl 
(&regs->ed_controlcurrent));
+       maybe_print_eds (controller, "ed_controlhead", readl (&regs->ed_controlhead), 
next, size);
+       maybe_print_eds (controller, "ed_controlcurrent", readl 
(&regs->ed_controlcurrent), next, size);
 
-       maybe_print_eds (controller, "ed_bulkhead", readl (&regs->ed_bulkhead));
-       maybe_print_eds (controller, "ed_bulkcurrent", readl (&regs->ed_bulkcurrent));
+       maybe_print_eds (controller, "ed_bulkhead", readl (&regs->ed_bulkhead), next, 
size);
+       maybe_print_eds (controller, "ed_bulkcurrent", readl (&regs->ed_bulkcurrent), 
next, size);
+
+       maybe_print_eds (controller, "donehead", readl (&regs->donehead), next, size);
+}
+
+#define dbg_port_sw(hc,label,num,value,next,size) \
+       ohci_dbg_sw (hc, next, size, \
+               "%s roothub.portstatus [%d] " \
+               "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
+               label, num, 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" : "" \
+               );
 
-       maybe_print_eds (controller, "donehead", readl (&regs->donehead));
-}
 
-static void ohci_dump_roothub (struct ohci_hcd *controller, int verbose)
+static void ohci_dump_roothub (struct ohci_hcd *controller, int verbose, char **next, 
unsigned *size)
 {
        __u32                   temp, ndp, i;
 
@@ -165,7 +197,7 @@
        ndp = (temp & RH_A_NDP);
 
        if (verbose) {
-               ohci_dbg (controller,
+         ohci_dbg_sw (controller, next, size,
                        "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" : "",
@@ -176,14 +208,14 @@
                        ndp
                        );
                temp = roothub_b (controller);
-               ohci_dbg (controller,
+               ohci_dbg_sw (controller, next, size,
                        "roothub.b: %08x PPCM=%04x DR=%04x\n",
                        temp,
                        (temp & RH_B_PPCM) >> 16,
                        (temp & RH_B_DR)
                        );
                temp = roothub_status (controller);
-               ohci_dbg (controller,
+               ohci_dbg_sw (controller, next, size,
                        "roothub.status: %08x%s%s%s%s%s%s\n",
                        temp,
                        (temp & RH_HS_CRWE) ? " CRWE" : "",
@@ -197,7 +229,7 @@
        
        for (i = 0; i < ndp; i++) {
                temp = roothub_portstatus (controller, i);
-               dbg_port (controller, "", i, temp);
+               dbg_port_sw (controller, "", i, temp, next, size);
        }
 }
 
@@ -206,11 +238,11 @@
        ohci_dbg (controller, "OHCI controller state\n");
 
        // dumps some of the state we know about
-       ohci_dump_status (controller);
+       ohci_dump_status (controller, NULL, 0);
        if (controller->hcca)
                ohci_dbg (controller,
                        "hcca frame #%04x\n", controller->hcca->frame_no);
-       ohci_dump_roothub (controller, 1);
+       ohci_dump_roothub (controller, 1, NULL, 0);
 }
 
 static const char data0 [] = "DATA0";
@@ -277,8 +309,7 @@
        u32     tmp = ed->hwINFO;
        char    *type = "";
 
-       ohci_dbg (ohci,
-               "%s, ed %p state 0x%x type %s; next ed %08x\n",
+       ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x",
                label,
                ed, ed->state, edstring (ed->type),
                le32_to_cpup (&ed->hwNextED));
@@ -288,7 +319,7 @@
        /* else from TDs ... control */
        }
        ohci_dbg (ohci,
-               "  info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d", le32_to_cpu (tmp),
+                 "  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,8 +328,7 @@
                0x000f & (le32_to_cpu (tmp) >> 7),
                type,
                0x007f & le32_to_cpu (tmp));
-       ohci_dbg (ohci,
-               "  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" : "",
@@ -518,10 +548,65 @@
 
 #undef DBG_SCHED_LIMIT
 
+static ssize_t
+show_registers (struct device *dev, char *buf)
+{
+       struct pci_dev          *pdev;
+       struct ohci_hcd         *ohci;
+       struct ohci_regs        *regs;
+       unsigned long           flags;
+       unsigned                temp, size, i;
+       char                    *next, scratch [80];
+       __u32                   rdata;
+
+       ohci = dev_to_ohci(dev);
+       regs = ohci->regs;
+       next = buf;
+       size = PAGE_SIZE;
+
+       spin_lock_irqsave (&ohci->lock, flags);
+
+       ohci_dump_status(ohci, &next, &size);
+
+       /* hcca */
+       if (ohci->hcca)
+         ohci_dbg_sw (ohci, &next, &size,
+                       "hcca frame #%04x\n", ohci->hcca->frame_no);
+
+       /* roothub */
+       ohci_dump_roothub (ohci, 1, &next, &size);
+
+
+       rdata = readl (&regs->fminterval);
+       temp = snprintf (next, size, "hcFmIntvl FI=0x%04x FSMPS=0x%04x FIT=%d\n",
+                        rdata & 0xffff, (rdata >> 16) & 0xefff, rdata>>31 );
+       size -= temp;
+       next += temp;
+
+       rdata = readl (&regs->fmremaining);
+       temp = snprintf (next, size, "hcFmRemaining FR=0x%04x FRT=%d\n",
+                        rdata & 0x3fff, rdata>>31 );
+       size -= temp;
+       next += temp;
+
+       rdata = readl (&regs->periodicstart);
+       temp = snprintf (next, size, "hcPeriodicStart=0x%04x\n",
+                        rdata & 0x3fff);
+       size -= temp;
+       next += temp;
+
+       spin_unlock_irqrestore (&ohci->lock, flags);
+
+       return PAGE_SIZE - size;
+}
+static DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
+
+
 static inline void create_debug_files (struct ohci_hcd *bus)
 {
        device_create_file (bus->hcd.controller, &dev_attr_async);
        device_create_file (bus->hcd.controller, &dev_attr_periodic);
+       device_create_file (bus->hcd.controller, &dev_attr_registers);
        // registers
        ohci_dbg (bus, "created debug files\n");
 }
@@ -530,6 +615,7 @@
 {
        device_remove_file (bus->hcd.controller, &dev_attr_async);
        device_remove_file (bus->hcd.controller, &dev_attr_periodic);
+       device_remove_file (bus->hcd.controller, &dev_attr_registers);
 }
 
 #endif

Reply via email to