From 18c20824d9cb05c461c30f86484c0f2b0132bb85 Mon Sep 17 00:00:00 2001
From: Konstantin Porotchkin <kostap@marvell.com>
Date: Tue, 19 Jan 2021 14:06:36 +0200
Subject: [PATCH] fix compilation errors popped up by GCC-10

1. Multiple structure definitions due to define usage
   in a header file.
2. Computing static array size from a derived pointer

Change-Id: Ic016813c3f06e2ec8ff9b7ad33c182c85faaa7d5
Signed-off-by: Konstantin Porotchkin <kostap@marvell.com>
Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/boot/mv_ddr/+/43918
Tested-by: sa_ip-sw-jenkins <sa_ip-sw-jenkins@marvell.com>
Reviewed-by: Ofer Heifetz <oferh@marvell.com>
Reviewed-by: Nadav Haklai <nadavh@marvell.com>
---
 drivers/snps/snps.h    |  2 +-
 drivers/snps/snps_fw.c | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/snps/snps.h b/drivers/snps/snps.h
index 2ed1fec..6964c1c 100644
--- a/drivers/snps/snps.h
+++ b/drivers/snps/snps.h
@@ -322,7 +322,7 @@ struct snps_global_data {
 	int current_run_num;
 };
 
-struct snps_global_data gd;
+extern struct snps_global_data gd;
 
 
 extern int static_section_completed;
diff --git a/drivers/snps/snps_fw.c b/drivers/snps/snps_fw.c
index 811d70c..7417e06 100644
--- a/drivers/snps/snps_fw.c
+++ b/drivers/snps/snps_fw.c
@@ -101,6 +101,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "ddr_topology_def.h"
 #include "ddr3_training_ip_db.h"
 
+struct snps_global_data gd;
+
 struct mail_box_major_message mb_major_messages[] = {
 /*	ID,					Message string	*/
 	{MB_MAJOR_ID_END_INIT,			"End of initialization"},
@@ -450,8 +452,13 @@ static void snps_mail_box_print_stream_msg(int msg_id, int msg_log_index)
 	debug_enter();
 
 	/* 1D and 2D have different mail box dictionary database */
-	mb_stream_database = (snps_get_state() == TRAINING_2D ? two_d_messages : one_d_messages);
-	stream_msg_count = sizeof(mb_stream_database) / sizeof(struct mail_box_stream_message);
+	if (snps_get_state() == TRAINING_2D) {
+		mb_stream_database = two_d_messages;
+		stream_msg_count = ARRAY_SIZE(two_d_messages);
+	} else {
+		mb_stream_database = one_d_messages;
+		stream_msg_count = ARRAY_SIZE(one_d_messages);
+	}
 
 	/* Most of the dictionary msg_id's are continuous, so first check database if
 	 * msg_id cell holds this msg_id */
