refactor(ti): add the sec hdr to the ti sci msg

We can make an assumption that since TF-A is a secure entity it will
always communicate with a secure header present in all it's TI SCI
messages, whether received or transmitted.
Hence, just add the sec hdr to the TI SCI header itself and get rid of
any logic that aims to skip these secure header bytes (like it was
being done in sec proxy for eg.)
No functional change expected. Hence, preserved the bits from the
previous sec proxy driver implementation where we zero out the chksum.

Change-Id: Id332276c038549e87dda1969b8dc90bcb19bf1ca
Signed-off-by: Dhruva Gole <d-gole@ti.com>
diff --git a/drivers/ti/ipc/sec_proxy.c b/drivers/ti/ipc/sec_proxy.c
index 74db8b6..55396f6 100644
--- a/drivers/ti/ipc/sec_proxy.c
+++ b/drivers/ti/ipc/sec_proxy.c
@@ -103,18 +103,6 @@
 };
 
 /**
- * struct sec_msg_hdr - Message header for secure messages and responses
- * @checksum:	CRC of message for integrity checking
- */
-union sec_msg_hdr {
-	struct {
-		uint16_t checksum;
-		uint16_t reserved;
-	} __packed;
-	uint32_t data;
-};
-
-/**
  * k3_sec_proxy_verify_thread() - Verify thread status before
  *				  sending/receiving data
  * @spt: Pointer to Secure Proxy thread description
@@ -209,7 +197,6 @@
 int ti_sci_transport_send(enum ti_sci_transport_chan_id id, const struct ti_sci_msg *msg)
 {
 	struct k3_sec_proxy_thread *spt = &spm.threads[id];
-	union sec_msg_hdr secure_header;
 	int num_words, trail_bytes, i, ret;
 	uintptr_t data_reg;
 
@@ -220,19 +207,13 @@
 	}
 
 	/* Check the message size */
-	if (msg->len + sizeof(secure_header) > spm.desc.max_msg_size) {
+	if (msg->len > spm.desc.max_msg_size) {
 		ERROR("Thread %s message length %lu > max msg size\n",
 		      spt->name, msg->len);
 		return -EINVAL;
 	}
 
-	/* TODO: Calculate checksum */
-	secure_header.checksum = 0;
-
-	/* Send the secure header */
 	data_reg = spm.desc.data_start_offset;
-	mmio_write_32(spt->data + data_reg, secure_header.data);
-	data_reg += sizeof(uint32_t);
 
 	/* Send whole words */
 	num_words = msg->len / sizeof(uint32_t);
@@ -282,7 +263,6 @@
 int ti_sci_transport_recv(enum ti_sci_transport_chan_id id, struct ti_sci_msg *msg)
 {
 	struct k3_sec_proxy_thread *spt = &spm.threads[id];
-	union sec_msg_hdr secure_header;
 	uintptr_t data_reg;
 	int num_words, trail_bytes, i, ret;
 
@@ -292,10 +272,7 @@
 		return ret;
 	}
 
-	/* Read secure header */
 	data_reg = spm.desc.data_start_offset;
-	secure_header.data = mmio_read_32(spt->data + data_reg);
-	data_reg += sizeof(uint32_t);
 
 	/* Read whole words */
 	num_words = msg->len / sizeof(uint32_t);
@@ -324,9 +301,6 @@
 	if (data_reg <= spm.desc.data_end_offset)
 		mmio_read_32(spt->data + spm.desc.data_end_offset);
 
-	/* TODO: Verify checksum */
-	(void)secure_header.checksum;
-
 	VERBOSE("Message successfully received from thread %s\n", spt->name);
 
 	return 0;
diff --git a/drivers/ti/ti_sci/ti_sci.c b/drivers/ti/ti_sci/ti_sci.c
index 7d1b470..f0813e5 100644
--- a/drivers/ti/ti_sci/ti_sci.c
+++ b/drivers/ti/ti_sci/ti_sci.c
@@ -69,6 +69,9 @@
 		return -ERANGE;
 
 	hdr = (struct ti_sci_msg_hdr *)tx_buf;
+
+	/* TODO: Calculate checksum */
+	hdr->sec_hdr.checksum = 0;
 	hdr->seq = ++message_sequence;
 	hdr->type = msg_type;
 	hdr->host = TI_SCI_HOST_ID;
@@ -133,6 +136,9 @@
 	if (!(hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK))
 		return -ENODEV;
 
+	/* TODO: Verify checksum */
+	(void)hdr->sec_hdr.checksum;
+
 	return 0;
 }
 
diff --git a/drivers/ti/ti_sci/ti_sci_protocol.h b/drivers/ti/ti_sci/ti_sci_protocol.h
index d9489f6..bdd2462 100644
--- a/drivers/ti/ti_sci/ti_sci_protocol.h
+++ b/drivers/ti/ti_sci/ti_sci_protocol.h
@@ -54,6 +54,17 @@
 #define TISCI_MSG_WAIT_PROC_BOOT_STATUS	0xc401
 
 /**
+ * struct ti_sci_secure_msg_hdr - Header that prefixes all TISCI messages sent
+ *				  via secure transport.
+ * @checksum:	crc16 checksum for the entire message
+ * @reserved:	Reserved for future use.
+ */
+struct ti_sci_secure_msg_hdr {
+	uint16_t checksum;
+	uint16_t reserved;
+} __packed;
+
+/**
  * struct ti_sci_msg_hdr - Generic Message Header for All messages and responses
  * @type:	Type of messages: One of TI_SCI_MSG* values
  * @host:	Host of the message
@@ -61,6 +72,7 @@
  * @flags:	Flag for the message
  */
 struct ti_sci_msg_hdr {
+	struct ti_sci_secure_msg_hdr sec_hdr;
 	uint16_t type;
 	uint8_t host;
 	uint8_t seq;