generic: provide get_port_stats() on rtl836x switches
authorThibaut VARENE <hacks@slashdirt.org>
Fri, 4 Aug 2017 10:29:52 +0000 (12:29 +0200)
committerJohn Crispin <john@phrozen.org>
Fri, 1 Sep 2017 07:30:35 +0000 (09:30 +0200)
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 <hacks@slashdirt.org>
target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic/files/drivers/net/phy/rtl8366rb.c
target/linux/generic/files/drivers/net/phy/rtl8366s.c
target/linux/generic/files/drivers/net/phy/rtl8367.c
target/linux/generic/files/drivers/net/phy/rtl8367b.c

index b8cdf30de48c8b94ec54fa78819fb093830e6650..ae045970dbb3eaf851aad1a8890c97dfb76cdfd0 100644 (file)
@@ -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)
index bd41385bed1a57f270fa3d270c72d6747cb8b7a4..4bb9e9a66eea93426f7f60c71b76b051e9774d8c 100644 (file)
@@ -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);
 
index 264343a81f701964aeef39be8a63a6bfe53f6a55..dc394c02b6660cfc2fc419b70c534e0a6365d734 100644 (file)
 #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)
index 1c8a106b104ed21f9e1b1fbcce21f725eb2ff22f..3f458f9dec91e9ef9fe732d5e9728270e6b72ab1 100644 (file)
 #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)
index 97cd1acfb51428f89c68969982b7fa4320abd8ed..9549961d767589789abedafd5b2d932c0e340273 100644 (file)
@@ -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)
index a73e35ed2d1c88c281dc3fdd823312abf783d844..dbf440a00ccc09664bfbac7abd63f3569ef884af 100644 (file)
@@ -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)