[v1,04/12] mldev: support device queue-pair setup

Message ID 20221114120238.2143832-5-jerinj@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series mldev: introduce machine learning device library |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob Kollanukkaran Nov. 14, 2022, 12:02 p.m. UTC
  From: Srikanth Yalavarthi <syalavarthi@marvell.com>

Added APIs to create a queue-pair attached to ML device.
Queue pairs are created with a user specified ID. Added
function prototypes to be used by ML drivers for queue
pair create and destroy.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 lib/mldev/rte_mldev.c      | 33 ++++++++++++++++++++++++++++
 lib/mldev/rte_mldev_core.h | 44 ++++++++++++++++++++++++++++++++++++++
 lib/mldev/version.map      |  1 +
 3 files changed, 78 insertions(+)
  

Patch

diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c
index 651f8b2f7c..c8672cff8e 100644
--- a/lib/mldev/rte_mldev.c
+++ b/lib/mldev/rte_mldev.c
@@ -306,3 +306,36 @@  rte_ml_dev_stop(int16_t dev_id)
 
 	return ret;
 }
+
+int
+rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id,
+			    const struct rte_ml_dev_qp_conf *qp_conf, int socket_id)
+{
+	struct rte_ml_dev *dev;
+
+	if (!rte_ml_dev_is_valid_dev(dev_id)) {
+		ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+		return -EINVAL;
+	}
+
+	dev = rte_ml_dev_pmd_get_dev(dev_id);
+	if (*dev->dev_ops->dev_queue_pair_setup == NULL)
+		return -ENOTSUP;
+
+	if (queue_pair_id >= dev->data->nb_queue_pairs) {
+		ML_DEV_LOG(ERR, "Invalid queue_pair_id = %d", queue_pair_id);
+		return -EINVAL;
+	}
+
+	if (qp_conf == NULL) {
+		ML_DEV_LOG(ERR, "Dev %d, qp_conf cannot be NULL\n", dev_id);
+		return -EINVAL;
+	}
+
+	if (dev->data->dev_started) {
+		ML_DEV_LOG(ERR, "Device %d must be stopped to allow configuration", dev_id);
+		return -EBUSY;
+	}
+
+	return (*dev->dev_ops->dev_queue_pair_setup)(dev, queue_pair_id, qp_conf, socket_id);
+}
diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h
index 1405cce7f7..e2a16034d6 100644
--- a/lib/mldev/rte_mldev_core.h
+++ b/lib/mldev/rte_mldev_core.h
@@ -117,6 +117,44 @@  typedef int (*mldev_start_t)(struct rte_ml_dev *dev);
  */
 typedef int (*mldev_stop_t)(struct rte_ml_dev *dev);
 
+/**
+ * @internal
+ *
+ * Setup a queue pair for a device.
+ *
+ * @param dev
+ *	ML device pointer.
+ * @param queue_pair_id
+ *	Queue pair index.
+ * @param queue_pair_conf
+ *	Queue pair configuration structure.
+ * @param socket_id
+ *	Socket index.
+ *
+ * @return
+ *	- 0 on success.
+ *	- < 0, error on failure.
+ */
+typedef int (*mldev_queue_pair_setup_t)(struct rte_ml_dev *dev, uint16_t queue_pair_id,
+					const struct rte_ml_dev_qp_conf *queue_pair_conf,
+					int socket_id);
+
+/**
+ * @internal
+ *
+ * Release memory resources allocated by given queue pair.
+ *
+ * @param dev
+ *	ML device pointer.
+ * @param queue_pair_id
+ *	Queue pair index.
+ *
+ * @return
+ *	- 0 on success.
+ *	- -EAGAIN, if can't close as device is busy.
+ */
+typedef int (*mldev_queue_pair_release_t)(struct rte_ml_dev *dev, uint16_t queue_pair_id);
+
 /**
  * @internal
  *
@@ -137,6 +175,12 @@  struct rte_ml_dev_ops {
 
 	/** Stop device. */
 	mldev_stop_t dev_stop;
+
+	/** Set up a device queue pair. */
+	mldev_queue_pair_setup_t dev_queue_pair_setup;
+
+	/** Release a device queue pair. */
+	mldev_queue_pair_release_t dev_queue_pair_release;
 };
 
 /**
diff --git a/lib/mldev/version.map b/lib/mldev/version.map
index 1be508ab5f..cd44c05f3a 100644
--- a/lib/mldev/version.map
+++ b/lib/mldev/version.map
@@ -6,6 +6,7 @@  EXPERIMENTAL {
 	rte_ml_dev_count;
 	rte_ml_dev_info_get;
 	rte_ml_dev_is_valid_dev;
+	rte_ml_dev_queue_pair_setup;
 	rte_ml_dev_socket_id;
 	rte_ml_dev_start;
 	rte_ml_dev_stop;