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 3ECF2A0C40; Fri, 25 Jun 2021 07:57:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98E5D40E78; Fri, 25 Jun 2021 07:57:26 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 48559410E8 for ; Fri, 25 Jun 2021 07:57:25 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15P5vCcm018209; Thu, 24 Jun 2021 22:57:24 -0700 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=vD6/gvBXS4iew80t9g1oXny7Lm0qEJUjSxcLyTyVdNg=; b=LJhYLTUksoMmcEcgwLrcqbcyr2KPD9qVIoQrbym3j8Mdq/F8oN0M0KMt7JmIz5X75mar 16kUYp8SXRHzgVHZT8/noa3BStxe6YECs03+2/7K1SoMNuFEfgMVIfdT40Er2FLMtfLM Lboq0rj4QxxcDJ5tnewcUQarxytp02NtisMeyo8lgJr4019IKrivmZi/+mLzqwoJ+PdE qBmA8//kAiBDovBV8Gbmn1ERj9bEytw7kZ8HKrypQD1qjNOEZO505FcRTce2mgujgT9/ AI7xZIcJk4nvq/OxTQLJotOQE9dBrzvuJFhEUuAoqiWjQepZy7BntLSyiEm7q0GlIGJh MA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 39d241shqa-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 24 Jun 2021 22:57:24 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 24 Jun 2021 22:57:22 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 24 Jun 2021 22:57:22 -0700 Received: from HY-LT1002.marvell.com (HY-LT1002.marvell.com [10.28.176.218]) by maili.marvell.com (Postfix) with ESMTP id 2D5E93F7068; Thu, 24 Jun 2021 22:57:18 -0700 (PDT) From: Anoob Joseph To: Akhil Goyal , Thomas Monjalon CC: Ankur Dwivedi , Jerin Jacob , Tejasree Kondoj , , Anoob Joseph , Archana Muniganti Date: Fri, 25 Jun 2021 11:26:15 +0530 Message-ID: <1624600591-29841-5-git-send-email-anoobj@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1624600591-29841-1-git-send-email-anoobj@marvell.com> References: <1624600591-29841-1-git-send-email-anoobj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: JUn-pX_daQ6r1cxF3omFoNZ9OxkW_jb3 X-Proofpoint-ORIG-GUID: JUn-pX_daQ6r1cxF3omFoNZ9OxkW_jb3 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-25_02:2021-06-24, 2021-06-25 signatures=0 Subject: [dpdk-dev] [PATCH v2 04/20] crypto/cnxk: add queue pair ops 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 Sender: "dev" From: Ankur Dwivedi Add ops for - queue_pair_setup() - queue_pair_release() Signed-off-by: Ankur Dwivedi Signed-off-by: Anoob Joseph Signed-off-by: Archana Muniganti Signed-off-by: Tejasree Kondoj --- drivers/crypto/cnxk/cn10k_cryptodev_ops.c | 4 +- drivers/crypto/cnxk/cn9k_cryptodev_ops.c | 4 +- drivers/crypto/cnxk/cnxk_cryptodev_ops.c | 253 ++++++++++++++++++++++++++++++ drivers/crypto/cnxk/cnxk_cryptodev_ops.h | 48 ++++++ 4 files changed, 305 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c index b0eccb3..007d449 100644 --- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c +++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c @@ -29,8 +29,8 @@ struct rte_cryptodev_ops cn10k_cpt_ops = { .stats_get = NULL, .stats_reset = NULL, - .queue_pair_setup = NULL, - .queue_pair_release = NULL, + .queue_pair_setup = cnxk_cpt_queue_pair_setup, + .queue_pair_release = cnxk_cpt_queue_pair_release, /* Symmetric crypto ops */ .sym_session_get_size = NULL, diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c index acfb071..73ccf5b 100644 --- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c +++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c @@ -29,8 +29,8 @@ struct rte_cryptodev_ops cn9k_cpt_ops = { .stats_get = NULL, .stats_reset = NULL, - .queue_pair_setup = NULL, - .queue_pair_release = NULL, + .queue_pair_setup = cnxk_cpt_queue_pair_setup, + .queue_pair_release = cnxk_cpt_queue_pair_release, /* Symmetric crypto ops */ .sym_session_get_size = NULL, diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c index 810f3b8..cf04aec 100644 --- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c +++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c @@ -11,6 +11,24 @@ #include "cnxk_cryptodev.h" #include "cnxk_cryptodev_ops.h" +static int +cnxk_cpt_get_mlen(void) +{ + uint32_t len; + + /* For MAC */ + len = 2 * sizeof(uint64_t); + len += ROC_SE_MAX_MAC_LEN * sizeof(uint8_t); + + len += ROC_SE_OFF_CTRL_LEN + ROC_CPT_AES_CBC_IV_LEN; + len += RTE_ALIGN_CEIL((ROC_SE_SG_LIST_HDR_SIZE + + (RTE_ALIGN_CEIL(ROC_SE_MAX_SG_IN_OUT_CNT, 4) >> + 2) * ROC_SE_SG_ENTRY_SIZE), + 8); + + return len; +} + int cnxk_cpt_dev_config(struct rte_cryptodev *dev, struct rte_cryptodev_config *conf) @@ -55,6 +73,16 @@ int cnxk_cpt_dev_close(struct rte_cryptodev *dev) { struct cnxk_cpt_vf *vf = dev->data->dev_private; + uint16_t i; + int ret; + + for (i = 0; i < dev->data->nb_queue_pairs; i++) { + ret = cnxk_cpt_queue_pair_release(dev, i); + if (ret < 0) { + plt_err("Could not release queue pair %u", i); + return ret; + } + } roc_cpt_dev_clear(&vf->cpt); @@ -75,3 +103,228 @@ cnxk_cpt_dev_info_get(struct rte_cryptodev *dev, info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ; info->min_mbuf_tailroom_req = 0; } + +static void +qp_memzone_name_get(char *name, int size, int dev_id, int qp_id) +{ + snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id); +} + +static int +cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev, + struct cnxk_cpt_qp *qp, uint8_t qp_id, + uint32_t nb_elements) +{ + char mempool_name[RTE_MEMPOOL_NAMESIZE]; + struct cpt_qp_meta_info *meta_info; + struct rte_mempool *pool; + uint32_t cache_sz; + int mlen = 8; + + if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) { + /* Get meta len */ + mlen = cnxk_cpt_get_mlen(); + } + + cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, nb_elements / 1.5); + + /* Allocate mempool */ + + snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u", + dev->data->dev_id, qp_id); + + pool = rte_mempool_create(mempool_name, nb_elements, mlen, cache_sz, 0, + NULL, NULL, NULL, NULL, rte_socket_id(), 0); + + if (pool == NULL) { + plt_err("Could not create mempool for metabuf"); + return rte_errno; + } + + meta_info = &qp->meta_info; + + meta_info->pool = pool; + meta_info->mlen = mlen; + + return 0; +} + +static void +cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp) +{ + struct cpt_qp_meta_info *meta_info = &qp->meta_info; + + rte_mempool_free(meta_info->pool); + + meta_info->pool = NULL; + meta_info->mlen = 0; +} + +static struct cnxk_cpt_qp * +cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id, + uint32_t iq_len) +{ + const struct rte_memzone *pq_mem; + char name[RTE_MEMZONE_NAMESIZE]; + struct cnxk_cpt_qp *qp; + uint32_t len; + uint8_t *va; + int ret; + + /* Allocate queue pair */ + qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp), + ROC_ALIGN, 0); + if (qp == NULL) { + plt_err("Could not allocate queue pair"); + return NULL; + } + + /* For pending queue */ + len = iq_len * sizeof(struct cpt_inflight_req); + + qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id, + qp_id); + + pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(), + RTE_MEMZONE_SIZE_HINT_ONLY | + RTE_MEMZONE_256MB, + RTE_CACHE_LINE_SIZE); + if (pq_mem == NULL) { + plt_err("Could not allocate reserved memzone"); + goto qp_free; + } + + va = pq_mem->addr; + + memset(va, 0, len); + + ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len); + if (ret) { + plt_err("Could not create mempool for metabuf"); + goto pq_mem_free; + } + + /* Initialize pending queue */ + qp->pend_q.req_queue = pq_mem->addr; + qp->pend_q.enq_tail = 0; + qp->pend_q.deq_head = 0; + qp->pend_q.pending_count = 0; + + return qp; + +pq_mem_free: + rte_memzone_free(pq_mem); +qp_free: + rte_free(qp); + return NULL; +} + +static int +cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp) +{ + const struct rte_memzone *pq_mem; + char name[RTE_MEMZONE_NAMESIZE]; + int ret; + + cnxk_cpt_metabuf_mempool_destroy(qp); + + qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id, + qp->lf.lf_id); + + pq_mem = rte_memzone_lookup(name); + + ret = rte_memzone_free(pq_mem); + if (ret) + return ret; + + rte_free(qp); + + return 0; +} + +int +cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id) +{ + struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id]; + struct cnxk_cpt_vf *vf = dev->data->dev_private; + struct roc_cpt *roc_cpt = &vf->cpt; + struct roc_cpt_lf *lf; + int ret; + + if (qp == NULL) + return -EINVAL; + + lf = roc_cpt->lf[qp_id]; + if (lf == NULL) + return -ENOTSUP; + + roc_cpt_lf_fini(lf); + + ret = cnxk_cpt_qp_destroy(dev, qp); + if (ret) { + plt_err("Could not destroy queue pair %d", qp_id); + return ret; + } + + roc_cpt->lf[qp_id] = NULL; + dev->data->queue_pairs[qp_id] = NULL; + + return 0; +} + +int +cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id, + const struct rte_cryptodev_qp_conf *conf, + int socket_id __rte_unused) +{ + struct cnxk_cpt_vf *vf = dev->data->dev_private; + struct roc_cpt *roc_cpt = &vf->cpt; + struct rte_pci_device *pci_dev; + struct cnxk_cpt_qp *qp; + int ret; + + if (dev->data->queue_pairs[qp_id] != NULL) + cnxk_cpt_queue_pair_release(dev, qp_id); + + pci_dev = RTE_DEV_TO_PCI(dev->device); + + if (pci_dev->mem_resource[2].addr == NULL) { + plt_err("Invalid PCI mem address"); + return -EIO; + } + + qp = cnxk_cpt_qp_create(dev, qp_id, conf->nb_descriptors); + if (qp == NULL) { + plt_err("Could not create queue pair %d", qp_id); + return -ENOMEM; + } + + qp->lf.lf_id = qp_id; + qp->lf.nb_desc = conf->nb_descriptors; + + ret = roc_cpt_lf_init(roc_cpt, &qp->lf); + if (ret < 0) { + plt_err("Could not initialize queue pair %d", qp_id); + ret = -EINVAL; + goto exit; + } + + roc_cpt->lf[qp_id] = &qp->lf; + + ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id); + if (ret < 0) { + roc_cpt->lf[qp_id] = NULL; + plt_err("Could not init lmtline for queue pair %d", qp_id); + goto exit; + } + + qp->sess_mp = conf->mp_session; + qp->sess_mp_priv = conf->mp_session_private; + dev->data->queue_pairs[qp_id] = qp; + + return 0; + +exit: + cnxk_cpt_qp_destroy(dev, qp); + return ret; +} diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h index 05c2623..f9440f9 100644 --- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h +++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h @@ -7,8 +7,50 @@ #include +#include "roc_api.h" + #define CNXK_CPT_MIN_HEADROOM_REQ 24 +struct cpt_qp_meta_info { + struct rte_mempool *pool; + int mlen; +}; + +struct cpt_inflight_req { + union cpt_res_s res; + struct rte_crypto_op *cop; + void *mdata; + uint8_t op_flags; +} __rte_aligned(16); + +struct pending_queue { + /** Pending requests count */ + uint64_t pending_count; + /** Array of pending requests */ + struct cpt_inflight_req *req_queue; + /** Tail of queue to be used for enqueue */ + uint16_t enq_tail; + /** Head of queue to be used for dequeue */ + uint16_t deq_head; + /** Timeout to track h/w being unresponsive */ + uint64_t time_out; +}; + +struct cnxk_cpt_qp { + struct roc_cpt_lf lf; + /**< Crypto LF */ + struct pending_queue pend_q; + /**< Pending queue */ + struct rte_mempool *sess_mp; + /**< Session mempool */ + struct rte_mempool *sess_mp_priv; + /**< Session private data mempool */ + struct cpt_qp_meta_info meta_info; + /**< Metabuf info required to support operations on the queue pair */ + struct roc_cpt_lmtline lmtline; + /**< Lmtline information */ +}; + int cnxk_cpt_dev_config(struct rte_cryptodev *dev, struct rte_cryptodev_config *conf); @@ -21,4 +63,10 @@ int cnxk_cpt_dev_close(struct rte_cryptodev *dev); void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info); +int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id, + const struct rte_cryptodev_qp_conf *conf, + int socket_id __rte_unused); + +int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id); + #endif /* _CNXK_CRYPTODEV_OPS_H_ */ -- 2.7.4