Reset firmware

Reset the firmware if it becomes unresponsive. Use ping to send
keep alive requests.

Only monitor ping and inference request messages. The other messages
pass no resources to the firmware and can be cancelled without
resetting the firmware.

Change-Id: Ifbcc370f02d79a64f25598f11376a1dc84a7a066
diff --git a/kernel/ethosu_mailbox.h b/kernel/ethosu_mailbox.h
index 956685b..55d4436 100644
--- a/kernel/ethosu_mailbox.h
+++ b/kernel/ethosu_mailbox.h
@@ -55,7 +55,15 @@
 	struct mbox_chan         *tx;
 	ethosu_mailbox_cb        callback;
 	void                     *user_arg;
+	struct list_head         pending_list;
 	struct ethosu_watchdog   *wdog;
+	unsigned                 ping_count;
+};
+
+struct ethosu_mailbox_msg {
+	struct list_head list;
+	void             (*fail)(struct ethosu_mailbox_msg *msg);
+	int              (*resend)(struct ethosu_mailbox_msg *msg);
 };
 
 /****************************************************************************
@@ -81,6 +89,26 @@
 void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
 
 /**
+ * ethosu_mailbox_wait_prepare() - Prepare to wait on firmware
+ *
+ * This function must only be called when the firmware is in a
+ * stopped state. It invalidates the firmware queues setting
+ * size, read and write positions to illegal values.
+ */
+void ethosu_mailbox_wait_prepare(struct ethosu_mailbox *mbox);
+
+/**
+ * ethosu_mailbox_wait_firmware() - Waiting for firmware to initialize
+ *                                  message queues
+ *
+ * Following a call to ethosu_mailbox_wait_prepare() this function waits for
+ * the firmware to boot up and initialize the firmware queues.
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_mailbox_wait_firmware(struct ethosu_mailbox *mbox);
+
+/**
  * ethosu_mailbox_read() - Read message from mailbox
  *
  * Return: 0 message read, else error code.
@@ -91,6 +119,30 @@
 			size_t length);
 
 /**
+ * ethosu_mailbox_find() - Find mailbox message
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_mailbox_find(struct ethosu_mailbox *mbox,
+			struct ethosu_mailbox_msg *msg);
+
+/**
+ * ethosu_mailbox_fail() - Fail mailbox messages
+ *
+ * Call fail() callback on all messages in pending list.
+ */
+void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);
+
+/**
+ * ethosu_mailbox_resend() - Resend mailbox messages
+ *
+ * Call resend() callback on all messages in pending list.
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_mailbox_resend(struct ethosu_mailbox *mbox);
+
+/**
  * ethosu_mailbox_reset() - Reset to end of queue
  */
 void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);