* [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics
@ 2026-03-23 11:50 Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 1/3] net: dpaa2-mac: extend APIs related to statistics Ioana Ciornei
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Ioana Ciornei @ 2026-03-23 11:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel
This patch set adds support for standard ethtool statistics - rmon,
eth-ctrl, eth-mac and pause - to dpaa2-mac and its users dpaa2-eth and
dpaa2-switch.
The first patch extends the firmware APIs related to MAC counters and
adds dpmac_get_statistics() which can be used to retrieve multiple counter
values through a single firmware call.
This new API is put in use in the second patch by gathering all
previously exported ethtool statistics through a single MC firmware
call. In this patch we are also adding the setup and cleanup
infrastructure which will be also used for the standard ethtool
counters.
The third patch adds the actual suppord for rmon, eth-ctrl, eth-mac and
pause statistics in dpaa2-mac and its users.
Changes in v5:
- 3/3: use DPMAC_CNT_ING_UNDERSIZED for the rmon etherStatsUndersizePkts
counter
Changes in v4:
- 2/3: fix dma_sync call and memory leak in the cleanup
- 3/3: add dma_sync_single_for_device before calling the MC API
Changes in v3:
- 1/3: limit the documentation entries to 80 chars
- 2/3: use dma_alloc_noncoherent() instead of kcalloc + dma_map_single
- 2/3, 3/3: reduce the number of lines that have more than 80 chars
Changes in v2:
- 2/3: fix fallback usecase by using dpaa2_mac_ethtool_stats[i].id
- 2/3: use the __le32/__le64 types for cnt_idx, cnt_values etc
Ioana Ciornei (3):
net: dpaa2-mac: extend APIs related to statistics
net: dpaa2-mac: retrieve MAC statistics in one firmware command
net: dpaa2-mac: export standard statistics
.../ethernet/freescale/dpaa2/dpaa2-ethtool.c | 61 ++-
.../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 409 ++++++++++++++++--
.../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 27 +-
.../freescale/dpaa2/dpaa2-switch-ethtool.c | 48 +-
.../net/ethernet/freescale/dpaa2/dpmac-cmd.h | 11 +-
drivers/net/ethernet/freescale/dpaa2/dpmac.c | 31 +-
drivers/net/ethernet/freescale/dpaa2/dpmac.h | 94 +++-
7 files changed, 638 insertions(+), 43 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v5 1/3] net: dpaa2-mac: extend APIs related to statistics
2026-03-23 11:50 [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
@ 2026-03-23 11:50 ` Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 2/3] net: dpaa2-mac: retrieve MAC statistics in one firmware command Ioana Ciornei
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Ioana Ciornei @ 2026-03-23 11:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel
Extend the dpmac_counter_id enum with the newly added counters which can
be interrogated through the MC firmware. Also add the
dpmac_get_statistics() API which can be used to retrieve multiple MAC
counters through a single firmware command.
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
Changes in v5:
- none
Changes in v4:
- none
Changes in v3:
- limit the documentation entries to 80 chars
Changes in v2:
- none
.../net/ethernet/freescale/dpaa2/dpmac-cmd.h | 11 ++-
drivers/net/ethernet/freescale/dpaa2/dpmac.c | 31 +++++-
drivers/net/ethernet/freescale/dpaa2/dpmac.h | 94 ++++++++++++++++++-
3 files changed, 132 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h b/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h
index e9ac2ecef3be..a864a99a0f75 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
/* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2019 NXP
+ * Copyright 2019, 2024-2026 NXP
*/
#ifndef _FSL_DPMAC_CMD_H
#define _FSL_DPMAC_CMD_H
@@ -28,6 +28,8 @@
#define DPMAC_CMDID_SET_PROTOCOL DPMAC_CMD(0x0c7)
+#define DPMAC_CMDID_GET_STATISTICS DPMAC_CMD(0x0c8)
+
/* Macros for accessing command fields smaller than 1byte */
#define DPMAC_MASK(field) \
GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \
@@ -82,4 +84,11 @@ struct dpmac_rsp_get_api_version {
struct dpmac_cmd_set_protocol {
u8 eth_if;
};
+
+struct dpmac_cmd_get_statistics {
+ __le64 iova_cnt;
+ __le64 iova_values;
+ __le32 num_cnt;
+};
+
#endif /* _FSL_DPMAC_CMD_H */
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac.c b/drivers/net/ethernet/freescale/dpaa2/dpmac.c
index f440a4c3b70c..efb9864d051f 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpmac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpmac.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2019 NXP
+ * Copyright 2019, 2024-2026 NXP
*/
#include <linux/fsl/mc.h>
#include "dpmac.h"
@@ -235,3 +235,32 @@ int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
return mc_send_command(mc_io, &cmd);
}
+
+/**
+ * dpmac_get_statistics() - Get MAC statistics
+ * @mc_io: Pointer to opaque I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token: Token of DPMAC object
+ * @iova_cnt: IOVA containing the requested MAC counters formatted as an
+ * array of __le32 representing the dpmac_counter_id.
+ * @iova_values: IOVA containing the values for all the requested counters
+ * formatted as an array of __le64.
+ * @num_cnt: Number of counters requested
+ *
+ * Return: '0' on Success; Error code otherwise.
+ */
+int dpmac_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
+ u64 iova_cnt, u64 iova_values, u32 num_cnt)
+{
+ struct dpmac_cmd_get_statistics *cmd_params;
+ struct fsl_mc_command cmd = { 0 };
+
+ cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_STATISTICS,
+ cmd_flags, token);
+ cmd_params = (struct dpmac_cmd_get_statistics *)cmd.params;
+ cmd_params->iova_cnt = cpu_to_le64(iova_cnt);
+ cmd_params->iova_values = cpu_to_le64(iova_values);
+ cmd_params->num_cnt = cpu_to_le32(num_cnt);
+
+ return mc_send_command(mc_io, &cmd);
+}
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac.h b/drivers/net/ethernet/freescale/dpaa2/dpmac.h
index 17488819ef68..b5276168b869 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpmac.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpmac.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
/* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2019 NXP
+ * Copyright 2019, 2024-2026 NXP
*/
#ifndef __FSL_DPMAC_H
#define __FSL_DPMAC_H
@@ -170,6 +170,58 @@ int dpmac_set_link_state(struct fsl_mc_io *mc_io,
* pause frames.
* @DPMAC_CNT_EGR_GOOD_FRAME: counts frames transmitted without error, including
* pause frames.
+ * @DPMAC_CNT_EGR_FRAME_64: counts transmitted 64-bytes frames, good or bad.
+ * @DPMAC_CNT_EGR_FRAME_127: counts transmitted 65 to 127-bytes frames, good or
+ * bad.
+ * @DPMAC_CNT_EGR_FRAME_255: counts transmitted 128 to 255-bytes frames, good
+ * or bad.
+ * @DPMAC_CNT_EGR_FRAME_511: counts transmitted 256 to 511-bytes frames, good
+ * or bad.
+ * @DPMAC_CNT_EGR_FRAME_1023: counts transmitted 512 to 1023-bytes frames, good
+ * or bad.
+ * @DPMAC_CNT_EGR_FRAME_1518: counts transmitted 1024 to 1518-bytes frames,
+ * good or bad.
+ * @DPMAC_CNT_EGR_FRAME_1519_MAX: counts transmitted 1519-bytes frames and
+ * larger (up to max frame length specified),
+ * good or bad.
+ * @DPMAC_CNT_ING_ALL_BYTE: counts bytes received in both good and bad packets
+ * @DPMAC_CNT_ING_FCS_ERR: counts frames received with a CRC-32 error but the
+ * frame is otherwise of correct length
+ * @DPMAC_CNT_ING_VLAN_FRAME: counts the received VLAN tagged frames which are
+ * valid.
+ * @DPMAC_CNT_ING_UNDERSIZED: counts received frames which were less than 64
+ * bytes long and with a good CRC.
+ * @DPMAC_CNT_ING_CONTROL_FRAME: counts received control frames (type 0x8808)
+ * but not pause frames.
+ * @DPMAC_CNT_ING_FRAME_DISCARD_NOT_TRUNC: counts the fully dropped frames (not
+ * truncated) due to internal errors of
+ * the MAC client. Occurs when a
+ * receive FIFO overflows.
+ * @DPMAC_CNT_EGR_ALL_BYTE: counts transmitted bytes in both good and bad
+ * packets.
+ * @DPMAC_CNT_EGR_FCS_ERR: counts trasmitted frames with a CRC-32 error except
+ * for underflows.
+ * @DPMAC_CNT_EGR_VLAN_FRAME: counts the transmitted VLAN tagged frames which
+ * are valid.
+ * @DPMAC_CNT_EGR_ALL_FRAME: counts all trasmitted frames, good or bad.
+ * @DPMAC_CNT_EGR_CONTROL_FRAME: counts transmitted control frames (type
+ * 0x8808) but not pause frames.
+ * @DPMAC_CNT_ING_PFC0: number of PFC frames received for class 0.
+ * @DPMAC_CNT_ING_PFC1: number of PFC frames received for class 1.
+ * @DPMAC_CNT_ING_PFC2: number of PFC frames received for class 2.
+ * @DPMAC_CNT_ING_PFC3: number of PFC frames received for class 3.
+ * @DPMAC_CNT_ING_PFC4: number of PFC frames received for class 4.
+ * @DPMAC_CNT_ING_PFC5: number of PFC frames received for class 5.
+ * @DPMAC_CNT_ING_PFC6: number of PFC frames received for class 6.
+ * @DPMAC_CNT_ING_PFC7: number of PFC frames received for class 7.
+ * @DPMAC_CNT_EGR_PFC0: number of PFC frames transmitted for class 0.
+ * @DPMAC_CNT_EGR_PFC1: number of PFC frames transmitted for class 1.
+ * @DPMAC_CNT_EGR_PFC2: number of PFC frames transmitted for class 2.
+ * @DPMAC_CNT_EGR_PFC3: number of PFC frames transmitted for class 3.
+ * @DPMAC_CNT_EGR_PFC4: number of PFC frames transmitted for class 4.
+ * @DPMAC_CNT_EGR_PFC5: number of PFC frames transmitted for class 5.
+ * @DPMAC_CNT_EGR_PFC6: number of PFC frames transmitted for class 6.
+ * @DPMAC_CNT_EGR_PFC7: number of PFC frames transmitted for class 7.
*/
enum dpmac_counter_id {
DPMAC_CNT_ING_FRAME_64,
@@ -199,7 +251,41 @@ enum dpmac_counter_id {
DPMAC_CNT_EGR_UCAST_FRAME,
DPMAC_CNT_EGR_ERR_FRAME,
DPMAC_CNT_ING_GOOD_FRAME,
- DPMAC_CNT_EGR_GOOD_FRAME
+ DPMAC_CNT_EGR_GOOD_FRAME,
+ DPMAC_CNT_EGR_FRAME_64,
+ DPMAC_CNT_EGR_FRAME_127,
+ DPMAC_CNT_EGR_FRAME_255,
+ DPMAC_CNT_EGR_FRAME_511,
+ DPMAC_CNT_EGR_FRAME_1023,
+ DPMAC_CNT_EGR_FRAME_1518,
+ DPMAC_CNT_EGR_FRAME_1519_MAX,
+ DPMAC_CNT_ING_ALL_BYTE,
+ DPMAC_CNT_ING_FCS_ERR,
+ DPMAC_CNT_ING_VLAN_FRAME,
+ DPMAC_CNT_ING_UNDERSIZED,
+ DPMAC_CNT_ING_CONTROL_FRAME,
+ DPMAC_CNT_ING_FRAME_DISCARD_NOT_TRUNC,
+ DPMAC_CNT_EGR_ALL_BYTE,
+ DPMAC_CNT_EGR_FCS_ERR,
+ DPMAC_CNT_EGR_VLAN_FRAME,
+ DPMAC_CNT_EGR_ALL_FRAME,
+ DPMAC_CNT_EGR_CONTROL_FRAME,
+ DPMAC_CNT_ING_PFC0,
+ DPMAC_CNT_ING_PFC1,
+ DPMAC_CNT_ING_PFC2,
+ DPMAC_CNT_ING_PFC3,
+ DPMAC_CNT_ING_PFC4,
+ DPMAC_CNT_ING_PFC5,
+ DPMAC_CNT_ING_PFC6,
+ DPMAC_CNT_ING_PFC7,
+ DPMAC_CNT_EGR_PFC0,
+ DPMAC_CNT_EGR_PFC1,
+ DPMAC_CNT_EGR_PFC2,
+ DPMAC_CNT_EGR_PFC3,
+ DPMAC_CNT_EGR_PFC4,
+ DPMAC_CNT_EGR_PFC5,
+ DPMAC_CNT_EGR_PFC6,
+ DPMAC_CNT_EGR_PFC7,
};
int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
@@ -210,4 +296,8 @@ int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
enum dpmac_eth_if protocol);
+
+int dpmac_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
+ u64 iova_cnt, u64 iova_values, u32 num_cnt);
+
#endif /* __FSL_DPMAC_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v5 2/3] net: dpaa2-mac: retrieve MAC statistics in one firmware command
2026-03-23 11:50 [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 1/3] net: dpaa2-mac: extend APIs related to statistics Ioana Ciornei
@ 2026-03-23 11:50 ` Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
2026-03-26 12:00 ` [PATCH net-next v5 0/3] " patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: Ioana Ciornei @ 2026-03-23 11:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel
The latest MC firmware version added a new command to retrieve all DPMAC
counters in a single firmware call. Use this new command, when possible,
in dpaa2-mac as well.
In order to use the dpmac_get_statistics() API, two DMA memory areas are
used: one to transmit what counters the driver is requesting and one to
receive the values of those counters. These memory areas are allocated
and DMA mapped at probe time so that we don't waste time at runtime.
And since we are planning to add rmon, eth-ctrl and other standard
statistics using the same infrastructure, make the setup and cleanup
processes as generic as possibile through the dpaa2_mac_setup_stats()
and dpaa2_mac_clear_stats() functions.
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
Changes in v5:
- none
Changes in v4:
- fix dma_sync call and memory leak in the cleanup
Changes in v3:
- use dma_alloc_noncoherent() instead of kcalloc + dma_map_single
- reduce the number of lines that have more than 80 chars
Changes in v2:
- fix fallback usecase by using dpaa2_mac_ethtool_stats[i].id
- use the __le32/__le64 types for cnt_idx, cnt_values etc
.../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 201 ++++++++++++++----
.../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 10 +-
2 files changed, 171 insertions(+), 40 deletions(-)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index 422ce13a7c94..5a7fda6a2012 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
-/* Copyright 2019 NXP */
+/* Copyright 2019, 2024-2026 NXP */
#include <linux/acpi.h>
#include <linux/pcs-lynx.h>
@@ -15,7 +15,118 @@
#define DPMAC_PROTOCOL_CHANGE_VER_MAJOR 4
#define DPMAC_PROTOCOL_CHANGE_VER_MINOR 8
+#define DPMAC_STATS_BUNDLE_VER_MAJOR 4
+#define DPMAC_STATS_BUNDLE_VER_MINOR 10
+
#define DPAA2_MAC_FEATURE_PROTOCOL_CHANGE BIT(0)
+#define DPAA2_MAC_FEATURE_STATS_BUNDLE BIT(1)
+
+struct dpmac_counter {
+ enum dpmac_counter_id id;
+ const char *name;
+};
+
+#define DPMAC_UNSTRUCTURED_COUNTER(counter_id, counter_name) \
+ { \
+ .id = counter_id, \
+ .name = counter_name, \
+ }
+
+static const struct dpmac_counter dpaa2_mac_ethtool_stats[] = {
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_ALL_FRAME, "[mac] rx all frames"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_GOOD_FRAME, "[mac] rx frames ok"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_ERR_FRAME, "[mac] rx frame errors"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_DISCARD, "[mac] rx frame discards"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_UCAST_FRAME, "[mac] rx u-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_BCAST_FRAME, "[mac] rx b-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_MCAST_FRAME, "[mac] rx m-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_64, "[mac] rx 64 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_127, "[mac] rx 65-127 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_255, "[mac] rx 128-255 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_511, "[mac] rx 256-511 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_1023, "[mac] rx 512-1023 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_1518, "[mac] rx 1024-1518 bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAME_1519_MAX, "[mac] rx 1519-max bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_FRAG, "[mac] rx frags"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_JABBER, "[mac] rx jabber"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_ALIGN_ERR, "[mac] rx align errors"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_OVERSIZED, "[mac] rx oversized"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_VALID_PAUSE_FRAME, "[mac] rx pause"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_BYTE, "[mac] rx bytes"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_GOOD_FRAME, "[mac] tx frames ok"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_UCAST_FRAME, "[mac] tx u-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_MCAST_FRAME, "[mac] tx m-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_BCAST_FRAME, "[mac] tx b-cast"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_ERR_FRAME, "[mac] tx frame errors"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_UNDERSIZED, "[mac] tx undersized"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_VALID_PAUSE_FRAME, "[mac] tx b-pause"),
+ DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_EGR_BYTE, "[mac] tx bytes"),
+};
+
+#define DPAA2_MAC_NUM_ETHTOOL_STATS ARRAY_SIZE(dpaa2_mac_ethtool_stats)
+
+static void dpaa2_mac_setup_stats(struct dpaa2_mac *mac,
+ struct dpaa2_mac_stats *stats,
+ size_t num_stats,
+ const struct dpmac_counter *counters)
+{
+ struct device *dev = mac->net_dev->dev.parent;
+ size_t size_idx, size_values;
+ __le32 *cnt_idx;
+
+ size_idx = num_stats * sizeof(u32);
+ stats->idx_dma_mem = dma_alloc_noncoherent(dev, size_idx,
+ &stats->idx_iova,
+ DMA_TO_DEVICE,
+ GFP_KERNEL);
+ if (!stats->idx_dma_mem)
+ goto out;
+
+ size_values = num_stats * sizeof(u64);
+ stats->values_dma_mem = dma_alloc_noncoherent(dev, size_values,
+ &stats->values_iova,
+ DMA_FROM_DEVICE,
+ GFP_KERNEL);
+ if (!stats->values_dma_mem)
+ goto err_alloc_values;
+
+ cnt_idx = stats->idx_dma_mem;
+ for (size_t i = 0; i < num_stats; i++)
+ *cnt_idx++ = cpu_to_le32((u32)(counters[i].id));
+
+ dma_sync_single_for_device(dev, stats->idx_iova, size_idx,
+ DMA_TO_DEVICE);
+
+ return;
+
+err_alloc_values:
+ dma_free_noncoherent(dev, num_stats * sizeof(u32), stats->idx_dma_mem,
+ stats->idx_iova, DMA_TO_DEVICE);
+out:
+ stats->idx_dma_mem = NULL;
+ stats->values_dma_mem = NULL;
+}
+
+static void dpaa2_mac_clear_stats(struct dpaa2_mac *mac,
+ struct dpaa2_mac_stats *stats,
+ size_t num_stats)
+{
+ struct device *dev = mac->net_dev->dev.parent;
+
+ if (stats->idx_dma_mem) {
+ dma_free_noncoherent(dev, num_stats * sizeof(u32),
+ stats->idx_dma_mem,
+ stats->idx_iova, DMA_TO_DEVICE);
+ stats->idx_dma_mem = NULL;
+ }
+
+ if (stats->values_dma_mem) {
+ dma_free_noncoherent(dev, num_stats * sizeof(u64),
+ stats->values_dma_mem,
+ stats->values_iova, DMA_FROM_DEVICE);
+ stats->values_dma_mem = NULL;
+ }
+}
static int dpaa2_mac_cmp_ver(struct dpaa2_mac *mac,
u16 ver_major, u16 ver_minor)
@@ -32,6 +143,10 @@ static void dpaa2_mac_detect_features(struct dpaa2_mac *mac)
if (dpaa2_mac_cmp_ver(mac, DPMAC_PROTOCOL_CHANGE_VER_MAJOR,
DPMAC_PROTOCOL_CHANGE_VER_MINOR) >= 0)
mac->features |= DPAA2_MAC_FEATURE_PROTOCOL_CHANGE;
+
+ if (dpaa2_mac_cmp_ver(mac, DPMAC_STATS_BUNDLE_VER_MAJOR,
+ DPMAC_STATS_BUNDLE_VER_MINOR) >= 0)
+ mac->features |= DPAA2_MAC_FEATURE_STATS_BUNDLE;
}
static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
@@ -504,6 +619,11 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
mac->fw_node = fw_node;
net_dev->dev.of_node = to_of_node(mac->fw_node);
+ if (mac->features & DPAA2_MAC_FEATURE_STATS_BUNDLE)
+ dpaa2_mac_setup_stats(mac, &mac->ethtool_stats,
+ DPAA2_MAC_NUM_ETHTOOL_STATS,
+ dpaa2_mac_ethtool_stats);
+
return 0;
err_close_dpmac:
@@ -515,66 +635,69 @@ void dpaa2_mac_close(struct dpaa2_mac *mac)
{
struct fsl_mc_device *dpmac_dev = mac->mc_dev;
+ if (mac->features & DPAA2_MAC_FEATURE_STATS_BUNDLE)
+ dpaa2_mac_clear_stats(mac, &mac->ethtool_stats,
+ DPAA2_MAC_NUM_ETHTOOL_STATS);
+
dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle);
if (mac->fw_node)
fwnode_handle_put(mac->fw_node);
}
-static char dpaa2_mac_ethtool_stats[][ETH_GSTRING_LEN] = {
- [DPMAC_CNT_ING_ALL_FRAME] = "[mac] rx all frames",
- [DPMAC_CNT_ING_GOOD_FRAME] = "[mac] rx frames ok",
- [DPMAC_CNT_ING_ERR_FRAME] = "[mac] rx frame errors",
- [DPMAC_CNT_ING_FRAME_DISCARD] = "[mac] rx frame discards",
- [DPMAC_CNT_ING_UCAST_FRAME] = "[mac] rx u-cast",
- [DPMAC_CNT_ING_BCAST_FRAME] = "[mac] rx b-cast",
- [DPMAC_CNT_ING_MCAST_FRAME] = "[mac] rx m-cast",
- [DPMAC_CNT_ING_FRAME_64] = "[mac] rx 64 bytes",
- [DPMAC_CNT_ING_FRAME_127] = "[mac] rx 65-127 bytes",
- [DPMAC_CNT_ING_FRAME_255] = "[mac] rx 128-255 bytes",
- [DPMAC_CNT_ING_FRAME_511] = "[mac] rx 256-511 bytes",
- [DPMAC_CNT_ING_FRAME_1023] = "[mac] rx 512-1023 bytes",
- [DPMAC_CNT_ING_FRAME_1518] = "[mac] rx 1024-1518 bytes",
- [DPMAC_CNT_ING_FRAME_1519_MAX] = "[mac] rx 1519-max bytes",
- [DPMAC_CNT_ING_FRAG] = "[mac] rx frags",
- [DPMAC_CNT_ING_JABBER] = "[mac] rx jabber",
- [DPMAC_CNT_ING_ALIGN_ERR] = "[mac] rx align errors",
- [DPMAC_CNT_ING_OVERSIZED] = "[mac] rx oversized",
- [DPMAC_CNT_ING_VALID_PAUSE_FRAME] = "[mac] rx pause",
- [DPMAC_CNT_ING_BYTE] = "[mac] rx bytes",
- [DPMAC_CNT_EGR_GOOD_FRAME] = "[mac] tx frames ok",
- [DPMAC_CNT_EGR_UCAST_FRAME] = "[mac] tx u-cast",
- [DPMAC_CNT_EGR_MCAST_FRAME] = "[mac] tx m-cast",
- [DPMAC_CNT_EGR_BCAST_FRAME] = "[mac] tx b-cast",
- [DPMAC_CNT_EGR_ERR_FRAME] = "[mac] tx frame errors",
- [DPMAC_CNT_EGR_UNDERSIZED] = "[mac] tx undersized",
- [DPMAC_CNT_EGR_VALID_PAUSE_FRAME] = "[mac] tx b-pause",
- [DPMAC_CNT_EGR_BYTE] = "[mac] tx bytes",
-};
-
-#define DPAA2_MAC_NUM_STATS ARRAY_SIZE(dpaa2_mac_ethtool_stats)
-
int dpaa2_mac_get_sset_count(void)
{
- return DPAA2_MAC_NUM_STATS;
+ return DPAA2_MAC_NUM_ETHTOOL_STATS;
}
void dpaa2_mac_get_strings(u8 **data)
{
int i;
- for (i = 0; i < DPAA2_MAC_NUM_STATS; i++)
- ethtool_puts(data, dpaa2_mac_ethtool_stats[i]);
+ for (i = 0; i < DPAA2_MAC_NUM_ETHTOOL_STATS; i++)
+ ethtool_puts(data, dpaa2_mac_ethtool_stats[i].name);
}
void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data)
{
+ size_t values_size = DPAA2_MAC_NUM_ETHTOOL_STATS * sizeof(u64);
+ struct device *dev = mac->net_dev->dev.parent;
struct fsl_mc_device *dpmac_dev = mac->mc_dev;
+ __le64 *cnt_values;
int i, err;
u64 value;
- for (i = 0; i < DPAA2_MAC_NUM_STATS; i++) {
+ if (!(mac->features & DPAA2_MAC_FEATURE_STATS_BUNDLE))
+ goto fallback;
+
+ if (!mac->ethtool_stats.idx_dma_mem ||
+ !mac->ethtool_stats.values_dma_mem)
+ goto fallback;
+
+ dma_sync_single_for_device(dev, mac->ethtool_stats.values_iova,
+ values_size, DMA_FROM_DEVICE);
+
+ err = dpmac_get_statistics(mac->mc_io, 0, dpmac_dev->mc_handle,
+ mac->ethtool_stats.idx_iova,
+ mac->ethtool_stats.values_iova,
+ DPAA2_MAC_NUM_ETHTOOL_STATS);
+ if (err)
+ goto fallback;
+
+ dma_sync_single_for_cpu(dev, mac->ethtool_stats.values_iova,
+ values_size, DMA_FROM_DEVICE);
+
+ cnt_values = mac->ethtool_stats.values_dma_mem;
+ for (i = 0; i < DPAA2_MAC_NUM_ETHTOOL_STATS; i++)
+ *(data + i) = le64_to_cpu(*cnt_values++);
+
+ return;
+
+fallback:
+
+ /* Fallback and retrieve each counter one by one */
+ for (i = 0; i < DPAA2_MAC_NUM_ETHTOOL_STATS; i++) {
err = dpmac_get_counter(mac->mc_io, 0, dpmac_dev->mc_handle,
- i, &value);
+ dpaa2_mac_ethtool_stats[i].id, &value);
if (err) {
netdev_err_once(mac->net_dev,
"dpmac_get_counter error %d\n", err);
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
index 53f8d106d11e..6f4981627961 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
-/* Copyright 2019 NXP */
+/* Copyright 2019, 2024-2026 NXP */
#ifndef DPAA2_MAC_H
#define DPAA2_MAC_H
@@ -11,6 +11,12 @@
#include "dpmac.h"
#include "dpmac-cmd.h"
+struct dpaa2_mac_stats {
+ __le32 *idx_dma_mem;
+ __le64 *values_dma_mem;
+ dma_addr_t idx_iova, values_iova;
+};
+
struct dpaa2_mac {
struct fsl_mc_device *mc_dev;
struct dpmac_link_state state;
@@ -28,6 +34,8 @@ struct dpaa2_mac {
struct fwnode_handle *fw_node;
struct phy *serdes_phy;
+
+ struct dpaa2_mac_stats ethtool_stats;
};
static inline bool dpaa2_mac_is_type_phy(struct dpaa2_mac *mac)
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics
2026-03-23 11:50 [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 1/3] net: dpaa2-mac: extend APIs related to statistics Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 2/3] net: dpaa2-mac: retrieve MAC statistics in one firmware command Ioana Ciornei
@ 2026-03-23 11:50 ` Ioana Ciornei
2026-03-25 13:47 ` Ioana Ciornei
2026-03-26 12:00 ` [PATCH net-next v5 0/3] " patchwork-bot+netdevbpf
3 siblings, 1 reply; 6+ messages in thread
From: Ioana Ciornei @ 2026-03-23 11:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel
Take advantage of all the newly added MAC counters available through the
MC API and export them through the standard statistics structures -
rmon, eth-ctrl, eth-mac and pause.
A new version based feature is added into dpaa2-mac -
DPAA2_MAC_FEATURE_STANDARD_STATS - and based on the two memory zones
needed for gathering the MAC counters are setup for each statistics
group.
The dpmac_counter structure is extended with a new field - size_t offset
- which is being used to instruct the dpaa2_mac_transfer_stats()
function where exactly to store a counter value inside the standard
statistics structure.
The newly added support is used both in the dpaa2-eth driver as well as
the dpaa2-switch one.
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
Changes in v5:
- use DPMAC_CNT_ING_UNDERSIZED for the rmon etherStatsUndersizePkts
counter
Changes in v4:
- add dma_sync_single_for_device before calling the MC API
Changes in v3:
- reduce the number of lines that have more than 80 chars
Changes in v2:
- none
.../ethernet/freescale/dpaa2/dpaa2-ethtool.c | 61 ++++-
.../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 214 ++++++++++++++++++
.../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 17 ++
.../freescale/dpaa2/dpaa2-switch-ethtool.c | 48 +++-
4 files changed, 338 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
index baab4f1c908d..59f5c778df38 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/* Copyright 2014-2016 Freescale Semiconductor Inc.
- * Copyright 2016-2022 NXP
+ * Copyright 2016-2022, 2024-2026 NXP
*/
#include <linux/net_tstamp.h>
@@ -938,6 +938,61 @@ static void dpaa2_eth_get_channels(struct net_device *net_dev,
channels->other_count;
}
+static void
+dpaa2_eth_get_rmon_stats(struct net_device *net_dev,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
+
+ mutex_lock(&priv->mac_lock);
+
+ if (dpaa2_eth_has_mac(priv))
+ dpaa2_mac_get_rmon_stats(priv->mac, rmon_stats, ranges);
+
+ mutex_unlock(&priv->mac_lock);
+}
+
+static void dpaa2_eth_get_pause_stats(struct net_device *net_dev,
+ struct ethtool_pause_stats *pause_stats)
+{
+ struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
+
+ mutex_lock(&priv->mac_lock);
+
+ if (dpaa2_eth_has_mac(priv))
+ dpaa2_mac_get_pause_stats(priv->mac, pause_stats);
+
+ mutex_unlock(&priv->mac_lock);
+}
+
+static void dpaa2_eth_get_ctrl_stats(struct net_device *net_dev,
+ struct ethtool_eth_ctrl_stats *ctrl_stats)
+{
+ struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
+
+ mutex_lock(&priv->mac_lock);
+
+ if (dpaa2_eth_has_mac(priv))
+ dpaa2_mac_get_ctrl_stats(priv->mac, ctrl_stats);
+
+ mutex_unlock(&priv->mac_lock);
+}
+
+static void
+dpaa2_eth_get_eth_mac_stats(struct net_device *net_dev,
+ struct ethtool_eth_mac_stats *eth_mac_stats)
+{
+ struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
+
+ mutex_lock(&priv->mac_lock);
+
+ if (dpaa2_eth_has_mac(priv))
+ dpaa2_mac_get_eth_mac_stats(priv->mac, eth_mac_stats);
+
+ mutex_unlock(&priv->mac_lock);
+}
+
const struct ethtool_ops dpaa2_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
@@ -962,4 +1017,8 @@ const struct ethtool_ops dpaa2_ethtool_ops = {
.get_coalesce = dpaa2_eth_get_coalesce,
.set_coalesce = dpaa2_eth_set_coalesce,
.get_channels = dpaa2_eth_get_channels,
+ .get_rmon_stats = dpaa2_eth_get_rmon_stats,
+ .get_pause_stats = dpaa2_eth_get_pause_stats,
+ .get_eth_ctrl_stats = dpaa2_eth_get_ctrl_stats,
+ .get_eth_mac_stats = dpaa2_eth_get_eth_mac_stats,
};
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index 5a7fda6a2012..ad812ebf3139 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -18,20 +18,43 @@
#define DPMAC_STATS_BUNDLE_VER_MAJOR 4
#define DPMAC_STATS_BUNDLE_VER_MINOR 10
+#define DPMAC_STANDARD_STATS_VER_MAJOR 4
+#define DPMAC_STANDARD_STATS_VER_MINOR 11
+
#define DPAA2_MAC_FEATURE_PROTOCOL_CHANGE BIT(0)
#define DPAA2_MAC_FEATURE_STATS_BUNDLE BIT(1)
+#define DPAA2_MAC_FEATURE_STANDARD_STATS BIT(2)
struct dpmac_counter {
enum dpmac_counter_id id;
+ size_t offset;
const char *name;
};
+#define DPMAC_COUNTER(counter_id, struct_name, struct_offset) \
+ { \
+ .id = counter_id, \
+ .offset = offsetof(struct_name, struct_offset), \
+ }
+
#define DPMAC_UNSTRUCTURED_COUNTER(counter_id, counter_name) \
{ \
.id = counter_id, \
.name = counter_name, \
}
+#define DPMAC_RMON_COUNTER(counter_id, struct_offset) \
+ DPMAC_COUNTER(counter_id, struct ethtool_rmon_stats, struct_offset)
+
+#define DPMAC_PAUSE_COUNTER(counter_id, struct_offset) \
+ DPMAC_COUNTER(counter_id, struct ethtool_pause_stats, struct_offset)
+
+#define DPMAC_CTRL_COUNTER(counter_id, struct_offset) \
+ DPMAC_COUNTER(counter_id, struct ethtool_eth_ctrl_stats, struct_offset)
+
+#define DPMAC_MAC_COUNTER(counter_id, struct_offset) \
+ DPMAC_COUNTER(counter_id, struct ethtool_eth_mac_stats, struct_offset)
+
static const struct dpmac_counter dpaa2_mac_ethtool_stats[] = {
DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_ALL_FRAME, "[mac] rx all frames"),
DPMAC_UNSTRUCTURED_COUNTER(DPMAC_CNT_ING_GOOD_FRAME, "[mac] rx frames ok"),
@@ -65,6 +88,60 @@ static const struct dpmac_counter dpaa2_mac_ethtool_stats[] = {
#define DPAA2_MAC_NUM_ETHTOOL_STATS ARRAY_SIZE(dpaa2_mac_ethtool_stats)
+static const struct dpmac_counter dpaa2_mac_rmon_stats[] = {
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_64, hist[0]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_127, hist[1]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_255, hist[2]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_511, hist[3]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1023, hist[4]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1518, hist[5]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1519_MAX, hist[6]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_64, hist_tx[0]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_127, hist_tx[1]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_255, hist_tx[2]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_511, hist_tx[3]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1023, hist_tx[4]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1518, hist_tx[5]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1519_MAX, hist_tx[6]),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_UNDERSIZED, undersize_pkts),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_OVERSIZED, oversize_pkts),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAG, fragments),
+ DPMAC_RMON_COUNTER(DPMAC_CNT_ING_JABBER, jabbers),
+};
+
+#define DPAA2_MAC_NUM_RMON_STATS ARRAY_SIZE(dpaa2_mac_rmon_stats)
+
+static const struct dpmac_counter dpaa2_mac_pause_stats[] = {
+ DPMAC_PAUSE_COUNTER(DPMAC_CNT_ING_VALID_PAUSE_FRAME, rx_pause_frames),
+ DPMAC_PAUSE_COUNTER(DPMAC_CNT_EGR_VALID_PAUSE_FRAME, tx_pause_frames),
+};
+
+#define DPAA2_MAC_NUM_PAUSE_STATS ARRAY_SIZE(dpaa2_mac_pause_stats)
+
+static const struct dpmac_counter dpaa2_mac_eth_ctrl_stats[] = {
+ DPMAC_CTRL_COUNTER(DPMAC_CNT_ING_CONTROL_FRAME, MACControlFramesReceived),
+ DPMAC_CTRL_COUNTER(DPMAC_CNT_EGR_CONTROL_FRAME, MACControlFramesTransmitted),
+};
+
+#define DPAA2_MAC_NUM_ETH_CTRL_STATS ARRAY_SIZE(dpaa2_mac_eth_ctrl_stats)
+
+static const struct dpmac_counter dpaa2_mac_eth_mac_stats[] = {
+ DPMAC_MAC_COUNTER(DPMAC_CNT_EGR_GOOD_FRAME, FramesTransmittedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_GOOD_FRAME, FramesReceivedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_FCS_ERR, FrameCheckSequenceErrors),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_ALIGN_ERR, AlignmentErrors),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_EGR_ALL_BYTE, OctetsTransmittedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_EGR_ERR_FRAME, FramesLostDueToIntMACXmitError),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_ALL_BYTE, OctetsReceivedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_FRAME_DISCARD_NOT_TRUNC, FramesLostDueToIntMACRcvError),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_EGR_MCAST_FRAME, MulticastFramesXmittedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_EGR_BCAST_FRAME, BroadcastFramesXmittedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_MCAST_FRAME, MulticastFramesReceivedOK),
+ DPMAC_MAC_COUNTER(DPMAC_CNT_ING_BCAST_FRAME, BroadcastFramesReceivedOK),
+};
+
+#define DPAA2_MAC_NUM_ETH_MAC_STATS ARRAY_SIZE(dpaa2_mac_eth_mac_stats)
+
static void dpaa2_mac_setup_stats(struct dpaa2_mac *mac,
struct dpaa2_mac_stats *stats,
size_t num_stats,
@@ -147,6 +224,10 @@ static void dpaa2_mac_detect_features(struct dpaa2_mac *mac)
if (dpaa2_mac_cmp_ver(mac, DPMAC_STATS_BUNDLE_VER_MAJOR,
DPMAC_STATS_BUNDLE_VER_MINOR) >= 0)
mac->features |= DPAA2_MAC_FEATURE_STATS_BUNDLE;
+
+ if (dpaa2_mac_cmp_ver(mac, DPMAC_STANDARD_STATS_VER_MAJOR,
+ DPMAC_STANDARD_STATS_VER_MINOR) >= 0)
+ mac->features |= DPAA2_MAC_FEATURE_STANDARD_STATS;
}
static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
@@ -624,6 +705,24 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
DPAA2_MAC_NUM_ETHTOOL_STATS,
dpaa2_mac_ethtool_stats);
+ if (mac->features & DPAA2_MAC_FEATURE_STANDARD_STATS) {
+ dpaa2_mac_setup_stats(mac, &mac->rmon_stats,
+ DPAA2_MAC_NUM_RMON_STATS,
+ dpaa2_mac_rmon_stats);
+
+ dpaa2_mac_setup_stats(mac, &mac->pause_stats,
+ DPAA2_MAC_NUM_PAUSE_STATS,
+ dpaa2_mac_pause_stats);
+
+ dpaa2_mac_setup_stats(mac, &mac->eth_ctrl_stats,
+ DPAA2_MAC_NUM_ETH_CTRL_STATS,
+ dpaa2_mac_eth_ctrl_stats);
+
+ dpaa2_mac_setup_stats(mac, &mac->eth_mac_stats,
+ DPAA2_MAC_NUM_ETH_MAC_STATS,
+ dpaa2_mac_eth_mac_stats);
+ }
+
return 0;
err_close_dpmac:
@@ -639,11 +738,126 @@ void dpaa2_mac_close(struct dpaa2_mac *mac)
dpaa2_mac_clear_stats(mac, &mac->ethtool_stats,
DPAA2_MAC_NUM_ETHTOOL_STATS);
+ if (mac->features & DPAA2_MAC_FEATURE_STANDARD_STATS) {
+ dpaa2_mac_clear_stats(mac, &mac->rmon_stats,
+ DPAA2_MAC_NUM_RMON_STATS);
+ dpaa2_mac_clear_stats(mac, &mac->pause_stats,
+ DPAA2_MAC_NUM_PAUSE_STATS);
+ dpaa2_mac_clear_stats(mac, &mac->eth_ctrl_stats,
+ DPAA2_MAC_NUM_ETH_CTRL_STATS);
+ dpaa2_mac_clear_stats(mac, &mac->eth_mac_stats,
+ DPAA2_MAC_NUM_ETH_MAC_STATS);
+ }
+
dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle);
if (mac->fw_node)
fwnode_handle_put(mac->fw_node);
}
+static void dpaa2_mac_transfer_stats(const struct dpmac_counter *counters,
+ size_t num_counters, void *s,
+ __le64 *cnt_values)
+{
+ for (size_t i = 0; i < num_counters; i++) {
+ u64 *p = s + counters[i].offset;
+
+ *p = le64_to_cpu(cnt_values[i]);
+ }
+}
+
+static const struct ethtool_rmon_hist_range dpaa2_mac_rmon_ranges[] = {
+ { 64, 64 },
+ { 65, 127 },
+ { 128, 255 },
+ { 256, 511 },
+ { 512, 1023 },
+ { 1024, 1518 },
+ { 1519, DPAA2_ETH_MFL },
+ {},
+};
+
+static void dpaa2_mac_get_standard_stats(struct dpaa2_mac *mac,
+ struct dpaa2_mac_stats *stats,
+ size_t num_cnt,
+ const struct dpmac_counter *counters,
+ void *s)
+{
+ struct device *dev = mac->net_dev->dev.parent;
+ struct fsl_mc_device *dpmac_dev = mac->mc_dev;
+ size_t values_size = num_cnt * sizeof(u64);
+ int err;
+
+ if (!(mac->features & DPAA2_MAC_FEATURE_STANDARD_STATS))
+ return;
+
+ if (!stats->idx_dma_mem || !stats->values_dma_mem)
+ return;
+
+ dma_sync_single_for_device(dev, stats->values_iova, values_size,
+ DMA_FROM_DEVICE);
+
+ err = dpmac_get_statistics(mac->mc_io, 0, dpmac_dev->mc_handle,
+ stats->idx_iova, stats->values_iova,
+ num_cnt);
+ if (err) {
+ netdev_err(mac->net_dev, "%s: dpmac_get_statistics() = %d\n",
+ __func__, err);
+ return;
+ }
+
+ dma_sync_single_for_cpu(dev, stats->values_iova, values_size,
+ DMA_FROM_DEVICE);
+
+ dpaa2_mac_transfer_stats(counters, num_cnt, s, stats->values_dma_mem);
+}
+
+void dpaa2_mac_get_rmon_stats(struct dpaa2_mac *mac,
+ struct ethtool_rmon_stats *s,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ if (s->src != ETHTOOL_MAC_STATS_SRC_AGGREGATE)
+ return;
+
+ dpaa2_mac_get_standard_stats(mac, &mac->rmon_stats,
+ DPAA2_MAC_NUM_RMON_STATS,
+ dpaa2_mac_rmon_stats, s);
+
+ *ranges = dpaa2_mac_rmon_ranges;
+}
+
+void dpaa2_mac_get_pause_stats(struct dpaa2_mac *mac,
+ struct ethtool_pause_stats *s)
+{
+ if (s->src != ETHTOOL_MAC_STATS_SRC_AGGREGATE)
+ return;
+
+ dpaa2_mac_get_standard_stats(mac, &mac->pause_stats,
+ DPAA2_MAC_NUM_PAUSE_STATS,
+ dpaa2_mac_pause_stats, s);
+}
+
+void dpaa2_mac_get_ctrl_stats(struct dpaa2_mac *mac,
+ struct ethtool_eth_ctrl_stats *s)
+{
+ if (s->src != ETHTOOL_MAC_STATS_SRC_AGGREGATE)
+ return;
+
+ dpaa2_mac_get_standard_stats(mac, &mac->eth_ctrl_stats,
+ DPAA2_MAC_NUM_ETH_CTRL_STATS,
+ dpaa2_mac_eth_ctrl_stats, s);
+}
+
+void dpaa2_mac_get_eth_mac_stats(struct dpaa2_mac *mac,
+ struct ethtool_eth_mac_stats *s)
+{
+ if (s->src != ETHTOOL_MAC_STATS_SRC_AGGREGATE)
+ return;
+
+ dpaa2_mac_get_standard_stats(mac, &mac->eth_mac_stats,
+ DPAA2_MAC_NUM_ETH_MAC_STATS,
+ dpaa2_mac_eth_mac_stats, s);
+}
+
int dpaa2_mac_get_sset_count(void)
{
return DPAA2_MAC_NUM_ETHTOOL_STATS;
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
index 6f4981627961..98c725f609e9 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
@@ -36,6 +36,10 @@ struct dpaa2_mac {
struct phy *serdes_phy;
struct dpaa2_mac_stats ethtool_stats;
+ struct dpaa2_mac_stats rmon_stats;
+ struct dpaa2_mac_stats pause_stats;
+ struct dpaa2_mac_stats eth_ctrl_stats;
+ struct dpaa2_mac_stats eth_mac_stats;
};
static inline bool dpaa2_mac_is_type_phy(struct dpaa2_mac *mac)
@@ -61,6 +65,19 @@ void dpaa2_mac_get_strings(u8 **data);
void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data);
+void dpaa2_mac_get_rmon_stats(struct dpaa2_mac *mac,
+ struct ethtool_rmon_stats *s,
+ const struct ethtool_rmon_hist_range **ranges);
+
+void dpaa2_mac_get_pause_stats(struct dpaa2_mac *mac,
+ struct ethtool_pause_stats *s);
+
+void dpaa2_mac_get_ctrl_stats(struct dpaa2_mac *mac,
+ struct ethtool_eth_ctrl_stats *s);
+
+void dpaa2_mac_get_eth_mac_stats(struct dpaa2_mac *mac,
+ struct ethtool_eth_mac_stats *s);
+
void dpaa2_mac_start(struct dpaa2_mac *mac);
void dpaa2_mac_stop(struct dpaa2_mac *mac);
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c
index a888f6e6e9b0..f5d9321c7ef9 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c
@@ -3,7 +3,7 @@
* DPAA2 Ethernet Switch ethtool support
*
* Copyright 2014-2016 Freescale Semiconductor Inc.
- * Copyright 2017-2018 NXP
+ * Copyright 2017-2018, 2024-2026 NXP
*
*/
@@ -210,6 +210,49 @@ static void dpaa2_switch_ethtool_get_stats(struct net_device *netdev,
mutex_unlock(&port_priv->mac_lock);
}
+static void
+dpaa2_switch_get_rmon_stats(struct net_device *netdev,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ struct ethsw_port_priv *port_priv = netdev_priv(netdev);
+
+ mutex_lock(&port_priv->mac_lock);
+
+ if (dpaa2_switch_port_has_mac(port_priv))
+ dpaa2_mac_get_rmon_stats(port_priv->mac, rmon_stats, ranges);
+
+ mutex_unlock(&port_priv->mac_lock);
+}
+
+static void
+dpaa2_switch_get_ctrl_stats(struct net_device *net_dev,
+ struct ethtool_eth_ctrl_stats *ctrl_stats)
+{
+ struct ethsw_port_priv *port_priv = netdev_priv(net_dev);
+
+ mutex_lock(&port_priv->mac_lock);
+
+ if (dpaa2_switch_port_has_mac(port_priv))
+ dpaa2_mac_get_ctrl_stats(port_priv->mac, ctrl_stats);
+
+ mutex_unlock(&port_priv->mac_lock);
+}
+
+static void
+dpaa2_switch_get_eth_mac_stats(struct net_device *net_dev,
+ struct ethtool_eth_mac_stats *eth_mac_stats)
+{
+ struct ethsw_port_priv *port_priv = netdev_priv(net_dev);
+
+ mutex_lock(&port_priv->mac_lock);
+
+ if (dpaa2_switch_port_has_mac(port_priv))
+ dpaa2_mac_get_eth_mac_stats(port_priv->mac, eth_mac_stats);
+
+ mutex_unlock(&port_priv->mac_lock);
+}
+
const struct ethtool_ops dpaa2_switch_port_ethtool_ops = {
.get_drvinfo = dpaa2_switch_get_drvinfo,
.get_link = ethtool_op_get_link,
@@ -218,4 +261,7 @@ const struct ethtool_ops dpaa2_switch_port_ethtool_ops = {
.get_strings = dpaa2_switch_ethtool_get_strings,
.get_ethtool_stats = dpaa2_switch_ethtool_get_stats,
.get_sset_count = dpaa2_switch_ethtool_get_sset_count,
+ .get_rmon_stats = dpaa2_switch_get_rmon_stats,
+ .get_eth_ctrl_stats = dpaa2_switch_get_ctrl_stats,
+ .get_eth_mac_stats = dpaa2_switch_get_eth_mac_stats,
};
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics
2026-03-23 11:50 ` [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
@ 2026-03-25 13:47 ` Ioana Ciornei
0 siblings, 0 replies; 6+ messages in thread
From: Ioana Ciornei @ 2026-03-25 13:47 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel
On Mon, Mar 23, 2026 at 01:50:39PM +0200, Ioana Ciornei wrote:
> Take advantage of all the newly added MAC counters available through the
> MC API and export them through the standard statistics structures -
> rmon, eth-ctrl, eth-mac and pause.
>
> A new version based feature is added into dpaa2-mac -
> DPAA2_MAC_FEATURE_STANDARD_STATS - and based on the two memory zones
> needed for gathering the MAC counters are setup for each statistics
> group.
>
> The dpmac_counter structure is extended with a new field - size_t offset
> - which is being used to instruct the dpaa2_mac_transfer_stats()
> function where exactly to store a counter value inside the standard
> statistics structure.
>
> The newly added support is used both in the dpaa2-eth driver as well as
> the dpaa2-switch one.
>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
> Changes in v5:
> - use DPMAC_CNT_ING_UNDERSIZED for the rmon etherStatsUndersizePkts
> counter
> Changes in v4:
> - add dma_sync_single_for_device before calling the MC API
> Changes in v3:
> - reduce the number of lines that have more than 80 chars
> Changes in v2:
> - none
>
> .../ethernet/freescale/dpaa2/dpaa2-ethtool.c | 61 ++++-
> .../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 214 ++++++++++++++++++
> .../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 17 ++
> .../freescale/dpaa2/dpaa2-switch-ethtool.c | 48 +++-
> 4 files changed, 338 insertions(+), 2 deletions(-)
>
(...)
> +static const struct dpmac_counter dpaa2_mac_rmon_stats[] = {
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_64, hist[0]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_127, hist[1]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_255, hist[2]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_511, hist[3]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1023, hist[4]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1518, hist[5]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAME_1519_MAX, hist[6]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_64, hist_tx[0]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_127, hist_tx[1]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_255, hist_tx[2]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_511, hist_tx[3]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1023, hist_tx[4]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1518, hist_tx[5]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_EGR_FRAME_1519_MAX, hist_tx[6]),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_UNDERSIZED, undersize_pkts),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_OVERSIZED, oversize_pkts),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_FRAG, fragments),
> + DPMAC_RMON_COUNTER(DPMAC_CNT_ING_JABBER, jabbers),
> +};
The AI still gives here the following feedback:
According to RFC 2819, the etherStatsUndersizePkts counter tracks the
number of undersized packets received. Should this map to an ingress
counter rather than the egress counter DPMAC_CNT_EGR_UNDERSIZED used
here?
Jakub Kicinski raised this concern in v4 review (Fri, 20 Mar 2026):
https://lore.kernel.org/netdev/20260320191943.2325cf38@kernel.org/
As it can be seen above, in v5 I changed the counter used to be the one
for the ingress side. This is not an issue, from my point of view.
(...)
> const struct ethtool_ops dpaa2_switch_port_ethtool_ops = {
> .get_drvinfo = dpaa2_switch_get_drvinfo,
> .get_link = ethtool_op_get_link,
> @@ -218,4 +261,7 @@ const struct ethtool_ops dpaa2_switch_port_ethtool_ops = {
> .get_strings = dpaa2_switch_ethtool_get_strings,
> .get_ethtool_stats = dpaa2_switch_ethtool_get_stats,
> .get_sset_count = dpaa2_switch_ethtool_get_sset_count,
> + .get_rmon_stats = dpaa2_switch_get_rmon_stats,
> + .get_eth_ctrl_stats = dpaa2_switch_get_ctrl_stats,
> + .get_eth_mac_stats = dpaa2_switch_get_eth_mac_stats,
> };
I know that the AI complains about the lack of the .get_pause_stats()
callback in the dpaa2-switch driver and the fact that memory is
alocated for the pause statistics is not actually used.
Since the dpaa2-switch does not currently expose pause configuration, I
also didn't expose the pause statistics. I also didn't want to pollute
this set by adding more unrelated changes to the dpaa2-switch. Hope
that's ok.
Ioana
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics
2026-03-23 11:50 [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
` (2 preceding siblings ...)
2026-03-23 11:50 ` [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
@ 2026-03-26 12:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-26 12:00 UTC (permalink / raw)
To: Ioana Ciornei
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
linux-kernel
Hello:
This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 23 Mar 2026 13:50:36 +0200 you wrote:
> This patch set adds support for standard ethtool statistics - rmon,
> eth-ctrl, eth-mac and pause - to dpaa2-mac and its users dpaa2-eth and
> dpaa2-switch.
>
> The first patch extends the firmware APIs related to MAC counters and
> adds dpmac_get_statistics() which can be used to retrieve multiple counter
> values through a single firmware call.
>
> [...]
Here is the summary with links:
- [net-next,v5,1/3] net: dpaa2-mac: extend APIs related to statistics
https://git.kernel.org/netdev/net-next/c/fbf3fecf6ae1
- [net-next,v5,2/3] net: dpaa2-mac: retrieve MAC statistics in one firmware command
https://git.kernel.org/netdev/net-next/c/d369154d9d7f
- [net-next,v5,3/3] net: dpaa2-mac: export standard statistics
https://git.kernel.org/netdev/net-next/c/dd1d4ccb8602
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-26 12:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 11:50 [PATCH net-next v5 0/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 1/3] net: dpaa2-mac: extend APIs related to statistics Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 2/3] net: dpaa2-mac: retrieve MAC statistics in one firmware command Ioana Ciornei
2026-03-23 11:50 ` [PATCH net-next v5 3/3] net: dpaa2-mac: export standard statistics Ioana Ciornei
2026-03-25 13:47 ` Ioana Ciornei
2026-03-26 12:00 ` [PATCH net-next v5 0/3] " patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox