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 2ECF6A0548; Sun, 9 May 2021 18:05:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3CB84111D; Sun, 9 May 2021 18:05:32 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2045.outbound.protection.outlook.com [40.107.93.45]) by mails.dpdk.org (Postfix) with ESMTP id A1F2141109 for ; Sun, 9 May 2021 18:05:30 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nEb5qIo0hG37tBTy2qwEOlhhX7KTGFe99KX2j5YAh+6NSVh/RcLVtUaEI6fBxm+a4hKnTk5xBu/TCRi662IvsGbub4RkKtWhItPx/unD8ZX9wiF2zrBnpR+hOVfVPy9rAId+34BaNwfnGEhYlEFXEa2+XdlUSuTRWDgH4vZsunkaCQEyl7GwcuZmq6eoqfBvuasnrikjrglWuGOOk+CKq6wgZoD4/cJah5W9S03hlU4L9sCd9VQ5xrK5VVFswenTxoIc9QTiskR50Y2wVfBNoDJGUXjAKPGjP7YQ+5a9T6f0C545Hu/KVY7JAj0xZSR5eRbZhL/0YpFN6mztwvd85A== 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=ykuPGjuKKyFrkYUZiwcTKDDmHRitGARR4h6DPfovR18=; b=DPNBfHiMuriDa6WoXd5rEb2f8Bh52yfFDFMpjWF29jGg0dxjOeWLk2nS2EuWFRs/mAnbqo6ivMrPX0gj8phzCq1GBLRwfsHFWVWSYWiEy1pbjhgZkyn3lz/2NXpx3PceNNB9f9+IMBiq95L9zN8lT1TPqi+drcmObxunQ7GEtPc3Nhwhc1i8A8Ho0CK+HCULGkMFRfoHES9SCkpxPYoathxAfypPEjbwoM0CjXDewjE3SCZM17dam0z47iLuf2lIDSIfCHeNiQinFvaydmW849toX81UXwAM2jdeCpLG/vbkLWREVISRUyaO9fJUuuxS7FRtz1nRUoeCH4YGYGSpKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net 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=ykuPGjuKKyFrkYUZiwcTKDDmHRitGARR4h6DPfovR18=; b=cp4DQrk8H0E55Y5k+4vuf7uAF8vr50aPxTLdQxSZjbyNwZMFxz5yX9Rygfkx01LtW4tsajkQuZ4PLV8iEWppzH/xuRLqVRA1AP3pc8pLKiaoVP80OrJL/Jzk9yoICCFmIVi6bro6sr7YP1FXAxK5zyoJr0hM8YI0DDHsAKzZuaq4nUmM2yB73sif2zVDJTGdwnG0l660/RjmL8Gn8dtIHOMUywY4dcEok90rC3AGOMK1D1/LG+ptSN554bnhk0Kdgf8YUdUuZ/9jeY1SvjijENZRgKyAvThM8K52o2aYfZvXiBSCW+t/50FSID+OgTvTHldnjYILz3TRSBjIejnSPQ== Received: from MW2PR16CA0062.namprd16.prod.outlook.com (2603:10b6:907:1::39) by DM5PR1201MB0041.namprd12.prod.outlook.com (2603:10b6:4:56::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Sun, 9 May 2021 16:05:29 +0000 Received: from CO1NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::66) by MW2PR16CA0062.outlook.office365.com (2603:10b6:907:1::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Sun, 9 May 2021 16:05:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; 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 CO1NAM11FT023.mail.protection.outlook.com (10.13.175.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4108.25 via Frontend Transport; Sun, 9 May 2021 16:05:28 +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; Sun, 9 May 2021 16:05:26 +0000 From: Matan Azrad To: CC: , , , "Thomas Monjalon" , Shiri Kuzin Date: Sun, 9 May 2021 19:04:56 +0300 Message-ID: <20210509160507.224644-4-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210509160507.224644-1-matan@nvidia.com> References: <20210504210857.3398397-1-matan@nvidia.com> <20210509160507.224644-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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1138a81d-a6cd-40c9-42ef-08d9130443be X-MS-TrafficTypeDiagnostic: DM5PR1201MB0041: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1EMmFDPcsbnIxEVaGkC/7YfI71cJ9Kgw1rwkV9qcStnvJHNxfTX2gt/2SxsSPYMRISWgzGfwnasAx1Xb5omONHGWiPvKAiBqRwCLfbWCirBL8pfe8cRtRmlWcDQumZ1kALarNBieXBZ0qxWDvsz9hoUI6/IovTm+JlRrfnc/VY0wn98Eq7aFYXmqzB0huqd/T9bOHGgKGK4hTl6zkWkJ0pvD2r1rD4tS7xiJbGUil8UeJ/oQr97UT05ggx8TqAYoMVI+5qOkZ4vAKmQ2X9nJSQS/47SPg8THUmjOfnrajhDukFtwYuEULFE94i/1PxROPuM30ZRtqeOLfM2YkE0a0BOhl1u24kYLg+pI7fWKYvpnnMZUl45l8LM7FerSjHSv0gXhp7HfOzT2/3aVRS4VTT81gH/x2amygJD4IGnxk01zQDOT4OyHwm236mvK86QxfPMcfNKETrRT2M+n5TjhjMzo9ZhEirA7R2iApv7Ahk8Si1H5jp6NdoKDZmBaSrOAz0SGTflBc8kbTMu+2/qs1ZyyQ2gpeUZ5RU583BgI0Q2BVXFrjl4EUsCmir4vXYZ5S8H7UI5EGxZz5zf1OPz7HZkelm8PUgPd9tAael+cnHBm2GRQAoVRID4yyquFh6yYqHG1ASF13rqqwJREBbhwfwIvfhgWzcIvDLrr7eMeWJ0= 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)(39860400002)(376002)(396003)(136003)(346002)(36840700001)(46966006)(82740400003)(47076005)(16526019)(186003)(86362001)(6286002)(36756003)(7696005)(5660300002)(316002)(6666004)(54906003)(478600001)(36906005)(8936002)(2906002)(6916009)(426003)(8676002)(356005)(55016002)(7636003)(36860700001)(336012)(82310400003)(1076003)(83380400001)(4326008)(2616005)(107886003)(26005)(70206006)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2021 16:05:28.5895 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1138a81d-a6cd-40c9-42ef-08d9130443be 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: CO1NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0041 Subject: [dpdk-dev] [PATCH v4 03/14] crypto/mlx5: add session 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: Shiri Kuzin Sessions are used in symmetric transformations in order to prepare objects and data for packet processing stage. A mlx5 session includes iv_offset, pointer to mlx5_crypto_dek struct, bsf_size, bsf_p_type, block size index, encryption_order and encryption standard. Implement the next session operations: mlx5_crypto_sym_session_get_size- returns the size of the mlx5 session struct. mlx5_crypto_sym_session_configure- prepares the DEK hash-list and saves all the session data. mlx5_crypto_sym_session_clear - destroys the DEK hash-list. Signed-off-by: Shiri Kuzin Acked-by: Matan Azrad --- drivers/crypto/mlx5/mlx5_crypto.c | 120 +++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index 2825f4192e..31d27245be 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -36,6 +37,29 @@ static const struct rte_driver mlx5_drv = { static struct cryptodev_driver mlx5_cryptodev_driver; +struct mlx5_crypto_session { + uint32_t bs_bpt_eo_es; + /* + * bsf_size, bsf_p_type, encryption_order and encryption standard, + * saved in big endian format. + */ + uint32_t bsp_res; + /* + * crypto_block_size_pointer and reserved 24 bits saved in big endian + * format. + */ + uint32_t iv_offset:16; + /* Starting point for Initialisation Vector. */ + struct mlx5_crypto_dek *dek; /* Pointer to dek struct. */ + uint32_t dek_id; /* DEK ID */ +} __rte_packed; + +static unsigned int +mlx5_crypto_sym_session_get_size(struct rte_cryptodev *dev __rte_unused) +{ + return sizeof(struct mlx5_crypto_session); +} + static int mlx5_crypto_dev_configure(struct rte_cryptodev *dev, struct rte_cryptodev_config *config __rte_unused) @@ -58,6 +82,96 @@ mlx5_crypto_dev_close(struct rte_cryptodev *dev) return 0; } +static int +mlx5_crypto_sym_session_configure(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *session, + struct rte_mempool *mp) +{ + struct mlx5_crypto_priv *priv = dev->data->dev_private; + struct mlx5_crypto_session *sess_private_data; + struct rte_crypto_cipher_xform *cipher; + uint8_t encryption_order; + int ret; + + if (unlikely(xform->next != NULL)) { + DRV_LOG(ERR, "Xform next is not supported."); + return -ENOTSUP; + } + if (unlikely((xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) || + (xform->cipher.algo != RTE_CRYPTO_CIPHER_AES_XTS))) { + DRV_LOG(ERR, "Only AES-XTS algorithm is supported."); + return -ENOTSUP; + } + ret = rte_mempool_get(mp, (void *)&sess_private_data); + if (ret != 0) { + DRV_LOG(ERR, + "Failed to get session %p private data from mempool.", + sess_private_data); + return -ENOMEM; + } + cipher = &xform->cipher; + sess_private_data->dek = mlx5_crypto_dek_prepare(priv, cipher); + if (sess_private_data->dek == NULL) { + rte_mempool_put(mp, sess_private_data); + DRV_LOG(ERR, "Failed to prepare dek."); + return -ENOMEM; + } + if (cipher->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) + encryption_order = MLX5_ENCRYPTION_ORDER_ENCRYPTED_RAW_MEMORY; + else + encryption_order = MLX5_ENCRYPTION_ORDER_ENCRYPTED_RAW_WIRE; + sess_private_data->bs_bpt_eo_es = rte_cpu_to_be_32 + (MLX5_BSF_SIZE_64B << MLX5_BSF_SIZE_OFFSET | + MLX5_BSF_P_TYPE_CRYPTO << MLX5_BSF_P_TYPE_OFFSET | + encryption_order << MLX5_ENCRYPTION_ORDER_OFFSET | + MLX5_ENCRYPTION_STANDARD_AES_XTS); + switch (xform->cipher.dataunit_len) { + case 0: + sess_private_data->bsp_res = 0; + break; + case 512: + sess_private_data->bsp_res = rte_cpu_to_be_32 + ((uint32_t)MLX5_BLOCK_SIZE_512B << + MLX5_BLOCK_SIZE_OFFSET); + break; + case 4096: + sess_private_data->bsp_res = rte_cpu_to_be_32 + ((uint32_t)MLX5_BLOCK_SIZE_4096B << + MLX5_BLOCK_SIZE_OFFSET); + break; + default: + DRV_LOG(ERR, "Cipher data unit length is not supported."); + return -ENOTSUP; + } + sess_private_data->iv_offset = cipher->iv.offset; + sess_private_data->dek_id = + rte_cpu_to_be_32(sess_private_data->dek->obj->id & + 0xffffff); + set_sym_session_private_data(session, dev->driver_id, + sess_private_data); + DRV_LOG(DEBUG, "Session %p was configured.", sess_private_data); + return 0; +} + +static void +mlx5_crypto_sym_session_clear(struct rte_cryptodev *dev, + struct rte_cryptodev_sym_session *sess) +{ + struct mlx5_crypto_priv *priv = dev->data->dev_private; + struct mlx5_crypto_session *spriv = get_sym_session_private_data(sess, + dev->driver_id); + + if (unlikely(spriv == NULL)) { + DRV_LOG(ERR, "Failed to get session %p private data.", spriv); + return; + } + mlx5_crypto_dek_destroy(priv, spriv->dek); + set_sym_session_private_data(sess, dev->driver_id, NULL); + rte_mempool_put(rte_mempool_from_obj(spriv), spriv); + DRV_LOG(DEBUG, "Session %p was cleared.", spriv); +} + static struct rte_cryptodev_ops mlx5_crypto_ops = { .dev_configure = mlx5_crypto_dev_configure, .dev_start = NULL, @@ -68,9 +182,9 @@ static struct rte_cryptodev_ops mlx5_crypto_ops = { .stats_reset = NULL, .queue_pair_setup = NULL, .queue_pair_release = NULL, - .sym_session_get_size = NULL, - .sym_session_configure = NULL, - .sym_session_clear = NULL, + .sym_session_get_size = mlx5_crypto_sym_session_get_size, + .sym_session_configure = mlx5_crypto_sym_session_configure, + .sym_session_clear = mlx5_crypto_sym_session_clear, .sym_get_raw_dp_ctx_size = NULL, .sym_configure_raw_dp_ctx = NULL, }; -- 2.25.1