Re: External USB3 disk fails with "Invalid field in cdb"

134 views
Skip to first unread message

Alan Stern

unread,
Jun 27, 2014, 2:42:03 PM6/27/14
to Michael Büsch, James Bottomley, Bryn M. Reeves, linux...@vger.kernel.org, linu...@vger.kernel.org, usb-s...@lists.one-eyed-alien.net
On Fri, 27 Jun 2014, Michael Büsch wrote:

> On Fri, 27 Jun 2014 08:48:01 -0700
> James Bottomley <James.B...@HansenPartnership.com> wrote:
>
> > On Fri, 2014-06-27 at 17:34 +0200, Michael Büsch wrote:
> > > I tried the following patch:
> > >
> > > Index: linux/drivers/scsi/sd.c
> > > ===================================================================
> > > --- linux.orig/drivers/scsi/sd.c 2014-06-26 18:40:39.214696552 +0200
> > > +++ linux/drivers/scsi/sd.c 2014-06-27 15:52:30.776159456 +0200
> > > @@ -2440,7 +2440,7 @@ sd_read_cache_type(struct scsi_disk *sdk
> > > sdkp->RCD = 0;
> > > }
> > >
> > > - sdkp->DPOFUA = (data.device_specific & 0x10) != 0;
> > > + sdkp->DPOFUA = 0;
> > > if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw) {
> > > sd_first_printk(KERN_NOTICE, sdkp,
> > > "Uses READ/WRITE(6), disabling FUA\n");
> > >
> > >
> > > This obviously is not the correct thing to do, but it makes the disk usable:
> > >
> > > Jun 27 17:26:50 marge kernel: [ 523.909815] usb 2-1: new SuperSpeed USB device number 2 using xhci_hcd
> > > Jun 27 17:26:50 marge kernel: [ 523.929246] usb 2-1: New USB device found, idVendor=152d, idProduct=0567
> > > Jun 27 17:26:50 marge kernel: [ 523.929258] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
> > > Jun 27 17:26:50 marge kernel: [ 523.929265] usb 2-1: Product: USB to ATA/ATAPI Bridge
> > > Jun 27 17:26:50 marge kernel: [ 523.929271] usb 2-1: Manufacturer: JMicron
> > > Jun 27 17:26:50 marge kernel: [ 523.929276] usb 2-1: SerialNumber: xxx
> > > Jun 27 17:26:50 marge kernel: [ 523.930999] usb-storage 2-1:1.0: USB Mass Storage device detected
> > > Jun 27 17:26:50 marge kernel: [ 523.931237] scsi12 : usb-storage 2-1:1.0
> > > Jun 27 17:26:51 marge kernel: [ 524.930451] scsi 12:0:0:0: Direct-Access JMicron Generic 0114 PQ: 0 ANSI: 6
> > > Jun 27 17:26:51 marge kernel: [ 524.931228] sd 12:0:0:0: Attached scsi generic sg3 type 0
> > > Jun 27 17:26:51 marge kernel: [ 524.932964] sd 12:0:0:0: [sdd] Spinning up disk...
> > > Jun 27 17:26:53 marge kernel: [ 525.937848] ..ready
> > > Jun 27 17:26:53 marge kernel: [ 526.942395] sd 12:0:0:0: [sdd] 976773168 512-byte logical blocks: (500 GB/465 GiB)
> > > Jun 27 17:26:53 marge kernel: [ 526.943037] sd 12:0:0:0: [sdd] Write Protect is off
> > > Jun 27 17:26:53 marge kernel: [ 526.943048] sd 12:0:0:0: [sdd] Mode Sense: 47 00 10 08
> > > Jun 27 17:26:53 marge kernel: [ 526.943662] sd 12:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
> > > Jun 27 17:26:53 marge kernel: [ 526.987919] sdd: sdd1
> > > Jun 27 17:26:53 marge kernel: [ 526.990055] sd 12:0:0:0: [sdd] Attached SCSI disk
> > > Jun 27 17:27:29 marge kernel: [ 563.227849] EXT4-fs (sdd1): warning: mounting fs with errors, running e2fsck is recommended
> > > Jun 27 17:27:29 marge kernel: [ 563.228043] EXT4-fs (sdd1): mounted filesystem with ordered data mode. Opts: (null)
> > >
> > > (This is on another machine, but it shows the same behavior without the patch.)
> > >
> > > Does somebody have a hint for a real fix?
> >
> > I suspect the problem is in the USB bridge: The device reports FUA
> > support in its initial IDENTIFY, which gets translated to the correct
> > mode page bits, but when we send a READ/WRITE with the FUA bit set, the
> > bridge doesn't know how to translate it and gives us the error. There's
> > probably some way in USB to blacklist the bridge, but we need to
> > understand the consequences of the blacklist: The device is claiming a
> > writeback cache which means if it won't do either FUA or SYNC CACHE,
> > there's going to be a data integrity failure.
> >
> > The fact that your initial hack works suggests that sync cache is
> > accepted by it, so we probably just need a USB blacklist fixing the FUA
> > problem.

Michael, can you post the "lsusb -v" output for this device? I see it
is made by JMicron; they are notorious for buggy USB-ATA bridges.

Alan Stern

Michael Büsch

unread,
Jun 27, 2014, 2:59:23 PM6/27/14
to Alan Stern, James Bottomley, Bryn M. Reeves, linux...@vger.kernel.org, linu...@vger.kernel.org, usb-s...@lists.one-eyed-alien.net
On Fri, 27 Jun 2014 14:42:01 -0400 (EDT)
Alan Stern <st...@rowland.harvard.edu> wrote:

> Michael, can you post the "lsusb -v" output for this device? I see it
> is made by JMicron; they are notorious for buggy USB-ATA bridges.

Of course. Here you go:

Bus 004 Device 009: ID 152d:0567 JMicron Technology Corp. / JMicron USA Technology Corp.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 3.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 9
idVendor 0x152d JMicron Technology Corp. / JMicron USA Technology Corp.
idProduct 0x0567
bcdDevice 1.14
iManufacturer 1 JMicron
iProduct 2 USB to ATA/ATAPI Bridge
iSerial 3 xxx
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 121
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 4 USB Mass Storage
bmAttributes 0xc0
Self Powered
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk-Only
iInterface 6 MSC Bulk-Only Transport
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 15
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 15
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 1
bNumEndpoints 4
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 98
iInterface 10 MSC USB Attached SCSI
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 0
Command pipe (0x01)
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 0
MaxStreams 16
Status pipe (0x02)
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 15
MaxStreams 16
Data-in pipe (0x03)
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x04 EP 4 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 0
bMaxBurst 15
MaxStreams 16
Data-out pipe (0x04)
Binary Object Store Descriptor:
bLength 5
bDescriptorType 15
wTotalLength 22
bNumDeviceCaps 2
USB 2.0 Extension Device Capability:
bLength 7
bDescriptorType 16
bDevCapabilityType 2
bmAttributes 0x00000002
Link Power Management (LPM) Supported
SuperSpeed USB Device Capability:
bLength 10
bDescriptorType 16
bDevCapabilityType 3
bmAttributes 0x00
wSpeedsSupported 0x000e
Device can operate at Full Speed (12Mbps)
Device can operate at High Speed (480Mbps)
Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport 1
Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat 10 micro seconds
bU2DevExitLat 32 micro seconds
Device Status: 0x000d
Self Powered
U1 Enabled
U2 Enabled



MaxPower=2mA is a nice guess for a hard disk. ;)

--
Michael
signature.asc

Michael Büsch

unread,
Jun 27, 2014, 2:59:23 PM6/27/14
to James Bottomley, Bryn M. Reeves, linux...@vger.kernel.org, linu...@vger.kernel.org, usb-s...@lists.one-eyed-alien.net
[Added USB lists to Cc]


--
Michael
signature.asc

Alan Stern

unread,
Jun 27, 2014, 3:23:44 PM6/27/14
to Michael Büsch, James Bottomley, Bryn M. Reeves, SCSI development list, USB list, USB Storage list
On Fri, 27 Jun 2014, Michael Büsch wrote:

...

> MaxPower=2mA is a nice guess for a hard disk. ;)

That refers to the amount of power the device draws from the USB bus.
Since the disk drive is self-powered, it doesn't use much bus power.

Does the patch below do what you and James want?

Alan Stern



Index: usb-3.16/include/linux/usb_usual.h
===================================================================
--- usb-3.16.orig/include/linux/usb_usual.h
+++ usb-3.16/include/linux/usb_usual.h
@@ -70,7 +70,9 @@
US_FLAG(NEEDS_CAP16, 0x00400000) \
/* cannot handle READ_CAPACITY_10 */ \
US_FLAG(IGNORE_UAS, 0x00800000) \
- /* Device advertises UAS but it is broken */
+ /* Device advertises UAS but it is broken */ \
+ US_FLAG(BROKEN_FUA, 0x01000000) \
+ /* Cannot handle FUA in WRITE CDBs */ \

#define US_FLAG(name, value) US_FL_##name = value ,
enum { US_DO_ALL_FLAGS };
Index: usb-3.16/include/scsi/scsi_device.h
===================================================================
--- usb-3.16.orig/include/scsi/scsi_device.h
+++ usb-3.16/include/scsi/scsi_device.h
@@ -173,6 +173,7 @@ struct scsi_device {
unsigned is_visible:1; /* is the device visible in sysfs */
unsigned wce_default_on:1; /* Cache is ON by default */
unsigned no_dif:1; /* T10 PI (DIF) should be disabled */
+ unsigned broken_fua:1; /* Don't set FUA bit */

atomic_t disk_events_disable_depth; /* disable depth for disk events */

Index: usb-3.16/drivers/usb/storage/unusual_devs.h
===================================================================
--- usb-3.16.orig/drivers/usb/storage/unusual_devs.h
+++ usb-3.16/drivers/usb/storage/unusual_devs.h
@@ -1936,6 +1936,13 @@ UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x
USB_SC_DEVICE, USB_PR_DEVICE, NULL,
US_FL_IGNORE_RESIDUE ),

+/* Reported by Michael Büsch <m...@bues.ch> */
+UNUSUAL_DEV( 0x152d, 0x0567, 0x0114, 0x0114,
+ "JMicron",
+ "USB to ATA/ATAPI Bridge",
+ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
+ US_FL_BROKEN_FUA ),
+
/* Reported by Alexandre Oliva <ol...@lsd.ic.unicamp.br>
* JMicron responds to USN and several other SCSI ioctls with a
* residue that causes subsequent I/O requests to fail. */
Index: usb-3.16/drivers/usb/storage/scsiglue.c
===================================================================
--- usb-3.16.orig/drivers/usb/storage/scsiglue.c
+++ usb-3.16/drivers/usb/storage/scsiglue.c
@@ -256,6 +256,10 @@ static int slave_configure(struct scsi_d
if (us->fflags & US_FL_WRITE_CACHE)
sdev->wce_default_on = 1;

+ /* A few buggy USB-ATA bridges don't understand FUA */
+ if (us->fflags & US_FL_BROKEN_FUA)
+ sdev->broken_fua = 1;
+
} else {

/* Non-disk-type devices don't need to blacklist any pages
Index: usb-3.16/drivers/scsi/sd.c
===================================================================
--- usb-3.16.orig/drivers/scsi/sd.c
+++ usb-3.16/drivers/scsi/sd.c
@@ -2441,7 +2441,10 @@ sd_read_cache_type(struct scsi_disk *sdk
}

sdkp->DPOFUA = (data.device_specific & 0x10) != 0;
- if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw) {
+ if (sdp->broken_fua) {
+ sd_first_printk(KERN_NOTICE, sdkp, "Disabling FUA\n");
+ sdkp->DPOFUA = 0;
+ } else if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw) {
sd_first_printk(KERN_NOTICE, sdkp,
"Uses READ/WRITE(6), disabling FUA\n");
sdkp->DPOFUA = 0;

Michael Büsch

unread,
Jun 27, 2014, 3:54:53 PM6/27/14
to Alan Stern, James Bottomley, Bryn M. Reeves, SCSI development list, USB list, USB Storage list
On Fri, 27 Jun 2014 15:23:42 -0400 (EDT)
Alan Stern <st...@rowland.harvard.edu> wrote:

> > MaxPower=2mA is a nice guess for a hard disk. ;)
>
> That refers to the amount of power the device draws from the USB bus.
> Since the disk drive is self-powered, it doesn't use much bus power.

Unless the device uses free energy or some other perpetual motion power source,
it seems that it actually is bus-powered.
So the self-powered from the descriptor is a lie, too.

> Does the patch below do what you and James want?

Yes, this does work. Thanks!

You can add my
Tested-by: Michael Büsch <m...@bues.ch>

--
Michael
signature.asc

Michael Büsch

unread,
Jun 30, 2014, 9:56:38 AM6/30/14
to Alan Stern, James Bottomley, Bryn M. Reeves, SCSI development list, USB list, USB Storage list
Does somebody pick this up for inclusion?
It'd also be good, if this hit stable.


--
Michael
signature.asc

James Bottomley

unread,
Jun 30, 2014, 10:12:45 AM6/30/14
to Alan Stern, Michael Büsch, Bryn M. Reeves, SCSI development list, USB list, USB Storage list
Yes, that's the usual annoying additions to our blacklist. You can add
my acked-by and could you cc stable?

Thanks,

James



Alan Stern

unread,
Jun 30, 2014, 10:27:41 AM6/30/14
to James Bottomley, Michael Büsch, Bryn M. Reeves, SCSI development list, USB list, USB Storage list
On Mon, 30 Jun 2014, James Bottomley wrote:

> > Does the patch below do what you and James want?
>
> Yes, that's the usual annoying additions to our blacklist. You can add
> my acked-by and could you cc stable?

Will do.

Alan Stern

Alan Stern

unread,
Jun 30, 2014, 11:04:23 AM6/30/14
to Michael Büsch, James Bottomley, Bryn M. Reeves, Matthew Dharm, SCSI development list, USB list, USB Storage list
Some buggy JMicron USB-ATA bridges don't know how to translate the FUA
bit in READs or WRITEs. This patch adds an entry in unusual_devs.h
and a blacklist flag to tell the sd driver not to use FUA.

Signed-off-by: Alan Stern <st...@rowland.harvard.edu>
Reported-by: Michael Büsch <m...@bues.ch>
Tested-by: Michael Büsch <m...@bues.ch>
Acked-by: James Bottomley <James.B...@HansenPartnership.com>
CC: Matthew Dharm <mdhar...@one-eyed-alien.net>
CC: <sta...@vger.kernel.org>

---


[as1751]


drivers/scsi/sd.c | 5 ++++-
drivers/usb/storage/scsiglue.c | 4 ++++
drivers/usb/storage/unusual_devs.h | 7 +++++++
include/linux/usb_usual.h | 4 +++-
include/scsi/scsi_device.h | 1 +
5 files changed, 19 insertions(+), 2 deletions(-)

Index: usb-3.16/include/linux/usb_usual.h
===================================================================
--- usb-3.16.orig/include/linux/usb_usual.h
+++ usb-3.16/include/linux/usb_usual.h
@@ -70,7 +70,9 @@
US_FLAG(NEEDS_CAP16, 0x00400000) \
/* cannot handle READ_CAPACITY_10 */ \
US_FLAG(IGNORE_UAS, 0x00800000) \
- /* Device advertises UAS but it is broken */
+ /* Device advertises UAS but it is broken */ \
+ US_FLAG(BROKEN_FUA, 0x01000000) \
+ /* Cannot handle FUA in WRITE or READ CDBs */ \

Alan Stern

unread,
Jun 30, 2014, 11:16:52 AM6/30/14
to Greg KH, Michael Büsch, James Bottomley, Bryn M. Reeves, Matthew Dharm, SCSI development list, USB list, USB Storage list
On Mon, 30 Jun 2014, Alan Stern wrote:

> Some buggy JMicron USB-ATA bridges don't know how to translate the FUA
> bit in READs or WRITEs. This patch adds an entry in unusual_devs.h
> and a blacklist flag to tell the sd driver not to use FUA.
>
> Signed-off-by: Alan Stern <st...@rowland.harvard.edu>
> Reported-by: Michael Büsch <m...@bues.ch>
> Tested-by: Michael Büsch <m...@bues.ch>
> Acked-by: James Bottomley <James.B...@HansenPartnership.com>
> CC: Matthew Dharm <mdhar...@one-eyed-alien.net>
> CC: <sta...@vger.kernel.org>

Greg:

I forgot to add your name to the recipient list on this patch. Since
James has already Ack'ed it, would you like to take it for your USB
tree?

Alan Stern

Greg KH

unread,
Jun 30, 2014, 1:48:09 PM6/30/14
to Alan Stern, Michael Büsch, James Bottomley, Bryn M. Reeves, Matthew Dharm, SCSI development list, USB list, USB Storage list
Sure, I can take it, thanks.

greg k-h
Reply all
Reply to author
Forward
0 new messages