[RFC Patch net-next 4/5] net: dsa: microchip: add eth phy grouping for ethtool statistics

From: Rakesh Sankaranarayanan
Date: Wed Nov 30 2022 - 08:30:41 EST


Add support for ethtool standard device statistics grouping. Support
ethernet phy statistics grouping using eth-phy groups parameter in
ethtool command.

Signed-off-by: Rakesh Sankaranarayanan <rakesh.sankaranarayanan@xxxxxxxxxxxxx>
---
drivers/net/dsa/microchip/ksz_common.c | 13 +++++++++
drivers/net/dsa/microchip/ksz_common.h | 2 ++
drivers/net/dsa/microchip/ksz_ethtool.c | 36 +++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 5 ++++
4 files changed, 56 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index ceb3c4f120bd..0f3925d0c668 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -161,6 +161,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.get_rmon_stats = ksz8_get_rmon_stats,
.get_eth_ctrl_stats = ksz8_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz8_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz8_get_eth_phy_stats,
.fdb_dump = ksz8_fdb_dump,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
@@ -201,6 +202,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz9477_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz9477_get_eth_phy_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -240,6 +242,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz9477_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz9477_get_eth_phy_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -1647,6 +1650,15 @@ static void ksz_get_eth_mac_stats(struct dsa_switch *ds, int port,
dev->dev_ops->get_eth_mac_stats(dev, port, mac_stats);
}

+static void ksz_get_eth_phy_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_device *dev = ds->priv;
+
+ if (dev->dev_ops->get_eth_phy_stats)
+ dev->dev_ops->get_eth_phy_stats(dev, port, phy_stats);
+}
+
static void ksz_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *buf)
{
@@ -2900,6 +2912,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.get_rmon_stats = ksz_get_rmon_stats,
.get_eth_ctrl_stats = ksz_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz_get_eth_phy_stats,
.port_change_mtu = ksz_change_mtu,
.port_max_mtu = ksz_max_mtu,
};
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 5b77f98483a9..c253d761b62b 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -346,6 +346,8 @@ struct ksz_dev_ops {
struct ethtool_eth_ctrl_stats *ctrl_stats);
void (*get_eth_mac_stats)(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+ void (*get_eth_phy_stats)(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);
};

struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
index 96529fea8e84..5061c503437a 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.c
+++ b/drivers/net/dsa/microchip/ksz_ethtool.c
@@ -203,6 +203,24 @@ void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
mutex_unlock(&mib->cnt_mutex);
}

+void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz8_rx_symbol_err];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_symbol_err, NULL, cnt);
+
+ phy_stats->SymbolErrorDuringCarrier = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges)
@@ -306,3 +324,21 @@ void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,

mutex_unlock(&mib->cnt_mutex);
}
+
+void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz9477_rx_symbol_err];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_symbol_err, NULL, cnt);
+
+ phy_stats->SymbolErrorDuringCarrier = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/microchip/ksz_ethtool.h
index 2dcfe8922b4e..042a0b38a899 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.h
+++ b/drivers/net/dsa/microchip/ksz_ethtool.h
@@ -15,6 +15,8 @@ void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);

void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
@@ -23,4 +25,7 @@ void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);
+
#endif
--
2.34.1