From: Thibaut VARENE Date: Fri, 4 Aug 2017 10:29:52 +0000 (+0200) Subject: generic: provide get_port_stats() on rtl836x switches X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0369e358916ef092a1644334f5dd1412051b68a4;p=openwrt%2Fstaging%2Fblocktrron.git generic: provide get_port_stats() on rtl836x 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/rtl8366_smi.c b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c index b8cdf30de4..ae045970db 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c @@ -1030,6 +1030,33 @@ int rtl8366_sw_get_port_mib(struct switch_dev *dev, } EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_mib); +int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats, + int txb_id, int rxb_id) +{ + struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev); + unsigned long long counter = 0; + int ret; + + if (port >= smi->num_ports) + return -EINVAL; + + ret = smi->ops->get_mib_counter(smi, txb_id, port, &counter); + if (ret) + return ret; + + stats->tx_bytes = counter; + + ret = smi->ops->get_mib_counter(smi, rxb_id, port, &counter); + if (ret) + return ret; + + stats->rx_bytes = counter; + + return 0; +} +EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_stats); + int rtl8366_sw_get_vlan_info(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val) diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h index bd41385bed..4bb9e9a66e 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h @@ -146,6 +146,9 @@ int rtl8366_sw_get_vlan_enable(struct switch_dev *dev, int rtl8366_sw_set_vlan_enable(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val); +int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats, + int txb_id, int rxb_id); struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev); diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c index 264343a81f..dc394c02b6 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c @@ -205,6 +205,9 @@ #define RTL8366RB_QOS_DEFAULT_PREIFG 1 +#define RTL8366RB_MIB_RXB_ID 0 /* IfInOctets */ +#define RTL8366RB_MIB_TXB_ID 20 /* IfOutOctets */ + static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = { { 0, 0, 4, "IfInOctets" }, { 0, 4, 4, "EtherStatsOctets" }, @@ -1146,6 +1149,13 @@ static int rtl8366rb_sw_reset_port_mibs(struct switch_dev *dev, RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan)); } +static int rtl8366rb_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + return (rtl8366_sw_get_port_stats(dev, port, stats, + RTL8366RB_MIB_TXB_ID, RTL8366RB_MIB_RXB_ID)); +} + static struct switch_attr rtl8366rb_globals[] = { { .type = SWITCH_TYPE_INT, @@ -1317,6 +1327,7 @@ static const struct switch_dev_ops rtl8366_ops = { .set_port_pvid = rtl8366_sw_set_port_pvid, .reset_switch = rtl8366_sw_reset_switch, .get_port_link = rtl8366rb_sw_get_port_link, + .get_port_stats = rtl8366rb_sw_get_port_stats, }; static int rtl8366rb_switch_init(struct rtl8366_smi *smi) diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366s.c b/target/linux/generic/files/drivers/net/phy/rtl8366s.c index 1c8a106b10..3f458f9dec 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366s.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8366s.c @@ -181,6 +181,9 @@ #define RTL8366S_VLAN_FID_SHIFT 12 #define RTL8366S_VLAN_FID_MASK 0x7 +#define RTL8366S_MIB_RXB_ID 0 /* IfInOctets */ +#define RTL8366S_MIB_TXB_ID 20 /* IfOutOctets */ + static struct rtl8366_mib_counter rtl8366s_mib_counters[] = { { 0, 0, 4, "IfInOctets" }, { 0, 4, 4, "EtherStatsOctets" }, @@ -982,6 +985,13 @@ static int rtl8366s_sw_reset_port_mibs(struct switch_dev *dev, 0, (1 << (val->port_vlan + 3))); } +static int rtl8366s_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + return (rtl8366_sw_get_port_stats(dev, port, stats, + RTL8366S_MIB_TXB_ID, RTL8366S_MIB_RXB_ID)); +} + static struct switch_attr rtl8366s_globals[] = { { .type = SWITCH_TYPE_INT, @@ -1105,6 +1115,7 @@ static const struct switch_dev_ops rtl8366_ops = { .set_port_pvid = rtl8366_sw_set_port_pvid, .reset_switch = rtl8366_sw_reset_switch, .get_port_link = rtl8366s_sw_get_port_link, + .get_port_stats = rtl8366s_sw_get_port_stats, }; static int rtl8366s_switch_init(struct rtl8366_smi *smi) diff --git a/target/linux/generic/files/drivers/net/phy/rtl8367.c b/target/linux/generic/files/drivers/net/phy/rtl8367.c index 97cd1acfb5..9549961d76 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8367.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8367.c @@ -253,6 +253,9 @@ struct rtl8367_initval { u16 val; }; +#define RTL8367_MIB_RXB_ID 0 /* IfInOctets */ +#define RTL8367_MIB_TXB_ID 20 /* IfOutOctets */ + static struct rtl8366_mib_counter rtl8367_mib_counters[] = { { 0, 0, 4, "IfInOctets" }, { 0, 4, 2, "Dot3StatsFCSErrors" }, @@ -1535,6 +1538,13 @@ static int rtl8367_sw_reset_port_mibs(struct switch_dev *dev, RTL8367_MIB_CTRL_PORT_RESET_MASK(port % 8)); } +static int rtl8367_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + return (rtl8366_sw_get_port_stats(dev, port, stats, + RTL8367_MIB_TXB_ID, RTL8367_MIB_RXB_ID)); +} + static struct switch_attr rtl8367_globals[] = { { .type = SWITCH_TYPE_INT, @@ -1622,6 +1632,7 @@ static const struct switch_dev_ops rtl8367_sw_ops = { .set_port_pvid = rtl8366_sw_set_port_pvid, .reset_switch = rtl8366_sw_reset_switch, .get_port_link = rtl8367_sw_get_port_link, + .get_port_stats = rtl8367_sw_get_port_stats, }; static int rtl8367_switch_init(struct rtl8366_smi *smi) diff --git a/target/linux/generic/files/drivers/net/phy/rtl8367b.c b/target/linux/generic/files/drivers/net/phy/rtl8367b.c index a73e35ed2d..dbf440a00c 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8367b.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8367b.c @@ -235,6 +235,9 @@ struct rtl8367b_initval { u16 val; }; +#define RTL8367B_MIB_RXB_ID 0 /* IfInOctets */ +#define RTL8367B_MIB_TXB_ID 28 /* IfOutOctets */ + static struct rtl8366_mib_counter rtl8367b_mib_counters[RTL8367B_NUM_MIB_COUNTERS] = { {0, 0, 4, "ifInOctets" }, @@ -1302,6 +1305,13 @@ static int rtl8367b_sw_reset_port_mibs(struct switch_dev *dev, RTL8367B_MIB_CTRL0_PORT_RESET_MASK(port % 8)); } +static int rtl8367b_sw_get_port_stats(struct switch_dev *dev, int port, + struct switch_port_stats *stats) +{ + return (rtl8366_sw_get_port_stats(dev, port, stats, + RTL8367B_MIB_TXB_ID, RTL8367B_MIB_RXB_ID)); +} + static struct switch_attr rtl8367b_globals[] = { { .type = SWITCH_TYPE_INT, @@ -1382,6 +1392,7 @@ static const struct switch_dev_ops rtl8367b_sw_ops = { .set_port_pvid = rtl8366_sw_set_port_pvid, .reset_switch = rtl8366_sw_reset_switch, .get_port_link = rtl8367b_sw_get_port_link, + .get_port_stats = rtl8367b_sw_get_port_stats, }; static int rtl8367b_switch_init(struct rtl8366_smi *smi)