Minidump: Modify size of crashdump buffer

This change modifies size of crashdump buffer to
12K from 16K for ipq60xx and ipq807x

This change also makes dumping of crashdump TLVs more
generic and does not assume any fixed positions for
static or dynamic dump segments

Change-Id: I9723ebf55e4a6db3360b3370a2c6e15d22741e08
Signed-off-by: Gitanjali Krishna <gitanjal@codeaurora.org>
diff --git a/board/qca/arm/common/crashdump.c b/board/qca/arm/common/crashdump.c
index 92dfdd8..caa56ef 100644
--- a/board/qca/arm/common/crashdump.c
+++ b/board/qca/arm/common/crashdump.c
@@ -260,13 +260,13 @@
 		struct qca_wdt_crashdump_data *crashdump_data)
 {
 	unsigned char cur_type = QCA_WDT_LOG_DUMP_TYPE_INVALID;
-	unsigned int cur_size;
-	int ret_val;
+	unsigned int cur_size = 0;
+	int ret_val = 0;
 	struct st_tlv_info tlv_info;
-	int static_enum_count;
+	int static_enum_count = 0;
+	int tlv_size = 0;
 
-	for (static_enum_count = QCA_WDT_LOG_DUMP_TYPE_INVALID; static_enum_count
-			< QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD ; static_enum_count++ ) {
+	while (static_enum_count < 3) {
 		ret_val = qca_wdt_scm_extract_tlv_info(scm_tlv_msg,
 			&cur_type, &cur_size);
 		if (!ret_val && cur_type == QCA_WDT_LOG_DUMP_TYPE_UNAME ){
@@ -274,6 +274,7 @@
 			ret_val = qca_wdt_scm_extract_tlv_data(scm_tlv_msg,
 					crashdump_data->uname, cur_size);
 			crashdump_tlv_count++;
+			static_enum_count++;
 		}else if (!ret_val && cur_type == QCA_WDT_LOG_DUMP_TYPE_DMESG){
 			ret_val = qca_wdt_scm_extract_tlv_data(scm_tlv_msg,
 				(unsigned char *)&tlv_info,
@@ -283,6 +284,7 @@
 				crashdump_data->log_buf_len = *(uint32_t *)(uintptr_t)tlv_info.size;
 		         }
 			crashdump_tlv_count++;
+			static_enum_count++;
 		}else if (!ret_val && cur_type == QCA_WDT_LOG_DUMP_TYPE_LEVEL1_PT){
 			ret_val = qca_wdt_scm_extract_tlv_data(scm_tlv_msg,(unsigned char *)&tlv_info,cur_size);
 			if (!ret_val) {
@@ -290,6 +292,11 @@
 				crashdump_data->pt_len = tlv_info.size;
 			}
 			crashdump_tlv_count++;
+			static_enum_count++;
+		}
+		else if(!ret_val && cur_type == QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD) {
+			tlv_size = (cur_size + QCA_WDT_SCM_TLV_TYPE_LEN_SIZE);
+			scm_tlv_msg->cur_msg_buffer_pos += tlv_size;
 		}
 	}
 	return ret_val;
@@ -327,16 +334,20 @@
 	uint32_t memaddr;
 	struct qca_wdt_scm_tlv_msg *scm_tlv_msg = &tlv_msg;
 	unsigned char cur_type = QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD;
-	unsigned int cur_size;
-	int ret_val,tlv_size;
+	unsigned int cur_size = 0;
+	int ret_val = 0;
+	int tlv_size = 0;
 	struct st_tlv_info tlv_info;
 	uint32_t wlan_tlv_size;
+
 	char wlan_segment_name[32];
 
 	if(strncmp(dumpinfo[indx].name, "WLAN_MOD" ,strlen("WLAN_MOD"))) {
 		return CMD_RET_FAILURE;
 	}
 
+	scm_tlv_msg->cur_msg_buffer_pos = scm_tlv_msg->msg_buffer;
+
 	do {
 		ret_val = qca_wdt_scm_extract_tlv_info(scm_tlv_msg,
 			&cur_type, &cur_size);
@@ -376,7 +387,10 @@
 			udelay(10000); /* give some delay for server */
 			if (ret_val == CMD_RET_FAILURE)
 				return CMD_RET_FAILURE;
-		}
+		} else {
+            tlv_size = (cur_size + QCA_WDT_SCM_TLV_TYPE_LEN_SIZE);
+            scm_tlv_msg->cur_msg_buffer_pos += tlv_size;
+        }
 	}while (cur_type != QCA_WDT_LOG_DUMP_TYPE_INVALID);
 
 	printf("\nMinidump: Dumped %d TLVs\n",crashdump_tlv_count);
diff --git a/include/configs/ipq6018.h b/include/configs/ipq6018.h
index edd85fe..7cad289 100644
--- a/include/configs/ipq6018.h
+++ b/include/configs/ipq6018.h
@@ -341,8 +341,8 @@
 
 #define CONFIG_QCA_KERNEL_CRASHDUMP_ADDRESS	*((unsigned int *)0x08600658)
 #define CONFIG_CPU_CONTEXT_DUMP_SIZE		4096
-#define TLV_BUF_OFFSET						240 * 1024
-#define CONFIG_TLV_DUMP_SIZE				16 * 1024
+#define TLV_BUF_OFFSET						244 * 1024
+#define CONFIG_TLV_DUMP_SIZE				12 * 1024
 
 /* L1 cache line size is 64 bytes, L2 cache line size is 128 bytes
  * Cache flush and invalidation based on L1 cache, so the cache line
diff --git a/include/configs/ipq807x.h b/include/configs/ipq807x.h
index 320b766..819e67a 100644
--- a/include/configs/ipq807x.h
+++ b/include/configs/ipq807x.h
@@ -320,9 +320,9 @@
 #endif
 
 #define CONFIG_QCA_KERNEL_CRASHDUMP_ADDRESS	*((unsigned int *)0x08600658)
-#define TLV_BUF_OFFSET				496 * 1024
+#define TLV_BUF_OFFSET				500 * 1024
 #define CONFIG_CPU_CONTEXT_DUMP_SIZE		4096
-#define CONFIG_TLV_DUMP_SIZE			16 * 1024
+#define CONFIG_TLV_DUMP_SIZE			12 * 1024
 
 
 /* L1 cache line size is 64 bytes, L2 cache line size is 128 bytes