From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0053.outbound.protection.outlook.com [104.47.40.53]) by dpdk.org (Postfix) with ESMTP id 584331B68A for ; Wed, 16 May 2018 08:06:02 +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:X-MS-Exchange-SenderADCheck; bh=fPxAHbhT2lYpWot/mnUbPgbl9F6Wd1XnrL4FyijVdhM=; b=Uj/rYBhC0x/IJf5hepBZlUZF2VWb+Q7kJOJVHgbtto8R9sqqW5Q44jqh+YAyPwJBGyNZFqKbVchd16fNzIOUWrVznBfyYwtu+fMCRCZKHrDz5BkuIzM+487qxE3eCNjDTS+oQK6+jnajiIkAxgCzJ4+yDBNZpMWnjkB4rXOIHUM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by DM5PR0701MB3637.namprd07.prod.outlook.com (2603:10b6:4:7d::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Wed, 16 May 2018 06:05:58 +0000 From: Shally Verma To: pablo.de.lara.guarch@intel.com Cc: fiona.trahe@intel.com, akhil.goyal@nxp.com, dev@dpdk.org, pathreya@caviumnetworks.com, Sunila Sahu , Ashish Gupta Date: Wed, 16 May 2018 11:35:09 +0530 Message-Id: <1526450713-17299-3-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526450713-17299-1-git-send-email-shally.verma@caviumnetworks.com> References: <1526450713-17299-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: PN1PR0101CA0047.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:c::33) To DM5PR0701MB3637.namprd07.prod.outlook.com (2603:10b6:4:7d::38) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DM5PR0701MB3637; X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3637; 3:wzlShP8x23QR/AxOKp2B8UJC2EnGC/pei/7qori+E1R7wQD2xPBGc+aKgv3VynLr+MqevFrzAQr1Y5ou7iTXiRP+j2J8R4uXKt/9MT+3OaaEkn6uq1INPEkbqdwMHaL2olbcDbqxjoMwAQri04sEpoKyj6uBKqtvZ08JYzIQpJlfn3OmiDSshchrEvSQYvI+9V3spnKZVofT4h7cWlhlcGI3nuo4m21kCAVZHTllb6lpjhFSUX7wE0/fq6S86jXq; 25:RNsmZTkVD3iAh7GN3LB1swpAm/R6AFgEAjSbqqUM1yeSUcOB4bJkQpNJ6aCqcREfyYP2BrfJtB1ZFQoiCxM/WICtR0To0+rXlnAGH4f0NOpWw+SZqJjaM7OvXetYDrJkevAE3nUW35yy8G67wUd9wHyDASYdDsKbJm1L8AqAEAWsLE1AeNuQzaLt1+WtrKfq8TdEC0VuZ5b7UNcfHI2uH96WbF/grW7oXpnHfB9YCXz6Pg+pNd/CRBNZwM1x1zcF/mnkEL/pw0ceYsx3ARNcRV2QW0yCgi5m7qrAaL1W0iVdZ6L85PvWXblmRyeGtyj8KiPXYs4ZZPeg2Em1k2kTMw==; 31:kOrGE6puDfghsFiJ11UryjY6UM4+dChsqbYUH+dJZsKqAMMFImMYhbKwK8B+7AIYfNbIXpyRHd+q3UI97CwGqDDE0KBfwWNLmI4pQZKmG+otuZMIJBaBJCEf7/X76BHWZJ3exoBDnFzToAnnO+dyLzWYOD8oShTblfwn5fuYUEftuZncswltk3pDC7l+jv+6FY+57PT06tkmIdvOCbIYsIp2hkkjSrZ7UGdd78Li/Rs= X-MS-TrafficTypeDiagnostic: DM5PR0701MB3637: X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3637; 20:k3z+qJkVwI1ftLfIUMaDhRAYQXQVmJU+rwFp2VnHOs+Hd2QXlFsLjsP8D337nIP+Y8EL5O6U+yA3WhHgveopLx8khaJXZSyXzT1MGBZBG6YnBmTza2114D553fvngsdSS4UEUzlusoQ9ODJut/uSU8jkzLnW1A5dYAjDt9eerQ4irg6SQPrwdBkHWGjOa17U+LJXzeiTReXat9nJN8TTEE4q2jIdSpxnP8h48jACdlA/E6q+JiDyvtiIyx62Bo7W+CVsWwVtM7zONhMs2lAP/FPyPESrJcGo+2EH9qJQ0P9+6nTc/jXdabXh2QGNIvdWysD4Hl3uXaVK7EyGU8EkiZhoEzf05dvjXDFUBciuHyqpJIrzWOIWm+UP75GhF9ToB5KPKrY5jRjPiMxPqoDnfoeLPypa6yqgQ1c64Y0CEdWexzRQfubcvD6UKElWdp3xDJZwjDAKC8CW9iKQ9IVKgNEfjuI3xUngeoKLcnya5yhAEmBDW4pLaOMjulDq27ax+5PZIf6B8JptnrIqeg7BC2imzO601o7frSyg5MkuUyePKkhT8M1ZOSc8/uxFh/1RcSJfsZPMT/+xHTAavOBPGoQMyQmwaqRLLMjzL28YNf4=; 4:UCxaW0E2b21Cdxn/CvUjRzqUK5KRcsQQdqcgsCwIe68nxUgg240r6RtE/uD5ykP4f5mXU79/QppjrckqdEbCvnCdc6/6Wf4C3I3HTA26CRbBy6sYkucOxwTcOkowa0MPM42GIkurZsgaG27DH+WQS7y/u32C7j3FRPTsnpY+DbRU46GxMwaU07wuiNhNVzbPSxFxj18xKKLWjr84sx6zYBX7S60c0X6hRV9H8pEYD4uyeBfNduraofVinRT3kEAfKdvsL190cQyMc2fDV1lj4w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:DM5PR0701MB3637; BCL:0; PCL:0; RULEID:; SRVR:DM5PR0701MB3637; X-Forefront-PRVS: 0674DC6DD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(396003)(39380400002)(366004)(39860400002)(189003)(199004)(76176011)(6486002)(7736002)(305945005)(42882007)(106356001)(105586002)(3846002)(6116002)(8656006)(53416004)(6666003)(47776003)(2351001)(2361001)(59450400001)(66066001)(6506007)(386003)(6512007)(55236004)(16526019)(8676002)(54906003)(51416003)(52116002)(50226002)(186003)(69596002)(81166006)(16586007)(316002)(26005)(6916009)(81156014)(107886003)(5660300001)(8936002)(53936002)(36756003)(48376002)(50466002)(25786009)(478600001)(956004)(72206003)(5890100001)(97736004)(476003)(11346002)(446003)(486006)(4326008)(2906002)(44832011)(68736007)(2616005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR0701MB3637; H:hyd1sverma-dt.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR0701MB3637; 23:sxB6EQPtnEVjXbMvnuTqPYkiakEhD138JQTtP4n?= =?us-ascii?Q?1jbsqYETbiQrLR3uELmZBdsciY03m3UvJvhlP1pSrMHF1f48Fg6gLoLJ51ZD?= =?us-ascii?Q?srmsa9vY4fOUgT7Uno0hmuhLoMRfWMnawW5Eq55Od9+rlSnXde4n64A6Dm5Y?= =?us-ascii?Q?otzi5jvvc9F12FJc7xfnd+ehuohYGwoF5Tm8UdH4F134hkBRmCtJOhidMY52?= =?us-ascii?Q?u1G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8bPXiPhjS4o0ptklYlxhm1t65bKGay27EoD268/my82tSGbFdW7oz7PC4+6TjndIThbfmRqXFRiiQtZDw==; 5:JrOGfgJoTBjdrshcBCdRZZWIywXxuQzxi6NzHLSBsHYtiVRsmoBMnihfG0IqSyOicp7hNJVaEIGYvf6sOJlDBtx0qU1j0PJRxMKBDJR+F2MvE5ZRltLuj0Jv0qsVntkqygGP1AfHjEVNK1M8iqm1nEzhOpUiTvhTw0Tu0Jx025g=; 24:OKMQFdzuIhgZHwoyUBzDL7+g/003IdAKKyCDn02+HR0l9vksQ5lmRWF0qdPlRcE7tKf2YcDE5rHdUYSSZAea1vThSULTvxknho1LzOGTUD8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3637; 7:M9xUMKGUfNUFNO/nrYT5aiQcqJZE096LVXsXLxoKl20EiNdbjOo/aNAphBA6nd9ZGwRhjcUn85Wtp7n6f+UiKfIts35ISe0Axl462t/u3Y6e4KzcwIjcE+5jcDT4d83Ce5RYBaauM8D4RQhfmdleIyDpic3TwVCsJ4/Ejj6stHJ6RoUzwh5O8B9jzOKTnjFLFtuS1TEMn44neWCaWqsZwC9p9mlcieGUud7lh8Cuu5UU0NqC+CiX0ACjgUj0RyNE X-MS-Office365-Filtering-Correlation-Id: dd8622b6-899a-48f7-a46c-08d5baf3196e X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2018 06:05:58.4449 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd8622b6-899a-48f7-a46c-08d5baf3196e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0701MB3637 Subject: [dpdk-dev] [PATCH v3 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: Wed, 16 May 2018 06:06:03 -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. Changes from v2: - added rte_cryptodev_asym_session_set/get_private_data for app to setup private data in a session as per latest dpdk-next-crypto spec - rename rte_cryptodev_get_asym_session_private_size to be consistent with other API names - correct rte_cryptodev_asym_session_create to pass void** to rte_mempool_get() and add for private_data_size flag Changes from v1 - 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 --- lib/librte_cryptodev/rte_crypto.h | 37 ++++- lib/librte_cryptodev/rte_cryptodev.c | 180 +++++++++++++++++++++++++ lib/librte_cryptodev/rte_cryptodev.h | 114 +++++++++++++++- lib/librte_cryptodev/rte_cryptodev_pmd.h | 58 +++++++- lib/librte_cryptodev/rte_cryptodev_version.map | 7 + 5 files changed, 392 insertions(+), 4 deletions(-) diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h index 25404264b..ef9820e55 100644 --- a/lib/librte_cryptodev/rte_crypto.h +++ b/lib/librte_cryptodev/rte_crypto.h @@ -23,6 +23,7 @@ extern "C" { #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 */ @@ -103,6 +106,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 */ }; @@ -123,6 +130,9 @@ __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type) 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; @@ -289,9 +299,14 @@ __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size) 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; @@ -394,6 +409,24 @@ rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, 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 2a95a351f..4015872ed 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -166,6 +166,31 @@ rte_crypto_aead_operation_strings[] = { [RTE_CRYPTO_AEAD_OP_DECRYPT] = "decrypt" }; +/** + * Asymmetric crypto transform operation strings identifiers. + */ +const char *rte_crypto_asym_xform_strings[] = { + [RTE_CRYPTO_ASYM_XFORM_NONE] = "none", + [RTE_CRYPTO_ASYM_XFORM_RSA] = "rsa", + [RTE_CRYPTO_ASYM_XFORM_MODEX] = "modexp", + [RTE_CRYPTO_ASYM_XFORM_MODINV] = "modinv", + [RTE_CRYPTO_ASYM_XFORM_DH] = "dh", + [RTE_CRYPTO_ASYM_XFORM_DSA] = "dsa", +}; + +/** + * Asymmetric crypto operation strings identifiers. + */ +const char *rte_crypto_asym_op_strings[] = { + [RTE_CRYPTO_ASYM_OP_ENCRYPT] = "encrypt", + [RTE_CRYPTO_ASYM_OP_DECRYPT] = "decrypt", + [RTE_CRYPTO_ASYM_OP_SIGN] = "sign", + [RTE_CRYPTO_ASYM_OP_VERIFY] = "verify", + [RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE] = "priv_key_generate", + [RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE] = "pub_key_generate", + [RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE] = "sharedsecret_compute", +}; + int rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum, const char *algo_string) @@ -1088,6 +1113,38 @@ rte_cryptodev_sym_session_init(uint8_t dev_id, 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) { @@ -1107,6 +1164,25 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp) 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; + } + + /* Clear device session pointer. + * Include the flag indicating presence of private data + */ + memset(sess, 0, (sizeof(void *) * nb_drivers) + sizeof(uint8_t)); + + return sess; +} + int rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id, struct rte_cryptodev_sym_session *sess) @@ -1177,6 +1253,22 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id, 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) { @@ -1201,6 +1293,31 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess) 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) { @@ -1241,6 +1358,29 @@ rte_cryptodev_get_private_session_size(uint8_t dev_id) } +unsigned int __rte_experimental +rte_cryptodev_asym_get_private_session_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; + +} + int __rte_experimental rte_cryptodev_sym_session_set_private_data( struct rte_cryptodev_sym_session *sess, @@ -1273,6 +1413,39 @@ rte_cryptodev_sym_session_get_private_data( return (uint8_t *)sess + off_set; } + +int __rte_experimental +rte_cryptodev_asym_session_set_private_data( + struct rte_cryptodev_asym_session *sess, + void *data, + uint16_t size) +{ + uint16_t off_set = sizeof(void *) * nb_drivers; + uint8_t *private_data_present = (uint8_t *)sess + off_set; + + if (sess == NULL) + return -EINVAL; + + *private_data_present = 1; + off_set += sizeof(uint8_t); + rte_memcpy((uint8_t *)sess + off_set, data, size); + return 0; +} + +void * __rte_experimental +rte_cryptodev_asym_session_get_private_data( + struct rte_cryptodev_asym_session *sess) +{ + uint16_t off_set = sizeof(void *) * nb_drivers; + uint8_t *private_data_present = (uint8_t *)sess + off_set; + + if (sess == NULL || !*private_data_present) + return NULL; + + off_set += sizeof(uint8_t); + return (uint8_t *)sess + off_set; +} + /** Initialise rte_crypto_op mempool element */ static void rte_crypto_op_init(struct rte_mempool *mempool, @@ -1303,6 +1476,13 @@ rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type, 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 261a359dc..623459a95 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -897,9 +897,14 @@ rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, */ 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) @@ -913,6 +918,18 @@ struct rte_cryptodev_sym_session { 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 @@ -928,6 +945,21 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool); int 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. * @@ -949,6 +981,27 @@ rte_cryptodev_sym_session_init(uint8_t dev_id, struct rte_crypto_sym_xform *xforms, 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. @@ -964,6 +1017,20 @@ int rte_cryptodev_sym_session_clear(uint8_t dev_id, 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. * @@ -984,6 +1051,18 @@ rte_cryptodev_get_header_session_size(void); */ 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_asym_get_private_session_size(uint8_t dev_id); /** * Attach queue pair with sym session. @@ -1069,6 +1148,39 @@ void * __rte_experimental rte_cryptodev_sym_session_get_private_data( struct rte_cryptodev_sym_session *sess); +/** + * Set private data for a session. + * + * @param sess Session pointer allocated by + * *rte_cryptodev_asym_session_create*. + * @param data Pointer to the private data. + * @param size Size of the private data. + * + * @return + * - On success, zero. + * - On failure, a negative value. + */ +int __rte_experimental +rte_cryptodev_asym_session_set_private_data( + struct rte_cryptodev_asym_session *sess, + void *data, + uint16_t size) + +/** + * Get private data of a session. + * + * @param sess Session pointer allocated by + * *rte_cryptodev_asym_session_create*. + * + * @return + * - On success return pointer to private data. + * - On failure returns NULL. + */ +void * __rte_experimental +rte_cryptodev_asym_session_get_private_data( + struct rte_cryptodev_asym_session *sess) + + #ifdef __cplusplus } #endif diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index 69d776934..615a22586 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. * @@ -331,6 +359,15 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev, 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 @@ -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 @@ set_session_private_data(struct rte_cryptodev_sym_session *sess, 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 560e46411..62b782444 100644 --- a/lib/librte_cryptodev/rte_cryptodev_version.map +++ b/lib/librte_cryptodev/rte_cryptodev_version.map @@ -89,6 +89,13 @@ DPDK_17.11 { EXPERIMENTAL { global: + rte_cryptodev_asym_get_private_session_size + rte_cryptodev_asym_session_clear; + rte_cryptodev_asym_session_create; + rte_cryptodev_asym_session_free; + rte_cryptodev_asym_session_init; + rte_cryptodev_asym_session_get_private_data + rte_cryptodev_asym_session_set_private_data rte_cryptodev_sym_session_get_private_data; rte_cryptodev_sym_session_set_private_data; } DPDK_17.11; -- 2.14.3