From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C148EA04DD; Wed, 21 Oct 2020 09:28:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 365ABAC78; Wed, 21 Oct 2020 09:28:14 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140057.outbound.protection.outlook.com [40.107.14.57]) by dpdk.org (Postfix) with ESMTP id 8AD60AC6E for ; Wed, 21 Oct 2020 09:28:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CmU+99/bmwyrvPBtz5NCdm4lLkWSVvu8POvN1B6dFds=; b=8i1GHRxWlRXrNJyGU3+wLl+wZqCHcOL9k0gQb5nAfkmyvWtCEeDYWEBcDXuAIfoef2nsYIH1n0zYUHuQeeleskSLu4AuIkkCBTbpM9069jwIzKsbrKwu2b/AOtnr9omB4ljikIxkwcwB5t3rUe+heCxblk/c41k8etAJmawtekU= Received: from MR2P264CA0099.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::15) by VI1PR08MB5536.eurprd08.prod.outlook.com (2603:10a6:803:13b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.27; Wed, 21 Oct 2020 07:28:09 +0000 Received: from VE1EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:33:cafe::1b) by MR2P264CA0099.outlook.office365.com (2603:10a6:500:33::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Wed, 21 Oct 2020 07:28:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT039.mail.protection.outlook.com (10.152.19.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Wed, 21 Oct 2020 07:28:08 +0000 Received: ("Tessian outbound c579d876a324:v64"); Wed, 21 Oct 2020 07:28:08 +0000 X-CR-MTA-TID: 64aa7808 Received: from f197a673b5d8.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id B2BB7187-8189-4CEF-8A47-827466546034.1; Wed, 21 Oct 2020 07:28:03 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f197a673b5d8.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 21 Oct 2020 07:28:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghDLx/9SmNxLiet0ySCiXs8erExQbf+OSKHf0INJROPrnZ5OQDs5xZKn4wfl+3TNyGleuoiTBL86JKxOAIJDvDlZU61tvpA637SOCmJTpC9KuqhYXQUG4wwriNgjAkyvwWcgsiD8CYZ0RZ738KgMGjV9fXP3OQRZq8G3jZYicYiGP0uPbZMF81DrXwzzCNDCAXK4+NSkMQvJ19I6F5dUC/GFL4wEYeTKZ9vWyWoGQA2clisDIE3K11DJlNllh1wAgqF4vgGOaZGAr1jarWaRxk/zfGbpQakzpUdC7HMbQ5D3w2uCIk7VJkS8LjcRri0mDmgjlH8C4m9lfBLVUtlcSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CmU+99/bmwyrvPBtz5NCdm4lLkWSVvu8POvN1B6dFds=; b=aK1rduzwktBPg5EnoSf8NPcwgOsHOeYmyz0loO9p6tp6ntqFJ+UzUEHDu1vZbW9HTG1BpSd6qST02AnLOtq2imL88dPlLR4yGGVFcb8J8jj82dNvLEl530Y9HU5Lvd3rL/Mzfh5blWtVw35SGgAn1MfIflhmQUCW5Ky71lBA3OXRw9UHF0+1398hrhyvCtl8he8Uo/VU689kSe/LmImTavL3PJUtZYrSHMIdesJ7L503C815ZYFCL/5drcTjjpkH1fZ9QjjeJPtxW6MR1eBZ/r0q4MHbS5P4NikFBB1KFum7ZuhbyKA2IUxIRSO1TnYE6FpeV6oLOTiwv7Vunf6Krg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CmU+99/bmwyrvPBtz5NCdm4lLkWSVvu8POvN1B6dFds=; b=8i1GHRxWlRXrNJyGU3+wLl+wZqCHcOL9k0gQb5nAfkmyvWtCEeDYWEBcDXuAIfoef2nsYIH1n0zYUHuQeeleskSLu4AuIkkCBTbpM9069jwIzKsbrKwu2b/AOtnr9omB4ljikIxkwcwB5t3rUe+heCxblk/c41k8etAJmawtekU= Received: from DBAPR08MB5814.eurprd08.prod.outlook.com (2603:10a6:10:1b1::6) by DB6PR0801MB1704.eurprd08.prod.outlook.com (2603:10a6:4:38::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.25; Wed, 21 Oct 2020 07:28:01 +0000 Received: from DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::7814:9c1:781f:475d]) by DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::7814:9c1:781f:475d%4]) with mapi id 15.20.3499.018; Wed, 21 Oct 2020 07:28:00 +0000 From: Honnappa Nagarahalli To: Abhinandan Gujjar , "dev@dpdk.org" , "declan.doherty@intel.com" , "Akhil.goyal@nxp.com" , "konstantin.ananyev@intel.com" CC: "narender.vangati@intel.com" , "jerinj@marvell.com" , nd , Honnappa Nagarahalli , nd Thread-Topic: [v3 1/2] cryptodev: support enqueue callback functions Thread-Index: AQHWptllq7GOu+oRQk6DYPuWT9LH7qmhpusQ Date: Wed, 21 Oct 2020 07:28:00 +0000 Message-ID: References: <1603076242-41883-1-git-send-email-abhinandan.gujjar@intel.com> <1603076242-41883-2-git-send-email-abhinandan.gujjar@intel.com> In-Reply-To: <1603076242-41883-2-git-send-email-abhinandan.gujjar@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 05B944CD6DE32D4D93B3B0093B4FA705.0 x-checkrecipientchecked: true Authentication-Results-Original: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [70.113.13.105] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 83eb5531-fcf0-42f0-bf68-08d87592dbfa x-ms-traffictypediagnostic: DB6PR0801MB1704:|VI1PR08MB5536: x-ld-processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XOs2exoPAcb0sEHbhT4A+4Pufv4FvJQMTRQ7TnlQjTiQNodpIQDR2TZv0WKlJE44LQI99urDYPpiBMRwSMyGgiFCTFVDK9CPsUOQ8plOPnRjXX75QlqsqfMf2VlZ0YB8hMEjVLbPeyOPE1g74TZkouHKhNXHQBsmdeE4jq23K0f5w81yaVghF2FLURkDLdvY6VUdi0VK5mTnlrg1Z9scf9fOj+F/Y82IHCr68t40HjbN0toBMF4inaIRaRRXMxy6sQmC93x3sklJEyEKIy8T/Ky5I/WQ4ruk5qI91VpjQF6ythaEXo9WnmNl2MiYdW4rdwFJgl49LsuYie6vef7mWW3+AjV7pcondmx9fOE+YWJ4KF1N/Ef/FzRSJo5y3rjIN9BscftN2xZwN7PADWWo6A== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBAPR08MB5814.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(346002)(396003)(39860400002)(136003)(55016002)(52536014)(186003)(76116006)(54906003)(66476007)(66446008)(66556008)(7696005)(110136005)(64756008)(26005)(8676002)(66946007)(966005)(30864003)(83380400001)(4326008)(316002)(478600001)(33656002)(2906002)(71200400001)(8936002)(86362001)(6506007)(5660300002)(9686003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: 41qUaE1zHe8bmT2n0tVeXsHzNGU+EseLPeDM44IKntfVPiP9smgUmqoRj4ywEUbVRCas8yDVGfRBEr4fyC9E3KCX4f8LKUaTMuF/IftDn2hqdNnQux9QhEWGDuLttn/hRWPvntpS0jawnh6nXollxSPiMBLQvlgy0Y9FikN+ky98Ye0ZfthW8VsMUVc9WWqLr18R/K9r74oWU73hGStNp40/rGP9JPRReHemAO72Qc7AkmbVnDqC4sigYMjiiKOdiew2Lij6uq7n3jIjaOTAH+jG019tve8uDCtrPYxGVenR6S8/VdvbLsWgxC7vG1YU5pATliDrMeoqQrvhYbtGjga0FdT4yx5Had1Lb0jg3L3p5aMUX0D5/+a4tpLAqfo9DPM/J6A/jmgwHJEffVKEN6343Ybr7Gl7Krd3CmYCnOpCxSf748YNFHbrYm4CDxKeiZ5lpIoY3d2W02YKfVgggY6+598wp9Xm3pO4tPVNefIgnx3Sk9kk4Sdjr+iyUpyYPAg8iLZ1rgZ9CoY5UCRPFVWA0bbbGMveHfMLpV7MygV5bAI76Xrd9DjCD4Kv42eJW3a8kHz6Eos6YbPhLDv/U9pmnw8i/9+psOa/tojRnJnrmCcYYhyPUulm7/7o7GU27cEn+eTx1zOuyR8oPRXW9w== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1704 Original-Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 67bb76ec-9d73-47cb-a6d3-08d87592d73d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fgg/zu8zHVjEIn4fQHBspfOYT38ChLsoVlg+vrevA9bais0k2py9sms/F2x8KrYXBBGpLfhpeRdPJ3aJRN/LCsDNjtEMw1OJRI5+dpD8YP0Bnd0jFiZYZjhc4mok/4SjepkcBPiPlLCn4ZQk5uHYO/iMUPAOYdTuXVKsuH+wmHyQB2X2f0MLVIjNR+5exQx5qFM3p4z5EdfXtXzcSzkP/bBm5JO3mgNV7ITtH0KqFzFyJlnJcnmUQyEYHzOVo+e3NJprPpmA8UYi7OM/mliGvKRJWQc6U7l5zUq5T3qtoCOoM2TC6GOjOH88odFbeTNTDNgzjQzCjpwficYLYNNuhg1/kBykILy3GiJGiweMLTuJSY5WmQoYB1I9Cyklxh2qDPKBov/YRlpOtw8dth0ZAm+3XeqDBeC7BX4Yg+K+ydky5+AZcocMtJeAxqcmYeOXFIhDP01V13ObA+ApdAEp9dsldEVGINtUvT1OefNvBfo= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(346002)(396003)(136003)(39860400002)(376002)(46966005)(9686003)(2906002)(70206006)(70586007)(52536014)(966005)(30864003)(478600001)(5660300002)(36906005)(110136005)(33656002)(82740400003)(83380400001)(4326008)(8936002)(81166007)(8676002)(336012)(47076004)(6506007)(86362001)(316002)(82310400003)(26005)(54906003)(356005)(186003)(55016002)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2020 07:28:08.7761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83eb5531-fcf0-42f0-bf68-08d87592dbfa X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5536 Subject: Re: [dpdk-dev] [v3 1/2] cryptodev: support enqueue callback functions 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" >=20 > This patch adds APIs to add/remove callback functions. The callback funct= ion > will be called for each burst of crypto ops received on a given crypto de= vice > queue pair. >=20 > Signed-off-by: Abhinandan Gujjar > --- > config/rte_config.h | 1 + > lib/librte_cryptodev/meson.build | 2 +- > lib/librte_cryptodev/rte_cryptodev.c | 201 > +++++++++++++++++++++++++ > lib/librte_cryptodev/rte_cryptodev.h | 153 ++++++++++++++++++- > lib/librte_cryptodev/rte_cryptodev_version.map | 2 + > 5 files changed, 357 insertions(+), 2 deletions(-) >=20 > diff --git a/config/rte_config.h b/config/rte_config.h index 03d90d7..e99= 9d93 > 100644 > --- a/config/rte_config.h > +++ b/config/rte_config.h > @@ -61,6 +61,7 @@ > /* cryptodev defines */ > #define RTE_CRYPTO_MAX_DEVS 64 > #define RTE_CRYPTODEV_NAME_LEN 64 > +#define RTE_CRYPTO_CALLBACKS 1 >=20 > /* compressdev defines */ > #define RTE_COMPRESS_MAX_DEVS 64 > diff --git a/lib/librte_cryptodev/meson.build b/lib/librte_cryptodev/meso= n.build > index c4c6b3b..8c5493f 100644 > --- a/lib/librte_cryptodev/meson.build > +++ b/lib/librte_cryptodev/meson.build > @@ -9,4 +9,4 @@ headers =3D files('rte_cryptodev.h', > 'rte_crypto.h', > 'rte_crypto_sym.h', > 'rte_crypto_asym.h') > -deps +=3D ['kvargs', 'mbuf'] > +deps +=3D ['kvargs', 'mbuf', 'rcu'] > diff --git a/lib/librte_cryptodev/rte_cryptodev.c > b/lib/librte_cryptodev/rte_cryptodev.c > index 3d95ac6..5ba774a 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.c > +++ b/lib/librte_cryptodev/rte_cryptodev.c > @@ -448,6 +448,10 @@ struct > rte_cryptodev_sym_session_pool_private_data { > return 0; > } >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > +/* spinlock for crypto device enq callbacks */ static rte_spinlock_t > +rte_cryptodev_enq_cb_lock =3D RTE_SPINLOCK_INITIALIZER; #endif >=20 > const char * > rte_cryptodev_get_feature_name(uint64_t flag) @@ -1136,6 +1140,203 @@ > struct rte_cryptodev * > socket_id); > } >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > + > +struct rte_cryptodev_cb * > +rte_cryptodev_add_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + rte_cryptodev_callback_fn cb_fn, > + void *cb_arg) > +{ > + struct rte_cryptodev *dev; > + struct rte_cryptodev_cb *cb, *tail; > + struct rte_cryptodev_enq_cb_rcu *list; > + struct rte_rcu_qsbr *qsbr; > + size_t size; > + > + /* Max thread set to 1, as one DP thread accessing a queue-pair */ > + const uint32_t max_threads =3D 1; > + > + if (!cb_fn) > + return NULL; > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + return NULL; > + } > + > + dev =3D &rte_crypto_devices[dev_id]; > + if (qp_id >=3D dev->data->nb_queue_pairs) { > + CDEV_LOG_ERR("Invalid queue_pair_id=3D%d", qp_id); > + return NULL; > + } > + > + rte_spinlock_lock(&rte_cryptodev_enq_cb_lock); > + if (dev->enq_cbs =3D=3D NULL) { > + dev->enq_cbs =3D rte_zmalloc(NULL, sizeof(cb) * > + dev->data->nb_queue_pairs, 0); > + if (dev->enq_cbs =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for > callbacks"); > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + rte_errno =3D ENOMEM; > + return NULL; > + } > + > + list =3D rte_zmalloc(NULL, sizeof(*list), 0); > + if (list =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for list on " > + "dev=3D%d, queue_pair_id=3D%d", dev_id, qp_id); > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + rte_errno =3D ENOMEM; > + rte_free(dev->enq_cbs); > + return NULL; > + } > + > + /* Create RCU QSBR variable */ > + size =3D rte_rcu_qsbr_get_memsize(max_threads); > + qsbr =3D rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); > + if (qsbr =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for RCU on > " > + "dev=3D%d, queue_pair_id=3D%d", dev_id, qp_id); > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + rte_errno =3D ENOMEM; > + rte_free(list); > + rte_free(dev->enq_cbs); > + dev->enq_cbs[qp_id] =3D NULL; > + return NULL; > + } > + > + if (rte_rcu_qsbr_init(qsbr, max_threads)) { > + CDEV_LOG_ERR("Failed to initialize for RCU on " > + "dev=3D%d, queue_pair_id=3D%d", dev_id, qp_id); > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + rte_free(qsbr); > + rte_free(list); > + rte_free(dev->enq_cbs); > + dev->enq_cbs[qp_id] =3D NULL; > + return NULL; > + } > + > + dev->enq_cbs[qp_id] =3D list; > + list->qsbr =3D qsbr; > + } > + > + cb =3D rte_zmalloc(NULL, sizeof(*cb), 0); > + if (cb =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for callback on " > + "dev=3D%d, queue_pair_id=3D%d", dev_id, qp_id); > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + rte_errno =3D ENOMEM; > + return NULL; > + } > + > + cb->fn =3D cb_fn; > + cb->arg =3D cb_arg; > + > + /* Add the callbacks in fifo order. */ > + list =3D dev->enq_cbs[qp_id]; > + tail =3D list->next; > + if (tail) { > + while (tail->next) > + tail =3D tail->next; > + tail->next =3D cb; > + } else > + list->next =3D cb; > + Correct memory orderings need to be used to provide reader-writer concurren= cy. Please look at [1] for changes you need to make here. [1] https://patches.dpdk.org/patch/80603/ > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + > + return cb; > +} > + > +int > +rte_cryptodev_remove_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + struct rte_cryptodev_cb *cb) > +{ > + struct rte_cryptodev *dev; > + struct rte_cryptodev_cb **prev_cb, *curr_cb; > + struct rte_cryptodev_enq_cb_rcu *list; > + uint16_t qp; > + int free_mem; > + int ret; > + > + free_mem =3D 1; > + ret =3D -EINVAL; > + > + if (!cb) { > + CDEV_LOG_ERR("cb is NULL"); > + return ret; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + return ret; > + } > + > + dev =3D &rte_crypto_devices[dev_id]; > + if (qp_id >=3D dev->data->nb_queue_pairs) { > + CDEV_LOG_ERR("Invalid queue_pair_id=3D%d", qp_id); > + return ret; > + } > + > + list =3D dev->enq_cbs[qp_id]; > + if (list =3D=3D NULL) { > + CDEV_LOG_ERR("Callback list is NULL"); > + return ret; > + } > + > + if (list->qsbr =3D=3D NULL) { > + CDEV_LOG_ERR("Rcu qsbr is NULL"); > + return ret; > + } > + > + rte_spinlock_lock(&rte_cryptodev_enq_cb_lock); > + if (dev->enq_cbs =3D=3D NULL) { > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + return ret; > + } > + > + prev_cb =3D &list->next; > + for (; *prev_cb !=3D NULL; prev_cb =3D &curr_cb->next) { > + curr_cb =3D *prev_cb; > + if (curr_cb =3D=3D cb) { > + /* Remove the user cb from the callback list. */ > + *prev_cb =3D curr_cb->next; > + ret =3D 0; > + break; > + } > + } > + > + if (!ret) { > + /* Call sync with invalid thread id as this is part of > + * control plane API > + */ > + rte_rcu_qsbr_synchronize(list->qsbr, > RTE_QSBR_THRID_INVALID); > + rte_free(cb); > + } > + > + if (list->next =3D=3D NULL) { > + rte_free(list->qsbr); > + rte_free(list); > + dev->enq_cbs[qp_id] =3D NULL; > + } > + > + for (qp =3D 0; qp < dev->data->nb_queue_pairs; qp++) > + if (dev->enq_cbs[qp] !=3D NULL) { > + free_mem =3D 0; > + break; > + } > + > + if (free_mem) { > + rte_free(dev->enq_cbs); > + dev->enq_cbs =3D NULL; > + } > + > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + > + return ret; > +} > +#endif >=20 > int > rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stat= s) diff > --git a/lib/librte_cryptodev/rte_cryptodev.h > b/lib/librte_cryptodev/rte_cryptodev.h > index 0935fd5..669746d 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.h > +++ b/lib/librte_cryptodev/rte_cryptodev.h > @@ -23,6 +23,7 @@ > #include "rte_dev.h" > #include > #include > +#include >=20 > #include "rte_cryptodev_trace_fp.h" >=20 > @@ -522,6 +523,34 @@ struct rte_cryptodev_qp_conf { > /**< The mempool for creating sess private data in sessionless mode */ > }; >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > +/** > + * Function type used for pre processing crypto ops when enqueue burst > +is > + * called. > + * > + * The callback function is called on enqueue burst immediately > + * before the crypto ops are put onto the hardware queue for processing. > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair in which ops are > + * to be enqueued for processing. The value > + * must be in the range [0, nb_queue_pairs - 1] > + * previously supplied to > + * *rte_cryptodev_configure*. > + * @param ops The address of an array of *nb_ops* pointers > + * to *rte_crypto_op* structures which contain > + * the crypto operations to be processed. > + * @param nb_ops The number of operations to process. > + * @param user_param The arbitrary user parameter passed in by the > + * application when the callback was originally > + * registered. > + * @return The number of ops to be enqueued to the > + * crypto device. > + */ > +typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t > qp_id, > + struct rte_crypto_op **ops, uint16_t nb_ops, void > *user_param); > +#endif > + > /** > * Typedef for application callback function to be registered by applica= tion > * software for notification of device events @@ -822,7 +851,6 @@ struct > rte_cryptodev_config { > enum rte_cryptodev_event_type event, > rte_cryptodev_cb_fn cb_fn, void *cb_arg); >=20 > - > typedef uint16_t (*dequeue_pkt_burst_t)(void *qp, > struct rte_crypto_op **ops, uint16_t nb_ops); > /**< Dequeue processed packets from queue pair of a device. */ @@ -839,6 > +867,33 @@ typedef uint16_t (*enqueue_pkt_burst_t)(void *qp, > /** Structure to keep track of registered callbacks */ > TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback); >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > +/** > + * @internal > + * Structure used to hold information about the callbacks to be called > +for a > + * queue pair on enqueue. > + */ > +struct rte_cryptodev_cb { > + struct rte_cryptodev_cb *next; > + /** < Pointer to next callback */ > + rte_cryptodev_callback_fn fn; > + /** < Pointer to callback function */ > + void *arg; > + /** < Pointer to argument */ > +}; > + > +/** > + * @internal > + * Structure used to hold information about the RCU for a queue pair. > + */ > +struct rte_cryptodev_enq_cb_rcu { > + struct rte_cryptodev_cb *next; > + /** < Pointer to next callback */ > + struct rte_rcu_qsbr *qsbr; > + /** < RCU QSBR variable per queue pair */ }; #endif > + > /** The data structure associated with each crypto device. */ struct > rte_cryptodev { > dequeue_pkt_burst_t dequeue_burst; > @@ -867,6 +922,11 @@ struct rte_cryptodev { > __extension__ > uint8_t attached : 1; > /**< Flag indicating the device is attached */ > + > +#ifdef RTE_CRYPTO_CALLBACKS > + struct rte_cryptodev_enq_cb_rcu **enq_cbs; > + /**< User application callback for pre enqueue processing */ #endif > } __rte_cache_aligned; >=20 > void * > @@ -989,6 +1049,25 @@ struct rte_cryptodev_data { { > struct rte_cryptodev *dev =3D &rte_cryptodevs[dev_id]; >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > + if (unlikely(dev->enq_cbs !=3D NULL && dev->enq_cbs[qp_id] !=3D NULL)) = { > + struct rte_cryptodev_enq_cb_rcu *list; > + struct rte_cryptodev_cb *cb; > + > + list =3D dev->enq_cbs[qp_id]; > + cb =3D list->next; > + rte_rcu_qsbr_thread_online(list->qsbr, 0); Move this 2 lines up as you are reading the addresses. Also, look at the patch mentioned earlier for memory orderings. > + > + do { > + nb_ops =3D cb->fn(dev_id, qp_id, ops, nb_ops, > + cb->arg); > + cb =3D cb->next; > + } while (cb !=3D NULL); > + > + rte_rcu_qsbr_thread_offline(list->qsbr, 0); > + } > +#endif > + > rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, > nb_ops); > return (*dev->enqueue_burst)( > dev->data->queue_pairs[qp_id], ops, nb_ops); @@ - > 1730,6 +1809,78 @@ struct rte_crypto_raw_dp_ctx { > rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx, > uint32_t n); >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Add a user callback for a given crypto device and queue pair which > +will be > + * called on crypto ops enqueue. > + * > + * This API configures a function to be called for each burst of crypto > +ops > + * received on a given crypto device queue pair. The return value is a > +pointer > + * that can be used later to remove the callback using > + * rte_cryptodev_remove_enq_callback(). > + * > + * Multiple functions are called in the order that they are added. > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair in which ops are > + * to be enqueued for processing. The value > + * must be in the range [0, nb_queue_pairs - 1] > + * previously supplied to > + * *rte_cryptodev_configure*. > + * @param cb_fn The callback function > + * @param cb_arg A generic pointer parameter which will be > passed > + * to each invocation of the callback function on > + * this crypto device and queue pair. > + * > + * @return > + * NULL on error. > + * On success, a pointer value which can later be used to remove the c= allback. > + */ > + > +__rte_experimental > +struct rte_cryptodev_cb * > +rte_cryptodev_add_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + rte_cryptodev_callback_fn cb_fn, > + void *cb_arg); > + > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Remove a user callback function for given crypto device and queue pai= r. > + * > + * This function is used to removed callbacks that were added to a > +crypto > + * device queue pair using rte_cryptodev_add_enq_callback(). > + * > + * > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair in which ops are > + * to be enqueued for processing. The value > + * must be in the range [0, nb_queue_pairs - 1] > + * previously supplied to > + * *rte_cryptodev_configure*. > + * @param cb Pointer to user supplied callback created via > + * rte_cryptodev_add_enq_callback(). > + * > + * @return > + * - 0: Success. Callback was removed. > + * - -EINVAL: The dev_id or the qp_id is out of range, or the callbac= k > + * is NULL or not found for the crypto device queue pair. > + */ > + > +__rte_experimental > +int rte_cryptodev_remove_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + struct rte_cryptodev_cb *cb); > + > +#endif > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map > b/lib/librte_cryptodev/rte_cryptodev_version.map > index 7e4360f..5d8d6b0 100644 > --- a/lib/librte_cryptodev/rte_cryptodev_version.map > +++ b/lib/librte_cryptodev/rte_cryptodev_version.map > @@ -101,6 +101,7 @@ EXPERIMENTAL { > rte_cryptodev_get_qp_status; >=20 > # added in 20.11 > + rte_cryptodev_add_enq_callback; > rte_cryptodev_configure_raw_dp_ctx; > rte_cryptodev_get_raw_dp_ctx_size; > rte_cryptodev_raw_dequeue; > @@ -109,4 +110,5 @@ EXPERIMENTAL { > rte_cryptodev_raw_enqueue; > rte_cryptodev_raw_enqueue_burst; > rte_cryptodev_raw_enqueue_done; > + rte_cryptodev_remove_enq_callback; > }; > -- > 1.9.1