Implemented driver functions to configure and close ML devices.
Added skeleton code and support to reconfigure ML device. PCI
device remove is enabled in device close.

Signed-off-by: Srikanth Yalavarthi <syalavar...@marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_dev.c |  2 ++
 drivers/ml/cnxk/cn10k_ml_dev.h | 21 ++++++++++++
 drivers/ml/cnxk/cn10k_ml_ops.c | 60 ++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)

diff --git a/drivers/ml/cnxk/cn10k_ml_dev.c b/drivers/ml/cnxk/cn10k_ml_dev.c
index c2e93c9a1a..fd45226add 100644
--- a/drivers/ml/cnxk/cn10k_ml_dev.c
+++ b/drivers/ml/cnxk/cn10k_ml_dev.c
@@ -65,6 +65,8 @@ cn10k_ml_pci_probe(struct rte_pci_driver *pci_drv, struct 
rte_pci_device *pci_de
        dev->dequeue_burst = NULL;
        dev->op_error_get = NULL;
 
+       mldev->state = ML_CN10K_DEV_STATE_PROBED;
+
        return 0;
 
 pmd_destroy:
diff --git a/drivers/ml/cnxk/cn10k_ml_dev.h b/drivers/ml/cnxk/cn10k_ml_dev.h
index 13d26373e4..e7fb5fc2e2 100644
--- a/drivers/ml/cnxk/cn10k_ml_dev.h
+++ b/drivers/ml/cnxk/cn10k_ml_dev.h
@@ -25,10 +25,31 @@
 /* Maximum number of segments for IO data */
 #define ML_CN10K_MAX_SEGMENTS 1
 
+/* ML command timeout in seconds */
+#define ML_CN10K_CMD_TIMEOUT 5
+
+/* Device configuration state enum */
+enum cn10k_ml_dev_state {
+       /* Probed and not configured */
+       ML_CN10K_DEV_STATE_PROBED = 0,
+
+       /* Configured */
+       ML_CN10K_DEV_STATE_CONFIGURED,
+
+       /* Started */
+       ML_CN10K_DEV_STATE_STARTED,
+
+       /* Closed */
+       ML_CN10K_DEV_STATE_CLOSED
+};
+
 /* Device private data */
 struct cn10k_ml_dev {
        /* Device ROC */
        struct roc_ml roc;
+
+       /* Configuration state */
+       enum cn10k_ml_dev_state state;
 };
 
 #endif /* _CN10K_ML_DEV_H_ */
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index bad5ad4713..3a78d8c816 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -25,7 +25,67 @@ cn10k_ml_dev_info_get(struct rte_ml_dev *dev, struct 
rte_ml_dev_info *dev_info)
        return 0;
 }
 
+static int
+cn10k_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config 
*conf)
+{
+       struct rte_ml_dev_info dev_info;
+       struct cn10k_ml_dev *mldev;
+
+       if (dev == NULL || conf == NULL)
+               return -EINVAL;
+
+       /* Get CN10K device handle */
+       mldev = dev->data->dev_private;
+
+       cn10k_ml_dev_info_get(dev, &dev_info);
+       if (conf->nb_models > dev_info.max_models) {
+               plt_err("Invalid device config, nb_models > %u\n", 
dev_info.max_models);
+               return -EINVAL;
+       }
+
+       if (conf->nb_queue_pairs > dev_info.max_queue_pairs) {
+               plt_err("Invalid device config, nb_queue_pairs > %u\n", 
dev_info.max_queue_pairs);
+               return -EINVAL;
+       }
+
+       if (mldev->state == ML_CN10K_DEV_STATE_PROBED) {
+               plt_ml_dbg("Configuring ML device, nb_queue_pairs = %u, 
nb_models = %u",
+                          conf->nb_queue_pairs, conf->nb_models);
+       } else if (mldev->state == ML_CN10K_DEV_STATE_CONFIGURED) {
+               plt_ml_dbg("Re-configuring ML device, nb_queue_pairs = %u, 
nb_models = %u",
+                          conf->nb_queue_pairs, conf->nb_models);
+       } else if (mldev->state == ML_CN10K_DEV_STATE_STARTED) {
+               plt_err("Device can't be reconfigured in started state\n");
+               return -ENOTSUP;
+       } else if (mldev->state == ML_CN10K_DEV_STATE_CLOSED) {
+               plt_err("Device can't be reconfigured after close\n");
+               return -ENOTSUP;
+       }
+
+       mldev->state = ML_CN10K_DEV_STATE_CONFIGURED;
+
+       return 0;
+}
+
+static int
+cn10k_ml_dev_close(struct rte_ml_dev *dev)
+{
+       struct cn10k_ml_dev *mldev;
+
+       if (dev == NULL)
+               return -EINVAL;
+
+       mldev = dev->data->dev_private;
+
+       mldev->state = ML_CN10K_DEV_STATE_CLOSED;
+
+       /* Remove PCI device */
+       return rte_dev_remove(dev->device);
+}
+
 struct rte_ml_dev_ops cn10k_ml_ops = {
        /* Device control ops */
        .dev_info_get = cn10k_ml_dev_info_get,
+       .dev_configure = cn10k_ml_dev_configure,
+       .dev_close = cn10k_ml_dev_close,
 };
-- 
2.17.1

Reply via email to