[v6,2/8] crypto/nitrox: create Nitrox symmetric cryptodev

Message ID 20190927062533.19005-3-rnagadheeraj@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: akhil goyal
Headers
Series add Nitrox crypto device support |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Nagadheeraj Rottela Sept. 27, 2019, 6:26 a.m. UTC
  Add Nitrox symmetric cryptodev with following operations,
- dev_configure
- dev_start
- dev_stop
- dev_close
- dev_infos_get

Signed-off-by: Nagadheeraj Rottela <rnagadheeraj@marvell.com>
---
 drivers/crypto/nitrox/Makefile        |   1 +
 drivers/crypto/nitrox/meson.build     |   1 +
 drivers/crypto/nitrox/nitrox_device.c |  13 +++
 drivers/crypto/nitrox/nitrox_device.h |   4 +
 drivers/crypto/nitrox/nitrox_sym.c    | 163 ++++++++++++++++++++++++++++++++++
 drivers/crypto/nitrox/nitrox_sym.h    |  13 +++
 6 files changed, 195 insertions(+)
 create mode 100644 drivers/crypto/nitrox/nitrox_sym.c
 create mode 100644 drivers/crypto/nitrox/nitrox_sym.h
  

Patch

diff --git a/drivers/crypto/nitrox/Makefile b/drivers/crypto/nitrox/Makefile
index 7681a6603..06c96ccd7 100644
--- a/drivers/crypto/nitrox/Makefile
+++ b/drivers/crypto/nitrox/Makefile
@@ -26,5 +26,6 @@  LDLIBS += -lrte_cryptodev
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_NITROX) += nitrox_device.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_NITROX) += nitrox_hal.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_NITROX) += nitrox_logs.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_NITROX) += nitrox_sym.c
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/crypto/nitrox/meson.build b/drivers/crypto/nitrox/meson.build
index ad81f8cd8..1277cf58e 100644
--- a/drivers/crypto/nitrox/meson.build
+++ b/drivers/crypto/nitrox/meson.build
@@ -12,4 +12,5 @@  sources = files(
 		'nitrox_device.c',
 		'nitrox_hal.c',
 		'nitrox_logs.c',
+		'nitrox_sym.c',
 		)
diff --git a/drivers/crypto/nitrox/nitrox_device.c b/drivers/crypto/nitrox/nitrox_device.c
index a73528211..5b319dd68 100644
--- a/drivers/crypto/nitrox/nitrox_device.c
+++ b/drivers/crypto/nitrox/nitrox_device.c
@@ -6,6 +6,7 @@ 
 
 #include "nitrox_device.h"
 #include "nitrox_hal.h"
+#include "nitrox_sym.h"
 
 #define PCI_VENDOR_ID_CAVIUM	0x177d
 #define NITROX_V_PCI_VF_DEV_ID	0x13
@@ -66,6 +67,7 @@  nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		struct rte_pci_device *pdev)
 {
 	struct nitrox_device *ndev;
+	int err;
 
 	/* Nitrox CSR space */
 	if (!pdev->mem_resource[0].addr)
@@ -76,6 +78,12 @@  nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		return -ENOMEM;
 
 	ndev_init(ndev, pdev);
+	err = nitrox_sym_pmd_create(ndev);
+	if (err) {
+		ndev_release(ndev);
+		return err;
+	}
+
 	return 0;
 }
 
@@ -83,11 +91,16 @@  static int
 nitrox_pci_remove(struct rte_pci_device *pdev)
 {
 	struct nitrox_device *ndev;
+	int err;
 
 	ndev = find_ndev(pdev);
 	if (!ndev)
 		return -ENODEV;
 
+	err = nitrox_sym_pmd_destroy(ndev);
+	if (err)
+		return err;
+
 	ndev_release(ndev);
 	return 0;
 }
diff --git a/drivers/crypto/nitrox/nitrox_device.h b/drivers/crypto/nitrox/nitrox_device.h
index 0d0167de2..6b8095f42 100644
--- a/drivers/crypto/nitrox/nitrox_device.h
+++ b/drivers/crypto/nitrox/nitrox_device.h
@@ -8,10 +8,14 @@ 
 #include <rte_bus_pci.h>
 #include <rte_cryptodev.h>
 
+struct nitrox_sym_device;
+
 struct nitrox_device {
 	TAILQ_ENTRY(nitrox_device) next;
 	struct rte_pci_device *pdev;
 	uint8_t *bar_addr;
+	struct nitrox_sym_device *sym_dev;
+	struct rte_device rte_sym_dev;
 	uint16_t nr_queues;
 };
 
diff --git a/drivers/crypto/nitrox/nitrox_sym.c b/drivers/crypto/nitrox/nitrox_sym.c
new file mode 100644
index 000000000..12817c6c7
--- /dev/null
+++ b/drivers/crypto/nitrox/nitrox_sym.c
@@ -0,0 +1,163 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2019 Marvell International Ltd.
+ */
+
+#include <stdbool.h>
+
+#include <rte_cryptodev_pmd.h>
+#include <rte_crypto.h>
+
+#include "nitrox_sym.h"
+#include "nitrox_device.h"
+#include "nitrox_logs.h"
+
+#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
+
+struct nitrox_sym_device {
+	struct rte_cryptodev *cdev;
+	struct nitrox_device *ndev;
+};
+
+uint8_t nitrox_sym_drv_id;
+static const char nitrox_sym_drv_name[] = RTE_STR(CRYPTODEV_NAME_NITROX_PMD);
+static const struct rte_driver nitrox_rte_sym_drv = {
+	.name = nitrox_sym_drv_name,
+	.alias = nitrox_sym_drv_name
+};
+
+static int nitrox_sym_dev_qp_release(struct rte_cryptodev *cdev,
+				     uint16_t qp_id);
+
+static int
+nitrox_sym_dev_config(struct rte_cryptodev *cdev,
+		      struct rte_cryptodev_config *config)
+{
+	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
+	struct nitrox_device *ndev = sym_dev->ndev;
+
+	if (config->nb_queue_pairs > ndev->nr_queues) {
+		NITROX_LOG(ERR, "Invalid queue pairs, max supported %d\n",
+			   ndev->nr_queues);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+nitrox_sym_dev_start(struct rte_cryptodev *cdev)
+{
+	/* SE cores initialization is done in PF */
+	RTE_SET_USED(cdev);
+	return 0;
+}
+
+static void
+nitrox_sym_dev_stop(struct rte_cryptodev *cdev)
+{
+	/* SE cores cleanup is done in PF */
+	RTE_SET_USED(cdev);
+}
+
+static int
+nitrox_sym_dev_close(struct rte_cryptodev *cdev)
+{
+	int i, ret;
+
+	for (i = 0; i < cdev->data->nb_queue_pairs; i++) {
+		ret = nitrox_sym_dev_qp_release(cdev, i);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static void
+nitrox_sym_dev_info_get(struct rte_cryptodev *cdev,
+			struct rte_cryptodev_info *info)
+{
+	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
+	struct nitrox_device *ndev = sym_dev->ndev;
+
+	if (!info)
+		return;
+
+	info->max_nb_queue_pairs = ndev->nr_queues;
+	info->feature_flags = cdev->feature_flags;
+	info->driver_id = nitrox_sym_drv_id;
+	info->sym.max_nb_sessions = 0;
+}
+
+static int
+nitrox_sym_dev_qp_release(struct rte_cryptodev *cdev, uint16_t qp_id)
+{
+	RTE_SET_USED(cdev);
+	RTE_SET_USED(qp_id);
+	return 0;
+}
+
+static struct rte_cryptodev_ops nitrox_cryptodev_ops = {
+	.dev_configure		= nitrox_sym_dev_config,
+	.dev_start		= nitrox_sym_dev_start,
+	.dev_stop		= nitrox_sym_dev_stop,
+	.dev_close		= nitrox_sym_dev_close,
+	.dev_infos_get		= nitrox_sym_dev_info_get,
+	.stats_get		= NULL,
+	.stats_reset		= NULL,
+	.queue_pair_setup	= NULL,
+	.queue_pair_release     = NULL,
+	.sym_session_get_size   = NULL,
+	.sym_session_configure  = NULL,
+	.sym_session_clear      = NULL
+};
+
+int
+nitrox_sym_pmd_create(struct nitrox_device *ndev)
+{
+	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+	struct rte_cryptodev_pmd_init_params init_params = {
+			.name = "",
+			.socket_id = ndev->pdev->device.numa_node,
+			.private_data_size = sizeof(struct nitrox_sym_device)
+	};
+	struct rte_cryptodev *cdev;
+
+	rte_pci_device_name(&ndev->pdev->addr, name, sizeof(name));
+	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN, "_n5sym");
+	ndev->rte_sym_dev.driver = &nitrox_rte_sym_drv;
+	ndev->rte_sym_dev.numa_node = ndev->pdev->device.numa_node;
+	ndev->rte_sym_dev.devargs = NULL;
+	cdev = rte_cryptodev_pmd_create(name, &ndev->rte_sym_dev,
+					&init_params);
+	if (!cdev) {
+		NITROX_LOG(ERR, "Cryptodev '%s' creation failed\n", name);
+		return -ENODEV;
+	}
+
+	ndev->rte_sym_dev.name = cdev->data->name;
+	cdev->driver_id = nitrox_sym_drv_id;
+	cdev->dev_ops = &nitrox_cryptodev_ops;
+	cdev->enqueue_burst = NULL;
+	cdev->dequeue_burst = NULL;
+	cdev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
+		RTE_CRYPTODEV_FF_HW_ACCELERATED;
+
+	ndev->sym_dev = cdev->data->dev_private;
+	ndev->sym_dev->cdev = cdev;
+	ndev->sym_dev->ndev = ndev;
+	NITROX_LOG(DEBUG, "Created cryptodev '%s', dev_id %d, drv_id %d\n",
+		   cdev->data->name, cdev->data->dev_id, nitrox_sym_drv_id);
+	return 0;
+}
+
+int
+nitrox_sym_pmd_destroy(struct nitrox_device *ndev)
+{
+	return rte_cryptodev_pmd_destroy(ndev->sym_dev->cdev);
+}
+
+static struct cryptodev_driver nitrox_crypto_drv;
+RTE_PMD_REGISTER_CRYPTO_DRIVER(nitrox_crypto_drv,
+		nitrox_rte_sym_drv,
+		nitrox_sym_drv_id);
diff --git a/drivers/crypto/nitrox/nitrox_sym.h b/drivers/crypto/nitrox/nitrox_sym.h
new file mode 100644
index 000000000..f30847e8a
--- /dev/null
+++ b/drivers/crypto/nitrox/nitrox_sym.h
@@ -0,0 +1,13 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2019 Marvell International Ltd.
+ */
+
+#ifndef _NITROX_SYM_H_
+#define _NITROX_SYM_H_
+
+struct nitrox_device;
+
+int nitrox_sym_pmd_create(struct nitrox_device *ndev);
+int nitrox_sym_pmd_destroy(struct nitrox_device *ndev);
+
+#endif /* _NITROX_SYM_H_ */