From patchwork Thu May 11 12:35:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umesh Kartha X-Patchwork-Id: 24247 X-Patchwork-Delegate: pablo.de.lara.guarch@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id E91F0692F; Thu, 11 May 2017 14:37:01 +0200 (CEST) Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0070.outbound.protection.outlook.com [104.47.33.70]) by dpdk.org (Postfix) with ESMTP id BF13568C5 for ; Thu, 11 May 2017 14:36:59 +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=fm99B24zlcioIUxyjFp6AAb/km92E8V5J8gE87cC8hg=; b=YYG93pkE17In5GUZWhc8Gv2KB8IK7zvPnP+b61FkAhOll2y1u7QrTqj3iXJYfsAJZzsPWPXZVpk6BUgpTCKYn7RXKtk+TQkEIIMDTBSjuRGvg7ZHBCZGUZQqRAY3cqcZubG758fcWpbxLfdPI5OfXH5qJCpvObLoTz41+r5lFNs= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from ukw0rk.in.caveonetworks.com (14.140.2.178) by BN6PR07MB2755.namprd07.prod.outlook.com (10.173.27.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1084.16; Thu, 11 May 2017 12:36:55 +0000 From: Umesh Kartha To: dev@dpdk.org Cc: Jerin Jacob , Balasubramanian Manoharan , Ram Kumar , Murthy Nidadavolu , declan.doherty@intel.com, pablo.de.lara.guarch@intel.com, Fiona Trahe Date: Thu, 11 May 2017 18:05:32 +0530 Message-Id: <1494506132-23107-4-git-send-email-Umesh.Kartha@caviumnetworks.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1494506132-23107-1-git-send-email-Umesh.Kartha@caviumnetworks.com> References: <1490177802-13398-1-git-send-email-Umesh.Kartha@caviumnetworks.com> <1494506132-23107-1-git-send-email-Umesh.Kartha@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [14.140.2.178] X-ClientProxiedBy: PN1PR01CA0092.INDPRD01.PROD.OUTLOOK.COM (10.174.144.160) To BN6PR07MB2755.namprd07.prod.outlook.com (10.173.27.141) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6ec8230-9b1a-4124-6fdb-08d4986a6a0c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:BN6PR07MB2755; X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB2755; 3:unuiUjl1O/0z0rML+MiriZ2uZCPR7/UbRRKPgihXU9SUXh/FTvXavI7hxNb/+GGSORBlN1knHugvouqAbWc2tgKoyS5fC2TNBXvMy2YdtxAGfCUXf7zfnHVKJCeMBU77upUU6n6X3MqFaZ+TBMgI3n3Exx5JZhTObduROLlDeh0dtV/a3XksZRpnIthw+j9Kg4uOjhntWfpRul1beg5J6mAMQHPFsN1Zdd7+yGFepxiyqpdH33oabhgVYxlNCavgBvZ2B0QzdWShJnwNO8CVdbY4VRNJzzIrCTo/K/9Zwf5wKBTyA5P/PJIRCkEVWYcUbiSo8SBrKzk9+4giUCfCJQ==; 25:5tO5wKZMDgUyGVhUqT7VYCKZc0OnW8OuvOqerUYwf6ZQrZaia65X6MtlPXXVZNQDSY3NS7Kn/ANccB0feIpTAirLjP46mmgyPdpPvkWH9EXXFeWew1HBQhmY02gqzP9Qn5FYwJymgxGw5wISXussVy2APUfJoCuuzjMaNKHEAe9cz8OxljDkGHbLAksIptQLIHh9DInxEuM1c3H1xqIW3HxHrXl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VH9WtQAPvquV+PkWd6XOZJuV2Zyrwd1+JndDysyN9jhZyVxoEx4rLHr186QmaYndDkoDaFH65GP1m/v31y07J3US51WD00lEm+/mx79/N0h9hQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(131327999870524); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123560025)(6072148); SRVR:BN6PR07MB2755; BCL:0; PCL:0; RULEID:; SRVR:BN6PR07MB2755; X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB2755; 4:jw1WdfGArOFFKWlwfrUshieP+pq+S7nX1KGh1W97dPX5IreVzhhTASQinueRPFfEs3Xgf2yNue2XCiBOMLTVYsiLj11pFDrSx0tLfkUq/93SphXmXzOlyw/grDb3citCAmSpXgr6jhHHEVJxZj66d08D3Q2oWtQQ/95TnbP+aK6Pe74/J+dlwSmhcqW0noYC07p7xtX/aEhKmGZIVd+5DeExzwmPDe/PkRhDsG86txwULlR8FOHuM/5fx6GsbtdRMJKVR2zAlqDUicMlZOOsNkXuCepuJ/UvB+M/0InXZHk1bsYU8IJKZpL2t6Pfh3Cws+SG4lCUQDKf3RN7T//iMn08uoePSus8KBSi9hm6SKcb43r8g6ROwT5OfvK53hEhmfiC6tM9LA4opxvcPZaDaIqbCh43RwK2f6FRam2Hydyn1z186JEIllJ5O60tzXdRBlc1yPDBhsEwK8hajGqiPlpH7vNoeMSo4Uu9YqED6q6749zq9RA88r78eQwP3FUsXuDv6R9fj752FY2b6a3/A8ramJU3sFkcvAcVUIi0AB/g7Hr71vJcdQXAwy8t7/PYbWBfWo7qDWXpjQD7Zob0JomIQWldGXc2jzWYiZqBvjooAw6rJu+nEbn17lIbiqivZWHd1P2fAZayvkXJXczj4gysLItGsWsHM8e26OK8lo0QodaYCFTENuZwLqmXj7BUnh8QW2rH+kKLw2GdGzCOrIstwL9vLBuTsL3Zoyvmu6t3mtmpcR7QNgU5cfUqk0/pug08Cy1wQObPHpmSY7HrxlxTNMr36WXvo29swulNDxZgY7P67EuU0UmqeiymnAPn X-Forefront-PRVS: 0304E36CA3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39400400002)(39410400002)(39450400003)(39840400002)(39850400002)(2351001)(305945005)(7736002)(189998001)(2906002)(4720700003)(478600001)(6916009)(6666003)(2950100002)(42882006)(25786009)(5890100001)(4326008)(2361001)(42186005)(72206003)(76176999)(5003940100001)(50986999)(5660300001)(81166006)(48376002)(54906002)(50226002)(6512007)(5009440100003)(66066001)(6486002)(53936002)(6116002)(3846002)(8676002)(36756003)(47776003)(110136004)(38730400002)(6506006)(50466002)(110426004)(461764006)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR07MB2755; H:ukw0rk.in.caveonetworks.com; FPR:; SPF:None; MLV:nov; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR07MB2755; 23:e8iUon4L0REopyBYf7UVDjJeP4XoC2mB8KqzlQp/C?= J7OAQoCsIZYzgwmhEx78+rts/MvZ9Ja2DyJY/e0KxNDeboX71AXrY7yPAAyHwW4IbfG3LnpwGQY1HM8ok2vNQ90sFzRZzxmDbgkYkB8j9pnxoxvsNsdIKxEYyKY40SQo6mAcGRUrWmicZ0MRc1xpQ3jqF7DWZYTXkuPct7jPitKsSZ69ZNUBwFEe3AZZvt6IwnARRcjD4r+m4BunPg3wMJr3nhKBMv6TraOuAqqXUpm/WpEPIMMQecVk29LMW+HSo1/O2g/rqfyuL+samBKsOOblgcRjavS1bKjbKVpXzs+froGhAWGcQjfjYrdFn1TsSIiB5uHljzj1hYzJN0RkPj+TqFLrWvzJBRFrzMj9yi7dEJSkm17fXug7yrmglTtDb07P4yiYnvYcx7OmMjEhhghogO4SBJsm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UOkHhK7WbqUEHiwDCrCRwDBU2h3COWd8yxYKyb1N+FYgId5Oe6T5LOHw82jaTsArvXWQSXyffhFCpWXOyV8F+rYUnYUzVFKkXECMnpcRPWzgUsgCpq449gxtzlzpxF+HXbSrJPhrK5L+ROQOfAw0YXBgvqE3meFHId4zQVC/HxaG5oClY7OciTTxRjx8H6VaF6dlNGKFumkT183KsRNBmjfwUwACjVeG35Cet1N2baRIgaSkfYZWXcn+EzV9HtdWzHbBGKtjuVYSSj0ZYfLgllto0DQh7cyFNvHJ7ay//rttUb9c1tAg==; 5:hpLfG6Qu2GK0L7zGqhS9ewloOxw4wrBHz8o+GxvojIf9QmR8KaHqsQKME7lfJWh0iVadmteYuO7Nc3iJHO+DLfn+ORkwTYcvCV6L8BHJJAD5tjYQPY5IvMk78I0Q/Hf/D9Z8i9DZclppUkvGFj+SBw==; 24:xaa6DZgmbDL3myKFHsPBGtQxolTg8W0gA4qxcXgBtr6G38QiFl0Hokt+6jCmaD9vw40YC/reeGTJLK0sSfQn/YwxF5YQolGMhWnNHxIrSYk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB2755; 7:3/h8Tv0p7qhPFU2sR/jm8ixxqaxSZUj6Uwsvr7LKUW9s2HCB8FT9NRF8+VtwzqgtiJGDBtVcsi+xuZ7qXeqNg4YvuScyrZUdtcdej/bes1E0UB3gS0H6IjjNWRUoaG+fvghTFkSjHvy8HqGWsOyBKYB+jgJQ6KHDjMmhvws6FwtvJ2rQXYl+avo+4l5vv3XX5eZ2uWR2q0CEzsACpNFOlc6YgtMhL1FFu3bp/8/RsjbfpRLeQy3UzS1aa6mIUqCdrKf1MZHCUaT44JbMIAAEpxTuNWHTsXqdvgnZRnyguK32tAayo2m1NEtAHMy/etrOuMdqEq90VA5rAUs97q/eqQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2017 12:36:55.6018 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR07MB2755 Subject: [dpdk-dev] [RFC PATCH v2 3/3] cryptodev: added asym queue pair and session apis X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Added asymmetric operation queue pairs to device file. Added asymmetric session creation/initialisation/deletion APIs. Added asymmetric queue pair APIs to device ops. Added APIs to attach asym session to queue pairs. Signed-off-by: Umesh Kartha --- lib/librte_cryptodev/rte_cryptodev.c | 352 ++++++++++++++++++++++++++++++- lib/librte_cryptodev/rte_cryptodev.h | 80 +++++++ lib/librte_cryptodev/rte_cryptodev_pmd.h | 113 ++++++++++ 3 files changed, 544 insertions(+), 1 deletion(-) diff --git lib/librte_cryptodev/rte_cryptodev.c lib/librte_cryptodev/rte_cryptodev.c index abcdeb0..d4e943c 100644 --- lib/librte_cryptodev/rte_cryptodev.c +++ lib/librte_cryptodev/rte_cryptodev.c @@ -1242,6 +1242,15 @@ struct rte_cryptodev * return dev->data->nb_queue_pairs; } +uint16_t +rte_cryptodev_asym_queue_pair_count(uint8_t dev_id) +{ + struct rte_cryptodev *dev; + + dev = &rte_crypto_devices[dev_id]; + return dev->data->asym_nb_queue_pairs; +} + static int rte_cryptodev_queue_pairs_config(struct rte_cryptodev *dev, uint16_t nb_qpairs, int socket_id) @@ -1320,6 +1329,87 @@ struct rte_cryptodev * return 0; } +static int +rte_cryptodev_asym_queue_pairs_config(struct rte_cryptodev *dev, + uint16_t nb_qpairs, int socket_id) +{ + struct rte_cryptodev_info dev_info; + void **qp; + unsigned i; + uint16_t sym_nb_qps = dev->data->nb_queue_pairs; + + if ((dev == NULL) || (nb_qpairs < 1)) { + CDEV_LOG_ERR("invalid param: dev %p, nb_queues %u", + dev, nb_qpairs); + return -EINVAL; + } + + CDEV_LOG_DEBUG("Setup asym %d queues pairs on device %u", + nb_qpairs, dev->data->dev_id); + + memset(&dev_info, 0, sizeof(struct rte_cryptodev_info)); + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); + (*dev->dev_ops->dev_infos_get)(dev, &dev_info); + + if ((nb_qpairs + sym_nb_qps) > (dev_info.max_nb_queue_pairs)) { + CDEV_LOG_ERR("Invalid num asym queue_pairs (%u) for dev %u", + nb_qpairs, dev->data->dev_id); + return -EINVAL; + } + + if (dev->data->asym_queue_pairs == NULL) { + /* first time configuration */ + dev->data->asym_queue_pairs = rte_zmalloc_socket( + "cryptodev->queue_pairs", + sizeof(dev->data->asym_queue_pairs[0]) * nb_qpairs, + RTE_CACHE_LINE_SIZE, socket_id); + + if (dev->data->asym_queue_pairs == NULL) { + dev->data->asym_nb_queue_pairs = 0; + CDEV_LOG_ERR("failed to get memory for asym " + "qp meta data, " + "nb_queues %u", + nb_qpairs); + return -(ENOMEM); + } + } else { /* re-configure */ + int ret; + uint16_t old_nb_queues = dev->data->asym_nb_queue_pairs; + + qp = dev->data->asym_queue_pairs; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release, + -ENOTSUP); + + for (i = nb_qpairs; i < old_nb_queues; i++) { + ret = (*dev->dev_ops->queue_pair_release)(dev, i); + if (ret < 0) + return ret; + } + + qp = rte_realloc(qp, sizeof(qp[0]) * nb_qpairs, + RTE_CACHE_LINE_SIZE); + if (qp == NULL) { + CDEV_LOG_ERR("failed to realloc asym qp meta data," + " nb_queues %u", nb_qpairs); + return -(ENOMEM); + } + + if (nb_qpairs > old_nb_queues) { + uint16_t new_qs = nb_qpairs - old_nb_queues; + + memset(qp + old_nb_queues, 0, + sizeof(qp[0]) * new_qs); + } + + dev->data->asym_queue_pairs = qp; + + } + dev->data->asym_nb_queue_pairs = nb_qpairs; + return 0; +} + int rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id) { @@ -1368,6 +1458,10 @@ struct rte_cryptodev * rte_cryptodev_sym_session_pool_create(struct rte_cryptodev *dev, unsigned nb_objs, unsigned obj_cache_size, int socket_id); +static int +rte_cryptodev_asym_session_pool_create(struct rte_cryptodev *dev, + unsigned nb_objs, unsigned obj_cache_size, int socket_id); + int rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config) { @@ -1398,6 +1492,16 @@ struct rte_cryptodev * return diag; } + /* Setup new number of asym queue pairs and reconfigure device. */ + diag = rte_cryptodev_asym_queue_pairs_config(dev, + config->asym_nb_queue_pairs, config->socket_id); + if (diag != 0) { + CDEV_LOG_ERR("dev%d rte_crypto_dev_asym_queue_pairs_config" + " = %d", + dev_id, diag); + return diag; + } + /* Setup Session mempool for device */ diag = rte_cryptodev_sym_session_pool_create(dev, config->session_mp.nb_objs, @@ -1406,6 +1510,15 @@ struct rte_cryptodev * if (diag != 0) return diag; + /* Setup Session mempool for device */ + diag = rte_cryptodev_asym_session_pool_create(dev, + config->asym_session_mp.nb_objs, + config->asym_session_mp.cache_size, + config->socket_id); + if (diag != 0) + return diag; + + return (*dev->dev_ops->dev_configure)(dev, config); } @@ -1496,6 +1609,16 @@ struct rte_cryptodev * return -EBUSY; } } + if (dev->data->asym_session_pool != NULL) { + if (!rte_mempool_full(dev->data->asym_session_pool)) { + CDEV_LOG_ERR("dev_id=%u close failed, session mempool " + "has sessions still in use, free " + "all sessions before calling close", + (unsigned)dev_id); + return -EBUSY; + } + } + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); retval = (*dev->dev_ops->dev_close)(dev); @@ -1535,6 +1658,35 @@ struct rte_cryptodev * socket_id); } +int +rte_cryptodev_asym_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, + const struct rte_cryptodev_qp_conf *qp_conf, int socket_id) +{ + struct rte_cryptodev *dev; + + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { + CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id); + return -EINVAL; + } + + dev = &rte_crypto_devices[dev_id]; + if (queue_pair_id >= dev->data->asym_nb_queue_pairs) { + CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id); + return -EINVAL; + } + + if (dev->data->dev_started) { + CDEV_LOG_ERR( + "device %d must be stopped to allow configuration", dev_id); + return -EBUSY; + } + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_setup, -ENOTSUP); + + return (*dev->dev_ops->asym_queue_pair_setup)(dev, queue_pair_id, + qp_conf, socket_id); +} + int rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats) @@ -1730,6 +1882,25 @@ struct rte_cryptodev * (*dev->dev_ops->session_initialize)(mp, sess); } +static void +rte_cryptodev_asym_session_init(struct rte_mempool *mp, + void *opaque_arg, + void *_sess, + __rte_unused unsigned i) +{ + struct rte_cryptodev_asym_session *sess = _sess; + struct rte_cryptodev *dev = opaque_arg; + + memset(sess, 0, mp->elt_size); + + sess->dev_id = dev->data->dev_id; + sess->dev_type = dev->dev_type; + sess->mp = mp; + + if (dev->dev_ops->asym_session_initialize) + (*dev->dev_ops->asym_session_initialize)(mp, sess); +} + static int rte_cryptodev_sym_session_pool_create(struct rte_cryptodev *dev, unsigned nb_objs, unsigned obj_cache_size, int socket_id) @@ -1792,6 +1963,70 @@ struct rte_cryptodev * return 0; } +static int +rte_cryptodev_asym_session_pool_create(struct rte_cryptodev *dev, + unsigned nb_objs, unsigned obj_cache_size, int socket_id) +{ + char mp_name[RTE_CRYPTODEV_NAME_MAX_LEN]; + unsigned priv_sess_size; + + unsigned n = snprintf(mp_name, sizeof(mp_name), "cdev_%d_sess_mp", + dev->data->dev_id); + if (n > sizeof(mp_name)) { + CDEV_LOG_ERR("Unable to create unique name for" + " session mempool"); + return -ENOMEM; + } + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_get_size, + -ENOTSUP); + priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev); + if (priv_sess_size == 0) { + CDEV_LOG_ERR("%s returned and invalid private session size ", + dev->data->name); + return -ENOMEM; + } + + unsigned elt_size = sizeof(struct rte_cryptodev_asym_session) + + priv_sess_size; + + dev->data->asym_session_pool = rte_mempool_lookup(mp_name); + if (dev->data->asym_session_pool != NULL) { + if ((dev->data->asym_session_pool->elt_size != elt_size) || + (dev->data->asym_session_pool->cache_size < + obj_cache_size) || + (dev->data->asym_session_pool->size < nb_objs)) { + + CDEV_LOG_ERR("%s mempool already exists with different" + " initialization parameters", mp_name); + dev->data->asym_session_pool = NULL; + return -ENOMEM; + } + } else { + dev->data->asym_session_pool = rte_mempool_create( + mp_name, /* mempool name */ + nb_objs, /* number of elements*/ + elt_size, /* element size*/ + obj_cache_size, /* Cache size*/ + 0, /* private data size */ + NULL, /* obj initialization constructor */ + NULL, /* obj initialization constructor arg */ + rte_cryptodev_asym_session_init, + /**< obj constructor*/ + dev, /* obj constructor arg */ + socket_id, /* socket id */ + 0); /* flags */ + + if (dev->data->asym_session_pool == NULL) { + CDEV_LOG_ERR("%s mempool allocation failed", mp_name); + return -ENOMEM; + } + } + + CDEV_LOG_DEBUG("%s mempool created!", mp_name); + return 0; +} + struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(uint8_t dev_id, struct rte_crypto_sym_xform *xform) @@ -1829,6 +2064,43 @@ struct rte_cryptodev_sym_session * return sess; } +struct rte_cryptodev_asym_session * +rte_cryptodev_asym_session_create(uint8_t dev_id, + struct rte_crypto_asym_xform *xform) +{ + struct rte_cryptodev *dev; + struct rte_cryptodev_asym_session *sess; + void *_sess; + + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { + CDEV_LOG_ERR("Invalid dev_id=%d", dev_id); + return NULL; + } + + dev = &rte_crypto_devices[dev_id]; + + /* Allocate a session structure from the session pool */ + if (rte_mempool_get(dev->data->asym_session_pool, &_sess)) { + CDEV_LOG_ERR("Couldn't get object from session mempool"); + return NULL; + } + + sess = (struct rte_cryptodev_asym_session *)_sess; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->session_configure, NULL); + if (dev->dev_ops->asym_session_configure(dev, xform, sess->_private) == + NULL) { + CDEV_LOG_ERR("dev_id %d failed to configure session details", + dev_id); + + /* Return session to mempool */ + rte_mempool_put(sess->mp, _sess); + return NULL; + } + + return sess; +} + int rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id, struct rte_cryptodev_sym_session *sess) @@ -1854,6 +2126,30 @@ struct rte_cryptodev_sym_session * } int +rte_cryptodev_queue_pair_attach_asym_session(uint16_t qp_id, + struct rte_cryptodev_asym_session *sess) +{ + struct rte_cryptodev *dev; + + if (!rte_cryptodev_pmd_is_valid_dev(sess->dev_id)) { + CDEV_LOG_ERR("Invalid dev_id=%d", sess->dev_id); + return -EINVAL; + } + + dev = &rte_crypto_devices[sess->dev_id]; + + /* The API is optional, not returning error if driver do not suuport */ + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_qp_attach_session, 0); + if (dev->dev_ops->asym_qp_attach_session(dev, qp_id, sess->_private)) { + CDEV_LOG_ERR("dev_id %d failed to attach qp: %d with session", + sess->dev_id, qp_id); + return -EPERM; + } + + return 0; +} + +int rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id, struct rte_cryptodev_sym_session *sess) { @@ -1876,6 +2172,31 @@ struct rte_cryptodev_sym_session * return 0; } + +int +rte_cryptodev_queue_pair_detach_asym_session(uint16_t qp_id, + struct rte_cryptodev_asym_session *sess) +{ + struct rte_cryptodev *dev; + + if (!rte_cryptodev_pmd_is_valid_dev(sess->dev_id)) { + CDEV_LOG_ERR("Invalid dev_id=%d", sess->dev_id); + return -EINVAL; + } + + dev = &rte_crypto_devices[sess->dev_id]; + + /* The API is optional, not returning error if driver do not suuport */ + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_qp_detach_session, 0); + if (dev->dev_ops->asym_qp_detach_session(dev, qp_id, sess->_private)) { + CDEV_LOG_ERR("dev_id %d failed to detach qp: %d from session", + sess->dev_id, qp_id); + return -EPERM; + } + + return 0; +} + struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_free(uint8_t dev_id, struct rte_cryptodev_sym_session *sess) @@ -1903,6 +2224,33 @@ struct rte_cryptodev_sym_session * return NULL; } +struct rte_cryptodev_asym_session * +rte_cryptodev_asym_session_free(uint8_t dev_id, + struct rte_cryptodev_asym_session *sess) +{ + struct rte_cryptodev *dev; + + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { + CDEV_LOG_ERR("Invalid dev_id=%d", dev_id); + return sess; + } + + dev = &rte_crypto_devices[dev_id]; + + /* Check the session belongs to this device type */ + if (sess->dev_type != dev->dev_type) + return sess; + + /* Let device implementation clear session material */ + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, sess); + dev->dev_ops->asym_session_clear(dev, (void *)sess->_private); + + /* Return session to mempool */ + rte_mempool_put(sess->mp, (void *)sess); + + return NULL; +} + /** Initialise rte_crypto_op mempool element */ static void rte_crypto_op_init(struct rte_mempool *mempool, @@ -1930,7 +2278,9 @@ struct rte_mempool * struct rte_crypto_op_pool_private *priv; unsigned elt_size = sizeof(struct rte_crypto_op) + - sizeof(struct rte_crypto_sym_op) + + (type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) ? + sizeof(struct rte_crypto_sym_op) : + sizeof(struct rte_crypto_asym_op) + priv_size; /* lookup mempool in case already allocated */ diff --git lib/librte_cryptodev/rte_cryptodev.h lib/librte_cryptodev/rte_cryptodev.h index f5f5a73..edfd8fd 100644 --- lib/librte_cryptodev/rte_cryptodev.h +++ lib/librte_cryptodev/rte_cryptodev.h @@ -674,6 +674,11 @@ struct rte_cryptodev_info { * Default 0 for infinite sessions */ } sym; + + struct { + unsigned max_nb_sessions; + /**< Maximum number of sessions supported by device. */ + } asym; }; #define RTE_CRYPTODEV_DETACHED (0) @@ -827,11 +832,18 @@ struct rte_cryptodev_config { int socket_id; /**< Socket to allocate resources on */ uint16_t nb_queue_pairs; /**< Number of queue pairs to configure on device */ + uint16_t asym_nb_queue_pairs; + /**< Number of asym_queue pairs to configure on device */ struct { uint32_t nb_objs; /**< Number of objects in mempool */ uint32_t cache_size; /**< l-core object cache size */ } session_mp; /**< Session mempool configuration */ + + struct { + uint32_t nb_objs; /**< Number of objects in mempool */ + uint32_t cache_size; /**< l-core object cache size */ + } asym_session_mp; /**< Session mempool configuration */ }; /** @@ -1098,11 +1110,22 @@ struct rte_cryptodev_data { struct rte_mempool *session_pool; /**< Session memory pool */ + + struct rte_mempool *asym_session_pool; + /**< Asymmetric xform session memory pool */ + void **queue_pairs; /**< Array of pointers to queue pairs. */ + + void **asym_queue_pairs; + /**< Array of pointers to asymmetric queue pairs */ + uint16_t nb_queue_pairs; /**< Number of device queue pairs. */ + uint16_t asym_nb_queue_pairs; + /**< Number of device queue pairs for asym ops */ + void *dev_private; /**< PMD-specific private data */ } __rte_cache_aligned; @@ -1216,6 +1239,24 @@ struct rte_cryptodev_sym_session { }; +/** Cryptodev symmetric crypto session */ +struct rte_cryptodev_asym_session { + RTE_STD_C11 + struct { + uint8_t dev_id; + /**< Device Id */ + enum rte_cryptodev_type dev_type; + /** Crypto Device type session created on */ + struct rte_mempool *mp; + /**< Mempool session allocated from */ + } __rte_aligned(8); + /**< Public asymmetric session details */ + + __extension__ char _private[0]; + /**< Private session material */ +}; + + /** * Initialise a session for symmetric cryptographic operations. * @@ -1241,6 +1282,32 @@ struct rte_cryptodev_sym_session { rte_cryptodev_sym_session_create(uint8_t dev_id, struct rte_crypto_sym_xform *xform); + +/** + * Initialise a session for asymmetric cryptographic operations. + * + * This function is used by the client to initialize immutable + * parameters of asymmetric cryptographic operation. + * To perform the operation the rte_cryptodev_enqueue_burst function is + * used. Each mbuf should contain a reference to the session + * pointer returned from this function contained within it's crypto_op if a + * session-based operation is being provisioned. Memory to contain the session + * information is allocated from within mempool managed by the cryptodev. + * + * The rte_cryptodev_session_free must be called to free allocated + * memory when the session is no longer required. + * + * @param dev_id The device identifier. + * @param xform Crypto transform chain. + + * + * @return + * Pointer to the created session or NULL + */ +extern struct rte_cryptodev_asym_session * +rte_cryptodev_asym_session_create(uint8_t dev_id, + struct rte_crypto_asym_xform *xform); + /** * Free the memory associated with a previously allocated session. * @@ -1257,6 +1324,19 @@ struct rte_cryptodev_sym_session { struct rte_cryptodev_sym_session *session); /** + * Free the memory associated with a previously allocated session. + * + * @param dev_id The device identifier. + * @param session Session pointer previously allocated by + * *rte_cryptodev_asym_session_create*. + * + * @return + * NULL on successful freeing of session. + * Session pointer on failure to free session. + */ +extern struct rte_cryptodev_asym_session * +rte_cryptodev_asym_session_free(uint8_t dev_id, + struct rte_cryptodev_asym_session *session); * Attach queue pair with sym session. * * @param qp_id Queue pair to which session will be attached. diff --git lib/librte_cryptodev/rte_cryptodev_pmd.h lib/librte_cryptodev/rte_cryptodev_pmd.h index 17ef37c..31c5804 100644 --- lib/librte_cryptodev/rte_cryptodev_pmd.h +++ lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -327,6 +327,22 @@ typedef int (*cryptodev_sym_create_session_pool_t)( struct rte_cryptodev *dev, unsigned nb_objs, unsigned obj_cache_size, int socket_id); +/** + * Create asymmetric session mempool to allocate sessions from + * + * @param dev Crypto device pointer + * @param nb_objs number of sessions objects in mempool + * @param obj_cache l-core object cache size, see *rte_ring_create* + * @param socket_id Socket Id to allocate mempool on. + * + * @return + * - On success returns a pointer to a rte_mempool + * - On failure returns a NULL pointer + */ +typedef int (*cryptodev_asym_create_session_pool_t)( + struct rte_cryptodev *dev, unsigned nb_objs, + unsigned obj_cache_size, int socket_id); + /** * Get the size of a cryptodev session @@ -341,6 +357,18 @@ typedef unsigned (*cryptodev_sym_get_session_private_size_t)( struct rte_cryptodev *dev); /** + * Get the size of an 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 (*cryptodev_asym_get_session_private_size_t)( + struct rte_cryptodev *dev); + +/** * Initialize a Crypto session on a device. * * @param dev Crypto device pointer @@ -355,6 +383,20 @@ typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool, void *session_private); /** + * Initialize an asymmetric Crypto 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 + * + * @return + * - Returns private session structure on success. + * - Returns NULL on failure. + */ +typedef void (*cryptodev_asym_initialize_session_t)(struct rte_mempool *mempool, + void *session_private); + +/** * Configure a Crypto session on a device. * * @param dev Crypto device pointer @@ -369,6 +411,20 @@ typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool, struct rte_crypto_sym_xform *xform, void *session_private); /** + * Configure an asymmetric Crypto session on a device. + * + * @param dev Crypto device pointer + * @param xform Single or chain of asymmetric crypto xforms + * @param priv_sess Pointer to cryptodev's private session structure + * + * @return + * - Returns private session structure on success. + * - Returns NULL on failure. + */ +typedef void *(*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev, + struct rte_crypto_asym_xform *xform, void *session_private); + +/** * Free Crypto session. * @param session Cryptodev session structure to free */ @@ -376,6 +432,13 @@ typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev, void *session_private); /** + * Free asymmetric Crypto session. + * @param session Cryptodev session structure to free + */ +typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev, + void *session_private); + +/** * Optional API for drivers to attach sessions with queue pair. * @param dev Crypto device pointer * @param qp_id queue pair id for attaching session @@ -389,6 +452,19 @@ typedef int (*cryptodev_sym_queue_pair_attach_session_t)( void *session_private); /** + * Optional API for drivers to attach asymmetric sessions with queue pair. + * @param dev Crypto device pointer + * @param qp_id queue pair id for attaching session + * @param priv_sess Pointer to cryptodev's private session structure + * @return + * - Return 0 on success + */ +typedef int (*cryptodev_asym_queue_pair_attach_session_t)( + struct rte_cryptodev *dev, + uint16_t qp_id, + void *session_private); + +/** * Optional API for drivers to detach sessions from queue pair. * @param dev Crypto device pointer * @param qp_id queue pair id for detaching session @@ -401,6 +477,20 @@ typedef int (*cryptodev_sym_queue_pair_detach_session_t)( uint16_t qp_id, void *session_private); +/** + * Optional API for drivers to detach asymmetric sessions from queue pair. + * @param dev Crypto device pointer + * @param qp_id queue pair id for detaching session + * @param priv_sess Pointer to cryptodev's private session + * structure. + * @return + * - Return 0 on success + */ +typedef int (*cryptodev_asym_queue_pair_detach_session_t)( + struct rte_cryptodev *dev, + uint16_t qp_id, + void *session_private); + /** Crypto device operations function pointer table */ struct rte_cryptodev_ops { cryptodev_configure_t dev_configure; /**< Configure device. */ @@ -426,18 +516,41 @@ struct rte_cryptodev_ops { cryptodev_queue_pair_count_t queue_pair_count; /**< Get count of the queue pairs. */ + cryptodev_queue_pair_setup_t asym_queue_pair_setup; + /**< Set up a device queue pair. */ + cryptodev_queue_pair_release_t asym_queue_pair_release; + /**< Release a queue pair. */ + cryptodev_queue_pair_start_t asym_queue_pair_start; + /**< Start a queue pair. */ + cryptodev_queue_pair_stop_t asym_queue_pair_stop; + /**< Stop a queue pair. */ + cryptodev_queue_pair_count_t asym_queue_pair_count; + /**< Get count of the queue pairs. */ + 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 asymmetric private session. */ cryptodev_sym_initialize_session_t session_initialize; /**< Initialization function for private session data */ + cryptodev_asym_initialize_session_t asym_session_initialize; + /**< Initialization asymmetric function for private session data */ cryptodev_sym_configure_session_t session_configure; /**< Configure a Crypto session. */ + cryptodev_asym_configure_session_t asym_session_configure; + /**< Configure an 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 an asymmetric Crypto sessions private data. */ cryptodev_sym_queue_pair_attach_session_t qp_attach_session; /**< Attach session to queue pair. */ + cryptodev_asym_queue_pair_attach_session_t asym_qp_attach_session; + /**< Attach asymmetric session to queue pair. */ cryptodev_sym_queue_pair_attach_session_t qp_detach_session; /**< Detach session from queue pair. */ + cryptodev_asym_queue_pair_attach_session_t asym_qp_detach_session; + /**< Detach asymmetric session from queue pair. */ };