svn commit: r303810 - head/sys/dev/etherswitch/arswitch

Adrian Chadd adrian at FreeBSD.org
Sun Aug 7 01:32:39 UTC 2016


Author: adrian
Date: Sun Aug  7 01:32:37 2016
New Revision: 303810
URL: https://svnweb.freebsd.org/changeset/base/303810

Log:
  [arswitch] extend the debug support to be configurable at runtime.
  
  * remove the DEBUG ifdef; defining it is too far reaching throughout
    the whole system;
  * add a bitmask in the softc for controlling debugging;
  * .. enable said debugging as a sysctl;
  * add bitmaps for register access, reset and vlans.
  
  TODO:
  
  * Now that the debug statements are configurable, we definitely could
    do with more debugging
  * Move the debugging into the top-level etherswitch driver and have
    sub-drivers obey.

Modified:
  head/sys/dev/etherswitch/arswitch/arswitch.c
  head/sys/dev/etherswitch/arswitch/arswitch_8327.c
  head/sys/dev/etherswitch/arswitch/arswitch_phy.c
  head/sys/dev/etherswitch/arswitch/arswitch_reg.c
  head/sys/dev/etherswitch/arswitch/arswitchvar.h

Modified: head/sys/dev/etherswitch/arswitch/arswitch.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch.c	Sun Aug  7 01:29:55 2016	(r303809)
+++ head/sys/dev/etherswitch/arswitch/arswitch.c	Sun Aug  7 01:32:37 2016	(r303810)
@@ -73,10 +73,6 @@
 #include "miibus_if.h"
 #include "etherswitch_if.h"
 
-#if	defined(DEBUG)
-static SYSCTL_NODE(_debug, OID_AUTO, arswitch, CTLFLAG_RD, 0, "arswitch");
-#endif
-
 /* Map ETHERSWITCH_PORT_LED_* to Atheros pattern codes */
 static int led_pattern_table[] = {
 	[ETHERSWITCH_PORT_LED_DEFAULT] = 0x3,
@@ -156,7 +152,7 @@ arswitch_probe(device_t dev)
 
 done:
 
-	DPRINTF(dev, "chipname=%s, id=%08x\n", chipname, id);
+	DPRINTF(sc, ARSWITCH_DBG_ANY, "chipname=%s, id=%08x\n", chipname, id);
 	if (chipname != NULL) {
 		snprintf(desc, sizeof(desc),
 		    "Atheros %s Ethernet Switch (ver %d rev %d)",
@@ -309,12 +305,12 @@ ar8xxx_atu_flush(struct arswitch_softc *
 static int
 arswitch_attach(device_t dev)
 {
-	struct arswitch_softc *sc;
+	struct arswitch_softc *sc = device_get_softc(dev);
+	struct sysctl_ctx_list *ctx;
+	struct sysctl_oid *tree;
 	int err = 0;
 	int port;
 
-	sc = device_get_softc(dev);
-
 	/* sc->sc_switchtype is already decided in arswitch_probe() */
 	sc->sc_dev = dev;
 	mtx_init(&sc->sc_mtx, "arswitch", NULL, MTX_DEF);
@@ -322,6 +318,13 @@ arswitch_attach(device_t dev)
 	strlcpy(sc->info.es_name, device_get_desc(dev),
 	    sizeof(sc->info.es_name));
 
+	/* Debugging */
+	ctx = device_get_sysctl_ctx(sc->sc_dev);
+	tree = device_get_sysctl_tree(sc->sc_dev);
+	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+	    "debug", CTLFLAG_RW, &sc->sc_debug, 0,
+	    "control debugging printfs");
+
 	/* Default HAL methods */
 	sc->hal.arswitch_port_init = ar8xxx_port_init;
 	sc->hal.arswitch_port_vlan_setup = ar8xxx_port_vlan_setup;
@@ -363,7 +366,8 @@ arswitch_attach(device_t dev)
 	else if (AR8X16_IS_SWITCH(sc, AR8327))
 		ar8327_attach(sc);
 	else {
-		DPRINTF(dev, "%s: unknown switch (%d)?\n", __func__, sc->sc_switchtype);
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: unknown switch (%d)?\n", __func__, sc->sc_switchtype);
 		return (ENXIO);
 	}
 
@@ -393,19 +397,24 @@ arswitch_attach(device_t dev)
 
 	/* Reset the switch. */
 	if (arswitch_reset(dev)) {
-		DPRINTF(dev, "%s: arswitch_reset: failed\n", __func__);
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: arswitch_reset: failed\n", __func__);
 		return (ENXIO);
 	}
 
 	err = sc->hal.arswitch_hw_setup(sc);
-	DPRINTF(dev, "%s: hw_setup: err=%d\n", __func__, err);
-	if (err != 0)
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: hw_setup: err=%d\n", __func__, err);
 		return (err);
+	}
 
 	err = sc->hal.arswitch_hw_global_setup(sc);
-	DPRINTF(dev, "%s: hw_global_setup: err=%d\n", __func__, err);
-	if (err != 0)
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: hw_global_setup: err=%d\n", __func__, err);
 		return (err);
+	}
 
 	/* Initialize the switch ports. */
 	for (port = 0; port <= sc->numphys; port++) {
@@ -416,22 +425,28 @@ arswitch_attach(device_t dev)
 	 * Attach the PHYs and complete the bus enumeration.
 	 */
 	err = arswitch_attach_phys(sc);
-	DPRINTF(dev, "%s: attach_phys: err=%d\n", __func__, err);
-	if (err != 0)
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: attach_phys: err=%d\n", __func__, err);
 		return (err);
+	}
 
 	/* Default to ingress filters off. */
 	err = arswitch_set_vlan_mode(sc, 0);
-	DPRINTF(dev, "%s: set_vlan_mode: err=%d\n", __func__, err);
-	if (err != 0)
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: set_vlan_mode: err=%d\n", __func__, err);
 		return (err);
+	}
 
 	bus_generic_probe(dev);
 	bus_enumerate_hinted_children(dev);
 	err = bus_generic_attach(dev);
-	DPRINTF(dev, "%s: bus_generic_attach: err=%d\n", __func__, err);
-	if (err != 0)
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: bus_generic_attach: err=%d\n", __func__, err);
 		return (err);
+	}
 	
 	callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
 
@@ -560,10 +575,11 @@ arswitch_miipollstat(struct arswitch_sof
 		else
 			portstatus = arswitch_readreg(sc->sc_dev,
 			    AR8X16_REG_PORT_STS(arswitch_portforphy(i)));
-#if 0
-		DPRINTF(sc->sc_dev, "p[%d]=%b\n",
+#if 1
+		DPRINTF(sc, ARSWITCH_DBG_POLL, "p[%d]=0x%08x (%b)\n",
 		    i,
 		    portstatus,
+		    portstatus,
 		    "\20\3TXMAC\4RXMAC\5TXFLOW\6RXFLOW\7"
 		    "DUPLEX\11LINK_UP\12LINK_AUTO\13LINK_PAUSE");
 #endif
@@ -845,8 +861,9 @@ arswitch_setled(struct arswitch_softc *s
 static void
 arswitch_statchg(device_t dev)
 {
+	struct arswitch_softc *sc = device_get_softc(dev);
 
-	DPRINTF(dev, "%s\n", __func__);
+	DPRINTF(sc, ARSWITCH_DBG_POLL, "%s\n", __func__);
 }
 
 static int
@@ -867,7 +884,7 @@ arswitch_ifmedia_sts(struct ifnet *ifp, 
 	struct arswitch_softc *sc = ifp->if_softc;
 	struct mii_data *mii = arswitch_miiforport(sc, ifp->if_dunit);
 
-	DPRINTF(sc->sc_dev, "%s\n", __func__);
+	DPRINTF(sc, ARSWITCH_DBG_POLL, "%s\n", __func__);
 
 	if (mii == NULL)
 		return;

Modified: head/sys/dev/etherswitch/arswitch/arswitch_8327.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_8327.c	Sun Aug  7 01:29:55 2016	(r303809)
+++ head/sys/dev/etherswitch/arswitch/arswitch_8327.c	Sun Aug  7 01:32:37 2016	(r303810)
@@ -1086,7 +1086,7 @@ ar8327_get_dot1q_vlan(struct arswitch_so
 	}
 
 	reg = arswitch_readreg(sc->sc_dev, AR8327_REG_VTU_FUNC0);
-	DPRINTF(sc->sc_dev, "%s: %d: reg=0x%08x\n", __func__, vid, reg);
+	DPRINTF(sc, ARSWITCH_DBG_REGIO, "%s: %d: reg=0x%08x\n", __func__, vid, reg);
 
 	/*
 	 * If any of the bits are set, update the port mask.
@@ -1118,7 +1118,7 @@ ar8327_set_dot1q_vlan(struct arswitch_so
 	op = AR8327_VTU_FUNC1_OP_LOAD;
 	vid &= 0xfff;
 
-	DPRINTF(sc->sc_dev,
+	DPRINTF(sc, ARSWITCH_DBG_VLAN,
 	    "%s: vid: %d, ports=0x%08x, untagged_ports=0x%08x\n",
 	    __func__,
 	    vid,

Modified: head/sys/dev/etherswitch/arswitch/arswitch_phy.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_phy.c	Sun Aug  7 01:29:55 2016	(r303809)
+++ head/sys/dev/etherswitch/arswitch/arswitch_phy.c	Sun Aug  7 01:32:37 2016	(r303810)
@@ -62,10 +62,6 @@
 #include "miibus_if.h"
 #include "etherswitch_if.h"
 
-#if	defined(DEBUG)
-static SYSCTL_NODE(_debug, OID_AUTO, arswitch, CTLFLAG_RD, 0, "arswitch");
-#endif
-
 /*
  * Access PHYs integrated into the switch by going direct
  * to the PHY space itself, rather than through the switch
@@ -81,6 +77,9 @@ arswitch_readphy_external(device_t dev, 
 
 	ARSWITCH_LOCK(sc);
 	ret = (MDIO_READREG(device_get_parent(dev), phy, reg));
+	DPRINTF(sc, ARSWITCH_DBG_PHYIO,
+	    "%s: phy=0x%08x, reg=0x%08x, ret=0x%08x\n",
+	    __func__, phy, reg, ret);
 	ARSWITCH_UNLOCK(sc);
 
 	return (ret);
@@ -96,6 +95,9 @@ arswitch_writephy_external(device_t dev,
 	ARSWITCH_LOCK(sc);
 	(void) MDIO_WRITEREG(device_get_parent(dev), phy,
 	    reg, data);
+	DPRINTF(sc, ARSWITCH_DBG_PHYIO,
+	    "%s: phy=0x%08x, reg=0x%08x, data=0x%08x\n",
+	    __func__, phy, reg, data);
 	ARSWITCH_UNLOCK(sc);
 
 	return (0);
@@ -141,7 +143,9 @@ arswitch_readphy_internal(device_t dev, 
 			break;
 	}
 	if (timeout < 0) {
-		DPRINTF(dev, "arswitch_readphy(): phy=%d.%02x; timeout=%d\n", phy, reg, timeout);
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "arswitch_readphy(): phy=%d.%02x; timeout=%d\n",
+		    phy, reg, timeout);
 		goto fail;
 	}
 	data = arswitch_readreg_lsb(dev, a) &

Modified: head/sys/dev/etherswitch/arswitch/arswitch_reg.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_reg.c	Sun Aug  7 01:29:55 2016	(r303809)
+++ head/sys/dev/etherswitch/arswitch/arswitch_reg.c	Sun Aug  7 01:32:37 2016	(r303810)
@@ -232,6 +232,8 @@ arswitch_modifyreg(device_t dev, int add
 	int value;
 	uint16_t phy, reg;
 
+	ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
+
 	arswitch_split_setpage(dev, addr, &phy, &reg);
 
 	value = arswitch_reg_read32(dev, 0x10 | phy, reg);
@@ -243,9 +245,12 @@ arswitch_modifyreg(device_t dev, int add
 int
 arswitch_waitreg(device_t dev, int addr, int mask, int val, int timeout)
 {
+	struct arswitch_softc *sc = device_get_softc(dev);
 	int err, v;
 	uint16_t phy, reg;
 
+	ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
+
 	arswitch_split_setpage(dev, addr, &phy, &reg);
 
 	err = -1;
@@ -261,5 +266,10 @@ arswitch_waitreg(device_t dev, int addr,
 		DELAY(1);
 		timeout--;
 	}
+	if (err != 0) {
+		DPRINTF(sc, ARSWITCH_DBG_ANY,
+		    "%s: waitreg failed; addr=0x%08x, mask=0x%08x, val=0x%08x\n",
+		    __func__, addr, mask, val);
+	}
 	return (err);
 }

Modified: head/sys/dev/etherswitch/arswitch/arswitchvar.h
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitchvar.h	Sun Aug  7 01:29:55 2016	(r303809)
+++ head/sys/dev/etherswitch/arswitch/arswitchvar.h	Sun Aug  7 01:32:37 2016	(r303810)
@@ -79,6 +79,8 @@ struct arswitch_softc {
 	struct callout	callout_tick;
 	etherswitch_info_t info;
 
+	uint32_t	sc_debug;
+
 	/* VLANs support */
 	int		vid[AR8X16_MAX_VLANS];
 	uint32_t	vlan_mode;
@@ -142,18 +144,27 @@ struct arswitch_softc {
 #define	ARSWITCH_TRYLOCK(_sc)			\
 	    mtx_trylock(&(_sc)->sc_mtx)
 
-#if defined(DEBUG)
-#define DPRINTF(dev, args...) device_printf(dev, args)
+#define	ARSWITCH_DBG_RESET		0x00000001
+#define	ARSWITCH_DBG_REGIO		0x00000002
+#define	ARSWITCH_DBG_PHYIO		0x00000004
+#define	ARSWITCH_DBG_POLL		0x00000008
+#define	ARSWITCH_DBG_VLAN		0x00000010
+#define	ARSWITCH_DBG_ANY		0xffffffff
+
+#if 1
+#define DPRINTF(sc, dbg, args...) \
+	do { \
+		if (((sc)->sc_debug & (dbg)) || \
+		    ((sc)->sc_debug == ARSWITCH_DBG_ANY)) { \
+			device_printf((sc)->sc_dev, args); 	\
+		} \
+	} while (0)
 #define DEVERR(dev, err, fmt, args...) do { \
 		if (err != 0) device_printf(dev, fmt, err, args); \
 	} while (0)
-#define DEBUG_INCRVAR(var)	do { \
-		var++; \
-	} while (0)
 #else
-#define DPRINTF(dev, args...)
+#define DPRINTF(dev, dbg, args...)
 #define DEVERR(dev, err, fmt, args...)
-#define DEBUG_INCRVAR(var)
 #endif
 
 #endif	/* __ARSWITCHVAR_H__ */


More information about the svn-src-all mailing list