From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 38D45A0A01; Mon, 4 Jan 2021 07:59:18 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B6DC71606D0; Mon, 4 Jan 2021 07:59:17 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 02D781606CF for ; Mon, 4 Jan 2021 07:59:15 +0100 (CET) IronPort-SDR: SY7Ef3Ih2saLRsBCqWX9yL15G4d0jVEj2Ie4q5UoylxzmDimyQbbTa0SmKViwOkS4jnVX6ttc2 TaPqXq+hOiDQ== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="174341324" X-IronPort-AV: E=Sophos;i="5.78,473,1599548400"; d="scan'208";a="174341324" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2021 22:59:14 -0800 IronPort-SDR: /n2YRP+gGRGAGMj+vleq/Ktty2rzinNzyqCPTo3zWHkLHYQgGIshCoXwz99+WVuBn3TM91s/y7 IM93xzS7D6Zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,473,1599548400"; d="scan'208";a="360683343" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga002.jf.intel.com with ESMTP; 03 Jan 2021 22:59:12 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sun, 3 Jan 2021 22:59:12 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Sun, 3 Jan 2021 22:59:12 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.104) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Sun, 3 Jan 2021 22:59:11 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FesObG4Vdeb1S0leEfJwsKLjbbFRPBzksZh0iV9fA1qVzOJef04WmiUSLLc7+EIOMn5AHg85xI6tBs1rjyLMNP/Gn3TRCbjce/Njrg5YOqjHRcUTMhNOixHKgMRHIx7VJ27G8I8ZiGkH+1DMCqCEiKCsG0f5vqjFNJg5Bma+pNHc/2iN2RIhGtMZNKUrS+NA6YEXfnSHaIrRGGkRzvCh3EfCwoVlTbghGY10S6QYEZth/+aMLowQnCk9txJVZvxWpYBuLyyHjCg6q+z/H3b7t58n1ruUdfgDmt0Ns8I/qIF1KCJY6g9yL/r9LoyKdmPkMDRXXtL0C7Bcgn/AJVoBeA== 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=uXIIOyXYMym67Wgg+Wch60/Vx0i6ZBmCy4Kc4jJQCyw=; b=VVhxTWleWDchm7FWjVU1UvjKQ6HBSOYsdGvV+qcDzecKN7ldAtFUh3EW47zaFevd11LHh11ereEKuDzoc78dX1WwKcKpn0U6NQ9BaURpKyVyzqlkuB4FS2ghAK+a1PN+pdGmFJuyAkMjggKM8hJoPA7/6e1nhQ7JmFKXaPAVdRPqatcuRuGgT6KD7OShaXqTYDUWyZLi80tYPM+vPfsd6rMtHH9d/p0wdbkCrIhNO3mGaMB+QqHfEvAhv3aQHFJ6d74dnlb5qVLniIGr0CGeZ/i4dKSbVxBls7k+qSkz79DoJzqmiQiyd4EwtfRx8EgjjL5chL5erSW+JYF//c3egQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uXIIOyXYMym67Wgg+Wch60/Vx0i6ZBmCy4Kc4jJQCyw=; b=RkAYIEB9Z1HeRTTQCgsqb2dZIyu8n6G/y10CenmYPj2fTQEICZqDd7qBJeEOyemX24lnutztl8CfEeXOTbLThKg6GxjYPC3uHHUdH+bCA8Swm6HF8hgNcBOd44pdVom+doVtnuGh0bmgXbSvdhnC/c3eSQxhN7n0xLnFqxWHkzU= Received: from MWHPR11MB1838.namprd11.prod.outlook.com (10.175.52.11) by MWHPR1101MB2127.namprd11.prod.outlook.com (10.174.100.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.21; Mon, 4 Jan 2021 06:59:10 +0000 Received: from MWHPR11MB1838.namprd11.prod.outlook.com ([fe80::d848:ec4d:f71:363f]) by MWHPR11MB1838.namprd11.prod.outlook.com ([fe80::d848:ec4d:f71:363f%9]) with mapi id 15.20.3721.024; Mon, 4 Jan 2021 06:59:10 +0000 From: "Gujjar, Abhinandan S" To: "dev@dpdk.org" , "akhil.goyal@nxp.com" , "Ananyev, Konstantin" Thread-Topic: [PATCH v7 1/2] cryptodev: support enqueue and dequeue callback functions Thread-Index: AQHW2HDVEuMOtFsXeUCh4xtbtaIyBqoXHRlA Date: Mon, 4 Jan 2021 06:59:09 +0000 Message-ID: References: <20201222144243.552262-1-abhinandan.gujjar@intel.com> <20201222144243.552262-2-abhinandan.gujjar@intel.com> In-Reply-To: <20201222144243.552262-2-abhinandan.gujjar@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=intel.com; x-originating-ip: [103.5.135.70] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9e0b24b9-a63f-4196-6485-08d8b07e3c81 x-ms-traffictypediagnostic: MWHPR1101MB2127: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NqUhsoPY91GbEYVSoCa2hJn+OKZqGpsrhQxBgPutNbZMp5zO7KLC6uayZbgTy2fzu0k6nTqJM+ByGkdUdArlnJ4h4cTQHwX3lEOV0h2hrnW0HhFM+/IgHefrQzS5+vNbpRgy81dVMXOu82f4phwmVwUGnROAQuszSub1SZubnQYevFJtnC88n8FmaM9DZm3umO8EzuykDKc15ieM+qT0xGbtGOg/jAkAxeREL9CSNWVm+X3Y9AVnpnOlnMetiWHZcX4+ykSz6iRh6KhY0EtDoSqXCXkGLc5Au6D3nGpNrAhzFidFCHEuI6z1Ylv1147EdNcu5WcxFv4wlSH8wbWF+Pjh0JybRpFerYI7io+APRbLu4MkfEKYvhSIfW/ECwz3 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR11MB1838.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(136003)(39860400002)(346002)(366004)(110136005)(83380400001)(33656002)(8676002)(316002)(6506007)(186003)(76116006)(66946007)(26005)(55236004)(53546011)(86362001)(7696005)(6636002)(478600001)(30864003)(55016002)(9686003)(2906002)(52536014)(66446008)(64756008)(66556008)(66476007)(8936002)(5660300002)(71200400001)(579004)(559001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?GN4Iih6mpGBPBNKVPp3C219dI1ruIUq8IdbvB6ri+8jGdZZxbmggzz/9Vx7+?= =?us-ascii?Q?t1iovYF1caYjOBAh2h90qhkCav4jiIJUmvxLYuRxPReThQpZcrPn6SjVnrr9?= =?us-ascii?Q?5a3MHYSXEhHQN9ME31UDsl+41fPVPZOqJrwLGZWl+g1mnmd/B36b2TWIuDFi?= =?us-ascii?Q?xUP7vLlOiVjAos3K2uLMb/brAzKvbvEg7v7u/rxvhadt4uTdQqu5D9tRBHiv?= =?us-ascii?Q?4nG4AXy6r0SHrpUpRzp7ZNI/Gjcut/SdfHDV/Xy9JM2peY4jaSrPPxlHlPx4?= =?us-ascii?Q?t1Ih5DfkfY09jg23KsdWqe3GzJf4hUbGTq+Nq/xjhZTjfg7Xdp8gz2qU1dNs?= =?us-ascii?Q?yPgJ2aPypvE18/06dNSJLeDk5ZNAhObacGnib42VZWpcpBHpDcc5pQd9JXgn?= =?us-ascii?Q?AIaCsxGh3syKJ228YldxPaTr17Yi9j9ak3+S4Kn8msgSGCMcvDrKDdfYPeSL?= =?us-ascii?Q?dk7Be3Czoxd7cDUE2obuduXdjeyI+PXgjHt4tKwEMQht3yCb0fhYkCMjMcwP?= =?us-ascii?Q?H6bU5TFixmLcEtEN2H5RlBzOJDYcS6JAEd9/MnrJncYM5Fevv7BH/FZ3ceb2?= =?us-ascii?Q?ODu9NYE9t1pSxVFwE2VA63SbCXF7aibtw4AXWdhnYME3jz5Be34Gifwe7AYc?= =?us-ascii?Q?OuNysZzWcoCDEw+6gegPcj8mcbryNTAIk1eHNN+VB/YrIaDYAiXapRhNVzjX?= =?us-ascii?Q?ujH0gpcB1sq4VrYE+FpnFUdGFU7PzRspWzzFEXcKNUTBWGds97/4z0foCkI2?= =?us-ascii?Q?HrYxAvoEmQfssivyIaF512fcOs4d4iGWI69RYPNKsqIbL+bmuiE5WJE/3xeN?= =?us-ascii?Q?xNIWQ+QMVDeoauve1bBr8rjRqCk1/HHnXZIAGYrXS/s4BSV5FbP7QTQsDmU8?= =?us-ascii?Q?Z4EDRfhc4GJ79hnPTLIkb3yTGhezGi6GDMi7Jx0iJ4m51eKjrhvTnn1s7iN2?= =?us-ascii?Q?q8DP1OfZa55TpqG559z663B/NkkBX1jqBr00U7/6ddk=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1838.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e0b24b9-a63f-4196-6485-08d8b07e3c81 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Jan 2021 06:59:09.9146 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2VvHlwY19aeq9QrRQiueMhPIuDsZ4jDqDIkg4pB3f/+0jG4Ff+y96qHMaZNaUzIAGW3GGhi//Nq66hB8YTIYW91lQ+8Da5JA2hq76N3Civw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1101MB2127 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v7 1/2] cryptodev: support enqueue and dequeue callback functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Hi Akhil, Could you please review the patches? Regards Abhinandan > -----Original Message----- > From: Gujjar, Abhinandan S > Sent: Tuesday, December 22, 2020 8:13 PM > To: dev@dpdk.org; akhil.goyal@nxp.com; Ananyev, Konstantin > > Cc: Gujjar, Abhinandan S > Subject: [PATCH v7 1/2] cryptodev: support enqueue and dequeue callback > functions >=20 > This patch adds APIs to add/remove callback functions on crypto > enqueue/dequeue burst. The callback function will be called for each burs= t of > crypto ops received/sent on a given crypto device queue pair. >=20 > Signed-off-by: Abhinandan Gujjar > Acked-by: Konstantin Ananyev > --- > config/rte_config.h | 1 + > doc/guides/prog_guide/cryptodev_lib.rst | 44 +++ > doc/guides/rel_notes/release_21_02.rst | 9 + > lib/librte_cryptodev/meson.build | 2 +- > lib/librte_cryptodev/rte_cryptodev.c | 398 +++++++++++++++++++++++- > lib/librte_cryptodev/rte_cryptodev.h | 246 ++++++++++++++- > lib/librte_cryptodev/version.map | 7 + > 7 files changed, 702 insertions(+), 5 deletions(-) >=20 > diff --git a/config/rte_config.h b/config/rte_config.h index > a0b5160ff..87f9786d7 100644 > --- a/config/rte_config.h > +++ b/config/rte_config.h > @@ -62,6 +62,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/doc/guides/prog_guide/cryptodev_lib.rst > b/doc/guides/prog_guide/cryptodev_lib.rst > index 473b014a1..9b1cf8d49 100644 > --- a/doc/guides/prog_guide/cryptodev_lib.rst > +++ b/doc/guides/prog_guide/cryptodev_lib.rst > @@ -338,6 +338,50 @@ start of private data information. The offset is cou= nted > from the start of the rte_crypto_op including other crypto information s= uch as > the IVs (since there can be an IV also for authentication). >=20 > +User callback APIs > +~~~~~~~~~~~~~~~~~~ > +The add APIs configures a user callback function to be called for each > +burst of crypto ops received/sent on a given crypto device queue pair. > +The return value is a pointer that can be used later to remove the > +callback using remove API. Application is expected to register a > +callback function of type ``rte_cryptodev_callback_fn``. Multiple > +callback functions can be added for a given queue pair. API does not res= trict > on maximum number of callbacks. > + > +Callbacks registered by application would not survive > +``rte_cryptodev_configure`` as it reinitializes the callback list. It > +is user responsibility to remove all installed callbacks before calling > ``rte_cryptodev_configure`` to avoid possible memory leakage. > + > +So, the application is expected to add user callback after > ``rte_cryptodev_configure``. > +The callbacks can also be added at the runtime. These callbacks get > +executed when > ``rte_cryptodev_enqueue_burst``/``rte_cryptodev_dequeue_burst`` is called= . > + > +.. code-block:: c > + > + 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_cb * > + rte_cryptodev_add_deq_callback(uint8_t dev_id, uint16_t > qp_id, > + rte_cryptodev_callback_fn cb_fn, > + void *cb_arg); > + > + 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); > + > +The remove API removes a callback function added by > +``rte_cryptodev_add_enq_callback``/``rte_cryptodev_add_deq_callback``. > + > +.. code-block:: c > + > + int rte_cryptodev_remove_enq_callback(uint8_t dev_id, uint16_t > qp_id, > + struct rte_cryptodev_cb *cb); > + > + int rte_cryptodev_remove_deq_callback(uint8_t dev_id, uint16_t > qp_id, > + struct rte_cryptodev_cb *cb); > + >=20 > Enqueue / Dequeue Burst APIs > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > diff --git a/doc/guides/rel_notes/release_21_02.rst > b/doc/guides/rel_notes/release_21_02.rst > index 638f98168..8c7866401 100644 > --- a/doc/guides/rel_notes/release_21_02.rst > +++ b/doc/guides/rel_notes/release_21_02.rst > @@ -55,6 +55,13 @@ New Features > Also, make sure to start the actual text at the margin. > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D >=20 > +* **Added enqueue & dequeue callback APIs for cryptodev library.** > + > + Cryptodev library is added with enqueue & dequeue callback APIs to > + enable applications to add/remove user callbacks which gets called > + for every enqueue/dequeue operation. > + > + >=20 > Removed Items > ------------- > @@ -84,6 +91,8 @@ API Changes > Also, make sure to start the actual text at the margin. > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D >=20 > +* cryptodev: The structure ``rte_cryptodev`` has been updated with > +pointers > + for adding enqueue and dequeue callbacks. >=20 > ABI Changes > ----------- > diff --git a/lib/librte_cryptodev/meson.build b/lib/librte_cryptodev/meso= n.build > index c4c6b3b6a..8c5493f4c 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 3d95ac6ea..40f55a3cd 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.c > +++ b/lib/librte_cryptodev/rte_cryptodev.c > @@ -448,6 +448,122 @@ > rte_cryptodev_asym_xform_capability_check_modlen( > return 0; > } >=20 > +/* spinlock for crypto device enq callbacks */ static rte_spinlock_t > +rte_cryptodev_callback_lock =3D RTE_SPINLOCK_INITIALIZER; > + > +static void > +cryptodev_cb_cleanup(struct rte_cryptodev *dev) { > + struct rte_cryptodev_cb_rcu *list; > + struct rte_cryptodev_cb *cb, *next; > + uint16_t qp_id; > + > + if (dev->enq_cbs =3D=3D NULL && dev->deq_cbs =3D=3D NULL) > + return; > + > + for (qp_id =3D 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { > + list =3D &dev->enq_cbs[qp_id]; > + cb =3D list->next; > + while (cb !=3D NULL) { > + next =3D cb->next; > + rte_free(cb); > + cb =3D next; > + } > + > + rte_free(list->qsbr); > + } > + > + for (qp_id =3D 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { > + list =3D &dev->deq_cbs[qp_id]; > + cb =3D list->next; > + while (cb !=3D NULL) { > + next =3D cb->next; > + rte_free(cb); > + cb =3D next; > + } > + > + rte_free(list->qsbr); > + } > + > + rte_free(dev->enq_cbs); > + dev->enq_cbs =3D NULL; > + rte_free(dev->deq_cbs); > + dev->deq_cbs =3D NULL; > +} > + > +static int > +cryptodev_cb_init(struct rte_cryptodev *dev) { > + struct rte_cryptodev_cb_rcu *list; > + struct rte_rcu_qsbr *qsbr; > + uint16_t qp_id; > + size_t size; > + > + /* Max thread set to 1, as one DP thread accessing a queue-pair */ > + const uint32_t max_threads =3D 1; > + > + dev->enq_cbs =3D rte_zmalloc(NULL, > + sizeof(struct rte_cryptodev_cb_rcu) * > + dev->data->nb_queue_pairs, 0); > + if (dev->enq_cbs =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for enq > callbacks"); > + return -ENOMEM; > + } > + > + dev->deq_cbs =3D rte_zmalloc(NULL, > + sizeof(struct rte_cryptodev_cb_rcu) * > + dev->data->nb_queue_pairs, 0); > + if (dev->deq_cbs =3D=3D NULL) { > + CDEV_LOG_ERR("Failed to allocate memory for deq > callbacks"); > + rte_free(dev->enq_cbs); > + return -ENOMEM; > + } > + > + /* Create RCU QSBR variable */ > + size =3D rte_rcu_qsbr_get_memsize(max_threads); > + > + for (qp_id =3D 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { > + list =3D &dev->enq_cbs[qp_id]; > + 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 " > + "queue_pair_id=3D%d", qp_id); > + goto cb_init_err; > + } > + > + if (rte_rcu_qsbr_init(qsbr, max_threads)) { > + CDEV_LOG_ERR("Failed to initialize for RCU on " > + "queue_pair_id=3D%d", qp_id); > + goto cb_init_err; > + } > + > + list->qsbr =3D qsbr; > + } > + > + for (qp_id =3D 0; qp_id < dev->data->nb_queue_pairs; qp_id++) { > + list =3D &dev->deq_cbs[qp_id]; > + 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 " > + "queue_pair_id=3D%d", qp_id); > + goto cb_init_err; > + } > + > + if (rte_rcu_qsbr_init(qsbr, max_threads)) { > + CDEV_LOG_ERR("Failed to initialize for RCU on " > + "queue_pair_id=3D%d", qp_id); > + goto cb_init_err; > + } > + > + list->qsbr =3D qsbr; > + } > + > + return 0; > + > +cb_init_err: > + cryptodev_cb_cleanup(dev); > + return -ENOMEM; > +} >=20 > const char * > rte_cryptodev_get_feature_name(uint64_t flag) @@ -927,6 +1043,10 @@ > rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *conf= ig) >=20 > RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, - > ENOTSUP); >=20 > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + cryptodev_cb_cleanup(dev); > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > + > /* Setup new number of queue pairs and reconfigure device. */ > diag =3D rte_cryptodev_queue_pairs_config(dev, config- > >nb_queue_pairs, > config->socket_id); > @@ -936,11 +1056,18 @@ rte_cryptodev_configure(uint8_t dev_id, struct > rte_cryptodev_config *config) > return diag; > } >=20 > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + diag =3D cryptodev_cb_init(dev); > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > + if (diag) { > + CDEV_LOG_ERR("Callback init failed for dev_id=3D%d", dev_id); > + return diag; > + } > + > rte_cryptodev_trace_configure(dev_id, config); > return (*dev->dev_ops->dev_configure)(dev, config); } >=20 > - > int > rte_cryptodev_start(uint8_t dev_id) > { > @@ -1136,6 +1263,275 @@ rte_cryptodev_queue_pair_setup(uint8_t dev_id, > uint16_t queue_pair_id, > socket_id); > } >=20 > +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_rcu *list; > + struct rte_cryptodev_cb *cb, *tail; > + > + if (!cb_fn) { > + CDEV_LOG_ERR("Callback is NULL on dev_id=3D%d", dev_id); > + rte_errno =3D EINVAL; > + return NULL; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + rte_errno =3D ENODEV; > + 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); > + rte_errno =3D ENODEV; > + return NULL; > + } > + > + 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_errno =3D ENOMEM; > + return NULL; > + } > + > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + > + 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; > + /* Stores to cb->fn and cb->param should complete before > + * cb is visible to data plane. > + */ > + __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); > + } else { > + /* Stores to cb->fn and cb->param should complete before > + * cb is visible to data plane. > + */ > + __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE); > + } > + > + rte_spinlock_unlock(&rte_cryptodev_callback_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_cb_rcu *list; > + int ret; > + > + ret =3D -EINVAL; > + > + if (!cb) { > + CDEV_LOG_ERR("Callback is NULL"); > + return -EINVAL; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + return -ENODEV; > + } > + > + 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 -ENODEV; > + } > + > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + if (dev->enq_cbs =3D=3D NULL) { > + CDEV_LOG_ERR("Callback not initialized"); > + goto cb_err; > + } > + > + list =3D &dev->enq_cbs[qp_id]; > + if (list =3D=3D NULL) { > + CDEV_LOG_ERR("Callback list is NULL"); > + goto cb_err; > + } > + > + if (list->qsbr =3D=3D NULL) { > + CDEV_LOG_ERR("Rcu qsbr is NULL"); > + goto cb_err; > + } > + > + 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. */ > + __atomic_store_n(prev_cb, curr_cb->next, > + __ATOMIC_RELAXED); > + 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); > + } > + > +cb_err: > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > + return ret; > +} > + > +struct rte_cryptodev_cb * > +rte_cryptodev_add_deq_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_rcu *list; > + struct rte_cryptodev_cb *cb, *tail; > + > + if (!cb_fn) { > + CDEV_LOG_ERR("Callback is NULL on dev_id=3D%d", dev_id); > + rte_errno =3D EINVAL; > + return NULL; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + rte_errno =3D ENODEV; > + 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); > + rte_errno =3D ENODEV; > + return NULL; > + } > + > + 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_errno =3D ENOMEM; > + return NULL; > + } > + > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + > + cb->fn =3D cb_fn; > + cb->arg =3D cb_arg; > + > + /* Add the callbacks in fifo order. */ > + list =3D &dev->deq_cbs[qp_id]; > + tail =3D list->next; > + > + if (tail) { > + while (tail->next) > + tail =3D tail->next; > + /* Stores to cb->fn and cb->param should complete before > + * cb is visible to data plane. > + */ > + __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); > + } else { > + /* Stores to cb->fn and cb->param should complete before > + * cb is visible to data plane. > + */ > + __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE); > + } > + > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > + > + return cb; > +} > + > +int > +rte_cryptodev_remove_deq_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_cb_rcu *list; > + int ret; > + > + ret =3D -EINVAL; > + > + if (!cb) { > + CDEV_LOG_ERR("Callback is NULL"); > + return -EINVAL; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%d", dev_id); > + return -ENODEV; > + } > + > + 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 -ENODEV; > + } > + > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > + if (dev->enq_cbs =3D=3D NULL) { > + CDEV_LOG_ERR("Callback not initialized"); > + goto cb_err; > + } > + > + list =3D &dev->deq_cbs[qp_id]; > + if (list =3D=3D NULL) { > + CDEV_LOG_ERR("Callback list is NULL"); > + goto cb_err; > + } > + > + if (list->qsbr =3D=3D NULL) { > + CDEV_LOG_ERR("Rcu qsbr is NULL"); > + goto cb_err; > + } > + > + 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. */ > + __atomic_store_n(prev_cb, curr_cb->next, > + __ATOMIC_RELAXED); > + 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); > + } > + > +cb_err: > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > + return ret; > +} >=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 0935fd587..ae34f33f6 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.h > +++ b/lib/librte_cryptodev/rte_cryptodev.h > @@ -23,6 +23,7 @@ extern "C" { > #include "rte_dev.h" > #include > #include > +#include >=20 > #include "rte_cryptodev_trace_fp.h" >=20 > @@ -522,6 +523,30 @@ struct rte_cryptodev_qp_conf { > /**< The mempool for creating sess private data in sessionless mode > */ }; >=20 > +/** > + * Function type used for processing crypto ops when enqueue/dequeue > +burst is > + * called. > + * > + * The callback function is called on enqueue/dequeue burst immediately. > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair on which ops are > + * enqueued/dequeued. 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); > + > /** > * Typedef for application callback function to be registered by applica= tion > * software for notification of device events @@ -822,7 +847,6 @@ > rte_cryptodev_callback_unregister(uint8_t dev_id, > 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 > +863,30 @@ struct rte_cryptodev_callback; > /** Structure to keep track of registered callbacks */ > TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback); >=20 > +/** > + * Structure used to hold information about the callbacks to be called > +for a > + * queue pair on enqueue/dequeue. > + */ > +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_cb_rcu { > + struct rte_cryptodev_cb *next; > + /**< Pointer to next callback */ > + struct rte_rcu_qsbr *qsbr; > + /**< RCU QSBR variable per queue pair */ }; > + > /** The data structure associated with each crypto device. */ struct > rte_cryptodev { > dequeue_pkt_burst_t dequeue_burst; > @@ -867,6 +915,12 @@ struct rte_cryptodev { > __extension__ > uint8_t attached : 1; > /**< Flag indicating the device is attached */ > + > + struct rte_cryptodev_cb_rcu *enq_cbs; > + /**< User application callback for pre enqueue processing */ > + > + struct rte_cryptodev_cb_rcu *deq_cbs; > + /**< User application callback for post dequeue processing */ > } __rte_cache_aligned; >=20 > void * > @@ -945,10 +999,33 @@ rte_cryptodev_dequeue_burst(uint8_t dev_id, > uint16_t qp_id, { > struct rte_cryptodev *dev =3D &rte_cryptodevs[dev_id]; >=20 > + rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, > +nb_ops); > nb_ops =3D (*dev->dequeue_burst) > (dev->data->queue_pairs[qp_id], ops, nb_ops); > - > - rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, > nb_ops); > +#ifdef RTE_CRYPTO_CALLBACKS > + if (unlikely(dev->deq_cbs !=3D NULL)) { > + struct rte_cryptodev_cb_rcu *list; > + struct rte_cryptodev_cb *cb; > + > + /* __ATOMIC_RELEASE memory order was used when the > + * call back was inserted into the list. > + * Since there is a clear dependency between loading > + * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order > is > + * not required. > + */ > + list =3D &dev->deq_cbs[qp_id]; > + rte_rcu_qsbr_thread_online(list->qsbr, 0); > + cb =3D __atomic_load_n(&list->next, __ATOMIC_RELAXED); > + > + while (cb !=3D NULL) { > + nb_ops =3D cb->fn(dev_id, qp_id, ops, nb_ops, > + cb->arg); > + cb =3D cb->next; > + }; > + > + rte_rcu_qsbr_thread_offline(list->qsbr, 0); > + } > +#endif > return nb_ops; > } >=20 > @@ -989,6 +1066,31 @@ rte_cryptodev_enqueue_burst(uint8_t dev_id, > uint16_t qp_id, { > struct rte_cryptodev *dev =3D &rte_cryptodevs[dev_id]; >=20 > +#ifdef RTE_CRYPTO_CALLBACKS > + if (unlikely(dev->enq_cbs !=3D NULL)) { > + struct rte_cryptodev_cb_rcu *list; > + struct rte_cryptodev_cb *cb; > + > + /* __ATOMIC_RELEASE memory order was used when the > + * call back was inserted into the list. > + * Since there is a clear dependency between loading > + * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order > is > + * not required. > + */ > + list =3D &dev->enq_cbs[qp_id]; > + rte_rcu_qsbr_thread_online(list->qsbr, 0); > + cb =3D __atomic_load_n(&list->next, __ATOMIC_RELAXED); > + > + while (cb !=3D NULL) { > + nb_ops =3D cb->fn(dev_id, qp_id, ops, nb_ops, > + cb->arg); > + cb =3D cb->next; > + }; > + > + 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 +1832,144 @@ int rte_cryptodev_raw_dequeue_done(struct > rte_crypto_raw_dp_ctx *ctx, > uint32_t n); >=20 > +/** > + * 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(). > + * > + * Callbacks registered by application would not survive > + * rte_cryptodev_configure() as it reinitializes the callback list. > + * It is user responsibility to remove all installed callbacks before > + * calling rte_cryptodev_configure() to avoid possible memory leakage. > + * Application is expected to call add API after rte_cryptodev_configure= (). > + * > + * Multiple functions can be registered per queue pair & they are > +called > + * in the order they were added. The API does not restrict on maximum > +number > + * of callbacks. > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair on 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 & rte_errno will contain the error code. > + * - On success, a pointer value which can later be used to remove the > + * callback. > + */ > + > +__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); > + > +/** > + * Remove a user callback function for given crypto device and queue pai= r. > + * > + * This function is used to remove enqueue 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 on which ops are > + * to be enqueued. 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. > + * - <0: The dev_id or the qp_id is out of range, or the callback > + * 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); > + > +/** > + * Add a user callback for a given crypto device and queue pair which > +will be > + * called on crypto ops dequeue. > + * > + * 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_deq_callback(). > + * > + * Callbacks registered by application would not survive > + * rte_cryptodev_configure() as it reinitializes the callback list. > + * It is user responsibility to remove all installed callbacks before > + * calling rte_cryptodev_configure() to avoid possible memory leakage. > + * Application is expected to call add API after rte_cryptodev_configure= (). > + * > + * Multiple functions can be registered per queue pair & they are > +called > + * in the order they were added. The API does not restrict on maximum > +number > + * of callbacks. > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair on which ops are > + * to be dequeued. 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 & rte_errno will contain the error code. > + * - On success, a pointer value which can later be used to remove the > + * callback. > + */ > + > +__rte_experimental > +struct rte_cryptodev_cb * > +rte_cryptodev_add_deq_callback(uint8_t dev_id, > + uint16_t qp_id, > + rte_cryptodev_callback_fn cb_fn, > + void *cb_arg); > + > +/** > + * Remove a user callback function for given crypto device and queue pai= r. > + * > + * This function is used to remove dequeue callbacks that were added to > +a > + * crypto device queue pair using rte_cryptodev_add_deq_callback(). > + * > + * > + * > + * @param dev_id The identifier of the device. > + * @param qp_id The index of the queue pair on which ops are > + * to be dequeued. 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_deq_callback(). > + * > + * @return > + * - 0: Success. Callback was removed. > + * - <0: The dev_id or the qp_id is out of range, or the callback > + * is NULL or not found for the crypto device queue pair. > + */ > +__rte_experimental > +int rte_cryptodev_remove_deq_callback(uint8_t dev_id, > + uint16_t qp_id, > + struct rte_cryptodev_cb *cb); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_cryptodev/version.map b/lib/librte_cryptodev/vers= ion.map > index 7e4360ff0..9f04737ae 100644 > --- a/lib/librte_cryptodev/version.map > +++ b/lib/librte_cryptodev/version.map > @@ -109,4 +109,11 @@ EXPERIMENTAL { > rte_cryptodev_raw_enqueue; > rte_cryptodev_raw_enqueue_burst; > rte_cryptodev_raw_enqueue_done; > + > + # added in 21.02 > + rte_cryptodev_add_deq_callback; > + rte_cryptodev_add_enq_callback; > + rte_cryptodev_remove_deq_callback; > + rte_cryptodev_remove_enq_callback; > + > }; > -- > 2.25.1