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 3D038A04B5; Tue, 27 Oct 2020 18:23:09 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 399ED2BF4; Tue, 27 Oct 2020 18:23:07 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 5B05F2BEA for ; Tue, 27 Oct 2020 18:23:05 +0100 (CET) IronPort-SDR: ThcUY08T3+SIL9DXpQrmrUX2CziC55q7huWCEaNce22iYcKSFm3gxnfbQIltweCrn5qp1Bor+3 4wIQosyD8eHw== X-IronPort-AV: E=McAfee;i="6000,8403,9787"; a="232312118" X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="232312118" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2020 10:23:03 -0700 IronPort-SDR: +UIqrbq31YtDAUB9ySkRCueoivrydDMcvxD0mikGDl8T65OBAJLXGE8xzoG0cE8J5VgtsIRwSf w1yo3ZiRkEWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="526012119" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by fmsmga005.fm.intel.com with ESMTP; 27 Oct 2020 10:23:02 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 27 Oct 2020 10:23:01 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 27 Oct 2020 10:23:01 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.46) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Tue, 27 Oct 2020 10:23:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dQfyfgTXKaoIh4XWG7pmbzq25qa8hr8vkwOGD+MGbjsW7xBePIcMZsGPn3H6h4n7MnlwvH+6815eyh5xBLXnr7jn+oOp6qrpCnZb06cX84Va/VtjYJBjHsTKFhOqv0r4Fk+kYGR/Z+/RYCN7sTXNYlywvoTqy7+iabBzBiHWKGHV/ZgtPkUa1R1TtT1y07a6LGVJWpLsviCNHPM3+zxNCob8Nc1Ut0n7cnduE46DRwQnH9nDt/A2KCMZbKK9wlvi16lGa5LlAyJ9te2mv6phvjl0Rk7RUg7DsgSHUeQhD1eDFWJ8qZ0FtZG7COu7ud29KlFQfIliUElqMvQv/Z2MIA== 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=xUh/GY/pspS7JdoL/SOm3aLvYRYOx8M7FaxH5Av0BM4=; b=Up1ryqEQ+et1dD3Rtj/DsPZhtPTcxfCInVmiMau8TFPdAc3GbLN5UBtaf6nvL2wPR8TQ/7Rf6iVlJsf3H+DcqGRh+yc4qeuinJLrdPoFIvmfhUqXXI8KnR+cY4/liTFc5VGSEFXPKBUK7Uhm0K+Rmu9cF8Ei+uOGKgNwHxdCwcBboqwnh/pc7CuxXKKqUc+fACpXQgDQJqWAvwWNbLX2/DarPUBSvYWVUkXMeOZxn8HR/D2DuRNAGEe+3pDlTLSsuJzBf6Ub+/7UiG/4MLTC5bmurXZfBb6FY7G7sa1M280TcjdUfyci4QowcWHRzoZQ/OYSLGSYFO9YfB5zlI/d3Q== 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=xUh/GY/pspS7JdoL/SOm3aLvYRYOx8M7FaxH5Av0BM4=; b=OV8YbPtK7t6VI3cAjfvkZp6+zeHS/ZOTQhZlsEXpziGjbTmiIl0/3kv66Vr1t446SbJB4sBmDwwqUkRL4niCUpQPoyy4n3OCjILLxCzZru4a4YO2COdxdBrynYuquBThT/djoKiHq6DuUYQGqbM05A5z3v3z/nFQKXJtcrNSFKg= Received: from MWHPR11MB1838.namprd11.prod.outlook.com (2603:10b6:300:10c::11) by MWHPR11MB1615.namprd11.prod.outlook.com (2603:10b6:301:c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.28; Tue, 27 Oct 2020 17:22:57 +0000 Received: from MWHPR11MB1838.namprd11.prod.outlook.com ([fe80::20fb:cc03:ce89:f0ea]) by MWHPR11MB1838.namprd11.prod.outlook.com ([fe80::20fb:cc03:ce89:f0ea%7]) with mapi id 15.20.3499.018; Tue, 27 Oct 2020 17:22:57 +0000 From: "Gujjar, Abhinandan S" To: "Ananyev, Konstantin" , "dev@dpdk.org" , "Doherty, Declan" , "akhil.goyal@nxp.com" , "Honnappa.Nagarahalli@arm.com" CC: "Vangati, Narender" , "jerinj@marvell.com" Thread-Topic: [v4 1/3] cryptodev: support enqueue callback functions Thread-Index: AQHWq8khg/yqaE27MkanYRdfhPnwbqmrZzKAgABKiQCAAAGwgIAAACcA Date: Tue, 27 Oct 2020 17:22:57 +0000 Message-ID: References: <1603619090-118652-1-git-send-email-abhinandan.gujjar@intel.com> <1603619090-118652-2-git-send-email-abhinandan.gujjar@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [157.49.168.0] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6e4c1db4-056c-463c-9262-08d87a9cf272 x-ms-traffictypediagnostic: MWHPR11MB1615: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr 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: 8PgknCM+gncK+1mVrLgfx/GxpgCO7MgAjH+YjMWHeIEAwHky5wxRwhOSdDZbif8fN9QH2oIsms/jrW4VQk5KkWt2bzWX8Z4CA3DE9JHossq00jKxFb34mcLLO29LWtr2ngTvkot66qVNaa+XnJCIxoJnGLqp57O0aDWLWXwuhVwPswLxHdf/QNDpM8SWWK5ERPLXKuzUWSKOQc/raLS+wBFqxYrn6S7XL30j3vVfmJCXivQePuOxUzLZhWU05WUTooOxKUQHzUGrYQM++BGmLUuXM2neD67RtoaIQ4Zr6vS80sc+OxkXexkUHe4KpPYR 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)(376002)(136003)(396003)(366004)(346002)(39860400002)(6506007)(66946007)(53546011)(7696005)(66476007)(66446008)(66556008)(76116006)(186003)(30864003)(55016002)(64756008)(71200400001)(9686003)(5660300002)(52536014)(83380400001)(2906002)(33656002)(86362001)(26005)(54906003)(478600001)(4326008)(8936002)(8676002)(316002)(110136005)(579004); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: d6yKyUmt/rDB1DvjfiBpHSHvtodnV7Dk5sOmMV/9c45ATXObJGmtUan5k3aZEx+rDA+QHqh8aCnfgWpSIgVfOY/oZl7mJkAefq/IwC7egb5mhHecI++k+6R/oryWvLNsNZaJ6sSr8TrXli9LRsUnhhDiOpxvVd+TYhIu5ZDoOtIjVPoUk+HONB1PUpr7as6OLV2g74gUqdCHg01lrCtRnp506Uq/uG7UvdLiSDbiiPfPQJaeEIW5EbwikiJ3psDZNgRPX8vHzodezFH+CmlADMKVYwFqyTTl9RKX2YdNLhmV94fD2PQSicZbGdcXFpaywND+Ii5bwupgN24SoU3rlJCThwuYGYNWBFRs4KqE3t1J7StVO+2UfmyJmv7hJbTRil9NOYEzY/XOfUPnowXIQQAZEKGFdmF2f8p9YhtgTdGCUKYtx5DQOSnRfWFqNnU0VfKNgHt7367S+flEKEB0ARUnJ0ovs30FjbGVJ+Wygf4B5N/tn3ugw5+8sqcDSDbh18aq9MQRGY6sDBIfPxCT0bofDnsVm187uuj8K3GqFd8mG/0iECVOrF21TTDsroUvVWGoAhDd5OaNGG8o+eu4PQ8w2+4g67ALX+vTSaJmjAytSV866RuCyP6m+NLI9DGF3zJ0xXHQLhoaGDQvhAWmoQ== 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: 6e4c1db4-056c-463c-9262-08d87a9cf272 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Oct 2020 17:22:57.2107 (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: hYwOfw5JKbqHNjtz5/0FuaAx+4LROUHSBqv3IbPQaAag3G8pXj7k30Ue8yJ9sm4AZbLECgUC2mxI6z5d30D5eYm6o3lygysrTkj/TIObPks= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1615 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [v4 1/3] 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" Sure Konstantin. Thanks Abhinandan > -----Original Message----- > From: Ananyev, Konstantin > Sent: Tuesday, October 27, 2020 10:51 PM > To: Gujjar, Abhinandan S ; dev@dpdk.org; > Doherty, Declan ; akhil.goyal@nxp.com; > Honnappa.Nagarahalli@arm.com > Cc: Vangati, Narender ; jerinj@marvell.com > Subject: RE: [v4 1/3] cryptodev: support enqueue callback functions >=20 > > > > > -----Original Message----- > > > From: Ananyev, Konstantin > > > Sent: Tuesday, October 27, 2020 6:18 PM > > > To: Gujjar, Abhinandan S ; > > > dev@dpdk.org; Doherty, Declan ; > > > akhil.goyal@nxp.com; Honnappa.Nagarahalli@arm.com > > > Cc: Vangati, Narender ; > > > jerinj@marvell.com > > > Subject: RE: [v4 1/3] cryptodev: support enqueue callback functions > > > > > > > > > > > > > > This patch adds APIs to add/remove callback functions. The > > > > callback function will be called for each burst of crypto ops > > > > received on a given crypto device queue pair. > > > > > > > > Signed-off-by: Abhinandan Gujjar > > > > --- > > > > config/rte_config.h | 1 + > > > > lib/librte_cryptodev/meson.build | 2 +- > > > > lib/librte_cryptodev/rte_cryptodev.c | 230 > > > +++++++++++++++++++++++++ > > > > lib/librte_cryptodev/rte_cryptodev.h | 158 +++++++++++++= +++- > > > > lib/librte_cryptodev/rte_cryptodev_version.map | 2 + > > > > 5 files changed, 391 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/config/rte_config.h b/config/rte_config.h index > > > > 03d90d7..e999d93 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 > > > > > > > > /* compressdev defines */ > > > > #define RTE_COMPRESS_MAX_DEVS 64 > > > > diff --git a/lib/librte_cryptodev/meson.build > > > > b/lib/librte_cryptodev/meson.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..0880d9b 100644 > > > > --- a/lib/librte_cryptodev/rte_cryptodev.c > > > > +++ b/lib/librte_cryptodev/rte_cryptodev.c > > > > @@ -448,6 +448,91 @@ struct > > > rte_cryptodev_sym_session_pool_private_data { > > > > return 0; > > > > } > > > > > > > > +#ifdef RTE_CRYPTO_CALLBACKS > > > > +/* 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 **prev_cb, *curr_cb; > > > > + struct rte_cryptodev_enq_cb_rcu *list; > > > > + uint16_t qp_id; > > > > + > > > > + if (dev->enq_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]; > > > > + prev_cb =3D &list->next; > > > > + > > > > + while (*prev_cb !=3D NULL) { > > > > + curr_cb =3D *prev_cb; > > > > + /* Remove the user cb from the callback list. */ > > > > + __atomic_store_n(prev_cb, curr_cb->next, > > > > + __ATOMIC_RELAXED); > > > > + rte_rcu_qsbr_synchronize(list->qsbr, > > > > + RTE_QSBR_THRID_INVALID); > > > > > > You call this function (cb_cleanup) only at dev_confiture(). > > > At that moment DP threads can't do enqueue/dequeue anyway. > > > So you can safely skip all this synchronization code here and just do= : > > > > > > cb =3D list->next; > > > while (cb !=3D NULL) { > > > next =3D cb->next; > > > rte_free(cb); > > > cb =3D next; > > > } > > > > > Ok > > > > > > > + rte_free(curr_cb); > > > > > > One thing that makes it sort of grey area: > > > we do free() for cb itself, but user provided data will be sort of 'l= ost'. > > > As it is not referenced from our cb struct anymore... > > > I see two options here - first just document explicitly that > > > callbacks wouldn't survive cryptodev_configure() and it is user > > > responsibility to remove all installed callbacks before doing > > > dev_configure() to avoid possible memory leakage. > > Ok. I will update the documentation for this and send a new patch set. >=20 > Ok, please keep my ack on your new version. >=20 > > > Another option - add user provided cleanup() function pointer into > > > struct rte_cryptodev_cb and call it here if provided: > > > 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 */ > > > void (*cleanup)(void *); > > > }; > > > > > > And here: > > > If (curr_cb->cleanup !=3D NULL) > > > curr_cb->cleanup(curr_cb->arg); > > > > > > rte_free(curr_cb); > > > > > > Rest of the code - LGTM. > > > So with that addressed: > > > Acked-by: Konstantin Ananyev > > > > > > > + } > > > > + > > > > + rte_free(list->qsbr); > > > > + } > > > > + > > > > + rte_free(dev->enq_cbs); > > > > + dev->enq_cbs =3D NULL; > > > > +} > > > > + > > > > +static int > > > > +cryptodev_cb_init(struct rte_cryptodev *dev) { > > > > + struct rte_cryptodev_enq_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_enq_cb_rcu) * > > > > + dev->data->nb_queue_pairs, 0); > > > > + if (dev->enq_cbs =3D=3D NULL) { > > > > + CDEV_LOG_ERR("Failed to allocate memory for callbacks"); > > > > + rte_errno =3D ENOMEM; > > > > + return -1; > > > > + } > > > > + > > > > + /* 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; > > > > + } > > > > + > > > > + return 0; > > > > + > > > > +cb_init_err: > > > > + rte_errno =3D ENOMEM; > > > > + cryptodev_cb_cleanup(dev); > > > > + return -1; > > > > + > > > > +} > > > > +#endif > > > > > > > > const char * > > > > rte_cryptodev_get_feature_name(uint64_t flag) @@ -927,6 +1012,11 > > > > @@ struct rte_cryptodev * > > > > > > > > RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, - > > > ENOTSUP); > > > > > > > > +#ifdef RTE_CRYPTO_CALLBACKS > > > > + rte_spinlock_lock(&rte_cryptodev_callback_lock); > > > > + cryptodev_cb_cleanup(dev); > > > > + rte_spinlock_unlock(&rte_cryptodev_callback_lock); > > > > +#endif > > > > /* 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,6 +1026,15 @@ struct rte_cryptodev * > > > > return diag; > > > > } > > > > > > > > +#ifdef RTE_CRYPTO_CALLBACKS > > > > + 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 -ENOMEM; > > > > + } > > > > +#endif > > > > rte_cryptodev_trace_configure(dev_id, config); > > > > return (*dev->dev_ops->dev_configure)(dev, config); } @@ > > > > -1136,6 > > > > +1235,137 @@ struct rte_cryptodev * > > > > socket_id); > > > > } > > > > > > > > +#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_enq_cb_rcu *list; > > > > + struct rte_cryptodev_cb *cb, *tail; > > > > + > > > > + 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; > > > > + } > > > > + > > > > + 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_enq_cb_rcu *list; > > > > + int ret; > > > > + > > > > + 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; > > > > + } > > > > + > > > > + 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; > > > > +} > > > > +#endif > > > > > > > > int > > > > rte_cryptodev_stats_get(uint8_t dev_id, struct > > > > rte_cryptodev_stats > > > > *stats) diff --git a/lib/librte_cryptodev/rte_cryptodev.h > > > > b/lib/librte_cryptodev/rte_cryptodev.h > > > > index 0935fd5..1b7d7ef 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 > > > > > > > > #include "rte_cryptodev_trace_fp.h" > > > > > > > > @@ -522,6 +523,34 @@ struct rte_cryptodev_qp_conf { > > > > /**< The mempool for creating sess private data in sessionless > > > > mode */ }; > > > > > > > > +#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 proce= ssing. > > > > + * > > > > + * @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 > application > > > > * 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); > > > > > > > > - > > > > 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); > > > > > > > > +#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 pa= ir. > > > > + */ > > > > +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,10 @@ struct > > > > rte_cryptodev { > > > > __extension__ > > > > uint8_t attached : 1; > > > > /**< Flag indicating the device is attached */ > > > > + > > > > + struct rte_cryptodev_enq_cb_rcu *enq_cbs; > > > > + /**< User application callback for pre enqueue processing */ > > > > + > > > > } __rte_cache_aligned; > > > > > > > > void * > > > > @@ -989,6 +1048,31 @@ struct rte_cryptodev_data { { > > > > struct rte_cryptodev *dev =3D &rte_cryptodevs[dev_id]; > > > > > > > > +#ifdef RTE_CRYPTO_CALLBACKS > > > > + if (unlikely(dev->enq_cbs !=3D NULL)) { > > > > + struct rte_cryptodev_enq_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 +1814,78 > > > > @@ struct rte_crypto_raw_dp_ctx { > > > > rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx, > > > > uint32_t n); > > > > > > > > +#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 > > > 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); > > > > + > > > > + > > > > +/** > > > > + * @warning > > > > + * @b EXPERIMENTAL: this API may change without prior notice > > > > + * > > > > + * Remove a user callback function for given crypto device and que= ue > pair. > > > > + * > > > > + * 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 c= allback > > > > + * 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; > > > > > > > > # 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