Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Add new sysctl hw.wmN.debug_flags. This sysctl c...



details:   https://anonhg.NetBSD.org/src/rev/40da0860da03
branches:  trunk
changeset: 1015657:40da0860da03
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Oct 30 06:23:39 2020 +0000

description:
Add new sysctl hw.wmN.debug_flags. This sysctl can be used if WM_DEBUG is set.
OK'd by knakahara.

% sysctl -d hw.wm0.debug_flags
hw.wm0.debug_flags: Debug flags:
        0x01 LINK
        0x02 TX
        0x04 RX
        0x08 GMII
        0x10 MANAGE
        0x20 NVM
        0x40 INIT
        0x80 LOCK

diffstat:

 sys/dev/pci/if_wm.c |  430 +++++++++++++++++++++++++++++----------------------
 1 files changed, 248 insertions(+), 182 deletions(-)

diffs (truncated from 1643 to 300 lines):

diff -r 6c6ede7f991d -r 40da0860da03 sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Fri Oct 30 06:02:05 2020 +0000
+++ b/sys/dev/pci/if_wm.c       Fri Oct 30 06:23:39 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.692 2020/10/28 07:08:08 msaitoh Exp $      */
+/*     $NetBSD: if_wm.c,v 1.693 2020/10/30 06:23:39 msaitoh Exp $      */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.692 2020/10/28 07:08:08 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.693 2020/10/30 06:23:39 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -157,11 +157,20 @@
 #define        WM_DEBUG_NVM            __BIT(5)
 #define        WM_DEBUG_INIT           __BIT(6)
 #define        WM_DEBUG_LOCK           __BIT(7)
-int    wm_debug = WM_DEBUG_TX | WM_DEBUG_RX | WM_DEBUG_LINK | WM_DEBUG_GMII
-    | WM_DEBUG_MANAGE | WM_DEBUG_NVM | WM_DEBUG_INIT | WM_DEBUG_LOCK;
-#define        DPRINTF(x, y)   do { if (wm_debug & (x)) printf y; } while (0)
+
+#if 0
+#define WM_DEBUG_DEFAULT       WM_DEBUG_TX | WM_DEBUG_RX | WM_DEBUG_LINK | \
+       WM_DEBUG_GMII | WM_DEBUG_MANAGE | WM_DEBUG_NVM | WM_DEBUG_INIT |    \
+       WM_DEBUG_LOCK
+#endif
+
+#define        DPRINTF(sc, x, y)                         \
+       do {                                      \
+               if ((sc)->sc_debug & (x))         \
+                       printf y;                 \
+       } while (0)
 #else
-#define        DPRINTF(x, y)   __nothing
+#define        DPRINTF(sc, x, y)       __nothing
 #endif /* WM_DEBUG */
 
 #ifdef NET_MPSAFE
@@ -624,6 +633,9 @@
 
        struct wm_phyop phy;
        struct wm_nvmop nvm;
+#ifdef WM_DEBUG
+       uint32_t sc_debug;
+#endif
 };
 
 #define WM_CORE_LOCK(_sc)                                              \
@@ -1033,6 +1045,10 @@
 static int     wm_pll_workaround_i210(struct wm_softc *);
 static void    wm_legacy_irq_quirk_spt(struct wm_softc *);
 
+#ifdef WM_DEBUG
+static int     wm_sysctl_debug(SYSCTLFN_PROTO);
+#endif
+
 CFATTACH_DECL3_NEW(wm, sizeof(struct wm_softc),
     wm_match, wm_attach, wm_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
 
@@ -1844,6 +1860,9 @@
        uint32_t link_mode;
        uint32_t reg;
 
+#if defined(WM_DEBUG) && defined(WM_DEBUG_DEFAULT)
+       sc->sc_debug = WM_DEBUG_DEFAULT;
+#endif
        sc->sc_dev = self;
        callout_init(&sc->sc_tick_ch, WM_CALLOUT_FLAGS);
        callout_setfunc(&sc->sc_tick_ch, wm_tick, sc);
@@ -3422,7 +3441,7 @@
        bool needreset = false;
        int rc = 0;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        WM_CORE_LOCK(sc);
@@ -3478,7 +3497,7 @@
        struct sockaddr_dl *sdl;
        int s, error;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
 #ifndef WM_MPSAFE
@@ -3807,7 +3826,7 @@
        uint32_t hash, reg, bit;
        int i, size, ralmax, rv;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        if (sc->sc_type >= WM_T_82544)
@@ -3951,7 +3970,7 @@
 wm_set_vlan(struct wm_softc *sc)
 {
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        /* Deal with VLAN enables. */
@@ -4037,7 +4056,7 @@
        uint32_t reg = 0;
        int i;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        /* Wait for eeprom to reload */
@@ -4076,7 +4095,7 @@
        uint32_t reg;
        int i;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        /* Wait for eeprom to reload */
@@ -4123,7 +4142,7 @@
                        delay(1000);
                }
                if (i >= WM_PHY_CFG_TIMEOUT)
-                       DPRINTF(WM_DEBUG_GMII, ("%s: %s failed\n",
+                       DPRINTF(sc, WM_DEBUG_GMII, ("%s: %s failed\n",
                                device_xname(sc->sc_dev), __func__));
                break;
        case WM_T_ICH8:
@@ -4220,7 +4239,7 @@
        uint16_t phy_data;
        int rv;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        KASSERT(CSR_READ(sc, WMREG_EXTCNFCTR) & EXTCNFCTR_MDIO_SW_OWNERSHIP);
 
@@ -4245,7 +4264,7 @@
                        phy_data |= __SHIFTIN((freq & 0x02) != 0,
                            HV_SMB_ADDR_FREQ_HIGH);
                } else
-                       DPRINTF(WM_DEBUG_INIT,
+                       DPRINTF(sc, WM_DEBUG_INIT,
                            ("%s: %s Unsupported SMB frequency in PHY\n",
                                device_xname(sc->sc_dev), __func__));
        }
@@ -4261,7 +4280,7 @@
        uint16_t phy_page = 0;
        int rv = 0;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        switch (sc->sc_type) {
@@ -4303,7 +4322,7 @@
            && ((extcnfctr & EXTCNFCTR_PCIE_WRITE_ENABLE) != 0))
                goto release;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s: Configure LCD by software\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s: Configure LCD by software\n",
                device_xname(sc->sc_dev), __func__));
        /* word_addr is in DWORD */
        word_addr = __SHIFTOUT(extcnfctr, EXTCNFCTR_EXT_CNF_POINTER) << 1;
@@ -4321,7 +4340,7 @@
                 * LCD Write Enable bits are set in the NVM. When both NVM bits
                 * are cleared, SW will configure them instead.
                 */
-               DPRINTF(WM_DEBUG_INIT, ("%s: %s: Configure SMBus and LED\n",
+               DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s: Configure SMBus and LED\n",
                        device_xname(sc->sc_dev), __func__));
                if ((rv = wm_write_smbus_addr(sc)) != 0)
                        goto release;
@@ -4432,7 +4451,7 @@
 {
        uint32_t tarc0, tarc1, reg;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        /* For 82571 variant, 80003 and ICHs */
@@ -4693,7 +4712,7 @@
 {
        uint32_t reg;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        if (wm_phy_resetisblocked(sc))
                return -1;
@@ -4810,7 +4829,7 @@
        uint16_t kmreg;
        int rv;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        KASSERT(sc->sc_type != 0);
 
@@ -5822,6 +5841,24 @@
        if (rv != 0)
                goto teardown;
 
+#ifdef WM_DEBUG
+       rv = sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_READWRITE,
+           CTLTYPE_INT, "debug_flags",
+           SYSCTL_DESCR(
+                   "Debug flags:\n"    \
+                   "\t0x01 LINK\n"     \
+                   "\t0x02 TX\n"       \
+                   "\t0x04 RX\n"       \
+                   "\t0x08 GMII\n"     \
+                   "\t0x10 MANAGE\n"   \
+                   "\t0x20 NVM\n"      \
+                   "\t0x40 INIT\n"     \
+                   "\t0x80 LOCK"),
+           wm_sysctl_debug, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL);
+       if (rv != 0)
+               goto teardown;
+#endif
+
        return;
 
 teardown:
@@ -5858,7 +5895,7 @@
        int i, j, trynum, error = 0;
        uint32_t reg, sfp_mask = 0;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        KASSERT(WM_CORE_LOCKED(sc));
 
@@ -6462,7 +6499,7 @@
        struct wm_txsoft *txs;
        int i, qidx;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        KASSERT(WM_CORE_LOCKED(sc));
 
@@ -7143,7 +7180,7 @@
     struct wm_txqueue *txq)
 {
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
        KASSERT(mutex_owned(txq->txq_lock));
 
@@ -7352,7 +7389,7 @@
 {
        int i, error = 0;
 
-       DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+       DPRINTF(sc, WM_DEBUG_INIT, ("%s: %s called\n",
                device_xname(sc->sc_dev), __func__));
 
        for (i = 0; i < sc->sc_nqueues; i++) {
@@ -7745,7 +7782,7 @@
                if (txq->txq_sfree < WM_TXQUEUE_GC(txq)) {
                        wm_txeof(txq, UINT_MAX);
                        if (txq->txq_sfree == 0) {
-                               DPRINTF(WM_DEBUG_TX,
+                               DPRINTF(sc, WM_DEBUG_TX,
                                    ("%s: TX: no free job descriptors\n",
                                        device_xname(sc->sc_dev)));
                                WM_Q_EVCNT_INCR(txq, txsstall);
@@ -7761,7 +7798,7 @@
                if (m0 == NULL)
                        break;
 
-               DPRINTF(WM_DEBUG_TX,
+               DPRINTF(sc, WM_DEBUG_TX,
                    ("%s: TX: have packet to transmit: %p\n",
                        device_xname(sc->sc_dev), m0));
 
@@ -7818,7 +7855,7 @@
                                continue;
                        }
                        /* Short on resources, just stop for now. */
-                       DPRINTF(WM_DEBUG_TX,
+                       DPRINTF(sc, WM_DEBUG_TX,
                            ("%s: TX: dmamap load failed: %d\n",
                                device_xname(sc->sc_dev), error));
                        break;
@@ -7845,7 +7882,7 @@
                         * pack on the queue, and punt. Notify the upper
                         * layer that there are no more slots left.



Home | Main Index | Thread Index | Old Index