From: Thibaut VARENE Date: Fri, 4 Aug 2017 10:28:56 +0000 (+0200) Subject: generic: provide get_port_stats() on adm6996 switches X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=4ddbc43cc15c2fa128a2f169964ef7eb508cf2c5;p=openwrt%2Fstaging%2Faparcar.git generic: provide get_port_stats() on adm6996 switches This patch provides a generic switch_dev_ops 'get_port_stats()' callback by taping into the relevant port MIB counters. This callback is used by swconfig_leds led trigger to blink LEDs with port network traffic. Signed-off-by: Thibaut VARENE --- diff --git a/target/linux/generic/files/drivers/net/phy/adm6996.c b/target/linux/generic/files/drivers/net/phy/adm6996.c index d9ea828929..42928bab07 100644 --- a/target/linux/generic/files/drivers/net/phy/adm6996.c +++ b/target/linux/generic/files/drivers/net/phy/adm6996.c @@ -112,6 +112,9 @@ static const struct adm6996_mib_desc adm6996_mibs[] = { MIB_DESC(ADM_CL30, "Error"), }; +#define ADM6996_MIB_RXB_ID 1 +#define ADM6996_MIB_TXB_ID 3 + static inline u16 r16(struct adm6996_priv *priv, enum admreg reg) { @@ -888,6 +891,34 @@ adm6996_sw_get_port_mib(struct switch_dev *dev, return 0; } +static int +adm6996_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + struct adm6996_priv *priv = to_adm(dev); + int id; + u32 reg = 0; + + if (port >= ADM_NUM_PORTS) + return -EINVAL; + + mutex_lock(&priv->mib_lock); + + id = ADM6996_MIB_TXB_ID; + reg = r16(priv, adm6996_mibs[id].offset + ADM_OFFSET_PORT(port)); + reg += r16(priv, adm6996_mibs[id].offset + ADM_OFFSET_PORT(port) + 1) << 16; + stats->tx_bytes = reg; + + id = ADM6996_MIB_RXB_ID; + reg = r16(priv, adm6996_mibs[id].offset + ADM_OFFSET_PORT(port)); + reg += r16(priv, adm6996_mibs[id].offset + ADM_OFFSET_PORT(port) + 1) << 16; + stats->rx_bytes = reg; + + mutex_unlock(&priv->mib_lock); + + return 0; +} + static struct switch_attr adm6996_globals[] = { { .type = SWITCH_TYPE_INT, @@ -956,6 +987,7 @@ static struct switch_dev_ops adm6996_ops = { .apply_config = adm6996_hw_apply, .reset_switch = adm6996_reset_switch, .get_port_link = adm6996_get_port_link, + .get_port_stats = adm6996_get_port_stats, }; static int adm6996_switch_init(struct adm6996_priv *priv, const char *alias, struct net_device *netdev)