From: Gagandeep Singh <g.singh@nxp.com>
To: dev@dpdk.org, Hemant Agrawal <hemant.agrawal@nxp.com>,
Sachin Saxena <sachin.saxena@nxp.com>
Cc: Apeksha Gupta <apeksha.gupta@nxp.com>,
Vanshika Shukla <vanshika.shukla@nxp.com>
Subject: [PATCH 06/11] net/dpaa2: support dpmac counters in stats
Date: Fri, 30 May 2025 12:43:39 +0530 [thread overview]
Message-ID: <20250530071344.2939434-7-g.singh@nxp.com> (raw)
In-Reply-To: <20250530071344.2939434-1-g.singh@nxp.com>
From: Apeksha Gupta <apeksha.gupta@nxp.com>
Add support of dpmac counters in xstats.
Signed-off-by: Apeksha Gupta <apeksha.gupta@nxp.com>
Signed-off-by: Vanshika Shukla <vanshika.shukla@nxp.com>
---
drivers/net/dpaa2/dpaa2_ethdev.c | 118 ++++++++++++++++++++++++++--
drivers/net/dpaa2/dpaa2_ethdev.h | 12 +++
drivers/net/dpaa2/mc/dpni.c | 29 ++++++-
drivers/net/dpaa2/mc/fsl_dpni.h | 3 +
drivers/net/dpaa2/mc/fsl_dpni_cmd.h | 11 ++-
5 files changed, 163 insertions(+), 10 deletions(-)
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index d17785a6ee..bbf4df69d4 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -106,6 +106,34 @@ static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
{"egress_confirmed_frames", 2, 4},
{"cgr_reject_frames", 4, 0},
{"cgr_reject_bytes", 4, 1},
+ {"mac_rx_64 bytes", 0, 0},
+ {"mac_rx_65-127 bytes", 0, 0},
+ {"mac_rx_128-255 bytes", 0, 0},
+ {"mac_rx_256-511 bytes", 0, 0},
+ {"mac_rx_512-1023 bytes", 0, 0},
+ {"mac_rx_1024-1518 bytes", 0, 0},
+ {"mac_rx_1519-max bytes", 0, 0},
+ {"mac_rx_frags", 0, 0},
+ {"mac_rx_jabber", 0, 0},
+ {"mac_rx_frame discards", 0, 0},
+ {"mac_rx_align errors", 0, 0},
+ {"mac_tx_undersized", 0, 0},
+ {"mac_rx_oversized", 0, 0},
+ {"mac_rx_pause", 0, 0},
+ {"mac_tx_b-pause", 0, 0},
+ {"mac_rx_bytes", 0, 0},
+ {"mac_rx_m-cast", 0, 0},
+ {"mac_rx_b-cast", 0, 0},
+ {"mac_rx_all frames", 0, 0},
+ {"mac_rx_u-cast", 0, 0},
+ {"mac_rx_frame errors", 0, 0},
+ {"mac_tx_bytes", 0, 0},
+ {"mac_tx_m-cast", 0, 0},
+ {"mac_tx_b-cast", 0, 0},
+ {"mac_tx_u-cast", 0, 0},
+ {"mac_tx_frame errors", 0, 0},
+ {"mac_rx_frames ok", 0, 0},
+ {"mac_tx_frames ok", 0, 0},
};
static struct rte_dpaa2_driver rte_dpaa2_pmd;
@@ -1713,16 +1741,67 @@ dpaa2_dev_stats_get(struct rte_eth_dev *dev,
return retcode;
};
+void
+dpaa2_dev_mac_setup_stats(struct rte_eth_dev *dev)
+{
+ struct dpaa2_dev_priv *priv = dev->data->dev_private;
+ uint32_t *cnt_idx;
+ int i;
+
+ priv->cnt_idx_dma_mem = rte_malloc(NULL, DPAA2_MAC_STATS_INDEX_DMA_SIZE,
+ RTE_CACHE_LINE_SIZE);
+ if (!priv->cnt_idx_dma_mem) {
+ DPAA2_PMD_ERR("Failure to allocate memory for mac index");
+ goto out;
+ }
+
+ priv->cnt_values_dma_mem = rte_malloc(NULL, DPAA2_MAC_STATS_VALUE_DMA_SIZE,
+ RTE_CACHE_LINE_SIZE);
+ if (!priv->cnt_values_dma_mem) {
+ DPAA2_PMD_ERR("Failure to allocate memory for mac values");
+ goto err_alloc_values;
+ }
+
+ cnt_idx = priv->cnt_idx_dma_mem;
+ for (i = 0; i < DPAA2_MAC_NUM_STATS; i++)
+ *cnt_idx++ = rte_cpu_to_le_32((uint32_t)i);
+
+ priv->cnt_idx_iova = rte_mem_virt2iova(priv->cnt_idx_dma_mem);
+ if (priv->cnt_idx_iova == RTE_BAD_IOVA) {
+ DPAA2_PMD_ERR("%s: No IOMMU map for count index dma mem(%p)",
+ __func__, priv->cnt_idx_dma_mem);
+ goto err_dma_map;
+ }
+
+ priv->cnt_values_iova = rte_mem_virt2iova(priv->cnt_values_dma_mem);
+ if (priv->cnt_values_iova == RTE_BAD_IOVA) {
+ DPAA2_PMD_ERR("%s: No IOMMU map for count values dma mem(%p)",
+ __func__, priv->cnt_values_dma_mem);
+ goto err_dma_map;
+ }
+
+ return;
+
+err_dma_map:
+ rte_free(priv->cnt_values_dma_mem);
+err_alloc_values:
+ rte_free(priv->cnt_idx_dma_mem);
+out:
+ priv->cnt_idx_dma_mem = NULL;
+ priv->cnt_values_dma_mem = NULL;
+}
+
static int
dpaa2_dev_xstats_get(struct rte_eth_dev *dev,
struct rte_eth_xstat *xstats, unsigned int n)
{
- struct dpaa2_dev_priv *priv = dev->data->dev_private;
struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
- int32_t retcode;
+ unsigned int i = 0, j = 0, num = RTE_DIM(dpaa2_xstats_strings);
+ struct dpaa2_dev_priv *priv = dev->data->dev_private;
union dpni_statistics value[5] = {};
- unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
uint8_t page_id, stats_id;
+ uint64_t *cnt_values;
+ int32_t retcode;
if (n < num)
return num;
@@ -1748,8 +1827,8 @@ dpaa2_dev_xstats_get(struct rte_eth_dev *dev,
if (retcode)
goto err;
- for (i = 0; i < priv->max_cgs; i++) {
- if (!priv->cgid_in_use[i]) {
+ for (j = 0; j < priv->max_cgs; j++) {
+ if (!priv->cgid_in_use[j]) {
/* Get Counters from page_4*/
retcode = dpni_get_statistics(dpni, CMD_PRI_LOW,
priv->token,
@@ -1759,13 +1838,38 @@ dpaa2_dev_xstats_get(struct rte_eth_dev *dev,
break;
}
}
-
- for (i = 0; i < num; i++) {
+ while (i < (num - DPAA2_MAC_NUM_STATS)) {
xstats[i].id = i;
page_id = dpaa2_xstats_strings[i].page_id;
stats_id = dpaa2_xstats_strings[i].stats_id;
xstats[i].value = value[page_id].raw.counter[stats_id];
+ i++;
+ }
+
+ dpaa2_dev_mac_setup_stats(dev);
+ retcode = dpni_get_mac_statistics(dpni, CMD_PRI_LOW, priv->token,
+ priv->cnt_idx_iova, priv->cnt_values_iova,
+ DPAA2_MAC_NUM_STATS);
+ if (retcode) {
+ DPAA2_PMD_WARN("MAC (mac_*) counters are not supported!!");
+ rte_free(priv->cnt_values_dma_mem);
+ rte_free(priv->cnt_idx_dma_mem);
+ while (i >= (num - DPAA2_MAC_NUM_STATS) && i < num) {
+ xstats[i].id = i;
+ xstats[i].value = 0;
+ i++;
+ }
}
+ if (!retcode) {
+ cnt_values = priv->cnt_values_dma_mem;
+ while (i >= (num - DPAA2_MAC_NUM_STATS) && i < num) {
+ /* mac counters value */
+ xstats[i].id = i;
+ xstats[i].value = rte_le_to_cpu_64(*cnt_values++);
+ i++;
+ }
+ }
+
return i;
err:
DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.h b/drivers/net/dpaa2/dpaa2_ethdev.h
index 103fa2ca67..532c257203 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.h
+++ b/drivers/net/dpaa2/dpaa2_ethdev.h
@@ -18,6 +18,7 @@
#include <mc/fsl_dpni.h>
#include <mc/fsl_mc_sys.h>
+#include <mc/fsl_dpmac.h>
#include "base/dpaa2_hw_dpni_annot.h"
@@ -129,6 +130,11 @@
#define DPAA2_PKT_TYPE_VLAN_1 0x0160
#define DPAA2_PKT_TYPE_VLAN_2 0x0260
+/* mac counters */
+#define DPAA2_MAC_NUM_STATS (DPMAC_CNT_EGR_GOOD_FRAME + 1)
+#define DPAA2_MAC_STATS_INDEX_DMA_SIZE (DPAA2_MAC_NUM_STATS * sizeof(uint32_t))
+#define DPAA2_MAC_STATS_VALUE_DMA_SIZE (DPAA2_MAC_NUM_STATS * sizeof(uint64_t))
+
/* Global pool used by driver for SG list TX */
extern struct rte_mempool *dpaa2_tx_sg_pool;
/* Maximum SG segments */
@@ -413,6 +419,10 @@ struct dpaa2_dev_priv {
uint8_t channel_inuse;
/* Stores correction offset for one step timestamping */
uint16_t ptp_correction_offset;
+ /* for mac counters */
+ uint32_t *cnt_idx_dma_mem;
+ uint64_t *cnt_values_dma_mem;
+ uint64_t cnt_idx_iova, cnt_values_iova;
struct dpaa2_dev_flow *curr;
LIST_HEAD(, dpaa2_dev_flow) flows;
@@ -498,4 +508,6 @@ int dpaa2_dev_recycle_qp_setup(struct rte_dpaa2_device *dpaa2_dev,
struct dpaa2_queue **txq,
struct dpaa2_queue **rxq);
+void
+dpaa2_dev_mac_setup_stats(struct rte_eth_dev *dev);
#endif /* _DPAA2_ETHDEV_H */
diff --git a/drivers/net/dpaa2/mc/dpni.c b/drivers/net/dpaa2/mc/dpni.c
index 558f08dc69..f651f29b02 100644
--- a/drivers/net/dpaa2/mc/dpni.c
+++ b/drivers/net/dpaa2/mc/dpni.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
*
* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2016-2023 NXP
+ * Copyright 2016-2025 NXP
*
*/
#include <fsl_mc_sys.h>
@@ -3493,3 +3493,30 @@ int dpni_sp_enable(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
/* send command to MC */
return mc_send_command(mc_io, &cmd);
}
+/**
+ * dpni_get_mac_statistics() - Get statistics on the connected DPMAC objects
+ * @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 dpni_get_mac_statistics(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
+ uint64_t iova_cnt, uint64_t iova_values, uint32_t num_cnt)
+{
+ struct dpni_cmd_get_mac_statistics *cmd_params;
+ struct mc_command cmd = { 0 };
+
+ cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAC_STATISTICS, cmd_flags, token);
+ cmd_params = (struct dpni_cmd_get_mac_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/dpaa2/mc/fsl_dpni.h b/drivers/net/dpaa2/mc/fsl_dpni.h
index 3a5fcfa8a5..2f8125314c 100644
--- a/drivers/net/dpaa2/mc/fsl_dpni.h
+++ b/drivers/net/dpaa2/mc/fsl_dpni.h
@@ -2014,4 +2014,7 @@ int dpni_set_sp_profile(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t to
int dpni_sp_enable(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
uint8_t type, uint8_t en);
+int dpni_get_mac_statistics(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
+ uint64_t iova_cnt, uint64_t iova_values, uint32_t num_cnt);
+
#endif /* __FSL_DPNI_H */
diff --git a/drivers/net/dpaa2/mc/fsl_dpni_cmd.h b/drivers/net/dpaa2/mc/fsl_dpni_cmd.h
index 1152182e34..f653f2c0e4 100644
--- a/drivers/net/dpaa2/mc/fsl_dpni_cmd.h
+++ b/drivers/net/dpaa2/mc/fsl_dpni_cmd.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
*
* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2016-2023 NXP
+ * Copyright 2016-2025 NXP
*
*/
#ifndef _FSL_DPNI_CMD_H
@@ -9,7 +9,7 @@
/* DPNI Version */
#define DPNI_VER_MAJOR 8
-#define DPNI_VER_MINOR 4
+#define DPNI_VER_MINOR 6
#define DPNI_CMD_BASE_VERSION 1
#define DPNI_CMD_VERSION_2 2
@@ -131,6 +131,7 @@
#define DPNI_CMDID_SP_ENABLE DPNI_CMD(0x280)
#define DPNI_CMDID_SET_QUEUE_TX_CONFIRMATION_MODE DPNI_CMD(0x281)
#define DPNI_CMDID_GET_QUEUE_TX_CONFIRMATION_MODE DPNI_CMD(0x282)
+#define DPNI_CMDID_GET_MAC_STATISTICS DPNI_CMD(0x283)
/* Macros for accessing command fields smaller than 1byte */
#define DPNI_MASK(field) \
@@ -1024,5 +1025,11 @@ struct dpni_cmd_sp_enable {
uint8_t en;
};
+struct dpni_cmd_get_mac_statistics {
+ uint64_t iova_cnt;
+ uint64_t iova_values;
+ uint32_t num_cnt;
+};
+
#pragma pack(pop)
#endif /* _FSL_DPNI_CMD_H */
--
2.25.1
next prev parent reply other threads:[~2025-05-30 7:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 7:13 [PATCH 00/11] NXP DPAA2 driver enhancements and fixes Gagandeep Singh
2025-05-30 7:13 ` [PATCH 01/11] net/dpaa2: fix issue of extract buffer preparation Gagandeep Singh
2025-05-30 7:13 ` [PATCH 02/11] net/dpaa2: fix shaper rate Gagandeep Singh
2025-05-30 7:13 ` [PATCH 03/11] bus/fslmc: add DPBP APIs for setting depletion thresholds Gagandeep Singh
2025-05-30 7:13 ` [PATCH 04/11] mempool/dpaa2: use unified VA to IOVA conversion Gagandeep Singh
2025-05-30 7:13 ` [PATCH 05/11] net/dpaa2: add dpmac MC header file Gagandeep Singh
2025-05-30 7:13 ` Gagandeep Singh [this message]
2025-05-30 7:13 ` [PATCH 07/11] net/dpaa2: support dpmac Tx stats Gagandeep Singh
2025-05-30 7:13 ` [PATCH 08/11] net/dpaa2: support dpmac Tx stats in xstats Gagandeep Singh
2025-05-30 7:13 ` [PATCH 09/11] net/dpaa2: retrieve DPNI API version at init time Gagandeep Singh
2025-05-30 7:13 ` [PATCH 10/11] net/dpaa2: setup the speed cap based on the actual MAC Gagandeep Singh
2025-05-30 7:13 ` [PATCH 11/11] net/dpaa2: enable software taildrop for ordered queues Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 00/11] NXP DPAA2 driver enhancements and fixes Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 01/11] net/dpaa2: fix issue of extract buffer preparation Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 02/11] net/dpaa2: fix shaper rate Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 03/11] bus/fslmc: add DPBP APIs for setting depletion thresholds Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 04/11] mempool/dpaa2: use unified VA to IOVA conversion Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 05/11] net/dpaa2: add dpmac MC header file Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 06/11] net/dpaa2: support dpmac counters in stats Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 07/11] net/dpaa2: support dpmac Tx stats Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 08/11] net/dpaa2: support dpmac Tx stats in xstats Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 09/11] net/dpaa2: retrieve DPNI API version at init time Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 10/11] net/dpaa2: setup the speed cap based on the actual MAC Gagandeep Singh
2025-06-02 10:40 ` [PATCH v2 11/11] net/dpaa2: enable software taildrop for ordered queues Gagandeep Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250530071344.2939434-7-g.singh@nxp.com \
--to=g.singh@nxp.com \
--cc=apeksha.gupta@nxp.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
--cc=sachin.saxena@nxp.com \
--cc=vanshika.shukla@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).