From: Harman Kalra <hkalra@marvell.com>
To: <dev@dpdk.org>, Harman Kalra <hkalra@marvell.com>
Subject: [PATCH v2 08/11] net/octeontx: implement xstats
Date: Mon, 23 May 2022 21:40:57 +0530 [thread overview]
Message-ID: <20220523161100.86280-8-hkalra@marvell.com> (raw)
In-Reply-To: <20220523161100.86280-1-hkalra@marvell.com>
Adding support for xstats eth operations.
Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
drivers/net/octeontx/base/octeontx_bgx.c | 17 +++
drivers/net/octeontx/base/octeontx_bgx.h | 3 +
drivers/net/octeontx/octeontx_ethdev.c | 126 +++++++++++++++++++++++
drivers/net/octeontx/octeontx_stats.h | 41 ++++++++
4 files changed, 187 insertions(+)
create mode 100644 drivers/net/octeontx/octeontx_stats.h
diff --git a/drivers/net/octeontx/base/octeontx_bgx.c b/drivers/net/octeontx/base/octeontx_bgx.c
index 1c6fa05ebc..81a8cbecaf 100644
--- a/drivers/net/octeontx/base/octeontx_bgx.c
+++ b/drivers/net/octeontx/base/octeontx_bgx.c
@@ -144,6 +144,23 @@ octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat)
return res;
}
+int
+octeontx_bgx_port_xstats(int port, octeontx_mbox_bgx_port_stats_t *stats)
+{
+ struct octeontx_mbox_hdr hdr;
+ int len = sizeof(octeontx_mbox_bgx_port_stats_t);
+ int res;
+
+ hdr.coproc = OCTEONTX_BGX_COPROC;
+ hdr.msg = MBOX_BGX_PORT_GET_STATS;
+ hdr.vfid = port;
+
+ res = octeontx_mbox_send(&hdr, NULL, 0, stats, len);
+ if (res < 0)
+ return -EACCES;
+ return res;
+}
+
int
octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats)
{
diff --git a/drivers/net/octeontx/base/octeontx_bgx.h b/drivers/net/octeontx/base/octeontx_bgx.h
index e4cfa3e73a..c5662202ac 100644
--- a/drivers/net/octeontx/base/octeontx_bgx.h
+++ b/drivers/net/octeontx/base/octeontx_bgx.h
@@ -117,6 +117,8 @@ typedef struct octeontx_mbox_bgx_port_stats {
uint64_t rx_oversize_errors;
uint64_t rx_fragmented_errors;
uint64_t rx_jabber_errors;
+ uint64_t rx_pause_packets;
+ uint64_t tx_pause_packets;
} octeontx_mbox_bgx_port_stats_t;
struct octeontx_mbox_bgx_port_mac_filter {
@@ -161,6 +163,7 @@ int octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf);
int octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat);
int octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats);
int octeontx_bgx_port_stats_clr(int port);
+int octeontx_bgx_port_xstats(int port, octeontx_mbox_bgx_port_stats_t *stats);
int octeontx_bgx_port_link_status(int port);
int octeontx_bgx_port_promisc_set(int port, int en);
int octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr);
diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 9351fcb5c7..c15014bdde 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -25,6 +25,7 @@
#include "octeontx_ethdev.h"
#include "octeontx_rxtx.h"
#include "octeontx_logs.h"
+#include "octeontx_stats.h"
/* Useful in stopping/closing event device if no of
* eth ports are using it.
@@ -846,6 +847,127 @@ octeontx_dev_link_update(struct rte_eth_dev *dev,
return rte_eth_linkstatus_set(dev, &link);
}
+static inline int octeontx_dev_total_xstat(void)
+{
+ return NUM_BGX_XSTAT;
+}
+
+static int
+octeontx_port_xstats(struct octeontx_nic *nic, struct rte_eth_xstat *xstats,
+ unsigned int n)
+{
+ octeontx_mbox_bgx_port_stats_t bgx_stats;
+ int stat_cnt, res, si, i;
+
+ res = octeontx_bgx_port_xstats(nic->port_id, &bgx_stats);
+ if (res < 0) {
+ octeontx_log_err("failed to get port stats %d", nic->port_id);
+ return res;
+ }
+
+ si = 0;
+ /* Fill BGX stats */
+ stat_cnt = (n > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : n;
+ n = n - stat_cnt;
+ for (i = 0; i < stat_cnt; i++) {
+ xstats[si].id = si;
+ xstats[si].value = *(uint64_t *)(((char *)&bgx_stats) +
+ octeontx_bgx_xstats[i].soffset);
+ si++;
+ }
+ /*TODO: Similarly fill rest of HW stats */
+
+ return si;
+}
+
+static int
+octeontx_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
+ uint64_t *stat_val, unsigned int n)
+{
+ unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
+ struct octeontx_nic *nic = octeontx_pmd_priv(dev);
+ struct rte_eth_xstat xstats[xstat_cnt];
+
+ octeontx_port_xstats(nic, xstats, xstat_cnt);
+ for (i = 0; i < n; i++) {
+ if (ids[i] >= xstat_cnt) {
+ PMD_INIT_LOG(ERR, "out of range id value");
+ return -1;
+ }
+ stat_val[i] = xstats[ids[i]].value;
+ }
+ return n;
+}
+
+static int
+octeontx_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
+ struct rte_eth_xstat_name *xstats_names,
+ unsigned int size)
+{
+ int stat_cnt, si, i;
+
+ if (xstats_names) {
+ si = 0;
+ /* Fill BGX stats */
+ stat_cnt = (size > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : size;
+ size = size - stat_cnt;
+ for (i = 0; i < stat_cnt; i++) {
+ strlcpy(xstats_names[si].name,
+ octeontx_bgx_xstats[i].sname,
+ sizeof(xstats_names[si].name));
+ si++;
+ }
+ /*TODO: Similarly fill rest of HW stats */
+ return si;
+ } else {
+ return octeontx_dev_total_xstat();
+ }
+}
+
+static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
+{
+ unsigned int i;
+
+ for (i = 0; i < NUM_BGX_XSTAT; i++) {
+ strlcpy(xstat_names[i].name, octeontx_bgx_xstats[i].sname,
+ RTE_ETH_XSTATS_NAME_SIZE);
+ }
+}
+
+static int
+octeontx_dev_xstats_get_names_by_id(struct rte_eth_dev *dev __rte_unused,
+ const uint64_t *ids,
+ struct rte_eth_xstat_name *stat_names,
+ unsigned int n)
+{
+ unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
+ struct rte_eth_xstat_name xstat_names[xstat_cnt];
+
+ build_xstat_names(xstat_names);
+ for (i = 0; i < n; i++) {
+ if (ids[i] >= xstat_cnt) {
+ PMD_INIT_LOG(ERR, "out of range id value");
+ return -1;
+ }
+ strlcpy(stat_names[i].name, xstat_names[ids[i]].name,
+ sizeof(stat_names[i].name));
+ }
+ /*TODO: Similarly fill rest of HW stats */
+
+ return n;
+}
+
+static int
+octeontx_dev_xstats_get(struct rte_eth_dev *dev,
+ struct rte_eth_xstat *xstats,
+ unsigned int n)
+{
+ struct octeontx_nic *nic = octeontx_pmd_priv(dev);
+
+ PMD_INIT_FUNC_TRACE();
+ return octeontx_port_xstats(nic, xstats, n);
+}
+
static int
octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
@@ -1354,6 +1476,10 @@ static const struct eth_dev_ops octeontx_dev_ops = {
.pool_ops_supported = octeontx_pool_ops,
.flow_ctrl_get = octeontx_dev_flow_ctrl_get,
.flow_ctrl_set = octeontx_dev_flow_ctrl_set,
+ .xstats_get = octeontx_dev_xstats_get,
+ .xstats_get_by_id = octeontx_dev_xstats_get_by_id,
+ .xstats_get_names = octeontx_dev_xstats_get_names,
+ .xstats_get_names_by_id = octeontx_dev_xstats_get_names_by_id,
};
/* Create Ethdev interface per BGX LMAC ports */
diff --git a/drivers/net/octeontx/octeontx_stats.h b/drivers/net/octeontx/octeontx_stats.h
new file mode 100644
index 0000000000..95e03a993d
--- /dev/null
+++ b/drivers/net/octeontx/octeontx_stats.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017 Cavium, Inc
+ */
+
+#ifndef __OCTEONTX_STATS_H__
+#define __OCTEONTX_STATS_H__
+
+#define BGX_XSTAT(stat) \
+ {#stat, offsetof(octeontx_mbox_bgx_port_stats_t, stat)}
+struct octeontx_xstats {
+ char sname[RTE_ETH_XSTATS_NAME_SIZE];
+ uint32_t soffset;
+};
+
+struct octeontx_xstats octeontx_bgx_xstats[] = {
+ BGX_XSTAT(rx_packets),
+ BGX_XSTAT(tx_packets),
+ BGX_XSTAT(rx_broadcast_packets),
+ BGX_XSTAT(multicast),
+ BGX_XSTAT(tx_multicast_packets),
+ BGX_XSTAT(tx_broadcast_packets),
+ BGX_XSTAT(rx_undersized_errors),
+ BGX_XSTAT(rx_oversize_errors),
+ BGX_XSTAT(rx_jabber_errors),
+ BGX_XSTAT(rx_crc_errors),
+ BGX_XSTAT(collisions),
+ BGX_XSTAT(tx_1_to_64_packets),
+ BGX_XSTAT(tx_65_to_127_packets),
+ BGX_XSTAT(tx_128_to_255_packets),
+ BGX_XSTAT(tx_256_to_511_packets),
+ BGX_XSTAT(tx_512_to_1023_packets),
+ BGX_XSTAT(tx_1024_to_1522_packets),
+ BGX_XSTAT(tx_1523_to_max_packets),
+ BGX_XSTAT(rx_fragmented_errors),
+ BGX_XSTAT(rx_pause_packets),
+ BGX_XSTAT(tx_pause_packets),
+};
+
+#define NUM_BGX_XSTAT \
+ (sizeof(octeontx_bgx_xstats) / sizeof(struct octeontx_xstats))
+#endif /* __OCTEONTX_STATS_H__ */
--
2.18.0
next prev parent reply other threads:[~2022-05-23 16:12 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-17 17:39 [PATCH 01/12] config: add thundert83 config Harman Kalra
2022-05-17 17:39 ` [PATCH 02/12] event/octeontx: fix SSO fastpath Harman Kalra
2022-05-23 16:10 ` [PATCH v2 01/11] " Harman Kalra
2022-05-23 16:10 ` [PATCH v2 02/11] net/octeontx: fix port close Harman Kalra
2022-05-23 16:10 ` [PATCH v2 03/11] net/octeontx: setting link attributes Harman Kalra
2022-05-23 16:10 ` [PATCH v2 04/11] net/octeontx: handle port reconfiguration Harman Kalra
2022-05-23 16:10 ` [PATCH v2 05/11] net/thunderx: implement polling of link state change Harman Kalra
2022-05-23 16:10 ` [PATCH v2 06/11] net/thunderx: reset Rx DMAC control register Harman Kalra
2022-05-23 16:10 ` [PATCH v2 07/11] net/thunderx: setting link attributes Harman Kalra
2022-05-23 16:10 ` Harman Kalra [this message]
2022-05-23 16:10 ` [PATCH v2 09/11] net/octeontx: support allmulticast Harman Kalra
2022-05-23 16:10 ` [PATCH v2 10/11] net/thunderx: device attach from secondary Harman Kalra
2022-05-23 16:11 ` [PATCH v2 11/11] net/thunderx: populate max and min MTU values Harman Kalra
2022-05-24 8:42 ` [PATCH v3 01/11] event/octeontx: fix SSO fastpath Harman Kalra
2022-05-24 8:42 ` [PATCH v3 02/11] net/octeontx: fix port close Harman Kalra
2022-05-24 8:42 ` [PATCH v3 03/11] net/octeontx: setting link attributes Harman Kalra
2022-05-24 8:42 ` [PATCH v3 04/11] net/octeontx: handle port reconfiguration Harman Kalra
2022-05-24 8:42 ` [PATCH v3 05/11] net/thunderx: implement polling of link state change Harman Kalra
2022-05-24 8:42 ` [PATCH v3 06/11] net/thunderx: reset Rx DMAC control register Harman Kalra
2022-05-24 8:42 ` [PATCH v3 07/11] net/thunderx: setting link attributes Harman Kalra
2022-05-24 8:42 ` [PATCH v3 08/11] net/octeontx: implement xstats Harman Kalra
2022-06-09 16:13 ` Jerin Jacob
2022-05-24 8:42 ` [PATCH v3 09/11] net/octeontx: support allmulticast Harman Kalra
2022-05-24 8:42 ` [PATCH v3 10/11] net/thunderx: device attach from secondary Harman Kalra
2022-05-24 8:42 ` [PATCH v3 11/11] net/thunderx: populate max and min MTU values Harman Kalra
2022-06-09 15:55 ` Jerin Jacob
2022-06-09 15:53 ` [PATCH v3 01/11] event/octeontx: fix SSO fastpath Jerin Jacob
2022-05-17 17:39 ` [PATCH 03/12] net/octeontx: fix port close Harman Kalra
2022-05-17 17:39 ` [PATCH 04/12] net/octeontx: setting link attributes Harman Kalra
2022-05-17 17:39 ` [PATCH 05/12] net/octeontx: handle port reconfiguration Harman Kalra
2022-05-17 17:39 ` [PATCH 06/12] net/thunderx: implement polling of link state change Harman Kalra
2022-05-17 17:39 ` [PATCH 07/12] net/thunderx: reset Rx DMAC control register Harman Kalra
2022-05-17 17:39 ` [PATCH 08/12] net/thunderx: setting link attributes Harman Kalra
2022-05-17 17:39 ` [PATCH 09/12] net/octeontx: implement xstats Harman Kalra
2022-05-17 17:39 ` [PATCH 10/12] net/octeontx: support allmulticast Harman Kalra
2022-05-17 17:39 ` [PATCH 11/12] net/thunderx: device attach from secondary Harman Kalra
2022-05-17 17:39 ` [PATCH 12/12] net/thunderx: populate max and min MTU values Harman Kalra
2022-05-18 6:10 ` [PATCH 01/12] config: add thundert83 config Ruifeng Wang
2022-05-23 13:34 ` [PATCH v2] config: add thunderX t83 config Harman Kalra
2022-06-01 22:02 ` Thomas Monjalon
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=20220523161100.86280-8-hkalra@marvell.com \
--to=hkalra@marvell.com \
--cc=dev@dpdk.org \
/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).