From: Srikanth Yalavarthi <syalavar...@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 <syalavar...@marvell.com>
Signed-off-by: Jerin Jacob <jer...@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(+)

diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c
index 961e12d150..928ea90ab5 100644
--- a/lib/mldev/rte_mldev.c
+++ b/lib/mldev/rte_mldev.c
@@ -352,4 +352,37 @@ 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)) {
+               RTE_MLDEV_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) {
+               RTE_MLDEV_LOG(ERR, "Invalid queue_pair_id = %d", queue_pair_id);
+               return -EINVAL;
+       }
+
+       if (qp_conf == NULL) {
+               RTE_MLDEV_LOG(ERR, "Dev %d, qp_conf cannot be NULL\n", dev_id);
+               return -EINVAL;
+       }
+
+       if (dev->data->dev_started) {
+               RTE_MLDEV_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);
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_ml_dev_logtype, INFO);
diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h
index dc79c5f630..f8d247b43e 100644
--- a/lib/mldev/rte_mldev_core.h
+++ b/lib/mldev/rte_mldev_core.h
@@ -113,6 +113,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
  *
@@ -133,6 +171,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 028b6a464d..fcf48f1760 100644
--- a/lib/mldev/version.map
+++ b/lib/mldev/version.map
@@ -8,6 +8,7 @@ EXPERIMENTAL {
        rte_ml_dev_init;
        rte_ml_dev_is_valid_dev;
        rte_ml_dev_logtype;
+       rte_ml_dev_queue_pair_setup;
        rte_ml_dev_socket_id;
        rte_ml_dev_start;
        rte_ml_dev_stop;
-- 
2.39.1

Reply via email to