DPDK patches and discussions
 help / color / mirror / Atom feed
From: vanshika.shukla@nxp.com
To: dev@dpdk.org, Gagandeep Singh <g.singh@nxp.com>,
	Sachin Saxena <sachin.saxena@nxp.com>,
	Vanshika Shukla <vanshika.shukla@nxp.com>
Cc: Apeksha Gupta <apeksha.gupta@nxp.com>
Subject: [v1 05/12] net/enetc: Add basic statistics
Date: Fri, 18 Oct 2024 12:56:37 +0530	[thread overview]
Message-ID: <20241018072644.2379012-6-vanshika.shukla@nxp.com> (raw)
In-Reply-To: <20241018072644.2379012-1-vanshika.shukla@nxp.com>

From: Vanshika Shukla <vanshika.shukla@nxp.com>

Introduces basic statistics collection for ENETC4 PMD, including:

- Packet transmit/receive counts
- Byte transmit/receive counts
- Error counters (TX/RX drops, errors)

Signed-off-by: Apeksha Gupta <apeksha.gupta@nxp.com>
Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 doc/guides/nics/features/enetc4.ini |  1 +
 drivers/net/enetc/base/enetc4_hw.h  |  7 +++++
 drivers/net/enetc/base/enetc_hw.h   |  5 +++-
 drivers/net/enetc/enetc4_ethdev.c   | 42 +++++++++++++++++++++++++++++
 drivers/net/enetc/enetc4_vf.c       | 24 +++++++++++++++++
 5 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/enetc4.ini b/doc/guides/nics/features/enetc4.ini
index 55b3b95953..e814852d2d 100644
--- a/doc/guides/nics/features/enetc4.ini
+++ b/doc/guides/nics/features/enetc4.ini
@@ -4,6 +4,7 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Basic stats          = Y
 L3 checksum offload  = Y
 L4 checksum offload  = Y
 Queue start/stop     = Y
diff --git a/drivers/net/enetc/base/enetc4_hw.h b/drivers/net/enetc/base/enetc4_hw.h
index 114d27f34b..874cdc4775 100644
--- a/drivers/net/enetc/base/enetc4_hw.h
+++ b/drivers/net/enetc/base/enetc4_hw.h
@@ -103,6 +103,13 @@
 #define IFMODE_SGMII			5
 #define PM_IF_MODE_ENA			BIT(15)
 
+/* Station interface statistics */
+#define ENETC4_SIROCT0           0x300
+#define ENETC4_SIRFRM0           0x308
+#define ENETC4_SITOCT0           0x320
+#define ENETC4_SITFRM0           0x328
+#define ENETC4_SITDFCR           0x340
+
 /* general register accessors */
 #define enetc4_rd_reg(reg)	rte_read32((void *)(reg))
 #define enetc4_wr_reg(reg, val)  rte_write32((val), (void *)(reg))
diff --git a/drivers/net/enetc/base/enetc_hw.h b/drivers/net/enetc/base/enetc_hw.h
index 3cdfe23fc0..3208d91bc5 100644
--- a/drivers/net/enetc/base/enetc_hw.h
+++ b/drivers/net/enetc/base/enetc_hw.h
@@ -278,7 +278,10 @@ union enetc_rx_bd {
 		union {
 			struct {
 				uint16_t flags;
-				uint16_t error;
+				uint8_t error;
+				uint8_t resv:6;
+				uint8_t r:1;
+				uint8_t f:1;
 			};
 			uint32_t lstatus;
 		};
diff --git a/drivers/net/enetc/enetc4_ethdev.c b/drivers/net/enetc/enetc4_ethdev.c
index 02f048aa3c..2db45ecf0c 100644
--- a/drivers/net/enetc/enetc4_ethdev.c
+++ b/drivers/net/enetc/enetc4_ethdev.c
@@ -484,6 +484,46 @@ enetc4_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 	rte_free(rx_ring);
 }
 
+static
+int enetc4_stats_get(struct rte_eth_dev *dev,
+		    struct rte_eth_stats *stats)
+{
+	struct enetc_eth_hw *hw =
+		ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct enetc_hw *enetc_hw = &hw->hw;
+
+	/*
+	 * Total received packets, bad + good, if we want to get counters
+	 * of only good received packets then use ENETC4_PM_RFRM,
+	 * ENETC4_PM_TFRM registers.
+	 */
+	stats->ipackets = enetc4_port_rd(enetc_hw, ENETC4_PM_RPKT(0));
+	stats->opackets = enetc4_port_rd(enetc_hw, ENETC4_PM_TPKT(0));
+	stats->ibytes =  enetc4_port_rd(enetc_hw, ENETC4_PM_REOCT(0));
+	stats->obytes = enetc4_port_rd(enetc_hw, ENETC4_PM_TEOCT(0));
+	/*
+	 * Dropped + Truncated packets, use ENETC4_PM_RDRNTP(0) for without
+	 * truncated packets
+	 */
+	stats->imissed = enetc4_port_rd(enetc_hw, ENETC4_PM_RDRP(0));
+	stats->ierrors = enetc4_port_rd(enetc_hw, ENETC4_PM_RERR(0));
+	stats->oerrors = enetc4_port_rd(enetc_hw, ENETC4_PM_TERR(0));
+
+	return 0;
+}
+
+static int
+enetc4_stats_reset(struct rte_eth_dev *dev)
+{
+	struct enetc_eth_hw *hw =
+		ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct enetc_hw *enetc_hw = &hw->hw;
+
+	enetc4_port_wr(enetc_hw, ENETC4_PM0_STAT_CONFIG, ENETC4_CLEAR_STATS);
+
+	return 0;
+}
+
 int
 enetc4_dev_close(struct rte_eth_dev *dev)
 {
@@ -668,6 +708,8 @@ static const struct eth_dev_ops enetc4_ops = {
 	.dev_stop             = enetc4_dev_stop,
 	.dev_close            = enetc4_dev_close,
 	.dev_infos_get        = enetc4_dev_infos_get,
+	.stats_get            = enetc4_stats_get,
+	.stats_reset          = enetc4_stats_reset,
 	.rx_queue_setup       = enetc4_rx_queue_setup,
 	.rx_queue_start       = enetc4_rx_queue_start,
 	.rx_queue_stop        = enetc4_rx_queue_stop,
diff --git a/drivers/net/enetc/enetc4_vf.c b/drivers/net/enetc/enetc4_vf.c
index 0c68229a8d..0d35fc2e1c 100644
--- a/drivers/net/enetc/enetc4_vf.c
+++ b/drivers/net/enetc/enetc4_vf.c
@@ -26,6 +26,29 @@ enetc4_vf_dev_start(struct rte_eth_dev *dev __rte_unused)
 	return 0;
 }
 
+static int
+enetc4_vf_stats_get(struct rte_eth_dev *dev,
+		    struct rte_eth_stats *stats)
+{
+	struct enetc_eth_hw *hw =
+		ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct enetc_hw *enetc_hw = &hw->hw;
+	struct enetc_bdr *rx_ring;
+	uint8_t i;
+
+	PMD_INIT_FUNC_TRACE();
+	stats->ipackets = enetc4_rd(enetc_hw, ENETC4_SIRFRM0);
+	stats->opackets = enetc4_rd(enetc_hw, ENETC4_SITFRM0);
+	stats->ibytes = enetc4_rd(enetc_hw, ENETC4_SIROCT0);
+	stats->obytes = enetc4_rd(enetc_hw, ENETC4_SITOCT0);
+	stats->oerrors = enetc4_rd(enetc_hw, ENETC4_SITDFCR);
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rx_ring = dev->data->rx_queues[i];
+		stats->ierrors += rx_ring->ierrors;
+	}
+	return 0;
+}
+
 /*
  * The set of PCI devices this driver supports
  */
@@ -41,6 +64,7 @@ static const struct eth_dev_ops enetc4_vf_ops = {
 	.dev_stop             = enetc4_vf_dev_stop,
 	.dev_close            = enetc4_dev_close,
 	.dev_infos_get        = enetc4_dev_infos_get,
+	.stats_get            = enetc4_vf_stats_get,
 	.rx_queue_setup       = enetc4_rx_queue_setup,
 	.rx_queue_start       = enetc4_rx_queue_start,
 	.rx_queue_stop        = enetc4_rx_queue_stop,
-- 
2.25.1


  parent reply	other threads:[~2024-10-18  7:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18  7:26 [v1 00/12] ENETC4 PMD support vanshika.shukla
2024-10-18  7:26 ` [v1 01/12] net/enetc: Add initial ENETC4 PMD driver support vanshika.shukla
2024-10-18  7:26 ` [v1 02/12] net/enetc: Add RX and TX queue APIs for ENETC4 PMD vanshika.shukla
2024-10-18  7:26 ` [v1 03/12] net/enetc: Optimize ENETC4 data path vanshika.shukla
2024-10-18  7:26 ` [v1 04/12] net/enetc: Add TX checksum offload and RX checksum validation vanshika.shukla
2024-10-18  7:26 ` vanshika.shukla [this message]
2024-10-18  7:26 ` [v1 06/12] net/enetc: Add packet type parsing support vanshika.shukla
2024-10-18  7:26 ` [v1 07/12] net/enetc: Add support for multiple queues with RSS vanshika.shukla
2024-10-18  7:26 ` [v1 08/12] net/enetc: Add VF to PF messaging support and primary MAC setup vanshika.shukla
2024-10-18  7:26 ` [v1 09/12] net/enetc: Add multicast and promiscuous mode support vanshika.shukla
2024-10-18  7:26 ` [v1 10/12] net/enetc: Add link speed and status support vanshika.shukla
2024-10-18  7:26 ` [v1 11/12] net/enetc: Add link status notification support vanshika.shukla
2024-10-18  7:26 ` [v1 12/12] net/enetc: Add MAC and VLAN filter support vanshika.shukla

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=20241018072644.2379012-6-vanshika.shukla@nxp.com \
    --to=vanshika.shukla@nxp.com \
    --cc=apeksha.gupta@nxp.com \
    --cc=dev@dpdk.org \
    --cc=g.singh@nxp.com \
    --cc=sachin.saxena@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).