Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Convert to USB_HIST.



details:   https://anonhg.NetBSD.org/src/rev/624c824972b0
branches:  trunk
changeset: 332676:624c824972b0
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Oct 03 11:05:36 2014 +0000

description:
Convert to USB_HIST.

>From Takahiro HAYASHI with tweaks from me.

diffstat:

 sys/dev/usb/xhci.c |  401 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 235 insertions(+), 166 deletions(-)

diffs (truncated from 1073 to 300 lines):

diff -r 59dfbf5bd653 -r 624c824972b0 sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Fri Oct 03 06:46:02 2014 +0000
+++ b/sys/dev/usb/xhci.c        Fri Oct 03 11:05:36 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.26 2014/08/12 13:50:42 skrll Exp $  */
+/*     $NetBSD: xhci.c,v 1.27 2014/10/03 11:05:36 skrll Exp $  */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -27,7 +27,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.26 2014/08/12 13:50:42 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.27 2014/10/03 11:05:36 skrll Exp $");
+
+#include "opt_usb.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -42,12 +44,14 @@
 #include <sys/condvar.h>
 #include <sys/bus.h>
 #include <sys/cpu.h>
+#include <sys/sysctl.h>
 
 #include <machine/endian.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdivar.h>
+#include <dev/usb/usbhist.h>
 #include <dev/usb/usb_mem.h>
 #include <dev/usb/usb_quirks.h>
 
@@ -55,14 +59,46 @@
 #include <dev/usb/xhcivar.h>
 #include <dev/usb/usbroothub_subr.h>
 
-#ifdef XHCI_DEBUG
-int xhcidebug = 0;
-#define DPRINTF(x)     do { if (xhcidebug) printf x; } while(0)
-#define DPRINTFN(n,x)  do { if (xhcidebug>(n)) printf x; } while (0)
+
+#ifdef USB_DEBUG
+#ifndef XHCI_DEBUG
+#define xhcidebug 0
 #else
-#define DPRINTF(x)
-#define DPRINTFN(n,x)
-#endif
+static int xhcidebug = 0;
+
+SYSCTL_SETUP(sysctl_hw_xhci_setup, "sysctl hw.xhci setup")
+{
+       int err;
+       const struct sysctlnode *rnode;
+       const struct sysctlnode *cnode;
+
+       err = sysctl_createv(clog, 0, NULL, &rnode,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "xhci",
+           SYSCTL_DESCR("xhci global controls"),
+           NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
+
+       if (err)
+               goto fail;
+
+       /* control debugging printfs */
+       err = sysctl_createv(clog, 0, &rnode, &cnode,
+           CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
+           "debug", SYSCTL_DESCR("Enable debugging output"),
+           NULL, 0, &xhcidebug, sizeof(xhcidebug), CTL_CREATE, CTL_EOL);
+       if (err)
+               goto fail;
+
+       return;
+fail:
+       aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
+
+#endif /* XHCI_DEBUG */
+#endif /* USB_DEBUG */
+
+#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(xhcidebug,N,FMT,A,B,C,D)
+#define XHCIHIST_FUNC() USBHIST_FUNC()
+#define XHCIHIST_CALLED(name) USBHIST_CALLED(xhcidebug)
 
 #define XHCI_DCI_SLOT 0
 #define XHCI_DCI_EP_CONTROL 1
@@ -577,7 +613,7 @@
        uint16_t hciversion;
        uint8_t caplength;
 
-       DPRINTF(("%s\n", __func__));
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
        /* XXX Low/Full/High speeds for now */
        sc->sc_bus.usbrev = USBREV_2_0;
@@ -855,6 +891,8 @@
        struct xhci_softc * const sc = v;
        int ret = 0;
 
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
        if (sc == NULL)
                return 0;
 
@@ -863,12 +901,10 @@
        if (sc->sc_dying || !device_has_power(sc->sc_dev))
                goto done;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
-
        /* If we get an interrupt while polling, then just ignore it. */
        if (sc->sc_bus.use_polling) {
 #ifdef DIAGNOSTIC
-               DPRINTFN(16, ("xhci_intr: ignored interrupt while polling\n"));
+               DPRINTFN(16, "ignored interrupt while polling", 0, 0, 0, 0);
 #endif
                goto done;
        }
@@ -885,8 +921,10 @@
        uint32_t usbsts;
        uint32_t iman;
 
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
        usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
-       //device_printf(sc->sc_dev, "%s USBSTS %08x\n", __func__, usbsts);
+       DPRINTFN(16, "USBSTS %08x", usbsts, 0, 0, 0);
 #if 0
        if ((usbsts & (XHCI_STS_EINT|XHCI_STS_PCD)) == 0) {
                return 0;
@@ -895,18 +933,18 @@
        xhci_op_write_4(sc, XHCI_USBSTS,
            usbsts & (2|XHCI_STS_EINT|XHCI_STS_PCD)); /* XXX */
        usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
-       //device_printf(sc->sc_dev, "%s USBSTS %08x\n", __func__, usbsts);
+       DPRINTFN(16, "USBSTS %08x", usbsts, 0, 0, 0);
 
        iman = xhci_rt_read_4(sc, XHCI_IMAN(0));
-       //device_printf(sc->sc_dev, "%s IMAN0 %08x\n", __func__, iman);
+       DPRINTFN(16, "IMAN0 %08x", iman, 0, 0, 0);
        if ((iman & XHCI_IMAN_INTR_PEND) == 0) {
                return 0;
        }
        xhci_rt_write_4(sc, XHCI_IMAN(0), iman);
        iman = xhci_rt_read_4(sc, XHCI_IMAN(0));
-       //device_printf(sc->sc_dev, "%s IMAN0 %08x\n", __func__, iman);
+       DPRINTFN(16, "IMAN0 %08x", iman, 0, 0, 0);
        usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
-       //device_printf(sc->sc_dev, "%s USBSTS %08x\n", __func__, usbsts);
+       DPRINTFN(16, "USBSTS %08x", usbsts, 0, 0, 0);
 
        sc->sc_bus.no_intrs++;
        usb_schedsoftintr(&sc->sc_bus);
@@ -926,8 +964,9 @@
        usbd_status err;
        uint32_t *cp;
 
-       device_printf(sc->sc_dev, "%s dci %u (0x%x)\n", __func__, dci,
-           pipe->endpoint->edesc->bEndpointAddress);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "dci %u epaddr 0x%02x attr 0x%02x",
+           dci, ed->bEndpointAddress, ed->bmAttributes, 0);
 
        /* XXX ensure input context is available? */
 
@@ -995,6 +1034,13 @@
 static usbd_status
 xhci_unconfigure_endpoint(usbd_pipe_handle pipe)
 {
+#ifdef USB_DEBUG
+       struct xhci_slot * const xs = pipe->device->hci_private;
+#endif
+
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "slot %u", xs->xs_idx, 0, 0, 0);
+
        return USBD_NORMAL_COMPLETION;
 }
 
@@ -1007,7 +1053,8 @@
        struct xhci_trb trb;
        usbd_status err;
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "dci %u", dci, 0, 0, 0);
 
        trb.trb_0 = 0;
        trb.trb_2 = 0;
@@ -1030,7 +1077,8 @@
        usbd_status err;
        const u_int dci = xhci_ep_get_dci(pipe->endpoint->edesc);
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "dci %u", dci, 0, 0, 0);
 
        trb.trb_0 = 0;
        trb.trb_2 = 0;
@@ -1054,7 +1102,8 @@
        struct xhci_trb trb;
        usbd_status err;
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "slot %u dci %u", xs->xs_idx, dci, 0, 0);
 
        memset(xr->xr_trb, 0, xr->xr_ntrb * XHCI_TRB_SIZE);
        usb_syncmem(&xr->xr_dma, 0, xr->xr_ntrb * XHCI_TRB_SIZE,
@@ -1080,13 +1129,11 @@
        usbd_device_handle const dev = pipe->device;
        struct xhci_softc * const sc = dev->bus->hci_private;
        usb_endpoint_descriptor_t * const ed = pipe->endpoint->edesc;
-       const int8_t addr = dev->address;
        const uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes);
 
-       DPRINTF(("%s\n", __func__));
-       DPRINTF(("addr %d\n", addr));
-       device_printf(sc->sc_dev, "%s addr %d depth %d port %d speed %d\n",
-           __func__, addr, dev->depth, dev->powersrc->portno, dev->speed);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(1, "addr %d depth %d port %d speed %d",
+           dev->address, dev->depth, dev->powersrc->portno, dev->speed);
 
        if (sc->sc_dying)
                return USBD_IOERROR;
@@ -1103,8 +1150,8 @@
                        break;
                default:
                        pipe->methods = NULL;
-                       DPRINTF(("xhci_open: bad bEndpointAddress 0x%02x\n",
-                           ed->bEndpointAddress));
+                       DPRINTFN(0, "bad bEndpointAddress 0x%02x",
+                           ed->bEndpointAddress, 0, 0, 0);
                        return USBD_INVAL;
                }
                return USBD_NORMAL_COMPLETION;
@@ -1141,7 +1188,8 @@
        usbd_xfer_handle const xfer = sc->sc_intrxfer;
        uint8_t *p;
 
-       device_printf(sc->sc_dev, "port %u status change\n", port);
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
+       DPRINTFN(4, "port %u status change", port, 0, 0, 0);
 
        if (xfer == NULL)
                return;
@@ -1152,7 +1200,7 @@
 
        port -= sc->sc_hs_port_start;
        port += 1;
-       device_printf(sc->sc_dev, "hs port %u status change\n", port);
+       DPRINTFN(4, "hs port %u status change", port, 0, 0, 0);
 
        p = KERNADDR(&xfer->dmabuf, 0);
        memset(p, 0, xfer->length);
@@ -1163,22 +1211,20 @@
 }
 
 static void
-xhci_handle_event(struct xhci_softc * const sc, const struct xhci_trb * const trb)
+xhci_handle_event(struct xhci_softc * const sc,
+    const struct xhci_trb * const trb)
 {
        uint64_t trb_0;
        uint32_t trb_2, trb_3;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
+       XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
        trb_0 = le64toh(trb->trb_0);
        trb_2 = le32toh(trb->trb_2);
        trb_3 = le32toh(trb->trb_3);
 
-#if 0
-       device_printf(sc->sc_dev,
-           "event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n", trb,
-           trb_0, trb_2, trb_3);
-#endif
+       DPRINTFN(14, "event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32,
+           trb, trb_0, trb_2, trb_3);
 
        switch (XHCI_TRB_3_TYPE_GET(trb_3)){
        case XHCI_TRB_EVENT_TRANSFER: {
@@ -1202,17 +1248,13 @@
                        xx = (void *)(uintptr_t)(trb_0 & ~0x3);
                }
                xfer = &xx->xx_xfer;
-#if 0
-               device_printf(sc->sc_dev, "%s xfer %p\n", __func__, xfer);
-#endif
+               DPRINTFN(14, "xfer %p", xfer, 0, 0, 0);
 
                if ((trb_3 & XHCI_TRB_3_ED_BIT) != 0) {
-#if 0
-                       device_printf(sc->sc_dev, "transfer event data: "
-                           "0x%016"PRIx64" 0x%08"PRIx32" %02x\n",



Home | Main Index | Thread Index | Old Index