From patchwork Tue Nov 5 18:41:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ananyev, Konstantin" X-Patchwork-Id: 62492 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B3ED0A04A2; Tue, 5 Nov 2019 19:42:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D16201BF86; Tue, 5 Nov 2019 19:42:16 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id C522C1BF85; Tue, 5 Nov 2019 19:42:14 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2019 10:42:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,271,1569308400"; d="scan'208";a="403454623" Received: from sivswdev08.ir.intel.com ([10.237.217.47]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2019 10:42:11 -0800 From: Konstantin Ananyev To: dev@dpdk.org, techboard@dpdk.org Cc: roy.fan.zhang@intel.com, declan.doherty@intel.com, akhil.goyal@nxp.com, Konstantin Ananyev Date: Tue, 5 Nov 2019 18:41:21 +0000 Message-Id: <20191105184122.15172-4-konstantin.ananyev@intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20191105184122.15172-1-konstantin.ananyev@intel.com> References: <20191105184122.15172-1-konstantin.ananyev@intel.com> Subject: [dpdk-dev] [RFC 3/4] cryptodev: introduce cpu-crypto API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" This patch extends rte_cryptodev API with CPU-CRYPTO mode. This is done by reusing existing rte_crypto_sym_session structure itself and related control-path cryptodev API (init/clear/get_size/etc.) For data-path new sym_cpu_ process() function is added into rte_cryptodev dev_ops. Crypto PMD that wants to support that functionality would need to: 1. claim RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO capability supported. 2. change at least the following functions inside rte_cryptodev_ops: . sym_session_get_size, . sym_session_configure, . sym_session_clear to accommodate support for both sync and async modes, 3. implement new function inside rte_cryptodev_ops: sym_cpu_process For data-path processing consumer of that API would have to maintain: struct rte_cryptodev_sym_session *sess, list of dev ids for which this session was properly initialized As an advantage of this approach - reuse of existing API and minimal visible changes for crypto PMDs. Signed-off-by: Konstantin Ananyev --- lib/librte_cryptodev/rte_crypto_sym.h | 11 ++++++++++- lib/librte_cryptodev/rte_cryptodev.c | 14 ++++++++++++++ lib/librte_cryptodev/rte_cryptodev.h | 24 ++++++++++++++++++++++++ lib/librte_cryptodev/rte_cryptodev_pmd.h | 22 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h index d8d9e9514..790c77524 100644 --- a/lib/librte_cryptodev/rte_crypto_sym.h +++ b/lib/librte_cryptodev/rte_crypto_sym.h @@ -166,6 +166,10 @@ struct rte_crypto_cipher_xform { * - Both keys must have the same size. **/ + /** + * CPU-CRYPTO specific data, should be set properly when + * (xform->type & RTE_CRYPTO_SYM_CPU_CRYPTO) != 0, otherwise ignored. + */ struct { /** * offset for cipher to start within user provided data buffer. @@ -415,6 +419,10 @@ struct rte_crypto_aead_xform { uint16_t length; /**< key length in bytes */ } __attribute__((__packed__)) key; + /** + * CPU-CRYPTO specific data, should be set properly when + * (xform->type & RTE_CRYPTO_SYM_CPU_CRYPTO) != 0, otherwise ignored. + */ struct { /** * offset for cipher to start within user provided data buffer. @@ -471,7 +479,8 @@ enum rte_crypto_sym_xform_type { RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */ RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */ RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */ - RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */ + RTE_CRYPTO_SYM_XFORM_AEAD, /**< AEAD xform */ + RTE_CRYPTO_SYM_CPU_CRYPTO = INT32_MIN, /**< xform for cpu-crypto */ }; /** diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 89aa2ed3e..b1dbaf4c1 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -1616,6 +1616,20 @@ rte_cryptodev_sym_session_get_user_data( return (void *)(sess->sess_data + sess->nb_drivers); } +__rte_experimental +int +rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id, + struct rte_cryptodev_sym_session *sess, struct rte_crypto_sym_vec *vec, + int32_t status[], uint32_t num) +{ + struct rte_cryptodev *dev; + + dev = rte_cryptodev_pmd_get_dev(dev_id); + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_cpu_process,-ENOTSUP); + + return dev->dev_ops->sym_cpu_process(dev, sess, vec, status, num); +} + /** Initialise rte_crypto_op mempool element */ static void rte_crypto_op_init(struct rte_mempool *mempool, diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index c6ffa3b35..24877006c 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -450,6 +450,8 @@ rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum, /**< Support encrypted-digest operations where digest is appended to data */ #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20) /**< Support asymmetric session-less operations */ +#define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO (1ULL << 21) +/**< Support symmeteric cpu-crypto processing */ /** @@ -1274,6 +1276,28 @@ void * rte_cryptodev_sym_session_get_user_data( struct rte_cryptodev_sym_session *sess); +/** + * Perform actual crypto processing (encrypt/digest or auth/decrypt) + * on user provided data. + * + * @param dev_id The device identifier. + * @param sess Cryptodev session structure + * @param vec Array of vectors for input data + * @param status Array of status values (one per vec) + * (RTE_CRYPTO_OP_STATUS_* values) + * @param num Number of elems in vec and status arrays. + * + * @return + * - Returns negative errno value on error, or non-negative number + * of successfully processed input vectors. + * +*/ +__rte_experimental +int +rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id, + struct rte_cryptodev_sym_session *sess, struct rte_crypto_sym_vec *vec, + int32_t status[], uint32_t num); + #ifdef __cplusplus } #endif diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index fba14f2fa..02e7a19ae 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -308,6 +308,26 @@ typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev, */ typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev, struct rte_cryptodev_asym_session *sess); +/** + * Perform actual crypto processing (encrypt/digest or auth/decrypt) + * on user provided data. + * + * @param dev Crypto device pointer + * @param sess Cryptodev session structure + * @param vec Array of vectors for input data + * @param status Array of status values (one per vec) + * (RTE_CRYPTO_OP_STATUS_* values) + * @param num Number of elems in vec and status arrays. + * + * @return + * - Returns negative errno value on error, or non-negative number + * of successfully processed input vectors. + * +*/ +typedef int (*cryptodev_sym_cpu_crypto_process_t)(struct rte_cryptodev *dev, + struct rte_cryptodev_sym_session *sess, struct rte_crypto_sym_vec *vec, + int32_t status[], uint32_t num); + /** Crypto device operations function pointer table */ struct rte_cryptodev_ops { @@ -342,6 +362,8 @@ struct rte_cryptodev_ops { /**< Clear a Crypto sessions private data. */ cryptodev_asym_free_session_t asym_session_clear; /**< Clear a Crypto sessions private data. */ + cryptodev_sym_cpu_crypto_process_t sym_cpu_process; + /**< process input data synchronously (cpu-crypto). */ };