Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb ugen(4): convert to USBHIST style debugging.



details:   https://anonhg.NetBSD.org/src/rev/825b5b78fafb
branches:  trunk
changeset: 371961:825b5b78fafb
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Oct 21 04:55:11 2022 +0000

description:
ugen(4): convert to USBHIST style debugging.

diffstat:

 sys/dev/usb/ugen.c |  215 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 136 insertions(+), 79 deletions(-)

diffs (truncated from 568 to 300 lines):

diff -r e9f76a663c4f -r 825b5b78fafb sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c        Fri Oct 21 03:08:29 2022 +0000
+++ b/sys/dev/usb/ugen.c        Fri Oct 21 04:55:11 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugen.c,v 1.168 2021/09/26 01:16:09 thorpej Exp $       */
+/*     $NetBSD: ugen.c,v 1.169 2022/10/21 04:55:11 mrg Exp $   */
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.168 2021/09/26 01:16:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.169 2022/10/21 04:55:11 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -64,17 +64,50 @@
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbhist.h>
 
 #include "ioconf.h"
 
-#ifdef UGEN_DEBUG
-#define DPRINTF(x)     if (ugendebug) printf x
-#define DPRINTFN(n,x)  if (ugendebug>(n)) printf x
+#ifdef USB_DEBUG
+#ifndef UGEN_DEBUG
+#define ugendebug 0
+#else
 int    ugendebug = 0;
-#else
-#define DPRINTF(x)
-#define DPRINTFN(n,x)
-#endif
+
+SYSCTL_SETUP(sysctl_hw_ugen_setup, "sysctl hw.ugen setup")
+{
+       int err;
+       const struct sysctlnode *rnode;
+       const struct sysctlnode *cnode;
+
+       err = sysctl_createv(clog, 0, NULL, &rnode,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "ugen",
+           SYSCTL_DESCR("ugen 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, &ugendebug, sizeof(ugendebug), CTL_CREATE, CTL_EOL);
+       if (err)
+               goto fail;
+
+       return;
+fail:
+       aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
+
+#endif /* UGEN_DEBUG */
+#endif /* USB_DEBUG */
+
+#define DPRINTF(FMT,A,B,C,D)    USBHIST_LOGN(ugendebug,1,FMT,A,B,C,D)
+#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(ugendebug,N,FMT,A,B,C,D)
+#define UGENHIST_FUNC()         USBHIST_FUNC()
+#define UGENHIST_CALLED(name)   USBHIST_CALLED(ugendebug)
 
 #define        UGEN_CHUNK      128     /* chunk size for read */
 #define        UGEN_IBSIZE     1020    /* buffer size */
@@ -438,8 +471,10 @@
        usbd_status err;
        int dir;
 
-       DPRINTFN(1,("ugen_set_config: %s to configno %d, sc=%p\n",
-                   device_xname(sc->sc_dev), configno, sc));
+       UGENHIST_FUNC(); UGENHIST_CALLED();
+
+       DPRINTFN(1, "ugen%jd: %s to configno %jd, sc=%jx",
+                   device_unit(sc->sc_dev), configno, sc, 0);
 
        KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
@@ -451,8 +486,8 @@
                for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++)
                        if (sc->sc_is_open[endptno]) {
                                DPRINTFN(1,
-                                    ("ugen_set_config: %s - endpoint %d is open\n",
-                                     device_xname(sc->sc_dev), endptno));
+                                    "%s - endpoint %d is open",
+                                     endptno, 0, 0, 0);
                                return USBD_IN_USE;
                        }
 
@@ -478,7 +513,7 @@
                goto out;
 
        for (ifaceno = 0; ifaceno < niface; ifaceno++) {
-               DPRINTFN(1,("ugen_set_config: ifaceno %d\n", ifaceno));
+               DPRINTFN(1, "ifaceno %jd", ifaceno, 0, 0, 0);
                err = usbd_device2interface_handle(dev, ifaceno, &iface);
                if (err)
                        goto out;
@@ -491,10 +526,9 @@
                        endpt = ed->bEndpointAddress;
                        dir = UE_GET_DIR(endpt) == UE_DIR_IN ? IN : OUT;
                        sce = &sc->sc_endpoints[UE_GET_ADDR(endpt)][dir];
-                       DPRINTFN(1,("ugen_set_config: endptno %d, endpt=0x%02x"
-                                   "(%d,%d), sce=%p\n",
-                                   endptno, endpt, UE_GET_ADDR(endpt),
-                                   UE_GET_DIR(endpt), sce));
+                       DPRINTFN(1, "endptno %jd, endpt=0x%02jx (%jd,%jd)",
+                                endptno, endpt, UE_GET_ADDR(endpt),
+                                UE_GET_DIR(endpt));
                        sce->sc = sc;
                        sce->edesc = ed;
                        sce->iface = iface;
@@ -530,13 +564,15 @@
        int error;
        int opened;
 
+       UGENHIST_FUNC(); UGENHIST_CALLED();
+
        KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
        if ((sc = ugenif_acquire(unit)) == NULL)
                return ENXIO;
 
-       DPRINTFN(5, ("ugenopen: flag=%d, mode=%d, unit=%d endpt=%d\n",
-                    flag, mode, unit, endpt));
+       DPRINTFN(5, "flag=%jd, mode=%jd, unit=%jd endpt=%jd",
+                    flag, mode, unit, endpt);
 
        /* The control endpoint allows multiple opens. */
        if (endpt == USB_CONTROL_ENDPOINT) {
@@ -570,8 +606,8 @@
                sce = &sc->sc_endpoints[endpt][dir];
                sce->state = 0;
                sce->timeout = USBD_NO_TIMEOUT;
-               DPRINTFN(5, ("ugenopen: sc=%p, endpt=%d, dir=%d, sce=%p\n",
-                            sc, endpt, dir, sce));
+               DPRINTFN(5, "sc=%jx, endpt=%jd, dir=%jd, sce=%jp",
+                            sc, endpt, dir, sce);
                edesc = sce->edesc;
                switch (edesc->bmAttributes & UE_XFERTYPE) {
                case UE_INTERRUPT:
@@ -590,8 +626,8 @@
                                goto out;
                        }
                        sce->ibuf = kmem_alloc(isize, KM_SLEEP);
-                       DPRINTFN(5, ("ugenopen: intr endpt=%d,isize=%d\n",
-                                    endpt, isize));
+                       DPRINTFN(5, "intr endpt=%d, isize=%d",
+                                    endpt, isize, 0, 0);
                        if (clalloc(&sce->q, UGEN_IBSIZE, 0) == -1) {
                                kmem_free(sce->ibuf, isize);
                                sce->ibuf = NULL;
@@ -610,7 +646,7 @@
                                error = EIO;
                                goto out;
                        }
-                       DPRINTFN(5, ("ugenopen: interrupt open done\n"));
+                       DPRINTFN(5, "interrupt open done", 0, 0, 0, 0);
                        break;
                case UE_BULK:
                        err = usbd_open_pipe(sce->iface,
@@ -640,8 +676,8 @@
                                KM_SLEEP);
                        sce->cur = sce->fill = sce->ibuf;
                        sce->limit = sce->ibuf + isize * UGEN_NISOFRAMES;
-                       DPRINTFN(5, ("ugenopen: isoc endpt=%d, isize=%d\n",
-                                    endpt, isize));
+                       DPRINTFN(5, "isoc endpt=%d, isize=%d",
+                                    endpt, isize, 0, 0);
                        err = usbd_open_pipe(sce->iface,
                                  edesc->bEndpointAddress, 0, &sce->pipeh);
                        if (err) {
@@ -666,7 +702,7 @@
                                    ugen_isoc_rintr);
                                (void)usbd_transfer(xfer);
                        }
-                       DPRINTFN(5, ("ugenopen: isoc open done\n"));
+                       DPRINTFN(5, "isoc open done", 0, 0, 0, 0);
                        break;
                bad:
                        while (--i >= 0) { /* implicit buffer free */
@@ -699,13 +735,15 @@
        int dir;
        int i;
 
+       UGENHIST_FUNC(); UGENHIST_CALLED();
+
        KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
        if (!sc->sc_is_open[endpt])
                goto out;
 
        if (endpt == USB_CONTROL_ENDPOINT) {
-               DPRINTFN(5, ("ugenclose: close control\n"));
+               DPRINTFN(5, "close control", 0, 0, 0, 0);
                goto out;
        }
 
@@ -715,8 +753,8 @@
                sce = &sc->sc_endpoints[endpt][dir];
                if (sce->pipeh == NULL)
                        continue;
-               DPRINTFN(5, ("ugenclose: endpt=%d dir=%d sce=%p\n",
-                            endpt, dir, sce));
+               DPRINTFN(5, "endpt=%jd dir=%jd sce=%jx",
+                            endpt, dir, sce, 0);
 
                usbd_abort_pipe(sce->pipeh);
 
@@ -771,8 +809,10 @@
        int endpt = UGENENDPOINT(dev);
        struct ugen_softc *sc;
 
-       DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
-                    flag, mode, UGENUNIT(dev), endpt));
+       UGENHIST_FUNC(); UGENHIST_CALLED();
+
+       DPRINTFN(5, "flag=%jd, mode=%jd, unit=%jd, endpt=%jd",
+                    flag, mode, UGENUNIT(dev), endpt);
 
        KASSERT(KERNEL_LOCKED_P()); /* ugen_do_close */
 
@@ -797,7 +837,9 @@
        usbd_status err;
        int error = 0;
 
-       DPRINTFN(5, ("%s: ugenread: %d\n", device_xname(sc->sc_dev), endpt));
+       UGENHIST_FUNC(); UGENHIST_CALLED();
+
+       DPRINTFN(5, "ugen%d: %jd", device_unit(sc->sc_dev), endpt, 0, 0);
 
        if (endpt == USB_CONTROL_ENDPOINT)
                return ENODEV;
@@ -814,11 +856,12 @@
                                mutex_exit(&sc->sc_lock);
                                return EWOULDBLOCK;
                        }
-                       DPRINTFN(5, ("ugenread: sleep on %p\n", sce));
+                       DPRINTFN(5, "sleep on %jx", sce, 0, 0, 0);
                        /* "ugenri" */
                        error = cv_timedwait_sig(&sce->cv, &sc->sc_lock,
                            mstohz(sce->timeout));
-                       DPRINTFN(5, ("ugenread: woke, error=%d\n", error));
+                       DPRINTFN(5, "woke, error=%jd",
+                                   error, 0, 0, 0);
                        if (sc->sc_dying)
                                error = EIO;
                        if (error)
@@ -834,7 +877,7 @@
 
                        /* Remove a small chunk from the input queue. */
                        q_to_b(&sce->q, sc->sc_buffer, n);
-                       DPRINTFN(5, ("ugenread: got %d chars\n", n));
+                       DPRINTFN(5, "got %jd chars", n, 0, 0, 0);
 
                        /* Copy the data to the user process. */
                        error = uiomove(sc->sc_buffer, n, uio);
@@ -844,8 +887,8 @@
                break;
        case UE_BULK:
                if (sce->state & UGEN_BULK_RA) {
-                       DPRINTFN(5, ("ugenread: BULK_RA req: %zd used: %d\n",
-                                    uio->uio_resid, sce->ra_wb_used));
+                       DPRINTFN(5, "BULK_RA req: %zd used: %d",
+                                    uio->uio_resid, sce->ra_wb_used, 0, 0);
                        xfer = sce->ra_wb_xfer;
 
                        mutex_enter(&sc->sc_lock);
@@ -855,15 +898,13 @@
                        }
                        while (uio->uio_resid > 0 && !error) {
                                while (sce->ra_wb_used == 0) {
-                                       DPRINTFN(5,
-                                                ("ugenread: sleep on %p\n",
-                                                 sce));
+                                       DPRINTFN(5, "sleep on %jx",
+                                                   sce, 0, 0, 0);
                                        /* "ugenrb" */
                                        error = cv_timedwait_sig(&sce->cv,
                                            &sc->sc_lock, mstohz(sce->timeout));
-                                       DPRINTFN(5,
-                                                ("ugenread: woke, error=%d\n",
-                                                 error));
+                                       DPRINTFN(5, "woke, error=%jd",
+                                                   error, 0, 0, 0);
                                        if (sc->sc_dying)
                                                error = EIO;
                                        if (error)
@@ -917,7 +958,7 @@



Home | Main Index | Thread Index | Old Index