[v3,03/11] libflash/mbox-flash: Move sequence handling to driver level

Message ID 20171205010113.23263-4-cyril.bur@au1.ibm.com
State New
Headers show
Series
  • MBOX Protocol: Onwards to V3
Related show

Commit Message

Cyril Bur Dec. 5, 2017, 1:01 a.m.
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 hw/lpc-mbox.c         |  9 +++++++++
 libflash/mbox-flash.c | 10 ----------
 2 files changed, 9 insertions(+), 10 deletions(-)

Patch

diff --git a/hw/lpc-mbox.c b/hw/lpc-mbox.c
index 7a57f1e7..74214938 100644
--- a/hw/lpc-mbox.c
+++ b/hw/lpc-mbox.c
@@ -63,6 +63,7 @@  struct mbox {
 	void *attn_data;
 	struct lock lock; /* Protect in_flight */
 	struct bmc_mbox_msg *in_flight;
+	uint8_t sequence;
 };
 
 static struct mbox mbox;
@@ -130,6 +131,7 @@  int bmc_mbox_enqueue(struct bmc_mbox_msg *msg)
 
 	mbox.in_flight = msg;
 	unlock(&mbox.lock);
+	msg->seq = ++mbox.sequence;
 
 	bmc_mbox_send_message(msg);
 
@@ -162,7 +164,13 @@  static void mbox_poll(struct timer *t __unused, void *data __unused,
 			prlog(PR_CRIT, "Couldn't find the message!!\n");
 			goto out_response;
 		}
+
 		bmc_mbox_recv_message(msg);
+		if (mbox.sequence != msg->seq) {
+			prlog(PR_ERR, "Got a response to a message we no longer care about\n");
+			goto out_response;
+		}
+
 		if (mbox.callback)
 			mbox.callback(msg, mbox.drv_data);
 		else
@@ -330,6 +338,7 @@  void mbox_init(void)
 	mbox.in_flight = NULL;
 	mbox.callback = NULL;
 	mbox.drv_data = NULL;
+	mbox.sequence = 0;
 	init_lock(&mbox.lock);
 
 	init_timer(&mbox.poller, mbox_poll, NULL);
diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
index c8a8dade..3615df78 100644
--- a/libflash/mbox-flash.c
+++ b/libflash/mbox-flash.c
@@ -59,7 +59,6 @@  struct mbox_flash_data {
 	bool pause;
 	bool busy;
 	bool ack;
-	uint8_t seq;
 	/* Plus one, commands start at 1 */
 	void (*handlers[MBOX_COMMAND_COUNT + 1])(struct mbox_flash_data *, struct bmc_mbox_msg*);
 	struct bmc_mbox_msg msg_mem;
@@ -199,7 +198,6 @@  static struct bmc_mbox_msg *msg_alloc(struct mbox_flash_data *mbox_flash,
 	 * really the performance optimisation you want to make.
 	 */
 	memset(&mbox_flash->msg_mem, 0, sizeof(mbox_flash->msg_mem));
-	mbox_flash->msg_mem.seq = ++mbox_flash->seq;
 	mbox_flash->msg_mem.command = command;
 	return &mbox_flash->msg_mem;
 }
@@ -900,14 +898,6 @@  static void mbox_flash_callback(struct bmc_mbox_msg *msg, void *priv)
 		goto out;
 	}
 
-	if (msg->seq != mbox_flash->seq) {
-		/* Uhoh */
-		prlog(PR_ERR, "Sequence numbers don't match! Got: %02x Expected: %02x\n",
-				msg->seq, mbox_flash->seq);
-		mbox_flash->rc = MBOX_R_SYSTEM_ERROR;
-		goto out;
-	}
-
 	if (msg->command > MBOX_COMMAND_COUNT) {
 		prlog(PR_ERR, "Got response to unknown command %02x\n", msg->command);
 		mbox_flash->rc = -1;