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 C234FA0547; Thu, 29 Apr 2021 17:49:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 26AA44135E; Thu, 29 Apr 2021 17:48:55 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2067.outbound.protection.outlook.com [40.107.243.67]) by mails.dpdk.org (Postfix) with ESMTP id 4C3664123F for ; Thu, 29 Apr 2021 17:48:53 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X5wBK7Ve/eigqorPv0t0SPSW9rmL4FGjURgEqm6FCsvkeerOmQ1Sg0WLiRriddDQiqHTk5Hp0H8lvxKb9McRmNpR8CRHY2km+Q2J7DlroEpmRzNlm4Tyhb+ib7q+YNQBsjpU1t6wq6IbvUBhSJsB0G1DPuBbVLyuul2GNu3gZeJ696BtusTxTanrat1kPuY5qaa3KoA21hne7rC/neWCSJuwmuDdtUl3t+Hx3ad9QZrur0bVyX+G2S2iSzsRa1VsafZgiCWOV1wA8CWiFDLf2BG6ZL05ZLUBGL0jq0QG+L3XaQfbMqYStiKHKuJR9HO8N0OWakUufcYBEoisQEoyJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nETauXdE6iVJGJkJRdo3pA09l3/OK4JPg3mITKdVHhI=; b=k2mnfPc+GNjtsQZ4+CwnARJewqW1t2XLSvOs4qewrCuqO/SxDyuyDtjU6u1un9MrXhoVB+VwRHzHL+PfoTLlG7r65R4evz1ozDGEFtNy+XzdJigPnbcQKm1vJtqnJgVIeWHoqHkXZHlOqioCeEHlVfKp4bTBwkN7ye/P/MG+l5WOpo+GCRgQ4HYaipyqRHd+9L6vqS3d1eNF/enPX6fz1FQBL6GCVMFeSzD/PQiVHXd9XW4vsQJumdbemzFSef5Eikeb84Xoo64Iv/hZg737KjTm0WDxDdTD/cO+CFpjdfYibWFGec0jnlF+rAaubjN5F4tbpoXreKLOt6AdQ8aYlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=marvell.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nETauXdE6iVJGJkJRdo3pA09l3/OK4JPg3mITKdVHhI=; b=ayZi8dQBm1JqjDo99X/pOBLszS4Hmty/bKOtbhJIC/5PBbP4HjP4vn9/KA2VUGG/t6ugCW9VtS/cJ/rVNOewKiQw84RIMDym6n2mEnQwPYLQ3HvMrGQKJ8X8h2n2GayjDd0L6yZcKSvLinN9w+exaL58x1RJibD9VbtFgwwSGNSKoZGsG0JMuGhvgZstS9Iz8ZjpqexLC1AWN5zXF3kUbSlaHOD1/T3GFPU3ly3pNFQS5cEj4ofQDAuAYYkEKISiiHAS80TFWo/6cREc60Zi0JLldWx6duYqnWdZJnzhzj06UT6a1Ih/lOxDf/sEIj+MThXFj96XP/2DRGWh3WdNOw== Received: from MWHPR1201CA0010.namprd12.prod.outlook.com (2603:10b6:301:4a::20) by MWHPR12MB1150.namprd12.prod.outlook.com (2603:10b6:300:f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 29 Apr 2021 15:48:51 +0000 Received: from CO1NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4a:cafe::fb) by MWHPR1201CA0010.outlook.office365.com (2603:10b6:301:4a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.25 via Frontend Transport; Thu, 29 Apr 2021 15:48:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT041.mail.protection.outlook.com (10.13.174.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4087.27 via Frontend Transport; Thu, 29 Apr 2021 15:48:51 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 29 Apr 2021 15:48:49 +0000 From: Matan Azrad To: CC: , , Date: Thu, 29 Apr 2021 18:47:10 +0300 Message-ID: <20210429154712.2820159-14-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210429154712.2820159-1-matan@nvidia.com> References: <20210408204849.9543-1-shirik@nvidia.com> <20210429154712.2820159-1-matan@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ebc0d9d-43a6-4c89-48ed-08d90b264940 X-MS-TrafficTypeDiagnostic: MWHPR12MB1150: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:252; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MCg/0bV4Ube0m48Vp9GBEdLVC5ctnjkKw0m5gSRu8RBNv4c+fXqC4/9YuyFSnUUGJuzZgV3wfVmE4QsS69Lozt0fYC8LrEihtK9Mvr9eVe9hNX/hMWw5X13oeaNWYXSmWkC3fyvqEyCjzF4b2aoN7gkrf80Cy6TXx3Np/441WF8Y5I36PsXzYJNsFN/2vR+RVNMX4motRCIGA/yGTYdeWnOtnnqoZDliMVGTP7Oxaf+Qan4Y7e8Gx3CFarZ/lEljO3X5DH+ZL4xWOnx0SAzMe4nqhsUljF5dNGJWWBxCrsxCH/7jtZAq6vIH+K4OTkIzNDNJ58I4FGfHkMK2gsi/HkcKRoCbXSsx5TVGLs9aV1ADdun3yCOxeR2y+/Mbt0/lDfSp5bc+hxTmsfA9d0+95XEmEldd4M58FIan5vVQTNjjhi9bKoTdqYXeE1gbj3czPZj49CBJcM8iigh+yorPRn5HwJ53vMq6xieEEzsBHFc6M+gM362XEyH9bFxKaZyv1hsNNPMRDDjCKGHq977OBA+FASpvymGLrV2jCOQsZKus0vVEudM2EKn45Y01n2k6BLjJHzbX7OofY68WfjTbInb5BfgnONrRL6VWYypCW0XsF+5Ke837zg16di/9UkfHND0WXrxdm4CdtnyUi29ZsRiOO8Inwu8/dhsD3XRf6kc= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(39860400002)(346002)(396003)(136003)(36840700001)(46966006)(86362001)(2616005)(82310400003)(478600001)(426003)(26005)(316002)(55016002)(6666004)(16526019)(70206006)(2906002)(70586007)(36906005)(5660300002)(186003)(7696005)(107886003)(6916009)(6286002)(1076003)(8676002)(36860700001)(356005)(36756003)(7636003)(82740400003)(336012)(4326008)(83380400001)(54906003)(47076005)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2021 15:48:51.3999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ebc0d9d-43a6-4c89-48ed-08d90b264940 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1150 Subject: [dpdk-dev] [PATCH v2 13/15] crypto/mlx5: add enqueue and dequeue operations 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: Suanming Mou The crypto operations are done with the WQE set which contains one UMR WQE and one rdma write WQE. Most segments of the WQE set are initialized properly during queue setup, only limited segments are initialized according to the crypto detail in the datapath process. This commit adds the enquue and dequeue operations and updates the WQE set segments accordingly. Signed-off-by: Suanming Mou Signed-off-by: Matan Azrad --- drivers/crypto/mlx5/mlx5_crypto.c | 243 +++++++++++++++++++++++++++++- drivers/crypto/mlx5/mlx5_crypto.h | 3 + 2 files changed, 241 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index e8f68eb115..08a8c1e925 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -268,6 +268,239 @@ mlx5_crypto_qp2rts(struct mlx5_crypto_qp *qp) return 0; } +static __rte_noinline uint32_t +mlx5_crypto_get_block_size(struct rte_crypto_op *op) +{ + uint32_t bl = op->sym->cipher.data.length; + + switch (bl) { + case (1 << 20): + return RTE_BE32(MLX5_BLOCK_SIZE_1MB << MLX5_BLOCK_SIZE_OFFSET); + case (1 << 12): + return RTE_BE32(MLX5_BLOCK_SIZE_4096B << + MLX5_BLOCK_SIZE_OFFSET); + case (1 << 9): + return RTE_BE32(MLX5_BLOCK_SIZE_512B << MLX5_BLOCK_SIZE_OFFSET); + default: + DRV_LOG(ERR, "Unknown block size: %u.", bl); + return UINT32_MAX; + } +} + +static __rte_always_inline uint32_t +mlx5_crypto_klm_set(struct mlx5_crypto_priv *priv, struct mlx5_crypto_qp *qp, + struct rte_mbuf *mbuf, struct mlx5_wqe_dseg *klm, + uint32_t offset, uint32_t *remain) +{ + uint32_t data_len = (rte_pktmbuf_data_len(mbuf) - offset); + uintptr_t addr = rte_pktmbuf_mtod_offset(mbuf, uintptr_t, offset); + + if (data_len > *remain) + data_len = *remain; + *remain -= data_len; + klm->bcount = rte_cpu_to_be_32(data_len); + klm->pbuf = rte_cpu_to_be_64(addr); + klm->lkey = mlx5_mr_addr2mr_bh(priv->pd, 0, + &priv->mr_scache, &qp->mr_ctrl, addr, + !!(mbuf->ol_flags & EXT_ATTACHED_MBUF)); + return klm->lkey; + +} + +static __rte_always_inline uint32_t +mlx5_crypto_klms_set(struct mlx5_crypto_priv *priv, struct mlx5_crypto_qp *qp, + struct rte_crypto_op *op, struct rte_mbuf *mbuf, + struct mlx5_wqe_dseg *klm) +{ + uint32_t remain_len = op->sym->cipher.data.length; + uint32_t nb_segs = mbuf->nb_segs; + uint32_t klm_n = 1; + + /* First mbuf needs to take the cipher offset. */ + if (unlikely(mlx5_crypto_klm_set(priv, qp, mbuf, klm, + op->sym->cipher.data.offset, &remain_len) == UINT32_MAX)) { + op->status = RTE_CRYPTO_OP_STATUS_ERROR; + return 0; + } + while (remain_len) { + nb_segs--; + mbuf = mbuf->next; + if (unlikely(mbuf == NULL || nb_segs == 0)) { + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return 0; + } + if (unlikely(mlx5_crypto_klm_set(priv, qp, mbuf, klm, 0, + &remain_len) == UINT32_MAX)) { + op->status = RTE_CRYPTO_OP_STATUS_ERROR; + return 0; + } + klm_n++; + } + return klm_n; +} + +static __rte_always_inline int +mlx5_crypto_wqe_set(struct mlx5_crypto_priv *priv, + struct mlx5_crypto_qp *qp, + struct rte_crypto_op *op, + struct mlx5_umr_wqe *umr) +{ + struct mlx5_crypto_session *sess = get_sym_session_private_data + (op->sym->session, mlx5_crypto_driver_id); + struct mlx5_wqe_cseg *cseg = &umr->ctr; + struct mlx5_wqe_mkey_cseg *mkc = &umr->mkc; + struct mlx5_wqe_dseg *klms = &umr->kseg[0]; + struct mlx5_wqe_umr_bsf_seg *bsf = ((struct mlx5_wqe_umr_bsf_seg *) + RTE_PTR_ADD(umr, priv->umr_wqe_size)) - 1; + uint16_t nop_ds; + /* Set UMR WQE. */ + uint32_t klm_n = mlx5_crypto_klms_set(priv, qp, op, + op->sym->m_dst ? op->sym->m_dst : op->sym->m_src, klms); + + if (unlikely(klm_n == 0)) + return 0; + bsf->bs_bpt_eo_es = sess->bs_bpt_eo_es; + if (unlikely(!sess->bsp_res)) { + bsf->bsp_res = mlx5_crypto_get_block_size(op); + if (unlikely(bsf->bsp_res == UINT32_MAX)) { + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return 0; + } + } else { + bsf->bsp_res = sess->bsp_res; + } + bsf->raw_data_size = rte_cpu_to_be_32(op->sym->cipher.data.length); + memcpy(bsf->xts_initial_tweak, + rte_crypto_op_ctod_offset(op, uint8_t *, sess->iv_offset), 16); + bsf->res_dp = sess->dek_id; + cseg->opcode = rte_cpu_to_be_32((qp->db_pi << 8) | MLX5_OPCODE_UMR); + mkc->len = rte_cpu_to_be_64(op->sym->cipher.data.length); + /* Set RDMA_WRITE WQE. */ + cseg = RTE_PTR_ADD(cseg, priv->umr_wqe_size); + klms = RTE_PTR_ADD(cseg, sizeof(struct mlx5_rdma_write_wqe)); + cseg->opcode = rte_cpu_to_be_32((qp->db_pi << 8) | + MLX5_OPCODE_RDMA_WRITE); + if (op->sym->m_dst != op->sym->m_src) { + klm_n = mlx5_crypto_klms_set(priv, qp, op, op->sym->m_src, + klms); + if (unlikely(klm_n == 0)) + return 0; + } else { + memcpy(klms, &umr->kseg[0], sizeof(*klms) * klm_n); + } + cseg->sq_ds = rte_cpu_to_be_32((qp->qp_obj->id << 8) | (2 + klm_n)); + qp->db_pi += priv->wqe_stride; + /* Set NOP WQE if needed. */ + klm_n = RTE_ALIGN(klm_n + 2, 4) - 2; + nop_ds = priv->max_rdmaw_klm_n - klm_n; + if (nop_ds) { + cseg = (struct mlx5_wqe_cseg *)(klms + klm_n); + cseg->opcode = rte_cpu_to_be_32(((qp->db_pi - (nop_ds >> 2)) << + 8) | MLX5_OPCODE_NOP); + cseg->sq_ds = rte_cpu_to_be_32((qp->qp_obj->id << 8) | nop_ds); + } + qp->wqe = (uint8_t *)cseg; + return 1; +} + +static __rte_always_inline void +mlx5_crypto_uar_write(uint64_t val, struct mlx5_crypto_priv *priv) +{ +#ifdef RTE_ARCH_64 + *priv->uar_addr = val; +#else /* !RTE_ARCH_64 */ + rte_spinlock_lock(&priv->uar32_sl); + *(volatile uint32_t *)priv->uar_addr = val; + rte_io_wmb(); + *((volatile uint32_t *)priv->uar_addr + 1) = val >> 32; + rte_spinlock_unlock(&priv->uar32_sl); +#endif +} + +static uint16_t +mlx5_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, + uint16_t nb_ops) +{ + struct mlx5_crypto_qp *qp = queue_pair; + struct mlx5_crypto_priv *priv = qp->priv; + struct mlx5_umr_wqe *umr; + struct rte_crypto_op *op; + uint16_t mask = qp->entries_n - 1; + uint16_t remain = qp->entries_n - (qp->pi - qp->ci); + + if (remain < nb_ops) + nb_ops = remain; + else + remain = nb_ops; + if (unlikely(remain == 0)) + return 0; + do { + op = *ops++; + umr = RTE_PTR_ADD(qp->umem_buf, priv->wqe_set_size * qp->pi); + if (unlikely(mlx5_crypto_wqe_set(priv, qp, op, umr) == 0)) + break; + qp->ops[qp->pi] = op; + qp->pi = (qp->pi + 1) & mask; + } while (--remain); + rte_io_wmb(); + qp->db_rec[MLX5_SND_DBR] = rte_cpu_to_be_32(qp->db_pi); + rte_wmb(); + mlx5_crypto_uar_write(*(volatile uint64_t *)qp->wqe, qp->priv); + rte_wmb(); + return nb_ops; +} + +static __rte_noinline void +mlx5_crypto_cqe_err_handle(struct mlx5_crypto_qp *qp, struct rte_crypto_op *op) +{ + const uint32_t idx = qp->ci & (qp->entries_n - 1); + volatile struct mlx5_err_cqe *cqe = (volatile struct mlx5_err_cqe *) + &qp->cq_obj.cqes[idx]; + + op->status = RTE_CRYPTO_OP_STATUS_ERROR; + DRV_LOG(ERR, "CQE ERR:%x.\n", rte_be_to_cpu_32(cqe->syndrome)); +} + +static uint16_t +mlx5_crypto_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, + uint16_t nb_ops) +{ + struct mlx5_crypto_qp *qp = queue_pair; + volatile struct mlx5_cqe *restrict cqe; + struct rte_crypto_op *restrict op; + const unsigned int cq_size = qp->entries_n; + const unsigned int mask = cq_size - 1; + uint32_t idx; + uint32_t next_idx = qp->ci & mask; + const uint16_t max = RTE_MIN((uint16_t)(qp->pi - qp->ci), nb_ops); + uint16_t i = 0; + int ret; + + if (unlikely(max == 0)) + return 0; + do { + idx = next_idx; + next_idx = (qp->ci + 1) & mask; + op = qp->ops[idx]; + cqe = &qp->cq_obj.cqes[idx]; + ret = check_cqe(cqe, cq_size, qp->ci); + rte_io_rmb(); + if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) { + if (unlikely(ret != MLX5_CQE_STATUS_HW_OWN)) + mlx5_crypto_cqe_err_handle(qp, op); + break; + } + op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; + ops[i++] = op; + qp->ci++; + } while (i < max); + if (likely(i != 0)) { + rte_io_wmb(); + qp->cq_obj.db_rec[0] = rte_cpu_to_be_32(qp->ci); + } + return i; +} + static void mlx5_crypto_qp_init(struct mlx5_crypto_priv *priv, struct mlx5_crypto_qp *qp) { @@ -489,8 +722,9 @@ mlx5_crypto_hw_global_prepare(struct mlx5_crypto_priv *priv) if (mlx5_crypto_pd_create(priv) != 0) return -1; priv->uar = mlx5_devx_alloc_uar(priv->ctx, -1); - if (priv->uar == NULL || mlx5_os_get_devx_uar_reg_addr(priv->uar) == - NULL) { + if (priv->uar) + priv->uar_addr = mlx5_os_get_devx_uar_reg_addr(priv->uar); + if (priv->uar == NULL || priv->uar_addr == NULL) { rte_errno = errno; claim_zero(mlx5_glue->dealloc_pd(priv->pd)); DRV_LOG(ERR, "Failed to allocate UAR."); @@ -685,9 +919,8 @@ mlx5_crypto_pci_probe(struct rte_pci_driver *pci_drv, DRV_LOG(INFO, "Crypto device %s was created successfully.", ibv->name); crypto_dev->dev_ops = &mlx5_crypto_ops; - crypto_dev->dequeue_burst = NULL; - crypto_dev->enqueue_burst = NULL; - crypto_dev->feature_flags = RTE_CRYPTODEV_FF_HW_ACCELERATED; + crypto_dev->dequeue_burst = mlx5_crypto_dequeue_burst; + crypto_dev->enqueue_burst = mlx5_crypto_enqueue_burst; crypto_dev->driver_id = mlx5_crypto_driver_id; priv = crypto_dev->data->dev_private; priv->ctx = ctx; diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index 52fcf5217f..ac4ad1834f 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.h +++ b/drivers/crypto/mlx5/mlx5_crypto.h @@ -37,6 +37,9 @@ struct mlx5_crypto_priv { uint16_t rdmw_wqe_size; uint16_t wqe_stride; uint16_t max_rdmaw_klm_n; +#ifndef RTE_ARCH_64 + rte_spinlock_t uar32_sl; +#endif /* RTE_ARCH_64 */ }; struct mlx5_crypto_qp { -- 2.25.1