Added cnxk wrapper for device dump and selftest debug
functions.

Signed-off-by: Srikanth Yalavarthi <syalavar...@marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_model.c | 118 +++++++++++++++++++++
 drivers/ml/cnxk/cn10k_ml_model.h |   1 +
 drivers/ml/cnxk/cn10k_ml_ocm.c   |   8 +-
 drivers/ml/cnxk/cn10k_ml_ocm.h   |   2 +-
 drivers/ml/cnxk/cn10k_ml_ops.c   | 176 ++-----------------------------
 drivers/ml/cnxk/cn10k_ml_ops.h   |   4 +-
 drivers/ml/cnxk/cnxk_ml_model.c  |  33 ++++++
 drivers/ml/cnxk/cnxk_ml_model.h  |   2 +
 drivers/ml/cnxk/cnxk_ml_ops.c    |  39 ++++++-
 drivers/ml/cnxk/cnxk_ml_utils.c  |  15 +++
 drivers/ml/cnxk/cnxk_ml_utils.h  |  17 +++
 drivers/ml/cnxk/meson.build      |   1 +
 12 files changed, 235 insertions(+), 181 deletions(-)
 create mode 100644 drivers/ml/cnxk/cnxk_ml_utils.c
 create mode 100644 drivers/ml/cnxk/cnxk_ml_utils.h

diff --git a/drivers/ml/cnxk/cn10k_ml_model.c b/drivers/ml/cnxk/cn10k_ml_model.c
index 48d70027ca..af9d5a666f 100644
--- a/drivers/ml/cnxk/cn10k_ml_model.c
+++ b/drivers/ml/cnxk/cn10k_ml_model.c
@@ -11,6 +11,7 @@
 #include "cnxk_ml_dev.h"
 #include "cnxk_ml_model.h"
 #include "cnxk_ml_ops.h"
+#include "cnxk_ml_utils.h"
 
 static enum rte_ml_io_type
 cn10k_ml_io_type_map(uint8_t type)
@@ -598,3 +599,120 @@ cn10k_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, 
struct cnxk_ml_model *mo
                                 
rte_ml_io_type_size_get(io_info->output[i].qtype);
        }
 }
+
+void
+cn10k_ml_layer_print(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_layer 
*layer, FILE *fp)
+{
+       struct cn10k_ml_ocm *ocm;
+       char str[STR_LEN];
+       uint8_t i;
+       uint8_t j;
+
+       ocm = &cnxk_mldev->cn10k_mldev.ocm;
+
+       /* Print debug info */
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, " Layer Information (Layer ID: %u, Name: %s)\n",
+               cnxk_mldev->index_map[layer->index].layer_id, layer->name);
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "index", layer->index);
+       fprintf(fp, "%*s : %s\n", FIELD_LEN, "name", layer->name);
+       fprintf(fp, "%*s : %u.%u.%u.%u\n", FIELD_LEN, "version",
+               layer->glow.metadata.model.version[0], 
layer->glow.metadata.model.version[1],
+               layer->glow.metadata.model.version[2], 
layer->glow.metadata.model.version[3]);
+       fprintf(fp, "%*s : 0x%016lx\n", FIELD_LEN, "layer", 
PLT_U64_CAST(layer));
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "batch_size", layer->batch_size);
+
+       /* Print model state */
+       if (layer->state == ML_CNXK_LAYER_STATE_LOADED)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "loaded");
+       if (layer->state == ML_CNXK_LAYER_STATE_JOB_ACTIVE)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "job_active");
+       if (layer->state == ML_CNXK_LAYER_STATE_STARTED)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "started");
+
+       /* Print OCM status */
+       fprintf(fp, "%*s : %" PRIu64 " bytes\n", FIELD_LEN, "wb_size",
+               layer->glow.metadata.model.ocm_wb_range_end -
+                       layer->glow.metadata.model.ocm_wb_range_start + 1);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "wb_pages", 
layer->glow.ocm_map.wb_pages);
+       fprintf(fp, "%*s : %" PRIu64 " bytes\n", FIELD_LEN, "scratch_size",
+               ocm->size_per_tile - 
layer->glow.metadata.model.ocm_tmp_range_floor);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "scratch_pages", 
layer->glow.ocm_map.scratch_pages);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_tiles",
+               layer->glow.metadata.model.tile_end - 
layer->glow.metadata.model.tile_start + 1);
+
+       if (layer->state == ML_CNXK_LAYER_STATE_STARTED) {
+               fprintf(fp, "%*s : 0x%0*" PRIx64 "\n", FIELD_LEN, "tilemask",
+                       ML_CN10K_OCM_NUMTILES / 4, 
layer->glow.ocm_map.tilemask);
+               fprintf(fp, "%*s : 0x%" PRIx64 "\n", FIELD_LEN, "ocm_wb_start",
+                       layer->glow.ocm_map.wb_page_start * ocm->page_size);
+       }
+
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_inputs", 
layer->glow.metadata.model.num_input);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_outputs", 
layer->glow.metadata.model.num_output);
+       fprintf(fp, "\n");
+
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "%8s  %16s  %12s  %18s\n", "input", "input_name", 
"input_type",
+               "model_input_type");
+       cnxk_ml_print_line(fp, LINE_LEN);
+       for (i = 0; i < layer->glow.metadata.model.num_input; i++) {
+               if (i < MRVL_ML_NUM_INPUT_OUTPUT_1) {
+                       fprintf(fp, "%8u  ", i);
+                       fprintf(fp, "%*s  ", 16, 
layer->glow.metadata.input1[i].input_name);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.input1[i].input_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 12, str);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.input1[i].model_input_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 18, str);
+                       fprintf(fp, "\n");
+               } else {
+                       j = i - MRVL_ML_NUM_INPUT_OUTPUT_1;
+
+                       fprintf(fp, "%8u  ", i);
+                       fprintf(fp, "%*s  ", 16, 
layer->glow.metadata.input2[j].input_name);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.input2[j].input_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 12, str);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.input2[j].model_input_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 18, str);
+                       fprintf(fp, "\n");
+               }
+       }
+       fprintf(fp, "\n");
+
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "%8s  %16s  %12s  %18s\n", "output", "output_name", 
"output_type",
+               "model_output_type");
+       cnxk_ml_print_line(fp, LINE_LEN);
+       for (i = 0; i < layer->glow.metadata.model.num_output; i++) {
+               if (i < MRVL_ML_NUM_INPUT_OUTPUT_1) {
+                       fprintf(fp, "%8u  ", i);
+                       fprintf(fp, "%*s  ", 16, 
layer->glow.metadata.output1[i].output_name);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.output1[i].output_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 12, str);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.output1[i].model_output_type,
+                                             str, STR_LEN);
+                       fprintf(fp, "%*s  ", 18, str);
+                       fprintf(fp, "\n");
+               } else {
+                       j = i - MRVL_ML_NUM_INPUT_OUTPUT_1;
+                       fprintf(fp, "%8u  ", i);
+                       fprintf(fp, "%*s  ", 16, 
layer->glow.metadata.output2[j].output_name);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.output2[j].output_type, str,
+                                             STR_LEN);
+                       fprintf(fp, "%*s  ", 12, str);
+                       
rte_ml_io_type_to_str(layer->glow.metadata.output2[j].model_output_type,
+                                             str, STR_LEN);
+                       fprintf(fp, "%*s  ", 18, str);
+                       fprintf(fp, "\n");
+               }
+       }
+       fprintf(fp, "\n");
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "\n");
+}
diff --git a/drivers/ml/cnxk/cn10k_ml_model.h b/drivers/ml/cnxk/cn10k_ml_model.h
index b891c9d627..45f2ed5fcf 100644
--- a/drivers/ml/cnxk/cn10k_ml_model.h
+++ b/drivers/ml/cnxk/cn10k_ml_model.h
@@ -460,5 +460,6 @@ int cn10k_ml_model_ocm_pages_count(struct cnxk_ml_dev 
*cnxk_mldev, struct cnxk_m
 void cn10k_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, struct 
cnxk_ml_model *model,
                             struct cnxk_ml_io_info *io_info,
                             struct cn10k_ml_model_metadata *metadata);
+void cn10k_ml_layer_print(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_layer 
*layer, FILE *fp);
 
 #endif /* _CN10K_ML_MODEL_H_ */
diff --git a/drivers/ml/cnxk/cn10k_ml_ocm.c b/drivers/ml/cnxk/cn10k_ml_ocm.c
index 2197e5e0ed..dc315cce10 100644
--- a/drivers/ml/cnxk/cn10k_ml_ocm.c
+++ b/drivers/ml/cnxk/cn10k_ml_ocm.c
@@ -481,19 +481,15 @@ cn10k_ml_ocm_pagemask_to_str(struct 
cn10k_ml_ocm_tile_info *tile_info, uint16_t
 }
 
 void
-cn10k_ml_ocm_print(struct rte_ml_dev *dev, FILE *fp)
+cn10k_ml_ocm_print(struct cnxk_ml_dev *cnxk_mldev, FILE *fp)
 {
-       struct cn10k_ml_dev *cn10k_mldev;
-       struct cnxk_ml_dev *cnxk_mldev;
        struct cn10k_ml_ocm *ocm;
        uint8_t tile_id;
        uint8_t word_id;
        int wb_pages;
        char *str;
 
-       cnxk_mldev = dev->data->dev_private;
-       cn10k_mldev = &cnxk_mldev->cn10k_mldev;
-       ocm = &cn10k_mldev->ocm;
+       ocm = &cnxk_mldev->cn10k_mldev.ocm;
 
        /* Nibbles + prefix '0x' */
        str = rte_zmalloc("ocm_mask_str", ocm->num_pages / 4 + 2, 
RTE_CACHE_LINE_SIZE);
diff --git a/drivers/ml/cnxk/cn10k_ml_ocm.h b/drivers/ml/cnxk/cn10k_ml_ocm.h
index 97b723a56a..bf8944f8ee 100644
--- a/drivers/ml/cnxk/cn10k_ml_ocm.h
+++ b/drivers/ml/cnxk/cn10k_ml_ocm.h
@@ -83,6 +83,6 @@ void cn10k_ml_ocm_reserve_pages(struct cnxk_ml_dev 
*cnxk_mldev, uint16_t model_i
                                uint16_t layer_id, uint64_t tilemask, int 
wb_page_start,
                                uint16_t wb_pages, uint16_t scratch_pages);
 void cn10k_ml_ocm_free_pages(struct cnxk_ml_dev *cnxk_mldev, uint16_t 
model_id, uint16_t layer_id);
-void cn10k_ml_ocm_print(struct rte_ml_dev *dev, FILE *fp);
+void cn10k_ml_ocm_print(struct cnxk_ml_dev *cnxk_mldev, FILE *fp);
 
 #endif /* _CN10K_ML_OCM_H_ */
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index c68e6c620c..a56d002d4c 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -18,11 +18,6 @@
 /* ML layer macros */
 #define CN10K_ML_LAYER_MEMZONE_NAME "ml_cn10k_layer_mz"
 
-/* Debug print width */
-#define STR_LEN          12
-#define FIELD_LEN 16
-#define LINE_LEN  90
-
 /* ML Job descriptor flags */
 #define ML_FLAGS_POLL_COMPL BIT(0)
 #define ML_FLAGS_SSO_COMPL  BIT(1)
@@ -70,16 +65,6 @@ static const struct cn10k_ml_stype_db_driver {
        {ML_DRIVER_ERR_FW_ERROR, "UNKNOWN FIRMWARE ERROR"},
 };
 
-static void
-print_line(FILE *fp, int len)
-{
-       int i;
-
-       for (i = 0; i < len; i++)
-               fprintf(fp, "-");
-       fprintf(fp, "\n");
-}
-
 static inline void
 cn10k_ml_set_poll_addr(struct cnxk_ml_req *req)
 {
@@ -113,140 +98,6 @@ cn10k_ml_qp_initialize(struct cnxk_ml_dev *cnxk_mldev, 
struct cnxk_ml_qp *qp)
        }
 }
 
-static void
-cn10k_ml_model_print(struct rte_ml_dev *dev, uint16_t model_id, FILE *fp)
-{
-       struct cn10k_ml_dev *cn10k_mldev;
-       struct cnxk_ml_dev *cnxk_mldev;
-       struct cnxk_ml_model *model;
-       struct cn10k_ml_ocm *ocm;
-       char str[STR_LEN];
-       uint8_t i;
-       uint8_t j;
-
-       cnxk_mldev = dev->data->dev_private;
-       cn10k_mldev = &cnxk_mldev->cn10k_mldev;
-       ocm = &cn10k_mldev->ocm;
-       model = dev->data->models[model_id];
-
-       /* Print debug info */
-       print_line(fp, LINE_LEN);
-       fprintf(fp, " Model Information (%s)\n", 
model->glow.metadata.model.name);
-       print_line(fp, LINE_LEN);
-       fprintf(fp, "%*s : %s\n", FIELD_LEN, "name", 
model->glow.metadata.model.name);
-       fprintf(fp, "%*s : %u.%u.%u.%u\n", FIELD_LEN, "version",
-               model->glow.metadata.model.version[0], 
model->glow.metadata.model.version[1],
-               model->glow.metadata.model.version[2], 
model->glow.metadata.model.version[3]);
-       if (strlen(model->name) != 0)
-               fprintf(fp, "%*s : %s\n", FIELD_LEN, "debug_name", model->name);
-       fprintf(fp, "%*s : 0x%016lx\n", FIELD_LEN, "model", 
PLT_U64_CAST(model));
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "model_id", model->model_id);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "batch_size", 
model->glow.metadata.model.batch_size);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_layers", 
model->glow.metadata.model.num_layers);
-
-       /* Print model state */
-       if (model->state == ML_CNXK_MODEL_STATE_LOADED)
-               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "loaded");
-       if (model->state == ML_CNXK_MODEL_STATE_JOB_ACTIVE)
-               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "job_active");
-       if (model->state == ML_CNXK_MODEL_STATE_STARTED)
-               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "started");
-
-       /* Print OCM status */
-       fprintf(fp, "%*s : %" PRIu64 " bytes\n", FIELD_LEN, "wb_size",
-               model->glow.metadata.model.ocm_wb_range_end -
-                       model->glow.metadata.model.ocm_wb_range_start + 1);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "wb_pages", 
model->layer[0].glow.ocm_map.wb_pages);
-       fprintf(fp, "%*s : %" PRIu64 " bytes\n", FIELD_LEN, "scratch_size",
-               ocm->size_per_tile - 
model->glow.metadata.model.ocm_tmp_range_floor);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "scratch_pages",
-               model->layer[0].glow.ocm_map.scratch_pages);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_tiles",
-               model->glow.metadata.model.tile_end - 
model->glow.metadata.model.tile_start + 1);
-
-       if (model->state == ML_CNXK_MODEL_STATE_STARTED) {
-               fprintf(fp, "%*s : 0x%0*" PRIx64 "\n", FIELD_LEN, "tilemask",
-                       ML_CN10K_OCM_NUMTILES / 4, 
model->layer[0].glow.ocm_map.tilemask);
-               fprintf(fp, "%*s : 0x%" PRIx64 "\n", FIELD_LEN, "ocm_wb_start",
-                       model->layer[0].glow.ocm_map.wb_page_start * 
cn10k_mldev->ocm.page_size);
-       }
-
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_inputs", 
model->glow.metadata.model.num_input);
-       fprintf(fp, "%*s : %u\n", FIELD_LEN, "num_outputs", 
model->glow.metadata.model.num_output);
-       fprintf(fp, "\n");
-
-       print_line(fp, LINE_LEN);
-       fprintf(fp, "%8s  %16s  %12s  %18s  %12s\n", "input", "input_name", 
"input_type",
-               "model_input_type", "quantize");
-       print_line(fp, LINE_LEN);
-       for (i = 0; i < model->glow.metadata.model.num_input; i++) {
-               if (i < MRVL_ML_NUM_INPUT_OUTPUT_1) {
-                       fprintf(fp, "%8u  ", i);
-                       fprintf(fp, "%*s  ", 16, 
model->glow.metadata.input1[i].input_name);
-                       
rte_ml_io_type_to_str(model->glow.metadata.input1[i].input_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 12, str);
-                       
rte_ml_io_type_to_str(model->glow.metadata.input1[i].model_input_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 18, str);
-                       fprintf(fp, "%*s", 12,
-                               (model->glow.metadata.input1[i].quantize == 1 ? 
"Yes" : "No"));
-                       fprintf(fp, "\n");
-               } else {
-                       j = i - MRVL_ML_NUM_INPUT_OUTPUT_1;
-
-                       fprintf(fp, "%8u  ", i);
-                       fprintf(fp, "%*s  ", 16, 
model->glow.metadata.input2[j].input_name);
-                       
rte_ml_io_type_to_str(model->glow.metadata.input2[j].input_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 12, str);
-                       
rte_ml_io_type_to_str(model->glow.metadata.input2[j].model_input_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 18, str);
-                       fprintf(fp, "%*s", 12,
-                               (model->glow.metadata.input2[j].quantize == 1 ? 
"Yes" : "No"));
-                       fprintf(fp, "\n");
-               }
-       }
-       fprintf(fp, "\n");
-
-       print_line(fp, LINE_LEN);
-       fprintf(fp, "%8s  %16s  %12s  %18s  %12s\n", "output", "output_name", 
"output_type",
-               "model_output_type", "dequantize");
-       print_line(fp, LINE_LEN);
-       for (i = 0; i < model->glow.metadata.model.num_output; i++) {
-               if (i < MRVL_ML_NUM_INPUT_OUTPUT_1) {
-                       fprintf(fp, "%8u  ", i);
-                       fprintf(fp, "%*s  ", 16, 
model->glow.metadata.output1[i].output_name);
-                       
rte_ml_io_type_to_str(model->glow.metadata.output1[i].output_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 12, str);
-                       
rte_ml_io_type_to_str(model->glow.metadata.output1[i].model_output_type,
-                                             str, STR_LEN);
-                       fprintf(fp, "%*s  ", 18, str);
-                       fprintf(fp, "%*s", 12,
-                               (model->glow.metadata.output1[i].dequantize == 
1 ? "Yes" : "No"));
-                       fprintf(fp, "\n");
-               } else {
-                       j = i - MRVL_ML_NUM_INPUT_OUTPUT_1;
-                       fprintf(fp, "%8u  ", i);
-                       fprintf(fp, "%*s  ", 16, 
model->glow.metadata.output2[j].output_name);
-                       
rte_ml_io_type_to_str(model->glow.metadata.output2[j].output_type, str,
-                                             STR_LEN);
-                       fprintf(fp, "%*s  ", 12, str);
-                       
rte_ml_io_type_to_str(model->glow.metadata.output2[j].model_output_type,
-                                             str, STR_LEN);
-                       fprintf(fp, "%*s  ", 18, str);
-                       fprintf(fp, "%*s", 12,
-                               (model->glow.metadata.output2[j].dequantize == 
1 ? "Yes" : "No"));
-                       fprintf(fp, "\n");
-               }
-       }
-       fprintf(fp, "\n");
-       print_line(fp, LINE_LEN);
-       fprintf(fp, "\n");
-}
-
 static void
 cn10k_ml_prep_sp_job_descriptor(struct cnxk_ml_dev *cnxk_mldev, struct 
cnxk_ml_layer *layer,
                                struct cnxk_ml_req *req, enum cn10k_ml_job_type 
job_type)
@@ -1120,38 +971,25 @@ cn10k_ml_dev_xstats_reset(struct rte_ml_dev *dev, enum 
rte_ml_dev_xstats_mode mo
 }
 
 int
-cn10k_ml_dev_dump(struct rte_ml_dev *dev, FILE *fp)
+cn10k_ml_dev_dump(struct cnxk_ml_dev *cnxk_mldev, FILE *fp)
 {
        struct cn10k_ml_dev *cn10k_mldev;
-       struct cnxk_ml_dev *cnxk_mldev;
-       struct cnxk_ml_model *model;
        struct cn10k_ml_fw *fw;
 
        uint32_t head_loc;
        uint32_t tail_loc;
-       uint16_t model_id;
        uint32_t bufsize;
        char *head_ptr;
        int core_id;
 
-       if (roc_env_is_asim())
-               return 0;
-
-       cnxk_mldev = dev->data->dev_private;
        cn10k_mldev = &cnxk_mldev->cn10k_mldev;
        fw = &cn10k_mldev->fw;
 
-       /* Dump model info */
-       for (model_id = 0; model_id < dev->data->nb_models; model_id++) {
-               model = dev->data->models[model_id];
-               if (model != NULL) {
-                       cn10k_ml_model_print(dev, model_id, fp);
-                       fprintf(fp, "\n");
-               }
-       }
-
        /* Dump OCM state */
-       cn10k_ml_ocm_print(dev, fp);
+       cn10k_ml_ocm_print(cnxk_mldev, fp);
+
+       if (roc_env_is_asim())
+               return 0;
 
        /* Dump debug buffer */
        for (core_id = 0; core_id <= 1; core_id++) {
@@ -1207,17 +1045,15 @@ cn10k_ml_dev_dump(struct rte_ml_dev *dev, FILE *fp)
 }
 
 int
-cn10k_ml_dev_selftest(struct rte_ml_dev *dev)
+cn10k_ml_dev_selftest(struct cnxk_ml_dev *cnxk_mldev)
 {
        struct cn10k_ml_dev *cn10k_mldev;
-       struct cnxk_ml_dev *cnxk_mldev;
        const struct plt_memzone *mz;
        struct cnxk_ml_req *req;
        uint64_t timeout_cycle;
        bool timeout;
        int ret;
 
-       cnxk_mldev = dev->data->dev_private;
        cn10k_mldev = &cnxk_mldev->cn10k_mldev;
        mz = plt_memzone_reserve_aligned("dev_selftest", sizeof(struct 
cnxk_ml_req), 0,
                                         ML_CN10K_ALIGN_SIZE);
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.h b/drivers/ml/cnxk/cn10k_ml_ops.h
index 780e2a9f9c..5fda98ae88 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.h
+++ b/drivers/ml/cnxk/cn10k_ml_ops.h
@@ -295,8 +295,8 @@ int cn10k_ml_dev_configure(struct cnxk_ml_dev *cnxk_mldev, 
const struct rte_ml_d
 int cn10k_ml_dev_close(struct cnxk_ml_dev *cnxk_mldev);
 int cn10k_ml_dev_start(struct cnxk_ml_dev *cnxk_mldev);
 int cn10k_ml_dev_stop(struct cnxk_ml_dev *cnxk_mldev);
-int cn10k_ml_dev_dump(struct rte_ml_dev *dev, FILE *fp);
-int cn10k_ml_dev_selftest(struct rte_ml_dev *dev);
+int cn10k_ml_dev_dump(struct cnxk_ml_dev *cnxk_mldev, FILE *fp);
+int cn10k_ml_dev_selftest(struct cnxk_ml_dev *cnxk_mldev);
 
 int cn10k_ml_dev_stats_get(struct rte_ml_dev *dev, struct rte_ml_dev_stats 
*stats);
 void cn10k_ml_dev_stats_reset(struct rte_ml_dev *dev);
diff --git a/drivers/ml/cnxk/cnxk_ml_model.c b/drivers/ml/cnxk/cnxk_ml_model.c
index 3d735ced3e..b069d4e3a5 100644
--- a/drivers/ml/cnxk/cnxk_ml_model.c
+++ b/drivers/ml/cnxk/cnxk_ml_model.c
@@ -5,3 +5,36 @@
 #include <rte_mldev.h>
 
 #include "cnxk_ml_model.h"
+#include "cnxk_ml_utils.h"
+
+void
+cnxk_ml_model_dump(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model 
*model, FILE *fp)
+{
+       struct cnxk_ml_layer *layer;
+       uint16_t layer_id;
+
+       /* Print debug info */
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, " Model Information (Model ID: %u, Name: %s)\n", 
model->model_id, model->name);
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "model_id", model->model_id);
+       fprintf(fp, "%*s : %s\n", FIELD_LEN, "name", model->name);
+       fprintf(fp, "%*s : 0x%016lx\n", FIELD_LEN, "model", 
PLT_U64_CAST(model));
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "batch_size", model->batch_size);
+       fprintf(fp, "%*s : %u\n", FIELD_LEN, "nb_layers", model->nb_layers);
+
+       /* Print model state */
+       if (model->state == ML_CNXK_MODEL_STATE_LOADED)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "loaded");
+       if (model->state == ML_CNXK_MODEL_STATE_JOB_ACTIVE)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "job_active");
+       if (model->state == ML_CNXK_MODEL_STATE_STARTED)
+               fprintf(fp, "%*s : %s\n", FIELD_LEN, "state", "started");
+       cnxk_ml_print_line(fp, LINE_LEN);
+       fprintf(fp, "\n");
+
+       for (layer_id = 0; layer_id < model->nb_layers; layer_id++) {
+               layer = &model->layer[layer_id];
+               cn10k_ml_layer_print(cnxk_mldev, layer, fp);
+       }
+}
diff --git a/drivers/ml/cnxk/cnxk_ml_model.h b/drivers/ml/cnxk/cnxk_ml_model.h
index a2994dbb71..66d979dd3c 100644
--- a/drivers/ml/cnxk/cnxk_ml_model.h
+++ b/drivers/ml/cnxk/cnxk_ml_model.h
@@ -108,4 +108,6 @@ struct cnxk_ml_model {
        plt_spinlock_t lock;
 };
 
+void cnxk_ml_model_dump(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model 
*model, FILE *fp);
+
 #endif /* _CNXK_ML_MODEL_H_ */
diff --git a/drivers/ml/cnxk/cnxk_ml_ops.c b/drivers/ml/cnxk/cnxk_ml_ops.c
index 63842025fc..66b88ddae1 100644
--- a/drivers/ml/cnxk/cnxk_ml_ops.c
+++ b/drivers/ml/cnxk/cnxk_ml_ops.c
@@ -409,6 +409,41 @@ cnxk_ml_dev_stop(struct rte_ml_dev *dev)
        return 0;
 }
 
+static int
+cnxk_ml_dev_dump(struct rte_ml_dev *dev, FILE *fp)
+{
+       struct cnxk_ml_dev *cnxk_mldev;
+       struct cnxk_ml_model *model;
+       uint16_t model_id;
+
+       if ((dev == NULL) || (fp == NULL))
+               return -EINVAL;
+
+       cnxk_mldev = dev->data->dev_private;
+
+       /* Dump model info */
+       for (model_id = 0; model_id < cnxk_mldev->mldev->data->nb_models; 
model_id++) {
+               model = cnxk_mldev->mldev->data->models[model_id];
+               if (model != NULL)
+                       cnxk_ml_model_dump(cnxk_mldev, model, fp);
+       }
+
+       return cn10k_ml_dev_dump(cnxk_mldev, fp);
+}
+
+static int
+cnxk_ml_dev_selftest(struct rte_ml_dev *dev)
+{
+       struct cnxk_ml_dev *cnxk_mldev;
+
+       if (dev == NULL)
+               return -EINVAL;
+
+       cnxk_mldev = dev->data->dev_private;
+
+       return cn10k_ml_dev_selftest(cnxk_mldev);
+}
+
 static int
 cnxk_ml_dev_queue_pair_setup(struct rte_ml_dev *dev, uint16_t queue_pair_id,
                             const struct rte_ml_dev_qp_conf *qp_conf, int 
socket_id)
@@ -729,8 +764,8 @@ struct rte_ml_dev_ops cnxk_ml_ops = {
        .dev_close = cnxk_ml_dev_close,
        .dev_start = cnxk_ml_dev_start,
        .dev_stop = cnxk_ml_dev_stop,
-       .dev_dump = cn10k_ml_dev_dump,
-       .dev_selftest = cn10k_ml_dev_selftest,
+       .dev_dump = cnxk_ml_dev_dump,
+       .dev_selftest = cnxk_ml_dev_selftest,
 
        /* Queue-pair handling ops */
        .dev_queue_pair_setup = cnxk_ml_dev_queue_pair_setup,
diff --git a/drivers/ml/cnxk/cnxk_ml_utils.c b/drivers/ml/cnxk/cnxk_ml_utils.c
new file mode 100644
index 0000000000..ca3670a9e8
--- /dev/null
+++ b/drivers/ml/cnxk/cnxk_ml_utils.c
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Marvell.
+ */
+
+#include "cnxk_ml_utils.h"
+
+void
+cnxk_ml_print_line(FILE *fp, int len)
+{
+       int i;
+
+       for (i = 0; i < len; i++)
+               fprintf(fp, "-");
+       fprintf(fp, "\n");
+}
diff --git a/drivers/ml/cnxk/cnxk_ml_utils.h b/drivers/ml/cnxk/cnxk_ml_utils.h
new file mode 100644
index 0000000000..ed2ab21346
--- /dev/null
+++ b/drivers/ml/cnxk/cnxk_ml_utils.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Marvell.
+ */
+
+#ifndef _CNXK_ML_UTILS_H_
+#define _CNXK_ML_UTILS_H_
+
+#include <rte_mldev.h>
+
+/* Debug print width */
+#define STR_LEN          12
+#define FIELD_LEN 16
+#define LINE_LEN  72
+
+void cnxk_ml_print_line(FILE *fp, int len);
+
+#endif /* _CNXK_ML_UTILS_H_ */
diff --git a/drivers/ml/cnxk/meson.build b/drivers/ml/cnxk/meson.build
index 79154c8698..5d27a87d91 100644
--- a/drivers/ml/cnxk/meson.build
+++ b/drivers/ml/cnxk/meson.build
@@ -16,6 +16,7 @@ sources = files(
         'cnxk_ml_io.c',
         'cnxk_ml_model.c',
         'cnxk_ml_ops.c',
+        'cnxk_ml_utils.c',
 )
 
 deps += ['mldev', 'common_cnxk', 'kvargs', 'hash']
-- 
2.42.0

Reply via email to