[v5,14/23] common/cnxk: get representees ethernet stats

Message ID 20240301191451.57168-15-hkalra@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series net/cnxk: support for port representors |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Harman Kalra March 1, 2024, 7:14 p.m. UTC
  Implementing an mbox interface to fetch the representees's ethernet
stats from the kernel.

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 drivers/common/cnxk/roc_eswitch.c | 45 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_eswitch.h |  2 ++
 drivers/common/cnxk/roc_mbox.h    | 31 +++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 4 files changed, 79 insertions(+)
  

Patch

diff --git a/drivers/common/cnxk/roc_eswitch.c b/drivers/common/cnxk/roc_eswitch.c
index 14819bad75..c67b4090a5 100644
--- a/drivers/common/cnxk/roc_eswitch.c
+++ b/drivers/common/cnxk/roc_eswitch.c
@@ -342,3 +342,48 @@  roc_eswitch_nix_process_repte_notify_cb_unregister(struct roc_nix *roc_nix)
 
 	dev->ops->repte_notify = NULL;
 }
+
+int
+roc_eswitch_nix_repte_stats(struct roc_nix *roc_nix, uint16_t pf_func, struct roc_nix_stats *stats)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+	struct nix_get_lf_stats_req *req;
+	struct nix_lf_stats_rsp *rsp;
+	struct mbox *mbox;
+	int rc;
+
+	mbox = mbox_get(dev->mbox);
+	req = mbox_alloc_msg_nix_get_lf_stats(mbox);
+	if (!req) {
+		rc = -ENOSPC;
+		goto exit;
+	}
+
+	req->hdr.pcifunc = roc_nix_get_pf_func(roc_nix);
+	req->pcifunc = pf_func;
+
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		goto exit;
+
+	stats->rx_octs = rsp->rx.octs;
+	stats->rx_ucast = rsp->rx.ucast;
+	stats->rx_bcast = rsp->rx.bcast;
+	stats->rx_mcast = rsp->rx.mcast;
+	stats->rx_drop = rsp->rx.drop;
+	stats->rx_drop_octs = rsp->rx.drop_octs;
+	stats->rx_drop_bcast = rsp->rx.drop_bcast;
+	stats->rx_drop_mcast = rsp->rx.drop_mcast;
+	stats->rx_err = rsp->rx.err;
+
+	stats->tx_ucast = rsp->tx.ucast;
+	stats->tx_bcast = rsp->tx.bcast;
+	stats->tx_mcast = rsp->tx.mcast;
+	stats->tx_drop = rsp->tx.drop;
+	stats->tx_octs = rsp->tx.octs;
+
+exit:
+	mbox_put(mbox);
+	return rc;
+}
diff --git a/drivers/common/cnxk/roc_eswitch.h b/drivers/common/cnxk/roc_eswitch.h
index e0df0038d4..b701ea69ee 100644
--- a/drivers/common/cnxk/roc_eswitch.h
+++ b/drivers/common/cnxk/roc_eswitch.h
@@ -51,6 +51,8 @@  int __roc_api roc_eswitch_npc_rss_action_configure(struct roc_npc *roc_npc,
 /* NIX */
 int __roc_api roc_eswitch_nix_vlan_tpid_set(struct roc_nix *nix, uint32_t type, uint16_t tpid,
 					    bool is_vf);
+int __roc_api roc_eswitch_nix_repte_stats(struct roc_nix *roc_nix, uint16_t pf_func,
+					  struct roc_nix_stats *stats);
 int __roc_api roc_eswitch_nix_process_repte_notify_cb_register(struct roc_nix *roc_nix,
 						    process_repte_notify_t proc_repte_nt);
 void __roc_api roc_eswitch_nix_process_repte_notify_cb_unregister(struct roc_nix *roc_nix);
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index d28e3ffd70..f1a3371ef9 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -306,6 +306,7 @@  struct mbox_msghdr {
 	M(NIX_MCAST_GRP_DESTROY, 0x802c, nix_mcast_grp_destroy, nix_mcast_grp_destroy_req, msg_rsp)\
 	M(NIX_MCAST_GRP_UPDATE, 0x802d, nix_mcast_grp_update, nix_mcast_grp_update_req,            \
 	  nix_mcast_grp_update_rsp)                                                                \
+	M(NIX_GET_LF_STATS,    0x802e, nix_get_lf_stats, nix_get_lf_stats_req, nix_lf_stats_rsp)   \
 	/* MCS mbox IDs (range 0xa000 - 0xbFFF) */                                                 \
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
@@ -1850,6 +1851,36 @@  struct nix_mcast_grp_update_rsp {
 	uint32_t __io mce_start_index;
 };
 
+struct nix_get_lf_stats_req {
+	struct mbox_msghdr hdr;
+	uint16_t __io pcifunc;
+	uint64_t __io rsvd;
+};
+
+struct nix_lf_stats_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io pcifunc;
+	struct {
+		uint64_t __io octs;
+		uint64_t __io ucast;
+		uint64_t __io bcast;
+		uint64_t __io mcast;
+		uint64_t __io drop;
+		uint64_t __io drop_octs;
+		uint64_t __io drop_mcast;
+		uint64_t __io drop_bcast;
+		uint64_t __io err;
+		uint64_t __io rsvd[5];
+	} rx;
+	struct {
+		uint64_t __io ucast;
+		uint64_t __io bcast;
+		uint64_t __io mcast;
+		uint64_t __io drop;
+		uint64_t __io octs;
+	} tx;
+};
+
 /* Global NIX inline IPSec configuration */
 struct nix_inline_ipsec_cfg {
 	struct mbox_msghdr hdr;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 5dd42c8044..18c2d9d632 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -89,6 +89,7 @@  INTERNAL {
 	roc_error_msg_get;
 	roc_eswitch_nix_process_repte_notify_cb_register;
 	roc_eswitch_nix_process_repte_notify_cb_unregister;
+	roc_eswitch_nix_repte_stats;
 	roc_eswitch_nix_vlan_tpid_set;
 	roc_eswitch_npc_mcam_delete_rule;
 	roc_eswitch_npc_mcam_rx_rule;