From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700045.outbound.protection.outlook.com [40.107.70.45]) by dpdk.org (Postfix) with ESMTP id DD4A91B477 for ; Tue, 10 Jul 2018 17:34:03 +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=PAM2ikgL0kwKe+FoWhQ2dVax8HrcTlAh1NLDkLonDRk=; b=EQRYy6cYa94ljJMaSULXdhFfmWFNv/TN0B2UWTh6fv3XKY+wj8lRxFaC/rS/LPku4Q5hOh3rUj9GFOi6cuF4CCWiMLk0CKfg9be9c7Puo4pt70iulEiuZ169jdgBvVj/e8RHJ/s83iONrwza7ysTe3ss254J2aE/AzrlPCTpRu4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by DM5PR0701MB3639.namprd07.prod.outlook.com (2603:10b6:4:7e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.20; Tue, 10 Jul 2018 15:34:00 +0000 From: Shally Verma To: pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pathreya@caviumnetworks.com, nmurthy@caviumnetworks.com, Ashish Gupta , Sunila Sahu , Umesh Kartha Date: Tue, 10 Jul 2018 21:03:19 +0530 Message-Id: <1531236801-5931-3-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1531236801-5931-1-git-send-email-shally.verma@caviumnetworks.com> References: <1531236801-5931-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: BM1PR0101CA0007.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::17) To DM5PR0701MB3639.namprd07.prod.outlook.com (2603:10b6:4:7e::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e2e037c-2fda-4548-b415-08d5e67a9053 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM5PR0701MB3639; X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3639; 3:rPV0BX2dHjOLCtxV9ruSx18bqRLGZ3D//yaPLIqSj7F89PJHPhN0jMrdEaX8oyYmbHgciZ0ibYvU5ZkGu+A+Hq4lkdVaxEXTVoREED6MowDzbLRIqmg3b78Ka7jlkZ4F670f5AEowgeveLInjX7AXMkonk+kWR7jYrGsIrKXIraI4a68n8+b22zOT+g6IIeHUmIgh2HkZn4fJdA8cJGdF6pxsAv5/hY8y7O4Cq0/nZvfNTo0WYdrkelKEZbn0GXQ; 25:kQEYFEV//xG5of8/JWCDA8H3VamnnGs0QwGA/KxBjwQimJLHn0iA3y5gG2q02m6LW61iuauJMY3XpbqURmZ61NXD8yxTmPwGCZdHm7Rcv/eAqrhH9bgtgOmsHBqZlHcDC1en0x/KaVxH821y5dnulLrQkTHE05KDRkoIovS4KkkZn5bBHg+PuYsSaPXhAc6pYEGtiI47wnAU2+IN6wjsTQo+gQO+IkViqGdrCSev0e6WrnabMuD8i7gb7tY3Jv9sQqqsb1U5ocnFNQSLe7OH9omDizGta2psvpmg+JWUmShpp7xcmGk/DTeJD11EGYNT3PBeD9EJPG05cIIH4AaiZA==; 31:vUtayplynshOtu9gdh46uPJAsW2RBhlebrbhL3iPCetkSiRqgEJIL7+kudh99iDXGDzgIEqEEeCtLJ3dHxwoGXg2DoNdUCbpY3rOpbnVaTJUeJdemH5bEJUG9BjikEhIxAxUkYCgrHDmTrZ8xMkM/HghlU/RtIqfOOqGaqK4X11zFKRQhv86RuISD4kZqOXUA7k5UmPlQzfrxuGZ+D5NU8NsPK63tsgNl8kQFeX82uE= X-MS-TrafficTypeDiagnostic: DM5PR0701MB3639: X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3639; 20:Tv/ozfkEjboTWHqiqeqBhrJU9qM7qaacYUxw4PdZuPIr8tjhhgFF8vRh6FqQCxODNcodQd66lG5V0pcoamNacrlKCjr9z1iHAQA5N2kDv7SaNzjoxsAxMU+PE7SAD6qxccN+9qQNqyaIwdtAyKAV8hJMrwNbzutCZMl5MZpH0B4vj9IasRhiWRr0qKZggoMu3OKFbX3PlmW5JEKDNSY6IBbRIQPwVLL608qumHOL4KEaJgL+HJEoFK7ATPb/FnT65gjAelykc0biraTijQraoGvvy+P7A7RGTFNl6l9HpWxEiOnPA58HY2WC3Izo4qIvgEnrwuC/kpoXRu7B4vxMFz59jMpf6rNubfWMj4jH47gnLlVFziZhcnBy4eLAXKrHNkbvL4Xs7Jx+YbguxTDrxIpRfI/ClKiHkczv6w66mn7aWuRS9sHQl7EFkcjeYRIgHc/9s18S3hSHM74Nto6m8dpHH3cUUj8LKZ0avuGdNH6pKhH5GYiS/ld+cYcuasspHkvAcpSf/9r/gylhL7+0dYol7mP3663zRFLhrI1GCQ5Hg3bbU/CN895w1N/cPaZsnD4TN+KjIOvTt9aLWSzA4Z528V2JxQu/OK2WrWWRszc=; 4:eROAq6eTfIJPJecsX2yUAplvZTp6x71ADtXLP+13xxRXZ9uLyOjLwiRUY4VOqzti2Kzx310DPC9lLGt7V7qRo6JDyBn5L5bD3im3oc1Ace0KuOW8Mp8+1OkmKDGoxDCJsBtgAKwBtmCDRJQb78kmORaz8j+2oMCC1XOU9N3dyNHhHg9gHY19JQ9nVpALy5C1alS7r537+CKViNEu/0Sd1XBaTUcIceOxp/Art6GsncN2aXkSEiHFP1XyozTwKpqYpstfBFu1Amm1mvDeKbsOEA== 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)(8121501046)(5005006)(10201501046)(93006095)(3002001)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DM5PR0701MB3639; BCL:0; PCL:0; RULEID:; SRVR:DM5PR0701MB3639; X-Forefront-PRVS: 0729050452 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(346002)(376002)(366004)(39860400002)(136003)(199004)(189003)(47776003)(2361001)(68736007)(53416004)(76176011)(66066001)(6486002)(6666003)(186003)(105586002)(16586007)(316002)(6916009)(51416003)(50466002)(97736004)(48376002)(72206003)(54906003)(8676002)(14444005)(4326008)(478600001)(5660300001)(16526019)(5024004)(50226002)(6512007)(2906002)(386003)(3846002)(6506007)(44832011)(106356001)(107886003)(2616005)(26005)(55236004)(69596002)(6116002)(956004)(81166006)(2351001)(305945005)(25786009)(81156014)(53936002)(36756003)(8936002)(11346002)(52116002)(476003)(7736002)(575784001)(486006)(42882007)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR0701MB3639; 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; DM5PR0701MB3639; 23:xpCcGJl3b8Hjbd/zaKJquzkPcJ+n2E3iXcXFmkm?= =?us-ascii?Q?Za0tdBEgiQiwJbNsfxrTkpUQqpa+UF/6DCkFyKWbZD2hdR8C9JXtQhy8E2Y0?= =?us-ascii?Q?tlAZLNbEvr8oDf3UQlyRi4MBRAILap5Qs9+GU5BP/K1iSt0qeEBtVu/0cnZz?= =?us-ascii?Q?k5ObTXg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Wc0BuYqeVkvuN4uTcdxY5AgoEzMmL3GJ9dmVGPw8Tay+CtN7QQa1zPLxXQBXlSXh0jqZvUNDFm5YjNeli+4q0l3mRT45FTRvFgDiTMD3ANw9ZVSBCj/ddkQEH+x/5w6/+ZFNOgF05eLanq4DLLZELth5yvP4lIW8SeYBUr/uTHWitaEpFpLo2+djyspPpZJZ5yY3e+m/VKpBQ40Mnw0R+qcUcqqUebSgrxD8svjc/yzhEgEIXWJiBzHvMM64yTDQ+zQRvWtUZsUdV0dFXxCNs6JTWxsWiMTn0VPQ2B5lSH5S4dGQ==; 5:LAAJRcy5JBhwnBw932xRf6SFptulezgMm5EP6DjlOED1f90st6De6H9CxrMXOp/z+JbPSe3OJ2A3krUXa86en3uU4+t5ITPBN+KtJbd9nr53cshnyMCO3DK4P6WskVI8ChYmU92qZLoArc3dJQIor2bXnEhDuD7j8sKg1ZxZhUw=; 24:NG26dUjroNh8wDCMo+UySim6/ss2+aX5ViDHTfdcyGPV4fCoKuZWE8EiVNmJFojbSCKR2d9fGevq568MUjHoDRUh/0wlHv+6VK89SnOHo5M= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3639; 7:MewHvYovr5BIxRVnm3s+erVavNNmtX7XZ0Y0FdG1/S7qMCpbq6u0CbjwP6JygbVJi8i3CpeoRPCJfLDrOVy3lpWJ6Yn/6LtJ3vNega5ZanBQOAb+xDiB8vetwGsbYLQehBGojFCgK1BP4XPVPK+JFc/bD4DFV3e3jakwFOS9lG9C58VQ96X/wPVRG/b0qmKw7rs5iUlGQ+kZ16T2kyz/U7fp40iDwmCBQ0elaMSKyAznxf6GTIkGqty+JS/aa97h X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2018 15:34:00.0749 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e2e037c-2fda-4548-b415-08d5e67a9053 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0701MB3639 Subject: [dpdk-dev] [PATCH v5 2/4] cryptodev: support asymmetric operations 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: Tue, 10 Jul 2018 15:34:04 -0000 From: Ashish Gupta 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. Signed-off-by: Shally Verma Signed-off-by: Sunila Sahu Signed-off-by: Ashish Gupta Signed-off-by: Umesh Kartha --- lib/librte_cryptodev/rte_crypto.h | 37 +++++- lib/librte_cryptodev/rte_cryptodev.c | 166 ++++++++++++++++++++++++- lib/librte_cryptodev/rte_cryptodev.h | 91 +++++++++++++- lib/librte_cryptodev/rte_cryptodev_pmd.h | 57 ++++++++- lib/librte_cryptodev/rte_cryptodev_version.map | 6 + 5 files changed, 352 insertions(+), 5 deletions(-) diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h index a16be65..fd5ef3a 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 */ @@ -114,6 +117,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 */ }; @@ -134,6 +141,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: + memset(op->asym, 0, sizeof(struct rte_crypto_asym_op)); + break; case RTE_CRYPTO_OP_TYPE_UNDEFINED: default: break; @@ -300,9 +310,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; @@ -405,6 +420,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; + op->asym->session = sess; + return 0; +} + #ifdef __cplusplus } #endif diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index fd1e738..da0d322 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) @@ -1079,6 +1104,41 @@ 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; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, + -ENOTSUP); + + 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) { @@ -1098,6 +1158,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_sym_session_clear(uint8_t dev_id, struct rte_cryptodev_sym_session *sess) @@ -1116,6 +1195,24 @@ 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; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP); + + dev->dev_ops->asym_session_clear(dev, sess); + + return 0; +} + int rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess) { @@ -1140,6 +1237,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_sym_get_header_session_size(void) { @@ -1151,6 +1273,17 @@ rte_cryptodev_sym_get_header_session_size(void) return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t)); } +unsigned int __rte_experimental +rte_cryptodev_asym_get_header_session_size(void) +{ + /* + * Header contains pointers to the private data + * of all registered drivers, and a flag which + * indicates presence of private data + */ + return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t)); +} + unsigned int rte_cryptodev_sym_get_private_session_size(uint8_t dev_id) { @@ -1180,6 +1313,29 @@ rte_cryptodev_sym_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_user_data( struct rte_cryptodev_sym_session *sess, @@ -1239,9 +1395,17 @@ rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type, struct rte_crypto_op_pool_private *priv; unsigned elt_size = sizeof(struct rte_crypto_op) + - sizeof(struct rte_crypto_sym_op) + priv_size; + if (type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) { + elt_size += sizeof(struct rte_crypto_sym_op); + } else if (type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) { + elt_size += sizeof(struct rte_crypto_asym_op); + } else { + CDEV_LOG_ERR("Invalid op_type\n"); + return NULL; + } + /* 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 4b279f8..f93dc71 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -848,9 +848,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) @@ -865,6 +870,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. @@ -880,6 +897,21 @@ 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. * * @param dev_id ID of device that we want the session to be used on @@ -902,6 +934,27 @@ rte_cryptodev_sym_session_init(uint8_t dev_id, 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. It is the application's responsibility * to ensure that private session data is not cleared while there are @@ -920,6 +973,20 @@ 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. * * @return @@ -929,6 +996,15 @@ unsigned int rte_cryptodev_sym_get_header_session_size(void); /** + * Get the size of the asymmetric session header, for all registered drivers. + * + * @return + * Size of the asymmetric header session. + */ +unsigned int __rte_experimental +rte_cryptodev_asym_get_header_session_size(void); + +/** * Get the size of the private symmetric session data * for a device. * @@ -943,6 +1019,19 @@ unsigned int rte_cryptodev_sym_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); + +/** * Provide driver identifier. * * @param name diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index ac6a1c4..92763d7 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -249,6 +249,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. @@ -268,7 +279,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. * @@ -277,6 +305,14 @@ 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); /** Crypto device operations function pointer table */ struct rte_cryptodev_ops { @@ -301,10 +337,16 @@ struct rte_cryptodev_ops { cryptodev_sym_get_session_private_size_t sym_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 sym_session_configure; /**< Configure a Crypto session. */ + cryptodev_asym_configure_session_t asym_session_configure; + /**< Configure asymmetric Crypto session. */ cryptodev_sym_free_session_t sym_session_clear; /**< Clear a Crypto sessions private data. */ + cryptodev_asym_free_session_t asym_session_clear; + /**< Clear a Crypto sessions private data. */ }; @@ -448,6 +490,19 @@ set_sym_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 93c7090..e63b51a 100644 --- a/lib/librte_cryptodev/rte_cryptodev_version.map +++ b/lib/librte_cryptodev/rte_cryptodev_version.map @@ -91,6 +91,12 @@ DPDK_18.05 { EXPERIMENTAL { global: + rte_cryptodev_asym_get_header_session_size; + 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_sym_session_get_user_data; rte_cryptodev_sym_session_set_user_data; }; -- 2.9.5