From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0044.outbound.protection.outlook.com [104.47.36.44]) by dpdk.org (Postfix) with ESMTP id 5BE161CAF5 for ; Thu, 5 Apr 2018 13:26:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6p2POOoTLM61oD6g23Y1xEaNAokqqm33A8i4bffBEwo=; b=mshLLguR/m9jmFNduq/MjxExN35qWRe63hqH4mXHh7AQdAAF3rdyfumezT9THRnuhRWtfYW5ni25mo11HxGQ+S0Kk/VcWGODfDvBPfpDmKUr7ipzbg/DLXVzSkuuDvfrmy0yZ+x0NpbfIvei9W4y5owmjUlKWGPuomOsWPkX8fg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by CY4PR0701MB3634.namprd07.prod.outlook.com (2603:10b6:910:92::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Thu, 5 Apr 2018 11:26:03 +0000 From: Shally Verma To: pablo.de.lara.guarch@intel.com Cc: declan.doherty@intel.com, fiona.trahe@intel.com, pathreya@caviumnetworks.com, ssahu@caviumnetworks.com, agupta@caviumnetworks.com, dev@dpdk.org, Sunila Sahu , Ashish Gupta Date: Thu, 5 Apr 2018 16:54:45 +0530 Message-Id: <1522927489-23668-3-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1522927489-23668-1-git-send-email-shally.verma@caviumnetworks.com> References: <1522927489-23668-1-git-send-email-shally.verma@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BM1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::23) To CY4PR0701MB3634.namprd07.prod.outlook.com (2603:10b6:910:92::36) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9cebb30d-cbcf-4438-9fa8-08d59ae8060c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR0701MB3634; X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3634; 3:hvrNOb2hv6QLyDzqreRtPnbr3E6k5dwAs+djGkRZt1AqGTfNq89XYKSvdU9FqK7/n9PeCx6tgTgETp0tZQYcuQeAWVowQNtN//v1FB8k65sw60cuyC7V1ixJQ/kCxXSdh4g4a1ZHuVYkx+qQ1GjaOYHUsFtWYZ1sDhaq/u5tBmqzf11rpMsu4TkwiCLdZ1O3FQplVnJs28KWr9WVpNZNY3WaprpATmBWlYnkG1lJ0J91W53YfM6yMXRu8tuZFCwg; 25:n6M7nm5rDO8zvavRo6PKglP3q1YXOt3+5Lilqh7WsxyXeiuuT6u9N8OBN9xADtj5vZ8OYju3MsAcM3JMCY6kSj3RI3RHHZDMoWWC9lecCiYiSeuRLf0lPHqQIria8V1unCTajoY0zpcUmkB390J+fMvB1nAMKIzDJ+bDXlxeOIOm9vXJgio/rhrs+JBtl8DM9n3Jqg11euKOrL6dwtP4s4t/1g6tQ86SnHa3JXvb9XMWQx1NnGeMKMd6F/jGz2ddZC9u8SWwCt3LIjPS5J8UJkkAP15E5KrvSVE+CeJxTKSdIc6D4u5gYr3908i4kLKoZXWwzrcPIVGgyHrVfyCGFg==; 31:ldngNm3rJOeIFFtMvvbfUAW7jieEcaoJeJXmrSvLpZGqWjP52xL4JF1+9Q6ee6LCu9xMJLoUDfytiUwAhxkLfkjAtqMpq2Qxef7PbmY4frrGiG3RskuFQUGmqXEw7MN0gLmcND8gFXIneWVe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-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231221)(944501327)(52105095)(93006095)(10201501046)(6041310)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR0701MB3634; BCL:0; PCL:0; RULEID:; SRVR:CY4PR0701MB3634; X-Forefront-PRVS: 06339BAE63 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(366004)(376002)(396003)(39860400002)(199004)(189003)(72206003)(478600001)(59450400001)(106356001)(6116002)(47776003)(7736002)(6486002)(55236004)(386003)(561944003)(3846002)(4326008)(42882007)(66066001)(105586002)(486006)(2361001)(76176011)(6506007)(305945005)(25786009)(51416003)(16526019)(69596002)(5660300001)(186003)(2351001)(26005)(6916009)(36756003)(53416004)(6666003)(54906003)(48376002)(8936002)(52116002)(81156014)(476003)(8676002)(2616005)(956004)(11346002)(97736004)(446003)(68736007)(53936002)(6512007)(5890100001)(2906002)(316002)(107886003)(16586007)(50226002)(81166006)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR0701MB3634; H:hyd1sverma-dt.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR0701MB3634; 23:mDLWe36BlSUrtuvLxaQkBchkVaba2v7w2D1TfsC?= =?us-ascii?Q?p59mK8Eup60ky/rJNR/PJVbFZRGUy5dz2ByleJMmohdHx5I8slxVmQ4CZxFU?= =?us-ascii?Q?y8Q/FFoUky7ntK7OOBaklzdq1WXF4twPdsalMH71TZSzYi6viWNUHYmkiQvh?= =?us-ascii?Q?xj3UhPuX/NKua4vmbQy0o9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R4BKIoHMO8OxO3JzTPKfNSVkM5WZQFHZNvtPEX7AIvqZzTZk6jcPa8u7qY3dYtcJL+SLMt0WYkF6JKzrbcFHP6H6nkqghxCcNConEphcCNDIda9acA==; 5:rkRx55iBk0EcEl/1kdmE/dCitlYpbLQR4fn6AfV8DUs3mzgUZBYDAQ/rtiNoFoqA6y6opcSda676oc8L1owMNvr13ix9nvMMOiD3Nqg6dPO5p5OV2G6G2iMOUq1c8orge8AWXXSGguqzgH1PbaYoaqhFXe+YrqysQJ+4riAnWAM=; 24:6EBtCyReMJ9cizedPbR7Iuo2SBElqkgmOnC83fByCxRctSVXnR6BQKvoxcN1xJM3lD7j3y+5J+UaPdiH6T5xiPGbCUS3bi4EL7g4MUfwq3A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3634; 7:pcFkFs6+ZRwjVKuS32Ehwnf91hedNnnmmrNdtaST/9bKh02RElA9153i9mdWUcv4lq4bhqB67IeHtB7Y1Wj+M8Blc6LnIDJi9IPRPiUhL6kQYLdIHAs32wHdNynAZE59BHSvHeDz5YZsRsexDM2TrAbJbNZ+WJG73Oe0dd4MfyP0jjNxx8QMq+NFz0gHpv9b2kY/mz0Bg7HiobdqOSjQlrn8/TFdJoJcj0GMMsNdDu350ZyLGGS4x/crcSdMRg3F X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2018 11:26:03.9003 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cebb30d-cbcf-4438-9fa8-08d59ae8060c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3634 Subject: [dpdk-dev] [PATCH v2 2/6] lib/cryptodev: add asym op support in cryptodev 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: , X-List-Received-Date: Thu, 05 Apr 2018 11:26:09 -0000 Extend DPDK librte_cryptodev to: - define asym op type in rte_crypto_op_type and associated op pool create/alloc APIs - define asym session and associated session APIs If PMD shows in its feature flag that it supports both sym and asym then it must support those on all its qps. If PMD support both but internally has hw with dedicated qp for each service then it *can* split itself into *symmetric only and asymmetric only PMD instances*. List of TBDs: - change PMD ops session_get_size, session_configure, session_clear to sym_session_* APIs - change external get_session_private_size to sym_get_session_* - per-service stats update Open for consideration: - sessionless asymmetric ops. current proposal only define session based operations. Changes from PATCHv1 - resolve new line error in librte_cryptodev/rte_cryptodev_version.map Signed-off-by: Shally Verma Signed-off-by: Sunila Sahu Signed-off-by: Ashish Gupta --- User must apply patch "lib/cryptodev: add asymmetric algos in cryptodev" before compilation --- lib/librte_cryptodev/rte_crypto.h | 37 +++++++- lib/librte_cryptodev/rte_cryptodev.c | 122 ++++++++++++++++++++++++- lib/librte_cryptodev/rte_cryptodev.h | 81 +++++++++++++++- lib/librte_cryptodev/rte_cryptodev_pmd.h | 58 +++++++++++- lib/librte_cryptodev/rte_cryptodev_version.map | 12 +++ 5 files changed, 305 insertions(+), 5 deletions(-) diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h index 95cf861..0fdec1b 100644 --- a/lib/librte_cryptodev/rte_crypto.h +++ b/lib/librte_cryptodev/rte_crypto.h @@ -23,6 +23,7 @@ #include #include "rte_crypto_sym.h" +#include "rte_crypto_asym.h" /** Crypto operation types */ enum rte_crypto_op_type { @@ -30,6 +31,8 @@ enum rte_crypto_op_type { /**< Undefined operation type */ RTE_CRYPTO_OP_TYPE_SYMMETRIC, /**< Symmetric operation */ + RTE_CRYPTO_OP_TYPE_ASYMMETRIC + /**< Asymmetric operation */ }; /** Status of crypto operation */ @@ -97,6 +100,10 @@ struct rte_crypto_op { union { struct rte_crypto_sym_op sym[0]; /**< Symmetric operation parameters */ + + struct rte_crypto_asym_op asym[0]; + /**< Asymmetric operation parameters */ + }; /**< operation specific parameters */ }; @@ -117,6 +124,9 @@ struct rte_crypto_op { case RTE_CRYPTO_OP_TYPE_SYMMETRIC: __rte_crypto_sym_op_reset(op->sym); break; + case RTE_CRYPTO_OP_TYPE_ASYMMETRIC: + __rte_crypto_asym_op_reset(op->asym); + break; case RTE_CRYPTO_OP_TYPE_UNDEFINED: default: break; @@ -283,9 +293,14 @@ struct rte_crypto_op_pool_private { if (likely(op->mempool != NULL)) { priv_size = __rte_crypto_op_get_priv_data_size(op->mempool); - if (likely(priv_size >= size)) - return (void *)((uint8_t *)(op + 1) + + if (likely(priv_size >= size)) { + if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) + return (void *)((uint8_t *)(op + 1) + sizeof(struct rte_crypto_sym_op)); + if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) + return (void *)((uint8_t *)(op+1) + + sizeof(struct rte_crypto_asym_op)); + } } return NULL; @@ -388,6 +403,24 @@ struct rte_crypto_op_pool_private { return __rte_crypto_sym_op_attach_sym_session(op->sym, sess); } +/** + * Attach a asymmetric session to a crypto operation + * + * @param op crypto operation, must be of type asymmetric + * @param sess cryptodev session + */ +static inline int +rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, + struct rte_cryptodev_asym_session *sess) +{ + if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_ASYMMETRIC)) + return -1; + + op->sess_type = RTE_CRYPTO_OP_WITH_SESSION; + + return __rte_crypto_op_attach_asym_session(op->asym, sess); +} + #ifdef __cplusplus } #endif diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 8745b6b..cca8d4c 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -1088,13 +1088,62 @@ struct rte_cryptodev * return 0; } +int __rte_experimental +rte_cryptodev_asym_session_init(uint8_t dev_id, + struct rte_cryptodev_asym_session *sess, + struct rte_crypto_asym_xform *xforms, + struct rte_mempool *mp) +{ + struct rte_cryptodev *dev; + uint8_t index; + int ret; + + dev = rte_cryptodev_pmd_get_dev(dev_id); + + if (sess == NULL || xforms == NULL || dev == NULL) + return -EINVAL; + + index = dev->driver_id; + + if (sess->sess_private_data[index] == NULL) { + ret = dev->dev_ops->asym_session_configure(dev, + xforms, + sess, mp); + if (ret < 0) { + CDEV_LOG_ERR( + "dev_id %d failed to configure session details", + dev_id); + return ret; + } + } + + return 0; +} + struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(struct rte_mempool *mp) { struct rte_cryptodev_sym_session *sess; /* Allocate a session structure from the session pool */ - if (rte_mempool_get(mp, (void **)&sess)) { + if (rte_mempool_get(mp, (void *)&sess)) { + CDEV_LOG_ERR("couldn't get object from session mempool"); + return NULL; + } + + /* Clear device session pointer */ + memset(sess, 0, (sizeof(void *) * nb_drivers)); + + return sess; +} + +struct rte_cryptodev_asym_session * __rte_experimental +rte_cryptodev_asym_session_create(struct rte_mempool *mp) +{ + struct rte_cryptodev_asym_session *sess; + + /* Allocate a session structure from the session pool */ + if (rte_mempool_get(mp, (void *)&sess)) { CDEV_LOG_ERR("couldn't get object from session mempool"); return NULL; } @@ -1175,6 +1224,22 @@ struct rte_cryptodev_sym_session * return 0; } +int __rte_experimental +rte_cryptodev_asym_session_clear(uint8_t dev_id, + struct rte_cryptodev_asym_session *sess) +{ + struct rte_cryptodev *dev; + + dev = rte_cryptodev_pmd_get_dev(dev_id); + + if (dev == NULL || sess == NULL) + return -EINVAL; + + dev->dev_ops->asym_session_clear(dev, sess); + + return 0; +} + int rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess) { @@ -1199,6 +1264,31 @@ struct rte_cryptodev_sym_session * return 0; } +int __rte_experimental +rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess) +{ + uint8_t i; + void *sess_priv; + struct rte_mempool *sess_mp; + + if (sess == NULL) + return -EINVAL; + + /* Check that all device private data has been freed */ + for (i = 0; i < nb_drivers; i++) { + sess_priv = get_asym_session_private_data(sess, i); + if (sess_priv != NULL) + return -EBUSY; + } + + /* Return session to mempool */ + sess_mp = rte_mempool_from_obj(sess); + rte_mempool_put(sess_mp, sess); + + return 0; +} + + unsigned int rte_cryptodev_get_header_session_size(void) { @@ -1238,6 +1328,29 @@ struct rte_cryptodev_sym_session * } +unsigned int __rte_experimental +rte_cryptodev_get_asym_session_private_size(uint8_t dev_id) +{ + struct rte_cryptodev *dev; + unsigned int header_size = sizeof(void *) * nb_drivers; + unsigned int priv_sess_size; + + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) + return 0; + + dev = rte_cryptodev_pmd_get_dev(dev_id); + + if (*dev->dev_ops->asym_session_get_size == NULL) + return 0; + + priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev); + if (priv_sess_size < header_size) + return header_size; + + return priv_sess_size; + +} + /** Initialise rte_crypto_op mempool element */ static void rte_crypto_op_init(struct rte_mempool *mempool, @@ -1268,6 +1381,13 @@ struct rte_mempool * sizeof(struct rte_crypto_sym_op) + priv_size; + if (type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) { + /* override size by size of asym op */ + elt_size = sizeof(struct rte_crypto_op) + + sizeof(struct rte_crypto_asym_op) + + priv_size; + } + /* lookup mempool in case already allocated */ struct rte_mempool *mp = rte_mempool_lookup(name); diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index c8fa689..68d1ae1 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -897,9 +897,14 @@ struct rte_cryptodev_data { */ struct rte_cryptodev_sym_session { __extension__ void *sess_private_data[0]; - /**< Private session material */ + /**< Private symmetric session material */ }; +/** Cryptodev asymmetric crypto session */ +struct rte_cryptodev_asym_session { + __extension__ void *sess_private_data[0]; + /**< Private asymmetric session material */ +}; /** * Create symmetric crypto session header (generic with no private data) @@ -914,6 +919,18 @@ struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(struct rte_mempool *mempool); /** + * Create asymmetric crypto session header (generic with no private data) + * + * @param mempool mempool to allocate asymmetric session + * objects from + * @return + * - On success return pointer to asym-session + * - On failure returns NULL + */ +struct rte_cryptodev_asym_session * __rte_experimental +rte_cryptodev_asym_session_create(struct rte_mempool *mempool); + +/** * Frees symmetric crypto session header, after checking that all * the device private data has been freed, returning it * to its original mempool. @@ -929,6 +946,21 @@ struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess); /** + * Frees asymmetric crypto session header, after checking that all + * the device private data has been freed, returning it + * to its original mempool. + * + * @param sess Session header to be freed. + * + * @return + * - 0 if successful. + * - -EINVAL if session is NULL. + * - -EBUSY if not all device private data has been freed. + */ +int __rte_experimental +rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess); + +/** * Fill out private data for the device id, based on its device type. * * @param dev_id ID of device that we want the session to be used on @@ -950,6 +982,27 @@ struct rte_cryptodev_sym_session * struct rte_mempool *mempool); /** + * Initialize asymmetric session on a device with specific asymmetric xform + * + * @param dev_id ID of device that we want the session to be used on + * @param sess Session to be set up on a device + * @param xforms Asymmetric crypto transform operations to apply on flow + * processed with this session + * @param mempool Mempool to be used for internal allocation. + * + * @return + * - On success, zero. + * - -EINVAL if input parameters are invalid. + * - -ENOTSUP if crypto device does not support the crypto transform. + * - -ENOMEM if the private session could not be allocated. + */ +int __rte_experimental +rte_cryptodev_asym_session_init(uint8_t dev_id, + struct rte_cryptodev_asym_session *sess, + struct rte_crypto_asym_xform *xforms, + struct rte_mempool *mempool); + +/** * Frees private data for the device id, based on its device type, * returning it to its mempool. * @@ -965,6 +1018,20 @@ struct rte_cryptodev_sym_session * struct rte_cryptodev_sym_session *sess); /** + * Frees resources held by asymmetric session during rte_cryptodev_session_init + * + * @param dev_id ID of device that uses the asymmetric session. + * @param sess Asymmetric session setup on device using + * rte_cryptodev_session_init + * @return + * - 0 if successful. + * - -EINVAL if device is invalid or session is NULL. + */ +int __rte_experimental +rte_cryptodev_asym_session_clear(uint8_t dev_id, + struct rte_cryptodev_asym_session *sess); + +/** * Get the size of the header session, for all registered drivers. * * @return @@ -984,6 +1051,18 @@ struct rte_cryptodev_sym_session * */ unsigned int rte_cryptodev_get_private_session_size(uint8_t dev_id); +/** + * Get the size of the private data for asymmetric session + * on device + * + * @param dev_id The device identifier. + * + * @return + * - Size of the asymmetric private data, if successful + * - 0 if device is invalid or does not have private session + */ +unsigned int __rte_experimental +rte_cryptodev_get_asym_session_private_size(uint8_t dev_id); /** * Attach queue pair with sym session. diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index 69d7769..615a225 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -302,6 +302,17 @@ typedef int (*cryptodev_sym_create_session_pool_t)( */ typedef unsigned (*cryptodev_sym_get_session_private_size_t)( struct rte_cryptodev *dev); +/** + * Get the size of a asymmetric cryptodev session + * + * @param dev Crypto device pointer + * + * @return + * - On success returns the size of the session structure for device + * - On failure returns 0 + */ +typedef unsigned int (*cryptodev_asym_get_session_private_size_t)( + struct rte_cryptodev *dev); /** * Configure a Crypto session on a device. @@ -321,7 +332,24 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, struct rte_cryptodev_sym_session *session, struct rte_mempool *mp); - +/** + * Configure a Crypto asymmetric session on a device. + * + * @param dev Crypto device pointer + * @param xform Single or chain of crypto xforms + * @param priv_sess Pointer to cryptodev's private session structure + * @param mp Mempool where the private session is allocated + * + * @return + * - Returns 0 if private session structure have been created successfully. + * - Returns -EINVAL if input parameters are invalid. + * - Returns -ENOTSUP if crypto device does not support the crypto transform. + * - Returns -ENOMEM if the private session could not be allocated. + */ +typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev, + struct rte_crypto_asym_xform *xform, + struct rte_cryptodev_asym_session *session, + struct rte_mempool *mp); /** * Free driver private session data. * @@ -332,6 +360,15 @@ typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess); /** + * Free asymmetric session private data. + * + * @param dev Crypto device pointer + * @param sess Cryptodev session structure + */ +typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev, + struct rte_cryptodev_asym_session *sess); + +/** * Optional API for drivers to attach sessions with queue pair. * @param dev Crypto device pointer * @param qp_id queue pair id for attaching session @@ -384,10 +421,16 @@ struct rte_cryptodev_ops { cryptodev_sym_get_session_private_size_t session_get_size; /**< Return private session. */ + cryptodev_asym_get_session_private_size_t asym_session_get_size; + /**< Return asym session private size. */ cryptodev_sym_configure_session_t session_configure; /**< Configure a Crypto session. */ + cryptodev_asym_configure_session_t asym_session_configure; + /**< Configure asymmetric Crypto session. */ cryptodev_sym_free_session_t session_clear; /**< Clear a Crypto sessions private data. */ + cryptodev_asym_free_session_t asym_session_clear; + /**< Clear a Crypto sessions private data. */ cryptodev_sym_queue_pair_attach_session_t qp_attach_session; /**< Attach session to queue pair. */ cryptodev_sym_queue_pair_detach_session_t qp_detach_session; @@ -535,6 +578,19 @@ uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv, sess->sess_private_data[driver_id] = private_data; } +static inline void * +get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess, + uint8_t driver_id) { + return sess->sess_private_data[driver_id]; +} + +static inline void +set_asym_session_private_data(struct rte_cryptodev_asym_session *sess, + uint8_t driver_id, void *private_data) +{ + sess->sess_private_data[driver_id] = private_data; +} + #ifdef __cplusplus } #endif diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map b/lib/librte_cryptodev/rte_cryptodev_version.map index eb47308..41c6798 100644 --- a/lib/librte_cryptodev/rte_cryptodev_version.map +++ b/lib/librte_cryptodev/rte_cryptodev_version.map @@ -85,3 +85,15 @@ DPDK_17.11 { rte_cryptodev_pmd_parse_input_args; } DPDK_17.08; + +EXPERIMENTAL { + global: + + rte_cryptodev_asym_session_clear; + rte_cryptodev_asym_session_create; + rte_cryptodev_asym_session_free; + rte_cryptodev_asym_session_init; + rte_cryptodev_get_asym_session_private_size; + + local: *; +}; -- 1.9.1