Source-Changes-HG archive

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

[src/nick-nhusb]: src/sys/dev/usb Convert to USBHIST



details:   https://anonhg.NetBSD.org/src/rev/842858c3eb58
branches:  nick-nhusb
changeset: 804255:842858c3eb58
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Feb 20 09:17:17 2015 +0000

description:
Convert to USBHIST

diffstat:

 sys/dev/usb/uhci.c |  507 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 311 insertions(+), 196 deletions(-)

diffs (truncated from 1308 to 300 lines):

diff -r 36a101e28c75 -r 842858c3eb58 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c        Fri Feb 20 09:16:49 2015 +0000
+++ b/sys/dev/usb/uhci.c        Fri Feb 20 09:17:17 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci.c,v 1.264.4.20 2015/02/20 09:16:49 skrll Exp $    */
+/*     $NetBSD: uhci.c,v 1.264.4.21 2015/02/20 09:17:17 skrll Exp $    */
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.264.4.20 2015/02/20 09:16:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.264.4.21 2015/02/20 09:17:17 skrll Exp $");
 
 #include <sys/param.h>
 
@@ -69,22 +69,56 @@
 #include <dev/usb/uhcireg.h>
 #include <dev/usb/uhcivar.h>
 #include <dev/usb/usbroothub.h>
+#include <dev/usb/usbhist.h>
 
 /* Use bandwidth reclamation for control transfers. Some devices choke on it. */
 /*#define UHCI_CTL_LOOP */
 
-
-
 #ifdef UHCI_DEBUG
 uhci_softc_t *thesc;
-#define DPRINTF(x)     if (uhcidebug) printf x
-#define DPRINTFN(n,x)  if (uhcidebug>(n)) printf x
-int uhcidebug = 0;
 int uhcinoloop = 0;
+#endif
+
+#ifdef USB_DEBUG
+#ifndef UHCI_DEBUG
+#define uhcidebug 0
 #else
-#define DPRINTF(x)
-#define DPRINTFN(n,x)
-#endif
+static int uhcidebug = 0;
+
+SYSCTL_SETUP(sysctl_hw_uhci_setup, "sysctl hw.uhci setup")
+{
+       int err;
+       const struct sysctlnode *rnode;
+       const struct sysctlnode *cnode;
+
+       err = sysctl_createv(clog, 0, NULL, &rnode,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "uhci",
+           SYSCTL_DESCR("uhci 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, &uhcidebug, sizeof(uhcidebug), CTL_CREATE, CTL_EOL);
+       if (err)
+               goto fail;
+
+       return;
+fail:
+       aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
+
+#endif /* UHCI_DEBUG */
+#endif /* USB_DEBUG */
+
+
+#define        DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(uhcidebug,N,FMT,A,B,C,D)
+#define        UHCIHIST_FUNC()         USBHIST_FUNC()
+#define        UHCIHIST_CALLED(name)   USBHIST_CALLED(uhcidebug)
 
 /*
  * The UHCI controller is little endian, so on big endian machines
@@ -342,7 +376,8 @@
 static inline uhci_soft_qh_t *
 uhci_find_prev_qh(uhci_soft_qh_t *pqh, uhci_soft_qh_t *sqh)
 {
-       DPRINTFN(15,("uhci_find_prev_qh: pqh=%p sqh=%p\n", pqh, sqh));
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+       DPRINTFN(15, "pqh=%p sqh=%p", pqh, sqh, 0, 0);
 
        for (; pqh->hlink != sqh; pqh = pqh->hlink) {
 #if defined(DIAGNOSTIC) || defined(UHCI_DEBUG)
@@ -375,7 +410,7 @@
        uhci_soft_qh_t *clsqh, *chsqh, *bsqh, *sqh, *lsqh;
        uhci_soft_td_t *std;
 
-       DPRINTFN(1,("uhci_init: start\n"));
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
 #ifdef UHCI_DEBUG
        thesc = sc;
@@ -519,7 +554,7 @@
 
        UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */
 
-       DPRINTFN(1,("uhci_init: enabling\n"));
+       DPRINTFN(1, "Enabling...", 0, 0, 0, 0);
 
        err =  uhci_run(sc, 1, 0);              /* and here we go... */
        UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
@@ -713,63 +748,68 @@
 Static void
 uhci_dumpregs(uhci_softc_t *sc)
 {
-       DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, "
-                    "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n",
-                    device_xname(sc->sc_dev),
-                    UREAD2(sc, UHCI_CMD),
-                    UREAD2(sc, UHCI_STS),
-                    UREAD2(sc, UHCI_INTR),
-                    UREAD2(sc, UHCI_FRNUM),
-                    UREAD4(sc, UHCI_FLBASEADDR),
-                    UREAD1(sc, UHCI_SOF),
-                    UREAD2(sc, UHCI_PORTSC1),
-                    UREAD2(sc, UHCI_PORTSC2)));
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+       DPRINTFN(1, "cmd =%04x  sts    =%04x  intr   =%04x  frnum =%04x",
+           UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS),
+           UREAD2(sc, UHCI_INTR), UREAD2(sc, UHCI_FRNUM));
+       DPRINTFN(1, "sof =%04x  portsc1=%04x  portsc2=%04x  flbase=%08x",
+           UREAD1(sc, UHCI_SOF), UREAD2(sc, UHCI_PORTSC1),
+           UREAD2(sc, UHCI_PORTSC2), UREAD4(sc, UHCI_FLBASEADDR));
 }
 
 void
 uhci_dump_td(uhci_soft_td_t *p)
 {
-       char sbuf[128], sbuf2[128];
-
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
        usb_syncmem(&p->dma, p->offs, sizeof(p->td),
            BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
-       DPRINTFN(-1,("TD(%p) at %08lx = link=0x%08lx status=0x%08lx "
-                    "token=0x%08lx buffer=0x%08lx\n",
-                    p, (long)p->physaddr,
-                    (long)le32toh(p->td.td_link),
-                    (long)le32toh(p->td.td_status),
-                    (long)le32toh(p->td.td_token),
-                    (long)le32toh(p->td.td_buffer)));
-
-       snprintb(sbuf, sizeof(sbuf), "\20\1T\2Q\3VF",
-           (uint32_t)le32toh(p->td.td_link));
-       snprintb(sbuf2, sizeof(sbuf2),
-           "\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
-           "STALLED\30ACTIVE\31IOC\32ISO\33LS\36SPD",
-           (uint32_t)le32toh(p->td.td_status));
-
-       DPRINTFN(-1,("  %s %s,errcnt=%d,actlen=%d pid=%02x,addr=%d,endpt=%d,"
-                    "D=%d,maxlen=%d\n", sbuf, sbuf2,
-                    UHCI_TD_GET_ERRCNT(le32toh(p->td.td_status)),
-                    UHCI_TD_GET_ACTLEN(le32toh(p->td.td_status)),
-                    UHCI_TD_GET_PID(le32toh(p->td.td_token)),
-                    UHCI_TD_GET_DEVADDR(le32toh(p->td.td_token)),
-                    UHCI_TD_GET_ENDPT(le32toh(p->td.td_token)),
-                    UHCI_TD_GET_DT(le32toh(p->td.td_token)),
-                    UHCI_TD_GET_MAXLEN(le32toh(p->td.td_token))));
-       usb_syncmem(&p->dma, p->offs, sizeof(p->td),
-           BUS_DMASYNC_PREREAD);
+
+       DPRINTFN(1, "TD(%p) at %08x", p, p->physaddr, 0, 0);
+       DPRINTFN(1, "   link=0x%08x status=0x%08x "
+           "token=0x%08x buffer=0x%08x",
+            le32toh(p->td.td_link),
+            le32toh(p->td.td_status),
+            le32toh(p->td.td_token),
+            le32toh(p->td.td_buffer));
+
+       DPRINTFN(1, "bitstuff=%d crcto   =%d nak     =%d babble  =%d",
+           !!(le32toh(p->td.td_status) & UHCI_TD_BITSTUFF),
+           !!(le32toh(p->td.td_status) & UHCI_TD_CRCTO),
+           !!(le32toh(p->td.td_status) & UHCI_TD_NAK),
+           !!(le32toh(p->td.td_status) & UHCI_TD_BABBLE));
+       DPRINTFN(1, "dbuffer =%d stalled =%d active  =%d ioc     =%d",
+           !!(le32toh(p->td.td_status) & UHCI_TD_DBUFFER),
+           !!(le32toh(p->td.td_status) & UHCI_TD_STALLED),
+           !!(le32toh(p->td.td_status) & UHCI_TD_ACTIVE),
+           !!(le32toh(p->td.td_status) & UHCI_TD_IOC));
+       DPRINTFN(1, "ios     =%d ls      =%d spd     =%d",
+           !!(le32toh(p->td.td_status) & UHCI_TD_IOS),
+           !!(le32toh(p->td.td_status) & UHCI_TD_LS),
+           !!(le32toh(p->td.td_status) & UHCI_TD_SPD), 0);
+       DPRINTFN(1, "errcnt  =%d actlen  =%d pid=%02x",
+           UHCI_TD_GET_ERRCNT(le32toh(p->td.td_status)),
+           UHCI_TD_GET_ACTLEN(le32toh(p->td.td_status)),
+           UHCI_TD_GET_PID(le32toh(p->td.td_token)), 0);
+       DPRINTFN(1, "addr=%d  endpt=%d  D=%d  maxlen=%d,",
+           UHCI_TD_GET_DEVADDR(le32toh(p->td.td_token)),
+           UHCI_TD_GET_ENDPT(le32toh(p->td.td_token)),
+           UHCI_TD_GET_DT(le32toh(p->td.td_token)),
+           UHCI_TD_GET_MAXLEN(le32toh(p->td.td_token)));
 }
 
 void
 uhci_dump_qh(uhci_soft_qh_t *sqh)
 {
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+
        usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh),
            BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
-       DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", sqh,
+
+       DPRINTFN(1, "QH(%p) at %08x: hlink=%08x elink=%08x", sqh,
            (int)sqh->physaddr, le32toh(sqh->qh.qh_hlink),
-           le32toh(sqh->qh.qh_elink)));
+           le32toh(sqh->qh.qh_elink));
+
        usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), BUS_DMASYNC_PREREAD);
 }
 
@@ -794,6 +834,8 @@
 void
 uhci_dump_qhs(uhci_soft_qh_t *sqh)
 {
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+
        uhci_dump_qh(sqh);
 
        /*
@@ -811,19 +853,18 @@
         * TD2.x being the TDs queued at QH2 and QH1 being referenced from QH1.
         */
 
-
        usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh),
            BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
        if (sqh->hlink != NULL && !(le32toh(sqh->qh.qh_hlink) & UHCI_PTR_T))
                uhci_dump_qhs(sqh->hlink);
        else
-               DPRINTF(("No QH\n"));
+               DPRINTFN(1, "No QH", 0, 0, 0, 0);
        usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), BUS_DMASYNC_PREREAD);
 
        if (sqh->elink != NULL && !(le32toh(sqh->qh.qh_elink) & UHCI_PTR_T))
                uhci_dump_tds(sqh->elink);
        else
-               DPRINTF(("No TD\n"));
+               DPRINTFN(1, "No QH", 0, 0, 0, 0);
 }
 
 void
@@ -929,7 +970,7 @@
        uhci_softc_t *sc;
        u_char *p;
 
-       DPRINTFN(20, ("uhci_poll_hub\n"));
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
        if (__predict_false(pipe->up_dev == NULL || pipe->up_dev->ud_bus == NULL))
                return; /* device has detached */
@@ -967,12 +1008,14 @@
 void
 uhci_add_loop(uhci_softc_t *sc)
 {
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+       
 #ifdef UHCI_DEBUG
        if (uhcinoloop)
                return;
 #endif
        if (++sc->sc_loops == 1) {
-               DPRINTFN(5,("uhci_start_loop: add\n"));
+               DPRINTFN(5, "add loop", 0, 0, 0, 0);
                /* Note, we don't loop back the soft pointer. */
                sc->sc_last_qh->qh.qh_hlink =
                    htole32(sc->sc_hctl_start->physaddr | UHCI_PTR_QH);
@@ -986,12 +1029,14 @@
 void
 uhci_rem_loop(uhci_softc_t *sc)
 {
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+
 #ifdef UHCI_DEBUG
        if (uhcinoloop)
                return;
 #endif
        if (--sc->sc_loops == 0) {
-               DPRINTFN(5,("uhci_end_loop: remove\n"));
+               DPRINTFN(5, "remove loop", 0, 0, 0, 0);
                sc->sc_last_qh->qh.qh_hlink = htole32(UHCI_PTR_T);
                usb_syncmem(&sc->sc_last_qh->dma,
                    sc->sc_last_qh->offs + offsetof(uhci_qh_t, qh_hlink),
@@ -1006,9 +1051,11 @@
 {
        uhci_soft_qh_t *eqh;
 
+       UHCIHIST_FUNC(); UHCIHIST_CALLED();
+
        KASSERT(mutex_owned(&sc->sc_lock));



Home | Main Index | Thread Index | Old Index