From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 50A3B4240B;
	Wed, 18 Jan 2023 09:55:47 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 40D4942DC0;
	Wed, 18 Jan 2023 09:54:13 +0100 (CET)
Received: from mga18.intel.com (mga18.intel.com [134.134.136.126])
 by mails.dpdk.org (Postfix) with ESMTP id 605EE42D7F
 for <dev@dpdk.org>; Wed, 18 Jan 2023 09:54:07 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1674032047; x=1705568047;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=Elf2YhyGqtGW7YZYWOTr+tL1ay7V7IkCL2R8R+y5lc0=;
 b=GhH5OyvNvmnD0JwcswV/LOYPJVCae99Qw69rTjbkbeOYOVrcx8pHQHS/
 JFfWQ2iab97skeh81utiwlu9l7Wyj8ZPdYt4olj5kiqZAn3Ux7QwCQmUp
 +rSGchSeuXMYbfyre4F0SkDcEik4m3Y246I5Po5BevynVsDpPA4QBufip
 bXqR9frAydu+Uqtf8pMTPcO65jbI353oaGyKtSjkWoBg2bTGwfFYKj3L7
 5VF1cnD0G8fPaEtEyKf1UtOjcVH6yzuJWv2bqh+LlArRJfO2sqUkSKY0B
 7Wv7fqclV7a65FWpPEC/ituZhicONACa/FfK7/n21rOHop6AIuVwY/pk/ A==;
X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="308498214"
X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="308498214"
Received: from fmsmga007.fm.intel.com ([10.253.24.52])
 by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 18 Jan 2023 00:53:59 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="661632116"
X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="661632116"
Received: from dpdk-mingxial-01.sh.intel.com ([10.67.119.167])
 by fmsmga007.fm.intel.com with ESMTP; 18 Jan 2023 00:53:57 -0800
From: Mingxia Liu <mingxia.liu@intel.com>
To: dev@dpdk.org, qi.z.zhang@intel.com, jingjing.wu@intel.com,
 beilei.xing@intel.com
Cc: Mingxia Liu <mingxia.liu@intel.com>
Subject: [PATCH v4 21/21] net/cpfl: add xstats ops
Date: Wed, 18 Jan 2023 07:57:38 +0000
Message-Id: <20230118075738.904616-22-mingxia.liu@intel.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20230118075738.904616-1-mingxia.liu@intel.com>
References: <20230113081931.221576-1-mingxia.liu@intel.com>
 <20230118075738.904616-1-mingxia.liu@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add support for these device ops:
- dev_xstats_get
- dev_xstats_get_names
- dev_xstats_reset

Signed-off-by: Mingxia Liu <mingxia.liu@intel.com>
---
 drivers/net/cpfl/cpfl_ethdev.c | 80 ++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
index ab427fcc0b..f178f3fbb8 100644
--- a/drivers/net/cpfl/cpfl_ethdev.c
+++ b/drivers/net/cpfl/cpfl_ethdev.c
@@ -80,6 +80,30 @@ static const uint64_t cpfl_ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP |
 			  RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
 			  RTE_ETH_RSS_FRAG_IPV6;
 
+struct rte_cpfl_xstats_name_off {
+	char name[RTE_ETH_XSTATS_NAME_SIZE];
+	unsigned int offset;
+};
+
+static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
+	{"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
+	{"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats, rx_unicast)},
+	{"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats, rx_multicast)},
+	{"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, rx_broadcast)},
+	{"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats, rx_discards)},
+	{"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
+	{"rx_unknown_protocol_packets", offsetof(struct virtchnl2_vport_stats,
+						 rx_unknown_protocol)},
+	{"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
+	{"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats, tx_unicast)},
+	{"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats, tx_multicast)},
+	{"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, tx_broadcast)},
+	{"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats, tx_discards)},
+	{"tx_error_packets", offsetof(struct virtchnl2_vport_stats, tx_errors)}};
+
+#define CPFL_NB_XSTATS (sizeof(rte_cpfl_stats_strings) / \
+		sizeof(rte_cpfl_stats_strings[0]))
+
 static int
 cpfl_dev_link_update(struct rte_eth_dev *dev,
 		     __rte_unused int wait_to_complete)
@@ -312,6 +336,59 @@ cpfl_dev_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev)
+{
+	cpfl_dev_stats_reset(dev);
+	return 0;
+}
+
+static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
+			       struct rte_eth_xstat *xstats, unsigned int n)
+{
+	struct idpf_vport *vport =
+		(struct idpf_vport *)dev->data->dev_private;
+	struct virtchnl2_vport_stats *pstats = NULL;
+	unsigned int i;
+	int ret;
+
+	if (n < CPFL_NB_XSTATS)
+		return CPFL_NB_XSTATS;
+
+	if (!xstats)
+		return 0;
+
+	ret = idpf_query_stats(vport, &pstats);
+	if (ret) {
+		PMD_DRV_LOG(ERR, "Get statistics failed");
+		return 0;
+	}
+
+	idpf_update_stats(&vport->eth_stats_offset, pstats);
+
+	/* loop over xstats array and values from pstats */
+	for (i = 0; i < CPFL_NB_XSTATS; i++) {
+		xstats[i].id = i;
+		xstats[i].value = *(uint64_t *)(((char *)pstats) +
+			rte_cpfl_stats_strings[i].offset);
+	}
+	return CPFL_NB_XSTATS;
+}
+
+static int cpfl_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
+				     struct rte_eth_xstat_name *xstats_names,
+				     __rte_unused unsigned int limit)
+{
+	unsigned int i;
+
+	if (xstats_names)
+		for (i = 0; i < CPFL_NB_XSTATS; i++) {
+			snprintf(xstats_names[i].name,
+				 sizeof(xstats_names[i].name),
+				 "%s", rte_cpfl_stats_strings[i].name);
+		}
+	return CPFL_NB_XSTATS;
+}
+
 static int cpfl_config_rss_hf(struct idpf_vport *vport, uint64_t rss_hf)
 {
 	uint64_t hena = 0, valid_rss_hf = 0;
@@ -1157,6 +1234,9 @@ static const struct eth_dev_ops cpfl_eth_dev_ops = {
 	.reta_query			= cpfl_rss_reta_query,
 	.rss_hash_update		= cpfl_rss_hash_update,
 	.rss_hash_conf_get		= cpfl_rss_hash_conf_get,
+	.xstats_get			= cpfl_dev_xstats_get,
+	.xstats_get_names		= cpfl_dev_xstats_get_names,
+	.xstats_reset			= cpfl_dev_xstats_reset,
 };
 
 static uint16_t
-- 
2.25.1