DPDK patches and discussions
 help / color / mirror / Atom feed
From: Akhil Goyal <gakhil@marvell.com>
To: <dev@dpdk.org>
Cc: <jerinj@marvell.com>, Akhil Goyal <gakhil@marvell.com>
Subject: [PATCH] common/cnxk: check MACsec HW capability
Date: Fri, 24 Jan 2025 23:51:51 +0530	[thread overview]
Message-ID: <20250124182151.3587238-1-gakhil@marvell.com> (raw)

Added ROC API to check if hardware has capability
to perform MACsec operations.
Skipped MACsec initialization if not supported by hardware

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 drivers/common/cnxk/roc_mbox.h  |  2 ++
 drivers/common/cnxk/roc_mcs.c   | 21 +++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h   |  2 ++
 drivers/common/cnxk/version.map |  1 +
 drivers/net/cnxk/cnxk_ethdev.c  |  4 ++--
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index f362d55bc2..989f33b0d2 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -2869,6 +2869,8 @@ struct get_hw_cap_rsp {
 	uint8_t __io nix_fixed_txschq_mapping;
 	uint8_t __io nix_shaping;      /* Is shaping and coloring supported */
 	uint8_t __io npc_hash_extract; /* Is hash extract supported */
+#define HW_CAP_MACSEC BIT_ULL(1)
+	uint64_t hw_caps;
 };
 
 struct ndc_sync_op {
diff --git a/drivers/common/cnxk/roc_mcs.c b/drivers/common/cnxk/roc_mcs.c
index f823f7f478..0ae5618c09 100644
--- a/drivers/common/cnxk/roc_mcs.c
+++ b/drivers/common/cnxk/roc_mcs.c
@@ -18,6 +18,27 @@ TAILQ_HEAD(mcs_event_cb_list, mcs_event_cb);
 
 PLT_STATIC_ASSERT(ROC_MCS_MEM_SZ >= (sizeof(struct mcs_priv) + sizeof(struct mcs_event_cb_list)));
 
+bool
+roc_mcs_is_supported(void)
+{
+	struct get_hw_cap_rsp *hw_cap_rsp;
+	struct npa_lf *npa;
+
+	/* Use mbox handler of first probed pci_func for initial mcs mbox communication. */
+	npa = idev_npa_obj_get();
+	if (!npa)
+		return false;
+
+	mbox_alloc_msg_get_hw_cap(npa->mbox);
+	if (mbox_process_msg(npa->mbox, (void *)&hw_cap_rsp))
+		return false;
+
+	if (hw_cap_rsp->hw_caps & HW_CAP_MACSEC)
+		return true;
+
+	return false;
+}
+
 int
 roc_mcs_hw_info_get(struct roc_mcs_hw_info *hw_info)
 {
diff --git a/drivers/common/cnxk/roc_mcs.h b/drivers/common/cnxk/roc_mcs.h
index 0627865a4d..3ac82f6f8c 100644
--- a/drivers/common/cnxk/roc_mcs.h
+++ b/drivers/common/cnxk/roc_mcs.h
@@ -498,6 +498,8 @@ struct roc_mcs {
 
 TAILQ_HEAD(roc_mcs_head, roc_mcs);
 
+/* Check HW capability for MACsec */
+__roc_api bool roc_mcs_is_supported(void);
 /* Initialization */
 __roc_api struct roc_mcs *roc_mcs_dev_init(uint8_t mcs_idx);
 __roc_api void roc_mcs_dev_fini(struct roc_mcs *mcs);
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 37b76c020e..97562b1663 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -171,6 +171,7 @@ INTERNAL {
 	roc_mcs_flowid_stats_get;
 	roc_mcs_hw_info_get;
 	roc_mcs_intr_configure;
+	roc_mcs_is_supported;
 	roc_mcs_lmac_mode_set;
 	roc_mcs_pn_table_write;
 	roc_mcs_pn_table_read;
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index ea980a6d5e..3efce5c634 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -2002,7 +2002,7 @@ cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
 	if (rc)
 		goto free_mac_addrs;
 
-	if (roc_feature_nix_has_macsec()) {
+	if (roc_feature_nix_has_macsec() && roc_mcs_is_supported()) {
 		rc = cnxk_mcs_dev_init(dev, 0);
 		if (rc) {
 			plt_err("Failed to init MCS");
@@ -2132,7 +2132,7 @@ cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
 	}
 	eth_dev->data->nb_rx_queues = 0;
 
-	if (roc_feature_nix_has_macsec())
+	if (roc_feature_nix_has_macsec() && roc_mcs_is_supported())
 		cnxk_mcs_dev_fini(dev);
 
 	/* Free security resources */
-- 
2.25.1


                 reply	other threads:[~2025-01-24 18:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250124182151.3587238-1-gakhil@marvell.com \
    --to=gakhil@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.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).