net: dsa: Provide CPU port statistics to master netdev
Subsystems (3)
PATCH 1/1 net: dsa: Provide CPU port statistics to master netdev
This patch overloads the DSA master netdev, aka CPU Ethernet MAC to also include switch-side statistics, which is useful for debugging purposes, when the switch is not properly connected to the Ethernet MAC (duplex mismatch, (RG)MII electrical issues etc.).
We accomplish this by retaining the original copy of the master netdev's ethtool_ops, and just overload the 3 operations we care about:get_sset_count, get_strings and get_ethtool_stats so as to intercept these calls and call into the original master_netdev ethtool_ops, plus our own.
We take this approach as opposed to providing a set of DSA helper functions that would retrive the CPU port's statistics, because the entire purpose of DSA is to allow unmodified Ethernet MAC drivers to be used as CPU conduit interfaces, therefore, statistics overlay in such drivers would simply not scale.
The new ethtool -S <iface> output would therefore look like this now:
<iface> statistics
p<2 digits cpu port number>_<switch MIB counter names>
---
Changes from RFC:
- prepend the CPU port as a prefix to make it clear what the stats are about, master netdev interface stats are unchanged
include/net/dsa.h | 5 ++++ net/dsa/slave.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)
include/net/dsa.h +5 -0
@@ -111,6 +111,11 @@ struct dsa_switch_tree {enum dsa_tag_protocol tag_protocol;/* +* Original copy of the master netdev ethtool_ops +*/ +struct ethtool_ops master_ethtool_ops; + +/* * The switch and port to which the CPU is attached. */ s8 cpu_switch;
net/dsa/slave.c +88 -0
112 lines not on this page · raw message
Signature · 1 line
2.1.0
Andrew Lunn
maintainernet/dsa/slave.c static void dsa_slave_get_strings(struct net_device *dev, · line 736
Quoted 12 lines
net/dsa/slave.c +12
-0+if (stringset ==ETH_SS_STATS && ds->drv->get_strings) { + ndata = data + mcount * len; +/* This function copies ETH_GSTRINGS_LEN bytes, we will mangle +* the output after to prepend our CPU port prefix we +* constructed earlier +*/ + ds->drv->get_strings (ds, cpu_port, ndata); + count = ds->drv->get_sset_count (ds); +for (i =0 ; i < count; i++) { +memmove (ndata + (i * len +sizeof (pfx)), + ndata + i * len, len -sizeof (pfx)); +memcpy (ndata + i * len, pfx,sizeof (pfx));
Hi Florian
Did you check what happens if this causes the NULL terminator to be discarded? Does ethtool handle that? As i said before, it is unclear if one is required.
Andrew
Quoted 15 lines · Andrew Lunn
net/dsa/slave.c static void dsa_slave_get_strings(struct net_device *dev, · line 736
Quoted 12 lines
net/dsa/slave.c +12
-0+if (stringset ==ETH_SS_STATS && ds->drv->get_strings) { + ndata = data + mcount * len; +/* This function copies ETH_GSTRINGS_LEN bytes, we will mangle +* the output after to prepend our CPU port prefix we +* constructed earlier +*/ + ds->drv->get_strings (ds, cpu_port, ndata); + count = ds->drv->get_sset_count (ds); +for (i =0 ; i < count; i++) { +memmove (ndata + (i * len +sizeof (pfx)), + ndata + i * len, len -sizeof (pfx)); +memcpy (ndata + i * len, pfx,sizeof (pfx));Hi Florian
Quoted 3 lines
Did you check what happens if this causes the NULL terminator to be discarded? Does ethtool handle that? As i said before, it is unclear if one is required.
I just did yes. So ethtool has a do_gstringset() function which NULL-terminates every strings set except the statistics kind (ETH_SS_STATS or ETH_SS_PHY_STATS) but this is not much of a problem because it limits the output to ETH_GSTRING_LEN anyway.
After injecting a bit of error in net/dsa/slave.c to have a much bigger prefix making us push the stats names, the stats are correcty truncated by ethtool. So we seem to be good to go with the current code in kernel and user space.
Signature · 1 line
Florian
From: Florian Fainelli <[email protected]>
Date: Wed, 27 Apr 2016 11:45:14 -0700
Quoted 17 lines
This patch overloads the DSA master netdev, aka CPU Ethernet MAC to also include switch-side statistics, which is useful for debugging purposes, when the switch is not properly connected to the Ethernet MAC (duplex mismatch, (RG)MII electrical issues etc.).
We accomplish this by retaining the original copy of the master netdev's
ethtool_ops, and just overload the 3 operations we care about:get_sset_count,get_stringsandget_ethtool_statsso as to intercept these calls and call into the originalmaster_netdevethtool_ops, plus our own.We take this approach as opposed to providing a set of DSA helper functions that would retrive the CPU port's statistics, because the entire purpose of DSA is to allow unmodified Ethernet MAC drivers to be used as CPU conduit interfaces, therefore, statistics overlay in such drivers would simply not scale.
Quoted 5 lines
The new ethtool -S <iface> output would therefore look like this now:
<iface> statistics
p<2 digits cpu port number>_<switch MIB counter names>Signed-off-by Florian Fainelli <[email protected]>
Applied, thanks Florian.