public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4
@ 2026-04-08  5:58 Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 1/5] net: enetc: add support for the standardized counters Wei Fang
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

For ENETC v1, some standardized statistics were redundantly included in
the unstructured statistics, so remove these duplicated entries.
Previously, the unstructured statistics only contained eMAC data and
did not include pMAC data; add pMAC statistics to ensure completeness.

For ENETC v4, the driver previously reported MAC statistics only for the
internal ENETC (Pseudo MAC). Extend the implementation to provide
additional statistics for both the internal ENETC and the standalone
ENETC.

Wei Fang (5):
  net: enetc: add support for the standardized counters
  net: enetc: show RX drop counters only for assigned RX rings
  net: enetc: remove standardized counters from enetc_pm_counters
  net: enetc: add unstructured pMAC counters for ENETC v1
  net: enetc: add unstructured counters for ENETC v4

 drivers/net/ethernet/freescale/enetc/enetc.h  |   2 +
 .../net/ethernet/freescale/enetc/enetc4_hw.h  | 192 ++++++++
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 427 +++++++++++++-----
 3 files changed, 519 insertions(+), 102 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/5] net: enetc: add support for the standardized counters
  2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
@ 2026-04-08  5:58 ` Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 2/5] net: enetc: show RX drop counters only for assigned RX rings Wei Fang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

ENETC v4 provides 64-bit counters for IEEE 802.3 basic and mandatory
managed objects, the IETF Management Information Database (MIB) package
(RFC2665), and Remote Network Monitoring (RMON) statistics. In addition,
some ENETCs support preemption, so these ENETCs have two MACs: MAC 0 is
the express MAC (eMAC), MAC 1 is the preemptible MAC (pMAC). Both MACs
support these statistics.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc.h  |   2 +
 .../net/ethernet/freescale/enetc/enetc4_hw.h  | 120 +++++++++++++++
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 141 +++++++++++++++---
 3 files changed, 245 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index aecd40aeef9c..e663bb5e614e 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -264,6 +264,8 @@ struct enetc_msg_swbd {
 };
 
 #define ENETC_REV1	0x1
+#define ENETC_REV4	0x4
+
 enum enetc_errata {
 	ENETC_ERR_VLAN_ISOL	= BIT(0),
 	ENETC_ERR_UCMCSWP	= BIT(1),
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
index 719c88ceb801..392992a646fb 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
@@ -196,6 +196,126 @@
 #define  PM_SINGLE_STEP_OFFSET_SET(o)	FIELD_PREP(PM_SINGLE_STEP_OFFSET, o)
 #define  PM_SINGLE_STEP_EN		BIT(31)
 
+/* Port MAC 0/1 Receive Ethernet Octets Counter */
+#define ENETC4_PM_REOCT(mac)		(0x5100 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Alignment Error Counter Register */
+#define ENETC4_PM_RALN(mac)		(0x5110 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Valid Pause Frame Counter */
+#define ENETC4_PM_RXPF(mac)		(0x5118 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Frame Counter */
+#define ENETC4_PM_RFRM(mac)		(0x5120 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Frame Check Sequence Error Counter */
+#define ENETC4_PM_RFCS(mac)		(0x5128 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Multicast Frame Counter */
+#define ENETC4_PM_RMCA(mac)		(0x5148 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Broadcast Frame Counter */
+#define ENETC4_PM_RBCA(mac)		(0x5150 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Undersized Packet Counter */
+#define ENETC4_PM_RUND(mac)		(0x5168 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 64-Octet Packet Counter */
+#define ENETC4_PM_R64(mac)		(0x5170 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 65 to 127-Octet Packet Counter */
+#define ENETC4_PM_R127(mac)		(0x5178 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 128 to 255-Octet Packet Counter */
+#define ENETC4_PM_R255(mac)		(0x5180 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 256 to 511-Octet Packet Counter */
+#define ENETC4_PM_R511(mac)		(0x5188 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 512 to 1023-Octet Packet Counter */
+#define ENETC4_PM_R1023(mac)		(0x5190 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 1024 to 1522-Octet Packet Counter */
+#define ENETC4_PM_R1522(mac)		(0x5198 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive 1523 to Max-Octet Packet Counter */
+#define ENETC4_PM_R1523X(mac)		(0x51a0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Oversized Packet Counter */
+#define ENETC4_PM_ROVR(mac)		(0x51a8 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Jabber Packet Counter */
+#define ENETC4_PM_RJBR(mac)		(0x51b0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Fragment Packet Counter */
+#define ENETC4_PM_RFRG(mac)		(0x51b8 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Control Packet Counter */
+#define ENETC4_PM_RCNP(mac)		(0x51c0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Dropped Not Truncated Packets Counter */
+#define ENETC4_PM_RDRNTP(mac)		(0x51c8 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Ethernet Octets Counter */
+#define ENETC4_PM_TEOCT(mac)		(0x5200 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Valid Pause Frame Counter */
+#define ENETC4_PM_TXPF(mac)		(0x5218 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Frame Counter */
+#define ENETC4_PM_TFRM(mac)		(0x5220 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Frame Error Counter */
+#define ENETC4_PM_TERR(mac)		(0x5238 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Multicast Frame Counter */
+#define ENETC4_PM_TMCA(mac)		(0x5248 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Broadcast Frame Counter */
+#define ENETC4_PM_TBCA(mac)		(0x5250 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Undersized Packet Counter */
+#define ENETC4_PM_TUND(mac)		(0x5268 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 64-Octet Packet Counter */
+#define ENETC4_PM_T64(mac)		(0x5270 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 65 to 127-Octet Packet Counter */
+#define ENETC4_PM_T127(mac)		(0x5278 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 128 to 255-Octet Packet Counter */
+#define ENETC4_PM_T255(mac)		(0x5280 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 256 to 511-Octet Packet Counter */
+#define ENETC4_PM_T511(mac)		(0x5288 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 512 to 1023-Octet Packet Counter */
+#define ENETC4_PM_T1023(mac)		(0x5290 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 1024 to 1522-Octet Packet Counter */
+#define ENETC4_PM_T1522(mac)		(0x5298 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit 1523 to TX_MTU-Octet Packet Counter */
+#define ENETC4_PM_T1523X(mac)		(0x52a0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Control Packet Counter */
+#define ENETC4_PM_TCNP(mac)		(0x52c0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Deferred Packet Counter */
+#define ENETC4_PM_TDFR(mac)		(0x52d0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Multiple Collisions Counter */
+#define ENETC4_PM_TMCOL(mac)		(0x52d8 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Single Collision */
+#define ENETC4_PM_TSCOL(mac)		(0x52e0 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Late Collision Counter */
+#define ENETC4_PM_TLCOL(mac)		(0x52e8 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit Excessive Collisions Counter */
+#define ENETC4_PM_TECOL(mac)		(0x52f0 + (mac) * 0x400)
+
 /* Port MAC 0 Interface Mode Control Register */
 #define ENETC4_PM_IF_MODE(mac)		(0x5300 + (mac) * 0x400)
 #define  PM_IF_MODE_IFMODE		GENMASK(2, 0)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index 7c17acaf7a38..c30a119e9142 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -320,27 +320,38 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 		data[o++] = enetc_port_rd64(hw, enetc_pm_counters[i].reg);
 }
 
-static void enetc_pause_stats(struct enetc_hw *hw, int mac,
+static void enetc_pause_stats(struct enetc_si *si, int mac,
 			      struct ethtool_pause_stats *pause_stats)
 {
-	pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC_PM_TXPF(mac));
-	pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC_PM_RXPF(mac));
+	struct enetc_hw *hw = &si->hw;
+
+	switch (si->pdev->revision) {
+	case ENETC_REV1:
+		pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC_PM_TXPF(mac));
+		pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC_PM_RXPF(mac));
+		break;
+	case ENETC_REV4:
+		pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_TXPF(mac));
+		pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_RXPF(mac));
+		break;
+	default:
+		break;
+	}
 }
 
 static void enetc_get_pause_stats(struct net_device *ndev,
 				  struct ethtool_pause_stats *pause_stats)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
 	struct enetc_si *si = priv->si;
 
 	switch (pause_stats->src) {
 	case ETHTOOL_MAC_STATS_SRC_EMAC:
-		enetc_pause_stats(hw, 0, pause_stats);
+		enetc_pause_stats(si, 0, pause_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_PMAC:
 		if (si->hw_features & ENETC_SI_F_QBU)
-			enetc_pause_stats(hw, 1, pause_stats);
+			enetc_pause_stats(si, 1, pause_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
 		ethtool_aggregate_pause_stats(ndev, pause_stats);
@@ -371,11 +382,45 @@ static void enetc_mac_stats(struct enetc_hw *hw, int mac,
 	s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RBCA(mac));
 }
 
-static void enetc_ctrl_stats(struct enetc_hw *hw, int mac,
+static void enetc4_mac_stats(struct enetc_hw *hw, int mac,
+			     struct ethtool_eth_mac_stats *s)
+{
+	s->FramesTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TFRM(mac));
+	s->SingleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TSCOL(mac));
+	s->MultipleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TMCOL(mac));
+	s->FramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RFRM(mac));
+	s->FrameCheckSequenceErrors = enetc_port_rd64(hw, ENETC4_PM_RFCS(mac));
+	s->AlignmentErrors = enetc_port_rd64(hw, ENETC4_PM_RALN(mac));
+	s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TEOCT(mac));
+	s->FramesWithDeferredXmissions = enetc_port_rd64(hw, ENETC4_PM_TDFR(mac));
+	s->LateCollisions = enetc_port_rd64(hw, ENETC4_PM_TLCOL(mac));
+	s->FramesAbortedDueToXSColls = enetc_port_rd64(hw, ENETC4_PM_TECOL(mac));
+	s->FramesLostDueToIntMACXmitError = enetc_port_rd64(hw, ENETC4_PM_TERR(mac));
+	s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC4_PM_REOCT(mac));
+	s->FramesLostDueToIntMACRcvError = enetc_port_rd64(hw, ENETC4_PM_RDRNTP(mac));
+	s->MulticastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TMCA(mac));
+	s->BroadcastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TBCA(mac));
+	s->MulticastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RMCA(mac));
+	s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RBCA(mac));
+}
+
+static void enetc_ctrl_stats(struct enetc_si *si, int mac,
 			     struct ethtool_eth_ctrl_stats *s)
 {
-	s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC_PM_TCNP(mac));
-	s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC_PM_RCNP(mac));
+	struct enetc_hw *hw = &si->hw;
+
+	switch (si->pdev->revision) {
+	case ENETC_REV1:
+		s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC_PM_TCNP(mac));
+		s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC_PM_RCNP(mac));
+		break;
+	case ENETC_REV4:
+		s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC4_PM_TCNP(mac));
+		s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC4_PM_RCNP(mac));
+		break;
+	default:
+		break;
+	}
 }
 
 static const struct ethtool_rmon_hist_range enetc_rmon_ranges[] = {
@@ -414,20 +459,61 @@ static void enetc_rmon_stats(struct enetc_hw *hw, int mac,
 	s->hist_tx[6] = enetc_port_rd64(hw, ENETC_PM_T1523X(mac));
 }
 
+static void enetc4_rmon_stats(struct enetc_hw *hw, int mac,
+			      struct ethtool_rmon_stats *s)
+{
+	s->undersize_pkts = enetc_port_rd64(hw, ENETC4_PM_RUND(mac));
+	s->oversize_pkts = enetc_port_rd64(hw, ENETC4_PM_ROVR(mac));
+	s->fragments = enetc_port_rd64(hw, ENETC4_PM_RFRG(mac));
+	s->jabbers = enetc_port_rd64(hw, ENETC4_PM_RJBR(mac));
+
+	s->hist[0] = enetc_port_rd64(hw, ENETC4_PM_R64(mac));
+	s->hist[1] = enetc_port_rd64(hw, ENETC4_PM_R127(mac));
+	s->hist[2] = enetc_port_rd64(hw, ENETC4_PM_R255(mac));
+	s->hist[3] = enetc_port_rd64(hw, ENETC4_PM_R511(mac));
+	s->hist[4] = enetc_port_rd64(hw, ENETC4_PM_R1023(mac));
+	s->hist[5] = enetc_port_rd64(hw, ENETC4_PM_R1522(mac));
+	s->hist[6] = enetc_port_rd64(hw, ENETC4_PM_R1523X(mac));
+
+	s->hist_tx[0] = enetc_port_rd64(hw, ENETC4_PM_T64(mac));
+	s->hist_tx[1] = enetc_port_rd64(hw, ENETC4_PM_T127(mac));
+	s->hist_tx[2] = enetc_port_rd64(hw, ENETC4_PM_T255(mac));
+	s->hist_tx[3] = enetc_port_rd64(hw, ENETC4_PM_T511(mac));
+	s->hist_tx[4] = enetc_port_rd64(hw, ENETC4_PM_T1023(mac));
+	s->hist_tx[5] = enetc_port_rd64(hw, ENETC4_PM_T1522(mac));
+	s->hist_tx[6] = enetc_port_rd64(hw, ENETC4_PM_T1523X(mac));
+}
+
+static void enetc_get_mac_stats(struct enetc_si *si, int mac,
+				struct ethtool_eth_mac_stats *mac_stats)
+{
+	struct enetc_hw *hw = &si->hw;
+
+	switch (si->pdev->revision) {
+	case ENETC_REV1:
+		enetc_mac_stats(hw, mac, mac_stats);
+		break;
+	case ENETC_REV4:
+		enetc4_mac_stats(hw, mac, mac_stats);
+		break;
+	default:
+		break;
+	}
+}
+
 static void enetc_get_eth_mac_stats(struct net_device *ndev,
 				    struct ethtool_eth_mac_stats *mac_stats)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
 	struct enetc_si *si = priv->si;
 
 	switch (mac_stats->src) {
 	case ETHTOOL_MAC_STATS_SRC_EMAC:
-		enetc_mac_stats(hw, 0, mac_stats);
+		enetc_get_mac_stats(si, 0, mac_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_PMAC:
 		if (si->hw_features & ENETC_SI_F_QBU)
-			enetc_mac_stats(hw, 1, mac_stats);
+			enetc_get_mac_stats(si, 1, mac_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
 		ethtool_aggregate_mac_stats(ndev, mac_stats);
@@ -481,16 +567,15 @@ static void enetc_get_eth_ctrl_stats(struct net_device *ndev,
 				     struct ethtool_eth_ctrl_stats *ctrl_stats)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
 	struct enetc_si *si = priv->si;
 
 	switch (ctrl_stats->src) {
 	case ETHTOOL_MAC_STATS_SRC_EMAC:
-		enetc_ctrl_stats(hw, 0, ctrl_stats);
+		enetc_ctrl_stats(si, 0, ctrl_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_PMAC:
 		if (si->hw_features & ENETC_SI_F_QBU)
-			enetc_ctrl_stats(hw, 1, ctrl_stats);
+			enetc_ctrl_stats(si, 1, ctrl_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
 		ethtool_aggregate_ctrl_stats(ndev, ctrl_stats);
@@ -498,23 +583,39 @@ static void enetc_get_eth_ctrl_stats(struct net_device *ndev,
 	}
 }
 
+static void enetc_get_mac_rmon_stats(struct enetc_si *si, int mac,
+				     struct ethtool_rmon_stats *rmon_stats)
+{
+	struct enetc_hw *hw = &si->hw;
+
+	switch (si->pdev->revision) {
+	case ENETC_REV1:
+		enetc_rmon_stats(hw, mac, rmon_stats);
+		break;
+	case ENETC_REV4:
+		enetc4_rmon_stats(hw, mac, rmon_stats);
+		break;
+	default:
+		break;
+	}
+}
+
 static void enetc_get_rmon_stats(struct net_device *ndev,
 				 struct ethtool_rmon_stats *rmon_stats,
 				 const struct ethtool_rmon_hist_range **ranges)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
 	struct enetc_si *si = priv->si;
 
 	*ranges = enetc_rmon_ranges;
 
 	switch (rmon_stats->src) {
 	case ETHTOOL_MAC_STATS_SRC_EMAC:
-		enetc_rmon_stats(hw, 0, rmon_stats);
+		enetc_get_mac_rmon_stats(si, 0, rmon_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_PMAC:
 		if (si->hw_features & ENETC_SI_F_QBU)
-			enetc_rmon_stats(hw, 1, rmon_stats);
+			enetc_get_mac_rmon_stats(si, 1, rmon_stats);
 		break;
 	case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
 		ethtool_aggregate_rmon_stats(ndev, rmon_stats);
@@ -1398,6 +1499,10 @@ const struct ethtool_ops enetc4_pf_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES |
 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
+	.get_pause_stats = enetc_get_pause_stats,
+	.get_rmon_stats = enetc_get_rmon_stats,
+	.get_eth_ctrl_stats = enetc_get_eth_ctrl_stats,
+	.get_eth_mac_stats = enetc_get_eth_mac_stats,
 	.get_ringparam = enetc_get_ringparam,
 	.get_coalesce = enetc_get_coalesce,
 	.set_coalesce = enetc_set_coalesce,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/5] net: enetc: show RX drop counters only for assigned RX rings
  2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 1/5] net: enetc: add support for the standardized counters Wei Fang
@ 2026-04-08  5:58 ` Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 3/5] net: enetc: remove standardized counters from enetc_pm_counters Wei Fang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

For ENETC v1, each SI provides 16 RBDCR registers for RX ring drop
counters, but this does not imply that an SI actually owns 16 RX rings.
The ENETC hardware supports a total of 16 RX rings, which are assigned
to 3 SIs (1 PSI and 2 VSIs), so each SI is assigned fewer than 16 RX
rings.

The current implementation always reports 16 RX drop counters per SI,
leading to redundant output for SIs with fewer RX rings. Update the
logic to display drop counters only for the RX rings that are actually
assigned to the SI.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 .../ethernet/freescale/enetc/enetc_ethtool.c   | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index c30a119e9142..36d1a2b810c2 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -124,22 +124,6 @@ static const struct {
 	{ ENETC_SITFRM, "SI tx frames" },
 	{ ENETC_SITUCA, "SI tx u-cast frames" },
 	{ ENETC_SITMCA, "SI tx m-cast frames" },
-	{ ENETC_RBDCR(0), "Rx ring  0 discarded frames" },
-	{ ENETC_RBDCR(1), "Rx ring  1 discarded frames" },
-	{ ENETC_RBDCR(2), "Rx ring  2 discarded frames" },
-	{ ENETC_RBDCR(3), "Rx ring  3 discarded frames" },
-	{ ENETC_RBDCR(4), "Rx ring  4 discarded frames" },
-	{ ENETC_RBDCR(5), "Rx ring  5 discarded frames" },
-	{ ENETC_RBDCR(6), "Rx ring  6 discarded frames" },
-	{ ENETC_RBDCR(7), "Rx ring  7 discarded frames" },
-	{ ENETC_RBDCR(8), "Rx ring  8 discarded frames" },
-	{ ENETC_RBDCR(9), "Rx ring  9 discarded frames" },
-	{ ENETC_RBDCR(10), "Rx ring 10 discarded frames" },
-	{ ENETC_RBDCR(11), "Rx ring 11 discarded frames" },
-	{ ENETC_RBDCR(12), "Rx ring 12 discarded frames" },
-	{ ENETC_RBDCR(13), "Rx ring 13 discarded frames" },
-	{ ENETC_RBDCR(14), "Rx ring 14 discarded frames" },
-	{ ENETC_RBDCR(15), "Rx ring 15 discarded frames" },
 };
 
 static const struct {
@@ -224,6 +208,7 @@ static const char rx_ring_stats[][ETH_GSTRING_LEN] = {
 	"Rx ring %2d recycle failures",
 	"Rx ring %2d redirects",
 	"Rx ring %2d redirect failures",
+	"Rx ring %2d discarded frames",
 };
 
 static const char tx_ring_stats[][ETH_GSTRING_LEN] = {
@@ -308,6 +293,7 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 		data[o++] = priv->rx_ring[i]->stats.recycle_failures;
 		data[o++] = priv->rx_ring[i]->stats.xdp_redirect;
 		data[o++] = priv->rx_ring[i]->stats.xdp_redirect_failures;
+		data[o++] = enetc_rd(hw, ENETC_RBDCR(i));
 	}
 
 	if (!enetc_si_is_pf(priv->si))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 3/5] net: enetc: remove standardized counters from enetc_pm_counters
  2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 1/5] net: enetc: add support for the standardized counters Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 2/5] net: enetc: show RX drop counters only for assigned RX rings Wei Fang
@ 2026-04-08  5:58 ` Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 4/5] net: enetc: add unstructured pMAC counters for ENETC v1 Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 5/5] net: enetc: add unstructured counters for ENETC v4 Wei Fang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

The standardized counters are already exposed via the get_pause_stats(),
get_rmon_stats(), get_eth_ctrl_stats() and get_eth_mac_stats()
interfaces. Keeping the same counters in enetc_pm_counters results in
redundant output.

Remove these standardized counters from enetc_pm_counters and rely on
the existing statistics interfaces to report them.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 40 -------------------
 1 file changed, 40 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index 36d1a2b810c2..504def405489 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -130,57 +130,17 @@ static const struct {
 	int reg;
 	char name[ETH_GSTRING_LEN] __nonstring;
 } enetc_pm_counters[] = {
-	{ ENETC_PM_REOCT(0),	"MAC rx ethernet octets" },
-	{ ENETC_PM_RALN(0),	"MAC rx alignment errors" },
-	{ ENETC_PM_RXPF(0),	"MAC rx valid pause frames" },
-	{ ENETC_PM_RFRM(0),	"MAC rx valid frames" },
-	{ ENETC_PM_RFCS(0),	"MAC rx fcs errors" },
 	{ ENETC_PM_RVLAN(0),	"MAC rx VLAN frames" },
 	{ ENETC_PM_RERR(0),	"MAC rx frame errors" },
 	{ ENETC_PM_RUCA(0),	"MAC rx unicast frames" },
-	{ ENETC_PM_RMCA(0),	"MAC rx multicast frames" },
-	{ ENETC_PM_RBCA(0),	"MAC rx broadcast frames" },
 	{ ENETC_PM_RDRP(0),	"MAC rx dropped packets" },
 	{ ENETC_PM_RPKT(0),	"MAC rx packets" },
-	{ ENETC_PM_RUND(0),	"MAC rx undersized packets" },
-	{ ENETC_PM_R64(0),	"MAC rx 64 byte packets" },
-	{ ENETC_PM_R127(0),	"MAC rx 65-127 byte packets" },
-	{ ENETC_PM_R255(0),	"MAC rx 128-255 byte packets" },
-	{ ENETC_PM_R511(0),	"MAC rx 256-511 byte packets" },
-	{ ENETC_PM_R1023(0),	"MAC rx 512-1023 byte packets" },
-	{ ENETC_PM_R1522(0),	"MAC rx 1024-1522 byte packets" },
-	{ ENETC_PM_R1523X(0),	"MAC rx 1523 to max-octet packets" },
-	{ ENETC_PM_ROVR(0),	"MAC rx oversized packets" },
-	{ ENETC_PM_RJBR(0),	"MAC rx jabber packets" },
-	{ ENETC_PM_RFRG(0),	"MAC rx fragment packets" },
-	{ ENETC_PM_RCNP(0),	"MAC rx control packets" },
-	{ ENETC_PM_RDRNTP(0),	"MAC rx fifo drop" },
-	{ ENETC_PM_TEOCT(0),	"MAC tx ethernet octets" },
 	{ ENETC_PM_TOCT(0),	"MAC tx octets" },
-	{ ENETC_PM_TCRSE(0),	"MAC tx carrier sense errors" },
-	{ ENETC_PM_TXPF(0),	"MAC tx valid pause frames" },
-	{ ENETC_PM_TFRM(0),	"MAC tx frames" },
 	{ ENETC_PM_TFCS(0),	"MAC tx fcs errors" },
 	{ ENETC_PM_TVLAN(0),	"MAC tx VLAN frames" },
-	{ ENETC_PM_TERR(0),	"MAC tx frame errors" },
 	{ ENETC_PM_TUCA(0),	"MAC tx unicast frames" },
-	{ ENETC_PM_TMCA(0),	"MAC tx multicast frames" },
-	{ ENETC_PM_TBCA(0),	"MAC tx broadcast frames" },
 	{ ENETC_PM_TPKT(0),	"MAC tx packets" },
 	{ ENETC_PM_TUND(0),	"MAC tx undersized packets" },
-	{ ENETC_PM_T64(0),	"MAC tx 64 byte packets" },
-	{ ENETC_PM_T127(0),	"MAC tx 65-127 byte packets" },
-	{ ENETC_PM_T255(0),	"MAC tx 128-255 byte packets" },
-	{ ENETC_PM_T511(0),	"MAC tx 256-511 byte packets" },
-	{ ENETC_PM_T1023(0),	"MAC tx 512-1023 byte packets" },
-	{ ENETC_PM_T1522(0),	"MAC tx 1024-1522 byte packets" },
-	{ ENETC_PM_T1523X(0),	"MAC tx 1523 to max-octet packets" },
-	{ ENETC_PM_TCNP(0),	"MAC tx control packets" },
-	{ ENETC_PM_TDFR(0),	"MAC tx deferred packets" },
-	{ ENETC_PM_TMCOL(0),	"MAC tx multiple collisions" },
-	{ ENETC_PM_TSCOL(0),	"MAC tx single collisions" },
-	{ ENETC_PM_TLCOL(0),	"MAC tx late collisions" },
-	{ ENETC_PM_TECOL(0),	"MAC tx excessive collisions" },
 };
 
 static const struct {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 4/5] net: enetc: add unstructured pMAC counters for ENETC v1
  2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
                   ` (2 preceding siblings ...)
  2026-04-08  5:58 ` [PATCH net-next 3/5] net: enetc: remove standardized counters from enetc_pm_counters Wei Fang
@ 2026-04-08  5:58 ` Wei Fang
  2026-04-08  5:58 ` [PATCH net-next 5/5] net: enetc: add unstructured counters for ENETC v4 Wei Fang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

The ENETC v1 has two MACs (eMAC and pMAC) to support preemption. The
existing unstructured counters include the eMAC counters, but not the
pMAC counters. So add pMAC counters to improve statistical coverage.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 77 ++++++++++++++-----
 1 file changed, 56 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index 504def405489..bdc5916e4400 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -129,18 +129,35 @@ static const struct {
 static const struct {
 	int reg;
 	char name[ETH_GSTRING_LEN] __nonstring;
-} enetc_pm_counters[] = {
-	{ ENETC_PM_RVLAN(0),	"MAC rx VLAN frames" },
-	{ ENETC_PM_RERR(0),	"MAC rx frame errors" },
-	{ ENETC_PM_RUCA(0),	"MAC rx unicast frames" },
-	{ ENETC_PM_RDRP(0),	"MAC rx dropped packets" },
-	{ ENETC_PM_RPKT(0),	"MAC rx packets" },
-	{ ENETC_PM_TOCT(0),	"MAC tx octets" },
-	{ ENETC_PM_TFCS(0),	"MAC tx fcs errors" },
-	{ ENETC_PM_TVLAN(0),	"MAC tx VLAN frames" },
-	{ ENETC_PM_TUCA(0),	"MAC tx unicast frames" },
-	{ ENETC_PM_TPKT(0),	"MAC tx packets" },
-	{ ENETC_PM_TUND(0),	"MAC tx undersized packets" },
+} enetc_emac_counters[] = {
+	{ ENETC_PM_RVLAN(0),	"eMAC rx VLAN frames" },
+	{ ENETC_PM_RERR(0),	"eMAC rx frame errors" },
+	{ ENETC_PM_RUCA(0),	"eMAC rx unicast frames" },
+	{ ENETC_PM_RDRP(0),	"eMAC rx dropped packets" },
+	{ ENETC_PM_RPKT(0),	"eMAC rx packets" },
+	{ ENETC_PM_TOCT(0),	"eMAC tx octets" },
+	{ ENETC_PM_TFCS(0),	"eMAC tx fcs errors" },
+	{ ENETC_PM_TVLAN(0),	"eMAC tx VLAN frames" },
+	{ ENETC_PM_TUCA(0),	"eMAC tx unicast frames" },
+	{ ENETC_PM_TPKT(0),	"eMAC tx packets" },
+	{ ENETC_PM_TUND(0),	"eMAC tx undersized packets" },
+};
+
+static const struct {
+	int reg;
+	char name[ETH_GSTRING_LEN] __nonstring;
+} enetc_pmac_counters[] = {
+	{ ENETC_PM_RVLAN(1),	"pMAC rx VLAN frames" },
+	{ ENETC_PM_RERR(1),	"pMAC rx frame errors" },
+	{ ENETC_PM_RUCA(1),	"pMAC rx unicast frames" },
+	{ ENETC_PM_RDRP(1),	"pMAC rx dropped packets" },
+	{ ENETC_PM_RPKT(1),	"pMAC rx packets" },
+	{ ENETC_PM_TOCT(1),	"pMAC tx octets" },
+	{ ENETC_PM_TFCS(1),	"pMAC tx fcs errors" },
+	{ ENETC_PM_TVLAN(1),	"pMAC tx VLAN frames" },
+	{ ENETC_PM_TUCA(1),	"pMAC tx unicast frames" },
+	{ ENETC_PM_TPKT(1),	"pMAC tx packets" },
+	{ ENETC_PM_TUND(1),	"pMAC tx undersized packets" },
 };
 
 static const struct {
@@ -181,6 +198,7 @@ static const char tx_ring_stats[][ETH_GSTRING_LEN] = {
 static int enetc_get_sset_count(struct net_device *ndev, int sset)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	struct enetc_si *si = priv->si;
 	int len;
 
 	if (sset != ETH_SS_STATS)
@@ -190,11 +208,14 @@ static int enetc_get_sset_count(struct net_device *ndev, int sset)
 	      ARRAY_SIZE(tx_ring_stats) * priv->num_tx_rings +
 	      ARRAY_SIZE(rx_ring_stats) * priv->num_rx_rings;
 
-	if (!enetc_si_is_pf(priv->si))
+	if (!enetc_si_is_pf(si))
 		return len;
 
 	len += ARRAY_SIZE(enetc_port_counters);
-	len += ARRAY_SIZE(enetc_pm_counters);
+	len += ARRAY_SIZE(enetc_emac_counters);
+
+	if (si->hw_features & ENETC_SI_F_QBU)
+		len += ARRAY_SIZE(enetc_pmac_counters);
 
 	return len;
 }
@@ -202,6 +223,7 @@ static int enetc_get_sset_count(struct net_device *ndev, int sset)
 static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	struct enetc_si *si = priv->si;
 	int i, j;
 
 	switch (stringset) {
@@ -215,14 +237,20 @@ static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 			for (j = 0; j < ARRAY_SIZE(rx_ring_stats); j++)
 				ethtool_sprintf(&data, rx_ring_stats[j], i);
 
-		if (!enetc_si_is_pf(priv->si))
+		if (!enetc_si_is_pf(si))
 			break;
 
 		for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
 			ethtool_cpy(&data, enetc_port_counters[i].name);
 
-		for (i = 0; i < ARRAY_SIZE(enetc_pm_counters); i++)
-			ethtool_cpy(&data, enetc_pm_counters[i].name);
+		for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
+			ethtool_cpy(&data, enetc_emac_counters[i].name);
+
+		if (!(si->hw_features & ENETC_SI_F_QBU))
+			break;
+
+		for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
+			ethtool_cpy(&data, enetc_pmac_counters[i].name);
 
 		break;
 	}
@@ -232,7 +260,8 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 				    struct ethtool_stats *stats, u64 *data)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
+	struct enetc_si *si = priv->si;
+	struct enetc_hw *hw = &si->hw;
 	int i, o = 0;
 
 	for (i = 0; i < ARRAY_SIZE(enetc_si_counters); i++)
@@ -256,14 +285,20 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 		data[o++] = enetc_rd(hw, ENETC_RBDCR(i));
 	}
 
-	if (!enetc_si_is_pf(priv->si))
+	if (!enetc_si_is_pf(si))
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
 		data[o++] = enetc_port_rd(hw, enetc_port_counters[i].reg);
 
-	for (i = 0; i < ARRAY_SIZE(enetc_pm_counters); i++)
-		data[o++] = enetc_port_rd64(hw, enetc_pm_counters[i].reg);
+	for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
+		data[o++] = enetc_port_rd64(hw, enetc_emac_counters[i].reg);
+
+	if (!(si->hw_features & ENETC_SI_F_QBU))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
+		data[o++] = enetc_port_rd64(hw, enetc_pmac_counters[i].reg);
 }
 
 static void enetc_pause_stats(struct enetc_si *si, int mac,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 5/5] net: enetc: add unstructured counters for ENETC v4
  2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
                   ` (3 preceding siblings ...)
  2026-04-08  5:58 ` [PATCH net-next 4/5] net: enetc: add unstructured pMAC counters for ENETC v1 Wei Fang
@ 2026-04-08  5:58 ` Wei Fang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Fang @ 2026-04-08  5:58 UTC (permalink / raw)
  To: claudiu.manoil, vladimir.oltean, xiaoning.wang, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, imx

Like ENETC v1, ENETC v4 also has many non-standard counters, so these
counters are added to improve statistical coverage.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |  72 +++++++
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 187 +++++++++++++++---
 2 files changed, 234 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
index 392992a646fb..f18437556a0e 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
@@ -64,6 +64,9 @@
 #define ENETC4_PPAUONTR			0x108
 #define ENETC4_PPAUOFFTR		0x10c
 
+/* Port ingress congestion DRa (a=0,1,2,3) discard count register */
+#define ENETC4_PICDRDCR(a)		((a) * 0x10 + 0x140)
+
 /* Port Station interface promiscuous MAC mode register */
 #define ENETC4_PSIPMMR			0x200
 #define  PSIPMMR_SI_MAC_UP(a)		BIT(a) /* a = SI index */
@@ -72,6 +75,12 @@
 /* Port Station interface promiscuous VLAN mode register */
 #define ENETC4_PSIPVMR			0x204
 
+/* Port broadcast frames dropped due to MAC filtering register */
+#define ENETC4_PBFDSIR			0x208
+
+/* Port frame drop MAC source address pruning register */
+#define ENETC4_PFDMSAPR			0x20c
+
 /* Port RSS key register n. n = 0,1,2,...,9 */
 #define ENETC4_PRSSKR(n)		((n) * 0x4 + 0x250)
 
@@ -79,6 +88,12 @@
 #define ENETC4_PSIMAFCAPR		0x280
 #define  PSIMAFCAPR_NUM_MAC_AFTE	GENMASK(11, 0)
 
+/* Port unicast frames dropped due to MAC filtering register */
+#define ENETC4_PUFDMFR			0x284
+
+/* Port multicast frames dropped due to MAC filtering register */
+#define ENETC4_PMFDMFR			0x288
+
 /* Port station interface VLAN filtering capability register */
 #define ENETC4_PSIVLANFCAPR		0x2c0
 #define  PSIVLANFCAPR_NUM_VLAN_FTE	GENMASK(11, 0)
@@ -87,6 +102,15 @@
 #define ENETC4_PSIVLANFMR		0x2c4
 #define  PSIVLANFMR_VS			BIT(0)
 
+/* Port unicast frames dropped VLAN filtering register */
+#define ENETC4_PUFDVFR			0x2d0
+
+/* Port multicast frames dropped VLAN filtering register */
+#define ENETC4_PMFDVFR			0x2d4
+
+/* Port broadcast frames dropped VLAN filtering register */
+#define ENETC4_PBFDVFR			0x2d8
+
 /* Port Station interface a primary MAC address registers */
 #define ENETC4_PSIPMAR0(a)		((a) * 0x80 + 0x2000)
 #define ENETC4_PSIPMAR1(a)		((a) * 0x80 + 0x2004)
@@ -141,6 +165,18 @@
 #define ENETC4_PSR			0x4104
 #define  PSR_RX_BUSY			BIT(1)
 
+/* Port Rx discard count register */
+#define ENETC4_PRXDCR			0x41c0
+
+/* Port Rx discard count read-reset register */
+#define ENETC4_PRXDCRRR			0x41c4
+
+/* Port Rx discard count reason register 0 */
+#define ENETC4_PRXDCRR0			0x41c8
+
+/* Port Rx discard count reason register 1 */
+#define ENETC4_PRXDCRR1			0x41cc
+
 /* Port traffic class a transmit maximum SDU register */
 #define ENETC4_PTCTMSDUR(a)		((a) * 0x20 + 0x4208)
 #define  PTCTMSDUR_MAXSDU		GENMASK(15, 0)
@@ -199,6 +235,9 @@
 /* Port MAC 0/1 Receive Ethernet Octets Counter */
 #define ENETC4_PM_REOCT(mac)		(0x5100 + (mac) * 0x400)
 
+/* Port MAC 0/1 Receive Octets Counter */
+#define ENETC4_PM_ROCT(mac)		(0x5108 + (mac) * 0x400)
+
 /* Port MAC 0/1 Receive Alignment Error Counter Register */
 #define ENETC4_PM_RALN(mac)		(0x5110 + (mac) * 0x400)
 
@@ -211,12 +250,27 @@
 /* Port MAC 0/1 Receive Frame Check Sequence Error Counter */
 #define ENETC4_PM_RFCS(mac)		(0x5128 + (mac) * 0x400)
 
+/* Port MAC 0/1 Receive VLAN Frame Counter */
+#define ENETC4_PM_RVLAN(mac)		(0x5130 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Frame Error Counter */
+#define ENETC4_PM_RERR(mac)		(0x5138 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Unicast Frame Counter */
+#define ENETC4_PM_RUCA(mac)		(0x5140 + (mac) * 0x400)
+
 /* Port MAC 0/1 Receive Multicast Frame Counter */
 #define ENETC4_PM_RMCA(mac)		(0x5148 + (mac) * 0x400)
 
 /* Port MAC 0/1 Receive Broadcast Frame Counter */
 #define ENETC4_PM_RBCA(mac)		(0x5150 + (mac) * 0x400)
 
+/* Port MAC 0/1 Receive Dropped Packets Counter */
+#define ENETC4_PM_RDRP(mac)		(0x5158 + (mac) * 0x400)
+
+/* Port MAC 0/1 Receive Packets Counter */
+#define ENETC4_PM_RPKT(mac)		(0x5160 + (mac) * 0x400)
+
 /* Port MAC 0/1 Receive Undersized Packet Counter */
 #define ENETC4_PM_RUND(mac)		(0x5168 + (mac) * 0x400)
 
@@ -259,21 +313,36 @@
 /* Port MAC 0/1 Transmit Ethernet Octets Counter */
 #define ENETC4_PM_TEOCT(mac)		(0x5200 + (mac) * 0x400)
 
+/* Port MAC 0/1 Transmit Octets Counter */
+#define ENETC4_PM_TOCT(mac)		(0x5208 + (mac) * 0x400)
+
 /* Port MAC 0/1 Transmit Valid Pause Frame Counter */
 #define ENETC4_PM_TXPF(mac)		(0x5218 + (mac) * 0x400)
 
 /* Port MAC 0/1 Transmit Frame Counter */
 #define ENETC4_PM_TFRM(mac)		(0x5220 + (mac) * 0x400)
 
+/* Port MAC 0/1 Transmit Frame Check Sequence Error Counter */
+#define ENETC4_PM_TFCS(mac)		(0x5228 + (mac) * 0x400)
+
+/* Port MAC 0/1 Transmit VLAN Frame Counter */
+#define ENETC4_PM_TVLAN(mac)		(0x5230 + (mac) * 0x400)
+
 /* Port MAC 0/1 Transmit Frame Error Counter */
 #define ENETC4_PM_TERR(mac)		(0x5238 + (mac) * 0x400)
 
+/* Port MAC 0/1 Transmit Unicast Frame Counter */
+#define ENETC4_PM_TUCA(mac)		(0x5240 + (mac) * 0x400)
+
 /* Port MAC 0/1 Transmit Multicast Frame Counter */
 #define ENETC4_PM_TMCA(mac)		(0x5248 + (mac) * 0x400)
 
 /* Port MAC 0/1 Transmit Broadcast Frame Counter */
 #define ENETC4_PM_TBCA(mac)		(0x5250 + (mac) * 0x400)
 
+/* Port MAC 0/1 Transmit Packets Counter */
+#define ENETC4_PM_TPKT(mac)		(0x5260 + (mac) * 0x400)
+
 /* Port MAC 0/1 Transmit Undersized Packet Counter */
 #define ENETC4_PM_TUND(mac)		(0x5268 + (mac) * 0x400)
 
@@ -316,6 +385,9 @@
 /* Port MAC 0/1 Transmit Excessive Collisions Counter */
 #define ENETC4_PM_TECOL(mac)		(0x52f0 + (mac) * 0x400)
 
+/* Port MAC 0/1 Transmit Invalid Octets Counter */
+#define ENETC4_PM_TIOCT(mac)		(0x52f8 + (mac) * 0x400)
+
 /* Port MAC 0 Interface Mode Control Register */
 #define ENETC4_PM_IF_MODE(mac)		(0x5300 + (mac) * 0x400)
 #define  PM_IF_MODE_IFMODE		GENMASK(2, 0)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index bdc5916e4400..71f376ef1be1 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -177,6 +177,65 @@ static const struct {
 	{ ENETC_PICDR(3),	"ICM DR3 discarded frames" },
 };
 
+static const struct {
+	int reg;
+	char name[ETH_GSTRING_LEN] __nonstring;
+} enetc4_emac_counters[] = {
+	{ ENETC4_PM_ROCT(0),	"eMAC rx octets" },
+	{ ENETC4_PM_RVLAN(0),	"eMAC rx VLAN frames" },
+	{ ENETC4_PM_RERR(0),	"eMAC rx frame errors" },
+	{ ENETC4_PM_RUCA(0),	"eMAC rx unicast frames" },
+	{ ENETC4_PM_RDRP(0),	"eMAC rx dropped packets" },
+	{ ENETC4_PM_RPKT(0),	"eMAC rx packets" },
+	{ ENETC4_PM_TOCT(0),	"eMAC tx octets" },
+	{ ENETC4_PM_TVLAN(0),	"eMAC tx VLAN frames" },
+	{ ENETC4_PM_TFCS(0),	"eMAC tx fcs errors" },
+	{ ENETC4_PM_TUCA(0),	"eMAC tx unicast frames" },
+	{ ENETC4_PM_TPKT(0),	"eMAC tx packets" },
+	{ ENETC4_PM_TUND(0),	"eMAC tx undersized packets" },
+	{ ENETC4_PM_TIOCT(0),	"eMAC tx invalid octets" },
+};
+
+static const struct {
+	int reg;
+	char name[ETH_GSTRING_LEN] __nonstring;
+} enetc4_pmac_counters[] = {
+	{ ENETC4_PM_ROCT(1),	"pMAC rx octets" },
+	{ ENETC4_PM_RVLAN(1),	"pMAC rx VLAN frames" },
+	{ ENETC4_PM_RERR(1),	"pMAC rx frame errors" },
+	{ ENETC4_PM_RUCA(1),	"pMAC rx unicast frames" },
+	{ ENETC4_PM_RDRP(1),	"pMAC rx dropped packets" },
+	{ ENETC4_PM_RPKT(1),	"pMAC rx packets" },
+	{ ENETC4_PM_TOCT(1),	"pMAC tx octets" },
+	{ ENETC4_PM_TVLAN(1),	"pMAC tx VLAN frames" },
+	{ ENETC4_PM_TFCS(1),	"pMAC tx fcs errors" },
+	{ ENETC4_PM_TUCA(1),	"pMAC tx unicast frames" },
+	{ ENETC4_PM_TPKT(1),	"pMAC tx packets" },
+	{ ENETC4_PM_TUND(1),	"pMAC tx undersized packets" },
+	{ ENETC4_PM_TIOCT(1),	"pMAC tx invalid octets" },
+};
+
+static const struct {
+	int reg;
+	char name[ETH_GSTRING_LEN] __nonstring;
+} enetc4_port_counters[] = {
+	{ ENETC4_PICDRDCR(0),	"ICM DR0 discarded frames" },
+	{ ENETC4_PICDRDCR(1),	"ICM DR1 discarded frames" },
+	{ ENETC4_PICDRDCR(2),	"ICM DR2 discarded frames" },
+	{ ENETC4_PICDRDCR(3),	"ICM DR3 discarded frames" },
+	{ ENETC4_PUFDMFR,	"MAC filter discarded unicast" },
+	{ ENETC4_PMFDMFR,	"MAC filter discarded multicast" },
+	{ ENETC4_PBFDSIR,	"MAC filter discarded broadcast" },
+	{ ENETC4_PFDMSAPR,	"MAC SA pruning discarded frames" },
+	{ ENETC4_PUFDVFR,	"VLAN filter discarded unicast" },
+	{ ENETC4_PMFDVFR,	"VLAN filter discarded multicast" },
+	{ ENETC4_PBFDVFR,	"VLAN filter discarded broadcast" },
+	{ ENETC4_PRXDCR,	"MAC rx discarded frames" },
+	{ ENETC4_PRXDCRRR,	"MAC rx discard read-reset" },
+	{ ENETC4_PRXDCRR0,	"MAC rx discard reason 0" },
+	{ ENETC4_PRXDCRR1,	"MAC rx discard reason 1" },
+};
+
 static const char rx_ring_stats[][ETH_GSTRING_LEN] = {
 	"Rx ring %2d frames",
 	"Rx ring %2d alloc errors",
@@ -211,15 +270,62 @@ static int enetc_get_sset_count(struct net_device *ndev, int sset)
 	if (!enetc_si_is_pf(si))
 		return len;
 
-	len += ARRAY_SIZE(enetc_port_counters);
-	len += ARRAY_SIZE(enetc_emac_counters);
+	if (is_enetc_rev1(si)) {
+		len += ARRAY_SIZE(enetc_port_counters);
+		len += ARRAY_SIZE(enetc_emac_counters);
+		if (si->hw_features & ENETC_SI_F_QBU)
+			len += ARRAY_SIZE(enetc_pmac_counters);
+	} else {
+		len += ARRAY_SIZE(enetc4_port_counters);
 
-	if (si->hw_features & ENETC_SI_F_QBU)
-		len += ARRAY_SIZE(enetc_pmac_counters);
+		if (enetc_is_pseudo_mac(si))
+			return len;
+
+		len += ARRAY_SIZE(enetc4_emac_counters);
+		if (si->hw_features & ENETC_SI_F_QBU)
+			len += ARRAY_SIZE(enetc4_pmac_counters);
+	}
 
 	return len;
 }
 
+static void enetc_get_pf_strings(struct enetc_si *si, u8 *data)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
+		ethtool_cpy(&data, enetc_port_counters[i].name);
+
+	for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
+		ethtool_cpy(&data, enetc_emac_counters[i].name);
+
+	if (!(si->hw_features & ENETC_SI_F_QBU))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
+		ethtool_cpy(&data, enetc_pmac_counters[i].name);
+}
+
+static void enetc4_get_pf_strings(struct enetc_si *si, u8 *data)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++)
+		ethtool_cpy(&data, enetc4_port_counters[i].name);
+
+	if (enetc_is_pseudo_mac(si))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++)
+		ethtool_cpy(&data, enetc4_emac_counters[i].name);
+
+	if (!(si->hw_features & ENETC_SI_F_QBU))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++)
+		ethtool_cpy(&data, enetc4_pmac_counters[i].name);
+}
+
 static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
@@ -240,20 +346,52 @@ static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 		if (!enetc_si_is_pf(si))
 			break;
 
-		for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
-			ethtool_cpy(&data, enetc_port_counters[i].name);
+		if (is_enetc_rev1(si))
+			enetc_get_pf_strings(si, data);
+		else
+			enetc4_get_pf_strings(si, data);
 
-		for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
-			ethtool_cpy(&data, enetc_emac_counters[i].name);
+		break;
+	}
+}
 
-		if (!(si->hw_features & ENETC_SI_F_QBU))
-			break;
+static void enetc_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data)
+{
+	struct enetc_hw *hw = &si->hw;
+	int i;
 
-		for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
-			ethtool_cpy(&data, enetc_pmac_counters[i].name);
+	for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
+		data[(*o)++] = enetc_port_rd(hw, enetc_port_counters[i].reg);
 
-		break;
-	}
+	for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
+		data[(*o)++] = enetc_port_rd64(hw, enetc_emac_counters[i].reg);
+
+	if (!(si->hw_features & ENETC_SI_F_QBU))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
+		data[(*o)++] = enetc_port_rd64(hw, enetc_pmac_counters[i].reg);
+}
+
+static void enetc4_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data)
+{
+	struct enetc_hw *hw = &si->hw;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++)
+		data[(*o)++] = enetc_port_rd(hw, enetc4_port_counters[i].reg);
+
+	if (enetc_is_pseudo_mac(si))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++)
+		data[(*o)++] = enetc_port_rd64(hw, enetc4_emac_counters[i].reg);
+
+	if (!(si->hw_features & ENETC_SI_F_QBU))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++)
+		data[(*o)++] = enetc_port_rd64(hw, enetc4_pmac_counters[i].reg);
 }
 
 static void enetc_get_ethtool_stats(struct net_device *ndev,
@@ -288,17 +426,10 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 	if (!enetc_si_is_pf(si))
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
-		data[o++] = enetc_port_rd(hw, enetc_port_counters[i].reg);
-
-	for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
-		data[o++] = enetc_port_rd64(hw, enetc_emac_counters[i].reg);
-
-	if (!(si->hw_features & ENETC_SI_F_QBU))
-		return;
-
-	for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
-		data[o++] = enetc_port_rd64(hw, enetc_pmac_counters[i].reg);
+	if (is_enetc_rev1(si))
+		enetc_pf_get_ethtool_stats(si, &o, data);
+	else
+		enetc4_pf_get_ethtool_stats(si, &o, data);
 }
 
 static void enetc_pause_stats(struct enetc_si *si, int mac,
@@ -1438,6 +1569,9 @@ const struct ethtool_ops enetc4_ppm_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES |
 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
+	.get_sset_count = enetc_get_sset_count,
+	.get_strings = enetc_get_strings,
+	.get_ethtool_stats = enetc_get_ethtool_stats,
 	.get_eth_mac_stats = enetc_ppm_get_eth_mac_stats,
 	.get_rx_ring_count = enetc_get_rx_ring_count,
 	.get_rxfh_key_size = enetc_get_rxfh_key_size,
@@ -1480,6 +1614,9 @@ const struct ethtool_ops enetc4_pf_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES |
 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
+	.get_sset_count = enetc_get_sset_count,
+	.get_strings = enetc_get_strings,
+	.get_ethtool_stats = enetc_get_ethtool_stats,
 	.get_pause_stats = enetc_get_pause_stats,
 	.get_rmon_stats = enetc_get_rmon_stats,
 	.get_eth_ctrl_stats = enetc_get_eth_ctrl_stats,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-08  6:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-08  5:58 [PATCH net-next 0/5] net: enetc: improve statistics for v1 and add statistics for v4 Wei Fang
2026-04-08  5:58 ` [PATCH net-next 1/5] net: enetc: add support for the standardized counters Wei Fang
2026-04-08  5:58 ` [PATCH net-next 2/5] net: enetc: show RX drop counters only for assigned RX rings Wei Fang
2026-04-08  5:58 ` [PATCH net-next 3/5] net: enetc: remove standardized counters from enetc_pm_counters Wei Fang
2026-04-08  5:58 ` [PATCH net-next 4/5] net: enetc: add unstructured pMAC counters for ENETC v1 Wei Fang
2026-04-08  5:58 ` [PATCH net-next 5/5] net: enetc: add unstructured counters for ENETC v4 Wei Fang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox