From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0068.outbound.protection.outlook.com [104.47.42.68]) by dpdk.org (Postfix) with ESMTP id 19E2C2B96 for ; Tue, 27 Mar 2018 14:55:10 +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=xlE/+GbJhCaiYb7DXaw0uSElFjY3QXeBU1Zml/Od0R0=; b=cndkYNxO38UObM6YLBD+PQg2oOLJ9HK4x9dEU04atW26WBus8fkWsFtsMR7UwzTax2BMcw8iLYDy3Gc3ZzNq3BYFW9gT48Soiyo4+eKd1ztVVS5KH948+VvfFtd1a9QnixC7dzvIYABS/lO1rJAHqOgfpjLJWU6hiAkRHBdXUdw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by MWHPR0701MB3644.namprd07.prod.outlook.com (2603:10b6:301:7d::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Tue, 27 Mar 2018 12:55:05 +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: Tue, 27 Mar 2018 18:24:39 +0530 Message-Id: <1522155281-16329-2-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1522155281-16329-1-git-send-email-shally.verma@caviumnetworks.com> References: <1522155281-16329-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: MA1PR01CA0089.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00::29) To MWHPR0701MB3644.namprd07.prod.outlook.com (2603:10b6:301:7d::37) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30fad2bf-d93e-4b02-a048-08d593e1f7ec X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MWHPR0701MB3644; X-Microsoft-Exchange-Diagnostics: 1; MWHPR0701MB3644; 3:bJgUrpAyqaV3mDNNcEPyEsjgf14w6H2A4OCIP3dzqVF+G770Rw0L+IiffcT+M0KCl9s8IY4BISoxvWyUtMCKxz/EVpqgVe9g/GhCdYbahI2cP9kYdmSR9fmf/jhWoqiN4EYLtb+CUgQBLJg7l7qBMoB7QczuWqlfASKD5odkBrMLeM5z5nk1DVxtGpDJENEhZEm6TCyxK9IyvvkwdJHnrOVotCp+HxH9lwR3gtxQj6Ah34u5URigCOIV4UFrBOlu; 25:c207XM1fNB9fJPQyjCYcrpXqWJuiTtt/5TBjMw280WaT2pEbCi1APyo0EZylSCCO+4ooHC2HwgGwhwZ1Z5C7joUl3Q3ul9lJw39coM4HGOvlvelNAvTMPO40YuT5eeTTLw9JvPNbDLtOUcu+iJaTcWeK6hb9vTeys1ldLSFD6E947SWreEAP/bjuNX3dxJCZQaJ8EMxj/M1q44oNBDhkcmHK8OSqCgN1cGzWs/6qRSr/QifKGc9NsOt9RxNmzXkr2DRh2TrnmRLsZDuXpA17vfVyZYQiVZk6mZFbVFtrZxT30fOJInBRwM+QVqleLO/CHMB6bEGKuvvZIIz9IGcL5w==; 31:nVSTz2hgO4qh85iQAddoxjcNPKz62JJH3Z5N3or9Ra4i69YI5TkZXWtDuAeuNpEJGU2X+GERAmCgnJcfKy24YFww8yS3apuwoEZ2GIU/OkwarZc+F6sbGAImmi+M57vlHWr/xELBBHrCnSpApe/V+w4HfMZnCIUEl9qyKO7S2SrCMuwazr1vl1cRFaDYC8UigzvStBLTGB7OZEY4Um1DabfLSsmynO68QXO6uyihXNQ= X-MS-TrafficTypeDiagnostic: MWHPR0701MB3644: X-Microsoft-Exchange-Diagnostics: 1; MWHPR0701MB3644; 20:7eVIhqw9X1Wb8gfmisbxMobR4lojFdzB7vnTnsQCDePBZ+9QtPyzf+TsIA1xoEKbE4wXPSh6mmKsQm+VU+uT2mFglgJVtTyf22dLOuBuireBjcDdnmLnnmCFAPYfdUfIjpCGupdv3X26rK+kN+HxB7aq67xPwDr6CWQgiWvd8YqGg1VDYI8MLn4MMBrW3HVLdhaAkeXbfw2NMgmw55Bg3HRCQiyqCtGSUCCSNdmtb24TgziglAvu/dgRq/ChVqExip/ZIOp/8aquyR/sOYjeUDpExb//tooanVvrN0p1xDW/ZaukNEvIwhvdOIWb+jrO+YQMsPd8Mf75A4atbRLAEvkLoFViDlDJI2EZsVVy/OxvUobew0ysnohoXOdApTDCxtBY3NADJf9/wbwgHM+t5VKqD+56mIQBsEYecFrmF8EDYhys5HiAPu557M/X846fEQi50fV8bsaz5WpC2Apxhng+mZdGwo9mNSCT+Smbr+YEf/tCmbn7aTB00sXebcvRFWNAf+IJmZRbj9bKa1TLDJYwT71d0PLoEU7KTzlRGBOE2TiWFfREC8EHNMaS7nwcVcj3NV/PQcGUAnmGKNHYb2azY9NR8GIPtTHCLWP6QJ8=; 4:ND5n/SMLjdNf1VUO94mFFDxAH/65e6rSt03bb1OG8cTM5pPaNxhXF08Ax835p9HUdpengFkr14SoZ5WCJO1Yw7E9a7npoe5gs/tsZBFJ0Mc8pXlZG98jwTMd5JwvTaaoPXqW22wziCdTJmWZZe19nDnQbbM3aukMe9Q5qxhwXaDWuEeWeZ1tutd0Su5mAe2pQ5nSeviZ+Hk+E/QfE56pyKnCK1hFMbB3zH+pM5eKAqsxR0pL10TZrDhpzcYKPVcWxeIOVNqwHGIAaafptH8r3A== X-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)(10201501046)(3231221)(944501327)(52105095)(93006095)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:MWHPR0701MB3644; BCL:0; PCL:0; RULEID:; SRVR:MWHPR0701MB3644; X-Forefront-PRVS: 0624A2429E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(366004)(39850400004)(396003)(376002)(39380400002)(189003)(199004)(55236004)(36756003)(81166006)(16586007)(68736007)(5890100001)(81156014)(50466002)(6666003)(106356001)(6916009)(53416004)(8676002)(5660300001)(478600001)(105586002)(2906002)(72206003)(50226002)(4326008)(3846002)(6116002)(69596002)(107886003)(48376002)(8936002)(2361001)(316002)(2351001)(97736004)(54906003)(6512007)(26005)(305945005)(42882007)(2616005)(446003)(16526019)(186003)(11346002)(6486002)(59450400001)(47776003)(7736002)(956004)(25786009)(53936002)(386003)(6506007)(51416003)(561944003)(486005)(52116002)(76176011)(476003)(486005)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR0701MB3644; H:hyd1sverma-dt.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR0701MB3644; 23:/Cs7gsWpC22HOgwjLtoMkxPKcmal1Mot5y71fqk?= =?us-ascii?Q?fHPBgfC4e8bN2/9+nQx2sZVqvy0qEzUbJBqH7YxqVAwdE1gQ3bsv0tXaj/Zh?= =?us-ascii?Q?Vmeh0/9F39iuBJp5rVn3Q1iD7GgkO93IkbgFaJEuXk93KfINQA7kILlKYnXZ?= =?us-ascii?Q?Bn+07BhhOKyhBtNP2N90uoOy+D9O1VexEwzrU9gL93egqfhCW83tMy85ApJv?= =?us-ascii?Q?WFbpriWLDP7GeZDbIXgTZTMeOObLcySkPTw40bl2NZI+RhEHsKAIZKJzvTot?= =?us-ascii?Q?miUpDnlzIjTnjtDEg1EOrg/iaGfiW7A3iArFi9BHvlXLSRaygSTk8WYzgOSO?= =?us-ascii?Q?s7S0zsTkG38JMQfpYN2X1Vf9KOMvJiaTsIltL2AOBJRsGdhensR6hSYION23?= =?us-ascii?Q?PglB2SKJRe6vmtf/oWCRYn4LBz8ENnBmeOvy6/KikBL6j2dNc+7yelojDJH4?= =?us-ascii?Q?6NrkF7WOo3TDWS7u7JPTNUH0NK1eYK3AN/Te7+Jc99t/5pP3h4WuSdQM5Ki6?= =?us-ascii?Q?O51fWErzqUmiry3FLwLm29o2pIANRgwlglr6E8G4m/72tLEA9QnbhpMHq00R?= =?us-ascii?Q?UPs2dhNEj0ecyrIq7DbdOWwOl2xexx614JJzbI89iuaA+Yf9BOaJQDEDIw6T?= =?us-ascii?Q?easIAJnpDn8RC/x1/xIZRDXT9t7nKPtET3NfDoJYIavQV8VdmzHVGGX49XWu?= =?us-ascii?Q?zEsXMqIslTtUEeLQbQOec5LOfqztbXP8ZrH+DB2mcig5Af8s0IyYtFpN2jQ0?= =?us-ascii?Q?65Sub3XTmVjw5dJGCqQf1pYbP9ui5ZAW+/V7T7f6B4lnNPyZGk69UcWEZStk?= =?us-ascii?Q?H4A5QsOYcL6+NrOnnhJElQp9YB6AhHrTaQyuMF0rggs8V5LznSvDNXTghUOi?= =?us-ascii?Q?DcslJetrN12FuPwm8zt65ULACnZ/2ZpohlbOtiLhC/wucf8YphvDd825796N?= =?us-ascii?Q?aWpvE/h0F5z2HZrCUUAEcw404nygNoL8zKZuK4ZZZzSKR7Cro32bWnOULCqZ?= =?us-ascii?Q?kvd6gMZ0xMMisKp6eT/IkYNYOFY5ySiyWkfbmLD0Q4MRFpGFKitpM9etsj3d?= =?us-ascii?Q?uy9t+Q7xOLlecy4ABffCoXhDKNUPmv8HF77vnVJqQqg9Mu+445RYM9L0JRvl?= =?us-ascii?Q?e0RioQ73BE83PCVqZ5HSzydAx893hwpAqcOo52VqHzzT3k6wWdl7luM8REiZ?= =?us-ascii?Q?flvs612TTSVi5u2BnW3LezHRThUfaTlOzqZSoUu5HT0ZiGZ0bL4tLteBnLMr?= =?us-ascii?Q?G50+15h0Q1H2tSMu1r6vxDgJJBveS847FSirWvWToQsdo5c/040m81UJj7fj?= =?us-ascii?Q?ENj2+k1E+bo/CZTMrAvGoIfiG4ARFswm1X7MG0Sf9vK0ca24zYRMK5raqv6e?= =?us-ascii?Q?tXvAGGsZPkGOPvlMDC+m7VqmdnJ/S1KvbeWa20w8uWF3UgyqJz8b96wDRiF6?= =?us-ascii?Q?wTLhYsREBzrZxSg9hBCuYtT6eg8dbLFw=3D?= X-Microsoft-Antispam-Message-Info: bc0qYm7DJc9C7sjxZc3HglaspoJz7DtdvcXqUanNquPuSIEKIDn5mE9hCqMo8X5VlFzPEgrKIQmOIWyprE2O3ZYJdAF8rZlpAQhqtVs6t5Aty39VEAfeTrzeFrOZEStxD0C0zlkVqedJTc1Z+6zb+JZ4pKHLVF3eyuoez3jMoa1CbCUPLbr9YjYDibsaMBPW X-Microsoft-Exchange-Diagnostics: 1; MWHPR0701MB3644; 6:HLB57s/Kdw/71nvd3orlAeDV01Iv42q2jKwJMRSVDpGvLOl3gM80lJzu/HwR8onT++0SLST1+5pocbzAxQoGS3wfCulCSjthMGjeYJ7JXGKPPj40J+Tz8rHi6drNF9Htv5gLhyk+7JueRFGFdEXnAt9h+tjaW1dQqt754C7FyPskxxmLqLeEFGzy7vyL32Fw56Vp/bjTSehA5yTFu6lITMZGwjWX/uXdAo4HFFm8nMg6yFrtRf7XkwwvRTKpmnHPLtBJYUaBUFOw3qlwKQ8BawzD6aHzD03oKuoQCufrVBc3JzA4v51Alqs5tTkao49qL37RoV61SP8YcCcFfgtCeuHqUY098pspllOhNPxP/KOR+pFXjS7RLLYKwTjvj35Q3NtERjCES0EMrSPdq/EOjrfkrvB4o5+9ZpXe5MMUWnFro1JBbB0sN2OMIeLSpknEtx/6Dep19mjKbznrYCWLvQ==; 5:VfJMmgV+vxgYXre8lcOxrDYNfWuB6suIX6Cf3BMG4Pcv/hMwMcLexKgktFiYXySi+ibQz5eUie0nJFcZFrOvJ08+SUNjw8MxXW3SGyaEtYHCXmHZdpsowGXYNfAhgL4PMGd29b4OMkKE9Y1O3eS+ikYQxM3TcfQa001h5U7FjSI=; 24:i0p/FwlQTLAZYzmS+0N1wT1m5/3Z8lp3IhK4RdGIMQsaUctQ3Ec79h1rJhTkNI6Y5NnEjsqhC0hmBBtLSNksPjCCF7NpBdAQvS2aXq0Q2Tc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR0701MB3644; 7:ofaXgTaFxUbVj7FyYELq7Vlj7KAuqoqxzT9d+BZs88Lt/HDtOHkvoFmySn/1aaDaQ8UQoArQLq8yXloPTSCaeojO/BcHr58izJWLj+RcMYvaXdk5ybKocBvT3bUUxGrXdIklIP6tbbarbNkxR9KyvMZfv9YVuxLe2gbnpK92s/iwnEmw0Tv0Q31Mune4n7locr3g4auaGDq+7c4lHUImFCJfdDmX+vQtZCcWfhie4XMxKOZEKgcORZliTMuzQjYW X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2018 12:55:05.1228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30fad2bf-d93e-4b02-a048-08d593e1f7ec X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0701MB3644 Subject: [dpdk-dev] [PATCH v1 1/3] lib/cryptodev: add support for asymmetric crypto op 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, 27 Mar 2018 12:55:12 -0000 Extend DPDK librte_cryptodev to: - define asym op type in rte_crypto_op_type and associated op 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. Application may choose to direct all asym ops to one qp and all sym to a different qp to avoid head-of-line blocking, but there is nothing in the qp setup or capabilities to prevent the application from sending an enqueue_burst() with a mix of asym and sym ops all to the same qp and it should work. 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. Signed-off-by: Shally Verma Signed-off-by: Sunila Sahu Signed-off-by: Ashish Gupta --- lib/librte_cryptodev/Makefile | 1 + 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 | 13 +++ 6 files changed, 307 insertions(+), 5 deletions(-) diff --git a/lib/librte_cryptodev/Makefile b/lib/librte_cryptodev/Makefile index bba8dee9f..6815e6ff3 100644 --- a/lib/librte_cryptodev/Makefile +++ b/lib/librte_cryptodev/Makefile @@ -12,6 +12,7 @@ LIBABIVER := 4 # build flags CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lrte_eal -lrte_mempool -lrte_ring -lrte_mbuf LDLIBS += -lrte_kvargs diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h index 95cf8615e..0fdec1bb3 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 */ @@ -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 @@ __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; @@ -283,9 +293,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; @@ -388,6 +403,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 8745b6b02..cca8d4cd4 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -1088,13 +1088,62 @@ 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) { 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 @@ 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) { @@ -1199,6 +1264,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) { @@ -1238,6 +1328,29 @@ rte_cryptodev_get_private_session_size(uint8_t dev_id) } +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 @@ 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 c8fa68935..68d1ae19e 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_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 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 eb47308b6..d5bd12a6a 100644 --- a/lib/librte_cryptodev/rte_cryptodev_version.map +++ b/lib/librte_cryptodev/rte_cryptodev_version.map @@ -85,3 +85,16 @@ 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: *; +}; + -- 2.14.3