scsi/sr: add no_read_disc_info scsi_device flag
Subsystems (3)
PATCH RESEND 1/4 scsi/sr: add no_read_disc_info scsi_device flag
Some USB devices emulate a usb-mass-storage attached (scsi) cdrom device, usually this fake cdrom contains the windows software for the device. While working on supporting Appotech ax3003 based photoframes, which do this I discovered that they will go of into lala land when ever they see a READ_DISC_INFO scsi command.
Thus this patch adds a scsi_device flag (which can then be set by the usb-storage driver through an unsual-devs entry), to indicate this, and makes the sr driver honor this flag.
I know this sucks, but as discussed on linux-scsi list there is no other way to make this device work properly.
Looking at usb traces made under windows, windows never sends a READ_DISC_INFO during normal interactions with a usb cdrom device. So as this cdrom emulation thingie becomes more common we might see more of this problem.
--- drivers/scsi/sr.c | 8 +++++++- include/scsi/scsi_device.h | 1 + 2 files changed, 8 insertions(+), 1 deletions(-)
drivers/scsi/sr.c +7 -1
@@ -849,10 +849,16 @@ static void get_capabilities(struct scsi_cd *cd)static int sr_packet (struct cdrom_device_info *cdi,struct packet_command *cgc) { +struct scsi_cd *cd = cdi->handle; +struct scsi_device *sdev = cd->device; + +if (cgc->cmd[0 ] ==GPCMD_READ_DISC_INFO && sdev->no_read_disc_info) +return -EDRIVE_CANT_DO_THIS ; +if (cgc->timeout <=0 ) cgc->timeout =IOCTL_TIMEOUT ; -sr_do_ioctl (cdi->handle, cgc); +sr_do_ioctl (cd, cgc);return cgc->stat; }
include/scsi/scsi_device.h +1 -0
@@ -148,6 +148,7 @@ struct scsi_device { unsigned retry_hwerror:1; /* Retry HARDWARE_ERROR */ unsigned last_sector_bug:1; /* do not use multisector accesses onSD_LAST_BUGGY_SECTORS */ + unsigned no_read_disc_info:1; /* Avoid READ_DISC_INFO cmds */ unsigned is_visible:1; /* is the device visible in sysfs */DECLARE_BITMAP (supported_events,SDEV_EVT_MAXBITS );/* supported events */
Signature · 6 lines
1.7.0.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH RESEND 2/4 usb-storage: Add new no_read_disc_info quirk
Appotech ax3003 (the larger brother of the ax203) based devices are even more buggy then the ax203. They will go of into lala land when ever they see a READ_DISC_INFO scsi command. So add a new US_FL which tells the scsi sr driver to not issue any READ_DISC_INFO scsi commands.
--- drivers/usb/storage/scsiglue.c | 4 ++++ drivers/usb/storage/unusual_devs.h | 5 +++++ include/linux/usb_usual.h | 4 +++- 3 files changed, 12 insertions(+), 1 deletions(-)
drivers/usb/storage/scsiglue.c +4 -0
@@ -253,6 +253,10 @@ static int slave_configure(struct scsi_device *sdev)* or to force 192-byte transfer lengths for MODE SENSE. * But they do need to use MODE SENSE(10). */ sdev->use_10_for_ms =1 ; + +/* Some (fake) usb cdrom devices don't like READ_DISC_INFO */ +if (us->fflags &US_FLAG_NO_READ_DISC_INFO ) + sdev->no_read_disc_info =1 ; }/* The CB and CBI transports have no way to pass LUN values
drivers/usb/storage/unusual_devs.h +5 -0
@@ -1858,6 +1858,11 @@ UNUSUAL_DEV( 0x1908, 0x1320, 0x0000, 0x0000, "Photo Frame", US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_BAD_SENSE ), +UNUSUAL_DEV (0x1908 ,0x3335 ,0x0200 ,0x0200 , +"BUILDWIN" , +"Photo Frame" , +US_SC_DEVICE ,US_PR_DEVICE ,NULL , +US_FL_NO_READ_DISC_INFO ), UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001, "ST",
include/linux/usb_usual.h +3 -1
@@ -58,7 +58,9 @@US_FLAG (CAPACITY_OK ,0x00010000 ) \ /* READ CAPACITY response is correct */ \US_FLAG (BAD_SENSE ,0x00020000 ) \ - /* Bad Sense (never more than 18 bytes) */ + /* Bad Sense (never more than 18 bytes) */ \ +US_FLAG (NO_READ_DISC_INFO ,0x00040000 ) \ + /* cannot handle READ_DISC_INFO */#define US_FLAG (name, value) US_FL_##name = value ,enum {US_DO_ALL_FLAGS };
Signature · 1 line
1.7.0.1
PATCH RESEND 3/4 scsi/sd: Add a no_read_capacity_16 scsi_device flag
In reply to Hans de GoedeI know I know, I seem to have a nack for digging up buggy usb devices which don't work with Linux, and I'm crazy enough to try to make them work. So this time a friend of mine asked me to get an mp4 player (an mp3 player which can play videos on a small screen) to work with Linux.
It is based on the well known rockbox chipset for which we already have an unusual devs entries to work around some of its bugs. But this model comes with an additional twist.
This model chokes on read_capacity_16 calls. Now normally we don't make those calls, but this model comes with an sdcard slot and when there is no card in there (and shipped from the factory there is none), it reports a size of 0. However this time the programmers actually got the read_capacity_10 response right! So they substract one from the size as stored internally in the mp3 player before reporting it back, resulting in an answer of ... 0xffffffff sectors, causing sd.c to try a read_capacity_16, on which the device crashes.
This patch adds a flag to scsi_device to indicate that a a device cannot handle read_capacity_16, and when this flag is set if a device reports an lba of 0xffffffff as answer to a read_capacity_10, assumes it tries to report a size of 0.
--- drivers/scsi/sd.c | 12 ++++++++++++ include/scsi/scsi_device.h | 1 + 2 files changed, 13 insertions(+), 0 deletions(-)
drivers/scsi/sd.c +12 -0
@@ -1450,6 +1450,9 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,unsigned long long lba;unsigned sector_size; +if (sdp->no_read_capacity_16) +return -EINVAL ; + do { memset(cmd, 0, 16); cmd[0] = SERVICE_ACTION_IN;
@@ -1578,6 +1581,15 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, sector_size =get_unaligned_be32 (&buffer[4 ]); lba =get_unaligned_be32 (&buffer[0 ]); +if (sdp->no_read_capacity_16 && (lba ==0xffffffff )) { +/* Some buggy (usb cardreader) devices return an lba of +0xffffffff when the want to report a size of 0 (with +which they really mean no media is present) */ + sdkp->capacity =0 ; + sdkp->hw_sector_size = sector_size; +return sector_size; + } +if ((sizeof (sdkp->capacity) ==4 ) && (lba ==0xffffffff )) {sd_printk (KERN_ERR , sdkp,"Too big for this kernel. Use a " "kernel compiled with support for large block "
include/scsi/scsi_device.h +1 -0
@@ -149,6 +149,7 @@ struct scsi_device { unsigned last_sector_bug:1; /* do not use multisector accesses onSD_LAST_BUGGY_SECTORS */ unsigned no_read_disc_info:1; /* Avoid READ_DISC_INFO cmds */ + unsigned no_read_capacity_16:1; /* Avoid READ_CAPACITY_16 cmds */ unsigned is_visible:1; /* is the device visible in sysfs */DECLARE_BITMAP (supported_events,SDEV_EVT_MAXBITS );/* supported events */
Signature · 1 line
1.7.0.1
Re: [PATCH resend 3/4] scsi/sd: Add a no_read_capacity_16 scsi_device flag
Hello.
Quoted 24 lines · Hans de Goede
I know I know, I seem to have a nack for digging up buggy usb devices which don't work with Linux, and I'm crazy enough to try to make them work. So this time a friend of mine asked me to get an mp4 player (an mp3 player which can play videos on a small screen) to work with Linux.
It is based on the well known rockbox chipset for which we already have an unusual devs entries to work around some of its bugs. But this model comes with an additional twist.
This model chokes on
read_capacity_16calls. Now normally we don't make those calls, but this model comes with an sdcard slot and when there is no card in there (and shipped from the factory there is none), it reports a size of 0. However this time the programmers actually got theread_capacity_10response right! So they substract one from the size as stored internally in the mp3 player before reporting it back, resulting in an answer of ...0xffffffffsectors, causingsd.cto try aread_capacity_16, on which the device crashes.This patch adds a flag to
scsi_deviceto indicate that a a device cannot handleread_capacity_16, and when this flag is set if a device reports an lba of0xffffffffas answer to aread_capacity_10, assumes it tries to report a size of 0.Signed-off-by Hans de Goede <[email protected]>
[...]
Quoted 4 lines
drivers/scsi/sd.c +0
-0
[...]
drivers/scsi/sd.c static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, · line 1584
Quoted 5 lines
drivers/scsi/sd.c +1
-0@@ -1578,6 +1581,15 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, sector_size =get_unaligned_be32 (&buffer[4 ]); lba =get_unaligned_be32 (&buffer[0 ]); +if (sdp->no_read_capacity_16 && (lba ==0xffffffff )) {
Parens around == are not necessary.
drivers/scsi/sd.c static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, · line 1587
Quoted 3 lines
drivers/scsi/sd.c +3
-0+/* Some buggy (usb cardreader) devices return an lba of +0xffffffff when the want to report a size of 0 (with +which they really mean no media is present) */
According to CodingStyle, the preferred format of the multi-line comments
is this:
/*
* bla
* bla
*/
WBR, Sergei
A message that is not in the archive (sent off-list or not yet received): 1279811521-11372-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
PATCH RESEND 4/4 usb-storage: Add new no_read_capacity_16 quirk
Some Rockbox based mp4 players will crash when ever they see a read_capacity_16 scsi command. So add a new US_FL which tells the scsi sd driver to not issue any read_capacity_16 scsi commands.
--- drivers/usb/storage/scsiglue.c | 4 ++++ drivers/usb/storage/unusual_devs.h | 3 ++- include/linux/usb_usual.h | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-)
drivers/usb/storage/scsiglue.c +4 -0
@@ -209,6 +209,10 @@ static int slave_configure(struct scsi_device *sdev)if (us->fflags &US_FL_CAPACITY_HEURISTICS ) sdev->guess_capacity =1 ; +/* Some devices cannot handle READ_CAPACITY_16 */ +if (us->fflags &US_FL_NO_READ_CAPACITY_16 ) + sdev->no_read_capacity_16 =1 ; +/* assume SPC3 or latter devices support sense size > 18 */ if (sdev->scsi_level >SCSI_SPC_2 ) us->fflags |=US_FL_SANE_SENSE ;
drivers/usb/storage/unusual_devs.h +2 -1
@@ -877,7 +877,8 @@ UNUSUAL_DEV( 0x071b, 0x3203, 0x0000, 0x0000,"RockChip" ,"MP3" ,US_SC_DEVICE ,US_PR_DEVICE ,NULL , - US_FL_NO_WP_DETECT | US_FL_MAX_SECTORS_64), +US_FL_NO_WP_DETECT |US_FL_MAX_SECTORS_64 | + US_FL_NO_READ_CAPACITY_16),/* Reported by Jean-Baptiste Onofre <[email protected]> * Support the following product :
include/linux/usb_usual.h +3 -1
@@ -60,7 +60,9 @@US_FLAG (BAD_SENSE ,0x00020000 ) \ /* Bad Sense (never more than 18 bytes) */ \US_FLAG (NO_READ_DISC_INFO ,0x00040000 ) \ - /* cannot handle READ_DISC_INFO */ + /* cannot handle READ_DISC_INFO */ \ +US_FLAG (NO_READ_CAPACITY_16 ,0x00080000 ) \ + /* cannot handle READ_CAPACITY_16 */#define US_FLAG (name, value) US_FL_##name = value ,enum {US_DO_ALL_FLAGS };
Signature · 6 lines
1.7.0.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html