summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-04-16 19:26:46 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-07 10:09:19 +0200
commit6f9fdf6b34cf45bedae92f9b02c0df8df5098037 (patch)
treec4303d342a2de9101ec87bfebb327fe5ce0308c8 /drivers
parent623c72a9c6bb79b6084946f1efe3b1358766f52f (diff)
downloadbarebox-6f9fdf6b34cf45bedae92f9b02c0df8df5098037.tar.gz
barebox-6f9fdf6b34cf45bedae92f9b02c0df8df5098037.tar.xz
usb: storage: retry for up to 10s on lengthy HDD spin up
Some USB disks take notoriously long to spin up. They are seen by a bus scan, but they report ready only after a few seconds have passed. This is not a problem if vbus is enabled early on, so devices have had a chance to spin up. If vbus is first enabled as part of the usb scan, not enough time might have passed for the USB disk to be usable. This issue was observed on an i.MX6QP with following topology: usb: USB: scanning bus for devices... usb: 5 USB Device(s) found 1 ID 0000:0000 | u-boot EHCI Host Controller | +-2 ID 0424:2517 | +-5 ID 1058:2621 | Western Digital Elements 2621 ... Unplugging and replugging the USB disk and doing a second usb scan made the unit ready test succeed. Increasing the retry count during initialization has negative consequences for other cases, like when a device is unplugged while being probed (which already takes way too long). Instead, just for the case of a detected USB mass storage device that couldn't get ready initially: retry for 10s at initialization time before giving up. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210416172646.26834-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/storage/usb.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index b417640186..b0f789b42a 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -141,20 +141,23 @@ exit:
return ret;
}
-static int usb_stor_test_unit_ready(struct us_blk_dev *usb_blkdev)
+static int usb_stor_test_unit_ready(struct us_blk_dev *usb_blkdev, u64 timeout_ns)
{
+ u64 start;
u8 cmd[6];
int ret;
memset(cmd, 0, sizeof(cmd));
cmd[0] = SCSI_TST_U_RDY;
- ret = usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), NULL, 0,
- 10, 100);
- if (ret < 0)
- return -ENODEV;
+ start = get_time_ns();
- return 0;
+ do {
+ ret = usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), NULL, 0,
+ 10, 100);
+ } while (ret < 0 && !is_timeout(start, timeout_ns));
+
+ return ret ? -ENODEV : 0;
}
static int read_capacity_16(struct us_blk_dev *usb_blkdev)
@@ -282,7 +285,7 @@ static int usb_stor_blk_io(struct block_device *disk_dev,
/* ensure unit ready */
dev_dbg(dev, "Testing for unit ready\n");
- if (usb_stor_test_unit_ready(pblk_dev)) {
+ if (usb_stor_test_unit_ready(pblk_dev, 0)) {
dev_dbg(dev, "Device NOT ready\n");
return -EIO;
}
@@ -365,7 +368,8 @@ static int usb_stor_init_blkdev(struct us_blk_dev *pblk_dev)
/* ensure unit ready */
dev_dbg(dev, "Testing for unit ready\n");
- result = usb_stor_test_unit_ready(pblk_dev);
+ /* retry a bit longer than usual as some HDDs take longer to spin up */
+ result = usb_stor_test_unit_ready(pblk_dev, 10ULL * NSEC_PER_SEC);
if (result) {
dev_dbg(dev, "Device NOT ready\n");
return result;