mboxd: Implement timeout return value in GET_MBOX_INFO

The previous patch added a new return field in GET_MBOX_INFO called
"suggested timeout" to be used to provide a suggested maximum timeout
value to the host.

Add this to the return arguments of GET_MBOX_INFO.

Note that the host is free to ignore the value and the daemon can
leave this blank if it doesn't want to provide a timeout.

We hard code a milliseconds per megabyte value which was determined
to be approximately 8000 based on testing and is close to linear
as the access size changes. Testing was conducted on an Aspeed ast2500
on a Witherspoon with the dev-4.7 OpenBMC branch.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Change-Id: If24e41ebb1d9f03c2bdcca84819f9430fd3eeff6
diff --git a/mboxd_msg.c b/mboxd_msg.c
index d02e0bf..0cc1cd2 100644
--- a/mboxd_msg.c
+++ b/mboxd_msg.c
@@ -147,6 +147,20 @@
 }
 
 /*
+ * get_suggested_timeout() - get the suggested timeout value in seconds
+ * @context:	The mbox context pointer
+ *
+ * Return:	Suggested timeout in seconds
+ */
+static uint16_t get_suggested_timeout(struct mbox_context *context)
+{
+	struct window_context *window = find_largest_window(context);
+	uint32_t max_size_mb = window ? (window->size >> 20) : 0;
+
+	return align_up(max_size_mb * FLASH_ACCESS_MS_PER_MB, 1000) / 1000;
+}
+
+/*
  * Command: GET_MBOX_INFO
  * Get the API version, default window size and block size
  * We also set the LPC mapping to point to the reserved memory region here so
@@ -229,6 +243,7 @@
 	}
 	if (context->version >= API_VERSION_2) {
 		resp->args[5] = context->block_size_shift;
+		put_u16(&resp->args[6], get_suggested_timeout(context));
 	}
 
 	return 0;