[PATCH] test: usb: storage: Increase retries for usb_stor_transport()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This should make writing and reading more reliable.

Also:
- change loop condition to make "retries" semantically correct
- add a debug message in case of fatal failure
---
And here is the test for how many retries were required at maximum. In case
anyone wants to try for themselves.

barebox:/ usb && mkdir /mnt/usb && mount /dev/disk0.0 /mnt/usb && echo 'generating 100MiB file' && memcpy -s /dev/prng -d testfile 0x0 0x0 104857600 && echo 'writing file to drive' && cp testfile /mnt/usb/testfile && md5sum testfile /mnt/usb/testfile; ls -l testfile /mnt/usb/testfile

The highest max_retries for our three drives was 4. So 10 should be high enough.

 drivers/usb/storage/usb.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 63d624e..90e4492 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -86,9 +86,13 @@ static int usb_stor_transport(struct us_blk_dev *usb_blkdev,
 	struct us_data *us = usb_blkdev->us;
 	struct device_d *dev = &us->pusb_dev->dev;
 	int i, ret;
+	static int max_retries = 0;
 
-
-	for (i = 0; i < retries; i++) {
+	for (i = 0; i <= retries; i++) {
+		if (cmd[0] == SCSI_WRITE10 && i > max_retries) {
+			max_retries = i;
+			printf("max_retries = %d\n", max_retries);
+		}
 		dev_dbg(dev, "%s\n", usb_stor_opcode_name(cmd[0]));
 		ret = us->transport(usb_blkdev, cmd, cmdlen, data, datalen);
 		dev_dbg(dev, "%s returns %d\n", usb_stor_opcode_name(cmd[0]),
@@ -105,6 +109,8 @@ static int usb_stor_transport(struct us_blk_dev *usb_blkdev,
 			mdelay(request_sense_delay_ms);
 	}
 
+	dev_dbg(dev, "Retried %s %d times, and failed.\n", usb_stor_opcode_name(cmd[0]), retries);
+
 	return -EIO;
 }
 
@@ -194,7 +200,7 @@ static int usb_stor_io_10(struct us_blk_dev *usb_blkdev, u8 opcode,
 	put_unaligned_be16(blocks, &cmd[7]);
 
 	return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data,
-				  blocks * SECTOR_SIZE, 2, 0);
+				  blocks * SECTOR_SIZE, 100, 0);
 }
 
 /***********************************************************************
-- 
2.7.4


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux