core: Add TX/RX API that exposes message tag and tag owner

MCTP received packets can carry a message tag and tag owner bit
which is set by a remote MCTP endpoint. This can be used by the
remote MCTP endpoint to track the responses. Thus, libmctp should
provide a mechanism for the upper layer MCTP applications to
respond with the same message tag.

This patchset extends TX and RX API with message tag and
tag owner bits.

Signed-off-by: Sumanth Bhat <sumanth.bhat@linux.intel.com>
Change-Id: I6d07eafa86c653abdd4313ab7cc77e5a93124477
diff --git a/tests/test_astlpc.c b/tests/test_astlpc.c
index 054eda1..f781fa5 100644
--- a/tests/test_astlpc.c
+++ b/tests/test_astlpc.c
@@ -150,7 +150,8 @@
 	.lpc_write = mctp_astlpc_mmio_lpc_write,
 };
 
-static void rx_message(uint8_t eid __unused, void *data __unused, void *msg,
+static void rx_message(uint8_t eid __unused, bool tag_owner __unused,
+		       uint8_t msg_tag __unused, void *data __unused, void *msg,
 		       size_t len)
 {
 	struct astlpc_test *test = data;
@@ -257,7 +258,8 @@
 	mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
 
 	/* BMC sends a message */
-	rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.bmc.mctp, 9, MCTP_MESSAGE_TO_SRC, 0, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 
 	/* Host receives the first packet */
@@ -284,6 +286,7 @@
 {
 	struct astlpc_test ctx = { 0 };
 	uint8_t msg[MCTP_BTU];
+	uint8_t tag = 0;
 	int rc;
 
 	/* Test harness initialisation */
@@ -297,7 +300,8 @@
 	mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx);
 
 	/* Host sends the single-packet message */
-	rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.host.mctp, 8, MCTP_MESSAGE_TO_DST, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
@@ -324,6 +328,7 @@
 {
 	struct astlpc_test ctx = { 0 };
 	uint8_t msg[MCTP_BTU];
+	uint8_t tag = 0;
 	int rc;
 
 	/* Test harness initialisation */
@@ -337,7 +342,8 @@
 	mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
 
 	/* BMC sends the single-packet message */
-	rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.bmc.mctp, 9, MCTP_MESSAGE_TO_SRC, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
@@ -549,6 +555,7 @@
 	struct astlpc_test ctx = { 0 };
 	uint8_t kcs[2] = { 0 };
 	uint8_t msg[MCTP_BTU];
+	uint8_t tag = 0;
 	int rc;
 
 	ctx.lpc_mem = calloc(1, LPC_WIN_SIZE);
@@ -594,7 +601,8 @@
 	mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
 
 	/* BMC sends the single-packet message */
-	rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.bmc.mctp, 9, MCTP_MESSAGE_TO_SRC, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 
 	/* Host receives the single-packet message */
@@ -615,6 +623,7 @@
 	struct astlpc_test ctx = { 0 };
 	uint8_t unwritten[MCTP_BTU];
 	uint8_t msg[MCTP_BTU];
+	uint8_t tag = 0;
 	int rc;
 
 	/* Test harness initialisation */
@@ -634,7 +643,8 @@
 	mctp_astlpc_poll(ctx.host.astlpc);
 
 	/* Host attempts to send the single-packet message, but is prevented */
-	rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.host.mctp, 8, MCTP_MESSAGE_TO_DST, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 	assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF));
 	astlpc_assert_tx_packet(&ctx.host, &unwritten[0], MCTP_BTU);
@@ -1083,6 +1093,7 @@
 	struct astlpc_endpoint *bmc, *host;
 	struct astlpc_test ctx;
 	uint8_t kcs[2] = { 0 };
+	uint8_t tag = 0;
 	void *lpc_mem;
 	int rc;
 
@@ -1117,7 +1128,8 @@
 
 	memset(ctx.msg, 0x5a, 2 * MCTP_BODY_SIZE(8192));
 
-	rc = mctp_message_tx(host->mctp, 8, ctx.msg, 2 * MCTP_BODY_SIZE(8192));
+	rc = mctp_message_tx(host->mctp, 8, MCTP_MESSAGE_TO_DST, tag, ctx.msg,
+			     2 * MCTP_BODY_SIZE(8192));
 	assert(rc == 0);
 	rc = mctp_astlpc_poll(bmc->astlpc);
 	assert(rc == 0);
@@ -1142,6 +1154,7 @@
 	struct astlpc_test ctx;
 	uint8_t kcs[2] = { 0 };
 	uint8_t msg[MCTP_BTU];
+	uint8_t tag = 0;
 	void *lpc_mem;
 	int rc;
 
@@ -1165,7 +1178,8 @@
 	 * terminating after a period long enough to packetise the message.
 	 */
 	alarm(1);
-	mctp_message_tx(bmc->mctp, 9, msg, sizeof(msg));
+	mctp_message_tx(bmc->mctp, 9, MCTP_MESSAGE_TO_SRC, tag, msg,
+			sizeof(msg));
 	alarm(0);
 
 	endpoint_destroy(bmc);
@@ -1178,6 +1192,7 @@
 	struct mctp_lpcmap_hdr *hdr;
 	uint8_t msg[MCTP_BTU];
 	uint32_t offset;
+	uint8_t tag = 0;
 	uint32_t code;
 	uint8_t *tlr;
 	int rc;
@@ -1193,7 +1208,8 @@
 	mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx);
 
 	/* Host sends the single-packet message */
-	rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.host.mctp, 8, MCTP_MESSAGE_TO_DST, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
@@ -1230,6 +1246,7 @@
 	struct mctp_lpcmap_hdr *hdr;
 	uint8_t msg[MCTP_BTU];
 	uint32_t offset;
+	uint8_t tag = 0;
 	uint32_t code;
 	uint8_t *tlr;
 	int rc;
@@ -1245,7 +1262,8 @@
 	mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
 
 	/* BMC sends the single-packet message */
-	rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
+	rc = mctp_message_tx(ctx.bmc.mctp, 9, MCTP_MESSAGE_TO_SRC, tag, msg,
+			     sizeof(msg));
 	assert(rc == 0);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);