Skip to content

Commit 88c810f

Browse files
AnsuelPaolo Abeni
authored andcommitted
net: dsa: mt7530: implement .get_stats64
It was reported that the internally calculated counter might differ from the real one from the Switch MIB. This can happen if the switch directly forward packets between the ports or offload small packets like ARP request. In such case, the kernel counter will desync compared to the real one transmitted and received by the Switch. To correctly provide the real info to the kernel, implement .get_stats64 that will directly read the current MIB counter from the switch register. Signed-off-by: Christian Marangi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent c3b904c commit 88c810f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

drivers/net/dsa/mt7530.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,51 @@ static void mt7530_get_rmon_stats(struct dsa_switch *ds, int port,
906906
*ranges = mt7530_rmon_ranges;
907907
}
908908

909+
static void mt7530_get_stats64(struct dsa_switch *ds, int port,
910+
struct rtnl_link_stats64 *storage)
911+
{
912+
struct mt7530_priv *priv = ds->priv;
913+
uint64_t data;
914+
915+
/* MIB counter doesn't provide a FramesTransmittedOK but instead
916+
* provide stats for Unicast, Broadcast and Multicast frames separately.
917+
* To simulate a global frame counter, read Unicast and addition Multicast
918+
* and Broadcast later
919+
*/
920+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_UNICAST, 1,
921+
&storage->rx_packets);
922+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_MULTICAST, 1,
923+
&storage->multicast);
924+
storage->rx_packets += storage->multicast;
925+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_BROADCAST, 1,
926+
&data);
927+
storage->rx_packets += data;
928+
929+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_TX_UNICAST, 1,
930+
&storage->tx_packets);
931+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_TX_MULTICAST, 1,
932+
&data);
933+
storage->tx_packets += data;
934+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_TX_BROADCAST, 1,
935+
&data);
936+
storage->tx_packets += data;
937+
938+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_BYTES, 2,
939+
&storage->rx_bytes);
940+
941+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_TX_BYTES, 2,
942+
&storage->tx_bytes);
943+
944+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_DROP, 1,
945+
&storage->rx_dropped);
946+
947+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_TX_DROP, 1,
948+
&storage->tx_dropped);
949+
950+
mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_CRC_ERR, 1,
951+
&storage->rx_crc_errors);
952+
}
953+
909954
static void mt7530_get_eth_ctrl_stats(struct dsa_switch *ds, int port,
910955
struct ethtool_eth_ctrl_stats *ctrl_stats)
911956
{
@@ -3207,6 +3252,7 @@ const struct dsa_switch_ops mt7530_switch_ops = {
32073252
.get_eth_mac_stats = mt7530_get_eth_mac_stats,
32083253
.get_rmon_stats = mt7530_get_rmon_stats,
32093254
.get_eth_ctrl_stats = mt7530_get_eth_ctrl_stats,
3255+
.get_stats64 = mt7530_get_stats64,
32103256
.set_ageing_time = mt7530_set_ageing_time,
32113257
.port_enable = mt7530_port_enable,
32123258
.port_disable = mt7530_port_disable,

0 commit comments

Comments
 (0)