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 41815A04B1; Thu, 24 Sep 2020 07:17:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A13AC1DA83; Thu, 24 Sep 2020 07:17:38 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80082.outbound.protection.outlook.com [40.107.8.82]) by dpdk.org (Postfix) with ESMTP id 026DA1D994 for ; Thu, 24 Sep 2020 07:17:36 +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=s9kP8TTaz6qKC5FozsJdEOJ24EAldwjq+S4ruQEDxZo=; b=zph6ETR7edVtfAkkJdT8MKJ7umOh7FtEO3aYyGcdissAE4MTpnCzwuosxUqqSVwUOy6FYqfo0Fh/GyIsrHwOK9NLeXTXdyFMr83yUYlogZ6abZBQ3k4PorYi4KFIgDCYgR7vSyHd6kNyTNeJrGYqYhXu3esr1oZ3eZAm7itSvRQ= Received: from MR2P264CA0068.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:31::32) by HE1PR08MB2889.eurprd08.prod.outlook.com (2603:10a6:7:39::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.22; Thu, 24 Sep 2020 05:17:22 +0000 Received: from VE1EUR03FT037.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:31:cafe::5) by MR2P264CA0068.outlook.office365.com (2603:10a6:500:31::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.21 via Frontend Transport; Thu, 24 Sep 2020 05:17:21 +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=bestguesspass 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 VE1EUR03FT037.mail.protection.outlook.com (10.152.19.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.21 via Frontend Transport; Thu, 24 Sep 2020 05:17:21 +0000 Received: ("Tessian outbound 34b830c8a0ef:v64"); Thu, 24 Sep 2020 05:17:21 +0000 X-CR-MTA-TID: 64aa7808 Received: from dcf1745e22b7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CEC1FF26-99F5-4EB1-980B-284397C81D6D.1; Thu, 24 Sep 2020 05:17:16 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id dcf1745e22b7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 24 Sep 2020 05:17:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NHTsrCOOsG2jlpTtpY1tGzOjS3KRAZJ5uWxeM0ZjKomjlHhUrDdDICaAkFl+GDBXItQSRnUYvP6OQqml/YtrR30O3oNCl+fEADIKQ5UG8omEnXJ49vXdqCuQI03oKRw+TDvctWeIif/6ItINh9MmJ0RcBlP0yGmTopW0DqqM5vfU4I4QosBBCz7psLXV46PqKLffCW9D+MGcTLTZAOcBrWUcwJS07iY9mQuqe5Jf+rdX9nfiCidmHI8uio8G49Cprc0b5HdPDnlU/LWiSvOvPdGJ0kzndZYNcRJOFKdu9qXJqXpK4Lb+QSugO8CdPBwj1Zb99Bh78uVjj9kZlKPvCg== 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=s9kP8TTaz6qKC5FozsJdEOJ24EAldwjq+S4ruQEDxZo=; b=F4p72ONG8ldNCoFTYuwrC5QnUzlmAAgUoC6kf2lLqntH83+yKrXeKLBTBjGp9mSMgLjJQr9q5bZWJBW/1sV26/Bg5RfwCTKpEmx06yVcTU77/qN9alrWI/BPSRo6DVvPYXX6p6BsK0/VhTDNmmjlf4yhOB7yQ7FpjQaOr9JLKD5Qb25XczGeSASOJ7O/iY0AQhXMYHwTXt2P8pUl1+kGFtsHdjamHc7ZLsRWGJ/+7C+d0M2hKXsxE2raY/BvckMiZXZ1CZpHw3u9BqcPVyJSA0Hn9fgqgDFNcs830InomP1T34Rbda0NBYO9ZyMKFVcjsskP2vJk/NzIIduKmn49Ww== 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=s9kP8TTaz6qKC5FozsJdEOJ24EAldwjq+S4ruQEDxZo=; b=zph6ETR7edVtfAkkJdT8MKJ7umOh7FtEO3aYyGcdissAE4MTpnCzwuosxUqqSVwUOy6FYqfo0Fh/GyIsrHwOK9NLeXTXdyFMr83yUYlogZ6abZBQ3k4PorYi4KFIgDCYgR7vSyHd6kNyTNeJrGYqYhXu3esr1oZ3eZAm7itSvRQ= Received: from DBAPR08MB5814.eurprd08.prod.outlook.com (2603:10a6:10:1b1::6) by DB8PR08MB5098.eurprd08.prod.outlook.com (2603:10a6:10:ec::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20; Thu, 24 Sep 2020 05:17:14 +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.3412.020; Thu, 24 Sep 2020 05:17:13 +0000 From: Honnappa Nagarahalli To: Abhinandan Gujjar , "dev@dpdk.org" CC: "declan.doherty@intel.com" , "jerinj@marvell.com" , "Akhil.goyal@nxp.com" , "narender.vangati@intel.com" , nd , Honnappa Nagarahalli , nd Thread-Topic: [dpdk-dev] [v2 1/2] cryptodev: support enqueue callback functions Thread-Index: AQHWkjHxpueHJn2Z1E+jIJevuNB9zg== Date: Thu, 24 Sep 2020 05:17:13 +0000 Message-ID: References: <1599549024-195051-1-git-send-email-abhinandan.gujjar@intel.com> In-Reply-To: <1599549024-195051-1-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: 62785ADBC40A684DAAEB8F616B8EE9EC.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: [217.140.110.7] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3b74222d-bb55-4111-c12e-08d860491d7f x-ms-traffictypediagnostic: DB8PR08MB5098:|HE1PR08MB2889: 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:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: jDiOJA+LpzAXVrAZOXkdCbkSEIxXvpajKf/vvCd0Tedw31WlqBZS3qc6CRjCZuJ+thsA0PNoTLjoEyZ474ajzN1Nw3k7Kzvao0nwWmwI4Ugohyh9/ZkykcnWK9bb/4oLqQRGUR/zj5GLx2zamtTj1zQFSpHf+L4DcpPV2jlZ8Nq+cq1jvJ+tmH8CeLFiz7ehYMmAMzbZRpGiFW/omQmP0X7Y5sjAZ9gI48pb/k14vwbXW7bNDg6FLeCG6ynph8BJoW2MVD47dQWAQsWWVi19WKYEWT8J0UcmihQ297ggq5dgtB34/1ERXBaUkPrmMcLsAQ38e9fMl9L6re5l1swHhQ== 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)(396003)(136003)(376002)(346002)(39850400004)(366004)(4326008)(478600001)(6506007)(30864003)(52536014)(54906003)(71200400001)(7696005)(186003)(26005)(110136005)(316002)(5660300002)(76116006)(2906002)(83380400001)(86362001)(8676002)(33656002)(66446008)(66476007)(66556008)(8936002)(9686003)(66946007)(64756008)(55016002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: 1MksqTyKwMWCefYgMANXVTgLJ6zHFXKjpqjm3RGi8eka80X9rZynJ4h+3wQEajNLNeB6gAGMAZUDtZsUWTlFJozrA+LYFQwvhGi4tb1JlBhg9r2layuBXmPBTnWaCw59UcAohTVy00biY/YsrpvgK9bsOAwjc2OyzEvWe+1oBJMds9d6HJjFmIN8Zh2kUGGH9rUemAlmrvwGW3Ag4uYi0oCQ8dxVHTbL1QvsPhT+EkH5QPbfdID00mqvNMmUIRS5ctCC+B37ZWdF0MGLxP/1G4maGqRIPheDsAV7B1yPB1B+Bl4Nzer/hzS/L8ymnSU5cogznbGNNuTi4KEP+cndLQa/jlri9DcvuVB/DHAkOVD2smCY/E5StWcwiDEFL7ABmHk7fpkcL1f6N/a8423Z4ovWv3EfPlv1nERSdio4TocEg+Pp5tSKX1/kT7cfDyDUOid3cZE5rqURGWPv0ASpR18w3Qsq8Vn98+s/obw/r2yW68PCOagn4R6SlCxMRJcR1ucslhNSUz4d7z73b6clXMn0wqlwdHIjAa+18QCM5vF4RfXfjTHR6A08DRnHq1ZyxTDDIkB6bBuTwRwj/16s1vpcV9QQDN2tC4+QKiXxTRAtGAUX3QXBJbfP0E8KqLbmsLlRCPenBWLljkFflaxufw== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5098 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: VE1EUR03FT037.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3624f4cd-7203-42a9-e549-08d8604918e6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QbECcdEg4uwc5NYhp2EBGo3iFm9fbHfACGx4hhh+GYHBRl2a9u8pFXVLoWX5J6Bk8NYvLYeOUsI5MtVCQI9bLJc+gAZx95PdSlwMOfdZhZxaqxUS2RWM18DaBR0E67bjX2FkK6E1vXMgCXAQECwnEWPSLPPJFku0K51QbK8D9q3eYYLwGZSCLL1gvmjEw6KbCWnShTqgpnj5us4GiY+nBz4nMRrdN5HJCwHzhzeB1lsVstwv1IvEOz5bSioshzMGWh3nrsHvUkvEFza5xB8OdlbsnU3VZGQf5CXhoFrWujZI2RL1Xd+ms9Oc+w61dRE4aRtOjcZ6ajXtzwisEH5O2bWOtzkWWDW8iOH5nRynbsdP2VExPCA4GB/83GnRoCgvIel7cvCnWzu+hoh4Q8Gn9b1WX3QbGsfFwfyN0Y9garj5hf/t68l7lJz5s1Pky3Br 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)(136003)(346002)(396003)(376002)(39850400004)(46966005)(47076004)(52536014)(2906002)(54906003)(30864003)(70206006)(110136005)(316002)(33656002)(36906005)(70586007)(5660300002)(186003)(8936002)(55016002)(26005)(82740400003)(6506007)(81166007)(7696005)(9686003)(336012)(4326008)(356005)(82310400003)(8676002)(478600001)(83380400001)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2020 05:17:21.5186 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b74222d-bb55-4111-c12e-08d860491d7f 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: VE1EUR03FT037.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB2889 Subject: Re: [dpdk-dev] [v2 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 > In an eventdev world, multiple workers (with ordered queue) will be worki= ng > on IPsec ESP processing. The ESP header's sequence number is unique and > has to be sequentially incremented in an orderly manner. > This rises a need for incrementing sequence number in crypto stage > especially in event crypto adapter. By adding a user callback to cryptode= v at > enqueue burst, the user callback will get executed in the context of even= t > crypto adapter. This helps the application to increment the ESP sequence > number atomically and orderly manner. >=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 > v1->v2: > Moved callback related members to the end of cryptodev struct Added > support for RCU >=20 > Signed-off-by: Abhinandan Gujjar > --- > config/common_base | 1 + > lib/librte_cryptodev/Makefile | 2 +- > lib/librte_cryptodev/rte_cryptodev.c | 157 > +++++++++++++++++++++++++ > lib/librte_cryptodev/rte_cryptodev.h | 154 > +++++++++++++++++++++++- > lib/librte_cryptodev/rte_cryptodev_version.map | 6 + > 5 files changed, 318 insertions(+), 2 deletions(-) >=20 > diff --git a/config/common_base b/config/common_base index > fbf0ee7..f5ebde4 100644 > --- a/config/common_base > +++ b/config/common_base > @@ -599,6 +599,7 @@ > CONFIG_RTE_LIBRTE_PMD_BBDEV_FPGA_5GNR_FEC=3Dy > # > CONFIG_RTE_LIBRTE_CRYPTODEV=3Dy > CONFIG_RTE_CRYPTO_MAX_DEVS=3D64 > +CONFIG_RTE_CRYPTODEV_CALLBACKS=3Dy >=20 > # > # Compile PMD for ARMv8 Crypto device > diff --git a/lib/librte_cryptodev/Makefile b/lib/librte_cryptodev/Makefil= e > index 73e77a2..514d552 100644 > --- a/lib/librte_cryptodev/Makefile > +++ b/lib/librte_cryptodev/Makefile > @@ -10,7 +10,7 @@ LIB =3D librte_cryptodev.a CFLAGS +=3D -O3 CFLAGS += =3D > $(WERROR_FLAGS) LDLIBS +=3D -lrte_eal -lrte_mempool -lrte_ring -lrte_mbu= f > -LDLIBS +=3D -lrte_kvargs > +LDLIBS +=3D -lrte_kvargs -lrte_rcu >=20 > # library source files > SRCS-y +=3D rte_cryptodev.c rte_cryptodev_pmd.c cryptodev_trace_points.c > diff --git a/lib/librte_cryptodev/rte_cryptodev.c > b/lib/librte_cryptodev/rte_cryptodev.c > index 1dd795b..2fb3e35 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.c > +++ b/lib/librte_cryptodev/rte_cryptodev.c > @@ -38,6 +38,7 @@ > #include > #include > #include > +#include >=20 > #include "rte_crypto.h" > #include "rte_cryptodev.h" > @@ -499,6 +500,10 @@ struct > rte_cryptodev_sym_session_pool_private_data { > return 0; > } >=20 > +#ifdef RTE_CRYPTODEV_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) @@ -1449,6 +1454,158 > @@ struct rte_cryptodev * > rte_spinlock_unlock(&rte_cryptodev_cb_lock); > } >=20 > +#ifdef RTE_CRYPTODEV_CALLBACKS > +int > +rte_cryptodev_rcu_qsbr_add(uint8_t dev_id, struct rte_rcu_qsbr *qsbr) { > + > + struct rte_cryptodev *dev; > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%" PRIu8, dev_id); > + return -EINVAL; > + } > + > + dev =3D &rte_crypto_devices[dev_id]; > + dev->qsbr =3D qsbr; > + return 0; > +} > + > +struct rte_cryptodev_enq_callback * > +rte_cryptodev_add_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + rte_cryptodev_enq_cb_fn cb_fn, > + void *cb_arg) > +{ > + struct rte_cryptodev *dev; > + struct rte_cryptodev_enq_callback *cb, *tail; > + > + if (!cb_fn) > + return NULL; > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%" PRIu8, 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; > + } > + > + cb->fn =3D cb_fn; > + cb->arg =3D cb_arg; > + > + 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_errno =3D ENOMEM; > + rte_free(cb); > + return NULL; > + } > + } > + > + /* Add the callbacks in fifo order. */ > + tail =3D dev->enq_cbs[qp_id]; > + if (tail) { > + while (tail->next) > + tail =3D tail->next; > + tail->next =3D cb; The store here needs to complete only after the cb->fn and cb->arg are writ= ten. You need to use __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE) > + } else > + dev->enq_cbs[qp_id] =3D cb; Same here, this should be __atomic_store_n(&dev->enq_cbs[qp_id], cb, __ATOM= IC_RELEASE) (same fixes are required in ethdev as well, will send out a patch) > + > + 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_enq_callback *cb) { > + struct rte_cryptodev *dev; > + struct rte_cryptodev_enq_callback **prev_cb, *curr_cb; > + uint16_t qp; > + int free_mem; > + int ret; > + > + free_mem =3D 1; > + > + if (!cb) { > + CDEV_LOG_ERR("cb is NULL"); > + return -EINVAL; > + } > + > + if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) { > + CDEV_LOG_ERR("Invalid dev_id=3D%" PRIu8, dev_id); > + return -EINVAL; > + } > + > + 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 -EINVAL; > + } > + > + if (!dev->qsbr) { > + CDEV_LOG_ERR("Rcu qsbr is NULL"); > + return -EINVAL; > + } > + > + rte_spinlock_lock(&rte_cryptodev_enq_cb_lock); > + if (dev->enq_cbs =3D=3D NULL) { > + rte_spinlock_unlock(&rte_cryptodev_enq_cb_lock); > + return -EINVAL; > + } > + > + prev_cb =3D &dev->enq_cbs[qp_id]; > + 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(dev->qsbr, > + RTE_QSBR_THRID_INVALID); > + rte_free(cb); > + } > + > + 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_sym_session_init(uint8_t dev_id, diff --git > a/lib/librte_cryptodev/rte_cryptodev.h > b/lib/librte_cryptodev/rte_cryptodev.h > index 7b3ebc2..2c7a47b 100644 > --- a/lib/librte_cryptodev/rte_cryptodev.h > +++ b/lib/librte_cryptodev/rte_cryptodev.h > @@ -530,6 +530,32 @@ struct rte_cryptodev_qp_conf { }; >=20 > /** > + * 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_enq_cb_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 > * > @@ -853,7 +879,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. */ @@ -870,6 > +895,17 @@ 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 > +/** > + * @internal > + * Structure used to hold information about the callbacks to be called > +for a > + * queue pair on enqueue. > + */ > +struct rte_cryptodev_enq_callback { > + struct rte_cryptodev_enq_callback *next; > + rte_cryptodev_enq_cb_fn fn; > + void *arg; > +}; > + > /** The data structure associated with each crypto device. */ struct > rte_cryptodev { > dequeue_pkt_burst_t dequeue_burst; > @@ -898,6 +934,14 @@ struct rte_cryptodev { > __extension__ > uint8_t attached : 1; > /**< Flag indicating the device is attached */ > + > +#ifdef RTE_CRYPTODEV_CALLBACKS > + struct rte_cryptodev_enq_callback **enq_cbs; > + /**< User application callback for pre enqueue processing */ > + > + struct rte_rcu_qsbr *qsbr; > + /** < RCU QSBR variable for rte_cryptodev_enq_callback */ #endif > } __rte_cache_aligned; >=20 > void * > @@ -1019,6 +1063,18 @@ struct rte_cryptodev_data { > struct rte_crypto_op **ops, uint16_t nb_ops) { > struct rte_cryptodev *dev =3D &rte_cryptodevs[dev_id]; > +#ifdef RTE_CRYPTODEV_CALLBACKS > + if (unlikely(dev->enq_cbs !=3D NULL && dev->enq_cbs[qp_id] !=3D NULL)) Suggest using __atomic_load_n(&dev->enq_cbs[qp_id], __ATOMIC_RELAXED) as th= is acts as the guard variable for cb->fn and cb->arg. > { > + struct rte_cryptodev_enq_callback *cb =3D > + dev->enq_cbs[qp_id]; > + > + do { > + nb_ops =3D cb->fn(dev_id, qp_id, ops, nb_ops, > + cb->arg); > + cb =3D cb->next; > + } while (cb !=3D NULL); > + } > +#endif >=20 > rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, > nb_ops); > return (*dev->enqueue_burst)( > @@ -1351,6 +1407,102 @@ struct rte_cryptodev_asym_session * > struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs > ofs, > struct rte_crypto_sym_vec *vec); >=20 > +#ifdef RTE_CRYPTODEV_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_enq_callback * > +rte_cryptodev_add_enq_callback(uint8_t dev_id, > + uint16_t qp_id, > + rte_cryptodev_enq_cb_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(). > + * > + * Note: The callback expects a RCU QSBR to be configured to > +synchronize > + * to free the memory. Application is expected to configure RCU QSBR > +after > + * adding an enqueue 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_enq_callback *cb); > + > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Associate RCU QSBR variable with a cryptodev. > + * > + * This function is used to add RCU QSBR to a crypto device. > + * The purpose of RCU is to help multiple threads to synchronize > + * with each other before initiating adding/removing callback > + * while dataplane threads are running enqueue callbacks. > + * > + * @param dev_id The identifier of the device. > + * @param qsr RCU QSBR configuration > + * @return > + * On success - 0 > + * On error - EINVAL. > + */ > + > +__rte_experimental > +int rte_cryptodev_rcu_qsbr_add(uint8_t dev_id, struct rte_rcu_qsbr > +*qsbr); #endif > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map > b/lib/librte_cryptodev/rte_cryptodev_version.map > index 02f6dcf..46de3ca 100644 > --- a/lib/librte_cryptodev/rte_cryptodev_version.map > +++ b/lib/librte_cryptodev/rte_cryptodev_version.map > @@ -64,6 +64,7 @@ DPDK_20.0 { > rte_cryptodev_sym_capability_get; > }; >=20 > + > EXPERIMENTAL { > global: >=20 > @@ -105,4 +106,9 @@ EXPERIMENTAL { >=20 > # added in 20.08 > rte_cryptodev_get_qp_status; > + > + # added in 20.11 > + rte_cryptodev_add_enq_callback; > + rte_cryptodev_remove_enq_callback; > + rte_cryptodev_rcu_qsbr_add; > }; > -- > 1.9.1