[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.
This commit is contained in:
parent
c7b25f3512
commit
90a75924ee
@ -73,10 +73,6 @@
|
|||||||
#include "miibus_if.h"
|
#include "miibus_if.h"
|
||||||
#include "etherswitch_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 */
|
/* Map ETHERSWITCH_PORT_LED_* to Atheros pattern codes */
|
||||||
static int led_pattern_table[] = {
|
static int led_pattern_table[] = {
|
||||||
[ETHERSWITCH_PORT_LED_DEFAULT] = 0x3,
|
[ETHERSWITCH_PORT_LED_DEFAULT] = 0x3,
|
||||||
@ -156,7 +152,7 @@ arswitch_probe(device_t dev)
|
|||||||
|
|
||||||
done:
|
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) {
|
if (chipname != NULL) {
|
||||||
snprintf(desc, sizeof(desc),
|
snprintf(desc, sizeof(desc),
|
||||||
"Atheros %s Ethernet Switch (ver %d rev %d)",
|
"Atheros %s Ethernet Switch (ver %d rev %d)",
|
||||||
@ -309,12 +305,12 @@ ar8xxx_atu_flush(struct arswitch_softc *sc)
|
|||||||
static int
|
static int
|
||||||
arswitch_attach(device_t dev)
|
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 err = 0;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
sc = device_get_softc(dev);
|
|
||||||
|
|
||||||
/* sc->sc_switchtype is already decided in arswitch_probe() */
|
/* sc->sc_switchtype is already decided in arswitch_probe() */
|
||||||
sc->sc_dev = dev;
|
sc->sc_dev = dev;
|
||||||
mtx_init(&sc->sc_mtx, "arswitch", NULL, MTX_DEF);
|
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),
|
strlcpy(sc->info.es_name, device_get_desc(dev),
|
||||||
sizeof(sc->info.es_name));
|
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 */
|
/* Default HAL methods */
|
||||||
sc->hal.arswitch_port_init = ar8xxx_port_init;
|
sc->hal.arswitch_port_init = ar8xxx_port_init;
|
||||||
sc->hal.arswitch_port_vlan_setup = ar8xxx_port_vlan_setup;
|
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))
|
else if (AR8X16_IS_SWITCH(sc, AR8327))
|
||||||
ar8327_attach(sc);
|
ar8327_attach(sc);
|
||||||
else {
|
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);
|
return (ENXIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,19 +397,24 @@ arswitch_attach(device_t dev)
|
|||||||
|
|
||||||
/* Reset the switch. */
|
/* Reset the switch. */
|
||||||
if (arswitch_reset(dev)) {
|
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);
|
return (ENXIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sc->hal.arswitch_hw_setup(sc);
|
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);
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
err = sc->hal.arswitch_hw_global_setup(sc);
|
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);
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the switch ports. */
|
/* Initialize the switch ports. */
|
||||||
for (port = 0; port <= sc->numphys; port++) {
|
for (port = 0; port <= sc->numphys; port++) {
|
||||||
@ -416,22 +425,28 @@ arswitch_attach(device_t dev)
|
|||||||
* Attach the PHYs and complete the bus enumeration.
|
* Attach the PHYs and complete the bus enumeration.
|
||||||
*/
|
*/
|
||||||
err = arswitch_attach_phys(sc);
|
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);
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
/* Default to ingress filters off. */
|
/* Default to ingress filters off. */
|
||||||
err = arswitch_set_vlan_mode(sc, 0);
|
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);
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
bus_generic_probe(dev);
|
bus_generic_probe(dev);
|
||||||
bus_enumerate_hinted_children(dev);
|
bus_enumerate_hinted_children(dev);
|
||||||
err = bus_generic_attach(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);
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
|
callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
|
||||||
|
|
||||||
@ -560,10 +575,11 @@ arswitch_miipollstat(struct arswitch_softc *sc)
|
|||||||
else
|
else
|
||||||
portstatus = arswitch_readreg(sc->sc_dev,
|
portstatus = arswitch_readreg(sc->sc_dev,
|
||||||
AR8X16_REG_PORT_STS(arswitch_portforphy(i)));
|
AR8X16_REG_PORT_STS(arswitch_portforphy(i)));
|
||||||
#if 0
|
#if 1
|
||||||
DPRINTF(sc->sc_dev, "p[%d]=%b\n",
|
DPRINTF(sc, ARSWITCH_DBG_POLL, "p[%d]=0x%08x (%b)\n",
|
||||||
i,
|
i,
|
||||||
portstatus,
|
portstatus,
|
||||||
|
portstatus,
|
||||||
"\20\3TXMAC\4RXMAC\5TXFLOW\6RXFLOW\7"
|
"\20\3TXMAC\4RXMAC\5TXFLOW\6RXFLOW\7"
|
||||||
"DUPLEX\11LINK_UP\12LINK_AUTO\13LINK_PAUSE");
|
"DUPLEX\11LINK_UP\12LINK_AUTO\13LINK_PAUSE");
|
||||||
#endif
|
#endif
|
||||||
@ -845,8 +861,9 @@ arswitch_setled(struct arswitch_softc *sc, int phy, int led, int style)
|
|||||||
static void
|
static void
|
||||||
arswitch_statchg(device_t dev)
|
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
|
static int
|
||||||
@ -867,7 +884,7 @@ arswitch_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
|||||||
struct arswitch_softc *sc = ifp->if_softc;
|
struct arswitch_softc *sc = ifp->if_softc;
|
||||||
struct mii_data *mii = arswitch_miiforport(sc, ifp->if_dunit);
|
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)
|
if (mii == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -1086,7 +1086,7 @@ ar8327_get_dot1q_vlan(struct arswitch_softc *sc, uint32_t *ports,
|
|||||||
}
|
}
|
||||||
|
|
||||||
reg = arswitch_readreg(sc->sc_dev, AR8327_REG_VTU_FUNC0);
|
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.
|
* If any of the bits are set, update the port mask.
|
||||||
@ -1118,7 +1118,7 @@ ar8327_set_dot1q_vlan(struct arswitch_softc *sc, uint32_t ports,
|
|||||||
op = AR8327_VTU_FUNC1_OP_LOAD;
|
op = AR8327_VTU_FUNC1_OP_LOAD;
|
||||||
vid &= 0xfff;
|
vid &= 0xfff;
|
||||||
|
|
||||||
DPRINTF(sc->sc_dev,
|
DPRINTF(sc, ARSWITCH_DBG_VLAN,
|
||||||
"%s: vid: %d, ports=0x%08x, untagged_ports=0x%08x\n",
|
"%s: vid: %d, ports=0x%08x, untagged_ports=0x%08x\n",
|
||||||
__func__,
|
__func__,
|
||||||
vid,
|
vid,
|
||||||
|
@ -62,10 +62,6 @@
|
|||||||
#include "miibus_if.h"
|
#include "miibus_if.h"
|
||||||
#include "etherswitch_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
|
* Access PHYs integrated into the switch by going direct
|
||||||
* to the PHY space itself, rather than through the switch
|
* to the PHY space itself, rather than through the switch
|
||||||
@ -81,6 +77,9 @@ arswitch_readphy_external(device_t dev, int phy, int reg)
|
|||||||
|
|
||||||
ARSWITCH_LOCK(sc);
|
ARSWITCH_LOCK(sc);
|
||||||
ret = (MDIO_READREG(device_get_parent(dev), phy, reg));
|
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);
|
ARSWITCH_UNLOCK(sc);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
@ -96,6 +95,9 @@ arswitch_writephy_external(device_t dev, int phy, int reg, int data)
|
|||||||
ARSWITCH_LOCK(sc);
|
ARSWITCH_LOCK(sc);
|
||||||
(void) MDIO_WRITEREG(device_get_parent(dev), phy,
|
(void) MDIO_WRITEREG(device_get_parent(dev), phy,
|
||||||
reg, data);
|
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);
|
ARSWITCH_UNLOCK(sc);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@ -141,7 +143,9 @@ arswitch_readphy_internal(device_t dev, int phy, int reg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (timeout < 0) {
|
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;
|
goto fail;
|
||||||
}
|
}
|
||||||
data = arswitch_readreg_lsb(dev, a) &
|
data = arswitch_readreg_lsb(dev, a) &
|
||||||
|
@ -232,6 +232,8 @@ arswitch_modifyreg(device_t dev, int addr, int mask, int set)
|
|||||||
int value;
|
int value;
|
||||||
uint16_t phy, reg;
|
uint16_t phy, reg;
|
||||||
|
|
||||||
|
ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
|
||||||
|
|
||||||
arswitch_split_setpage(dev, addr, &phy, ®);
|
arswitch_split_setpage(dev, addr, &phy, ®);
|
||||||
|
|
||||||
value = arswitch_reg_read32(dev, 0x10 | phy, reg);
|
value = arswitch_reg_read32(dev, 0x10 | phy, reg);
|
||||||
@ -243,9 +245,12 @@ arswitch_modifyreg(device_t dev, int addr, int mask, int set)
|
|||||||
int
|
int
|
||||||
arswitch_waitreg(device_t dev, int addr, int mask, int val, int timeout)
|
arswitch_waitreg(device_t dev, int addr, int mask, int val, int timeout)
|
||||||
{
|
{
|
||||||
|
struct arswitch_softc *sc = device_get_softc(dev);
|
||||||
int err, v;
|
int err, v;
|
||||||
uint16_t phy, reg;
|
uint16_t phy, reg;
|
||||||
|
|
||||||
|
ARSWITCH_LOCK_ASSERT(sc, MA_OWNED);
|
||||||
|
|
||||||
arswitch_split_setpage(dev, addr, &phy, ®);
|
arswitch_split_setpage(dev, addr, &phy, ®);
|
||||||
|
|
||||||
err = -1;
|
err = -1;
|
||||||
@ -261,5 +266,10 @@ arswitch_waitreg(device_t dev, int addr, int mask, int val, int timeout)
|
|||||||
DELAY(1);
|
DELAY(1);
|
||||||
timeout--;
|
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);
|
return (err);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ struct arswitch_softc {
|
|||||||
struct callout callout_tick;
|
struct callout callout_tick;
|
||||||
etherswitch_info_t info;
|
etherswitch_info_t info;
|
||||||
|
|
||||||
|
uint32_t sc_debug;
|
||||||
|
|
||||||
/* VLANs support */
|
/* VLANs support */
|
||||||
int vid[AR8X16_MAX_VLANS];
|
int vid[AR8X16_MAX_VLANS];
|
||||||
uint32_t vlan_mode;
|
uint32_t vlan_mode;
|
||||||
@ -142,18 +144,27 @@ struct arswitch_softc {
|
|||||||
#define ARSWITCH_TRYLOCK(_sc) \
|
#define ARSWITCH_TRYLOCK(_sc) \
|
||||||
mtx_trylock(&(_sc)->sc_mtx)
|
mtx_trylock(&(_sc)->sc_mtx)
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#define ARSWITCH_DBG_RESET 0x00000001
|
||||||
#define DPRINTF(dev, args...) device_printf(dev, args)
|
#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 { \
|
#define DEVERR(dev, err, fmt, args...) do { \
|
||||||
if (err != 0) device_printf(dev, fmt, err, args); \
|
if (err != 0) device_printf(dev, fmt, err, args); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define DEBUG_INCRVAR(var) do { \
|
|
||||||
var++; \
|
|
||||||
} while (0)
|
|
||||||
#else
|
#else
|
||||||
#define DPRINTF(dev, args...)
|
#define DPRINTF(dev, dbg, args...)
|
||||||
#define DEVERR(dev, err, fmt, args...)
|
#define DEVERR(dev, err, fmt, args...)
|
||||||
#define DEBUG_INCRVAR(var)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __ARSWITCHVAR_H__ */
|
#endif /* __ARSWITCHVAR_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user