From patchwork Wed Oct 26 10:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618808 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317042pvb; Wed, 26 Oct 2022 04:01:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4K0cWJDyK5N99+RxA3JTSLAwl5gYJPmxsrJewtGARPcRe237XpY2eftI+7yv0k7BASFC+V X-Received: by 2002:a5d:4ac8:0:b0:236:781a:8d2d with SMTP id y8-20020a5d4ac8000000b00236781a8d2dmr8898402wrs.715.1666782085621; Wed, 26 Oct 2022 04:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782085; cv=none; d=google.com; s=arc-20160816; b=u0sNKM5MBOCqcbbc0ShpEV5+5remoi9JsPelTNungg2OhceKUMK4dWJYgPKE5b/SsH O3S0F86EoW10tVlRdBBCijYUowh+19fDXmHs8x/lBxYU6y8lTBKqVrui4HEPzKRDypfD o7UqA7az3pxgw+jWYGzwYG8L0+wFPf7tLZJn75t85p3Nw78wP205Qo2Ye2/vbSVxiqmp pArHP+65O8xWi2Jm5eajaNEPKZ6+JiaOf480AB2Nwh6o8SeediGwZLQxy+OKR12BbX96 b1yvctj0CMbHvMFe6VUOjZL4qDLOrRWFlQIUzWovGHX63NdL0gQI1bGIOgdB484wKnVh 8LYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mA2GgYtrtLWfJ7gQUEuGSD6oUUd9ZrpUWfXaS4o+1ro=; b=PRUQMyR+iazZ223fwQgEQ1W+G5qrqOa8QwVD6XTYKThd2BSts4GZIGcmHHPuUt4Z7+ c/d3EdYOSttZgTw/efvG0ScK9BPuzfOF68Qx3khZ1rx6S02P6NFtBqlPvcw0rxI01j9e H+sArSqLeOisBo0WxcFlG6fCTSX81qMMKN/Ksg/KEPce/vH520FJGYSsx8ODF4+Teq2H XapPGQrrFjq4k8CsCbihnk3Lqc8iMOJYvTT1LbkwxnTYEW9ukbi5zrANIu+NvCxrQunP tm1lYFUhLXv7VI//VbtvCh+FAiKe6nVjRuiB1Mz5nc3JL8A0OZvrgLA+szgtjqjKio0C pNpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tkchKPBR; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id iv19-20020a05600c549300b003cf42c30ec6si1563505wmb.34.2022.10.26.04.01.25; Wed, 26 Oct 2022 04:01:25 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tkchKPBR; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 673F1427F6; Wed, 26 Oct 2022 13:01:22 +0200 (CEST) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by mails.dpdk.org (Postfix) with ESMTP id A692440041 for ; Wed, 26 Oct 2022 13:01:18 +0200 (CEST) Received: by mail-wr1-f43.google.com with SMTP id z14so12174695wrn.7 for ; Wed, 26 Oct 2022 04:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mA2GgYtrtLWfJ7gQUEuGSD6oUUd9ZrpUWfXaS4o+1ro=; b=tkchKPBR+girVC1HDR3VMo/LZj75TDczCgJwD7MzVH7tYfy1P8f++xAMzxZ8m1MXol I3dYwvYVg2SqN7xyGl05fwBlyPf7uZifFK5i3XymHDvPEEqas904tASBlqgB6ninBO4x scO8zB9lau+bsWcpqt1nTxzFN9c4H7dcZvcB7crSlUYOxFen8rlJMczPDOkTcJJ3v9mX ayGOL1aFlOv394EMQXBoyqDLDL/sAiSrRqP0GEokjxzoyPfQ75TjNH4x9EzjDXEGrDhK UK6Ne7cac0k1rVtpqoLzx5E5rhgCxYKqMRT/3JAceWVdkV2NvvjVfIJsCCN8oBPtVJWZ lKzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mA2GgYtrtLWfJ7gQUEuGSD6oUUd9ZrpUWfXaS4o+1ro=; b=472OEja7W3inwUAsGgPLbwFjs5F4eABVJqIs78ARFde8aCXy4ivibb4NmqQr2GeKXz Mb8nilGiHhMFhjR/2fTmw16pT74rfg2Uig9RKVLv3MfyNgVBae3zQyQM0KEOTXTJFiqJ 99PFlfATZ9dYkdPHgxnmrnjgUp6bxnF5UVTPIYPRa2omP+dYyct4wSfj9QTtexz5KCoM V98oish7hDB2bJBOVeoneqwfR1JLnTcOJXuG4C28sDTgC2rkrpeJ6n8i9j+6rWWLjvmS PzbmKcUn9YnkOeSK5tyJ8+Ldz19BZ7Bmp4OD/d5urJQtaCZ9CdlJZy9zztE/7/k2YPdh +o2Q== X-Gm-Message-State: ACrzQf1RHt60LXdtOOsJKejkVdDTbAPo9EseEp+vt0712BHnFDaPSeX9 k6aQ39xHF2Zvzgo/LtOnyJAlsA== X-Received: by 2002:adf:dd4d:0:b0:236:6e72:be17 with SMTP id u13-20020adfdd4d000000b002366e72be17mr10985607wrm.460.1666782078337; Wed, 26 Oct 2022 04:01:18 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:17 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 1/6] crypto/uadk: introduce uadk crypto driver Date: Wed, 26 Oct 2022 18:54:24 +0800 Message-Id: <20221026105429.1899867-2-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 Introduce a new crypto PMD for hardware accelerators based on UADK [1]. UADK is a framework for user applications to access hardware accelerators. UADK relies on IOMMU SVA (Shared Virtual Address) feature, which share the same page table between IOMMU and MMU. Thereby user application can directly use virtual address for device dma, which enhances the performance as well as easy usability. This patch adds the basic framework. [1] https://github.com/Linaro/uadk Signed-off-by: Zhangfei Gao --- MAINTAINERS | 6 + doc/guides/cryptodevs/features/uadk.ini | 33 ++++++ doc/guides/cryptodevs/index.rst | 1 + doc/guides/cryptodevs/uadk.rst | 72 ++++++++++++ doc/guides/rel_notes/release_22_11.rst | 6 + drivers/crypto/meson.build | 1 + drivers/crypto/uadk/meson.build | 30 +++++ drivers/crypto/uadk/uadk_crypto_pmd.c | 110 ++++++++++++++++++ drivers/crypto/uadk/uadk_crypto_pmd_private.h | 25 ++++ drivers/crypto/uadk/version.map | 3 + 10 files changed, 287 insertions(+) create mode 100644 doc/guides/cryptodevs/features/uadk.ini create mode 100644 doc/guides/cryptodevs/uadk.rst create mode 100644 drivers/crypto/uadk/meson.build create mode 100644 drivers/crypto/uadk/uadk_crypto_pmd.c create mode 100644 drivers/crypto/uadk/uadk_crypto_pmd_private.h create mode 100644 drivers/crypto/uadk/version.map diff --git a/MAINTAINERS b/MAINTAINERS index 6f56111323..bf9baa9070 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1060,6 +1060,12 @@ M: Kai Ji F: drivers/crypto/scheduler/ F: doc/guides/cryptodevs/scheduler.rst +HiSilicon UADK crypto +M: Zhangfei Gao +F: drivers/crypto/uadk/ +F: doc/guides/cryptodevs/uadk.rst +F: doc/guides/cryptodevs/features/uadk.ini + Intel QuickAssist M: Kai Ji F: drivers/crypto/qat/ diff --git a/doc/guides/cryptodevs/features/uadk.ini b/doc/guides/cryptodevs/features/uadk.ini new file mode 100644 index 0000000000..df5ad40e3d --- /dev/null +++ b/doc/guides/cryptodevs/features/uadk.ini @@ -0,0 +1,33 @@ +; +; Supported features of the 'uadk' crypto driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +HW Accelerated = Y + +; +; Supported crypto algorithms of the 'uadk' crypto driver. +; +[Cipher] + +; +; Supported authentication algorithms of the 'uadk' crypto driver. +; +[Auth] + +; +; Supported AEAD algorithms of the 'uadk' crypto driver. +; +[AEAD] + +; +; Supported Asymmetric algorithms of the 'uadk' crypto driver. +; +[Asymmetric] + +; +; Supported Operating systems of the 'uadk' crypto driver. +; +[OS] +Linux = Y diff --git a/doc/guides/cryptodevs/index.rst b/doc/guides/cryptodevs/index.rst index 39cca6dbde..cb4ce227e9 100644 --- a/doc/guides/cryptodevs/index.rst +++ b/doc/guides/cryptodevs/index.rst @@ -30,5 +30,6 @@ Crypto Device Drivers scheduler snow3g qat + uadk virtio zuc diff --git a/doc/guides/cryptodevs/uadk.rst b/doc/guides/cryptodevs/uadk.rst new file mode 100644 index 0000000000..2a0cb300e9 --- /dev/null +++ b/doc/guides/cryptodevs/uadk.rst @@ -0,0 +1,72 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright 2022-2023 Huawei Technologies Co.,Ltd. All rights reserved. + Copyright 2022-2023 Linaro ltd. + +UADK Crypto Poll Mode Driver +============================ + +This code provides the initial implementation of the UADK poll mode +driver. All cryptographic operations are using UADK library crypto API, +which is algorithm level API, abstracting accelerators' low level +implementations. + +UADK crypto PMD relies on UADK library [1] + +UADK is a framework for user applications to access hardware accelerators. +UADK relies on IOMMU SVA (Shared Virtual Address) feature, which share +the same page table between IOMMU and MMU. +As a result, user application can directly use virtual address for device DMA, +which enhances the performance as well as easy usability. + + +Features +-------- + +UADK crypto PMD has support for: + + +Test steps +---------- + + .. code-block:: console + + 1. Build UADK + $ git clone https://github.com/Linaro/uadk.git + $ cd uadk + $ mkdir build + $ ./autogen.sh + $ ./configure --prefix=$PWD/build + $ make + $ make install + + * Without --prefix, UADK will be installed to /usr/local/lib by default + * If get error:"cannot find -lnuma", please install the libnuma-dev + + 2. Run pkg-config libwd to ensure env is setup correctly + $ export PKG_CONFIG_PATH=$PWD/build/lib/pkgconfig + $ pkg-config libwd --cflags --libs + -I/usr/local/include -L/usr/local/lib -lwd + + * export PKG_CONFIG_PATH is required on demand, + not needed if UADK is installed to /usr/local/lib + + 3. Build DPDK + $ cd dpdk + $ mkdir build + $ meson build (--reconfigure) + $ cd build + $ ninja + $ sudo ninja install + + 4. Prepare hugepage for dpdk + $ echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages + $ echo 1024 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages + $ echo 1024 > /sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages + $ echo 1024 > /sys/devices/system/node/node3/hugepages/hugepages-2048kB/nr_hugepages + $ mkdir -p /mnt/huge_2mb + $ mount -t hugetlbfs none /mnt/huge_2mb -o pagesize=2MB + + 5. Run test app + + +[1] https://github.com/Linaro/uadk diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index 81cd66390d..6126031d2b 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -197,6 +197,12 @@ New Features integrated on SPR-EE. See the :doc:`../bbdevs/acc200` BBDEV guide for more details on this new driver. +* **Added UADK crypto driver.** + + Added a new ``UADK`` crypto driver for the UADK library + See the + :doc:`../cryptodevs/uadk.rst` UADK guide for more details on this new driver. + * **Added eventdev adapter instance get API.** * Added ``rte_event_eth_rx_adapter_instance_get`` to get Rx adapter diff --git a/drivers/crypto/meson.build b/drivers/crypto/meson.build index 147b8cf633..ee5377deff 100644 --- a/drivers/crypto/meson.build +++ b/drivers/crypto/meson.build @@ -18,6 +18,7 @@ drivers = [ 'octeontx', 'openssl', 'scheduler', + 'uadk', 'virtio', ] diff --git a/drivers/crypto/uadk/meson.build b/drivers/crypto/uadk/meson.build new file mode 100644 index 0000000000..f6fae0a239 --- /dev/null +++ b/drivers/crypto/uadk/meson.build @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022-2023 Huawei Technologies Co.,Ltd. All rights reserved. +# Copyright 2022-2023 Linaro ltd. + +if not is_linux + build = false + reason = 'only supported on Linux' + subdir_done() +endif + +sources = files( + 'uadk_crypto_pmd.c', +) + +deps += 'bus_vdev' +dep = dependency('libwd_crypto', required: false, method: 'pkg-config') +if not dep.found() + build = false + reason = 'missing dependency, "libwd_crypto"' +else + ext_deps += dep +endif + +dep = dependency('libwd', required: false, method: 'pkg-config') +if not dep.found() + build = false + reason = 'missing dependency, "libwd"' +else + ext_deps += dep +endif diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c new file mode 100644 index 0000000000..34df3ccbb9 --- /dev/null +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2022-2023 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2022-2023 Linaro ltd. + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "uadk_crypto_pmd_private.h" + +static uint8_t uadk_cryptodev_driver_id; + +static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { + .dev_configure = NULL, + .dev_start = NULL, + .dev_stop = NULL, + .dev_close = NULL, + .stats_get = NULL, + .stats_reset = NULL, + .dev_infos_get = NULL, + .queue_pair_setup = NULL, + .queue_pair_release = NULL, + .sym_session_get_size = NULL, + .sym_session_configure = NULL, + .sym_session_clear = NULL, +}; + +static int +uadk_cryptodev_probe(struct rte_vdev_device *vdev) +{ + struct rte_cryptodev_pmd_init_params init_params = { + .name = "", + .private_data_size = sizeof(struct uadk_crypto_priv), + .max_nb_queue_pairs = + RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS, + }; + enum uadk_crypto_version version = UADK_CRYPTO_V2; + struct uadk_crypto_priv *priv; + struct rte_cryptodev *dev; + struct uacce_dev *udev; + const char *name; + + udev = wd_get_accel_dev("cipher"); + if (!udev) + return -ENODEV; + + if (!strcmp(udev->api, "hisi_qm_v2")) + version = UADK_CRYPTO_V2; + + free(udev); + + name = rte_vdev_device_name(vdev); + if (name == NULL) + return -EINVAL; + + dev = rte_cryptodev_pmd_create(name, &vdev->device, &init_params); + if (dev == NULL) { + UADK_LOG(ERR, "driver %s: create failed", init_params.name); + return -ENODEV; + } + + dev->dev_ops = &uadk_crypto_pmd_ops; + dev->driver_id = uadk_cryptodev_driver_id; + dev->dequeue_burst = NULL; + dev->enqueue_burst = NULL; + dev->feature_flags = RTE_CRYPTODEV_FF_HW_ACCELERATED; + priv = dev->data->dev_private; + priv->version = version; + + rte_cryptodev_pmd_probing_finish(dev); + + return 0; +} + +static int +uadk_cryptodev_remove(struct rte_vdev_device *vdev) +{ + struct rte_cryptodev *cryptodev; + const char *name; + + name = rte_vdev_device_name(vdev); + if (name == NULL) + return -EINVAL; + + cryptodev = rte_cryptodev_pmd_get_named_dev(name); + if (cryptodev == NULL) + return -ENODEV; + + return rte_cryptodev_pmd_destroy(cryptodev); +} + +static struct rte_vdev_driver uadk_crypto_pmd = { + .probe = uadk_cryptodev_probe, + .remove = uadk_cryptodev_remove, +}; + +static struct cryptodev_driver uadk_crypto_drv; + +#define UADK_CRYPTO_DRIVER_NAME crypto_uadk +RTE_PMD_REGISTER_VDEV(UADK_CRYPTO_DRIVER_NAME, uadk_crypto_pmd); +RTE_PMD_REGISTER_CRYPTO_DRIVER(uadk_crypto_drv, uadk_crypto_pmd.driver, + uadk_cryptodev_driver_id); +RTE_LOG_REGISTER_DEFAULT(uadk_crypto_logtype, INFO); diff --git a/drivers/crypto/uadk/uadk_crypto_pmd_private.h b/drivers/crypto/uadk/uadk_crypto_pmd_private.h new file mode 100644 index 0000000000..c4090f6119 --- /dev/null +++ b/drivers/crypto/uadk/uadk_crypto_pmd_private.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2022-2023 Huawei Technologies Co.,Ltd. All rights reserved. + * Copyright 2022-2023 Linaro ltd. + */ + +#ifndef _UADK_CRYPTO_PMD_PRIVATE_H_ +#define _UADK_CRYPTO_PMD_PRIVATE_H_ + +enum uadk_crypto_version { + UADK_CRYPTO_V2, + UADK_CRYPTO_V3, +}; + +struct uadk_crypto_priv { + enum uadk_crypto_version version; +} __rte_cache_aligned; + +extern int uadk_crypto_logtype; + +#define UADK_LOG(level, fmt, ...) \ + rte_log(RTE_LOG_ ## level, uadk_crypto_logtype, \ + "%s() line %u: " fmt "\n", __func__, __LINE__, \ + ## __VA_ARGS__) + +#endif /* _UADK_CRYPTO_PMD_PRIVATE_H_ */ diff --git a/drivers/crypto/uadk/version.map b/drivers/crypto/uadk/version.map new file mode 100644 index 0000000000..78c3585d7c --- /dev/null +++ b/drivers/crypto/uadk/version.map @@ -0,0 +1,3 @@ +DPDK_23 { + local: *; +}; From patchwork Wed Oct 26 10:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618809 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317123pvb; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Dg9UOuXYRghy9yfFNAvdbPCEHlH2IcMtTrDYCJK19s9Pedf5o+v7i6Qla9aA08jWmLVjd X-Received: by 2002:a05:600c:548a:b0:3c6:dd03:2d31 with SMTP id iv10-20020a05600c548a00b003c6dd032d31mr2007086wmb.95.1666782092410; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782092; cv=none; d=google.com; s=arc-20160816; b=mQnPvC4RDn8H5k0fa4DsAzjbBQ/9jCoRnycr3MtYlNhMO81qEH2k65rQSn67fQRXXc vPxKZsnqUIEBtxdSHixta4PsvvrUFQ0QMe9jJQzVKRbnBP2DYBxaE0U/8JN6xX3swKBI /udWCDf0oeFaq+XGOuVlwa+gMHBzBF0gVrrndykx87OZ2tQXiDyG7rq0XZQL+hVq+IzD SLJdpvkhTEojZovciVTji6qfLyBZMGGYLQnbqH3jt8z57C2w68P9NPO2xKJCPm4F/rG2 kHi/JEUP6wa9Hak81HsCMPuJE8M8DlIX93kmew8m+3VisDZLPKC6rjhS7Aqwf4Wfc+go UXxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=MGzStkulEGDKzbikSUl6a8wmLOXLU2MxQApZ7GmokwJgjROfdL6qZwYrCcAz3Ty6aD Rk6aV/TkvqPrr/4bsE2GvLzk+21q/Ae0yXtJ3Wp3hDXWkJBAadC+vyw3gPgDGXfmSPdt rWLrr9GdxDHdLee2zoNcXW2rs7hWiM75kHfVFz1nPJGZMC0dT3/UupQdANTD7633+Ywz QJwlt7qULVggrFI3Vu4CZJbhmf0R1/CMxKTFaPosVqUu2IWb7JmgKFfg11mbWruk7O3X Q0CYOLysRmhIhWZQVq+SB3xWRRoaIFx+S/ocC5y+7cSyCim2iVQtRqHrOvxiC6fTfPnU 8jUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gLvEJxfr; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id s18-20020adfeb12000000b0022e5dcfe79csi3418957wrn.179.2022.10.26.04.01.32; Wed, 26 Oct 2022 04:01:32 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gLvEJxfr; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3EC0742B8E; Wed, 26 Oct 2022 13:01:23 +0200 (CEST) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by mails.dpdk.org (Postfix) with ESMTP id 3E3BF40041 for ; Wed, 26 Oct 2022 13:01:19 +0200 (CEST) Received: by mail-wm1-f53.google.com with SMTP id t4so9896352wmj.5 for ; Wed, 26 Oct 2022 04:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=gLvEJxfr3Eo4bYExAfSTQaWHJiIodlpbZFkuo8mjziOOI2HhyetTXt6fGfEFFivFqt vaJW7anYWV56x2z4KI+CBZcT2+5U3GmmDtkH1JCiuN4EL/0qadci6Vl5/JxruS85Gjiw 4RHX8eeYAUNr7AQfL2vgtYhWnnjwCmlLGb/p2X31gsBqKUjLnZ6uy270h1bPB+ZjKYyl EURBQT/NsEIr2yKnxBxlSFimtpVSzvKMohI5n/FSMSxOGCH5tOnR+/f6/U03BANTKkRU G2i+VuGSP76BDDFHyYL3LQd2o5TTT47w0Fh8IbbHacUWCivHfGGYrAckVGLfYxhE0fQ5 YxHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3dWeuK1LQWnCrDceoCT+coyKRdO+N1O756x/1vJeQaQ=; b=Vc+J/BpQtGnffBdlfsgb/OaN+F9k/pC8Uy32XBjy4aj7hUZZSvLGPOGO9viPVi3xAB /HAo0S6/8tfGZusrmaKNcQoV1oXKGH+k8FY36+4SQR3MOuzXbsykVJ9ImDG44mYN1teL XZKdhNGmK5SYEFcFphGu7klAFIw8XFQpMYRX0M1gduCThoK/+DnvnA8d7C4o96XrQNK9 qben6II0cMJLKtXCiJpV2zzIqbc1v+o716MYClFILd7+gIillmuxCi6Wk1IDCMUYdO/j f+5qkqTFegnLhW/01yQXFFiRTekXNyI2WX5SHHbKGkFh5TJF7PVmMrVntAjROWuaeE07 /jIA== X-Gm-Message-State: ACrzQf0SQnXJC7qWU5hX6yp9IYbWXoaYIMvDwQN6JsTP6ctP74n99KJL hsTdh32Zgop1DH46YwXnEXgFfA== X-Received: by 2002:a05:600c:4ed0:b0:3cd:3422:62d8 with SMTP id g16-20020a05600c4ed000b003cd342262d8mr1990745wmq.154.1666782078867; Wed, 26 Oct 2022 04:01:18 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:18 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 2/6] crypto/uadk: support basic operations Date: Wed, 26 Oct 2022 18:54:25 +0800 Message-Id: <20221026105429.1899867-3-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 Support the basic dev control operations: configure, close, start, stop and get info, as well as queue pairs operations. Signed-off-by: Zhangfei Gao --- drivers/crypto/uadk/uadk_crypto_pmd.c | 194 +++++++++++++++++- drivers/crypto/uadk/uadk_crypto_pmd_private.h | 19 ++ 2 files changed, 204 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index 34df3ccbb9..b383029a45 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -17,16 +17,192 @@ static uint8_t uadk_cryptodev_driver_id; +static const struct rte_cryptodev_capabilities uadk_crypto_v2_capabilities[] = { + /* End of capabilities */ + RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() +}; + +/* Configure device */ +static int +uadk_crypto_pmd_config(struct rte_cryptodev *dev __rte_unused, + struct rte_cryptodev_config *config __rte_unused) +{ + return 0; +} + +/* Start device */ +static int +uadk_crypto_pmd_start(struct rte_cryptodev *dev __rte_unused) +{ + return 0; +} + +/* Stop device */ +static void +uadk_crypto_pmd_stop(struct rte_cryptodev *dev __rte_unused) +{ +} + +/* Close device */ +static int +uadk_crypto_pmd_close(struct rte_cryptodev *dev __rte_unused) +{ + return 0; +} + +/* Get device statistics */ +static void +uadk_crypto_pmd_stats_get(struct rte_cryptodev *dev, + struct rte_cryptodev_stats *stats) +{ + int qp_id; + + for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + stats->enqueued_count += qp->qp_stats.enqueued_count; + stats->dequeued_count += qp->qp_stats.dequeued_count; + stats->enqueue_err_count += qp->qp_stats.enqueue_err_count; + stats->dequeue_err_count += qp->qp_stats.dequeue_err_count; + } +} + +/* Reset device statistics */ +static void +uadk_crypto_pmd_stats_reset(struct rte_cryptodev *dev __rte_unused) +{ + int qp_id; + + for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + memset(&qp->qp_stats, 0, sizeof(qp->qp_stats)); + } +} + +/* Get device info */ +static void +uadk_crypto_pmd_info_get(struct rte_cryptodev *dev, + struct rte_cryptodev_info *dev_info) +{ + struct uadk_crypto_priv *priv = dev->data->dev_private; + + if (dev_info != NULL) { + dev_info->driver_id = dev->driver_id; + dev_info->driver_name = dev->device->driver->name; + dev_info->max_nb_queue_pairs = 128; + /* No limit of number of sessions */ + dev_info->sym.max_nb_sessions = 0; + dev_info->feature_flags = dev->feature_flags; + + if (priv->version == UADK_CRYPTO_V2) + dev_info->capabilities = uadk_crypto_v2_capabilities; + } +} + +/* Release queue pair */ +static int +uadk_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id) +{ + struct uadk_qp *qp = dev->data->queue_pairs[qp_id]; + + if (qp) { + rte_ring_free(qp->processed_pkts); + rte_free(qp); + dev->data->queue_pairs[qp_id] = NULL; + } + + return 0; +} + +/* set a unique name for the queue pair based on its name, dev_id and qp_id */ +static int +uadk_pmd_qp_set_unique_name(struct rte_cryptodev *dev, + struct uadk_qp *qp) +{ + unsigned int n = snprintf(qp->name, sizeof(qp->name), + "uadk_crypto_pmd_%u_qp_%u", + dev->data->dev_id, qp->id); + + if (n >= sizeof(qp->name)) + return -EINVAL; + + return 0; +} + +/* Create a ring to place process packets on */ +static struct rte_ring * +uadk_pmd_qp_create_processed_pkts_ring(struct uadk_qp *qp, + unsigned int ring_size, int socket_id) +{ + struct rte_ring *r = qp->processed_pkts; + + if (r) { + if (rte_ring_get_size(r) >= ring_size) { + UADK_LOG(INFO, "Reusing existing ring %s for processed packets", + qp->name); + return r; + } + + UADK_LOG(ERR, "Unable to reuse existing ring %s for processed packets", + qp->name); + return NULL; + } + + return rte_ring_create(qp->name, ring_size, socket_id, + RING_F_EXACT_SZ); +} + +static int +uadk_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id, + const struct rte_cryptodev_qp_conf *qp_conf, + int socket_id) +{ + struct uadk_qp *qp; + + /* Free memory prior to re-allocation if needed. */ + if (dev->data->queue_pairs[qp_id] != NULL) + uadk_crypto_pmd_qp_release(dev, qp_id); + + /* Allocate the queue pair data structure. */ + qp = rte_zmalloc_socket("uadk PMD Queue Pair", sizeof(*qp), + RTE_CACHE_LINE_SIZE, socket_id); + if (qp == NULL) + return (-ENOMEM); + + qp->id = qp_id; + dev->data->queue_pairs[qp_id] = qp; + + if (uadk_pmd_qp_set_unique_name(dev, qp)) + goto qp_setup_cleanup; + + qp->processed_pkts = uadk_pmd_qp_create_processed_pkts_ring(qp, + qp_conf->nb_descriptors, socket_id); + if (qp->processed_pkts == NULL) + goto qp_setup_cleanup; + + memset(&qp->qp_stats, 0, sizeof(qp->qp_stats)); + + return 0; + +qp_setup_cleanup: + if (qp) { + rte_free(qp); + qp = NULL; + } + return -EINVAL; +} + static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { - .dev_configure = NULL, - .dev_start = NULL, - .dev_stop = NULL, - .dev_close = NULL, - .stats_get = NULL, - .stats_reset = NULL, - .dev_infos_get = NULL, - .queue_pair_setup = NULL, - .queue_pair_release = NULL, + .dev_configure = uadk_crypto_pmd_config, + .dev_start = uadk_crypto_pmd_start, + .dev_stop = uadk_crypto_pmd_stop, + .dev_close = uadk_crypto_pmd_close, + .stats_get = uadk_crypto_pmd_stats_get, + .stats_reset = uadk_crypto_pmd_stats_reset, + .dev_infos_get = uadk_crypto_pmd_info_get, + .queue_pair_setup = uadk_crypto_pmd_qp_setup, + .queue_pair_release = uadk_crypto_pmd_qp_release, .sym_session_get_size = NULL, .sym_session_configure = NULL, .sym_session_clear = NULL, diff --git a/drivers/crypto/uadk/uadk_crypto_pmd_private.h b/drivers/crypto/uadk/uadk_crypto_pmd_private.h index c4090f6119..3060583b54 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd_private.h +++ b/drivers/crypto/uadk/uadk_crypto_pmd_private.h @@ -6,6 +6,25 @@ #ifndef _UADK_CRYPTO_PMD_PRIVATE_H_ #define _UADK_CRYPTO_PMD_PRIVATE_H_ +/* Maximum length for digest (SHA-512 needs 64 bytes) */ +#define DIGEST_LENGTH_MAX 64 + +struct uadk_qp { + /* Ring for placing process packets */ + struct rte_ring *processed_pkts; + /* Queue pair statistics */ + struct rte_cryptodev_stats qp_stats; + /* Queue Pair Identifier */ + uint16_t id; + /* Unique Queue Pair Name */ + char name[RTE_CRYPTODEV_NAME_MAX_LEN]; + /* Buffer used to store the digest generated + * by the driver when verifying a digest provided + * by the user (using authentication verify operation) + */ + uint8_t temp_digest[DIGEST_LENGTH_MAX]; +} __rte_cache_aligned; + enum uadk_crypto_version { UADK_CRYPTO_V2, UADK_CRYPTO_V3, From patchwork Wed Oct 26 10:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618810 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317204pvb; Wed, 26 Oct 2022 04:01:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4CuEtgrnhqFupF0gKTU0qxAnt8B2MFypwC7imRd17mAvN5UCHo0UTUDlLMi+1S07QFYShK X-Received: by 2002:a5d:59c6:0:b0:235:fae6:354c with SMTP id v6-20020a5d59c6000000b00235fae6354cmr22176099wry.713.1666782098810; Wed, 26 Oct 2022 04:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782098; cv=none; d=google.com; s=arc-20160816; b=D/4W4cW+pFrM6msGdazaEV8E4nPSNrNFNRD+pH0qxH8e5FenfZlnRjSTLGFLkc/w6R +6YsLKphhRE+S1OvVDXip5XHEFt/IRf3S/IMDO3vt9oGSzwm2XibHxpLBvLHUrdT9wOY sFgXYOsp4WVMnUrRDEG0CBeZY9DTRQ0EZ8aXvhx/aLy35g5W7nUqYzmW+FRMdeReKylA jpEgfTUBZ9nF+huP05NQKIy6EhHp6xHY/3SjQnnAvcZwO4m4JltmYOapfq5j18D1pSyS btHguKO290t7+bJi0B5bEqSj/O0li7lCx0shSfNyGHHsV0jiXRUIMmvDHxHwZ+DN8wwr 1JMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gCo/lEt/vnZnd2GQBv7rIYWCKFZr1IXcB/HdSoa8dvw=; b=jyJFBsBz3dzDTe/Cb5oxzTkNm97xkH2YjdznPSeH6Uhx1ea+ug4juDvDbMRJtFisFS lOwhuvnUTMxu2S0I3QzcdHRwxw54JPFRFkahn1KTYENE2ESUrMCjISuOykAh8c/6QCyH bKa5Wg/2v5XLICX+hGxuL1Moy8+k3tW/aC42/U/eWIUo1v1J2cPCdktxzOWbAn9XlMLj kwjr0RcbpayZFUOYIrNee0CNykZ4gtZCjnmBaYaTHH9rv/KNZoMznl2ynK+I/iQ3hoAx e7r7utGCb9SRrG/VuwLuEB6+38YwcwREsmKYnWtmVX++8l/cm+l1T8r/s3/mzoFntJsJ 0Htw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uAsD8ADd; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id h186-20020a1c21c3000000b003c7174bdb82si1232229wmh.32.2022.10.26.04.01.38; Wed, 26 Oct 2022 04:01:38 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uAsD8ADd; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F3AA342BAD; Wed, 26 Oct 2022 13:01:23 +0200 (CEST) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mails.dpdk.org (Postfix) with ESMTP id 06E5841153 for ; Wed, 26 Oct 2022 13:01:19 +0200 (CEST) Received: by mail-wm1-f42.google.com with SMTP id c7-20020a05600c0ac700b003c6cad86f38so1197942wmr.2 for ; Wed, 26 Oct 2022 04:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gCo/lEt/vnZnd2GQBv7rIYWCKFZr1IXcB/HdSoa8dvw=; b=uAsD8ADdIJBHN4NwT7NXN6qBN7c9aiyNoGvmocw/lDGkDUOEUophdRyV9ywKPkA63r bpqrPuMtAib/AwaXJZ2txJFFDWkDnw5u6zODEnh+ZDtEAdA776OQyhdkth55HQufoUvI cK8EMRDKZTlObYrhDrlm49jacIJOCn8zQD69ECYXW41FP8YbdvQ8yfUdKl3ZpCA87Aqu u2iY2gzjqfHE2cAzM1DmJKZgcmMKfeN/vK3CqM9Gac5gWDBBduTMp5HZWmY5DQvncr3P HD1RBfZWSyWZogGKWXbzJ1loRklKwPi5STsSpKIgkDmCM5k+JD/R5v5Yztt9/yrLSTh7 Yq/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gCo/lEt/vnZnd2GQBv7rIYWCKFZr1IXcB/HdSoa8dvw=; b=15kZH4dzab7d+7beEfwhloqScMVi9tfi6jQ9b96hLuzlk+nfSM9Mdo/GrQtkR/4Dze 5sTtWdrEFNUL3rYhGNQEdFvZxBCEoMY+/aJ4Rh1dnnbfGo3rkJJlsYeIJFs5vSc/o3ay FBjxJsmVHnp8m/slUUmecMqD5PpU9HDhFfHAsgdLfwgAf2bBfNIjm3z09n52nUYoCMtO LUe5qJasQyBWcyGmUPAjlxjtXDasM5sWsfpswrFZBHkM3Wgplak2PEutx5EcSzLu9PYW /qnDvuINymVzg01nKQnxg3C4ogj9RxCJCbggwMqJFCh0q4dYoAdGG5c1+v/tIQUNSJeo Cy+g== X-Gm-Message-State: ACrzQf1BEhelnxnqEWpcB4mietaVdJa/yUt88/3j9iiB8u5WSHL+uL5G Df40kCA/UgFQSHHEIWyXem1puA== X-Received: by 2002:a05:600c:1c9d:b0:3c5:8081:1fc4 with SMTP id k29-20020a05600c1c9d00b003c580811fc4mr2044549wms.161.1666782079710; Wed, 26 Oct 2022 04:01:19 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:19 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 3/6] crypto/uadk: support enqueue/dequeue operations Date: Wed, 26 Oct 2022 18:54:26 +0800 Message-Id: <20221026105429.1899867-4-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 This commit adds the enqueue and dequeue operations. Signed-off-by: Zhangfei Gao --- drivers/crypto/uadk/uadk_crypto_pmd.c | 53 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index b383029a45..b889dac8b0 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -208,6 +208,55 @@ static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { .sym_session_clear = NULL, }; +static uint16_t +uadk_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, + uint16_t nb_ops) +{ + struct uadk_qp *qp = queue_pair; + struct rte_crypto_op *op; + uint16_t enqd = 0; + int i, ret; + + for (i = 0; i < nb_ops; i++) { + op = ops[i]; + op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + + if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED) + op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; + + if (op->status != RTE_CRYPTO_OP_STATUS_ERROR) { + ret = rte_ring_enqueue(qp->processed_pkts, (void *)op); + if (ret < 0) + goto enqueue_err; + qp->qp_stats.enqueued_count++; + enqd++; + } else { + /* increment count if failed to enqueue op */ + qp->qp_stats.enqueue_err_count++; + } + } + + return enqd; + +enqueue_err: + qp->qp_stats.enqueue_err_count++; + return enqd; +} + +static uint16_t +uadk_crypto_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, + uint16_t nb_ops) +{ + struct uadk_qp *qp = queue_pair; + unsigned int nb_dequeued; + + nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts, + (void **)ops, nb_ops, NULL); + qp->qp_stats.dequeued_count += nb_dequeued; + + return nb_dequeued; +} + static int uadk_cryptodev_probe(struct rte_vdev_device *vdev) { @@ -244,8 +293,8 @@ uadk_cryptodev_probe(struct rte_vdev_device *vdev) dev->dev_ops = &uadk_crypto_pmd_ops; dev->driver_id = uadk_cryptodev_driver_id; - dev->dequeue_burst = NULL; - dev->enqueue_burst = NULL; + dev->dequeue_burst = uadk_crypto_dequeue_burst; + dev->enqueue_burst = uadk_crypto_enqueue_burst; dev->feature_flags = RTE_CRYPTODEV_FF_HW_ACCELERATED; priv = dev->data->dev_private; priv->version = version; From patchwork Wed Oct 26 10:54:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618811 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317259pvb; Wed, 26 Oct 2022 04:01:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ICJdfFEMvv7fI4HnnUhtlfzaUXre9pPPc14fHh4//kH9BGDZXUlO0kYe/WQbjTFv3Ni2k X-Received: by 2002:a5d:4a41:0:b0:228:48c6:7386 with SMTP id v1-20020a5d4a41000000b0022848c67386mr28322552wrs.649.1666782105151; Wed, 26 Oct 2022 04:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782105; cv=none; d=google.com; s=arc-20160816; b=AD+6JdeGhDFzzrn9fl73Lr9P0b78XUY99Xincroz9oWI52snq134ezKfpDYm50ZLhn ty+L5E/sU/bdgP1L0VPlh3SeI8MVa0h6sJ6ERdUg8m/vgwLklMMhmfLRfDdBxzaAxGtI x233PeGc4iJGZ0jnW1WcWprLzYHqU0dXCh3Ssj6e6j3S+MORDGo8mIYubXhYQjfbqPiH vELNMJ+P9CF0o3muTGz/KZRfWeikz56FyrX2gVSE+OcHMEzTYjTBjORmzC4dL4d0Zb5f Tymxufz4ubT4EyDWkWCxVit0qhGKiZEGnr7d7iQNTHkZmSIRNsCB7W21HyJD4oQothTD X/mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5LbadSr2F/V9e00/azLMh5kK2GK9h8fdx23Ph4AXK/Y=; b=LQ2SOIuz7n/N4JRmZlPrGNULe5ashjd2y4wHBhvZTXuNC0vMNL6CWD/Q6tgqE41byN Zuq9LGlRh+Qxt7bJsUW8MXWXfVSkWHrx9h0/WsGn28LTrPjkNsWWBgOyBtww6JnT1Der kS4vqp8Gd+Lkd3wO/Hurg32SsBe41qMDf/SPjCiICxpEo4TscxBksOXHLjeI6R5jGUJR OatAtR47bgQqAR8LwdASjAhqHYPyDzOsxaDs+iOjRKN4n5mSfgNDY1dBr74fic0z7RkL B2rICH7p5T6y3HFjZ45drD4q+txRnZHvjkM0uCMwpJUcAVKa111uruyjnvrm/c2AXncB 42Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UNMz+n9+; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id w7-20020adfbac7000000b002303b696937si3733199wrg.865.2022.10.26.04.01.44; Wed, 26 Oct 2022 04:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UNMz+n9+; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A7C7E42BB7; Wed, 26 Oct 2022 13:01:24 +0200 (CEST) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mails.dpdk.org (Postfix) with ESMTP id 060C941611 for ; Wed, 26 Oct 2022 13:01:21 +0200 (CEST) Received: by mail-wm1-f48.google.com with SMTP id az22-20020a05600c601600b003c6b72797fdso1254502wmb.5 for ; Wed, 26 Oct 2022 04:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5LbadSr2F/V9e00/azLMh5kK2GK9h8fdx23Ph4AXK/Y=; b=UNMz+n9+dNECinkd4qDfDrZIxSqfJfsTZwiXJZ0ASwVzo0uV/aherXHUjubrxnPHkr RErTNIy6CMU8yezI8l+KT+srnDlCzy0vpPMszzB1uVzpkInm2iQx5SHLuYkE7HRdisza fhzEMlDFT/olvXJV0xWG7HYVJjva0Th2Lt6bClm+RTud3nEMBEzQDr/BHBxSt1SGauGC X/IkcPlwcugmumvcwnWqfsXVYEClKE+Tm5QbgQp7pcxKaPW9O0mTSY/76loeEJUsT5Nl feD6YdgjNCnfyEGSOtbAvpILpJchQ6113wO93hCasWnoY4hdPpeeky38eec3P5XFhR3+ TdZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5LbadSr2F/V9e00/azLMh5kK2GK9h8fdx23Ph4AXK/Y=; b=JGjtckWznkdofUC12k9iGQcCow8aPgbVFH/0gkHawrRluiCQJJfhgHeawHrw1GzM/I QDUgyiEwXzBPD2Ts82alI6XYV2jI5x7UFjdIBBi9Uf0xXRogqTZxYrUynyrHpCQ6iPtR i0nVDrnMDKyRSWAi3XKuolxrGfeXCqUZAhf/BpBRyPJJONtkVffMEenPgkA/ekd9kfa/ lOhIgha79y7qGzCqNEVMW6B9TNWMgucGIUARpGHUhWmN8d5kz3XIpeLnyYcrGnXqt8WL LA4asXXZoRrbA8eNYL+9GFZhwAX3/fN8dcefrCSM4aaoRCDEiD/YygbzxaXYpzKoJxIj 4DQw== X-Gm-Message-State: ACrzQf0uDFPP5Y8Pv1Asn4UE5iWD8WP8/Edhic4lcJy44E6Kj2hrNz5N RYRXuA+fgNHM3W2GoE6cfedNsg== X-Received: by 2002:a05:600c:3d10:b0:3c6:f1f9:b42 with SMTP id bh16-20020a05600c3d1000b003c6f1f90b42mr1907192wmb.15.1666782080729; Wed, 26 Oct 2022 04:01:20 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:20 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 4/6] crypto/uadk: support cipher algorithms Date: Wed, 26 Oct 2022 18:54:27 +0800 Message-Id: <20221026105429.1899867-5-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 Add support for cipher algorithms, including AES_ECB, AES_CBC, AES_XTS, and DES_CBC mode. Signed-off-by: Zhangfei Gao --- doc/guides/cryptodevs/features/uadk.ini | 10 + doc/guides/cryptodevs/uadk.rst | 6 + drivers/crypto/uadk/uadk_crypto_pmd.c | 303 +++++++++++++++++- drivers/crypto/uadk/uadk_crypto_pmd_private.h | 23 ++ 4 files changed, 337 insertions(+), 5 deletions(-) diff --git a/doc/guides/cryptodevs/features/uadk.ini b/doc/guides/cryptodevs/features/uadk.ini index df5ad40e3d..005e08ac8d 100644 --- a/doc/guides/cryptodevs/features/uadk.ini +++ b/doc/guides/cryptodevs/features/uadk.ini @@ -4,12 +4,22 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +Symmetric crypto = Y HW Accelerated = Y ; ; Supported crypto algorithms of the 'uadk' crypto driver. ; [Cipher] +AES CBC (128) = Y +AES CBC (192) = Y +AES CBC (256) = Y +AES ECB (128) = Y +AES ECB (192) = Y +AES ECB (256) = Y +AES XTS (128) = Y +AES XTS (256) = Y +DES CBC = Y ; ; Supported authentication algorithms of the 'uadk' crypto driver. diff --git a/doc/guides/cryptodevs/uadk.rst b/doc/guides/cryptodevs/uadk.rst index 2a0cb300e9..e0ca097961 100644 --- a/doc/guides/cryptodevs/uadk.rst +++ b/doc/guides/cryptodevs/uadk.rst @@ -24,6 +24,12 @@ Features UADK crypto PMD has support for: +Cipher algorithms: + +* ``RTE_CRYPTO_CIPHER_AES_ECB`` +* ``RTE_CRYPTO_CIPHER_AES_CBC`` +* ``RTE_CRYPTO_CIPHER_AES_XTS`` +* ``RTE_CRYPTO_CIPHER_DES_CBC`` Test steps ---------- diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index b889dac8b0..f112a96033 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -18,6 +18,86 @@ static uint8_t uadk_cryptodev_driver_id; static const struct rte_cryptodev_capabilities uadk_crypto_v2_capabilities[] = { + { /* AES ECB */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_ECB, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .iv_size = { + .min = 0, + .max = 0, + .increment = 0 + } + }, } + }, } + }, + { /* AES CBC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_CBC, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .iv_size = { + .min = 16, + .max = 16, + .increment = 0 + } + }, } + }, } + }, + { /* AES XTS */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_XTS, + .block_size = 1, + .key_size = { + .min = 32, + .max = 64, + .increment = 32 + }, + .iv_size = { + .min = 0, + .max = 0, + .increment = 0 + } + }, } + }, } + }, + { /* DES CBC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_DES_CBC, + .block_size = 8, + .key_size = { + .min = 8, + .max = 8, + .increment = 0 + }, + .iv_size = { + .min = 8, + .max = 8, + .increment = 0 + } + }, } + }, } + }, /* End of capabilities */ RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; @@ -45,8 +125,15 @@ uadk_crypto_pmd_stop(struct rte_cryptodev *dev __rte_unused) /* Close device */ static int -uadk_crypto_pmd_close(struct rte_cryptodev *dev __rte_unused) +uadk_crypto_pmd_close(struct rte_cryptodev *dev) { + struct uadk_crypto_priv *priv = dev->data->dev_private; + + if (priv->env_cipher_init) { + wd_cipher_env_uninit(); + priv->env_cipher_init = false; + } + return 0; } @@ -193,6 +280,159 @@ uadk_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id, return -EINVAL; } +static unsigned int +uadk_crypto_sym_session_get_size(struct rte_cryptodev *dev __rte_unused) +{ + return sizeof(struct uadk_crypto_session); +} + +static enum uadk_chain_order +uadk_get_chain_order(const struct rte_crypto_sym_xform *xform) +{ + enum uadk_chain_order res = UADK_CHAIN_NOT_SUPPORTED; + + if (xform != NULL) { + if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { + if (xform->next == NULL) + res = UADK_CHAIN_ONLY_CIPHER; + } + } + + return res; +} + +static int +uadk_set_session_cipher_parameters(struct rte_cryptodev *dev, + struct uadk_crypto_session *sess, + struct rte_crypto_sym_xform *xform) +{ + struct uadk_crypto_priv *priv = dev->data->dev_private; + struct rte_crypto_cipher_xform *cipher = &xform->cipher; + struct wd_cipher_sess_setup setup = {0}; + struct sched_params params = {0}; + int ret; + + if (!priv->env_cipher_init) { + ret = wd_cipher_env_init(NULL); + if (ret < 0) + return -EINVAL; + priv->env_cipher_init = true; + } + + sess->cipher.direction = cipher->op; + sess->iv.offset = cipher->iv.offset; + sess->iv.length = cipher->iv.length; + + switch (cipher->algo) { + /* Cover supported cipher algorithms */ + case RTE_CRYPTO_CIPHER_AES_CTR: + setup.alg = WD_CIPHER_AES; + setup.mode = WD_CIPHER_CTR; + sess->cipher.req.out_bytes = 64; + break; + case RTE_CRYPTO_CIPHER_AES_ECB: + setup.alg = WD_CIPHER_AES; + setup.mode = WD_CIPHER_ECB; + sess->cipher.req.out_bytes = 16; + break; + case RTE_CRYPTO_CIPHER_AES_CBC: + setup.alg = WD_CIPHER_AES; + setup.mode = WD_CIPHER_CBC; + if (cipher->key.length == 16) + sess->cipher.req.out_bytes = 16; + else + sess->cipher.req.out_bytes = 64; + break; + case RTE_CRYPTO_CIPHER_AES_XTS: + setup.alg = WD_CIPHER_AES; + setup.mode = WD_CIPHER_XTS; + if (cipher->key.length == 16) + sess->cipher.req.out_bytes = 32; + else + sess->cipher.req.out_bytes = 512; + break; + default: + ret = -ENOTSUP; + goto env_uninit; + } + + params.numa_id = -1; /* choose nearby numa node */ + setup.sched_param = ¶ms; + sess->handle_cipher = wd_cipher_alloc_sess(&setup); + if (!sess->handle_cipher) { + UADK_LOG(ERR, "uadk failed to alloc session!\n"); + ret = -EINVAL; + goto env_uninit; + } + + ret = wd_cipher_set_key(sess->handle_cipher, cipher->key.data, cipher->key.length); + if (ret) { + wd_cipher_free_sess(sess->handle_cipher); + UADK_LOG(ERR, "uadk failed to set key!\n"); + ret = -EINVAL; + goto env_uninit; + } + + return 0; + +env_uninit: + wd_cipher_env_uninit(); + priv->env_cipher_init = false; + return ret; +} + +static int +uadk_crypto_sym_session_configure(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *session) +{ + struct rte_crypto_sym_xform *cipher_xform = NULL; + struct uadk_crypto_session *sess = CRYPTODEV_GET_SYM_SESS_PRIV(session); + int ret; + + if (unlikely(!sess)) { + UADK_LOG(ERR, "Session not available"); + return -EINVAL; + } + + sess->chain_order = uadk_get_chain_order(xform); + switch (sess->chain_order) { + case UADK_CHAIN_ONLY_CIPHER: + cipher_xform = xform; + break; + default: + return -ENOTSUP; + } + + if (cipher_xform) { + ret = uadk_set_session_cipher_parameters(dev, sess, cipher_xform); + if (ret != 0) { + UADK_LOG(ERR, + "Invalid/unsupported cipher parameters"); + return ret; + } + } + + return 0; +} + +static void +uadk_crypto_sym_session_clear(struct rte_cryptodev *dev __rte_unused, + struct rte_cryptodev_sym_session *session) +{ + struct uadk_crypto_session *sess = CRYPTODEV_GET_SYM_SESS_PRIV(session); + + if (unlikely(sess == NULL)) { + UADK_LOG(ERR, "Session not available"); + return; + } + + if (sess->handle_cipher) { + wd_cipher_free_sess(sess->handle_cipher); + sess->handle_cipher = 0; + } +} + static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { .dev_configure = uadk_crypto_pmd_config, .dev_start = uadk_crypto_pmd_start, @@ -203,16 +443,51 @@ static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { .dev_infos_get = uadk_crypto_pmd_info_get, .queue_pair_setup = uadk_crypto_pmd_qp_setup, .queue_pair_release = uadk_crypto_pmd_qp_release, - .sym_session_get_size = NULL, - .sym_session_configure = NULL, - .sym_session_clear = NULL, + .sym_session_get_size = uadk_crypto_sym_session_get_size, + .sym_session_configure = uadk_crypto_sym_session_configure, + .sym_session_clear = uadk_crypto_sym_session_clear, }; +static void +uadk_process_cipher_op(struct rte_crypto_op *op, + struct uadk_crypto_session *sess, + struct rte_mbuf *msrc, struct rte_mbuf *mdst) +{ + uint32_t off = op->sym->cipher.data.offset; + int ret; + + if (!sess) { + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return; + } + + sess->cipher.req.src = rte_pktmbuf_mtod_offset(msrc, uint8_t *, off); + sess->cipher.req.in_bytes = op->sym->cipher.data.length; + sess->cipher.req.dst = rte_pktmbuf_mtod_offset(mdst, uint8_t *, off); + sess->cipher.req.out_buf_bytes = sess->cipher.req.in_bytes; + sess->cipher.req.iv_bytes = sess->iv.length; + sess->cipher.req.iv = rte_crypto_op_ctod_offset(op, uint8_t *, + sess->iv.offset); + if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) + sess->cipher.req.op_type = WD_CIPHER_ENCRYPTION; + else + sess->cipher.req.op_type = WD_CIPHER_DECRYPTION; + + do { + ret = wd_do_cipher_sync(sess->handle_cipher, &sess->cipher.req); + } while (ret == -WD_EBUSY); + + if (ret) + op->status = RTE_CRYPTO_OP_STATUS_ERROR; +} + static uint16_t uadk_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, uint16_t nb_ops) { struct uadk_qp *qp = queue_pair; + struct uadk_crypto_session *sess = NULL; + struct rte_mbuf *msrc, *mdst; struct rte_crypto_op *op; uint16_t enqd = 0; int i, ret; @@ -220,6 +495,23 @@ uadk_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { op = ops[i]; op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + msrc = op->sym->m_src; + mdst = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src; + + if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) { + if (likely(op->sym->session != NULL)) + sess = CRYPTODEV_GET_SYM_SESS_PRIV( + op->sym->session); + } + + switch (sess->chain_order) { + case UADK_CHAIN_ONLY_CIPHER: + uadk_process_cipher_op(op, sess, msrc, mdst); + break; + default: + op->status = RTE_CRYPTO_OP_STATUS_ERROR; + break; + } if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED) op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; @@ -295,7 +587,8 @@ uadk_cryptodev_probe(struct rte_vdev_device *vdev) dev->driver_id = uadk_cryptodev_driver_id; dev->dequeue_burst = uadk_crypto_dequeue_burst; dev->enqueue_burst = uadk_crypto_enqueue_burst; - dev->feature_flags = RTE_CRYPTODEV_FF_HW_ACCELERATED; + dev->feature_flags = RTE_CRYPTODEV_FF_HW_ACCELERATED | + RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO; priv = dev->data->dev_private; priv->version = version; diff --git a/drivers/crypto/uadk/uadk_crypto_pmd_private.h b/drivers/crypto/uadk/uadk_crypto_pmd_private.h index 3060583b54..e981420cef 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd_private.h +++ b/drivers/crypto/uadk/uadk_crypto_pmd_private.h @@ -25,12 +25,35 @@ struct uadk_qp { uint8_t temp_digest[DIGEST_LENGTH_MAX]; } __rte_cache_aligned; +enum uadk_chain_order { + UADK_CHAIN_ONLY_CIPHER, + UADK_CHAIN_NOT_SUPPORTED +}; + +struct uadk_crypto_session { + handle_t handle_cipher; + enum uadk_chain_order chain_order; + + /* IV parameters */ + struct { + uint16_t length; + uint16_t offset; + } iv; + + /* Cipher Parameters */ + struct { + enum rte_crypto_cipher_operation direction; + struct wd_cipher_req req; + } cipher; +} __rte_cache_aligned; + enum uadk_crypto_version { UADK_CRYPTO_V2, UADK_CRYPTO_V3, }; struct uadk_crypto_priv { + bool env_cipher_init; enum uadk_crypto_version version; } __rte_cache_aligned; From patchwork Wed Oct 26 10:54:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618812 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317381pvb; Wed, 26 Oct 2022 04:01:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5E2fZVtsjuaVlkn4yRy1XwyK8nSL63iaT7n+bTmvjYZ71tgKx4QZn5Q7ja4f2sZ6GKy43Z X-Received: by 2002:a05:600c:4f90:b0:3cf:39bd:4b6a with SMTP id n16-20020a05600c4f9000b003cf39bd4b6amr1968970wmq.17.1666782114413; Wed, 26 Oct 2022 04:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782114; cv=none; d=google.com; s=arc-20160816; b=JjwbMGG/ynLQNj+UtW9AwNbFd5gMn8xM7JuwK2mt994Shstyd5KtFIS/eoIGZ3alO0 QXJXWr5iZBlUiu0OwXW8BY6flQ3vBY6YSl+YmYm0658847GRVEQhv4UypJdLkB+JLj3q 1EOTkcaUnAYM2+/V4H8451UwQcvvV6Ld28O9Jwe7M+PehdNE1aJvEmvT0RG/PsO52sRR tkGk7ow3n7JG/N7NSyShLbhhXQ5FFkoNW+yBCMB0PbiNgT+j+6dYSnvx9+CjOedz6zba Bnw1mhJ8OxoWMQiwWDxqS/Jxs/WXuOg515ULENCH3G3i0t5eO/KUfP/I/9jsFkhoSwuO ebMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IdAhHD7IQvHkV7WFALp4Sq5Q3i2a4WMQzBZ6Nq9PKwk=; b=e/NYDHpt6ISk6S2n1VIIqws0rqEtXU5lWcMrV9qfcQPG0UAIaTeIbA/xaH/Gwf5lkw k7T2sS0vzrCeFMMuEJKJAEE+7xn9EqxGnZVwmFJoQVorVNqul9uZgzpH6gZCnG/NczRo SIx1fRWKKyaKoMnx0mlDxL2U7AjlkPNJP17zIZEBfWqOHxcJHv8mvh0Xz3f/pAxq4jEx vKlodIYCqD6kqp1nH4UxpIUKPTMH+alleVZvigkDDKE6zy08js8NqjH/P7u6o3WEvmrR xVSQD0XjmChYwB/ytUcTmRjWLeuOPC34xhFUqOVkThljWcplSDIML6AfTCLlwtpAB4Zn EjMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f6RrtEGT; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id m30-20020adfa3de000000b0023664467c75si3649268wrb.793.2022.10.26.04.01.54; Wed, 26 Oct 2022 04:01:54 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f6RrtEGT; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C290942BCF; Wed, 26 Oct 2022 13:01:28 +0200 (CEST) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id C393141611 for ; Wed, 26 Oct 2022 13:01:21 +0200 (CEST) Received: by mail-wm1-f52.google.com with SMTP id l32so9927124wms.2 for ; Wed, 26 Oct 2022 04:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IdAhHD7IQvHkV7WFALp4Sq5Q3i2a4WMQzBZ6Nq9PKwk=; b=f6RrtEGT3LJXMzB56fD2+hkB19r43jGtAJZQEiBRX9fkrRkdfDX+BdztvbxxPdTgfQ n/PydRULmKrHIymEWKkwsA4HPBx3fJaBs7VaThL3z/tBHurxV/fH6qz4KXrI3tMTITw+ 2FjhfbLZT/YG1Hcjd8wL0lSRCPXUITrurwdqxQzvGSiZebzJrKKsnfS6Yzh9HYlKgwZN j2bVwjMclgGpSkaw6HAfAaOwlT9b7WXc5Q10v+2azoFljfAzdJ6OvmwCfkrqGWaP/6yO AhsBby18piuh/E9LC3Kug75ghDCEm3WoxP4fdYtH/rKOXsMTtFfsODNb0VmKIFUQYW5l zzWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IdAhHD7IQvHkV7WFALp4Sq5Q3i2a4WMQzBZ6Nq9PKwk=; b=RWHHNs+waWOmrUQDdBDkR4sl4HH4CA4hoag/OY66GDuNYNvCH0/+iDBwPoevtCqS3W HY+zmUheuNqqPqqCGLv/cWxEm0Q1UvNXuZNcxfqObFYNiZneMsd4I65VgOfWFX+6dJnX yqI6dMc0Qk81lcCfTF9lv2w00+ofqEyArGU7zZ7pYP1YPGLxHW4oUdCLpU1aggQwEUEm lOV56eD4CJhN6EKcz+/42x1/etpCxgBHSpS51bdl0q/xylkqDOw0H+1uQa3buZ9QRYR3 nsbkQ4ngN1nSFy/LSQX8CEVRy5JqK57npc2Btahcfnb1aCww8KvtpaKoGHkL/eJtDG7I Zdyw== X-Gm-Message-State: ACrzQf0ttggbO+qWSiAqmvgMTQD3iraqItL5qNyQclzqLEzZj5NDGRc1 hjzn1T84mc5zavKac29wKlow8A== X-Received: by 2002:a05:600c:5114:b0:3c7:8eb:fb28 with SMTP id o20-20020a05600c511400b003c708ebfb28mr1946853wms.93.1666782081474; Wed, 26 Oct 2022 04:01:21 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:21 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 5/6] crypto/uadk: support auth algorithms Date: Wed, 26 Oct 2022 18:54:28 +0800 Message-Id: <20221026105429.1899867-6-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 Add support for MD5, SHA1, SHA224, SHA256, SHA384, SHA512 Authentication algorithms with and without HMAC. Signed-off-by: Zhangfei Gao --- doc/guides/cryptodevs/features/uadk.ini | 12 + doc/guides/cryptodevs/uadk.rst | 15 + drivers/crypto/uadk/uadk_crypto_pmd.c | 447 ++++++++++++++++++ drivers/crypto/uadk/uadk_crypto_pmd_private.h | 12 + 4 files changed, 486 insertions(+) diff --git a/doc/guides/cryptodevs/features/uadk.ini b/doc/guides/cryptodevs/features/uadk.ini index 005e08ac8d..2e8a37a2b3 100644 --- a/doc/guides/cryptodevs/features/uadk.ini +++ b/doc/guides/cryptodevs/features/uadk.ini @@ -25,6 +25,18 @@ DES CBC = Y ; Supported authentication algorithms of the 'uadk' crypto driver. ; [Auth] +MD5 = Y +MD5 HMAC = Y +SHA1 = Y +SHA1 HMAC = Y +SHA224 = Y +SHA224 HMAC = Y +SHA256 = Y +SHA256 HMAC = Y +SHA384 = Y +SHA384 HMAC = Y +SHA512 = Y +SHA512 HMAC = Y ; ; Supported AEAD algorithms of the 'uadk' crypto driver. diff --git a/doc/guides/cryptodevs/uadk.rst b/doc/guides/cryptodevs/uadk.rst index e0ca097961..19bb461e72 100644 --- a/doc/guides/cryptodevs/uadk.rst +++ b/doc/guides/cryptodevs/uadk.rst @@ -31,6 +31,21 @@ Cipher algorithms: * ``RTE_CRYPTO_CIPHER_AES_XTS`` * ``RTE_CRYPTO_CIPHER_DES_CBC`` +Hash algorithms: + +* ``RTE_CRYPTO_AUTH_MD5`` +* ``RTE_CRYPTO_AUTH_MD5_HMAC`` +* ``RTE_CRYPTO_AUTH_SHA1`` +* ``RTE_CRYPTO_AUTH_SHA1_HMAC`` +* ``RTE_CRYPTO_AUTH_SHA224`` +* ``RTE_CRYPTO_AUTH_SHA224_HMAC`` +* ``RTE_CRYPTO_AUTH_SHA256`` +* ``RTE_CRYPTO_AUTH_SHA256_HMAC`` +* ``RTE_CRYPTO_AUTH_SHA384`` +* ``RTE_CRYPTO_AUTH_SHA384_HMAC`` +* ``RTE_CRYPTO_AUTH_SHA512`` +* ``RTE_CRYPTO_AUTH_SHA512_HMAC`` + Test steps ---------- diff --git a/drivers/crypto/uadk/uadk_crypto_pmd.c b/drivers/crypto/uadk/uadk_crypto_pmd.c index f112a96033..2ba9804981 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd.c +++ b/drivers/crypto/uadk/uadk_crypto_pmd.c @@ -18,6 +18,252 @@ static uint8_t uadk_cryptodev_driver_id; static const struct rte_cryptodev_capabilities uadk_crypto_v2_capabilities[] = { + { /* MD5 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_MD5_HMAC, + .block_size = 64, + .key_size = { + .min = 1, + .max = 64, + .increment = 1 + }, + .digest_size = { + .min = 16, + .max = 16, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* MD5 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_MD5, + .block_size = 64, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 16, + .max = 16, + .increment = 0 + }, + }, } + }, } + }, + { /* SHA1 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA1_HMAC, + .block_size = 64, + .key_size = { + .min = 1, + .max = 64, + .increment = 1 + }, + .digest_size = { + .min = 20, + .max = 20, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* SHA1 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA1, + .block_size = 64, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 20, + .max = 20, + .increment = 0 + }, + }, } + }, } + }, + { /* SHA224 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA224_HMAC, + .block_size = 64, + .key_size = { + .min = 1, + .max = 64, + .increment = 1 + }, + .digest_size = { + .min = 28, + .max = 28, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* SHA224 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA224, + .block_size = 64, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 28, + .max = 28, + .increment = 0 + }, + }, } + }, } + }, + { /* SHA256 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA256_HMAC, + .block_size = 64, + .key_size = { + .min = 1, + .max = 64, + .increment = 1 + }, + .digest_size = { + .min = 32, + .max = 32, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* SHA256 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA256, + .block_size = 64, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 32, + .max = 32, + .increment = 0 + }, + }, } + }, } + }, + { /* SHA384 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA384_HMAC, + .block_size = 128, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 48, + .max = 48, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* SHA384 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA384, + .block_size = 64, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 48, + .max = 48, + .increment = 0 + }, + }, } + }, } + }, + { /* SHA512 HMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA512_HMAC, + .block_size = 128, + .key_size = { + .min = 1, + .max = 128, + .increment = 1 + }, + .digest_size = { + .min = 64, + .max = 64, + .increment = 0 + }, + .iv_size = { 0 } + }, } + }, } + }, + { /* SHA512 */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_SHA512, + .block_size = 128, + .key_size = { + .min = 0, + .max = 0, + .increment = 0 + }, + .digest_size = { + .min = 64, + .max = 64, + .increment = 0 + }, + }, } + }, } + }, { /* AES ECB */ .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, {.sym = { @@ -134,6 +380,11 @@ uadk_crypto_pmd_close(struct rte_cryptodev *dev) priv->env_cipher_init = false; } + if (priv->env_auth_init) { + wd_digest_env_uninit(); + priv->env_auth_init = false; + } + return 0; } @@ -292,9 +543,19 @@ uadk_get_chain_order(const struct rte_crypto_sym_xform *xform) enum uadk_chain_order res = UADK_CHAIN_NOT_SUPPORTED; if (xform != NULL) { + if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) { + if (xform->next == NULL) + res = UADK_CHAIN_ONLY_AUTH; + else if (xform->next->type == + RTE_CRYPTO_SYM_XFORM_CIPHER) + res = UADK_CHAIN_AUTH_CIPHER; + } + if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { if (xform->next == NULL) res = UADK_CHAIN_ONLY_CIPHER; + else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) + res = UADK_CHAIN_CIPHER_AUTH; } } @@ -381,12 +642,119 @@ uadk_set_session_cipher_parameters(struct rte_cryptodev *dev, return ret; } +/* Set session auth parameters */ +static int +uadk_set_session_auth_parameters(struct rte_cryptodev *dev, + struct uadk_crypto_session *sess, + struct rte_crypto_sym_xform *xform) +{ + struct uadk_crypto_priv *priv = dev->data->dev_private; + struct wd_digest_sess_setup setup = {0}; + struct sched_params params = {0}; + int ret; + + if (!priv->env_auth_init) { + ret = wd_digest_env_init(NULL); + if (ret < 0) + return -EINVAL; + priv->env_auth_init = true; + } + + sess->auth.operation = xform->auth.op; + sess->auth.digest_length = xform->auth.digest_length; + + switch (xform->auth.algo) { + case RTE_CRYPTO_AUTH_MD5: + case RTE_CRYPTO_AUTH_MD5_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_MD5) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_MD5; + sess->auth.req.out_buf_bytes = 16; + sess->auth.req.out_bytes = 16; + break; + case RTE_CRYPTO_AUTH_SHA1: + case RTE_CRYPTO_AUTH_SHA1_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_SHA1) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_SHA1; + sess->auth.req.out_buf_bytes = 20; + sess->auth.req.out_bytes = 20; + break; + case RTE_CRYPTO_AUTH_SHA224: + case RTE_CRYPTO_AUTH_SHA224_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_SHA224) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_SHA224; + sess->auth.req.out_buf_bytes = 28; + sess->auth.req.out_bytes = 28; + break; + case RTE_CRYPTO_AUTH_SHA256: + case RTE_CRYPTO_AUTH_SHA256_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_SHA256) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_SHA256; + sess->auth.req.out_buf_bytes = 32; + sess->auth.req.out_bytes = 32; + break; + case RTE_CRYPTO_AUTH_SHA384: + case RTE_CRYPTO_AUTH_SHA384_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_SHA384) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_SHA384; + sess->auth.req.out_buf_bytes = 48; + sess->auth.req.out_bytes = 48; + break; + case RTE_CRYPTO_AUTH_SHA512: + case RTE_CRYPTO_AUTH_SHA512_HMAC: + setup.mode = (xform->auth.algo == RTE_CRYPTO_AUTH_SHA512) ? + WD_DIGEST_NORMAL : WD_DIGEST_HMAC; + setup.alg = WD_DIGEST_SHA512; + sess->auth.req.out_buf_bytes = 64; + sess->auth.req.out_bytes = 64; + break; + default: + ret = -ENOTSUP; + goto env_uninit; + } + + params.numa_id = -1; /* choose nearby numa node */ + setup.sched_param = ¶ms; + sess->handle_digest = wd_digest_alloc_sess(&setup); + if (!sess->handle_digest) { + UADK_LOG(ERR, "uadk failed to alloc session!\n"); + ret = -EINVAL; + goto env_uninit; + } + + /* if mode is HMAC, should set key */ + if (setup.mode == WD_DIGEST_HMAC) { + ret = wd_digest_set_key(sess->handle_digest, + xform->auth.key.data, + xform->auth.key.length); + if (ret) { + UADK_LOG(ERR, "uadk failed to alloc session!\n"); + wd_digest_free_sess(sess->handle_digest); + sess->handle_digest = 0; + ret = -EINVAL; + goto env_uninit; + } + } + + return 0; + +env_uninit: + wd_digest_env_uninit(); + priv->env_auth_init = false; + return ret; +} + static int uadk_crypto_sym_session_configure(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, struct rte_cryptodev_sym_session *session) { struct rte_crypto_sym_xform *cipher_xform = NULL; + struct rte_crypto_sym_xform *auth_xform = NULL; struct uadk_crypto_session *sess = CRYPTODEV_GET_SYM_SESS_PRIV(session); int ret; @@ -400,6 +768,17 @@ uadk_crypto_sym_session_configure(struct rte_cryptodev *dev, case UADK_CHAIN_ONLY_CIPHER: cipher_xform = xform; break; + case UADK_CHAIN_ONLY_AUTH: + auth_xform = xform; + break; + case UADK_CHAIN_CIPHER_AUTH: + cipher_xform = xform; + auth_xform = xform->next; + break; + case UADK_CHAIN_AUTH_CIPHER: + auth_xform = xform; + cipher_xform = xform->next; + break; default: return -ENOTSUP; } @@ -413,6 +792,15 @@ uadk_crypto_sym_session_configure(struct rte_cryptodev *dev, } } + if (auth_xform) { + ret = uadk_set_session_auth_parameters(dev, sess, auth_xform); + if (ret != 0) { + UADK_LOG(ERR, + "Invalid/unsupported auth parameters"); + return ret; + } + } + return 0; } @@ -431,6 +819,11 @@ uadk_crypto_sym_session_clear(struct rte_cryptodev *dev __rte_unused, wd_cipher_free_sess(sess->handle_cipher); sess->handle_cipher = 0; } + + if (sess->handle_digest) { + wd_digest_free_sess(sess->handle_digest); + sess->handle_digest = 0; + } } static struct rte_cryptodev_ops uadk_crypto_pmd_ops = { @@ -481,6 +874,49 @@ uadk_process_cipher_op(struct rte_crypto_op *op, op->status = RTE_CRYPTO_OP_STATUS_ERROR; } +static void +uadk_process_auth_op(struct uadk_qp *qp, struct rte_crypto_op *op, + struct uadk_crypto_session *sess, + struct rte_mbuf *msrc, struct rte_mbuf *mdst) +{ + uint32_t srclen = op->sym->auth.data.length; + uint32_t off = op->sym->auth.data.offset; + uint8_t *dst = qp->temp_digest; + int ret; + + if (!sess) { + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return; + } + + sess->auth.req.in = rte_pktmbuf_mtod_offset(msrc, uint8_t *, off); + sess->auth.req.in_bytes = srclen; + sess->auth.req.out = dst; + + do { + ret = wd_do_digest_sync(sess->handle_digest, &sess->auth.req); + } while (ret == -WD_EBUSY); + + if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) { + if (memcmp(dst, op->sym->auth.digest.data, + sess->auth.digest_length) != 0) { + op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; + } + } else { + uint8_t *auth_dst; + + auth_dst = op->sym->auth.digest.data; + if (auth_dst == NULL) + auth_dst = rte_pktmbuf_mtod_offset(mdst, uint8_t *, + op->sym->auth.data.offset + + op->sym->auth.data.length); + memcpy(auth_dst, dst, sess->auth.digest_length); + } + + if (ret) + op->status = RTE_CRYPTO_OP_STATUS_ERROR; +} + static uint16_t uadk_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, uint16_t nb_ops) @@ -508,6 +944,17 @@ uadk_crypto_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops, case UADK_CHAIN_ONLY_CIPHER: uadk_process_cipher_op(op, sess, msrc, mdst); break; + case UADK_CHAIN_ONLY_AUTH: + uadk_process_auth_op(qp, op, sess, msrc, mdst); + break; + case UADK_CHAIN_CIPHER_AUTH: + uadk_process_cipher_op(op, sess, msrc, mdst); + uadk_process_auth_op(qp, op, sess, mdst, mdst); + break; + case UADK_CHAIN_AUTH_CIPHER: + uadk_process_auth_op(qp, op, sess, msrc, mdst); + uadk_process_cipher_op(op, sess, msrc, mdst); + break; default: op->status = RTE_CRYPTO_OP_STATUS_ERROR; break; diff --git a/drivers/crypto/uadk/uadk_crypto_pmd_private.h b/drivers/crypto/uadk/uadk_crypto_pmd_private.h index e981420cef..9075f0f058 100644 --- a/drivers/crypto/uadk/uadk_crypto_pmd_private.h +++ b/drivers/crypto/uadk/uadk_crypto_pmd_private.h @@ -27,11 +27,15 @@ struct uadk_qp { enum uadk_chain_order { UADK_CHAIN_ONLY_CIPHER, + UADK_CHAIN_ONLY_AUTH, + UADK_CHAIN_CIPHER_AUTH, + UADK_CHAIN_AUTH_CIPHER, UADK_CHAIN_NOT_SUPPORTED }; struct uadk_crypto_session { handle_t handle_cipher; + handle_t handle_digest; enum uadk_chain_order chain_order; /* IV parameters */ @@ -45,6 +49,13 @@ struct uadk_crypto_session { enum rte_crypto_cipher_operation direction; struct wd_cipher_req req; } cipher; + + /* Authentication Parameters */ + struct { + struct wd_digest_req req; + enum rte_crypto_auth_operation operation; + uint16_t digest_length; + } auth; } __rte_cache_aligned; enum uadk_crypto_version { @@ -54,6 +65,7 @@ enum uadk_crypto_version { struct uadk_crypto_priv { bool env_cipher_init; + bool env_auth_init; enum uadk_crypto_version version; } __rte_cache_aligned; From patchwork Wed Oct 26 10:54:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 618813 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp317600pvb; Wed, 26 Oct 2022 04:02:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5sgRQiULZw1KcoIi4SeA51LD9dsfl7Uy4immmeF3VoTFoxKGsPREkpPHXgSDpnAjXKUwrN X-Received: by 2002:adf:e58c:0:b0:236:6a4c:c605 with SMTP id l12-20020adfe58c000000b002366a4cc605mr12885562wrm.597.1666782121651; Wed, 26 Oct 2022 04:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666782121; cv=none; d=google.com; s=arc-20160816; b=E9NvMrzfXh7Zj2/f9EeW0cw5SU7NnUnPpBP3pMdh7VIoCNyNzZF0dHEG9K013X4p5r DK8/kVMm+lvvBVpC60eCpHJNv5meOtXjYbOV6x2Zq6LaS6AMBPodcUiSW1mbhawgjliN Q6eFRs+eYxH7C4apIPVO8vtcG8jHIlUH9VmElJYebsExjvEbim9axnD5ZMJfBlIeH64E MM1+6XBSovZeUYPSI5+0AXdP82xpQjWq/hfsK/ozOKbHgNiK7FvI152/YGoRo7bc9NZo 4o2aRxpuas/Pza+rXMJdCLz9/ocVJclZ9ED8HOg8dF9N/svUyEGTTrHbe2mf/ao9TT53 lC8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YLQK8xwHrELfFX9ObHmi++zDodD6cvT0mUggqlVEgMg=; b=CNFE65IGoq1Iz1HjaVmeyOPmNTv8K9RoK5HUehLu5vE6UUs6VweK9tGGzFX0bZnM4R O5II/Xat7yhv3W3V0r/hfcO7DjzawlufkazxjCgbx0g8SPtqxBCq620W+UR5avSRTqAK eE5zRI73g0pIB3qITFj/mMzuI1+4WkF1M3Ju0QMrRlC0m37jcRxz4yIijJqFiIrs6Iig Ap/c8W5GGNzTg3CSRzEdmWC30IgoQKUih4gzWFKuZL/gzaU080cf125jJP6F1Bgq/Tpb tylLG7Y7YGxJIjK+fScYa6MRxcWBdCb2slVMqaFs91l7mcS+X7K7lJUe/JRGb7alPB8Q IaCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FrDtK8Iq; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id h9-20020a05600c350900b003a5f6f7f204si1249695wmq.209.2022.10.26.04.02.01; Wed, 26 Oct 2022 04:02:01 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FrDtK8Iq; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F1A942BE6; Wed, 26 Oct 2022 13:01:29 +0200 (CEST) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mails.dpdk.org (Postfix) with ESMTP id 5D0EA41611 for ; Wed, 26 Oct 2022 13:01:22 +0200 (CEST) Received: by mail-wm1-f51.google.com with SMTP id l14-20020a05600c1d0e00b003c6ecc94285so2017032wms.1 for ; Wed, 26 Oct 2022 04:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YLQK8xwHrELfFX9ObHmi++zDodD6cvT0mUggqlVEgMg=; b=FrDtK8IqWY4aMfzZzYmGdoWO1JPWelQ8HEsAHE5jKCtwGA6BTqg46E6vGCq81RkKEn P2uzPCxzMLU+EyQbu8KBJYtCjEWGE5wARYDuMXaaO9HU4NpPK9fz5B0LWaQFifKI50+H DAQtBr6bFxTorK+tKtxu+LDwaaH66fUXdQJyyFmpTLapQL9uqY7dEFyaX20LopE9iRdx lFfKtdGsA/I6ycbsHSm1gLX3Ws/GTh41jKvU7kr7777f2eRt3yFgFHr+jQBfRaLAcpMW 2sOvtNPrPKr++pP9Fe/FA10s2zAmn3TYpToqpZJhtME+2Un5P10Me4NgFA3z+CHpshfO L+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YLQK8xwHrELfFX9ObHmi++zDodD6cvT0mUggqlVEgMg=; b=3XGTA1xbImNKlttQNHCGzAox24sGPdI5D+nV67+8wjKDx4q1luXKyzt7QZd6CWU4Ui 8dzIe11fKsvodj6Q2MafJuhI4IR/BDWf9Dld/Rt92jFtFpgOMQAqmR3aJLQnLU0paxIZ n46b38wdDrlEI20JnrZwgHRGDNY125RLDZopBezw3RtqiXjNXUicG5cWHrQfEm9fdBV8 uLBEMV00hpjVP22aovxQMB6qW0gEtkTomwijDyoESODvUGBrAB0n5v+897vGpLFAKY9g y0IYGSUV4XOLIUng1CPEqV1zRDEBp8ln/AO8MYTbyRU4mxt7FX632dqgdmM9cYGm14he TdoQ== X-Gm-Message-State: ACrzQf3H8JEYbauXXSUpWQbdnK4cSz7BkNr01H3e5za2qfjc6/4WL2Aw +TK5E/GS3DW7HghU5T8Fp3ztcV50d1Xa8aZq X-Received: by 2002:a05:600c:a4c:b0:3b4:fc1b:81 with SMTP id c12-20020a05600c0a4c00b003b4fc1b0081mr1963032wmq.125.1666782082074; Wed, 26 Oct 2022 04:01:22 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id h14-20020a5d688e000000b0023660f6cecfsm4856094wru.80.2022.10.26.04.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:01:21 -0700 (PDT) From: Zhangfei Gao To: Akhil Goyal , Declan Doherty , Fan Zhang , Ashish Gupta , Ray Kinsella , "thomas@monjalon.net" Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v6 6/6] test/crypto: support uadk PMD Date: Wed, 26 Oct 2022 18:54:29 +0800 Message-Id: <20221026105429.1899867-7-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026105429.1899867-1-zhangfei.gao@linaro.org> References: <20221026105429.1899867-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 Example: sudo dpdk-test --vdev=crypto_uadk --log-level=6 RTE>>cryptodev_uadk_autotest RTE>>quit Signed-off-by: Zhangfei Gao --- app/test/meson.build | 1 + app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + doc/guides/cryptodevs/uadk.rst | 3 +++ 4 files changed, 12 insertions(+) diff --git a/app/test/meson.build b/app/test/meson.build index 396b133959..f34d19e3c3 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -312,6 +312,7 @@ driver_test_names = [ 'cryptodev_sw_mvsam_autotest', 'cryptodev_sw_snow3g_autotest', 'cryptodev_sw_zuc_autotest', + 'cryptodev_uadk_autotest', 'dmadev_autotest', 'rawdev_autotest', ] diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 43fcef7e73..101a68fb70 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -16538,6 +16538,12 @@ test_cryptodev_qat(void) return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); } +static int +test_cryptodev_uadk(void) +{ + return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); +} + static int test_cryptodev_virtio(void) { @@ -16881,6 +16887,7 @@ REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND(cryptodev_uadk_autotest, test_cryptodev_uadk); REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h index 29a7d4db2b..abd795f54a 100644 --- a/app/test/test_cryptodev.h +++ b/app/test/test_cryptodev.h @@ -74,6 +74,7 @@ #define CRYPTODEV_NAME_CN9K_PMD crypto_cn9k #define CRYPTODEV_NAME_CN10K_PMD crypto_cn10k #define CRYPTODEV_NAME_MLX5_PMD crypto_mlx5 +#define CRYPTODEV_NAME_UADK_PMD crypto_uadk enum cryptodev_api_test_type { diff --git a/doc/guides/cryptodevs/uadk.rst b/doc/guides/cryptodevs/uadk.rst index 19bb461e72..c9508ecd9e 100644 --- a/doc/guides/cryptodevs/uadk.rst +++ b/doc/guides/cryptodevs/uadk.rst @@ -88,6 +88,9 @@ Test steps $ mount -t hugetlbfs none /mnt/huge_2mb -o pagesize=2MB 5. Run test app + $ sudo dpdk-test --vdev=crypto_uadk --log-level=6 + RTE>>cryptodev_uadk_autotest + RTE>>quit [1] https://github.com/Linaro/uadk