[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220322195455.703921-8-prasanna.vengateshan@microchip.com>
Date: Wed, 23 Mar 2022 01:24:52 +0530
From: Prasanna Vengateshan <prasanna.vengateshan@...rochip.com>
To: <andrew@...n.ch>, <netdev@...r.kernel.org>, <olteanv@...il.com>,
<robh+dt@...nel.org>
CC: <UNGLinuxDriver@...rochip.com>, <woojung.huh@...rochip.com>,
<hkallweit1@...il.com>, <linux@...linux.org.uk>,
<davem@...emloft.net>, <kuba@...nel.org>,
<linux-kernel@...r.kernel.org>, <vivien.didelot@...il.com>,
<f.fainelli@...il.com>, <devicetree@...r.kernel.org>,
<pabeni@...hat.com>
Subject: [PATCH v10 net-next 07/10] net: dsa: microchip: add support for ethtool port counters
Added support for get_eth_**_stats() (phy/mac/ctrl) and
get_stats64()
Reused the KSZ common APIs for get_ethtool_stats() & get_sset_count()
along with relevant lan937x hooks for KSZ common layer and added
support for get_strings()
Signed-off-by: Prasanna Vengateshan <prasanna.vengateshan@...rochip.com>
Reviewed-by: Florian Fainelli <f.fainelli@...il.com>
---
drivers/net/dsa/microchip/lan937x_main.c | 118 +++++++++++++++++++++++
1 file changed, 118 insertions(+)
diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c
index c7b7b9b373d7..51640234dda6 100644
--- a/drivers/net/dsa/microchip/lan937x_main.c
+++ b/drivers/net/dsa/microchip/lan937x_main.c
@@ -45,6 +45,20 @@ static int lan937x_phy_write16(struct dsa_switch *ds, int addr, int reg,
return lan937x_internal_phy_write(dev, addr, reg, val);
}
+static void lan937x_get_strings(struct dsa_switch *ds, int port, u32 stringset,
+ u8 *buf)
+{
+ struct ksz_device *dev = ds->priv;
+ int i;
+
+ if (stringset != ETH_SS_STATS)
+ return;
+
+ for (i = 0; i < dev->mib_cnt; i++)
+ memcpy(buf + i * ETH_GSTRING_LEN, lan937x_mib_names[i].string,
+ ETH_GSTRING_LEN);
+}
+
static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,
u8 state)
{
@@ -357,12 +371,116 @@ static void lan937x_phylink_get_caps(struct dsa_switch *ds, int port,
}
}
+static void lan937x_get_eth_phy_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_device *dev = ds->priv;
+ struct ksz_port_mib *mib = &dev->ports[port].mib;
+ u64 *cnt;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[lan937x_mib_rx_sym_err];
+ lan937x_r_mib_pkt(dev, port, lan937x_mib_rx_sym_err, NULL, cnt);
+
+ phy_stats->SymbolErrorDuringCarrier = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
+static void lan937x_get_eth_mac_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_mac_stats *mac_stats)
+{
+ struct ksz_device *dev = ds->priv;
+ struct ksz_port_mib *mib = &dev->ports[port].mib;
+ u64 *ctr = mib->counters;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ while (mib->cnt_ptr < dev->mib_cnt) {
+ lan937x_r_mib_pkt(dev, port, mib->cnt_ptr,
+ NULL, &mib->counters[mib->cnt_ptr]);
+ ++mib->cnt_ptr;
+ }
+
+ mac_stats->FramesTransmittedOK = ctr[lan937x_mib_tx_mcast] +
+ ctr[lan937x_mib_tx_bcast] +
+ ctr[lan937x_mib_tx_ucast] +
+ ctr[lan937x_mib_tx_pause];
+
+ mac_stats->SingleCollisionFrames = ctr[lan937x_mib_tx_single_col];
+ mac_stats->MultipleCollisionFrames = ctr[lan937x_mib_tx_mult_col];
+
+ mac_stats->FramesReceivedOK = ctr[lan937x_mib_rx_mcast] +
+ ctr[lan937x_mib_rx_bcast] +
+ ctr[lan937x_mib_rx_ucast] +
+ ctr[lan937x_mib_rx_pause];
+
+ mac_stats->FrameCheckSequenceErrors = ctr[lan937x_mib_rx_crc_err];
+ mac_stats->AlignmentErrors = ctr[lan937x_mib_rx_align_err];
+ mac_stats->OctetsTransmittedOK = ctr[lan937x_mib_tx_total];
+ mac_stats->FramesWithDeferredXmissions = ctr[lan937x_mib_tx_deferred];
+ mac_stats->LateCollisions = ctr[lan937x_mib_tx_late_col];
+ mac_stats->FramesAbortedDueToXSColls = ctr[lan937x_mib_tx_exc_col];
+ mac_stats->FramesLostDueToIntMACXmitError = ctr[lan937x_mib_tx_discard];
+
+ mac_stats->OctetsReceivedOK = ctr[lan937x_mib_rx_total];
+ mac_stats->FramesLostDueToIntMACRcvError = ctr[lan937x_mib_rx_discard];
+ mac_stats->MulticastFramesXmittedOK = ctr[lan937x_mib_tx_mcast];
+ mac_stats->BroadcastFramesXmittedOK = ctr[lan937x_mib_tx_bcast];
+
+ mac_stats->MulticastFramesReceivedOK = ctr[lan937x_mib_rx_mcast];
+ mac_stats->BroadcastFramesReceivedOK = ctr[lan937x_mib_rx_bcast];
+ mac_stats->InRangeLengthErrors = ctr[lan937x_mib_rx_fragments];
+
+ mib->cnt_ptr = 0;
+ mutex_unlock(&mib->cnt_mutex);
+}
+
+static void lan937x_get_eth_ctrl_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_sts)
+{
+ struct ksz_device *dev = ds->priv;
+ struct ksz_port_mib *mib = &dev->ports[port].mib;
+ u64 *cnt;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[lan937x_mib_rx_pause];
+ lan937x_r_mib_pkt(dev, port, lan937x_mib_rx_pause, NULL, cnt);
+ ctrl_sts->MACControlFramesReceived = *cnt;
+
+ cnt = &mib->counters[lan937x_mib_tx_pause];
+ lan937x_r_mib_pkt(dev, port, lan937x_mib_tx_pause, NULL, cnt);
+ ctrl_sts->MACControlFramesTransmitted = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
+static void lan937x_get_stats64(struct dsa_switch *ds, int port,
+ struct rtnl_link_stats64 *s)
+{
+ struct ksz_device *dev = ds->priv;
+ struct ksz_port_mib *mib = &dev->ports[port].mib;
+
+ spin_lock(&mib->stats64_lock);
+ memcpy(s, &mib->stats64, sizeof(*s));
+ spin_unlock(&mib->stats64_lock);
+}
+
const struct dsa_switch_ops lan937x_switch_ops = {
.get_tag_protocol = lan937x_get_tag_protocol,
.setup = lan937x_setup,
.phy_read = lan937x_phy_read16,
.phy_write = lan937x_phy_write16,
.port_enable = ksz_enable_port,
+ .get_strings = lan937x_get_strings,
+ .get_ethtool_stats = ksz_get_ethtool_stats,
+ .get_sset_count = ksz_sset_count,
+ .get_eth_ctrl_stats = lan937x_get_eth_ctrl_stats,
+ .get_eth_mac_stats = lan937x_get_eth_mac_stats,
+ .get_eth_phy_stats = lan937x_get_eth_phy_stats,
+ .get_stats64 = lan937x_get_stats64,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
.port_stp_state_set = lan937x_port_stp_state_set,
--
2.30.2
Powered by blists - more mailing lists