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 5EDE24297B; Tue, 18 Apr 2023 11:24:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CEFD842D13; Tue, 18 Apr 2023 11:24:05 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) by mails.dpdk.org (Postfix) with ESMTP id 94EB642D0E for ; Tue, 18 Apr 2023 11:24:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nZ274HeIQGXI2e56ZRcyUsqzwsChKt3vmLcM2ktocDmku1Ka0BWagmTMXPxBL62mskH6TI40P1kzG/yXQ0s3L9mcJiYynZeGs7e/nZVBYwOxxyael65MYHRiFYRKm+X0GQLu/1q9wYra9lgxN/marzOFZsQcX3bs7GriX4XfNLunzGm3ISDCiagHP0x0nDUEScyfyA5RycL4t8IId60DOdEvcinuyh4Kr0AS7og0QGmu5gNmhOmdfB56Mos7R/q0z1sKinpuPLo5OMg2QyzSL/mp11wsYM5R4g/yik/N7NXqY0Jw1QmutQUD/ET0zGUT/6ObpeueWPbZfKSrxzCxIQ== 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=ri9x2S+IfjlRJppSDgvTi76s2MAEVKhz8d9ssiKmVCM=; b=UTEQFegXefb8fnktbEQBMP/RH/Lt8f4auyhDUGDrDiRjup/lPjTtaK4gemho+7tgGOLUBQGh6pf2KN+L/tggtU4vHS1GUOoq7KCOGtjS/Y7QDq7GUEPXPd+OV4uJzdGaCjdGFMHtMEYnNavUI7keTMLilP1dHlNeY8SE1sPRuqooAOW2vzSd/g5VaR+NVPreXTRoAhwv58X5tlxm0Z74oJ04NnH8ffhrW0eM8X+XtV7q8hPeV+bYegNKH2pE6cpVgBaC8+xqeXZ0KMwmZQdd5/8ckTI4M+QYKj0fSyremYnVldC4wiJIpA8i/nXmoRwnzIVLxUYV3hKbUENh5QNYig== 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=ri9x2S+IfjlRJppSDgvTi76s2MAEVKhz8d9ssiKmVCM=; b=J4sehTatYim+Elg+QXufz0tC4Ei3XBm/KwOX6kI0FSuzp9FS9YZjhEHvDIFlRbRgmoc1UvMRW62vWXwhe8ADom8T6WYiXZOw/lyPuVVzevhoeWNbYjbNLA8mgnlRpAcKEJz9LngO01hy7t1yNVxjqwuEIln5T7e8PzFlQRjsD9RkQzg/hnEb2vIDITmmM1k/qdsSr5qm0yg1E17p2miqhp5S1yc4RTqGiRuhA1L/wJCMjJG8IzJkOkul428wGl6YoQrRcY5kpFCQkKv0cJMGmAitGvafPaN2pHhkWex3vnPcM6jtSgHOvtdgmWtptZiZhPWrK4vgrUrG9v+CCe1ilw== Received: from MW4PR04CA0256.namprd04.prod.outlook.com (2603:10b6:303:88::21) by DM4PR12MB5867.namprd12.prod.outlook.com (2603:10b6:8:66::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Tue, 18 Apr 2023 09:24:01 +0000 Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::d7) by MW4PR04CA0256.outlook.office365.com (2603:10b6:303:88::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.47 via Frontend Transport; Tue, 18 Apr 2023 09:24:01 +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 CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20 via Frontend Transport; Tue, 18 Apr 2023 09:24:01 +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; Tue, 18 Apr 2023 02:23:52 -0700 Received: from nvidia.com (10.126.230.37) 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; Tue, 18 Apr 2023 02:23:50 -0700 From: Suanming Mou To: CC: , , Subject: [RFC PATCH 3/5] crypto/mlx5: add AES-GCM session configure Date: Tue, 18 Apr 2023 12:23:23 +0300 Message-ID: <20230418092325.2578712-4-suanmingm@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418092325.2578712-1-suanmingm@nvidia.com> References: <20230418092325.2578712-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|DM4PR12MB5867:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d68cf0e-8689-4eda-061d-08db3feea566 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ln7hI/CySQtyVqYbTrR1v9IElbWI/64Tr+6YtxpCISc5fNEsbPliakDGcL4wriimSieeNjsjGjHCd0ChxXiZL2QFFoBZBikS4vKrKU2tBIPhDyx8amKdy6B78RAC6uN09SPRZ0vTxHbyAAvPExtkU5TNft62UPamataid/I9eo5wmD8BWILgtrTnh54ELZDb3q3DS/+J4W2VmWDrsO53lYPootNI1RRe832a+A5UkMm5vtIV8BReqUzqwkIEAhF0g8bKQY2VH+mtDS4YkFPOAT22lYRx+9DTxjKnq1YXaJIKK+41BnNSRrsqj+QhHeGp/Fbip164iIELXuYysPL/vHJxsrtI/YJfK2PH+U3vj4YY4sXYq8FR8X0/tf0zqQhvrY9ZT6ifuUkhJ/1zpjlHac2smas1wY36RLK+98h+ELmQlJtGu2eYc+oAthWEI/5QLOutGOpssHSGD6rctZvLxUJsMGikEMuPE/m+RUkHJlsGef2JmbN/J5wzQOw488euNNcKyDyrN0gBPR41JWhcnX8mgEOFC9SN9RWEqDV0v02uNgKHsE8K4jp7I0xX38lVkMCU+bellJ79zXTp6le+TMRwbUEM/ZdPVIDJktr0MtPSFgIFXPkzfwkb9zKgc4M5jbF7Oyz4Aw3qeOjxAbq69pOiY8RJHrNj2DkPXOeEL58swUhiY/emLVBBTVmXL37h78Ww29wMfNdNrcCh2o4EmhEo3LmBd5+CfvPtb5s3ksVd4fdPac4oKSAimxwthZOshfEjc6GWtpeH7E3cpAe5tl1j4Cx8Zyx3QX26r7zWolo= 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)(136003)(39860400002)(396003)(346002)(376002)(451199021)(46966006)(40470700004)(36840700001)(40480700001)(55016003)(82310400005)(4326008)(2616005)(40460700003)(16526019)(6286002)(186003)(41300700001)(36860700001)(426003)(336012)(47076005)(83380400001)(7696005)(6666004)(6636002)(37006003)(316002)(54906003)(478600001)(1076003)(26005)(70206006)(70586007)(7636003)(356005)(82740400003)(86362001)(36756003)(6862004)(8676002)(8936002)(34020700004)(2906002)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2023 09:24:01.1812 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d68cf0e-8689-4eda-061d-08db3feea566 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: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5867 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.c | 15 --------- drivers/crypto/mlx5/mlx5_crypto.h | 35 ++++++++++++++++++++ drivers/crypto/mlx5/mlx5_crypto_gcm.c | 46 +++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 15 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index 9728be24dd..25ff66ee7e 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -528,11 +528,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.c b/drivers/crypto/mlx5/mlx5_crypto.c index 66c9f94346..8946f13e5e 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -83,21 +83,6 @@ 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 void mlx5_crypto_dev_infos_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *dev_info) diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index 11352f9409..c34a860404 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.h +++ b/drivers/crypto/mlx5/mlx5_crypto.h @@ -73,6 +73,41 @@ struct mlx5_crypto_devarg_params { uint32_t is_aes_gcm:1; }; +struct mlx5_crypto_session { + 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. + */ + 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; + int mlx5_crypto_dek_destroy(struct mlx5_crypto_priv *priv, struct mlx5_crypto_dek *dek); diff --git a/drivers/crypto/mlx5/mlx5_crypto_gcm.c b/drivers/crypto/mlx5/mlx5_crypto_gcm.c index c7fd86d7b9..6c2c759fba 100644 --- a/drivers/crypto/mlx5/mlx5_crypto_gcm.c +++ b/drivers/crypto/mlx5/mlx5_crypto_gcm.c @@ -81,12 +81,58 @@ mlx5_crypto_generate_gcm_cap(struct mlx5_hca_crypto_mmo_attr *mmo_attr, 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 mlx5_common_device *cdev = priv->cdev; + struct rte_cryptodev *crypto_dev = priv->crypto_dev; + struct rte_cryptodev_ops *dev_ops = crypto_dev->dev_ops; int ret; + /* Override AES-GCM specified ops. */ + dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure; /* Generate GCM capability. */ ret = mlx5_crypto_generate_gcm_cap(&cdev->config.hca_attr.crypto_mmo, mlx5_crypto_gcm_caps); -- 2.25.1