Commit 21c13a4f7bc185552c4b402b792c3bbb9aa69df0
Committed by
Greg Kroah-Hartman
1 parent
3af51ac9c0
Exists in
master
and in
20 other branches
usb-storage: redo incorrect reads
Some USB mass-storage devices have bugs that cause them not to handle the first READ(10) command they receive correctly. The Corsair Padlock v2 returns completely bogus data for its first read (possibly it returns the data in encrypted form even though the device is supposed to be unlocked). The Feiya SD/SDHC card reader fails to complete the first READ(10) command after it is plugged in or after a new card is inserted, returning a status code that indicates it thinks the command was invalid, which prevents the kernel from retrying the read. Since the first read of a new device or a new medium is for the partition sector, the kernel is unable to retrieve the device's partition table. Users have to manually issue an "hdparm -z" or "blockdev --rereadpt" command before they can access the device. This patch (as1470) works around the problem. It adds a new quirk flag, US_FL_INVALID_READ10, indicating that the first READ(10) should always be retried immediately, as should any failing READ(10) commands (provided the preceding READ(10) command succeeded, to avoid getting stuck in a loop). The patch also adds appropriate unusual_devs entries containing the new flag. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Tested-by: Sven Geggus <sven-usbst@geggus.net> Tested-by: Paul Hartman <paul.hartman+linux@gmail.com> CC: Matthew Dharm <mdharm-usb@one-eyed-alien.net> CC: <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 6 changed files with 67 additions and 2 deletions Side-by-side Diff
Documentation/kernel-parameters.txt
... | ... | @@ -2598,6 +2598,8 @@ |
2598 | 2598 | unlock ejectable media); |
2599 | 2599 | m = MAX_SECTORS_64 (don't transfer more |
2600 | 2600 | than 64 sectors = 32 KB at a time); |
2601 | + n = INITIAL_READ10 (force a retry of the | |
2602 | + initial READ(10) command); | |
2601 | 2603 | o = CAPACITY_OK (accept the capacity |
2602 | 2604 | reported by the device); |
2603 | 2605 | r = IGNORE_RESIDUE (the device reports |
drivers/usb/storage/transport.c
... | ... | @@ -819,6 +819,35 @@ |
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | + /* | |
823 | + * Some devices don't work or return incorrect data the first | |
824 | + * time they get a READ(10) command, or for the first READ(10) | |
825 | + * after a media change. If the INITIAL_READ10 flag is set, | |
826 | + * keep track of whether READ(10) commands succeed. If the | |
827 | + * previous one succeeded and this one failed, set the REDO_READ10 | |
828 | + * flag to force a retry. | |
829 | + */ | |
830 | + if (unlikely((us->fflags & US_FL_INITIAL_READ10) && | |
831 | + srb->cmnd[0] == READ_10)) { | |
832 | + if (srb->result == SAM_STAT_GOOD) { | |
833 | + set_bit(US_FLIDX_READ10_WORKED, &us->dflags); | |
834 | + } else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) { | |
835 | + clear_bit(US_FLIDX_READ10_WORKED, &us->dflags); | |
836 | + set_bit(US_FLIDX_REDO_READ10, &us->dflags); | |
837 | + } | |
838 | + | |
839 | + /* | |
840 | + * Next, if the REDO_READ10 flag is set, return a result | |
841 | + * code that will cause the SCSI core to retry the READ(10) | |
842 | + * command immediately. | |
843 | + */ | |
844 | + if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) { | |
845 | + clear_bit(US_FLIDX_REDO_READ10, &us->dflags); | |
846 | + srb->result = DID_IMM_RETRY << 16; | |
847 | + srb->sense_buffer[0] = 0; | |
848 | + } | |
849 | + } | |
850 | + | |
822 | 851 | /* Did we transfer less than the minimum amount required? */ |
823 | 852 | if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) && |
824 | 853 | scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) |
drivers/usb/storage/unusual_devs.h
... | ... | @@ -1114,6 +1114,16 @@ |
1114 | 1114 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
1115 | 1115 | US_FL_FIX_CAPACITY ), |
1116 | 1116 | |
1117 | +/* Reported by Paul Hartman <paul.hartman+linux@gmail.com> | |
1118 | + * This card reader returns "Illegal Request, Logical Block Address | |
1119 | + * Out of Range" for the first READ(10) after a new card is inserted. | |
1120 | + */ | |
1121 | +UNUSUAL_DEV( 0x090c, 0x6000, 0x0100, 0x0100, | |
1122 | + "Feiya", | |
1123 | + "SD/SDHC Card Reader", | |
1124 | + USB_SC_DEVICE, USB_PR_DEVICE, NULL, | |
1125 | + US_FL_INITIAL_READ10 ), | |
1126 | + | |
1117 | 1127 | /* This Pentax still camera is not conformant |
1118 | 1128 | * to the USB storage specification: - |
1119 | 1129 | * - It does not like the INQUIRY command. So we must handle this command |
... | ... | @@ -1887,6 +1897,15 @@ |
1887 | 1897 | "Photo Frame", |
1888 | 1898 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
1889 | 1899 | US_FL_NO_READ_DISC_INFO ), |
1900 | + | |
1901 | +/* Reported by Sven Geggus <sven-usbst@geggus.net> | |
1902 | + * This encrypted pen drive returns bogus data for the initial READ(10). | |
1903 | + */ | |
1904 | +UNUSUAL_DEV( 0x1b1c, 0x1ab5, 0x0200, 0x0200, | |
1905 | + "Corsair", | |
1906 | + "Padlock v2", | |
1907 | + USB_SC_DEVICE, USB_PR_DEVICE, NULL, | |
1908 | + US_FL_INITIAL_READ10 ), | |
1890 | 1909 | |
1891 | 1910 | /* Patch by Richard Schütz <r.schtz@t-online.de> |
1892 | 1911 | * This external hard drive enclosure uses a JMicron chip which |
drivers/usb/storage/usb.c
... | ... | @@ -440,7 +440,8 @@ |
440 | 440 | US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | |
441 | 441 | US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | |
442 | 442 | US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT | |
443 | - US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16); | |
443 | + US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | | |
444 | + US_FL_INITIAL_READ10); | |
444 | 445 | |
445 | 446 | p = quirks; |
446 | 447 | while (*p) { |
... | ... | @@ -490,6 +491,9 @@ |
490 | 491 | case 'm': |
491 | 492 | f |= US_FL_MAX_SECTORS_64; |
492 | 493 | break; |
494 | + case 'n': | |
495 | + f |= US_FL_INITIAL_READ10; | |
496 | + break; | |
493 | 497 | case 'o': |
494 | 498 | f |= US_FL_CAPACITY_OK; |
495 | 499 | break; |
... | ... | @@ -952,6 +956,13 @@ |
952 | 956 | result = get_pipes(us); |
953 | 957 | if (result) |
954 | 958 | goto BadDevice; |
959 | + | |
960 | + /* | |
961 | + * If the device returns invalid data for the first READ(10) | |
962 | + * command, indicate the command should be retried. | |
963 | + */ | |
964 | + if (us->fflags & US_FL_INITIAL_READ10) | |
965 | + set_bit(US_FLIDX_REDO_READ10, &us->dflags); | |
955 | 966 | |
956 | 967 | /* Acquire all the other resources and add the host */ |
957 | 968 | result = usb_stor_acquire_resources(us); |
drivers/usb/storage/usb.h
... | ... | @@ -73,6 +73,8 @@ |
73 | 73 | #define US_FLIDX_RESETTING 4 /* device reset in progress */ |
74 | 74 | #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ |
75 | 75 | #define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */ |
76 | +#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */ | |
77 | +#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */ | |
76 | 78 | |
77 | 79 | #define USB_STOR_STRING_LEN 32 |
78 | 80 |
include/linux/usb_usual.h
... | ... | @@ -62,7 +62,9 @@ |
62 | 62 | US_FLAG(NO_READ_DISC_INFO, 0x00040000) \ |
63 | 63 | /* cannot handle READ_DISC_INFO */ \ |
64 | 64 | US_FLAG(NO_READ_CAPACITY_16, 0x00080000) \ |
65 | - /* cannot handle READ_CAPACITY_16 */ | |
65 | + /* cannot handle READ_CAPACITY_16 */ \ | |
66 | + US_FLAG(INITIAL_READ10, 0x00100000) \ | |
67 | + /* Initial READ(10) (and others) must be retried */ | |
66 | 68 | |
67 | 69 | #define US_FLAG(name, value) US_FL_##name = value , |
68 | 70 | enum { US_DO_ALL_FLAGS }; |