mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] usb: storage: increase init retry count to support lengthy HDD spin up
@ 2021-03-01 11:07 Ahmad Fatoum
  2021-03-01 15:57 ` Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-03-01 11:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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. By increasing the retry count
during initialization, this workaround is no longer necessary.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/storage/usb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index b417640186a2..7b0aecd757b0 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -141,7 +141,7 @@ 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, int retries)
 {
 	u8 cmd[6];
 	int ret;
@@ -150,7 +150,7 @@ static int usb_stor_test_unit_ready(struct us_blk_dev *usb_blkdev)
 	cmd[0] = SCSI_TST_U_RDY;
 
 	ret = usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), NULL, 0,
-				 10, 100);
+				 retries, 100);
 	if (ret < 0)
 		return -ENODEV;
 
@@ -282,7 +282,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, 10)) {
 		dev_dbg(dev, "Device NOT ready\n");
 		return -EIO;
 	}
@@ -365,7 +365,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, 60);
 	if (result) {
 		dev_dbg(dev, "Device NOT ready\n");
 		return result;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: storage: increase init retry count to support lengthy HDD spin up
  2021-03-01 11:07 [PATCH] usb: storage: increase init retry count to support lengthy HDD spin up Ahmad Fatoum
@ 2021-03-01 15:57 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2021-03-01 15:57 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox

Hi,

On 01.03.21 12:07, Ahmad Fatoum wrote:
> 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. By increasing the retry count
> during initialization, this workaround is no longer necessary.

Please dismiss for now. This doesn't always work, even for my HDD.



> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/usb/storage/usb.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
> index b417640186a2..7b0aecd757b0 100644
> --- a/drivers/usb/storage/usb.c
> +++ b/drivers/usb/storage/usb.c
> @@ -141,7 +141,7 @@ 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, int retries)
>  {
>  	u8 cmd[6];
>  	int ret;
> @@ -150,7 +150,7 @@ static int usb_stor_test_unit_ready(struct us_blk_dev *usb_blkdev)
>  	cmd[0] = SCSI_TST_U_RDY;
>  
>  	ret = usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), NULL, 0,
> -				 10, 100);
> +				 retries, 100);
>  	if (ret < 0)
>  		return -ENODEV;
>  
> @@ -282,7 +282,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, 10)) {
>  		dev_dbg(dev, "Device NOT ready\n");
>  		return -EIO;
>  	}
> @@ -365,7 +365,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, 60);
>  	if (result) {
>  		dev_dbg(dev, "Device NOT ready\n");
>  		return result;
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-01 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 11:07 [PATCH] usb: storage: increase init retry count to support lengthy HDD spin up Ahmad Fatoum
2021-03-01 15:57 ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox