libpayload: Increase accuracy of timeout period for media init.

When bringing up media, we claim to wait for up to 30 seconds for a
device to respond to our TEST_UNIT_READY command. Actually, we can wait
far longer because we do not take into account execution delay.

To improve timeout accuracy, make use of gettimeofday(), which calculates
time based upon a CPU counter. This improves the user experience
slightly when certain non-working USB devices are used.

Change-Id: Id9605ecfc0a522d7a0b039fd8eac541232605082
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/169208
Reviewed-by: Julius Werner <jwerner@chromium.org>
(cherry picked from commit 1d3d535db83ff478c512e37f37015b43927b3efc)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6646
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Shawn Nematbakhsh
2013-09-12 18:09:39 -07:00
committed by Isaac Christensen
parent 6ada053709
commit 7ecc912b32

View File

@@ -537,22 +537,26 @@ static void
usb_msc_test_unit_ready (usbdev_t *dev) usb_msc_test_unit_ready (usbdev_t *dev)
{ {
int i; int i;
time_t start_time_secs;
struct timeval tv;
/* SCSI/ATA specs say we have to wait up to 30s. Ugh */ /* SCSI/ATA specs say we have to wait up to 30s. Ugh */
const int timeout = 30 * 10; const int timeout_secs = 30;
usb_debug (" Waiting for device to become ready..."); usb_debug (" Waiting for device to become ready...");
/* Initially mark the device ready. */ /* Initially mark the device ready. */
usb_msc_mark_ready (dev); usb_msc_mark_ready (dev);
gettimeofday (&tv, NULL);
start_time_secs = tv.tv_sec;
for (i = 0; i < timeout; i++) { while (tv.tv_sec - start_time_secs < timeout_secs) {
switch (test_unit_ready (dev)) { switch (test_unit_ready (dev)) {
case MSC_COMMAND_OK: case MSC_COMMAND_OK:
break; break;
case MSC_COMMAND_FAIL: case MSC_COMMAND_FAIL:
mdelay (100); mdelay (100);
if (!(timeout % 10)) usb_debug (".");
usb_debug ("."); gettimeofday (&tv, NULL);
continue; continue;
default: default:
usb_debug ("detached. Device not ready.\n"); usb_debug ("detached. Device not ready.\n");
@@ -561,7 +565,7 @@ usb_msc_test_unit_ready (usbdev_t *dev)
} }
break; break;
} }
if (i >= timeout) { if (!(tv.tv_sec - start_time_secs < timeout_secs)) {
usb_debug ("timeout. Device not ready.\n"); usb_debug ("timeout. Device not ready.\n");
usb_msc_mark_not_ready (dev); usb_msc_mark_not_ready (dev);
} }