diff mbox series

[3/4] crypto/qat: move capabilities initialization to spec files

Message ID 20210901144729.26784-4-arkadiuszx.kusztal@intel.com (mailing list archive)
State Superseded
Delegated to: akhil goyal
Headers show
Series drivers/qat: isolate implementations of qat generations | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Kusztal, ArkadiuszX Sept. 1, 2021, 2:47 p.m. UTC
Move capabilites static struct to particular generations into
separate translation units that it can be isolated from each other.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/crypto/qat/dev/qat_sym_pmd_gen1.c | 27 ++++++++-
 drivers/crypto/qat/dev/qat_sym_pmd_gen2.c | 25 ++++++++-
 drivers/crypto/qat/dev/qat_sym_pmd_gen3.c | 26 ++++++++-
 drivers/crypto/qat/dev/qat_sym_pmd_gen4.c | 24 +++++++-
 drivers/crypto/qat/qat_sym_pmd.c          | 68 +++++++----------------
 drivers/crypto/qat/qat_sym_pmd.h          | 19 ++++++-
 6 files changed, 135 insertions(+), 54 deletions(-)
diff mbox series

Patch

diff --git a/drivers/crypto/qat/dev/qat_sym_pmd_gen1.c b/drivers/crypto/qat/dev/qat_sym_pmd_gen1.c
index 4a4dc9ab55..40ec77f846 100644
--- a/drivers/crypto/qat/dev/qat_sym_pmd_gen1.c
+++ b/drivers/crypto/qat/dev/qat_sym_pmd_gen1.c
@@ -8,6 +8,12 @@ 
 #include "qat_sym_session.h"
 #include "qat_sym.h"
 #include "qat_sym_pmd_gen1.h"
+#include "qat_sym_capabilities.h"
+
+static struct rte_cryptodev_capabilities qat_gen1_sym_capabilities[] = {
+	QAT_BASE_GEN1_SYM_CAPABILITIES,
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
 
 int qat_sym_qp_setup_gen1(struct rte_cryptodev *dev, uint16_t qp_id,
 	const struct rte_cryptodev_qp_conf *qp_conf,
@@ -49,7 +55,24 @@  struct rte_cryptodev_ops crypto_qat_gen1_ops = {
 		.sym_configure_raw_dp_ctx = qat_sym_configure_dp_ctx,
 };
 
-RTE_INIT(qat_sym_pmd_gen1_init)
+static struct
+qat_capabilities_info get_capabilties_gen1(
+			struct qat_pci_device *qat_dev __rte_unused)
 {
-	QAT_CRYPTODEV_OPS[QAT_GEN1] = &crypto_qat_gen1_ops;
+	struct qat_capabilities_info capa_info;
+
+	capa_info.data = qat_gen1_sym_capabilities;
+	capa_info.size = sizeof(qat_gen1_sym_capabilities);
+	return capa_info;
 }
+
+static struct
+qat_sym_pmd_dev_ops qat_sym_pmd_ops_gen1 = {
+	.qat_sym_get_capabilities	= get_capabilties_gen1,
+};
+
+RTE_INIT(qat_sym_pmd_gen1_init)
+{
+	QAT_CRYPTODEV_OPS[QAT_GEN1]	= &crypto_qat_gen1_ops;
+	qat_sym_pmd_ops[QAT_GEN1]	= &qat_sym_pmd_ops_gen1;
+}
\ No newline at end of file
diff --git a/drivers/crypto/qat/dev/qat_sym_pmd_gen2.c b/drivers/crypto/qat/dev/qat_sym_pmd_gen2.c
index 6344d7de13..18dfca3a84 100644
--- a/drivers/crypto/qat/dev/qat_sym_pmd_gen2.c
+++ b/drivers/crypto/qat/dev/qat_sym_pmd_gen2.c
@@ -7,9 +7,16 @@ 
 #include "qat_sym_pmd.h"
 #include "qat_sym_session.h"
 #include "qat_sym.h"
+#include "qat_sym_capabilities.h"
 
 #define MIXED_CRYPTO_MIN_FW_VER 0x04090000
 
+static struct rte_cryptodev_capabilities qat_gen2_sym_capabilities[] = {
+	QAT_BASE_GEN1_SYM_CAPABILITIES,
+	QAT_EXTRA_GEN2_SYM_CAPABILITIES,
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
 static int qat_sym_qp_setup_gen2(struct rte_cryptodev *dev, uint16_t qp_id,
 	const struct rte_cryptodev_qp_conf *qp_conf,
 	int socket_id)
@@ -74,7 +81,23 @@  struct rte_cryptodev_ops crypto_qat_gen2_ops = {
 		.sym_configure_raw_dp_ctx = qat_sym_configure_dp_ctx,
 };
 
+static struct
+qat_capabilities_info get_capabilties_gen2(
+			struct qat_pci_device *qat_dev __rte_unused)
+{
+	struct qat_capabilities_info capa_info;
+	capa_info.data = qat_gen2_sym_capabilities;
+	capa_info.size = sizeof(qat_gen2_sym_capabilities);
+	return capa_info;
+}
+
+static struct
+qat_sym_pmd_dev_ops qat_sym_pmd_ops_gen2 = {
+	.qat_sym_get_capabilities	= get_capabilties_gen2,
+};
+
 RTE_INIT(qat_sym_pmd_gen2)
 {
-	QAT_CRYPTODEV_OPS[QAT_GEN2] = &crypto_qat_gen2_ops;
+	QAT_CRYPTODEV_OPS[QAT_GEN2]	= &crypto_qat_gen2_ops;
+	qat_sym_pmd_ops[QAT_GEN2]	= &qat_sym_pmd_ops_gen2;
 }
diff --git a/drivers/crypto/qat/dev/qat_sym_pmd_gen3.c b/drivers/crypto/qat/dev/qat_sym_pmd_gen3.c
index f8488cd122..e914a09362 100644
--- a/drivers/crypto/qat/dev/qat_sym_pmd_gen3.c
+++ b/drivers/crypto/qat/dev/qat_sym_pmd_gen3.c
@@ -9,6 +9,13 @@ 
 #include "qat_sym.h"
 #include "qat_sym_pmd_gen1.h"
 
+static struct rte_cryptodev_capabilities qat_gen3_sym_capabilities[] = {
+	QAT_BASE_GEN1_SYM_CAPABILITIES,
+	QAT_EXTRA_GEN2_SYM_CAPABILITIES,
+	QAT_EXTRA_GEN3_SYM_CAPABILITIES,
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
 struct rte_cryptodev_ops crypto_qat_gen3_ops = {
 
 		/* Device related operations */
@@ -33,7 +40,24 @@  struct rte_cryptodev_ops crypto_qat_gen3_ops = {
 		.sym_configure_raw_dp_ctx = qat_sym_configure_dp_ctx,
 };
 
+static struct
+qat_capabilities_info get_capabilties_gen3(
+			struct qat_pci_device *qat_dev __rte_unused)
+{
+	struct qat_capabilities_info capa_info;
+	capa_info.data = qat_gen3_sym_capabilities;
+	capa_info.size = sizeof(qat_gen3_sym_capabilities);
+	return capa_info;
+}
+
+static struct
+qat_sym_pmd_dev_ops qat_sym_pmd_ops_gen3 = {
+	.qat_sym_get_capabilities	= get_capabilties_gen3,
+};
+
+
 RTE_INIT(qat_sym_pmd_gen3_init)
 {
-	QAT_CRYPTODEV_OPS[QAT_GEN3] = &crypto_qat_gen3_ops;
+	QAT_CRYPTODEV_OPS[QAT_GEN3]	= &crypto_qat_gen3_ops;
+	qat_sym_pmd_ops[QAT_GEN3]	= &qat_sym_pmd_ops_gen3;
 }
diff --git a/drivers/crypto/qat/dev/qat_sym_pmd_gen4.c b/drivers/crypto/qat/dev/qat_sym_pmd_gen4.c
index 9470e78fb1..834ae88d38 100644
--- a/drivers/crypto/qat/dev/qat_sym_pmd_gen4.c
+++ b/drivers/crypto/qat/dev/qat_sym_pmd_gen4.c
@@ -8,6 +8,11 @@ 
 #include "qat_sym_session.h"
 #include "qat_sym.h"
 
+static struct rte_cryptodev_capabilities qat_gen4_sym_capabilities[] = {
+	QAT_BASE_GEN4_SYM_CAPABILITIES,
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
 static int
 qat_select_valid_queue(struct qat_pci_device *qat_dev, int qp_id,
 			enum qat_service_type service_type)
@@ -76,7 +81,24 @@  struct rte_cryptodev_ops crypto_qat_gen4_ops = {
 		.sym_configure_raw_dp_ctx = qat_sym_configure_dp_ctx,
 };
 
+static struct
+qat_capabilities_info get_capabilties_gen4(
+			struct qat_pci_device *qat_dev __rte_unused)
+{
+	struct qat_capabilities_info capa_info;
+
+	capa_info.data = qat_gen4_sym_capabilities;
+	capa_info.size = sizeof(qat_gen4_sym_capabilities);
+	return capa_info;
+}
+
+static struct
+qat_sym_pmd_dev_ops qat_sym_pmd_ops_gen4 = {
+	.qat_sym_get_capabilities	= get_capabilties_gen4,
+};
+
 RTE_INIT(qat_sym_pmd_gen4_init)
 {
-	QAT_CRYPTODEV_OPS[QAT_GEN4] = &crypto_qat_gen4_ops;
+	QAT_CRYPTODEV_OPS[QAT_GEN4]	= &crypto_qat_gen4_ops;
+	qat_sym_pmd_ops[QAT_GEN4]	= &qat_sym_pmd_ops_gen4;
 }
diff --git a/drivers/crypto/qat/qat_sym_pmd.c b/drivers/crypto/qat/qat_sym_pmd.c
index ee1a7e52bc..dc1dcbe34f 100644
--- a/drivers/crypto/qat/qat_sym_pmd.c
+++ b/drivers/crypto/qat/qat_sym_pmd.c
@@ -22,28 +22,9 @@ 
 
 uint8_t qat_sym_driver_id;
 
-static const struct rte_cryptodev_capabilities qat_gen1_sym_capabilities[] = {
-	QAT_BASE_GEN1_SYM_CAPABILITIES,
-	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
-};
-
-static const struct rte_cryptodev_capabilities qat_gen2_sym_capabilities[] = {
-	QAT_BASE_GEN1_SYM_CAPABILITIES,
-	QAT_EXTRA_GEN2_SYM_CAPABILITIES,
-	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
-};
-
-static const struct rte_cryptodev_capabilities qat_gen3_sym_capabilities[] = {
-	QAT_BASE_GEN1_SYM_CAPABILITIES,
-	QAT_EXTRA_GEN2_SYM_CAPABILITIES,
-	QAT_EXTRA_GEN3_SYM_CAPABILITIES,
-	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
-};
-
-static const struct rte_cryptodev_capabilities qat_gen4_sym_capabilities[] = {
-	QAT_BASE_GEN4_SYM_CAPABILITIES,
-	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
-};
+struct qat_capabilities_info qat_sym_capabilities[QAT_DEV_GEN_NO];
+struct rte_cryptodev_ops *QAT_CRYPTODEV_OPS[QAT_DEV_GEN_NO];
+struct qat_sym_pmd_dev_ops *qat_sym_pmd_ops[QAT_DEV_GEN_NO];
 
 #ifdef RTE_LIB_SECURITY
 static const struct rte_cryptodev_capabilities
@@ -62,6 +43,16 @@  static const struct rte_security_capability qat_security_capabilities[] = {
 
 struct rte_cryptodev_ops *QAT_CRYPTODEV_OPS[QAT_DEV_GEN_NO];
 
+static struct
+qat_capabilities_info qat_sym_get_capa_info(
+		struct qat_pci_device *qat_dev)
+{
+	struct qat_sym_pmd_dev_ops *ops =
+			qat_sym_pmd_ops[qat_dev->qat_dev_gen];
+
+	return ops->qat_sym_get_capabilities(qat_dev);
+}
+
 int qat_sym_dev_config(__rte_unused struct rte_cryptodev *dev,
 		__rte_unused struct rte_cryptodev_config *config)
 {
@@ -83,7 +74,7 @@  int qat_sym_dev_close(struct rte_cryptodev *dev)
 	int i, ret;
 
 	for (i = 0; i < dev->data->nb_queue_pairs; i++) {
-		ret = qat_sym_qp_release(dev, i);
+		ret = dev->dev_ops->queue_pair_release(dev, i);
 		if (ret < 0)
 			return ret;
 	}
@@ -171,7 +162,7 @@  int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 
 	/* If qp is already in use free ring memory and qp metadata. */
 	if (*qp_addr != NULL) {
-		ret = qat_sym_qp_release(dev, qp_id);
+		ret = dev->dev_ops->queue_pair_release(dev, qp_id);
 		if (ret < 0)
 			return -EBUSY;
 	}
@@ -283,6 +274,7 @@  qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,
 	char capa_memz_name[RTE_CRYPTODEV_NAME_MAX_LEN];
 	struct rte_cryptodev *cryptodev;
 	struct qat_sym_dev_private *internals;
+	struct qat_capabilities_info capa_info;
 	const struct rte_cryptodev_capabilities *capabilities;
 	uint64_t capa_size;
 
@@ -370,30 +362,10 @@  qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,
 	internals->qat_dev = qat_pci_dev;
 
 	internals->sym_dev_id = cryptodev->data->dev_id;
-	switch (qat_pci_dev->qat_dev_gen) {
-	case QAT_GEN1:
-		capabilities = qat_gen1_sym_capabilities;
-		capa_size = sizeof(qat_gen1_sym_capabilities);
-		break;
-	case QAT_GEN2:
-		capabilities = qat_gen2_sym_capabilities;
-		capa_size = sizeof(qat_gen2_sym_capabilities);
-		break;
-	case QAT_GEN3:
-		capabilities = qat_gen3_sym_capabilities;
-		capa_size = sizeof(qat_gen3_sym_capabilities);
-		break;
-	case QAT_GEN4:
-		capabilities = qat_gen4_sym_capabilities;
-		capa_size = sizeof(qat_gen4_sym_capabilities);
-		break;
-	default:
-		QAT_LOG(DEBUG,
-			"QAT gen %d capabilities unknown",
-			qat_pci_dev->qat_dev_gen);
-		ret = -(EINVAL);
-		goto error;
-	}
+
+	capa_info = qat_sym_get_capa_info(qat_pci_dev);
+	capabilities = capa_info.data;
+	capa_size = capa_info.size;
 
 	internals->capa_mz = rte_memzone_lookup(capa_memz_name);
 	if (internals->capa_mz == NULL) {
diff --git a/drivers/crypto/qat/qat_sym_pmd.h b/drivers/crypto/qat/qat_sym_pmd.h
index f676a296e4..a03d2a0f04 100644
--- a/drivers/crypto/qat/qat_sym_pmd.h
+++ b/drivers/crypto/qat/qat_sym_pmd.h
@@ -26,7 +26,24 @@ 
 
 extern uint8_t qat_sym_driver_id;
 
-extern struct rte_cryptodev_ops *QAT_CRYPTODEV_OPS[];
+struct qat_capabilities_info {
+	struct rte_cryptodev_capabilities *data;
+	uint64_t size;
+};
+
+extern struct
+rte_cryptodev_ops *QAT_CRYPTODEV_OPS[];
+extern struct
+qat_capabilities_info qat_sym_capabilities[];
+
+typedef struct qat_capabilities_info (*get_capabilities_info_t)
+			(struct qat_pci_device *qat_dev);
+
+struct qat_sym_pmd_dev_ops {
+	get_capabilities_info_t qat_sym_get_capabilities;
+};
+
+extern struct qat_sym_pmd_dev_ops *qat_sym_pmd_ops[];
 
 /** private data structure for a QAT device.
  * This QAT device is a device offering only symmetric crypto service,