Fix wait for TX buffer blocking receive callback

Currently, the mailbox uses the rpmsg_send function to send messages,
which will block for up to 15 seconds if there is no TX buffer available
for the message. This is an issue because the device mutex is locked
while waiting and the receive callback for messages uses the same mutex
to prevent concurrent access so no received messages can be handled
while waiting for a TX buffer.

To resolve this, the mailbox has been changed to use the rpmsg_trysend
function, which will return directly if there is no TX buffer available,
together with a wait queue. While waiting in the queue to send the
message, the device mutex is released to not block the receive callback
and other users of the mutex.

Change-Id: I34fbfd21167b49fb83744ab2473ab02632a809ee
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
diff --git a/kernel/ethosu_device.c b/kernel/ethosu_device.c
index 6866857..b889a7b 100644
--- a/kernel/ethosu_device.c
+++ b/kernel/ethosu_device.c
@@ -71,6 +71,7 @@
 {
 	struct ethosu_device *edev = dev_get_drvdata(&rpdev->dev);
 	struct device *dev = &edev->dev;
+	struct ethosu_mailbox *mbox = &edev->mailbox;
 	struct ethosu_core_rpmsg *rpmsg = data;
 	int length = len - sizeof(rpmsg->header);
 	int ret = 0;
@@ -106,7 +107,7 @@
 		break;
 	case ETHOSU_CORE_MSG_PING:
 		dev_info(dev, "Msg: Ping");
-		ret = ethosu_mailbox_pong(&edev->mailbox);
+		ret = ethosu_mailbox_pong(mbox);
 		break;
 	case ETHOSU_CORE_MSG_PONG:
 		dev_info(dev, "Msg: Pong");
@@ -124,7 +125,7 @@
 			 "Msg: Inference response. ofm_count=%u, status=%u",
 			 rpmsg->inf_rsp.ofm_count, rpmsg->inf_rsp.status);
 
-		ethosu_inference_rsp(&edev->mailbox, rpmsg->header.msg_id,
+		ethosu_inference_rsp(mbox, rpmsg->header.msg_id,
 				     &rpmsg->inf_rsp);
 		break;
 	case ETHOSU_CORE_MSG_CANCEL_INFERENCE_RSP:
@@ -139,7 +140,7 @@
 		dev_info(dev,
 			 "Msg: Cancel Inference response. status=%u",
 			 rpmsg->cancel_rsp.status);
-		ethosu_cancel_inference_rsp(&edev->mailbox,
+		ethosu_cancel_inference_rsp(mbox,
 					    rpmsg->header.msg_id,
 					    &rpmsg->cancel_rsp);
 		break;
@@ -156,7 +157,7 @@
 			rpmsg->version_rsp.major, rpmsg->version_rsp.minor,
 			rpmsg->version_rsp.patch);
 
-		ethosu_version_rsp(&edev->mailbox, rpmsg->header.msg_id,
+		ethosu_version_rsp(mbox, rpmsg->header.msg_id,
 				   &rpmsg->version_rsp);
 		break;
 	case ETHOSU_CORE_MSG_CAPABILITIES_RSP:
@@ -184,7 +185,7 @@
 			 rpmsg->cap_rsp.cmd_stream_version,
 			 rpmsg->cap_rsp.custom_dma);
 
-		ethosu_capability_rsp(&edev->mailbox, rpmsg->header.msg_id,
+		ethosu_capability_rsp(mbox, rpmsg->header.msg_id,
 				      &rpmsg->cap_rsp);
 		break;
 	case ETHOSU_CORE_MSG_NETWORK_INFO_RSP:
@@ -200,7 +201,7 @@
 			 "Msg: Network info response. status=%u",
 			 rpmsg->net_info_rsp.status);
 
-		ethosu_network_info_rsp(&edev->mailbox,
+		ethosu_network_info_rsp(mbox,
 					rpmsg->header.msg_id,
 					&rpmsg->net_info_rsp);
 
@@ -215,6 +216,8 @@
 
 	device_unlock(dev);
 
+	wake_up(&mbox->send_queue);
+
 	return ret;
 }