[2/8] cryptodev: move inline APIs into separate structure

Message ID 20210829125139.2173235-3-gakhil@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series cryptodev: hide internal strutures |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Akhil Goyal Aug. 29, 2021, 12:51 p.m. UTC
  Move fastpath inline function pointers from rte_cryptodev into a
separate structure accessed via a flat array.
The intension is to make rte_cryptodev and related structures private
to avoid future API/ABI breakages.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 lib/cryptodev/cryptodev_pmd.c      | 33 ++++++++++++++++++++++++++++++
 lib/cryptodev/cryptodev_pmd.h      |  9 ++++++++
 lib/cryptodev/rte_cryptodev.c      |  3 +++
 lib/cryptodev/rte_cryptodev_core.h | 19 +++++++++++++++++
 lib/cryptodev/version.map          |  4 ++++
 5 files changed, 68 insertions(+)
  

Comments

Fan Zhang Sept. 13, 2021, 2:11 p.m. UTC | #1
> -----Original Message-----
> From: Akhil Goyal <gakhil@marvell.com>
> Sent: Sunday, August 29, 2021 1:52 PM
> To: dev@dpdk.org
> Cc: anoobj@marvell.com; Nicolau, Radu <radu.nicolau@intel.com>; Doherty,
> Declan <declan.doherty@intel.com>; hemant.agrawal@nxp.com;
> matan@nvidia.com; Ananyev, Konstantin <konstantin.ananyev@intel.com>;
> thomas@monjalon.net; Zhang, Roy Fan <roy.fan.zhang@intel.com>;
> asomalap@amd.com; ruifeng.wang@arm.com;
> ajit.khaparde@broadcom.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Trahe, Fiona <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: [PATCH 2/8] cryptodev: move inline APIs into separate structure
> 
> Move fastpath inline function pointers from rte_cryptodev into a
> separate structure accessed via a flat array.
> The intension is to make rte_cryptodev and related structures private
> to avoid future API/ABI breakages.
> 
> Signed-off-by: Akhil Goyal <gakhil@marvell.com>
> ---
Tested-by: Rebecca Troy <rebecca.troy@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
  
Ananyev, Konstantin Sept. 16, 2021, 3:21 p.m. UTC | #2
Hi Akhil,

Overall, looks good to me.
Few comments below.
Konstantin

> Move fastpath inline function pointers from rte_cryptodev into a
> separate structure accessed via a flat array.
> The intension is to make rte_cryptodev and related structures private
> to avoid future API/ABI breakages.
> 
> Signed-off-by: Akhil Goyal <gakhil@marvell.com>
> ---
>  lib/cryptodev/cryptodev_pmd.c      | 33 ++++++++++++++++++++++++++++++
>  lib/cryptodev/cryptodev_pmd.h      |  9 ++++++++
>  lib/cryptodev/rte_cryptodev.c      |  3 +++
>  lib/cryptodev/rte_cryptodev_core.h | 19 +++++++++++++++++
>  lib/cryptodev/version.map          |  4 ++++
>  5 files changed, 68 insertions(+)
> 
> diff --git a/lib/cryptodev/cryptodev_pmd.c b/lib/cryptodev/cryptodev_pmd.c
> index 71e34140cd..46772dc355 100644
> --- a/lib/cryptodev/cryptodev_pmd.c
> +++ b/lib/cryptodev/cryptodev_pmd.c
> @@ -158,3 +158,36 @@ rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)
> 
>  	return 0;
>  }
> +
> +static uint16_t
> +dummy_crypto_enqueue_burst(__rte_unused uint8_t dev_id,
> +			  __rte_unused uint8_t qp_id,
> +			  __rte_unused struct rte_crypto_op **ops,
> +			  __rte_unused uint16_t nb_ops)
> +{
> +	CDEV_LOG_ERR(
> +		"crypto enqueue burst requested for unconfigured crypto device");
> +	return 0;
> +}
> +
> +static uint16_t
> +dummy_crypto_dequeue_burst(__rte_unused uint8_t dev_id,
> +			  __rte_unused uint8_t qp_id,
> +			  __rte_unused struct rte_crypto_op **ops,
> +			  __rte_unused uint16_t nb_ops)
> +{
> +	CDEV_LOG_ERR(
> +		"crypto enqueue burst requested for unconfigured crypto device");
> +	return 0;
> +}
> +
> +void
> +rte_cryptodev_api_reset(struct rte_cryptodev_api *api)
> +{
> +	static const struct rte_cryptodev_api dummy = {
> +		.enqueue_burst = dummy_crypto_enqueue_burst,
> +		.dequeue_burst = dummy_crypto_dequeue_burst,
> +	};
> +
> +	*api = dummy;
> +}
> diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
> index f775ba6beb..eeaea13a23 100644
> --- a/lib/cryptodev/cryptodev_pmd.h
> +++ b/lib/cryptodev/cryptodev_pmd.h
> @@ -520,6 +520,15 @@ RTE_INIT(init_ ##driver_id)\
>  	driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
>  }
> 
> +/**
> + * Reset crypto device fastpath APIs to dummy values.
> + *
> + * @param The *api* pointer to reset.
> + */
> +__rte_internal
> +void
> +rte_cryptodev_api_reset(struct rte_cryptodev_api *api);
> +
>  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 9fa3aff1d3..26f8390668 100644
> --- a/lib/cryptodev/rte_cryptodev.c
> +++ b/lib/cryptodev/rte_cryptodev.c
> @@ -54,6 +54,9 @@ static struct rte_cryptodev_global cryptodev_globals = {
>  		.nb_devs		= 0
>  };
> 
> +/* Public fastpath APIs. */
> +struct rte_cryptodev_api *rte_cryptodev_api;

I think it has to be an statically allocated array:
struct rte_cryptodev_api rte_cryptodev_api[RTE_CRYPTO_MAX_DEVS];
Other alternative would be to allocate space for it at some RTE_INIT() function,
but not sure is it really worth it.

Another thing - to make things a bit more error prone - probably
need to fill it with dummy pointers at RTE_INIT timeframe.
Also, I think we need to call rte_cryptodev_api_reset() at 
rte_cryptodev_pmd_destroy() or so.

> +
>  /* spinlock for crypto device callbacks */
>  static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
> 
> diff --git a/lib/cryptodev/rte_cryptodev_core.h b/lib/cryptodev/rte_cryptodev_core.h
> index 1633e55889..ec38f70e0c 100644
> --- a/lib/cryptodev/rte_cryptodev_core.h
> +++ b/lib/cryptodev/rte_cryptodev_core.h
> @@ -25,6 +25,25 @@ typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
>  		struct rte_crypto_op **ops,	uint16_t nb_ops);
>  /**< Enqueue packets for processing on queue pair of a device. */
> 
> +typedef uint16_t (*rte_crypto_dequeue_burst_t)(uint8_t dev_id, uint8_t qp_id,
> +					      struct rte_crypto_op **ops,
> +					      uint16_t nb_ops);
> +/**< @internal Dequeue processed packets from queue pair of a device. */
> +typedef uint16_t (*rte_crypto_enqueue_burst_t)(uint8_t dev_id, uint8_t qp_id,
> +					      struct rte_crypto_op **ops,
> +					      uint16_t nb_ops);
> +/**< @internal Enqueue packets for processing on queue pair of a device. */
> +
> +struct rte_cryptodev_api {
> +	rte_crypto_enqueue_burst_t enqueue_burst;
> +	/**< PMD enqueue burst function. */
> +	rte_crypto_dequeue_burst_t dequeue_burst;
> +	/**< PMD dequeue burst function. */
> +	uintptr_t reserved[6];
> +} __rte_cache_aligned;
> +
> +extern struct rte_cryptodev_api *rte_cryptodev_api;
> +
>  /**
>   * @internal
>   * The data part, with no function pointers, associated with each device.
> diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
> index 2fdf70002d..050089ae55 100644
> --- a/lib/cryptodev/version.map
> +++ b/lib/cryptodev/version.map
> @@ -57,6 +57,9 @@ DPDK_22 {
>  	rte_cryptodev_sym_session_init;
>  	rte_cryptodevs;
> 
> +	#added in 21.11
> +	rte_cryptodev_api;
> +
>  	local: *;
>  };
> 
> @@ -114,6 +117,7 @@ INTERNAL {
>  	global:
> 
>  	rte_cryptodev_allocate_driver;
> +	rte_cryptodev_api_reset;
>  	rte_cryptodev_pmd_allocate;
>  	rte_cryptodev_pmd_callback_process;
>  	rte_cryptodev_pmd_create;
> --
> 2.25.1
  

Patch

diff --git a/lib/cryptodev/cryptodev_pmd.c b/lib/cryptodev/cryptodev_pmd.c
index 71e34140cd..46772dc355 100644
--- a/lib/cryptodev/cryptodev_pmd.c
+++ b/lib/cryptodev/cryptodev_pmd.c
@@ -158,3 +158,36 @@  rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)
 
 	return 0;
 }
+
+static uint16_t
+dummy_crypto_enqueue_burst(__rte_unused uint8_t dev_id,
+			  __rte_unused uint8_t qp_id,
+			  __rte_unused struct rte_crypto_op **ops,
+			  __rte_unused uint16_t nb_ops)
+{
+	CDEV_LOG_ERR(
+		"crypto enqueue burst requested for unconfigured crypto device");
+	return 0;
+}
+
+static uint16_t
+dummy_crypto_dequeue_burst(__rte_unused uint8_t dev_id,
+			  __rte_unused uint8_t qp_id,
+			  __rte_unused struct rte_crypto_op **ops,
+			  __rte_unused uint16_t nb_ops)
+{
+	CDEV_LOG_ERR(
+		"crypto enqueue burst requested for unconfigured crypto device");
+	return 0;
+}
+
+void
+rte_cryptodev_api_reset(struct rte_cryptodev_api *api)
+{
+	static const struct rte_cryptodev_api dummy = {
+		.enqueue_burst = dummy_crypto_enqueue_burst,
+		.dequeue_burst = dummy_crypto_dequeue_burst,
+	};
+
+	*api = dummy;
+}
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index f775ba6beb..eeaea13a23 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -520,6 +520,15 @@  RTE_INIT(init_ ##driver_id)\
 	driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
 }
 
+/**
+ * Reset crypto device fastpath APIs to dummy values.
+ *
+ * @param The *api* pointer to reset.
+ */
+__rte_internal
+void
+rte_cryptodev_api_reset(struct rte_cryptodev_api *api);
+
 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 9fa3aff1d3..26f8390668 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -54,6 +54,9 @@  static struct rte_cryptodev_global cryptodev_globals = {
 		.nb_devs		= 0
 };
 
+/* Public fastpath APIs. */
+struct rte_cryptodev_api *rte_cryptodev_api;
+
 /* spinlock for crypto device callbacks */
 static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
diff --git a/lib/cryptodev/rte_cryptodev_core.h b/lib/cryptodev/rte_cryptodev_core.h
index 1633e55889..ec38f70e0c 100644
--- a/lib/cryptodev/rte_cryptodev_core.h
+++ b/lib/cryptodev/rte_cryptodev_core.h
@@ -25,6 +25,25 @@  typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
 		struct rte_crypto_op **ops,	uint16_t nb_ops);
 /**< Enqueue packets for processing on queue pair of a device. */
 
+typedef uint16_t (*rte_crypto_dequeue_burst_t)(uint8_t dev_id, uint8_t qp_id,
+					      struct rte_crypto_op **ops,
+					      uint16_t nb_ops);
+/**< @internal Dequeue processed packets from queue pair of a device. */
+typedef uint16_t (*rte_crypto_enqueue_burst_t)(uint8_t dev_id, uint8_t qp_id,
+					      struct rte_crypto_op **ops,
+					      uint16_t nb_ops);
+/**< @internal Enqueue packets for processing on queue pair of a device. */
+
+struct rte_cryptodev_api {
+	rte_crypto_enqueue_burst_t enqueue_burst;
+	/**< PMD enqueue burst function. */
+	rte_crypto_dequeue_burst_t dequeue_burst;
+	/**< PMD dequeue burst function. */
+	uintptr_t reserved[6];
+} __rte_cache_aligned;
+
+extern struct rte_cryptodev_api *rte_cryptodev_api;
+
 /**
  * @internal
  * The data part, with no function pointers, associated with each device.
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 2fdf70002d..050089ae55 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -57,6 +57,9 @@  DPDK_22 {
 	rte_cryptodev_sym_session_init;
 	rte_cryptodevs;
 
+	#added in 21.11
+	rte_cryptodev_api;
+
 	local: *;
 };
 
@@ -114,6 +117,7 @@  INTERNAL {
 	global:
 
 	rte_cryptodev_allocate_driver;
+	rte_cryptodev_api_reset;
 	rte_cryptodev_pmd_allocate;
 	rte_cryptodev_pmd_callback_process;
 	rte_cryptodev_pmd_create;