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 3BB4942BA3; Fri, 26 May 2023 05:16:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8861042D3B; Fri, 26 May 2023 05:15:52 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2077.outbound.protection.outlook.com [40.107.92.77]) by mails.dpdk.org (Postfix) with ESMTP id 451DD42B71 for ; Fri, 26 May 2023 05:15:49 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k4y4CyJB7fftFPQgtHbaMAVTrvgBsLR5qIBgRG9bErXlwcAIq/FGILeXP56H/AsTYiaPKJMkdb+VcQD4SwfAw9NsLD4X8r2xmNvZA6dY6539IGMC/GBcjjdEh0Il6nAE2aTNWTIcKAUD3uOyFape5xtRFYQ/hlqx50UgvzVS03CUzPSu0BbAeVnLCNkbNYkZCChPouOaeecuvkIq3LHkAb02t2cqVITfAI4zF3yDC+INigyomA9FiXl4dtqo+3tIccKXfFeiDkiEkhCxCGiK4aZyV1DD6buccoVMVP2TJXdLTztHrBJZfJqxuJ2Mwle6oIsWXaAUku7AW6jUT8AZaA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PTw2VemPomIOyP8/UdMO3OTsV9E4FMs0AC6DRTB+o7k=; b=RdXScnVV5SNZbAVHCR3Cq9u4D/OtNBjJIjgNNxCUk2esaYhpO9fbGdRw5KZJHN18OJds4FFzIRBnapWVEl6oIIhzBb0mq6uBnZuF6cu17mOKZTKT67lk1N4RWS27G2FUGdpLzT4Cf3acxKnf4Prj8byrt6CcwyXhyOngWVL184jKU+kIELgjMRD11D7zZVdQgM+LRJHAPKTX4kK4QYi9FhmoQUYwJmAnjf7tK6J5RoiVrHQBrHQ+FhA4/VG4VcALdDA67UsZbIYlCfAzGTPS7+G5JeVRIUgdiZ7un6SwQpQA9tFM1hLLnrhLgbLB4QP1lGuuOEipZilbVmjdSsyruQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=PTw2VemPomIOyP8/UdMO3OTsV9E4FMs0AC6DRTB+o7k=; b=Bs5ie6vFCICbm93TpJpAV/ParoXMvYoJ4dKykB20W1Qnz2gErs+MnzXoYLYuOzFpqJ90m4kKzrvbda6pNI8eKZ9MMp+HDiqZNTZylUbZzmUvrF0SDMMrzUahXjukhkLgol8gV6cx0w0QQv6UoeVHnipbbUtG4pqmWiUEefH2yDLL56QmH1T5wIzIrBYfSaj2Xcuu1O3zep65Eb1CKx8gt0S528RZseZWNBgFfMUNWJEvplMR2GKPhoQ16lVNLpI1CWAlToctROIoZMF/Kr0VhQtc/JeRtgnjDAHYqvKaUrRLNweQzOXnr1ukk11xnW9PGullp6Ijw2F0gUcaOEwB1w== Received: from BN0PR08CA0017.namprd08.prod.outlook.com (2603:10b6:408:142::24) by IA1PR12MB9064.namprd12.prod.outlook.com (2603:10b6:208:3a8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.17; Fri, 26 May 2023 03:15:47 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:142:cafe::d) by BN0PR08CA0017.outlook.office365.com (2603:10b6:408:142::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.18 via Frontend Transport; Fri, 26 May 2023 03:15:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.18 via Frontend Transport; Fri, 26 May 2023 03:15:47 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 25 May 2023 20:15:33 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 25 May 2023 20:15:30 -0700 From: Suanming Mou To: Matan Azrad , Viacheslav Ovsiienko CC: , Subject: [PATCH v2 5/9] crypto/mlx5: add AES-GCM session configure Date: Fri, 26 May 2023 06:14:17 +0300 Message-ID: <20230526031422.913377-6-suanmingm@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230526031422.913377-1-suanmingm@nvidia.com> References: <20230418092325.2578712-1-suanmingm@nvidia.com> <20230526031422.913377-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT009:EE_|IA1PR12MB9064:EE_ X-MS-Office365-Filtering-Correlation-Id: 1546b555-fe5f-4239-188c-08db5d978038 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yE2TBCmCSDxKThFnVel83rEaFcQZZ+ol8ABMVuxFFcroLbjJRLUte9/y4nwdT8pb456XtJ+olxi5QnGRzsW1aEnjD9iEGXDgcHYfvV2jbkVJoPsPYr/ZemCNL07JBJFMRTpIWBuqKvHdovG2XGJwGhxYZvDptowZVzfAztB5+qsv0LmkVPewYHn4n06FNhoG8B1R7CZsVLh2gE0pxlh2Nmj8NLIZfTmuCZq4pdRW8wIzVnDNPS57/cfIgu8VBcyEeUIL1O/iSo1P40aqj2DEdvT+sRJdd8nBXKzW+qOONTKM1Qmx0XVbrCIzyGwLPlyIz343TEutf71Hd3nTAsT6zT91NWnvwhj7UqdvRqAvnuc0A9Vbt7U4TKKXuolC+5aRnYssUpaEvsjREktyo4c4TOfo9rTL3iWSzTAwkpdyOGKDJovv4TJJM7Lkl1xW0VvYOpdfoYegZOgQw8Qlk/7pb81OjRTxhvMoRsAdYYXo3G/vL/RMf+qa4ImQeh3D6STvKpJkjebc4im8phDyp6cfy73vokvDdypcs5POLwD7tBMH92YXgsSfkT1iHWf63tHKIeQWsVGpcvYLOTvNPVcqHuTnh8IzIQ1btRKCVEF1P68cC4eIomhNeNBsvoGeg09nxP4X5yI4TJDjxBwmI1pklpuGmxJVsRXoON5/Tp67YIf26dUppHy0tm2GcbukmHVEmsE9b83Z4B7BjCQFz6HtSv9Wx2x9adOS3uG3NFY4HKr/aTLHzHNKaxAHluh649x1 X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199021)(40470700004)(36840700001)(46966006)(5660300002)(54906003)(4326008)(110136005)(70586007)(6636002)(70206006)(8676002)(41300700001)(8936002)(1076003)(26005)(107886003)(316002)(6666004)(7696005)(478600001)(6286002)(186003)(16526019)(40460700003)(2616005)(336012)(426003)(2906002)(47076005)(83380400001)(36860700001)(7636003)(356005)(82740400003)(40480700001)(55016003)(86362001)(82310400005)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2023 03:15:47.3630 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1546b555-fe5f-4239-188c-08db5d978038 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9064 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 Sessions are used in symmetric transformations in order to prepare objects and data for packet processing stage. The AES-GCM session includes IV, AAD, digest(tag), DEK, operation mode information. Signed-off-by: Suanming Mou --- drivers/common/mlx5/mlx5_prm.h | 12 +++++++ drivers/crypto/mlx5/mlx5_crypto.h | 40 ++++++++++++++++++----- drivers/crypto/mlx5/mlx5_crypto_gcm.c | 47 +++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index b4446f56b9..3b26499a47 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -523,11 +523,23 @@ enum { MLX5_BLOCK_SIZE_4048B = 0x6, }; +enum { + MLX5_ENCRYPTION_TYPE_AES_GCM = 0x3, +}; + +enum { + MLX5_CRYPTO_OP_TYPE_ENCRYPTION = 0x0, + MLX5_CRYPTO_OP_TYPE_DECRYPTION = 0x1, +}; + #define MLX5_BSF_SIZE_OFFSET 30 #define MLX5_BSF_P_TYPE_OFFSET 24 #define MLX5_ENCRYPTION_ORDER_OFFSET 16 #define MLX5_BLOCK_SIZE_OFFSET 24 +#define MLX5_CRYPTO_MMO_TYPE_OFFSET 24 +#define MLX5_CRYPTO_MMO_OP_OFFSET 20 + struct mlx5_wqe_umr_bsf_seg { /* * bs_bpt_eo_es contains: diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index bb5a557a38..6cb4d4ddec 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.h +++ b/drivers/crypto/mlx5/mlx5_crypto.h @@ -72,16 +72,40 @@ struct mlx5_crypto_devarg_params { }; 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. - */ + union { + /**< AES-XTS configuration. */ + struct { + 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. + */ + }; + /**< AES-GCM configuration. */ + struct { + uint32_t mmo_ctrl; + /**< Crypto control fields with algo type and op type in big + * endian format. + */ + uint32_t wqe_aad_len; + /**< Crypto AAD length field in big endian format. */ + uint32_t wqe_tag_len; + /**< Crypto tag length field in big endian format. */ + uint16_t tag_len; + /**< AES-GCM crypto digest size in bytes. */ + uint16_t aad_len; + /**< The length of the additional authenticated data (AAD) in bytes. */ + uint32_t op_type; + /**< Operation type. */ + }; + }; uint32_t iv_offset:16; /**< Starting point for Initialisation Vector. */ + uint32_t iv_len; + /**< Initialisation Vector length. */ struct mlx5_crypto_dek *dek; /**< Pointer to dek struct. */ uint32_t dek_id; /**< DEK ID */ } __rte_packed; diff --git a/drivers/crypto/mlx5/mlx5_crypto_gcm.c b/drivers/crypto/mlx5/mlx5_crypto_gcm.c index 676bec6b18..6b6a3df57c 100644 --- a/drivers/crypto/mlx5/mlx5_crypto_gcm.c +++ b/drivers/crypto/mlx5/mlx5_crypto_gcm.c @@ -58,9 +58,56 @@ mlx5_crypto_dek_fill_gcm_attr(struct mlx5_crypto_dek *dek, return 0; } +static int +mlx5_crypto_sym_gcm_session_configure(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *session) +{ + struct mlx5_crypto_priv *priv = dev->data->dev_private; + struct mlx5_crypto_session *sess_private_data = CRYPTODEV_GET_SYM_SESS_PRIV(session); + struct rte_crypto_aead_xform *aead = &xform->aead; + uint32_t op_type; + + if (unlikely(xform->next != NULL)) { + DRV_LOG(ERR, "Xform next is not supported."); + return -ENOTSUP; + } + if (aead->algo != RTE_CRYPTO_AEAD_AES_GCM) { + DRV_LOG(ERR, "Only AES-GCM algorithm is supported."); + return -ENOTSUP; + } + if (aead->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) + op_type = MLX5_CRYPTO_OP_TYPE_ENCRYPTION; + else + op_type = MLX5_CRYPTO_OP_TYPE_DECRYPTION; + sess_private_data->op_type = op_type; + sess_private_data->mmo_ctrl = rte_cpu_to_be_32 + (op_type << MLX5_CRYPTO_MMO_OP_OFFSET | + MLX5_ENCRYPTION_TYPE_AES_GCM << MLX5_CRYPTO_MMO_TYPE_OFFSET); + sess_private_data->aad_len = aead->aad_length; + sess_private_data->tag_len = aead->digest_length; + sess_private_data->iv_offset = aead->iv.offset; + sess_private_data->iv_len = aead->iv.length; + sess_private_data->dek = mlx5_crypto_dek_prepare(priv, xform); + if (sess_private_data->dek == NULL) { + DRV_LOG(ERR, "Failed to prepare dek."); + return -ENOMEM; + } + sess_private_data->dek_id = + rte_cpu_to_be_32(sess_private_data->dek->obj->id & + 0xffffff); + DRV_LOG(DEBUG, "Session %p was configured.", sess_private_data); + return 0; +} + int mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv) { + struct rte_cryptodev *crypto_dev = priv->crypto_dev; + struct rte_cryptodev_ops *dev_ops = crypto_dev->dev_ops; + + /* Override AES-GCM specified ops. */ + dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure; priv->caps = mlx5_crypto_gcm_caps; return 0; } -- 2.25.1