DPDK patches and discussions
 help / color / mirror / Atom feed
From: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
To: declan.doherty@intel.com
Cc: dev@dpdk.org, Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
Subject: [dpdk-dev] [RFC] cryptodev: remove crypto device type enumeration
Date: Fri,  5 May 2017 13:07:55 +0200	[thread overview]
Message-ID: <20170505110755.8403-1-slawomirx.mrozowicz@intel.com> (raw)

This RFC changes device type identification to be based on a unique
driver id replacing the current device type enumeration, which needed
library changes every time a new crypto driver was added.

The driver id is assigned dynamically during driver registration using
the new macro RTE_PMD_REGISTER_CRYPTO_DRIVER which returns a unique
uint8_t identifier for that driver. New APIs are also introduced
to allow retrieval of the driver id using the driver name.

Library code is included in the RFC
(implementation in progress, API complete).

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
 drivers/crypto/null/null_crypto_pmd.c          |  7 ++-
 drivers/crypto/null/null_crypto_pmd_ops.c      |  2 +-
 drivers/crypto/openssl/rte_openssl_pmd.c       | 13 +++--
 drivers/crypto/openssl/rte_openssl_pmd_ops.c   |  2 +-
 lib/librte_cryptodev/rte_cryptodev.c           | 39 +++++++++++++--
 lib/librte_cryptodev/rte_cryptodev.h           | 68 +++++++++++++++++---------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       |  2 +-
 lib/librte_cryptodev/rte_cryptodev_version.map | 10 +++-
 8 files changed, 108 insertions(+), 35 deletions(-)

diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c
index 023450a..90eb41a 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -95,7 +95,9 @@ get_session(struct null_crypto_qp *qp, struct rte_crypto_sym_op *op)
 
 	if (op->sess_type == RTE_CRYPTO_SYM_OP_WITH_SESSION) {
 		if (unlikely(op->session == NULL ||
-			     op->session->dev_type != RTE_CRYPTODEV_NULL_PMD))
+			     op->session->driver_id !=
+					     rte_cryptodev_driver_id_get(
+				RTE_STR(RTE_CRYPTODEV_NULL_PMD))))
 			return NULL;
 
 		sess = (struct null_crypto_session *)op->session->_private;
@@ -183,7 +185,8 @@ cryptodev_null_create(const char *name,
 		goto init_error;
 	}
 
-	dev->dev_type = RTE_CRYPTODEV_NULL_PMD;
+	dev->driver_id = rte_cryptodev_driver_id_get(
+			RTE_STR(RTE_CRYPTODEV_NULL_PMD));
 	dev->dev_ops = null_crypto_pmd_ops;
 
 	/* register rx/tx burst functions for data path */
diff --git a/drivers/crypto/null/null_crypto_pmd_ops.c b/drivers/crypto/null/null_crypto_pmd_ops.c
index 12c946c..a7c891e 100644
--- a/drivers/crypto/null/null_crypto_pmd_ops.c
+++ b/drivers/crypto/null/null_crypto_pmd_ops.c
@@ -151,7 +151,7 @@ null_crypto_pmd_info_get(struct rte_cryptodev *dev,
 	struct null_crypto_private *internals = dev->data->dev_private;
 
 	if (dev_info != NULL) {
-		dev_info->dev_type = dev->dev_type;
+		dev_info->driver_id = dev->driver_id;
 		dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
 		dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
 		dev_info->feature_flags = dev->feature_flags;
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index f0c5ca3..5069d02 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -448,8 +448,9 @@ get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
 	if (op->sym->sess_type == RTE_CRYPTO_SYM_OP_WITH_SESSION) {
 		/* get existing session */
 		if (likely(op->sym->session != NULL &&
-				op->sym->session->dev_type ==
-				RTE_CRYPTODEV_OPENSSL_PMD))
+				op->sym->session->driver_id ==
+						rte_cryptodev_driver_id_get(
+				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))))
 			sess = (struct openssl_session *)
 				op->sym->session->_private;
 	} else  {
@@ -1283,7 +1284,8 @@ cryptodev_openssl_create(const char *name,
 		goto init_error;
 	}
 
-	dev->dev_type = RTE_CRYPTODEV_OPENSSL_PMD;
+	dev->driver_id = rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
 	dev->dev_ops = rte_openssl_pmd_ops;
 
 	/* register rx/tx burst functions for data path */
@@ -1366,9 +1368,14 @@ static struct rte_vdev_driver cryptodev_openssl_pmd_drv = {
 	.remove = cryptodev_openssl_remove
 };
 
+static uint8_t cryptodev_openssl_driver_id;
+
 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_OPENSSL_PMD,
 	cryptodev_openssl_pmd_drv);
 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_OPENSSL_PMD,
 	"max_nb_queue_pairs=<int> "
 	"max_nb_sessions=<int> "
 	"socket_id=<int>");
+RTE_PMD_REGISTER_CRYPTO_DRIVER(CRYPTODEV_NAME_OPENSSL_PMD,
+	cryptodev_openssl_driver_id);
+
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 25d1a4b..ecf28c2 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -536,7 +536,7 @@ openssl_pmd_info_get(struct rte_cryptodev *dev,
 	struct openssl_private *internals = dev->data->dev_private;
 
 	if (dev_info != NULL) {
-		dev_info->dev_type = dev->dev_type;
+		dev_info->driver_id = dev->driver_id;
 		dev_info->feature_flags = dev->feature_flags;
 		dev_info->capabilities = openssl_pmd_capabilities;
 		dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index 6f5080c..46ee042 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -509,12 +509,12 @@ rte_cryptodev_count(void)
 }
 
 uint8_t
-rte_cryptodev_count_devtype(enum rte_cryptodev_type type)
+rte_cryptodev_device_count_by_driver(uint8_t driver_id)
 {
 	uint8_t i, dev_count = 0;
 
 	for (i = 0; i < rte_cryptodev_globals->max_devs; i++)
-		if (rte_cryptodev_globals->devs[i].dev_type == type &&
+		if (rte_cryptodev_globals->devs[i].driver_id == driver_id &&
 			rte_cryptodev_globals->devs[i].attached ==
 					RTE_CRYPTODEV_ATTACHED)
 			dev_count++;
@@ -1293,7 +1293,7 @@ rte_cryptodev_sym_session_init(struct rte_mempool *mp,
 	memset(sess, 0, mp->elt_size);
 
 	sess->dev_id = dev->data->dev_id;
-	sess->dev_type = dev->dev_type;
+	sess->driver_id = dev->driver_id;
 	sess->mp = mp;
 
 	if (dev->dev_ops->session_initialize)
@@ -1460,7 +1460,7 @@ rte_cryptodev_sym_session_free(uint8_t dev_id,
 	dev = &rte_crypto_devices[dev_id];
 
 	/* Check the session belongs to this device type */
-	if (sess->dev_type != dev->dev_type)
+	if (sess->driver_id != dev->driver_id)
 		return sess;
 
 	/* Let device implementation clear session material */
@@ -1572,3 +1572,34 @@ rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix)
 
 	return -1;
 }
+
+static struct {
+	char name[RTE_CRYPTODEV_NAME_LEN];
+} rte_cryptodev_registered_drivers[RTE_CRYPTO_MAX_DEVS];
+
+static uint8_t rte_cryptodev_driver_id;
+
+uint8_t
+rte_cryptodev_driver_id_get(const char *name)
+{
+	for (uint8_t id = 0; id < rte_cryptodev_driver_id; id++)
+		if (strcmp(name, rte_cryptodev_registered_drivers[id].name)
+				== 0)
+			return id;
+	return 0;
+}
+
+char *
+rte_cryptodev_driver_name_get(uint8_t driver_id)
+{
+	return rte_cryptodev_registered_drivers[driver_id].name;
+}
+
+uint8_t
+rte_cryptodev_allocate_driver_id(const char *name)
+{
+	rte_cryptodev_driver_id++;
+	strcpy(rte_cryptodev_registered_drivers
+			[rte_cryptodev_driver_id].name, name);
+	return rte_cryptodev_driver_id;
+}
diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h
index 88aeb87..533017c 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -73,21 +73,6 @@ extern "C" {
 #define CRYPTODEV_NAME_DPAA2_SEC_PMD	cryptodev_dpaa2_sec_pmd
 /**< NXP DPAA2 - SEC PMD device name */
 
-/** Crypto device type */
-enum rte_cryptodev_type {
-	RTE_CRYPTODEV_NULL_PMD = 1,	/**< Null crypto PMD */
-	RTE_CRYPTODEV_AESNI_GCM_PMD,	/**< AES-NI GCM PMD */
-	RTE_CRYPTODEV_AESNI_MB_PMD,	/**< AES-NI multi buffer PMD */
-	RTE_CRYPTODEV_QAT_SYM_PMD,	/**< QAT PMD Symmetric Crypto */
-	RTE_CRYPTODEV_SNOW3G_PMD,	/**< SNOW 3G PMD */
-	RTE_CRYPTODEV_KASUMI_PMD,	/**< KASUMI PMD */
-	RTE_CRYPTODEV_ZUC_PMD,		/**< ZUC PMD */
-	RTE_CRYPTODEV_OPENSSL_PMD,    /**<  OpenSSL PMD */
-	RTE_CRYPTODEV_ARMV8_PMD,	/**< ARMv8 crypto PMD */
-	RTE_CRYPTODEV_SCHEDULER_PMD,	/**< Crypto Scheduler PMD */
-	RTE_CRYPTODEV_DPAA2_SEC_PMD,    /**< NXP DPAA2 - SEC PMD */
-};
-
 extern const char **rte_cyptodev_names;
 
 /* Logging Macros */
@@ -321,7 +306,7 @@ rte_cryptodev_get_feature_name(uint64_t flag);
 /**  Crypto device information */
 struct rte_cryptodev_info {
 	const char *driver_name;		/**< Driver name. */
-	enum rte_cryptodev_type dev_type;	/**< Device type */
+	uint8_t driver_id;			/**< Driver identifier */
 	struct rte_pci_device *pci_dev;		/**< PCI information. */
 
 	uint64_t feature_flags;			/**< Feature flags */
@@ -454,13 +439,13 @@ rte_cryptodev_count(void);
 /**
  * Get number of crypto device defined type.
  *
- * @param	type	type of device.
+ * @param	driver_id	driver identifier.
  *
  * @return
  *   Returns number of crypto device.
  */
 extern uint8_t
-rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
+rte_cryptodev_device_count_by_driver(uint8_t driver_id);
 
 /**
  * Get number and identifiers of attached crypto device.
@@ -475,6 +460,7 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
 uint8_t
 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
 		uint8_t nb_devices);
+
 /*
  * Return the NUMA socket to which a device is connected
  *
@@ -732,8 +718,8 @@ struct rte_cryptodev {
 	struct rte_device *device;
 	/**< Backing device */
 
-	enum rte_cryptodev_type dev_type;
-	/**< Crypto device type */
+	uint8_t driver_id;
+	/**< Crypto driver identifier*/
 
 	struct rte_cryptodev_cb_list link_intr_cbs;
 	/**< User application callback for interrupts if present */
@@ -870,8 +856,8 @@ struct rte_cryptodev_sym_session {
 	struct {
 		uint8_t dev_id;
 		/**< Device Id */
-		enum rte_cryptodev_type dev_type;
-		/** Crypto Device type session created on */
+		uint8_t driver_id;
+		/** Crypto driver identifier session created on */
 		struct rte_mempool *mp;
 		/**< Mempool session allocated from */
 	} __rte_aligned(8);
@@ -952,6 +938,44 @@ int
 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
 		struct rte_cryptodev_sym_session *session);
 
+/**
+ * Provide driver identifier.
+ *
+ * @param name
+ *   The pointer to a driver name.
+ * @return
+ *  The driver type identifier or 0 if no driver found
+ */
+uint8_t rte_cryptodev_driver_id_get(const char *name);
+
+/**
+ * Provide driver name.
+ *
+ * @param driver_id
+ *   The driver identifier.
+ * @return
+ *  The driver name or null if no driver found
+ */
+char *rte_cryptodev_driver_name_get(uint8_t driver_id);
+
+/**
+ * Allocate driver identifier.
+ *
+ * @param name
+ *   The pointer to a driver name to be initialized.
+ * @return
+ *  The driver type identifier
+ */
+uint8_t rte_cryptodev_allocate_driver_id(const char *name);
+
+
+#define RTE_PMD_REGISTER_CRYPTO_DRIVER(name, driver_id)\
+RTE_INIT(init_ ##driver_id);\
+static void init_ ##driver_id(void)\
+{\
+	driver_id = rte_cryptodev_allocate_driver_id(RTE_STR(name));\
+}
+
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h
index 356b9dc..ef32c12 100644
--- a/lib/librte_cryptodev/rte_cryptodev_pmd.h
+++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h
@@ -69,7 +69,7 @@ struct rte_cryptodev_session {
 	RTE_STD_C11
 	struct {
 		uint8_t dev_id;
-		enum rte_cryptodev_type type;
+		uint8_t driver_id;
 		struct rte_mempool *mp;
 	} __rte_aligned(8);
 
diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map b/lib/librte_cryptodev/rte_cryptodev_version.map
index 9ac510e..7e6d783 100644
--- a/lib/librte_cryptodev/rte_cryptodev_version.map
+++ b/lib/librte_cryptodev/rte_cryptodev_version.map
@@ -6,7 +6,6 @@ DPDK_16.04 {
 	rte_cryptodev_callback_unregister;
 	rte_cryptodev_close;
 	rte_cryptodev_count;
-	rte_cryptodev_count_devtype;
 	rte_cryptodev_configure;
 	rte_cryptodev_create_vdev;
 	rte_cryptodev_get_dev_id;
@@ -74,3 +73,12 @@ DPDK_17.05 {
 	rte_cryptodev_queue_pair_detach_sym_session;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_cryptodev_device_count_by_driver;
+
+} DPDK_17.05;
+
+
-- 
2.5.0

             reply	other threads:[~2017-05-05 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-05 11:07 Slawomir Mrozowicz [this message]
2017-05-05 15:37 ` Declan Doherty
2017-05-08 10:35   ` Declan Doherty

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=20170505110755.8403-1-slawomirx.mrozowicz@intel.com \
    --to=slawomirx.mrozowicz@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    /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).