[05/11] examples/pipeline: support crypto devices

Message ID 20230111205608.87953-6-cristian.dumitrescu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series pipeline: add IPsec support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Cristian Dumitrescu Jan. 11, 2023, 8:56 p.m. UTC
  Add support for crypto devices in the application.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Kamalakannan R <kamalakannan.r@intel.com>
---
 examples/pipeline/obj.c | 61 +++++++++++++++++++++++++++++++++++++++++
 examples/pipeline/obj.h | 11 ++++++++
 2 files changed, 72 insertions(+)
  

Patch

diff --git a/examples/pipeline/obj.c b/examples/pipeline/obj.c
index a5c09e7219..078395c6aa 100644
--- a/examples/pipeline/obj.c
+++ b/examples/pipeline/obj.c
@@ -7,6 +7,7 @@ 
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
+#include <rte_cryptodev.h>
 
 #include "obj.h"
 
@@ -191,3 +192,63 @@  ethdev_config(const char *name, struct ethdev_params *params)
 
 	return 0;
 }
+
+/*
+ * cryptodev
+ */
+int
+cryptodev_config(const char *name, struct cryptodev_params *params)
+{
+	struct rte_cryptodev_info dev_info;
+	struct rte_cryptodev_config dev_conf;
+	struct rte_cryptodev_qp_conf queue_conf;
+	uint8_t dev_id;
+	uint32_t socket_id, i;
+	int status;
+
+	/* Check input parameters. */
+	if (!name ||
+	    !params->n_queue_pairs ||
+	    !params->queue_size)
+		return -EINVAL;
+
+	/* Find the crypto device. */
+	status = rte_cryptodev_get_dev_id(name);
+	if (status < 0)
+		return -EINVAL;
+
+	dev_id = (uint8_t)status;
+
+	rte_cryptodev_info_get(dev_id, &dev_info);
+	if (params->n_queue_pairs > dev_info.max_nb_queue_pairs)
+		return -EINVAL;
+
+	socket_id = rte_cryptodev_socket_id(dev_id);
+
+	/* Configure the crypto device. */
+	dev_conf.socket_id = socket_id;
+	dev_conf.nb_queue_pairs = params->n_queue_pairs;
+	dev_conf.ff_disable = 0;
+
+	status = rte_cryptodev_configure(dev_id, &dev_conf);
+	if (status)
+		return status;
+
+	/* Configure the crypto device queue pairs. */
+	queue_conf.nb_descriptors = params->queue_size;
+	queue_conf.mp_session = NULL;
+	queue_conf.mp_session_private = NULL;
+
+	for (i = 0; i < params->n_queue_pairs; i++) {
+		status = rte_cryptodev_queue_pair_setup(dev_id, i, &queue_conf, socket_id);
+		if (status)
+			return status;
+	}
+
+	/* Start the crypto device. */
+	status = rte_cryptodev_start(dev_id);
+	if (status)
+		return status;
+
+	return 0;
+}
diff --git a/examples/pipeline/obj.h b/examples/pipeline/obj.h
index fb091f4ba7..0f103be6a7 100644
--- a/examples/pipeline/obj.h
+++ b/examples/pipeline/obj.h
@@ -38,4 +38,15 @@  struct ethdev_params {
 int
 ethdev_config(const char *name, struct ethdev_params *params);
 
+/*
+ * cryptodev
+ */
+struct cryptodev_params {
+	uint32_t n_queue_pairs;
+	uint32_t queue_size;
+};
+
+int
+cryptodev_config(const char *name, struct cryptodev_params *params);
+
 #endif /* _INCLUDE_OBJ_H_ */