Add protocol version check during probing

To ensure that the Linux kernel NPU driver and the firmware used are
compatible, the NPU driver will now request and verify the protocol
version when setting up the device during the probing.

Change-Id: I13bca96bf6f98ca90dc79e11ae637c269c2a5eec
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
diff --git a/kernel/ethosu_device.c b/kernel/ethosu_device.c
index 32d04ae..0df6c07 100644
--- a/kernel/ethosu_device.c
+++ b/kernel/ethosu_device.c
@@ -31,6 +31,7 @@
 #include "ethosu_cancel_inference.h"
 #include "ethosu_network.h"
 #include "ethosu_network_info.h"
+#include "ethosu_version.h"
 #include "uapi/ethosu.h"
 
 #include <linux/dma-mapping.h>
@@ -145,26 +146,18 @@
 	case ETHOSU_CORE_MSG_VERSION_RSP:
 		if (length != sizeof(rpmsg->version_rsp)) {
 			dev_warn(dev,
-				 "Msg: Version response of incorrect size. size=%u, expected=%zu", length,
+				 "Msg: Protocol version response of incorrect size. size=%u, expected=%zu", length,
 				 sizeof(rpmsg->version_rsp));
 			ret = -EBADMSG;
 			break;
 		}
 
-		dev_info(dev, "Msg: Version response v%u.%u.%u",
-			 rpmsg->version_rsp.major, rpmsg->version_rsp.minor,
-			 rpmsg->version_rsp.patch);
+		dev_dbg(dev, "Msg: Protocol version response %u.%u.%u",
+			rpmsg->version_rsp.major, rpmsg->version_rsp.minor,
+			rpmsg->version_rsp.patch);
 
-		/* Check major and minor version match, else return error */
-		if (rpmsg->version_rsp.major != ETHOSU_CORE_MSG_VERSION_MAJOR ||
-		    rpmsg->version_rsp.minor != ETHOSU_CORE_MSG_VERSION_MINOR) {
-			dev_warn(dev, "Msg: Version mismatch detected! ");
-			dev_warn(dev, "Local version: v%u.%u.%u",
-				 ETHOSU_CORE_MSG_VERSION_MAJOR,
-				 ETHOSU_CORE_MSG_VERSION_MINOR,
-				 ETHOSU_CORE_MSG_VERSION_PATCH);
-		}
-
+		ethosu_version_rsp(&edev->mailbox, rpmsg->header.msg_id,
+				   &rpmsg->version_rsp);
 		break;
 	case ETHOSU_CORE_MSG_CAPABILITIES_RSP:
 		if (length != sizeof(rpmsg->cap_rsp)) {
@@ -457,7 +450,13 @@
 	if (ret)
 		goto free_rpmsg_ept;
 
-	ethosu_mailbox_ping(&edev->mailbox);
+	device_lock(dev);
+	ret = ethosu_version_check_request(dev, &edev->mailbox);
+	device_unlock(dev);
+	if (ret) {
+		dev_err(dev, "Protocol version check failed: %d", ret);
+		goto deinit_mailbox;
+	}
 
 	device_lock(dev);
 	ret = ethosu_capabilities_request(dev, &edev->mailbox,