DPDK patches and discussions
 help / color / mirror / Atom feed
From: Akhil Goyal <gakhil@marvell.com>
To: <dev@dpdk.org>
Cc: <anoobj@marvell.com>, <radu.nicolau@intel.com>,
	<declan.doherty@intel.com>, <hemant.agrawal@nxp.com>,
	<matan@nvidia.com>, <konstantin.ananyev@intel.com>,
	<thomas@monjalon.net>, <roy.fan.zhang@intel.com>,
	<asomalap@amd.com>, <ruifeng.wang@arm.com>,
	<ajit.khaparde@broadcom.com>, <pablo.de.lara.guarch@intel.com>,
	<fiona.trahe@intel.com>, <adwivedi@marvell.com>,
	<michaelsh@marvell.com>, <rnagadheeraj@marvell.com>,
	<jianjay.zhou@huawei.com>, <jerinj@marvell.com>,
	Akhil Goyal <gakhil@marvell.com>
Subject: [dpdk-dev] [PATCH 3/8] cryptodev: add helper functions for new datapath interface
Date: Sun, 29 Aug 2021 18:21:34 +0530	[thread overview]
Message-ID: <20210829125139.2173235-4-gakhil@marvell.com> (raw)
In-Reply-To: <20210829125139.2173235-1-gakhil@marvell.com>

Add helper functions and macros to help drivers to
transition to new datapath interface.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 lib/cryptodev/cryptodev_pmd.h | 246 ++++++++++++++++++++++++++++++++++
 lib/cryptodev/rte_cryptodev.c |  40 +++++-
 lib/cryptodev/version.map     |   4 +
 3 files changed, 289 insertions(+), 1 deletion(-)

diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index eeaea13a23..d40e5cee94 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -70,6 +70,13 @@ struct cryptodev_driver {
 	const struct rte_driver *driver;
 	uint8_t id;
 };
+/**
+ * @internal
+ * The pool of *rte_cryptodev* structures. The size of the pool
+ * is configured at compile-time in the <rte_cryptodev.c> file.
+ */
+extern struct rte_cryptodev rte_crypto_devices[];
+
 
 /**
  * Get the rte_cryptodev structure device pointer for the device. Assumes a
@@ -529,6 +536,245 @@ __rte_internal
 void
 rte_cryptodev_api_reset(struct rte_cryptodev_api *api);
 
+/**
+ * @internal
+ * Helper routine for cryptodev_dequeue_burst.
+ * Should be called as first thing on entrance to the PMD's
+ * rte_cryptodev_dequeue_burst implementation.
+ * Does necessary checks and returns pointer to cryptodev identifier.
+ *
+ * @param dev_id
+ *  The device identifier of the crypto device.
+ * @param qp_id
+ *  The index of the queue pair from which processed crypto ops will
+ *  be dequeued.
+ *
+ * @return
+ *  Pointer to device queue pair on success or NULL otherwise.
+ */
+__rte_internal
+static inline void *
+_rte_cryptodev_dequeue_prolog(uint8_t dev_id, uint8_t qp_id)
+{
+	struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
+
+	return dev->data->queue_pairs[qp_id];
+}
+
+/**
+ * @internal
+ * Helper routine for crypto driver dequeue API.
+ * Should be called at exit from PMD's rte_cryptodev_dequeue_burst
+ * implementation.
+ * Does necessary post-processing - invokes RX callbacks if any, tracing, etc.
+ *
+ * @param dev_id
+ *  The device identifier of the Crypto device.
+ * @param qp_id
+ *  The index of the queue pair from which to retrieve input crypto_ops.
+ * @param ops
+ *   The address of an array of pointers to *rte_crypto_op* structures that
+ *   have been retrieved from the device.
+ * @param nb_ops
+ *   The number of ops that were retrieved from the device.
+ *
+ * @return
+ *  The number of crypto ops effectively supplied to the *ops* array.
+ */
+__rte_internal
+static inline uint16_t
+_rte_cryptodev_dequeue_epilog(uint16_t dev_id, uint16_t qp_id,
+	struct rte_crypto_op **ops, uint16_t nb_ops)
+{
+#ifdef RTE_CRYPTO_CALLBACKS
+	struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
+
+	if (unlikely(dev->deq_cbs != 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 = &dev->deq_cbs[qp_id];
+		rte_rcu_qsbr_thread_online(list->qsbr, 0);
+		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
+
+		while (cb != NULL) {
+			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
+					cb->arg);
+			cb = cb->next;
+		};
+
+		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
+	}
+#endif
+
+	return nb_ops;
+}
+#define _RTE_CRYPTO_DEQ_FUNC(fn)	_rte_crypto_deq_##fn
+
+/**
+ * @internal
+ * Helper macro to create new API wrappers for existing PMD dequeue functions.
+ */
+#define _RTE_CRYPTO_DEQ_PROTO(fn) \
+	uint16_t _RTE_CRYPTO_DEQ_FUNC(fn)(uint8_t dev_id, uint8_t qp_id, \
+			struct rte_crypto_op **ops, uint16_t nb_ops)
+
+/**
+ * @internal
+ * Helper macro to create new API wrappers for existing PMD dequeue functions.
+ */
+#define _RTE_CRYPTO_DEQ_DEF(fn) \
+_RTE_CRYPTO_DEQ_PROTO(fn) \
+{ \
+	void *qp = _rte_cryptodev_dequeue_prolog(dev_id, qp_id); \
+	if (qp == NULL) \
+		return 0; \
+	nb_ops = fn(qp, ops, nb_ops); \
+	return _rte_cryptodev_dequeue_epilog(dev_id, qp_id, ops, nb_ops); \
+}
+
+/**
+ * @internal
+ * Helper routine for cryptodev_enqueue_burst.
+ * Should be called as first thing on entrance to the PMD's
+ * rte_cryptodev_enqueue_burst implementation.
+ * Does necessary checks and returns pointer to cryptodev queue pair.
+ *
+ * @param dev_id
+ *  The device identifier of the crypto device.
+ * @param qp_id
+ *  The index of the queue pair in which packets will be enqueued.
+ * @param ops
+ *   The address of an array of pointers to *rte_crypto_op* structures that
+ *   will be enqueued to the device.
+ * @param nb_ops
+ *   The number of ops that will be sent to the device.
+ *
+ * @return
+ *  Pointer to device queue pair on success or NULL otherwise.
+ */
+__rte_internal
+static inline void *
+_rte_cryptodev_enqueue_prolog(uint8_t dev_id, uint8_t qp_id,
+		struct rte_crypto_op **ops, uint16_t nb_ops)
+{
+	struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
+
+#ifdef RTE_CRYPTO_CALLBACKS
+	if (unlikely(dev->enq_cbs != 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 = &dev->enq_cbs[qp_id];
+		rte_rcu_qsbr_thread_online(list->qsbr, 0);
+		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
+
+		while (cb != NULL) {
+			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
+					cb->arg);
+			cb = cb->next;
+		};
+
+		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
+	}
+#endif
+	return dev->data->queue_pairs[qp_id];
+}
+
+#define _RTE_CRYPTO_ENQ_FUNC(fn)	_rte_crypto_enq_##fn
+
+/**
+ * @internal
+ * Helper macro to create new API wrappers for existing PMD enqueue functions.
+ */
+#define _RTE_CRYPTO_ENQ_PROTO(fn) \
+	uint16_t _RTE_CRYPTO_ENQ_FUNC(fn)(uint8_t dev_id, uint8_t qp_id, \
+			struct rte_crypto_op **ops, uint16_t nb_ops)
+
+/**
+ * @internal
+ * Helper macro to create new API wrappers for existing PMD enqueue functions.
+ */
+#define _RTE_CRYPTO_ENQ_DEF(fn) \
+_RTE_CRYPTO_ENQ_PROTO(fn) \
+{ \
+	void *qp = _rte_cryptodev_enqueue_prolog(dev_id, qp_id, ops, nb_ops); \
+	if (qp == NULL) \
+		return 0; \
+	return fn(qp, ops, nb_ops); \
+}
+
+/**
+ * @internal
+ * Helper routine to get enqueue burst function of a given device.
+ *
+ * @param dev_id
+ *  The device identifier of the Crypto device.
+ *
+ * @return
+ *  The function if valid else NULL
+ */
+__rte_internal
+rte_crypto_enqueue_burst_t
+rte_crypto_get_enq_burst_fn(uint8_t dev_id);
+
+/**
+ * @internal
+ * Helper routine to get dequeue burst function of a given device.
+ *
+ * @param dev_id
+ *  The device identifier of the Crypto device.
+ *
+ * @return
+ *  The function if valid else NULL
+ */
+__rte_internal
+rte_crypto_dequeue_burst_t
+rte_crypto_get_deq_burst_fn(uint8_t dev_id);
+
+/**
+ * @internal
+ * Helper routine to set enqueue burst function of a given device.
+ *
+ * @param dev_id
+ *  The device identifier of the Crypto device.
+ *
+ * @return
+ *  0		Success.
+ *  -EINVAL	Failure if dev_id or fn are in-valid.
+ */
+__rte_internal
+int
+rte_crypto_set_enq_burst_fn(uint8_t dev_id, rte_crypto_enqueue_burst_t fn);
+
+/**
+ * @internal
+ * Helper routine to set dequeue burst function of a given device.
+ *
+ * @param dev_id
+ *  The device identifier of the Crypto device.
+ *
+ * @return
+ *  0		Success.
+ *  -EINVAL	Failure if dev_id or fn are in-valid.
+ */
+__rte_internal
+int
+rte_crypto_set_deq_burst_fn(uint8_t dev_id, rte_crypto_dequeue_burst_t fn);
+
+
 static inline void *
 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
 		uint8_t driver_id) {
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 26f8390668..4ab82d21d0 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -44,7 +44,7 @@
 
 static uint8_t nb_drivers;
 
-static struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
+struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
 
 struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
 
@@ -1270,6 +1270,44 @@ rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
 			socket_id);
 }
 
+rte_crypto_enqueue_burst_t
+rte_crypto_get_enq_burst_fn(uint8_t dev_id)
+{
+	if (dev_id >= RTE_CRYPTO_MAX_DEVS) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+	return rte_cryptodev_api[dev_id].enqueue_burst;
+}
+
+rte_crypto_dequeue_burst_t
+rte_crypto_get_deq_burst_fn(uint8_t dev_id)
+{
+	if (dev_id >= RTE_CRYPTO_MAX_DEVS) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+	return rte_cryptodev_api[dev_id].dequeue_burst;
+}
+
+int
+rte_crypto_set_enq_burst_fn(uint8_t dev_id, rte_crypto_enqueue_burst_t fn)
+{
+	if (dev_id >= RTE_CRYPTO_MAX_DEVS || fn == NULL)
+		return -EINVAL;
+	rte_cryptodev_api[dev_id].enqueue_burst = fn;
+	return 0;
+}
+
+int
+rte_crypto_set_deq_burst_fn(uint8_t dev_id, rte_crypto_dequeue_burst_t fn)
+{
+	if (dev_id >= RTE_CRYPTO_MAX_DEVS || fn == NULL)
+		return -EINVAL;
+	rte_cryptodev_api[dev_id].dequeue_burst = fn;
+	return 0;
+}
+
 struct rte_cryptodev_cb *
 rte_cryptodev_add_enq_callback(uint8_t dev_id,
 			       uint16_t qp_id,
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 050089ae55..b64384cc05 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -116,6 +116,10 @@ EXPERIMENTAL {
 INTERNAL {
 	global:
 
+	rte_crypto_get_deq_burst_fn;
+	rte_crypto_get_enq_burst_fn;
+	rte_crypto_set_deq_burst_fn;
+	rte_crypto_set_enq_burst_fn;
 	rte_cryptodev_allocate_driver;
 	rte_cryptodev_api_reset;
 	rte_cryptodev_pmd_allocate;
-- 
2.25.1


  parent reply	other threads:[~2021-08-29 12:52 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 12:51 [dpdk-dev] [PATCH 0/8] cryptodev: hide internal strutures Akhil Goyal
2021-08-29 12:51 ` [dpdk-dev] [PATCH 1/8] cryptodev: separate out internal structures Akhil Goyal
2021-09-08 10:50   ` Anoob Joseph
2021-09-08 11:11     ` Akhil Goyal
2021-09-13 14:10   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 2/8] cryptodev: move inline APIs into separate structure Akhil Goyal
2021-09-13 14:11   ` Zhang, Roy Fan
2021-09-16 15:21   ` Ananyev, Konstantin
2021-08-29 12:51 ` Akhil Goyal [this message]
2021-08-30 20:07   ` [dpdk-dev] [PATCH 3/8] cryptodev: add helper functions for new datapath interface Zhang, Roy Fan
2021-08-31  6:14     ` Akhil Goyal
2021-09-13 14:20   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 4/8] cryptodev: use new API for datapath functions Akhil Goyal
2021-09-13 14:20   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 5/8] drivers/crypto: use new framework for datapath Akhil Goyal
2021-09-13 14:20   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 6/8] crypto/scheduler: rename enq-deq functions Akhil Goyal
2021-09-13 14:21   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 7/8] crypto/scheduler: update for new datapath framework Akhil Goyal
2021-09-13 14:21   ` Zhang, Roy Fan
2021-08-29 12:51 ` [dpdk-dev] [PATCH 8/8] cryptodev: move device specific structures Akhil Goyal
2021-09-13 14:22   ` Zhang, Roy Fan
2021-09-06 18:29 ` [dpdk-dev] [PATCH 0/8] cryptodev: hide internal strutures Akhil Goyal
2021-09-13 14:09 ` Zhang, Roy Fan
2021-10-11 12:43 ` [dpdk-dev] [PATCH v2 0/5] cryptodev: hide internal structures Akhil Goyal
2021-10-11 12:43   ` [dpdk-dev] [PATCH v2 1/5] cryptodev: separate out " Akhil Goyal
2021-10-11 14:50     ` Zhang, Roy Fan
2021-10-11 12:43   ` [dpdk-dev] [PATCH v2 2/5] cryptodev: allocate max space for internal qp array Akhil Goyal
2021-10-11 14:51     ` Zhang, Roy Fan
2021-10-11 12:43   ` [dpdk-dev] [PATCH v2 3/5] cryptodev: move inline APIs into separate structure Akhil Goyal
2021-10-11 14:45     ` Zhang, Roy Fan
2021-10-18  7:02       ` Akhil Goyal
2021-10-11 12:43   ` [dpdk-dev] [PATCH v2 4/5] cryptodev: update fast path APIs to use new flat array Akhil Goyal
2021-10-11 14:54     ` Zhang, Roy Fan
2021-10-11 12:43   ` [dpdk-dev] [PATCH v2 5/5] cryptodev: move device specific structures Akhil Goyal
2021-10-11 15:05     ` Zhang, Roy Fan
2021-10-18  7:07       ` Akhil Goyal
2021-10-11 16:03   ` [dpdk-dev] [PATCH v2 0/5] cryptodev: hide internal structures Zhang, Roy Fan
2021-10-11 17:07     ` Ji, Kai
2021-10-11 18:21       ` Zhang, Roy Fan
2021-10-15 18:38   ` Ananyev, Konstantin
2021-10-15 18:42     ` Akhil Goyal
2021-10-19 11:03       ` Ananyev, Konstantin
2021-10-18 14:41   ` [dpdk-dev] [PATCH v3 0/7] " Akhil Goyal
2021-10-18 14:41     ` [dpdk-dev] [PATCH v3 1/7] cryptodev: separate out " Akhil Goyal
2021-10-18 14:41     ` [dpdk-dev] [PATCH v3 2/7] cryptodev: allocate max space for internal qp array Akhil Goyal
2021-10-18 14:41     ` [dpdk-dev] [PATCH v3 3/7] cryptodev: move inline APIs into separate structure Akhil Goyal
2021-10-19 11:11       ` Ananyev, Konstantin
2021-10-19 11:50         ` Akhil Goyal
2021-10-19 14:27           ` Ananyev, Konstantin
2021-10-19 16:00       ` Zhang, Roy Fan
2021-10-18 14:41     ` [dpdk-dev] [PATCH v3 4/7] cryptodev: add PMD device probe finish API Akhil Goyal
2021-10-19 16:01       ` Zhang, Roy Fan
2021-10-18 14:41     ` [dpdk-dev] [PATCH v3 5/7] drivers/crypto: invoke probing finish function Akhil Goyal
2021-10-19 16:03       ` Zhang, Roy Fan
2021-10-20  7:05       ` Matan Azrad
2021-10-18 14:42     ` [dpdk-dev] [PATCH v3 6/7] cryptodev: update fast path APIs to use new flat array Akhil Goyal
2021-10-19 12:28       ` Ananyev, Konstantin
2021-10-19 12:47         ` Akhil Goyal
2021-10-19 14:25           ` Ananyev, Konstantin
2021-10-18 14:42     ` [dpdk-dev] [PATCH v3 7/7] cryptodev: move device specific structures Akhil Goyal
2021-10-20 10:25     ` [dpdk-dev] [PATCH v3 0/7] cryptodev: hide internal structures Power, Ciara
2021-10-20 11:27     ` [dpdk-dev] [PATCH v4 0/8] " Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 1/8] cryptodev: separate out " Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 2/8] cryptodev: allocate max space for internal qp array Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 3/8] cryptodev: move inline APIs into separate structure Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 4/8] crypto/scheduler: use proper API for device start/stop Akhil Goyal
2021-10-20 11:31         ` Zhang, Roy Fan
2021-10-20 12:20           ` Ananyev, Konstantin
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 5/8] cryptodev: add PMD device probe finish API Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 6/8] drivers/crypto: invoke probing finish function Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 7/8] cryptodev: update fast path APIs to use new flat array Akhil Goyal
2021-10-20 11:27       ` [dpdk-dev] [PATCH v4 8/8] cryptodev: move device specific structures Akhil Goyal
2021-10-20 13:36       ` [dpdk-dev] [PATCH v4 0/8] cryptodev: hide internal structures Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210829125139.2173235-4-gakhil@marvell.com \
    --to=gakhil@marvell.com \
    --cc=adwivedi@marvell.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=anoobj@marvell.com \
    --cc=asomalap@amd.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@intel.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerinj@marvell.com \
    --cc=jianjay.zhou@huawei.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=matan@nvidia.com \
    --cc=michaelsh@marvell.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=radu.nicolau@intel.com \
    --cc=rnagadheeraj@marvell.com \
    --cc=roy.fan.zhang@intel.com \
    --cc=ruifeng.wang@arm.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).