From c79d78f63ba993a7fb45b7c842cfcfefb38ba5b6 Mon Sep 17 00:00:00 2001
From: "Min Hu (Connor)" <humin29@huawei.com>
Date: Fri, 11 Feb 2022 10:42:46 +0800
Subject: [PATCH 03/13] net/hns3: dump device basic info

This patch dumps device basic info such as device name, adapter state
for debug.

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c      |  1 +
 drivers/net/hns3/hns3_ethdev.h      |  1 +
 drivers/net/hns3/hns3_ethdev_dump.c | 99 +++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_ethdev_vf.c   |  1 +
 drivers/net/hns3/meson.build        |  1 +
 5 files changed, 103 insertions(+)
 create mode 100644 drivers/net/hns3/hns3_ethdev_dump.c

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 13ebcde002..a9394eeeff 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -6568,6 +6568,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = {
 	.timesync_adjust_time       = hns3_timesync_adjust_time,
 	.timesync_read_time         = hns3_timesync_read_time,
 	.timesync_write_time        = hns3_timesync_write_time,
+	.eth_dev_priv_dump          = hns3_eth_dev_priv_dump,
 };
 
 static const struct hns3_reset_ops hns3_reset_ops = {
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index d62884cd9b..412626c053 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -1055,6 +1055,7 @@ int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts);
 int hns3_timesync_write_time(struct rte_eth_dev *dev,
 			const struct timespec *ts);
 int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
+int hns3_eth_dev_priv_dump(struct rte_eth_dev *dev, FILE *file);
 
 static inline bool
 is_reset_pending(struct hns3_adapter *hns)
diff --git a/drivers/net/hns3/hns3_ethdev_dump.c b/drivers/net/hns3/hns3_ethdev_dump.c
new file mode 100644
index 0000000000..bd95184b02
--- /dev/null
+++ b/drivers/net/hns3/hns3_ethdev_dump.c
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 HiSilicon Limited
+ */
+
+#include <rte_kvargs.h>
+#include <rte_bus_pci.h>
+#include <ethdev_pci.h>
+#include <rte_pci.h>
+
+#include "hns3_common.h"
+#include "hns3_logs.h"
+#include "hns3_regs.h"
+#include "hns3_rxtx.h"
+
+static const char *
+hns3_get_adapter_state_name(uint32_t state)
+{
+	static const char * const state_name[] = {
+		"UNINITIALIZED",
+		"INITIALIZED",
+		"CONFIGURING",
+		"CONFIGURED",
+		"STARTING",
+		"STARTED",
+		"STOPPING",
+		"CLOSING",
+		"CLOSED",
+		"REMOVED",
+		"NSTATES"
+	};
+
+	if (state < RTE_DIM(state_name))
+		return state_name[state];
+	else
+		return "unknown";
+}
+
+static const char *
+hns3_get_io_func_hint_name(uint32_t hint)
+{
+	switch (hint) {
+	case HNS3_IO_FUNC_HINT_NONE:
+		return "none";
+	case HNS3_IO_FUNC_HINT_VEC:
+		return "vec";
+	case HNS3_IO_FUNC_HINT_SVE:
+		return "sve";
+	case HNS3_IO_FUNC_HINT_SIMPLE:
+		return "simple";
+	case HNS3_IO_FUNC_HINT_COMMON:
+		return "common";
+	default:
+		return "unknown";
+	}
+}
+
+static void
+hns3_get_device_basic_info(FILE *file, struct rte_eth_dev *dev)
+{
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = &hns->hw;
+
+	fprintf(file,
+		"  - Device Base Info:\n"
+		"\t  -- name: %s\n"
+		"\t  -- adapter_state=%s\n"
+		"\t  -- nb_rx_queues=%u nb_tx_queues=%u\n"
+		"\t  -- total_tqps_num=%u tqps_num=%u intr_tqps_num=%u\n"
+		"\t  -- rss_size_max=%u alloc_rss_size=%u tx_qnum_per_tc=%u\n"
+		"\t  -- min_tx_pkt_len=%u intr_mapping_mode=%u vlan_mode=%u\n"
+		"\t  -- tso_mode=%u max_non_tso_bd_num=%u\n"
+		"\t  -- max_tm_rate=%u Mbps\n"
+		"\t  -- set link down: %s\n"
+		"\t  -- rx_func_hint=%s tx_func_hint=%s\n"
+		"\t  -- dev_flags: lsc=%d\n"
+		"\t  -- intr_conf: lsc=%u rxq=%u\n",
+		dev->data->name,
+		hns3_get_adapter_state_name(hw->adapter_state),
+		dev->data->nb_rx_queues, dev->data->nb_tx_queues,
+		hw->total_tqps_num, hw->tqps_num, hw->intr_tqps_num,
+		hw->rss_size_max, hw->alloc_rss_size, hw->tx_qnum_per_tc,
+		hw->min_tx_pkt_len, hw->intr.mapping_mode, hw->vlan_mode,
+		hw->tso_mode, hw->max_non_tso_bd_num,
+		hw->max_tm_rate,
+		hw->set_link_down ? "Yes" : "No",
+		hns3_get_io_func_hint_name(hns->rx_func_hint),
+		hns3_get_io_func_hint_name(hns->tx_func_hint),
+		!!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC),
+		dev->data->dev_conf.intr_conf.lsc,
+		dev->data->dev_conf.intr_conf.rxq);
+}
+
+int
+hns3_eth_dev_priv_dump(struct rte_eth_dev *dev, FILE *file)
+{
+	hns3_get_device_basic_info(file, dev);
+
+	return 0;
+}
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 5f905c515c..aee0c36360 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -2290,6 +2290,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = {
 	.get_reg            = hns3_get_regs,
 	.dev_supported_ptypes_get = hns3_dev_supported_ptypes_get,
 	.tx_done_cleanup    = hns3_tx_done_cleanup,
+	.eth_dev_priv_dump  = hns3_eth_dev_priv_dump,
 };
 
 static const struct hns3_reset_ops hns3vf_reset_ops = {
diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
index 8a4c7cc100..665b2afedf 100644
--- a/drivers/net/hns3/meson.build
+++ b/drivers/net/hns3/meson.build
@@ -30,6 +30,7 @@ sources = files(
         'hns3_tm.c',
         'hns3_ptp.c',
         'hns3_common.c',
+	'hns3_ethdev_dump.c',
 )
 
 deps += ['hash']
-- 
2.30.0

