DPDK patches and discussions
 help / color / mirror / Atom feed
From: Nithin Dabilpuram <ndabilpuram@marvell.com>
To: <jerinj@marvell.com>, Nithin Dabilpuram <ndabilpuram@marvell.com>,
	"Kiran Kumar K" <kirankumark@marvell.com>,
	Sunil Kumar Kori <skori@marvell.com>,
	Satha Rao <skoteshwar@marvell.com>
Cc: <dev@dpdk.org>, Srujana Challa <schalla@marvell.com>
Subject: [dpdk-dev] [PATCH 7/9] net/cnxk: write CPT CTX through microcode op
Date: Tue, 2 Nov 2021 21:24:18 +0530	[thread overview]
Message-ID: <20211102155421.486-7-ndabilpuram@marvell.com> (raw)
In-Reply-To: <20211102155421.486-1-ndabilpuram@marvell.com>

From: Srujana Challa <schalla@marvell.com>

Adds support to write CPT CTX through microcode op(SET_CTX/WRITE_SA)
for cn10k inline mode.

Signed-off-by: Srujana Challa <schalla@marvell.com>
---
 drivers/net/cnxk/cn10k_ethdev_sec.c | 59 +++++++++++++++++++++----------------
 drivers/net/cnxk/cnxk_ethdev.c      | 49 +++++++++++++++++++++++++-----
 drivers/net/cnxk/cnxk_ethdev.h      |  6 ++++
 drivers/net/cnxk/cnxk_ethdev_sec.c  |  1 +
 4 files changed, 83 insertions(+), 32 deletions(-)

diff --git a/drivers/net/cnxk/cn10k_ethdev_sec.c b/drivers/net/cnxk/cn10k_ethdev_sec.c
index 82dc636..235c168 100644
--- a/drivers/net/cnxk/cn10k_ethdev_sec.c
+++ b/drivers/net/cnxk/cn10k_ethdev_sec.c
@@ -277,8 +277,8 @@ cn10k_eth_sec_session_create(void *device,
 		roc_nix_inl_dev_lock();
 
 	if (inbound) {
+		struct roc_ot_ipsec_inb_sa *inb_sa, *inb_sa_dptr;
 		struct cn10k_inb_priv_data *inb_priv;
-		struct roc_ot_ipsec_inb_sa *inb_sa;
 		uintptr_t sa;
 
 		PLT_STATIC_ASSERT(sizeof(struct cn10k_inb_priv_data) <
@@ -307,10 +307,11 @@ cn10k_eth_sec_session_create(void *device,
 			goto mempool_put;
 		}
 
-		memset(inb_sa, 0, sizeof(struct roc_ot_ipsec_inb_sa));
+		inb_sa_dptr = (struct roc_ot_ipsec_inb_sa *)dev->inb.sa_dptr;
+		memset(inb_sa_dptr, 0, sizeof(struct roc_ot_ipsec_inb_sa));
 
 		/* Fill inbound sa params */
-		rc = cnxk_ot_ipsec_inb_sa_fill(inb_sa, ipsec, crypto);
+		rc = cnxk_ot_ipsec_inb_sa_fill(inb_sa_dptr, ipsec, crypto);
 		if (rc) {
 			plt_err("Failed to init inbound sa, rc=%d", rc);
 			goto mempool_put;
@@ -323,7 +324,7 @@ cn10k_eth_sec_session_create(void *device,
 		inb_priv->userdata = conf->userdata;
 
 		/* Save SA index/SPI in cookie for now */
-		inb_sa->w1.s.cookie = rte_cpu_to_be_32(ipsec->spi);
+		inb_sa_dptr->w1.s.cookie = rte_cpu_to_be_32(ipsec->spi);
 
 		/* Prepare session priv */
 		sess_priv.inb_sa = 1;
@@ -339,9 +340,15 @@ cn10k_eth_sec_session_create(void *device,
 
 		TAILQ_INSERT_TAIL(&dev->inb.list, eth_sec, entry);
 		dev->inb.nb_sess++;
+		/* Sync session in context cache */
+		rc = roc_nix_inl_ctx_write(&dev->nix, inb_sa_dptr, eth_sec->sa,
+					   eth_sec->inb,
+					   sizeof(struct roc_ot_ipsec_inb_sa));
+		if (rc)
+			goto mempool_put;
 	} else {
+		struct roc_ot_ipsec_outb_sa *outb_sa, *outb_sa_dptr;
 		struct cn10k_outb_priv_data *outb_priv;
-		struct roc_ot_ipsec_outb_sa *outb_sa;
 		struct cnxk_ipsec_outb_rlens *rlens;
 		uint64_t sa_base = dev->outb.sa_base;
 		uint32_t sa_idx;
@@ -358,10 +365,11 @@ cn10k_eth_sec_session_create(void *device,
 		outb_priv = roc_nix_inl_ot_ipsec_outb_sa_sw_rsvd(outb_sa);
 		rlens = &outb_priv->rlens;
 
-		memset(outb_sa, 0, sizeof(struct roc_ot_ipsec_outb_sa));
+		outb_sa_dptr = (struct roc_ot_ipsec_outb_sa *)dev->outb.sa_dptr;
+		memset(outb_sa_dptr, 0, sizeof(struct roc_ot_ipsec_outb_sa));
 
 		/* Fill outbound sa params */
-		rc = cnxk_ot_ipsec_outb_sa_fill(outb_sa, ipsec, crypto);
+		rc = cnxk_ot_ipsec_outb_sa_fill(outb_sa_dptr, ipsec, crypto);
 		if (rc) {
 			plt_err("Failed to init outbound sa, rc=%d", rc);
 			rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
@@ -381,8 +389,8 @@ cn10k_eth_sec_session_create(void *device,
 		sess_priv.roundup_byte = rlens->roundup_byte;
 		sess_priv.roundup_len = rlens->roundup_len;
 		sess_priv.partial_len = rlens->partial_len;
-		sess_priv.mode = outb_sa->w2.s.ipsec_mode;
-		sess_priv.outer_ip_ver = outb_sa->w2.s.outer_ip_ver;
+		sess_priv.mode = outb_sa_dptr->w2.s.ipsec_mode;
+		sess_priv.outer_ip_ver = outb_sa_dptr->w2.s.outer_ip_ver;
 
 		/* Pointer from eth_sec -> outb_sa */
 		eth_sec->sa = outb_sa;
@@ -392,12 +400,13 @@ cn10k_eth_sec_session_create(void *device,
 
 		TAILQ_INSERT_TAIL(&dev->outb.list, eth_sec, entry);
 		dev->outb.nb_sess++;
+		/* Sync session in context cache */
+		rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa_dptr, eth_sec->sa,
+					   eth_sec->inb,
+					   sizeof(struct roc_ot_ipsec_outb_sa));
+		if (rc)
+			goto mempool_put;
 	}
-
-	/* Sync session in context cache */
-	roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb,
-			    ROC_NIX_INL_SA_OP_RELOAD);
-
 	if (inbound && inl_dev)
 		roc_nix_inl_dev_unlock();
 
@@ -422,10 +431,9 @@ cn10k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
 {
 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
-	struct roc_ot_ipsec_inb_sa *inb_sa;
-	struct roc_ot_ipsec_outb_sa *outb_sa;
 	struct cnxk_eth_sec_sess *eth_sec;
 	struct rte_mempool *mp;
+	void *sa_dptr;
 
 	eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
 	if (!eth_sec)
@@ -435,27 +443,28 @@ cn10k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
 		roc_nix_inl_dev_lock();
 
 	if (eth_sec->inb) {
-		inb_sa = eth_sec->sa;
 		/* Disable SA */
-		inb_sa->w2.s.valid = 0;
+		sa_dptr = dev->inb.sa_dptr;
+		roc_nix_inl_inb_sa_init(sa_dptr);
 
+		roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa,
+				      eth_sec->inb,
+				      sizeof(struct roc_ot_ipsec_inb_sa));
 		TAILQ_REMOVE(&dev->inb.list, eth_sec, entry);
 		dev->inb.nb_sess--;
 	} else {
-		outb_sa = eth_sec->sa;
 		/* Disable SA */
-		outb_sa->w2.s.valid = 0;
+		sa_dptr = dev->outb.sa_dptr;
+		roc_nix_inl_outb_sa_init(sa_dptr);
 
+		roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa,
+				      eth_sec->inb,
+				      sizeof(struct roc_ot_ipsec_outb_sa));
 		/* Release Outbound SA index */
 		cnxk_eth_outb_sa_idx_put(dev, eth_sec->sa_idx);
 		TAILQ_REMOVE(&dev->outb.list, eth_sec, entry);
 		dev->outb.nb_sess--;
 	}
-
-	/* Sync session in context cache */
-	roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb,
-			    ROC_NIX_INL_SA_OP_RELOAD);
-
 	if (eth_sec->inl_dev)
 		roc_nix_inl_dev_unlock();
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index e9bebfe..5059fca 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -78,6 +78,17 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 		 * Will be overridden when event mode rq's are setup.
 		 */
 		cnxk_nix_inb_mode_set(dev, true);
+
+		/* Allocate memory to be used as dptr for CPT ucode
+		 * WRITE_SA op.
+		 */
+		dev->inb.sa_dptr =
+			plt_zmalloc(ROC_NIX_INL_OT_IPSEC_INB_HW_SZ, 0);
+		if (!dev->inb.sa_dptr) {
+			plt_err("Couldn't allocate memory for SA dptr");
+			rc = -ENOMEM;
+			goto cleanup;
+		}
 	}
 
 	if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY ||
@@ -95,14 +106,25 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 		if (rc) {
 			plt_err("Failed to initialize nix inline outb, rc=%d",
 				rc);
-			goto cleanup;
+			goto sa_dptr_free;
 		}
 
 		dev->outb.lf_base = roc_nix_inl_outb_lf_base_get(nix);
 
-		/* Skip the rest if RTE_ETH_TX_OFFLOAD_SECURITY is not enabled */
+		/* Skip the rest if DEV_TX_OFFLOAD_SECURITY is not enabled */
 		if (!(dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY))
-			goto done;
+			return 0;
+
+		/* Allocate memory to be used as dptr for CPT ucode
+		 * WRITE_SA op.
+		 */
+		dev->outb.sa_dptr =
+			plt_zmalloc(ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ, 0);
+		if (!dev->outb.sa_dptr) {
+			plt_err("Couldn't allocate memory for SA dptr");
+			rc = -ENOMEM;
+			goto sa_dptr_free;
+		}
 
 		rc = -ENOMEM;
 		/* Allocate a bitmap to alloc and free sa indexes */
@@ -112,7 +134,7 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 			plt_err("Outbound SA bmap alloc failed");
 
 			rc |= roc_nix_inl_outb_fini(nix);
-			goto cleanup;
+			goto sa_dptr_free;
 		}
 
 		rc = -EIO;
@@ -122,7 +144,7 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 
 			rc |= roc_nix_inl_outb_fini(nix);
 			plt_free(mem);
-			goto cleanup;
+			goto sa_dptr_free;
 		}
 
 		for (i = 0; i < dev->outb.max_sa; i++)
@@ -132,9 +154,13 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 		dev->outb.sa_bmap_mem = mem;
 		dev->outb.sa_bmap = bmap;
 	}
-
-done:
 	return 0;
+
+sa_dptr_free:
+	if (dev->inb.sa_dptr)
+		plt_free(dev->inb.sa_dptr);
+	if (dev->outb.sa_dptr)
+		plt_free(dev->outb.sa_dptr);
 cleanup:
 	if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
 		rc |= roc_nix_inl_inb_fini(nix);
@@ -196,6 +222,11 @@ nix_security_release(struct cnxk_eth_dev *dev)
 		if (rc)
 			plt_err("Failed to cleanup nix inline inb, rc=%d", rc);
 		ret |= rc;
+
+		if (dev->inb.sa_dptr) {
+			plt_free(dev->inb.sa_dptr);
+			dev->inb.sa_dptr = NULL;
+		}
 	}
 
 	/* Cleanup Inline outbound */
@@ -216,6 +247,10 @@ nix_security_release(struct cnxk_eth_dev *dev)
 		plt_free(dev->outb.sa_bmap_mem);
 		dev->outb.sa_bmap = NULL;
 		dev->outb.sa_bmap_mem = NULL;
+		if (dev->outb.sa_dptr) {
+			plt_free(dev->outb.sa_dptr);
+			dev->outb.sa_dptr = NULL;
+		}
 	}
 
 	dev->inb.inl_dev = false;
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7e4939f..93879c8 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -268,6 +268,9 @@ struct cnxk_eth_dev_sec_inb {
 
 	/* List of sessions */
 	struct cnxk_eth_sec_sess_list list;
+
+	/* DPTR for WRITE_SA microcode op */
+	void *sa_dptr;
 };
 
 /* Outbound security data */
@@ -298,6 +301,9 @@ struct cnxk_eth_dev_sec_outb {
 
 	/* List of sessions */
 	struct cnxk_eth_sec_sess_list list;
+
+	/* DPTR for WRITE_SA microcode op */
+	void *sa_dptr;
 };
 
 struct cnxk_eth_dev {
diff --git a/drivers/net/cnxk/cnxk_ethdev_sec.c b/drivers/net/cnxk/cnxk_ethdev_sec.c
index ae3e49c..3fef056 100644
--- a/drivers/net/cnxk/cnxk_ethdev_sec.c
+++ b/drivers/net/cnxk/cnxk_ethdev_sec.c
@@ -277,6 +277,7 @@ cnxk_nix_inl_dev_probe(struct rte_pci_driver *pci_drv,
 		goto free_mem;
 	}
 
+	inl_dev->attach_cptlf = true;
 	rc = roc_nix_inl_dev_init(inl_dev);
 	if (rc) {
 		plt_err("Failed to init nix inl device, rc=%d(%s)", rc,
-- 
2.8.4


  parent reply	other threads:[~2021-11-02 15:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 15:54 [dpdk-dev] [PATCH 1/9] common/cnxk: add code to " Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 2/9] common/cnxk: add CPT CTX sync mailbox API Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 3/9] common/cnxk: support flow control on LBK Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 4/9] common/cnxk: enable tm to listen on Rx pause frames Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 5/9] common/cnxk: enable bp on CPT with inline inbound Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 6/9] common/cnxk: support changing drop re flag after lf alloc Nithin Dabilpuram
2021-11-02 15:54 ` Nithin Dabilpuram [this message]
2021-11-02 15:54 ` [dpdk-dev] [PATCH 8/9] net/cnxk: allow fc on lbk and enable tm bp on Rx pause Nithin Dabilpuram
2021-11-02 15:54 ` [dpdk-dev] [PATCH 9/9] event/cnxk: disable drop re on vector enable for cn10k a0 Nithin Dabilpuram
2021-11-03 15:09 ` [dpdk-dev] [PATCH 1/9] common/cnxk: add code to write CPT CTX through microcode op Jerin Jacob

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=20211102155421.486-7-ndabilpuram@marvell.com \
    --to=ndabilpuram@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=schalla@marvell.com \
    --cc=skori@marvell.com \
    --cc=skoteshwar@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).