Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb usbhist(9):



details:   https://anonhg.NetBSD.org/src/rev/02b24c92dcf7
branches:  trunk
changeset: 453667:02b24c92dcf7
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Aug 22 00:24:07 2019 +0000

description:
usbhist(9):
- add a USBHIST_CALLARGSN() that only prints the message if debug level is N

aue(4):
- switch from printf() to usbhist for debugging

diffstat:

 sys/dev/usb/if_aue.c  |  205 ++++++++++++++++++++++++++++++++++---------------
 sys/dev/usb/usbhist.h |    8 +-
 2 files changed, 150 insertions(+), 63 deletions(-)

diffs (truncated from 529 to 300 lines):

diff -r 0f32d1b8bdc7 -r 02b24c92dcf7 sys/dev/usb/if_aue.c
--- a/sys/dev/usb/if_aue.c      Wed Aug 21 21:45:47 2019 +0000
+++ b/sys/dev/usb/if_aue.c      Thu Aug 22 00:24:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_aue.c,v 1.156 2019/08/07 06:31:03 msaitoh Exp $     */
+/*     $NetBSD: if_aue.c,v 1.157 2019/08/22 00:24:07 mrg Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.156 2019/08/07 06:31:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.157 2019/08/22 00:24:07 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -116,20 +116,57 @@
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbdevs.h>
+#include <dev/usb/usbhist.h>
 
 #include <sys/condvar.h>
 #include <sys/kthread.h>
 
 #include <dev/usb/if_auereg.h>
 
-#ifdef AUE_DEBUG
-#define DPRINTF(x)     if (auedebug) printf x
-#define DPRINTFN(n, x) if (auedebug >= (n)) printf x
-int    auedebug = 0;
+#ifdef USB_DEBUG
+#ifndef AUE_DEBUG
+#define auedebug 0
 #else
-#define DPRINTF(x)
-#define DPRINTFN(n, x)
-#endif
+static int auedebug = 10;
+
+SYSCTL_SETUP(sysctl_hw_aue_setup, "sysctl hw.aue setup")
+{
+       int err;
+       const struct sysctlnode *rnode;
+       const struct sysctlnode *cnode;
+
+       err = sysctl_createv(clog, 0, NULL, &rnode,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "aue",
+           SYSCTL_DESCR("aue 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, &auedebug, sizeof(auedebug), CTL_CREATE, CTL_EOL);
+       if (err)
+               goto fail;
+
+       return;
+fail:
+       aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
+
+#endif /* AXE_DEBUG */
+#endif /* USB_DEBUG */
+
+#define DPRINTF(FMT,A,B,C,D)   USBHIST_LOGN(auedebug,1,FMT,A,B,C,D)
+#define DPRINTFN(N,FMT,A,B,C,D)        USBHIST_LOGN(auedebug,N,FMT,A,B,C,D)
+#define AUEHIST_FUNC()         USBHIST_FUNC()
+#define AUEHIST_CALLED(name)   USBHIST_CALLED(auedebug)
+#define AUEHIST_CALLARGS(FMT,A,B,C,D) \
+                               USBHIST_CALLARGS(auedebug,FMT,A,B,C,D)
+#define AUEHIST_CALLARGSN(N,FMT,A,B,C,D) \
+                               USBHIST_CALLARGSN(auedebug,N,FMT,A,B,C,D)
 
 /*
  * Various supported device vendors/products.
@@ -279,8 +316,9 @@
        err = usbd_do_request(sc->aue_udev, &req, &val);
 
        if (err) {
-               DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
-                   device_xname(sc->aue_dev), reg, usbd_errstr(err)));
+               AUEHIST_FUNC();
+               AUEHIST_CALLARGS("%d: aue_csr_read_1: reg=%#x err=%#s",
+                   device_unit(sc->aue_dev), reg, usbd_errstr(err), 0);
                return 0;
        }
 
@@ -306,8 +344,9 @@
        err = usbd_do_request(sc->aue_udev, &req, &val);
 
        if (err) {
-               DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
-                   device_xname(sc->aue_dev), reg, usbd_errstr(err)));
+               AUEHIST_FUNC();
+               AUEHIST_CALLARGS("%d: aue_csr_read_2: reg=%#x err=%s",
+                   device_unit(sc->aue_dev), reg, usbd_errstr(err), 0);
                return 0;
        }
 
@@ -334,8 +373,9 @@
        err = usbd_do_request(sc->aue_udev, &req, &val);
 
        if (err) {
-               DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
-                   device_xname(sc->aue_dev), reg, usbd_errstr(err)));
+               AUEHIST_FUNC();
+               AUEHIST_CALLARGS("%d: aue_csr_write_1: reg=%#x err=%s",
+                   device_unit(sc->aue_dev), reg, usbd_errstr(err), 0);
                return -1;
        }
 
@@ -362,8 +402,9 @@
        err = usbd_do_request(sc->aue_udev, &req, &val);
 
        if (err) {
-               DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
-                   device_xname(sc->aue_dev), reg, usbd_errstr(err)));
+               AUEHIST_FUNC();
+               AUEHIST_CALLARGS("%s: aue_csr_write_2: reg=%#x err=%s",
+                   device_unit(sc->aue_dev), reg, usbd_errstr(err), 0);
                return -1;
        }
 
@@ -377,6 +418,7 @@
 aue_eeprom_getword(struct aue_softc *sc, int addr)
 {
        int             i;
+       AUEHIST_FUNC(); AUEHIST_CALLED();
 
        aue_csr_write_1(sc, AUE_EE_REG, addr);
        aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
@@ -404,7 +446,9 @@
        int                     off = 0;
        int                     word;
 
-       DPRINTFN(5,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGS("%d: enter",
+           device_unit(sc->aue_dev), 0, 0, 0);
 
        for (i = 0; i < 3; i++) {
                word = aue_eeprom_getword(sc, off + i);
@@ -435,10 +479,11 @@
        struct aue_softc *sc = device_private(dev);
        int                     i, rv = 0;
 
+       AUEHIST_FUNC();
+
        if (sc->aue_dying) {
-#ifdef DIAGNOSTIC
-               printf("%s: dying\n", device_xname(sc->aue_dev));
-#endif
+               AUEHIST_CALLARGS("%d: phy=%jx reg=%jx is dying",
+                   device_unit(sc->aue_dev), phy, reg, 0);
                return -1;
        }
 
@@ -470,15 +515,16 @@
        }
 
        if (i == AUE_TIMEOUT) {
-               printf("%s: MII read timed out\n", device_xname(sc->aue_dev));
+               AUEHIST_CALLARGS("%d: phy=%jx reg=%jx read timed out",
+                   device_unit(sc->aue_dev), phy, reg, 0);
                rv = ETIMEDOUT;
                goto out;
        }
 
        *val = aue_csr_read_2(sc, AUE_PHY_DATA);
 
-       DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04hx\n",
-           device_xname(sc->aue_dev), __func__, phy, reg, *val));
+       AUEHIST_CALLARGS("%d: phy=%jx reg=%jx => %#04hx",
+           device_unit(sc->aue_dev), phy, reg, *val);
 
 out:
        aue_unlock_mii(sc);
@@ -491,6 +537,10 @@
        struct aue_softc *sc = device_private(dev);
        int                     i, rv = 0;
 
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGS("%d: phy=%d reg=%d data=%#04hx",
+           device_unit(sc->aue_dev), phy, reg, val);
+
 #if 0
        if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
            sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
@@ -499,9 +549,6 @@
        }
 #endif
 
-       DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04hx\n",
-           device_xname(sc->aue_dev), __func__, phy, reg, val));
-
        aue_lock_mii(sc);
        aue_csr_write_2(sc, AUE_PHY_DATA, val);
        aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
@@ -513,7 +560,8 @@
        }
 
        if (i == AUE_TIMEOUT) {
-               printf("%s: MII read timed out\n", device_xname(sc->aue_dev));
+               DPRINTF("%d: phy=%jx reg=%jx val=%jx write timed out",
+                   device_unit(sc->aue_dev), phy, reg, val);
                rv = ETIMEDOUT;
        }
        aue_unlock_mii(sc);
@@ -527,7 +575,9 @@
        struct aue_softc *sc = ifp->if_softc;
        struct mii_data *mii = GET_MII(sc);
 
-       DPRINTFN(5,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC(); AUEHIST_CALLED();
+       AUEHIST_CALLARGS("%d: ifp=%jx",
+           device_unit(sc->aue_dev), (uintptr_t)ifp, 0, 0);
 
        aue_lock_mii(sc);
        AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
@@ -556,7 +606,6 @@
                aue_miibus_readreg(sc->aue_dev, 0, 0x1b, &auxmode);
                aue_miibus_writereg(sc->aue_dev, 0, 0x1b, auxmode | 0x04);
        }
-       DPRINTFN(5,("%s: %s: exit\n", device_xname(sc->aue_dev), __func__));
 }
 
 #define AUE_POLY       0xEDB88320
@@ -589,7 +638,9 @@
        uint32_t                h = 0, i;
        uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
 
-       DPRINTFN(5,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(5, "%d: enter",
+           device_unit(sc->aue_dev), 0, 0, 0);
 
        ifp = GET_IFP(sc);
 
@@ -644,7 +695,9 @@
 {
        int             i;
 
-       DPRINTFN(2,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(2, "%d: enter",
+           device_unit(sc->aue_dev), 0, 0, 0);
 
        AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
 
@@ -744,9 +797,11 @@
        usb_endpoint_descriptor_t       *ed;
        int                     i;
 
-       DPRINTFN(5,(" : aue_attach: sc=%p", sc));
+       sc->aue_dev = self;
 
-       sc->aue_dev = self;
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(2, "%d: enter sc=%jx",
+           device_unit(sc->aue_dev), (uintptr_t)sc, 0, 0);
 
        aprint_naive("\n");
        aprint_normal("\n");
@@ -892,7 +947,9 @@
        struct ifnet            *ifp = GET_IFP(sc);
        int                     s;
 
-       DPRINTFN(2,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(2, "%d: enter",
+           device_unit(sc->aue_dev), 0, 0, 0);
 
        if (!sc->aue_attached) {
                /* Detached before attached finished, so just bail out. */
@@ -966,7 +1023,9 @@
 {
        struct aue_softc *sc = device_private(self);
 
-       DPRINTFN(2,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(2, "%d: enter",
+           device_unit(sc->aue_dev), 0, 0, 0);
 
        switch (act) {
        case DVACT_DEACTIVATE:
@@ -986,7 +1045,9 @@
 {
        struct mbuf             *m_new = NULL;
 
-       DPRINTFN(10,("%s: %s: enter\n", device_xname(sc->aue_dev),__func__));
+       AUEHIST_FUNC();
+       AUEHIST_CALLARGSN(10, "%d: enter",



Home | Main Index | Thread Index | Old Index