DPDK patches and discussions
 help / color / mirror / Atom feed
From: Zaiyu Wang <zaiyuwang@trustnetic.com>
To: dev@dpdk.org
Cc: Zaiyu Wang <zaiyuwang@trustnetic.com>,
	Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH 11/15] net/ngbe: add stats and xstats ops for VF device
Date: Thu,  9 Jan 2025 12:02:21 +0800	[thread overview]
Message-ID: <20250109040227.1016-12-zaiyuwang@trustnetic.com> (raw)
In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com>

Add support to get stats and extended stats by reading hardware
registers

Signed-off-by: Zaiyu Wang <zaiyuwang@trustnetic.com>
---
 doc/guides/nics/features/ngbe_vf.ini |   2 +
 drivers/net/ngbe/base/ngbe_vf.h      |  32 +++++++
 drivers/net/ngbe/ngbe_ethdev_vf.c    | 137 +++++++++++++++++++++++++++
 3 files changed, 171 insertions(+)

diff --git a/doc/guides/nics/features/ngbe_vf.ini b/doc/guides/nics/features/ngbe_vf.ini
index b5c4981195..0c26db73f9 100644
--- a/doc/guides/nics/features/ngbe_vf.ini
+++ b/doc/guides/nics/features/ngbe_vf.ini
@@ -24,6 +24,8 @@ Rx descriptor status = Y
 Tx descriptor status = Y
 Inner L3 checksum    = P
 Inner L4 checksum    = P
+Basic stats          = Y
+Extended stats       = Y
 Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
diff --git a/drivers/net/ngbe/base/ngbe_vf.h b/drivers/net/ngbe/base/ngbe_vf.h
index 5cf225dd35..abe1655f8e 100644
--- a/drivers/net/ngbe/base/ngbe_vf.h
+++ b/drivers/net/ngbe/base/ngbe_vf.h
@@ -11,6 +11,38 @@
 #define NGBE_VF_MAX_TX_QUEUES	1
 #define NGBE_VF_MAX_RX_QUEUES	1
 
+struct ngbevf_hw_stats {
+	u64 base_vfgprc;
+	u64 base_vfgptc;
+	u64 base_vfgorc;
+	u64 base_vfgotc;
+	u64 base_vfmprc;
+
+	u64 last_vfgprc;
+	u64 last_vfgptc;
+	u64 last_vfgorc;
+	u64 last_vfgotc;
+	u64 last_vfmprc;
+	u64 last_vfbprc;
+	u64 last_vfmptc;
+	u64 last_vfbptc;
+
+	u64 vfgprc;
+	u64 vfgptc;
+	u64 vfgorc;
+	u64 vfgotc;
+	u64 vfmprc;
+	u64 vfbprc;
+	u64 vfmptc;
+	u64 vfbptc;
+
+	u64 saved_reset_vfgprc;
+	u64 saved_reset_vfgptc;
+	u64 saved_reset_vfgorc;
+	u64 saved_reset_vfgotc;
+	u64 saved_reset_vfmprc;
+};
+
 s32 ngbe_init_ops_vf(struct ngbe_hw *hw);
 s32 ngbe_init_hw_vf(struct ngbe_hw *hw);
 s32 ngbe_start_hw_vf(struct ngbe_hw *hw);
diff --git a/drivers/net/ngbe/ngbe_ethdev_vf.c b/drivers/net/ngbe/ngbe_ethdev_vf.c
index 1f3f957d8a..434776b26b 100644
--- a/drivers/net/ngbe/ngbe_ethdev_vf.c
+++ b/drivers/net/ngbe/ngbe_ethdev_vf.c
@@ -67,6 +67,13 @@ static const struct rte_eth_desc_lim tx_desc_lim = {
 
 static const struct eth_dev_ops ngbevf_eth_dev_ops;
 
+static const struct rte_ngbe_xstats_name_off rte_ngbevf_stats_strings[] = {
+	{"rx_multicast_packets", offsetof(struct ngbevf_hw_stats, vfmprc)},
+};
+
+#define NGBEVF_NB_XSTATS (sizeof(rte_ngbevf_stats_strings) /	\
+		sizeof(rte_ngbevf_stats_strings[0]))
+
 /*
  * Negotiate mailbox API version with the PF.
  * After reset API version is always set to the basic one (ngbe_mbox_api_10).
@@ -182,6 +189,9 @@ eth_ngbevf_dev_init(struct rte_eth_dev *eth_dev)
 	/* init_mailbox_params */
 	hw->mbx.init_params(hw);
 
+	/* Reset the hw statistics */
+	ngbevf_dev_stats_reset(eth_dev);
+
 	/* Disable the interrupts for VF */
 	ngbevf_intr_disable(eth_dev);
 
@@ -301,6 +311,128 @@ static struct rte_pci_driver rte_ngbevf_pmd = {
 	.remove = eth_ngbevf_pci_remove,
 };
 
+static int ngbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
+	struct rte_eth_xstat_name *xstats_names, unsigned int limit)
+{
+	unsigned int i;
+
+	if (limit < NGBEVF_NB_XSTATS && xstats_names != NULL)
+		return -ENOMEM;
+
+	if (xstats_names != NULL)
+		for (i = 0; i < NGBEVF_NB_XSTATS; i++)
+			snprintf(xstats_names[i].name,
+				sizeof(xstats_names[i].name),
+				"%s", rte_ngbevf_stats_strings[i].name);
+	return NGBEVF_NB_XSTATS;
+}
+
+static void
+ngbevf_update_stats(struct rte_eth_dev *dev)
+{
+	struct ngbe_hw *hw = ngbe_dev_hw(dev);
+	struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
+			  NGBE_DEV_STATS(dev);
+
+	/* Good Rx packet, include VF loopback */
+	NGBE_UPDCNT32(NGBE_QPRXPKT(0),
+	    hw_stats->last_vfgprc, hw_stats->vfgprc);
+
+	/* Good Rx octets, include VF loopback */
+	NGBE_UPDCNT36(NGBE_QPRXOCTL(0),
+	    hw_stats->last_vfgorc, hw_stats->vfgorc);
+
+	/* Rx Multicst Packet */
+	NGBE_UPDCNT32(NGBE_QPRXMPKT(0),
+	    hw_stats->last_vfmprc, hw_stats->vfmprc);
+
+	/* Rx Broadcast Packet */
+	NGBE_UPDCNT32(NGBE_QPRXBPKT(0),
+	    hw_stats->last_vfbprc, hw_stats->vfbprc);
+
+	hw->rx_loaded = 0;
+
+	/* Good Tx packet, include VF loopback */
+	NGBE_UPDCNT32(NGBE_QPTXPKT(0),
+	    hw_stats->last_vfgptc, hw_stats->vfgptc);
+
+	/* Good Tx octets, include VF loopback */
+	NGBE_UPDCNT36(NGBE_QPTXOCTL(0),
+	    hw_stats->last_vfgotc, hw_stats->vfgotc);
+
+	/* Tx Multicst Packet */
+	NGBE_UPDCNT32(NGBE_QPTXMPKT(0),
+	    hw_stats->last_vfmprc, hw_stats->vfmprc);
+
+	/* Tx Broadcast Packet */
+	NGBE_UPDCNT32(NGBE_QPTXBPKT(0),
+	    hw_stats->last_vfbptc, hw_stats->vfbptc);
+
+	hw->offset_loaded = 0;
+}
+
+static int
+ngbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
+		       unsigned int n)
+{
+	struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
+			NGBE_DEV_STATS(dev);
+	unsigned int i;
+
+	if (n < NGBEVF_NB_XSTATS)
+		return NGBEVF_NB_XSTATS;
+
+	ngbevf_update_stats(dev);
+
+	if (!xstats)
+		return 0;
+
+	/* Extended stats */
+	for (i = 0; i < NGBEVF_NB_XSTATS; i++) {
+		xstats[i].id = i;
+		xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
+			rte_ngbevf_stats_strings[i].offset);
+	}
+
+	return NGBEVF_NB_XSTATS;
+}
+
+static int
+ngbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
+{
+	struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
+			  NGBE_DEV_STATS(dev);
+
+	ngbevf_update_stats(dev);
+
+	if (stats == NULL)
+		return -EINVAL;
+
+	stats->ipackets = hw_stats->vfgprc;
+	stats->ibytes = hw_stats->vfgorc;
+	stats->opackets = hw_stats->vfgptc;
+	stats->obytes = hw_stats->vfgotc;
+	return 0;
+}
+
+static int
+ngbevf_dev_stats_reset(struct rte_eth_dev *dev)
+{
+	struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
+			NGBE_DEV_STATS(dev);
+
+	/* Sync HW register to the last stats */
+	ngbevf_dev_stats_get(dev, NULL);
+
+	/* reset HW current stats*/
+	hw_stats->vfgprc = 0;
+	hw_stats->vfgorc = 0;
+	hw_stats->vfgptc = 0;
+	hw_stats->vfgotc = 0;
+
+	return 0;
+}
+
 static int
 ngbevf_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
@@ -947,6 +1079,11 @@ ngbevf_dev_interrupt_handler(void *param)
 static const struct eth_dev_ops ngbevf_eth_dev_ops = {
 	.dev_configure        = ngbevf_dev_configure,
 	.link_update          = ngbevf_dev_link_update,
+	.stats_get            = ngbevf_dev_stats_get,
+	.xstats_get           = ngbevf_dev_xstats_get,
+	.stats_reset          = ngbevf_dev_stats_reset,
+	.xstats_reset         = ngbevf_dev_stats_reset,
+	.xstats_get_names     = ngbevf_dev_xstats_get_names,
 	.promiscuous_enable   = ngbevf_dev_promiscuous_enable,
 	.promiscuous_disable  = ngbevf_dev_promiscuous_disable,
 	.allmulticast_enable  = ngbevf_dev_allmulticast_enable,
-- 
2.21.0.windows.1


  parent reply	other threads:[~2025-01-09  4:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09  4:02 [PATCH 00/15] net/ngbe: add VF driver support Zaiyu Wang
2025-01-09  4:02 ` [PATCH 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-09  4:02 ` [PATCH 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-09  4:02 ` [PATCH 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-09  4:02 ` [PATCH 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 08/15] net/ngbe: add vlan related ops " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 10/15] net/ngbe: add link update ops " Zaiyu Wang
2025-01-09  4:02 ` Zaiyu Wang [this message]
2025-01-09  4:02 ` [PATCH 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang

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=20250109040227.1016-12-zaiyuwang@trustnetic.com \
    --to=zaiyuwang@trustnetic.com \
    --cc=dev@dpdk.org \
    --cc=jiawenwu@trustnetic.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).