[qca-ssdk-shell]:add reg dump command

add register dump command

Change-Id: I2f1fa2bd09649bd20b2c3cb724cbe05f77c92309
Signed-off-by: slv <slv@codeaurora.org>
diff --git a/include/api/api_desc.h b/include/api/api_desc.h
index e3aaf9e..71fe1f9 100755
--- a/include/api/api_desc.h
+++ b/include/api/api_desc.h
@@ -1901,7 +1901,16 @@
     SW_PARAM_DEF(SW_API_REG_FIELD_SET, SW_UINT32, 4, SW_PARAM_PTR|SW_PARAM_IN, "Data"),\
     SW_PARAM_DEF(SW_API_REG_FIELD_SET, SW_UINT32, 4, SW_PARAM_IN, "Data Len"),
 
+#define SW_API_REG_DUMP_DESC \
+    SW_PARAM_DEF(SW_API_REG_DUMP, SW_UINT32, 4, SW_PARAM_IN, "Dev ID"), \
+    SW_PARAM_DEF(SW_API_REG_DUMP, SW_UINT32, 4, SW_PARAM_IN, "Register group idx"), \
+    SW_PARAM_DEF(SW_API_REG_DUMP, SW_REG_DUMP, sizeof(fal_reg_dump_t), SW_PARAM_PTR|SW_PARAM_OUT, \
+              "Register dump"),
 
+#define SW_API_DBG_REG_DUMP_DESC \
+    SW_PARAM_DEF(SW_API_DBG_REG_DUMP, SW_UINT32, 4, SW_PARAM_IN, "Dev ID"), \
+    SW_PARAM_DEF(SW_API_DBG_REG_DUMP, SW_DBG_REG_DUMP, sizeof(fal_debug_reg_dump_t), SW_PARAM_PTR|SW_PARAM_OUT, \
+              "Debug Register dump"),
 
 
 #define SW_API_COSMAP_DSCP_TO_PRI_SET_DESC \
diff --git a/include/api/sw_api.h b/include/api/sw_api.h
index 66b62ed..2937da1 100755
--- a/include/api/sw_api.h
+++ b/include/api/sw_api.h
@@ -127,6 +127,8 @@
 		SW_FIBER_MODE,
 		SW_INTERFACE_MODE,
 		SW_COUNTER_INFO,
+		SW_REG_DUMP,
+		SW_DBG_REG_DUMP,
     } sw_data_type_e;
 
     typedef struct
diff --git a/include/api/sw_ioctl.h b/include/api/sw_ioctl.h
index 0975387..deb2d89 100755
--- a/include/api/sw_ioctl.h
+++ b/include/api/sw_ioctl.h
@@ -608,7 +608,8 @@
 #define SW_API_REG_FIELD_SET       (7  + SW_API_DEBUG_OFFSET)
 #define SW_API_PSGMII_REG_GET             (8  + SW_API_DEBUG_OFFSET)
 #define SW_API_PSGMII_REG_SET             (9  + SW_API_DEBUG_OFFSET)
-
+#define SW_API_REG_DUMP          			(10  + SW_API_DEBUG_OFFSET)
+#define SW_API_DBG_REG_DUMP          		(11  + SW_API_DEBUG_OFFSET)
 
 #define SW_API_MAX                 0xffff
 
diff --git a/include/fal/fal_api.h b/include/fal/fal_api.h
index f2544e3..d2ec7f5 100755
--- a/include/fal/fal_api.h
+++ b/include/fal/fal_api.h
@@ -1218,7 +1218,10 @@
     SW_API_DEF(SW_API_PSGMII_REG_GET, fal_psgmii_reg_get), \
     SW_API_DEF(SW_API_PSGMII_REG_SET, fal_psgmii_reg_set), \
     SW_API_DEF(SW_API_REG_FIELD_GET, fal_reg_field_get), \
-    SW_API_DEF(SW_API_REG_FIELD_SET, fal_reg_field_set),
+    SW_API_DEF(SW_API_REG_FIELD_SET, fal_reg_field_set), \
+    SW_API_DEF(SW_API_REG_DUMP, fal_reg_dump), \
+    SW_API_DEF(SW_API_DBG_REG_DUMP, fal_dbg_reg_dump),
+
 
 #define REG_API_PARAM \
     SW_API_DESC(SW_API_PHY_GET) \
@@ -1228,7 +1231,9 @@
     SW_API_DESC(SW_API_PSGMII_REG_GET) \
     SW_API_DESC(SW_API_PSGMII_REG_SET) \
     SW_API_DESC(SW_API_REG_FIELD_GET) \
-    SW_API_DESC(SW_API_REG_FIELD_SET)
+    SW_API_DESC(SW_API_REG_FIELD_SET) \
+    SW_API_DESC(SW_API_REG_DUMP) \
+    SW_API_DESC(SW_API_DBG_REG_DUMP)
 
 
 #define SSDK_API \
diff --git a/include/fal/fal_reg_access.h b/include/fal/fal_reg_access.h
index 2b364be..68d0b02 100755
--- a/include/fal/fal_reg_access.h
+++ b/include/fal/fal_reg_access.h
@@ -61,6 +61,11 @@
                       a_uint32_t bit_offset, a_uint32_t field_len,
                       const a_uint8_t value[], a_uint32_t value_len);
 
+	sw_error_t 
+	fal_reg_dump(a_uint32_t dev_id, a_uint32_t reg_idx,fal_reg_dump_t *reg_dump);
+
+	sw_error_t
+	fal_dbg_reg_dump(a_uint32_t dev_id, fal_reg_dump_t *reg_dump);
 
 #ifdef __cplusplus
 }
diff --git a/include/fal/fal_type.h b/include/fal/fal_type.h
index e4d9939..92817f1 100755
--- a/include/fal/fal_type.h
+++ b/include/fal/fal_type.h
@@ -96,6 +96,22 @@
         a_uint32_t     egress_byte;
     } fal_counter_entry_t;
 
+	typedef struct{
+		a_uint32_t reg_count;
+		a_uint32_t reg_base;
+		a_uint32_t reg_end;
+		a_uint32_t reg_value[256];
+		a_int8_t   reg_name[32];
+	}fal_reg_dump_t;
+
+	typedef struct{
+		a_uint32_t reg_count;
+		a_uint32_t reg_addr[32];
+		a_uint32_t reg_value[32];
+		a_int8_t   reg_name[32];
+	}fal_debug_reg_dump_t;
+
+
 #ifdef __cplusplus
 }
 #endif                          /* __cplusplus */
diff --git a/include/shell/shell_io.h b/include/shell/shell_io.h
index b051ca3..12b6c76 100755
--- a/include/shell/shell_io.h
+++ b/include/shell/shell_io.h
@@ -399,5 +399,11 @@
 void
 cmd_data_print_counter_info(a_uint8_t * param_name, a_uint32_t * buf, a_uint32_t size);
 
+void
+cmd_data_print_register_info(a_uint8_t * param_name, a_uint32_t * buf, a_uint32_t size);
+
+void
+cmd_data_print_debug_register_info(a_uint8_t * param_name, a_uint32_t * buf, a_uint32_t size);
+
 #endif
 
diff --git a/src/fal_uk/fal_reg_access.c b/src/fal_uk/fal_reg_access.c
index 56293ed..d09b57d 100755
--- a/src/fal_uk/fal_reg_access.c
+++ b/src/fal_uk/fal_reg_access.c
@@ -101,3 +101,21 @@
     return rv;
 }
 
+sw_error_t
+fal_reg_dump(a_uint32_t dev_id, a_uint32_t reg_idx,fal_reg_dump_t *reg_dump)
+{
+    sw_error_t rv;
+
+    rv = sw_uk_exec(SW_API_REG_DUMP, dev_id, (a_uint32_t) reg_idx,(a_uint32_t) reg_dump);
+    return rv;
+}
+
+
+sw_error_t
+fal_dbg_reg_dump(a_uint32_t dev_id,fal_reg_dump_t *reg_dump)
+{
+    sw_error_t rv;
+
+    rv = sw_uk_exec(SW_API_DBG_REG_DUMP, dev_id,(a_uint32_t) reg_dump);
+    return rv;
+}
diff --git a/src/shell/shell_config.c b/src/shell/shell_config.c
index d94d62a..573d723 100755
--- a/src/shell/shell_config.c
+++ b/src/shell/shell_config.c
@@ -730,6 +730,8 @@
             {"phy", "set", "write phy register", "<ph_id> <reg_addr> <value>", SW_API_PHY_SET, NULL},
             {"reg", "get", "read switch register", "<reg_addr> <4>", SW_API_REG_GET, NULL},
             {"reg", "set", "write switch register", "<reg_addr> <value> <4>", SW_API_REG_SET, NULL},
+			{"reg", "dump", "dump switch register group", "<group id> <0-6>", SW_API_REG_DUMP, NULL},
+			{"dbgreg", "dump", "dump switch dbg register group", "", SW_API_DBG_REG_DUMP, NULL},
             {"preg", "get", "read psgmii register", "<reg_addr> <4>", SW_API_PSGMII_REG_GET, NULL},
             {"preg", "set", "write psgmii register", "<reg_addr> <value> <4>", SW_API_PSGMII_REG_SET, NULL},
             {"field", "get", "read switch register field", "<reg_addr> <offset> <len> <4>", SW_API_REG_FIELD_GET, NULL},
diff --git a/src/shell/shell_io.c b/src/shell/shell_io.c
index 0248466..02a07a2 100755
--- a/src/shell/shell_io.c
+++ b/src/shell/shell_io.c
@@ -217,6 +217,8 @@
     SW_TYPE_DEF(SW_FIBER_MODE, cmd_data_check_fiber_mode, cmd_data_print_fiber_mode),
     SW_TYPE_DEF(SW_INTERFACE_MODE, cmd_data_check_interface_mode, cmd_data_print_interface_mode),
     SW_TYPE_DEF(SW_COUNTER_INFO, NULL, cmd_data_print_counter_info),
+    SW_TYPE_DEF(SW_REG_DUMP, NULL, cmd_data_print_register_info),
+    SW_TYPE_DEF(SW_DBG_REG_DUMP, NULL, cmd_data_print_debug_register_info),
 };
 
 sw_data_type_t *
@@ -510,6 +512,60 @@
     }
 }
 
+void
+cmd_data_print_debug_register_info(a_uint8_t * param_name, a_uint32_t * buf, a_uint32_t size)
+{
+    dprintf("\n[%s]", param_name);
+	fal_debug_reg_dump_t * reg_dump = (fal_debug_reg_dump_t * )buf;
+
+	a_uint32_t reg_count;
+
+	dprintf("\n%s. ", reg_dump->reg_name);
+
+	reg_count = 0;
+	dprintf("\n");
+	for (;reg_count < reg_dump->reg_count;reg_count++)
+	{
+		dprintf("%08x:%08x  ",reg_dump->reg_addr[reg_count], reg_dump->reg_value[reg_count]);
+		if ((reg_count + 1) % 4 == 0)
+			dprintf("\n");
+	}
+
+	dprintf("\n\n\n");
+}
+
+
+
+void
+cmd_data_print_register_info(a_uint8_t * param_name, a_uint32_t * buf, a_uint32_t size)
+{
+    dprintf("\n[%s]", param_name);
+	fal_reg_dump_t * reg_dump = (fal_reg_dump_t * )buf;
+
+	a_uint32_t n[8]={0,4,8,0xc,0x10,0x14,0x18,0x1c};
+
+	a_uint32_t i;
+	a_uint32_t dump_addr, reg_count, reg_val;
+
+	dprintf("\n%s. ", reg_dump->reg_name);
+	dprintf("\n	%8x %8x %8x %8x %8x %8x %8x %8x\n",
+					n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]);
+	dprintf(" [%04x] ", reg_dump->reg_base);
+
+	reg_count = 0;
+	for (dump_addr = reg_dump->reg_base;
+			(dump_addr <= reg_dump->reg_end )&& (reg_count <= reg_dump->reg_count);
+			reg_count++)
+	{
+		dprintf("%08x ", reg_dump->reg_value[reg_count]);
+		dump_addr += 4;
+		if ((reg_count + 1) % 8 == 0)
+			dprintf("\n [%04x] ", dump_addr);
+	}
+
+	dprintf("\n\n\n");
+}
+
 
 /*port ctrl*/
 sw_error_t