From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F1682A034F; Tue, 7 Dec 2021 07:51:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B947341238; Tue, 7 Dec 2021 07:51:46 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 2EC974117E for ; Tue, 7 Dec 2021 07:51:45 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1B75a1Bh014965 for ; Mon, 6 Dec 2021 22:51:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=kKaB6OMKvg9cFqmC9F5DoBHQdf2n+P3uJafzh2364Xc=; b=K3z8nWJE511SXhcgdW801mnKX+97gpxYcF102mIKEpuh0xxJxVmsDq/8LhCZmXJvgQhM dAQxp/uvx9kGMLCsxPDL8ZOAtoouAp+j32cL+ENIsq2fF54qKffrbnZ6wQ6eqMgfoYtQ hM7lTossk771WdQBj4kfCKZEnoNdFF1Bsqt9xglrIdeQmvq9x+09XBw5FoH/PzQZNPC5 1iurzl9kE2LmUyqlxbcmzf5/IFDTup44TKfGkA5Kn/1h47+JIWdFtTcTw+uAAV+fG2oJ IZlDsYKL6OB+j5CojZldBXdpQiHkmt6vY02bHv/I+9hxW9FqgV9V3ufOjo78/IIeF4Hz qw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3ct1hyg7dx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 06 Dec 2021 22:51:44 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 6 Dec 2021 22:51:41 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 6 Dec 2021 22:51:41 -0800 Received: from HY-LT1002.marvell.com (HY-LT1002.marvell.com [10.28.176.218]) by maili.marvell.com (Postfix) with ESMTP id EDDC13F7071; Mon, 6 Dec 2021 22:51:39 -0800 (PST) From: Anoob Joseph To: Akhil Goyal , Jerin Jacob CC: Tejasree Kondoj , Archana Muniganti , Subject: [PATCH 10/25] crypto/cnxk: write CPT CTX through microcode op Date: Tue, 7 Dec 2021 12:20:43 +0530 Message-ID: <1638859858-734-11-git-send-email-anoobj@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1638859858-734-1-git-send-email-anoobj@marvell.com> References: <1638859858-734-1-git-send-email-anoobj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: 2ppToZh3LP0cxY6NUncuphJ8qBui7tpa X-Proofpoint-GUID: 2ppToZh3LP0cxY6NUncuphJ8qBui7tpa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-07_02,2021-12-06_02,2021-12-02_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Tejasree Kondoj Adding support to write CPT CTX through microcode op(SET_CTX) for cn10k lookaside PMD. Signed-off-by: Tejasree Kondoj --- drivers/crypto/cnxk/cn10k_ipsec.c | 121 ++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 32 deletions(-) diff --git a/drivers/crypto/cnxk/cn10k_ipsec.c b/drivers/crypto/cnxk/cn10k_ipsec.c index 1bd127e..a11a6b7 100644 --- a/drivers/crypto/cnxk/cn10k_ipsec.c +++ b/drivers/crypto/cnxk/cn10k_ipsec.c @@ -2,18 +2,19 @@ * Copyright(C) 2021 Marvell. */ -#include #include #include #include +#include #include #include #include +#include "cn10k_ipsec.h" #include "cnxk_cryptodev.h" +#include "cnxk_cryptodev_ops.h" #include "cnxk_ipsec.h" #include "cnxk_security.h" -#include "cn10k_ipsec.h" #include "roc_api.h" @@ -32,36 +33,46 @@ ipsec_cpt_inst_w7_get(struct roc_cpt *roc_cpt, void *sa) } static int -cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt, +cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt, struct roc_cpt_lf *lf, struct rte_security_ipsec_xform *ipsec_xfrm, struct rte_crypto_sym_xform *crypto_xfrm, struct rte_security_session *sec_sess) { union roc_ot_ipsec_outb_param1 param1; - struct roc_ot_ipsec_outb_sa *out_sa; + struct roc_ot_ipsec_outb_sa *sa_dptr; struct cnxk_ipsec_outb_rlens rlens; struct cn10k_sec_session *sess; struct cn10k_ipsec_sa *sa; union cpt_inst_w4 inst_w4; - int ret; + void *out_sa; + int ret = 0; sess = get_sec_session_private_data(sec_sess); sa = &sess->sa; out_sa = &sa->out_sa; - memset(out_sa, 0, sizeof(struct roc_ot_ipsec_outb_sa)); + /* Allocate memory to be used as dptr for CPT ucode WRITE_SA op */ + sa_dptr = plt_zmalloc(ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ, 0); + if (sa_dptr == NULL) { + plt_err("Couldn't allocate memory for SA dptr"); + return -ENOMEM; + } + + memset(sa_dptr, 0, sizeof(struct roc_ot_ipsec_outb_sa)); /* Translate security parameters to SA */ - ret = cnxk_ot_ipsec_outb_sa_fill(out_sa, ipsec_xfrm, crypto_xfrm); - if (ret) - return ret; + ret = cnxk_ot_ipsec_outb_sa_fill(sa_dptr, ipsec_xfrm, crypto_xfrm); + if (ret) { + plt_err("Could not fill outbound session parameters"); + goto sa_dptr_free; + } sa->inst.w7 = ipsec_cpt_inst_w7_get(roc_cpt, sa); #ifdef LA_IPSEC_DEBUG /* Use IV from application in debug mode */ if (ipsec_xfrm->options.iv_gen_disable == 1) { - out_sa->w2.s.iv_src = ROC_IE_OT_SA_IV_SRC_FROM_SA; + sa_dptr->w2.s.iv_src = ROC_IE_OT_SA_IV_SRC_FROM_SA; if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) { sa->iv_offset = crypto_xfrm->aead.iv.offset; sa->iv_length = crypto_xfrm->aead.iv.length; @@ -73,14 +84,15 @@ cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt, #else if (ipsec_xfrm->options.iv_gen_disable != 0) { plt_err("Application provided IV not supported"); - return -ENOTSUP; + ret = -ENOTSUP; + goto sa_dptr_free; } #endif /* Get Rlen calculation data */ ret = cnxk_ipsec_outb_rlens_get(&rlens, ipsec_xfrm, crypto_xfrm); if (ret) - return ret; + goto sa_dptr_free; sa->max_extended_len = rlens.max_extended_len; @@ -110,37 +122,61 @@ cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt, sa->inst.w4 = inst_w4.u64; - return 0; + memset(out_sa, 0, sizeof(struct roc_ot_ipsec_outb_sa)); + + /* Copy word0 from sa_dptr to populate ctx_push_sz ctx_size fields */ + memcpy(out_sa, sa_dptr, 8); + + /* Write session using microcode opcode */ + ret = roc_cpt_ctx_write(lf, sa_dptr, out_sa, + ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ); + if (ret) { + plt_err("Could not write outbound session to hardware"); + goto sa_dptr_free; + } + + /* Trigger CTX flush to write dirty data back to DRAM */ + roc_cpt_lf_ctx_flush(lf, out_sa, false); + +sa_dptr_free: + plt_free(sa_dptr); + + return ret; } static int -cn10k_ipsec_inb_sa_create(struct roc_cpt *roc_cpt, +cn10k_ipsec_inb_sa_create(struct roc_cpt *roc_cpt, struct roc_cpt_lf *lf, struct rte_security_ipsec_xform *ipsec_xfrm, struct rte_crypto_sym_xform *crypto_xfrm, struct rte_security_session *sec_sess) { union roc_ot_ipsec_inb_param1 param1; - struct roc_ot_ipsec_inb_sa *in_sa; + struct roc_ot_ipsec_inb_sa *sa_dptr; struct cn10k_sec_session *sess; struct cn10k_ipsec_sa *sa; union cpt_inst_w4 inst_w4; - int ret; + void *in_sa; + int ret = 0; sess = get_sec_session_private_data(sec_sess); sa = &sess->sa; in_sa = &sa->in_sa; - memset(in_sa, 0, sizeof(struct roc_ot_ipsec_inb_sa)); - - /* Translate security parameters to SA */ - ret = cnxk_ot_ipsec_inb_sa_fill(in_sa, ipsec_xfrm, crypto_xfrm); - if (ret) - return ret; + /* Allocate memory to be used as dptr for CPT ucode WRITE_SA op */ + sa_dptr = plt_zmalloc(ROC_NIX_INL_OT_IPSEC_INB_HW_SZ, 0); + if (sa_dptr == NULL) { + plt_err("Couldn't allocate memory for SA dptr"); + return -ENOMEM; + } - /* TODO add support for antireplay */ - sa->in_sa.w0.s.ar_win = 0; + memset(sa_dptr, 0, sizeof(struct roc_ot_ipsec_inb_sa)); - /* TODO add support for udp encap */ + /* Translate security parameters to SA */ + ret = cnxk_ot_ipsec_inb_sa_fill(sa_dptr, ipsec_xfrm, crypto_xfrm); + if (ret) { + plt_err("Could not fill inbound session parameters"); + goto sa_dptr_free; + } sa->inst.w7 = ipsec_cpt_inst_w7_get(roc_cpt, sa); @@ -173,7 +209,26 @@ cn10k_ipsec_inb_sa_create(struct roc_cpt *roc_cpt, sa->inst.w4 = inst_w4.u64; - return 0; + memset(in_sa, 0, sizeof(struct roc_ot_ipsec_inb_sa)); + + /* Copy word0 from sa_dptr to populate ctx_push_sz ctx_size fields */ + memcpy(in_sa, sa_dptr, 8); + + /* Write session using microcode opcode */ + ret = roc_cpt_ctx_write(lf, sa_dptr, in_sa, + ROC_NIX_INL_OT_IPSEC_INB_HW_SZ); + if (ret) { + plt_err("Could not write inbound session to hardware"); + goto sa_dptr_free; + } + + /* Trigger CTX flush to write dirty data back to DRAM */ + roc_cpt_lf_ctx_flush(lf, in_sa, false); + +sa_dptr_free: + plt_free(sa_dptr); + + return ret; } static int @@ -185,12 +240,11 @@ cn10k_ipsec_session_create(void *dev, struct rte_cryptodev *crypto_dev = dev; struct roc_cpt *roc_cpt; struct cnxk_cpt_vf *vf; + struct cnxk_cpt_qp *qp; int ret; - vf = crypto_dev->data->dev_private; - roc_cpt = &vf->cpt; - - if (crypto_dev->data->queue_pairs[0] == NULL) { + qp = crypto_dev->data->queue_pairs[0]; + if (qp == NULL) { plt_err("Setup cpt queue pair before creating security session"); return -EPERM; } @@ -199,11 +253,14 @@ cn10k_ipsec_session_create(void *dev, if (ret) return ret; + vf = crypto_dev->data->dev_private; + roc_cpt = &vf->cpt; + if (ipsec_xfrm->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) - return cn10k_ipsec_inb_sa_create(roc_cpt, ipsec_xfrm, + return cn10k_ipsec_inb_sa_create(roc_cpt, &qp->lf, ipsec_xfrm, crypto_xfrm, sess); else - return cn10k_ipsec_outb_sa_create(roc_cpt, ipsec_xfrm, + return cn10k_ipsec_outb_sa_create(roc_cpt, &qp->lf, ipsec_xfrm, crypto_xfrm, sess); } -- 2.7.4