From a0ac3e3cd5e94657ee1a58c74037aa6898898c75 Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Fri, 4 Aug 2023 17:25:53 +0800
Subject: hikptool/roce: Add roce_rst cmd for reset signal registers query

Add roce_rst cmd for reset signal registers query.

Example:
hikptool roce_rst -i eth1

Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
 net/hikp_net_lib.h                            |  1 +
 .../roce_ext_common/hikp_roce_ext_common.c    |  1 +
 .../roce_ext_common/hikp_roce_ext_common.h    |  1 +
 net/roce/roce_rst/hikp_roce_rst.c             | 78 +++++++++++++++++++
 net/roce/roce_rst/hikp_roce_rst.h             | 29 +++++++
 5 files changed, 110 insertions(+)
 create mode 100644 net/roce/roce_rst/hikp_roce_rst.c
 create mode 100644 net/roce/roce_rst/hikp_roce_rst.h

diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h
index 21b5357..e60fc15 100644
--- a/net/hikp_net_lib.h
+++ b/net/hikp_net_lib.h
@@ -100,6 +100,7 @@ enum roce_cmd_type {
 	GET_ROCEE_TIMER_CMD,
 	GET_ROCEE_TRP_CMD,
 	GET_ROCEE_TSP_CMD,
+	GET_ROCEE_RST_CMD,
 };
 
 enum ub_cmd_type {
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.c b/net/roce/roce_ext_common/hikp_roce_ext_common.c
index ec47dce..01dded5 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -42,6 +42,7 @@ static const struct cmd_type_info {
 	{GET_ROCEE_TIMER_CMD, "TIMER", ROCE_HIKP_TIMER_REG_NUM_EXT},
 	{GET_ROCEE_TRP_CMD, "TRP", ROCE_HIKP_TRP_REG_NUM_EXT},
 	{GET_ROCEE_TSP_CMD, "TSP", ROCE_HIKP_TSP_REG_NUM_EXT},
+	{GET_ROCEE_RST_CMD, "RST", ROCE_HIKP_RST_REG_NUM},
 };
 
 static int get_cmd_info_table_idx(enum roce_cmd_type cmd_type)
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.h b/net/roce/roce_ext_common/hikp_roce_ext_common.h
index 1e8063d..918712f 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.h
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.h
@@ -27,6 +27,7 @@
 #define ROCE_HIKP_TIMER_REG_NUM_EXT ROCE_MAX_REG_NUM
 #define ROCE_HIKP_TRP_REG_NUM_EXT ROCE_MAX_REG_NUM
 #define ROCE_HIKP_TSP_REG_NUM_EXT ROCE_MAX_REG_NUM
+#define ROCE_HIKP_RST_REG_NUM ROCE_MAX_REG_NUM
 
 struct roce_ext_head {
 	uint8_t total_block_num;
diff --git a/net/roce/roce_rst/hikp_roce_rst.c b/net/roce/roce_rst/hikp_roce_rst.c
new file mode 100644
index 0000000..ad4dd0c
--- /dev/null
+++ b/net/roce/roce_rst/hikp_roce_rst.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Hisilicon Technologies Co., Ltd.
+ * Hikptool is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *          http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ *
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include "hikp_roce_rst.h"
+
+static struct cmd_roce_rst_param g_roce_rst_param = { 0 };
+
+static int hikp_roce_rst_help(struct major_cmd_ctrl *self, const char *argv)
+{
+	printf("\n  Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n");
+	printf("\n         %s\n", self->cmd_ptr->help_info);
+	printf("  Options:\n\n");
+	printf("    %s, %-25s %s\n", "-h", "--help", "display this help and exit");
+	printf("    %s, %-25s %s\n", "-i", "--interface=<interface>", "device target, e.g. eth0");
+	printf("\n");
+
+	return 0;
+}
+
+static int hikp_roce_rst_target(struct major_cmd_ctrl *self, const char *argv)
+{
+	self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_roce_rst_param.target));
+	if (self->err_no)
+		snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.\n", argv);
+
+	return self->err_no;
+}
+
+static int hikp_roce_rst_get_data(struct hikp_cmd_ret **cmd_ret,
+				  uint32_t block_id)
+{
+	struct hikp_cmd_header req_header = { 0 };
+	struct roce_rst_req_param req_data;
+	uint32_t req_size;
+	int ret;
+
+	req_data.bdf = g_roce_rst_param.target.bdf;
+	req_data.block_id = block_id;
+
+	req_size = sizeof(struct roce_rst_req_param);
+	hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_RST_CMD,
+		      g_roce_rst_param.sub_cmd);
+	*cmd_ret = hikp_cmd_alloc(&req_header, &req_data, req_size);
+	ret = hikp_rsp_normal_check(*cmd_ret);
+	if (ret)
+		printf("hikptool roce_rst cmd_ret malloc failed, sub_cmd = %u, ret = %d.\n",
+			g_roce_rst_param.sub_cmd, ret);
+
+	return ret;
+}
+
+static void hikp_roce_rst_execute(struct major_cmd_ctrl *self)
+{
+	hikp_roce_ext_execute(self, GET_ROCEE_RST_CMD, hikp_roce_rst_get_data);
+}
+
+static void cmd_roce_rst_init(void)
+{
+	struct major_cmd_ctrl *major_cmd = get_major_cmd();
+
+	major_cmd->option_count = 0;
+	major_cmd->execute = hikp_roce_rst_execute;
+
+	cmd_option_register("-h", "--help", false, hikp_roce_rst_help);
+	cmd_option_register("-i", "--interface", true, hikp_roce_rst_target);
+}
+
+HIKP_CMD_DECLARE("roce_rst", "get roce_rst registers information", cmd_roce_rst_init);
diff --git a/net/roce/roce_rst/hikp_roce_rst.h b/net/roce/roce_rst/hikp_roce_rst.h
new file mode 100644
index 0000000..731effc
--- /dev/null
+++ b/net/roce/roce_rst/hikp_roce_rst.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2023 Hisilicon Technologies Co., Ltd.
+ * Hikptool is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *          http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ *
+ * See the Mulan PSL v2 for more details.
+ */
+
+#ifndef __HIKP_ROCE_RST_H__
+#define __HIKP_ROCE_RST_H__
+
+#include "hikp_roce_ext_common.h"
+
+struct cmd_roce_rst_param {
+	struct tool_target target;
+	uint32_t sub_cmd;
+};
+
+struct roce_rst_req_param {
+	struct bdf_t bdf;
+	uint32_t block_id;
+};
+
+#endif /* __HIKP_ROCE_RST_H__ */
-- 
2.30.0

