[v3,5/9] crypto/ionic: add capabilities and basic ops

Message ID 20240607142740.60175-6-andrew.boyer@amd.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers
Series crypto/ionic: introduce AMD Pensando driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Boyer June 7, 2024, 2:27 p.m. UTC
  This exposes the supported capabilities to the stack.

Signed-off-by: Andrew Boyer <andrew.boyer@amd.com>
---
 drivers/crypto/ionic/ionic_crypto.h      |  3 ++
 drivers/crypto/ionic/ionic_crypto_caps.c | 25 +++++++++
 drivers/crypto/ionic/ionic_crypto_main.c |  8 +++
 drivers/crypto/ionic/ionic_crypto_ops.c  | 66 ++++++++++++++++++++++++
 drivers/crypto/ionic/meson.build         |  2 +
 5 files changed, 104 insertions(+)
 create mode 100644 drivers/crypto/ionic/ionic_crypto_caps.c
 create mode 100644 drivers/crypto/ionic/ionic_crypto_ops.c
  

Patch

diff --git a/drivers/crypto/ionic/ionic_crypto.h b/drivers/crypto/ionic/ionic_crypto.h
index 065e1bd826..f487768c10 100644
--- a/drivers/crypto/ionic/ionic_crypto.h
+++ b/drivers/crypto/ionic/ionic_crypto.h
@@ -34,6 +34,8 @@  extern int iocpt_logtype;
 
 #define IOCPT_PRINT_CALL() IOCPT_PRINT(DEBUG, " >>")
 
+const struct rte_cryptodev_capabilities *iocpt_get_caps(uint64_t flags);
+
 static inline void iocpt_struct_size_checks(void)
 {
 	RTE_BUILD_BUG_ON(sizeof(struct ionic_doorbell) != 8);
@@ -227,6 +229,7 @@  int iocpt_probe(void *bus_dev, struct rte_device *rte_dev,
 int iocpt_remove(struct rte_device *rte_dev);
 
 void iocpt_configure(struct iocpt_dev *dev);
+int iocpt_assign_ops(struct rte_cryptodev *cdev);
 void iocpt_deinit(struct iocpt_dev *dev);
 
 int iocpt_dev_identify(struct iocpt_dev *dev);
diff --git a/drivers/crypto/ionic/ionic_crypto_caps.c b/drivers/crypto/ionic/ionic_crypto_caps.c
new file mode 100644
index 0000000000..c22681fabc
--- /dev/null
+++ b/drivers/crypto/ionic/ionic_crypto_caps.c
@@ -0,0 +1,25 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021-2024 Advanced Micro Devices, Inc.
+ */
+
+#include <rte_cryptodev.h>
+
+#include "ionic_crypto.h"
+
+static const struct rte_cryptodev_capabilities iocpt_sym_caps[] = {
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
+static const struct rte_cryptodev_capabilities iocpt_asym_caps[] = {
+	/* None */
+	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
+const struct rte_cryptodev_capabilities *
+iocpt_get_caps(uint64_t flags)
+{
+	if (flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
+		return iocpt_asym_caps;
+	else
+		return iocpt_sym_caps;
+}
diff --git a/drivers/crypto/ionic/ionic_crypto_main.c b/drivers/crypto/ionic/ionic_crypto_main.c
index 1b668b3c3e..e95d2918d2 100644
--- a/drivers/crypto/ionic/ionic_crypto_main.c
+++ b/drivers/crypto/ionic/ionic_crypto_main.c
@@ -505,8 +505,16 @@  iocpt_probe(void *bus_dev, struct rte_device *rte_dev,
 		goto err_free_objs;
 	}
 
+	err = iocpt_assign_ops(cdev);
+	if (err != 0) {
+		IOCPT_PRINT(ERR, "Failed to configure opts");
+		goto err_deinit_dev;
+	}
+
 	return 0;
 
+err_deinit_dev:
+	iocpt_deinit(dev);
 err_free_objs:
 	iocpt_free_objs(dev);
 err_destroy_crypto_dev:
diff --git a/drivers/crypto/ionic/ionic_crypto_ops.c b/drivers/crypto/ionic/ionic_crypto_ops.c
new file mode 100644
index 0000000000..74a6ce56ea
--- /dev/null
+++ b/drivers/crypto/ionic/ionic_crypto_ops.c
@@ -0,0 +1,66 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021-2024 Advanced Micro Devices, Inc.
+ */
+
+#include <rte_cryptodev.h>
+#include <cryptodev_pmd.h>
+#include <rte_errno.h>
+#include <rte_malloc.h>
+#include <rte_mempool.h>
+
+#include "ionic_crypto.h"
+
+static int
+iocpt_op_config(struct rte_cryptodev *cdev,
+		struct rte_cryptodev_config *config __rte_unused)
+{
+	struct iocpt_dev *dev = cdev->data->dev_private;
+
+	iocpt_configure(dev);
+
+	return 0;
+}
+
+static int
+iocpt_op_close(struct rte_cryptodev *cdev)
+{
+	struct iocpt_dev *dev = cdev->data->dev_private;
+
+	iocpt_deinit(dev);
+
+	return 0;
+}
+
+static void
+iocpt_op_info_get(struct rte_cryptodev *cdev, struct rte_cryptodev_info *info)
+{
+	struct iocpt_dev *dev = cdev->data->dev_private;
+
+	if (info == NULL)
+		return;
+
+	info->max_nb_queue_pairs = dev->max_qps;
+	info->feature_flags = dev->features;
+	info->capabilities = iocpt_get_caps(info->feature_flags);
+	info->sym.max_nb_sessions = dev->max_sessions;
+	info->driver_id = dev->driver_id;
+	info->min_mbuf_headroom_req = 0;
+	info->min_mbuf_tailroom_req = 0;
+}
+
+static struct rte_cryptodev_ops iocpt_ops = {
+	.dev_configure = iocpt_op_config,
+	.dev_close = iocpt_op_close,
+	.dev_infos_get = iocpt_op_info_get,
+};
+
+int
+iocpt_assign_ops(struct rte_cryptodev *cdev)
+{
+	struct iocpt_dev *dev = cdev->data->dev_private;
+
+	cdev->dev_ops = &iocpt_ops;
+	cdev->feature_flags = dev->features;
+
+	return 0;
+}
diff --git a/drivers/crypto/ionic/meson.build b/drivers/crypto/ionic/meson.build
index a6e0a1d415..b63428fa9b 100644
--- a/drivers/crypto/ionic/meson.build
+++ b/drivers/crypto/ionic/meson.build
@@ -5,8 +5,10 @@  deps += ['bus_vdev']
 deps += ['common_ionic']
 
 sources = files(
+        'ionic_crypto_caps.c',
         'ionic_crypto_cmds.c',
         'ionic_crypto_main.c',
+        'ionic_crypto_ops.c',
         'ionic_crypto_vdev.c',
 )
 name = 'ionic_crypto'