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 4E2F5A0547; Thu, 29 Apr 2021 17:47:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 68E2B41341; Thu, 29 Apr 2021 17:47:53 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.66]) by mails.dpdk.org (Postfix) with ESMTP id 0AC0241341 for ; Thu, 29 Apr 2021 17:47:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DIdDzIChhsjtSszZQCAvtI9RirVe4EXphpIZRGIygYBjAUjd0eYUTC4SelW8YsoyxfqB+XLoxaJQP2pm/x4/jmxdQ98IxaIj3US7AMKJh+kos/LxDYQj1k5zDLPXHv0ZUpu9zEwjcQCkeOKRWPdn3+Bw3rXJkMofPoTmIQ2fMBnjJULcUvdlCYVjaX6W/6+L57M9VZvABarVx/JRpx/kBWxKARdAdt2cRroSj3QvAG744aFxdCHPycYkLcnY8aRU6JOZkh5RYu3YGPBfeNRo9o4OBcHPipP5jL6k+yUnaQKmOnRCyBQrLwGeWgftffwnnV3vlfiYhzi+ODc+qOJEVQ== 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=Fvn7Nk55eKs/4ju4wUcGAeGdJU9UCC9t0t8A4X3A02Y=; b=S+RvcHrCqlav3tbsH6NLd8KqqHmouTEfpK+WxkwTOFTUMA7/EG4bMqQ7QUxJPXpnPFY7ARe4CKklXO7yeVrTdx6R8vZTNKzNfQeipc+XEYpP4zA36hiZEK2hyNzxBIowMWnlmUCjMyUCW3Wa/HOySQ7WmRh60XHBSO21PW+nTD93sQtJGFsAN7nTHAmw1LCY3KKZSIAXFo6t3h90VF6twCkDU5MTk/ooREswdSUmE1AyxcrjeR8f2EdWNQFbh4b+AQcZjMTL8JZ5ZMCfFei1hRaV636JSCBdtibV+C6czTipASzYnGC1fZYp7B1j1RZkSvKwAidm2erfu3hOZ7W5iA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=marvell.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fvn7Nk55eKs/4ju4wUcGAeGdJU9UCC9t0t8A4X3A02Y=; b=Inxef5++xcXa+gLo+six2xvaEw64Niq1A2kG/9XhTr89Inbxw9knRGpoYtKNztR0Uqmvinu8EIbRHmeVXOl+kJUKeWmd37K5eC+PlkDMKEYP1loeLktQFVkPJzxBV/Yo7bDTfILpqYMXBvdxvfncFfk8GlJOlX5HUtbyBfqPX+EAi7Ii1CVie3gi6yfGkXhWY2EUTnepuw4Gy3keKTz32ShZTxYkELntW394xzT724oERmrj6oAyjjM1Z/55CLvg/X0BSJcT+J3aIf0NJjYcswsjvp4Kjs6LVFqOk3aYReiBh03R9R8uiZG1eAMRQjepxXlylH9k+szvgb2VRLBmyA== Received: from DM5PR21CA0001.namprd21.prod.outlook.com (2603:10b6:3:ac::11) by MN2PR12MB4093.namprd12.prod.outlook.com (2603:10b6:208:198::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Thu, 29 Apr 2021 15:47:50 +0000 Received: from DM6NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ac:cafe::36) by DM5PR21CA0001.outlook.office365.com (2603:10b6:3:ac::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.2 via Frontend Transport; Thu, 29 Apr 2021 15:47:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT065.mail.protection.outlook.com (10.13.172.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4087.27 via Frontend Transport; Thu, 29 Apr 2021 15:47:50 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 29 Apr 2021 15:47:48 +0000 From: Matan Azrad To: CC: , , , "Shiri Kuzin" Date: Thu, 29 Apr 2021 18:47:00 +0300 Message-ID: <20210429154712.2820159-4-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210429154712.2820159-1-matan@nvidia.com> References: <20210408204849.9543-1-shirik@nvidia.com> <20210429154712.2820159-1-matan@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d7a3bf5e-6dff-49cb-abe4-08d90b2624e4 X-MS-TrafficTypeDiagnostic: MN2PR12MB4093: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AOj+hlxFncdJr8ve4E4e1mXVJpp8VTnMaOfA4JwJwLmqEcdvk54RphU4RXwX/b4ZGDL+sJ9SXzlo7g4rDnsL9GQc1Q0ga6ZbYmeP9mmbQAxp4KhxwoO03CJGsIwbGOdESpn334JmqLE0BGrN4hskmEfmIfdbIqh32VPveOArpT7xUp6mMJVivCqeHoOoXViPA9TLvpp7N8yq3nEOXU8oqTUMOeGa2pZ0cHqCNJYbf0rAAZkoe/E86B8DjKTqz26+QOlGrxlPFtc00o4OGyhDFWiRsfruzuKtgEymZUD75tspwPZsP8X6G7Qwp/CcZQfffBGrKL9HYUgkRPyqpqRZfUYcT39aoXmonrdoYVS9dskW7/Y/x4TBE97fXTWct6iVCd1J3hEF1dfufBmbopVM0CeI/7N7TjTybT6y8pmF9N/FAFtukZuVDV+FbRmdsFKP0Fn5/V/l63Ch+FwijfN3x6oCQ7JBlkKMgRREmFqbVpPvfiIujulH4cInUeRLaGWl40Mft1DqXWp8Bfrz8Et1X8caWk0/ns/LBlFyqPyVFz2M1Bi5M32j8B0Ov8tFQ5hdDAdfiKloBcWtR+7jCmYeZGvBLuxfWIq9RI8ivym+h4SU31ICAlLXeEE4uc6KwqNPcgRCqBg27KqEwHxmuFa0jLOVai8TsV2mYUUp3UgdLxo= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(346002)(39860400002)(136003)(396003)(46966006)(36840700001)(82740400003)(55016002)(316002)(1076003)(54906003)(2616005)(6666004)(426003)(36906005)(8676002)(16526019)(4326008)(107886003)(6286002)(2906002)(83380400001)(70586007)(8936002)(336012)(356005)(6916009)(26005)(5660300002)(7696005)(86362001)(36860700001)(478600001)(70206006)(47076005)(7636003)(36756003)(186003)(82310400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2021 15:47:50.4265 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d7a3bf5e-6dff-49cb-abe4-08d90b2624e4 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: DM6NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4093 Subject: [dpdk-dev] [PATCH v2 03/15] crypto/mlx5: support 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, 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 | 96 ++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index e7c70c521f..c494ed00d1 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,24 @@ 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 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 +77,77 @@ 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); + 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 *sess_private_data = + get_sym_session_private_data(sess, dev->driver_id); + + if (unlikely(sess_private_data == NULL)) { + DRV_LOG(ERR, "Failed to get session %p private data.", + sess_private_data); + return; + } + mlx5_crypto_dek_destroy(priv, sess_private_data->dek); + DRV_LOG(DEBUG, "Session %p was cleared.", sess_private_data); +} + static struct rte_cryptodev_ops mlx5_crypto_ops = { .dev_configure = mlx5_crypto_dev_configure, .dev_start = NULL, @@ -68,9 +158,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