WIP: DHCP: Wait for a response for 10 seconds instead of the polling delay.

Instead of assuming the amount of time spend waiting for the network device
to respond is an adequate timeout, wait for a fixed amount of time, currently
set to 10 seconds, before resending the request.

This code is untested other than making sure it compiles.

BUG=chrome-os-partner:20861
TEST=Compiled for falco.
BRANCH=None

Original-Change-Id: If99a936464e74977cf20f605c26642797246b7ae
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/62219
Commit-Queue: Bowgo Tsai <bowgotsai@chromium.org>
Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
Reviewed-by: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 95fe79870ea918d6c7cdef6fedd1c3a14284f79b)

Change-Id: If20a425e073e68c52814b3c9a88d6a2750038484
Reviewed-on: https://gerrit.chromium.org/gerrit/65114
Commit-Queue: Bowgo Tsai <bowgotsai@chromium.org>
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
diff --git a/src/netboot/dhcp.c b/src/netboot/dhcp.c
index 93da272..578c88c 100644
--- a/src/netboot/dhcp.c
+++ b/src/netboot/dhcp.c
@@ -24,6 +24,7 @@
 #include <endian.h>
 #include <libpayload.h>
 
+#include "base/time.h"
 #include "drivers/net/net.h"
 #include "net/net.h"
 #include "net/uip.h"
@@ -45,6 +46,9 @@
 static const uint16_t DhcpServerPort = 67;
 static const uint16_t DhcpClientPort = 68;
 
+// Wait for a response for 10 seconds before resending a request.
+static const uint64_t DhcpRespTimeoutUs = 10 * 1000 * 1000;
+
 typedef struct __attribute__((packed)) DhcpPacket
 {
 	uint8_t opcode;
@@ -373,7 +377,11 @@
 	// Poll network driver until we get a reply. Resend periodically.
 	net_set_callback(&dhcp_callback);
 	for (;;) {
-		net_poll();
+		uint64_t start = timer_us(0);
+		do {
+			net_poll();
+		} while (!dhcp_in_ready &&
+			 timer_us(start) < DhcpRespTimeoutUs);
 		if (dhcp_in_ready)
 			break;
 		// No response, try again.