net: dpaa2-mac: export standard statistics
Ioana Ciornei
maintainerv5 cover net: dpaa2-mac: export standard statistics
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(-)
Signature · 1 line
2.25.1
Ioana Ciornei
maintainerPATCH v5 1/3 net: dpaa2-mac: extend APIs related to statistics
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.
---
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(-)
drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h +10 -1
@@ -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 */
drivers/net/ethernet/freescale/dpaa2/dpmac.c +30 -1
@@ -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); +}
drivers/net/ethernet/freescale/dpaa2/dpmac.h +92 -2
115 lines not on this page · raw message
Signature · 1 line
2.25.1
Ioana Ciornei
maintainerPATCH v5 2/3 net: dpaa2-mac: retrieve MAC statistics in one firmware command
In reply to Ioana CiorneiThe 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.
---
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(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +162 -39
@@ -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);
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h +9 -1
@@ -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)
Signature · 1 line
2.25.1
Ioana Ciornei
maintainerPATCH v5 3/3 net: dpaa2-mac: export standard statistics
In reply to Ioana CiorneiTake 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.
---
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(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c +60 -1
@@ -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, };
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +214 -0
263 lines not on this page · raw message
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h +17 -0
@@ -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);
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c +47 -1
64 lines not on this page · raw message
Signature · 1 line
2.25.1
Ioana Ciornei
maintainerQuoted 35 lines · Ioana Ciornei
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_counterstructure is extended with a new field -size_toffset
- which is being used to instruct thedpaa2_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 <[email protected]>---
Changes in v5:
- useDPMAC_CNT_ING_UNDERSIZEDfor the rmon etherStatsUndersizePkts counter
Changes in v4:
- adddma_sync_single_for_devicebefore 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(-)
(...)
Quoted 10 lines
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +10
-0+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 ]),
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c static const struct dpmac_counter dpaa2_mac_ethtool_stats[] = { · line 110
Quoted 10 lines
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +10
-0+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/[email protected]/
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.
(...)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c const struct ethtool_ops dpaa2_switch_port_ethtool_ops = { · line 267
Quoted 11 lines
const struct
ethtool_opsdpaa2_switch_port_ethtool_ops= {drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c +3
-0.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
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html