DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/nfp: implement xstats functions
@ 2023-05-17  7:33 Chaoyong He
  2023-05-18 11:46 ` Ferruh Yigit
  0 siblings, 1 reply; 2+ messages in thread
From: Chaoyong He @ 2023-05-17  7:33 UTC (permalink / raw)
  To: dev; +Cc: oss-drivers, niklas.soderlund, James Hershaw, Chaoyong He

From: James Hershaw <james.hershaw@corigine.com>

To align the stats collected by nfp_net_xstats_get() to those collected
by the `ethtool -S` command. This includes a number of extended
statistics for both nfp_net and nfp_net_vf devices, as well as MAC
statistics for nfp_net devices only. This does not include extended
statistics for flower representors.

The addresses and names of counters for these statistics are added as an
array.

The various xstats functions for the nfp PMD are implemented in line
with the RTE API.

Signed-off-by: James Hershaw <james.hershaw@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 drivers/net/nfp/nfp_common.c    | 309 ++++++++++++++++++++++++++++++++
 drivers/net/nfp/nfp_common.h    |  20 +++
 drivers/net/nfp/nfp_ctrl.h      |  77 +++++++-
 drivers/net/nfp/nfp_ethdev.c    |  25 +++
 drivers/net/nfp/nfp_ethdev_vf.c |  13 ++
 5 files changed, 443 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index f17632a364..de05fe8e95 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -47,6 +47,7 @@
 #include "nfd3/nfp_nfd3.h"
 #include "nfdk/nfp_nfdk.h"
 
+#include <stdint.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -54,6 +55,121 @@
 #include <stdio.h>
 #include <sys/ioctl.h>
 
+enum nfp_xstat_group {
+	NFP_XSTAT_GROUP_NET,
+	NFP_XSTAT_GROUP_MAC
+};
+struct nfp_xstat {
+	char name[RTE_ETH_XSTATS_NAME_SIZE];
+	int offset;
+	enum nfp_xstat_group group;
+};
+
+#define NFP_XSTAT_NET(_name, _offset) {                 \
+	.name = _name,                                  \
+	.offset = NFP_NET_CFG_STATS_##_offset,          \
+	.group = NFP_XSTAT_GROUP_NET,                   \
+}
+
+#define NFP_XSTAT_MAC(_name, _offset) {                 \
+	.name = _name,                                  \
+	.offset = NFP_MAC_STATS_##_offset,              \
+	.group = NFP_XSTAT_GROUP_MAC,                   \
+}
+
+static const struct nfp_xstat nfp_net_xstats[] = {
+	/**
+	 * Basic xstats available on both VF and PF.
+	 * Note that in case new statistics of group NFP_XSTAT_GROUP_NET
+	 * are added to this array, they must appear before any statistics
+	 * of group NFP_XSTAT_GROUP_MAC.
+	 */
+	NFP_XSTAT_NET("rx_good_packets_mc", RX_MC_FRAMES),
+	NFP_XSTAT_NET("tx_good_packets_mc", TX_MC_FRAMES),
+	NFP_XSTAT_NET("rx_good_packets_bc", RX_BC_FRAMES),
+	NFP_XSTAT_NET("tx_good_packets_bc", TX_BC_FRAMES),
+	NFP_XSTAT_NET("rx_good_bytes_uc", RX_UC_OCTETS),
+	NFP_XSTAT_NET("tx_good_bytes_uc", TX_UC_OCTETS),
+	NFP_XSTAT_NET("rx_good_bytes_mc", RX_MC_OCTETS),
+	NFP_XSTAT_NET("tx_good_bytes_mc", TX_MC_OCTETS),
+	NFP_XSTAT_NET("rx_good_bytes_bc", RX_BC_OCTETS),
+	NFP_XSTAT_NET("tx_good_bytes_bc", TX_BC_OCTETS),
+	NFP_XSTAT_NET("tx_missed_erros", TX_DISCARDS),
+	NFP_XSTAT_NET("bpf_pass_pkts", APP0_FRAMES),
+	NFP_XSTAT_NET("bpf_pass_bytes", APP0_BYTES),
+	NFP_XSTAT_NET("bpf_app1_pkts", APP1_FRAMES),
+	NFP_XSTAT_NET("bpf_app1_bytes", APP1_BYTES),
+	NFP_XSTAT_NET("bpf_app2_pkts", APP2_FRAMES),
+	NFP_XSTAT_NET("bpf_app2_bytes", APP2_BYTES),
+	NFP_XSTAT_NET("bpf_app3_pkts", APP3_FRAMES),
+	NFP_XSTAT_NET("bpf_app3_bytes", APP3_BYTES),
+	/**
+	 * MAC xstats available only on PF. These statistics are not available for VFs as the
+	 * PF is not initialized when the VF is initialized as it is still bound to the kernel
+	 * driver. As such, the PMD cannot obtain a CPP handle and access the rtsym_table in order
+	 * to get the pointer to the start of the MAC statistics counters.
+	 */
+	NFP_XSTAT_MAC("mac.rx_octets", RX_IN_OCTS),
+	NFP_XSTAT_MAC("mac.rx_frame_too_long_errors", RX_FRAME_TOO_LONG_ERRORS),
+	NFP_XSTAT_MAC("mac.rx_range_length_errors", RX_RANGE_LENGTH_ERRORS),
+	NFP_XSTAT_MAC("mac.rx_vlan_received_ok", RX_VLAN_RECEIVED_OK),
+	NFP_XSTAT_MAC("mac.rx_errors", RX_IN_ERRORS),
+	NFP_XSTAT_MAC("mac.rx_broadcast_pkts", RX_IN_BROADCAST_PKTS),
+	NFP_XSTAT_MAC("mac.rx_drop_events", RX_DROP_EVENTS),
+	NFP_XSTAT_MAC("mac.rx_alignment_errors", RX_ALIGNMENT_ERRORS),
+	NFP_XSTAT_MAC("mac.rx_pause_mac_ctrl_frames", RX_PAUSE_MAC_CTRL_FRAMES),
+	NFP_XSTAT_MAC("mac.rx_frames_received_ok", RX_FRAMES_RECEIVED_OK),
+	NFP_XSTAT_MAC("mac.rx_frame_check_sequence_errors", RX_FRAME_CHECK_SEQ_ERRORS),
+	NFP_XSTAT_MAC("mac.rx_unicast_pkts", RX_UNICAST_PKTS),
+	NFP_XSTAT_MAC("mac.rx_multicast_pkts", RX_MULTICAST_PKTS),
+	NFP_XSTAT_MAC("mac.rx_pkts", RX_PKTS),
+	NFP_XSTAT_MAC("mac.rx_undersize_pkts", RX_UNDERSIZE_PKTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_64_octets", RX_PKTS_64_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_65_to_127_octets", RX_PKTS_65_TO_127_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_128_to_255_octets", RX_PKTS_128_TO_255_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_256_to_511_octets", RX_PKTS_256_TO_511_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_512_to_1023_octets", RX_PKTS_512_TO_1023_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_1024_to_1518_octets", RX_PKTS_1024_TO_1518_OCTS),
+	NFP_XSTAT_MAC("mac.rx_pkts_1519_to_max_octets", RX_PKTS_1519_TO_MAX_OCTS),
+	NFP_XSTAT_MAC("mac.rx_jabbers", RX_JABBERS),
+	NFP_XSTAT_MAC("mac.rx_fragments", RX_FRAGMENTS),
+	NFP_XSTAT_MAC("mac.rx_oversize_pkts", RX_OVERSIZE_PKTS),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class0", RX_PAUSE_FRAMES_CLASS0),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class1", RX_PAUSE_FRAMES_CLASS1),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class2", RX_PAUSE_FRAMES_CLASS2),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class3", RX_PAUSE_FRAMES_CLASS3),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class4", RX_PAUSE_FRAMES_CLASS4),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class5", RX_PAUSE_FRAMES_CLASS5),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class6", RX_PAUSE_FRAMES_CLASS6),
+	NFP_XSTAT_MAC("mac.rx_pause_frames_class7", RX_PAUSE_FRAMES_CLASS7),
+	NFP_XSTAT_MAC("mac.rx_mac_ctrl_frames_received", RX_MAC_CTRL_FRAMES_REC),
+	NFP_XSTAT_MAC("mac.rx_mac_head_drop", RX_MAC_HEAD_DROP),
+	NFP_XSTAT_MAC("mac.tx_queue_drop", TX_QUEUE_DROP),
+	NFP_XSTAT_MAC("mac.tx_octets", TX_OUT_OCTS),
+	NFP_XSTAT_MAC("mac.tx_vlan_transmitted_ok", TX_VLAN_TRANSMITTED_OK),
+	NFP_XSTAT_MAC("mac.tx_errors", TX_OUT_ERRORS),
+	NFP_XSTAT_MAC("mac.tx_broadcast_pkts", TX_BROADCAST_PKTS),
+	NFP_XSTAT_MAC("mac.tx_pause_mac_ctrl_frames", TX_PAUSE_MAC_CTRL_FRAMES),
+	NFP_XSTAT_MAC("mac.tx_frames_transmitted_ok", TX_FRAMES_TRANSMITTED_OK),
+	NFP_XSTAT_MAC("mac.tx_unicast_pkts", TX_UNICAST_PKTS),
+	NFP_XSTAT_MAC("mac.tx_multicast_pkts", TX_MULTICAST_PKTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_64_octets", TX_PKTS_64_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_65_to_127_octets", TX_PKTS_65_TO_127_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_128_to_255_octets", TX_PKTS_128_TO_255_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_256_to_511_octets", TX_PKTS_256_TO_511_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_512_to_1023_octets", TX_PKTS_512_TO_1023_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_1024_to_1518_octets", TX_PKTS_1024_TO_1518_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pkts_1519_to_max_octets", TX_PKTS_1519_TO_MAX_OCTS),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class0", TX_PAUSE_FRAMES_CLASS0),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class1", TX_PAUSE_FRAMES_CLASS1),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class2", TX_PAUSE_FRAMES_CLASS2),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class3", TX_PAUSE_FRAMES_CLASS3),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class4", TX_PAUSE_FRAMES_CLASS4),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class5", TX_PAUSE_FRAMES_CLASS5),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class6", TX_PAUSE_FRAMES_CLASS6),
+	NFP_XSTAT_MAC("mac.tx_pause_frames_class7", TX_PAUSE_FRAMES_CLASS7),
+};
+
 static const uint32_t nfp_net_link_speed_nfp2rte[] = {
 	[NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = RTE_ETH_SPEED_NUM_NONE,
 	[NFP_NET_CFG_STS_LINK_RATE_UNKNOWN]     = RTE_ETH_SPEED_NUM_NONE,
@@ -794,6 +910,199 @@ nfp_net_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+uint32_t
+nfp_net_xstats_size(const struct rte_eth_dev *dev)
+{
+	/* If the device is a VF, then there will be no MAC stats */
+	struct nfp_net_hw *hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	const uint32_t size = RTE_DIM(nfp_net_xstats);
+
+	if (hw->mac_stats == NULL) {
+		uint32_t count;
+		for (count = 0; count < size; count++) {
+			if (nfp_net_xstats[count].group == NFP_XSTAT_GROUP_MAC)
+				break;
+		}
+		return count;
+	}
+
+	return size;
+}
+
+static const struct nfp_xstat *
+nfp_net_xstats_info(const struct rte_eth_dev *dev,
+		uint32_t index)
+{
+	if (index >= nfp_net_xstats_size(dev)) {
+		PMD_DRV_LOG(ERR, "xstat index out of bounds");
+		return NULL;
+	}
+
+	return &nfp_net_xstats[index];
+}
+
+static uint64_t
+nfp_net_xstats_value(const struct rte_eth_dev *dev,
+		uint32_t index,
+		bool raw)
+{
+	uint64_t value;
+	struct nfp_net_hw *hw;
+	struct nfp_xstat xstat;
+
+	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	xstat = nfp_net_xstats[index];
+
+	if (xstat.group == NFP_XSTAT_GROUP_MAC)
+		value = nn_readq(hw->mac_stats + xstat.offset);
+	else
+		value = nn_cfg_readq(hw, xstat.offset);
+
+	if (raw)
+		return value;
+
+	/**
+	 * A baseline value of each statistic counter is recorded when stats are "reset".
+	 * Thus, the value returned by this function need to be decremented by this
+	 * baseline value. The result is the count of this statistic since the last time
+	 * it was "reset".
+	 */
+	return value - hw->eth_xstats_base[index].value;
+}
+
+int
+nfp_net_xstats_get_names(struct rte_eth_dev *dev,
+		struct rte_eth_xstat_name *xstats_names,
+		unsigned int size)
+{
+	/* NOTE: All callers ensure dev is always set. */
+	uint32_t id;
+	uint32_t nfp_size;
+	uint32_t read_size;
+
+	nfp_size = nfp_net_xstats_size(dev);
+
+	if (xstats_names == NULL)
+		return nfp_size;
+
+	/* Read at most NFP xstats number of names. */
+	read_size = RTE_MIN(size, nfp_size);
+
+	for (id = 0; id < read_size; id++)
+		rte_strlcpy(xstats_names[id].name, nfp_net_xstats[id].name,
+				RTE_ETH_XSTATS_NAME_SIZE);
+
+	return read_size;
+}
+
+int
+nfp_net_xstats_get(struct rte_eth_dev *dev,
+		struct rte_eth_xstat *xstats,
+		unsigned int n)
+{
+	/* NOTE: All callers ensure dev is always set. */
+	uint32_t id;
+	uint32_t nfp_size;
+	uint32_t read_size;
+
+	nfp_size = nfp_net_xstats_size(dev);
+
+	if (xstats == NULL)
+		return nfp_size;
+
+	/* Read at most NFP xstats number of values. */
+	read_size = RTE_MIN(n, nfp_size);
+
+	for (id = 0; id < read_size; id++) {
+		xstats[id].id = id;
+		xstats[id].value = nfp_net_xstats_value(dev, id, false);
+	}
+
+	return read_size;
+}
+
+int
+nfp_net_xstats_get_names_by_id(struct rte_eth_dev *dev,
+		const uint64_t *ids,
+		struct rte_eth_xstat_name *xstats_names,
+		unsigned int size)
+{
+	/**
+	 * NOTE: The only caller rte_eth_xstats_get_names_by_id() ensures dev,
+	 * ids, xstats_names and size are valid, and non-NULL.
+	 */
+	uint32_t i;
+	uint32_t read_size;
+
+	/* Read at most NFP xstats number of names. */
+	read_size = RTE_MIN(size, nfp_net_xstats_size(dev));
+
+	for (i = 0; i < read_size; i++) {
+		const struct nfp_xstat *xstat;
+
+		/* Make sure ID is valid for device. */
+		xstat = nfp_net_xstats_info(dev, ids[i]);
+		if (xstat == NULL)
+			return -EINVAL;
+
+		rte_strlcpy(xstats_names[i].name, xstat->name,
+				RTE_ETH_XSTATS_NAME_SIZE);
+	}
+
+	return read_size;
+}
+
+int
+nfp_net_xstats_get_by_id(struct rte_eth_dev *dev,
+		const uint64_t *ids,
+		uint64_t *values,
+		unsigned int n)
+{
+	/**
+	 * NOTE: The only caller rte_eth_xstats_get_by_id() ensures dev,
+	 * ids, values and n are valid, and non-NULL.
+	 */
+	uint32_t i;
+	uint32_t read_size;
+
+	/* Read at most NFP xstats number of values. */
+	read_size = RTE_MIN(n, nfp_net_xstats_size(dev));
+
+	for (i = 0; i < read_size; i++) {
+		const struct nfp_xstat *xstat;
+
+		/* Make sure index is valid for device. */
+		xstat = nfp_net_xstats_info(dev, ids[i]);
+		if (xstat == NULL)
+			return -EINVAL;
+
+		values[i] = nfp_net_xstats_value(dev, ids[i], false);
+	}
+
+	return read_size;
+}
+
+int
+nfp_net_xstats_reset(struct rte_eth_dev *dev)
+{
+	uint32_t id;
+	uint32_t read_size;
+	struct nfp_net_hw *hw;
+
+	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	read_size = nfp_net_xstats_size(dev);
+
+	for (id = 0; id < read_size; id++) {
+		hw->eth_xstats_base[id].id = id;
+		hw->eth_xstats_base[id].value = nfp_net_xstats_value(dev, id, true);
+	}
+	/**
+	 * Successfully reset xstats, now call function to reset basic stats
+	 * return value is then based on the success of that function
+	 */
+	return nfp_net_stats_reset(dev);
+}
+
 int
 nfp_net_rx_desc_limits(struct nfp_net_hw *hw,
 		uint16_t *min_rx_desc,
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index 3a8b023c75..76f4eef980 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -244,11 +244,15 @@ struct nfp_net_hw {
 
 	/* Records starting point for counters */
 	struct rte_eth_stats eth_stats_base;
+	struct rte_eth_xstat *eth_xstats_base;
 
 	struct nfp_cpp *cpp;
 	struct nfp_cpp_area *ctrl_area;
 	struct nfp_cpp_area *hwqueues_area;
 	struct nfp_cpp_area *msix_area;
+	struct nfp_cpp_area *mac_stats_area;
+	uint8_t *mac_stats_bar;
+	uint8_t *mac_stats;
 
 	uint8_t *hw_queues;
 	/* Sequential physical port number */
@@ -444,6 +448,22 @@ int nfp_net_link_update(struct rte_eth_dev *dev,
 			__rte_unused int wait_to_complete);
 int nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
 int nfp_net_stats_reset(struct rte_eth_dev *dev);
+uint32_t nfp_net_xstats_size(const struct rte_eth_dev *dev);
+int nfp_net_xstats_get_names(struct rte_eth_dev *dev,
+		struct rte_eth_xstat_name *xstats_names,
+		unsigned int size __rte_unused);
+int nfp_net_xstats_get(struct rte_eth_dev *dev,
+		struct rte_eth_xstat *xstats,
+		unsigned int n __rte_unused);
+int nfp_net_xstats_get_names_by_id(struct rte_eth_dev *dev,
+		const uint64_t *ids,
+		struct rte_eth_xstat_name *xstats_names,
+		unsigned int size);
+int nfp_net_xstats_get_by_id(struct rte_eth_dev *dev,
+		const uint64_t *ids,
+		uint64_t *values,
+		unsigned int n);
+int nfp_net_xstats_reset(struct rte_eth_dev *dev);
 int nfp_net_infos_get(struct rte_eth_dev *dev,
 		      struct rte_eth_dev_info *dev_info);
 const uint32_t *nfp_net_supported_ptypes_get(struct rte_eth_dev *dev);
diff --git a/drivers/net/nfp/nfp_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
index c5961bdfcf..c8ca14e017 100644
--- a/drivers/net/nfp/nfp_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -329,6 +329,15 @@
 #define NFP_NET_CFG_STATS_TX_MC_FRAMES  (NFP_NET_CFG_STATS_BASE + 0x80)
 #define NFP_NET_CFG_STATS_TX_BC_FRAMES  (NFP_NET_CFG_STATS_BASE + 0x88)
 
+#define NFP_NET_CFG_STATS_APP0_FRAMES   (NFP_NET_CFG_STATS_BASE + 0x90)
+#define NFP_NET_CFG_STATS_APP0_BYTES    (NFP_NET_CFG_STATS_BASE + 0x98)
+#define NFP_NET_CFG_STATS_APP1_FRAMES   (NFP_NET_CFG_STATS_BASE + 0xa0)
+#define NFP_NET_CFG_STATS_APP1_BYTES    (NFP_NET_CFG_STATS_BASE + 0xa8)
+#define NFP_NET_CFG_STATS_APP2_FRAMES   (NFP_NET_CFG_STATS_BASE + 0xb0)
+#define NFP_NET_CFG_STATS_APP2_BYTES    (NFP_NET_CFG_STATS_BASE + 0xb8)
+#define NFP_NET_CFG_STATS_APP3_FRAMES   (NFP_NET_CFG_STATS_BASE + 0xc0)
+#define NFP_NET_CFG_STATS_APP3_BYTES    (NFP_NET_CFG_STATS_BASE + 0xc8)
+
 /*
  * Per ring stats (0x1000 - 0x1800)
  * options, 64bit per entry
@@ -342,7 +351,73 @@
 #define NFP_NET_CFG_RXR_STATS(_x)       (NFP_NET_CFG_RXR_STATS_BASE + \
 					 ((_x) * 0x10))
 
-/* PF multiport offset */
+/**
+ * Mac stats (0x0000 - 0x0200)
+ * all counters are 64bit.
+ */
+#define NFP_MAC_STATS_BASE                0x0000
+#define NFP_MAC_STATS_SIZE                0x0200
+
+#define NFP_MAC_STATS_RX_IN_OCTS                (NFP_MAC_STATS_BASE + 0x000)
+#define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS  (NFP_MAC_STATS_BASE + 0x010)
+#define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS    (NFP_MAC_STATS_BASE + 0x018)
+#define NFP_MAC_STATS_RX_VLAN_RECEIVED_OK       (NFP_MAC_STATS_BASE + 0x020)
+#define NFP_MAC_STATS_RX_IN_ERRORS              (NFP_MAC_STATS_BASE + 0x028)
+#define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS      (NFP_MAC_STATS_BASE + 0x030)
+#define NFP_MAC_STATS_RX_DROP_EVENTS            (NFP_MAC_STATS_BASE + 0x038)
+#define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS       (NFP_MAC_STATS_BASE + 0x040)
+#define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES  (NFP_MAC_STATS_BASE + 0x048)
+#define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK     (NFP_MAC_STATS_BASE + 0x050)
+#define NFP_MAC_STATS_RX_FRAME_CHECK_SEQ_ERRORS (NFP_MAC_STATS_BASE + 0x058)
+#define NFP_MAC_STATS_RX_UNICAST_PKTS           (NFP_MAC_STATS_BASE + 0x060)
+#define NFP_MAC_STATS_RX_MULTICAST_PKTS         (NFP_MAC_STATS_BASE + 0x068)
+#define NFP_MAC_STATS_RX_PKTS                   (NFP_MAC_STATS_BASE + 0x070)
+#define NFP_MAC_STATS_RX_UNDERSIZE_PKTS         (NFP_MAC_STATS_BASE + 0x078)
+#define NFP_MAC_STATS_RX_PKTS_64_OCTS           (NFP_MAC_STATS_BASE + 0x080)
+#define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTS    (NFP_MAC_STATS_BASE + 0x088)
+#define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTS  (NFP_MAC_STATS_BASE + 0x090)
+#define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTS (NFP_MAC_STATS_BASE + 0x098)
+#define NFP_MAC_STATS_RX_JABBERS                (NFP_MAC_STATS_BASE + 0x0a0)
+#define NFP_MAC_STATS_RX_FRAGMENTS              (NFP_MAC_STATS_BASE + 0x0a8)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2    (NFP_MAC_STATS_BASE + 0x0b0)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3    (NFP_MAC_STATS_BASE + 0x0b8)
+#define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTS   (NFP_MAC_STATS_BASE + 0x0c0)
+#define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTS   (NFP_MAC_STATS_BASE + 0x0c8)
+#define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTS  (NFP_MAC_STATS_BASE + 0x0d0)
+#define NFP_MAC_STATS_RX_OVERSIZE_PKTS          (NFP_MAC_STATS_BASE + 0x0d8)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0    (NFP_MAC_STATS_BASE + 0x0e0)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1    (NFP_MAC_STATS_BASE + 0x0e8)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4    (NFP_MAC_STATS_BASE + 0x0f0)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5    (NFP_MAC_STATS_BASE + 0x0f8)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6    (NFP_MAC_STATS_BASE + 0x100)
+#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7    (NFP_MAC_STATS_BASE + 0x108)
+#define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_REC    (NFP_MAC_STATS_BASE + 0x110)
+#define NFP_MAC_STATS_RX_MAC_HEAD_DROP          (NFP_MAC_STATS_BASE + 0x118)
+#define NFP_MAC_STATS_TX_QUEUE_DROP             (NFP_MAC_STATS_BASE + 0x138)
+#define NFP_MAC_STATS_TX_OUT_OCTS               (NFP_MAC_STATS_BASE + 0x140)
+#define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK    (NFP_MAC_STATS_BASE + 0x150)
+#define NFP_MAC_STATS_TX_OUT_ERRORS             (NFP_MAC_STATS_BASE + 0x158)
+#define NFP_MAC_STATS_TX_BROADCAST_PKTS         (NFP_MAC_STATS_BASE + 0x160)
+#define NFP_MAC_STATS_TX_PKTS_64_OCTS           (NFP_MAC_STATS_BASE + 0x168)
+#define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTS   (NFP_MAC_STATS_BASE + 0x170)
+#define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTS  (NFP_MAC_STATS_BASE + 0x178)
+#define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES  (NFP_MAC_STATS_BASE + 0x180)
+#define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK  (NFP_MAC_STATS_BASE + 0x188)
+#define NFP_MAC_STATS_TX_UNICAST_PKTS           (NFP_MAC_STATS_BASE + 0x190)
+#define NFP_MAC_STATS_TX_MULTICAST_PKTS         (NFP_MAC_STATS_BASE + 0x198)
+#define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTS    (NFP_MAC_STATS_BASE + 0x1a0)
+#define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTS   (NFP_MAC_STATS_BASE + 0x1a8)
+#define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTS (NFP_MAC_STATS_BASE + 0x1b0)
+#define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTS  (NFP_MAC_STATS_BASE + 0x1b8)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0    (NFP_MAC_STATS_BASE + 0x1c0)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1    (NFP_MAC_STATS_BASE + 0x1c8)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4    (NFP_MAC_STATS_BASE + 0x1d0)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5    (NFP_MAC_STATS_BASE + 0x1d8)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2    (NFP_MAC_STATS_BASE + 0x1e0)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3    (NFP_MAC_STATS_BASE + 0x1e8)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6    (NFP_MAC_STATS_BASE + 0x1f0)
+#define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7    (NFP_MAC_STATS_BASE + 0x1f8)
+
 #define NFP_PF_CSR_SLICE_SIZE	(32 * 1024)
 
 /*
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index c2684ec268..d48534fd61 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -448,6 +448,11 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = {
 	.link_update		= nfp_net_link_update,
 	.stats_get		= nfp_net_stats_get,
 	.stats_reset		= nfp_net_stats_reset,
+	.xstats_get             = nfp_net_xstats_get,
+	.xstats_reset           = nfp_net_xstats_reset,
+	.xstats_get_names       = nfp_net_xstats_get_names,
+	.xstats_get_by_id       = nfp_net_xstats_get_by_id,
+	.xstats_get_names_by_id = nfp_net_xstats_get_names_by_id,
 	.dev_infos_get		= nfp_net_infos_get,
 	.dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
 	.mtu_set		= nfp_net_dev_mtu_set,
@@ -553,15 +558,27 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 	}
 
 	if (port == 0) {
+		uint32_t min_size;
+
 		hw->ctrl_bar = pf_dev->ctrl_bar;
+		min_size = NFP_MAC_STATS_SIZE * hw->pf_dev->nfp_eth_table->max_index;
+		hw->mac_stats_bar = nfp_rtsym_map(hw->pf_dev->sym_tbl, "_mac_stats",
+				min_size, &hw->mac_stats_area);
+		if (hw->mac_stats_bar == NULL) {
+			PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _mac_stats_bar");
+			return -EIO;
+		}
+		hw->mac_stats = hw->mac_stats_bar;
 	} else {
 		if (pf_dev->ctrl_bar == NULL)
 			return -ENODEV;
 		/* Use port offset in pf ctrl_bar for this ports control bar */
 		hw->ctrl_bar = pf_dev->ctrl_bar + (port * NFP_PF_CSR_SLICE_SIZE);
+		hw->mac_stats = app_fw_nic->ports[0]->mac_stats_bar + (port * NFP_MAC_STATS_SIZE);
 	}
 
 	PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
+	PMD_INIT_LOG(DEBUG, "MAC stats: %p", hw->mac_stats);
 
 	hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
 
@@ -573,6 +590,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 
 	hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
 	hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
+	hw->eth_xstats_base = rte_malloc("rte_eth_xstat", sizeof(struct rte_eth_xstat) *
+			nfp_net_xstats_size(eth_dev), 0);
+	if (hw->eth_xstats_base == NULL) {
+		PMD_INIT_LOG(ERR, "no memory for xstats base values on device %s!",
+				pci_dev->device.name);
+		return -ENOMEM;
+	}
+
 
 	/* Work out where in the BAR the queues start. */
 	switch (pci_dev->id.device_id) {
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 5fd2dc11a3..7521a6ec90 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -229,6 +229,11 @@ static const struct eth_dev_ops nfp_netvf_eth_dev_ops = {
 	.link_update		= nfp_net_link_update,
 	.stats_get		= nfp_net_stats_get,
 	.stats_reset		= nfp_net_stats_reset,
+	.xstats_get             = nfp_net_xstats_get,
+	.xstats_reset           = nfp_net_xstats_reset,
+	.xstats_get_names       = nfp_net_xstats_get_names,
+	.xstats_get_by_id       = nfp_net_xstats_get_by_id,
+	.xstats_get_names_by_id = nfp_net_xstats_get_names_by_id,
 	.dev_infos_get		= nfp_net_infos_get,
 	.dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
 	.mtu_set		= nfp_net_dev_mtu_set,
@@ -335,6 +340,14 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
 		return -ENODEV;
 	}
 
+	hw->eth_xstats_base = rte_malloc("rte_eth_xstat", sizeof(struct rte_eth_xstat) *
+			nfp_net_xstats_size(eth_dev), 0);
+	if (hw->eth_xstats_base == NULL) {
+		PMD_INIT_LOG(ERR, "no memory for xstats base values on device %s!",
+				pci_dev->device.name);
+		return -ENOMEM;
+	}
+
 	/* Work out where in the BAR the queues start. */
 	switch (pci_dev->id.device_id) {
 	case PCI_DEVICE_ID_NFP3800_VF_NIC:
-- 
2.39.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/nfp: implement xstats functions
  2023-05-17  7:33 [PATCH] net/nfp: implement xstats functions Chaoyong He
@ 2023-05-18 11:46 ` Ferruh Yigit
  0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2023-05-18 11:46 UTC (permalink / raw)
  To: Chaoyong He, dev; +Cc: oss-drivers, niklas.soderlund, James Hershaw

On 5/17/2023 8:33 AM, Chaoyong He wrote:
> From: James Hershaw <james.hershaw@corigine.com>
> 
> To align the stats collected by nfp_net_xstats_get() to those collected
> by the `ethtool -S` command. This includes a number of extended
> statistics for both nfp_net and nfp_net_vf devices, as well as MAC
> statistics for nfp_net devices only. This does not include extended
> statistics for flower representors.
> 
> The addresses and names of counters for these statistics are added as an
> array.
> 
> The various xstats functions for the nfp PMD are implemented in line
> with the RTE API.
> 
> Signed-off-by: James Hershaw <james.hershaw@corigine.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
> Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
>

Applied to dpdk-next-net/main, thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-18 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17  7:33 [PATCH] net/nfp: implement xstats functions Chaoyong He
2023-05-18 11:46 ` Ferruh Yigit

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).