public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]indistinguishable devices with broken and unbroken firmware
@ 2007-02-07 14:22 Oliver Neukum
  2007-02-07 15:05 ` Christoph Hellwig
  2007-02-07 18:40 ` Alan Stern
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Neukum @ 2007-02-07 14:22 UTC (permalink / raw)
  To: usb-storage, linux-scsi

Hi,

there's a USB mass storage device which exists in two version. One
reports the correct size and the other does not. Apart from that they
are identical and cannot be told apart. Here's a heuristic based on the
empirical finding that drives have even sizes. I know it's ugly, but it fixes
an ugly bug.

	Regards
		Oliver

Signed-off-by: Oliver Neukum <oneukum@suse.de>
----

--- a/drivers/usb/storage/unusual_devs.h	2007-02-06 14:14:49.000000000 +0100
+++ b/drivers/usb/storage/unusual_devs.h	2007-02-07 15:14:01.000000000 +0100
@@ -1430,7 +1430,7 @@
 		"DataStor",
 		"USB4500 FW1.04",
 		US_SC_DEVICE, US_PR_DEVICE, NULL,
-		US_FL_FIX_CAPACITY),
+		US_FL_CAPACITY_HEURISTICS),
 
 /* Control/Bulk transport for all SubClass values */
 USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
--- a/drivers/usb/storage/scsiglue.c	2007-02-06 14:13:49.000000000 +0100
+++ b/drivers/usb/storage/scsiglue.c	2007-02-07 15:14:01.000000000 +0100
@@ -170,6 +170,12 @@
 		if (us->flags & US_FL_FIX_CAPACITY)
 			sdev->fix_capacity = 1;
 
+		/* A few disks have two indistinguishable version, one of
+		 * which reports the correct capacity and the other does not.
+		 * The sd driver has to guess which is the case. */
+		if (us->flags & US_FL_CAPACITY_HEURISTICS)
+			sdev->guess_capacity = 1;
+
 		/* Some devices report a SCSI revision level above 2 but are
 		 * unable to handle the REPORT LUNS command (for which
 		 * support is mandatory at level 3).  Since we already have
--- a/drivers/scsi/sd.c	2007-02-06 14:14:48.000000000 +0100
+++ b/drivers/scsi/sd.c	2007-02-07 15:14:01.000000000 +0100
@@ -1273,6 +1273,13 @@
 	if (sdp->fix_capacity)
 		--sdkp->capacity;
 
+	/* Some devices have version which report the correct sizes
+	 * and others which do not. We guess size according to a heuristic
+	 * and err on the side of lowering the capacity. */
+	if (sdp->guess_capacity)
+		if (sdkp->capacity & 0x01) /* odd sizes are odd */
+			--sdkp->capacity;
+
 got_data:
 	if (sector_size == 0) {
 		sector_size = 512;
--- a/include/linux/usb_usual.h	2007-02-06 14:14:07.000000000 +0100
+++ b/include/linux/usb_usual.h	2007-02-07 15:14:01.000000000 +0100
@@ -46,7 +46,9 @@
 	US_FLAG(MAX_SECTORS_64,	0x00000400)			\
 		/* Sets max_sectors to 64    */			\
 	US_FLAG(IGNORE_DEVICE,	0x00000800)			\
-		/* Don't claim device */
+		/* Don't claim device */			\
+	US_FLAG(CAPACITY_HEURISTICS,	0x00001000)		\
+		/* sometimes sizes is too big */
 
 #define US_FLAG(name, value)	US_FL_##name = value ,
 enum { US_DO_ALL_FLAGS };
--- a/include/scsi/scsi_device.h	2007-02-06 14:14:57.000000000 +0100
+++ b/include/scsi/scsi_device.h	2007-02-07 15:14:01.000000000 +0100
@@ -122,6 +122,7 @@
 	unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
 	unsigned select_no_atn:1;
 	unsigned fix_capacity:1;	/* READ_CAPACITY is too high by 1 */
+	unsigned guess_capacity:1;	/* READ_CAPACITY might be too high by 1 */
 	unsigned retry_hwerror:1;	/* Retry HARDWARE_ERROR */
 
 	unsigned int device_blocked;	/* Device returned QUEUE_FULL. */

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

* Re: [PATCH]indistinguishable devices with broken and unbroken firmware
  2007-02-07 14:22 [PATCH]indistinguishable devices with broken and unbroken firmware Oliver Neukum
@ 2007-02-07 15:05 ` Christoph Hellwig
  2007-02-07 15:16   ` Oliver Neukum
  2007-02-07 18:40 ` Alan Stern
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2007-02-07 15:05 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: usb-storage, linux-scsi

On Wed, Feb 07, 2007 at 03:22:39PM +0100, Oliver Neukum wrote:
> Hi,
> 
> there's a USB mass storage device which exists in two version. One
> reports the correct size and the other does not. Apart from that they
> are identical and cannot be told apart. Here's a heuristic based on the
> empirical finding that drives have even sizes. I know it's ugly, but it fixes
> an ugly bug.

Do we really need a second flag?  Alternatively fix_capacity could be
changed to mean fix size if odd.


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

* Re: [PATCH]indistinguishable devices with broken and unbroken firmware
  2007-02-07 15:05 ` Christoph Hellwig
@ 2007-02-07 15:16   ` Oliver Neukum
  2007-02-07 18:42     ` [usb-storage] " Alan Stern
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Neukum @ 2007-02-07 15:16 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: usb-storage, linux-scsi

Am Mittwoch, 7. Februar 2007 16:05 schrieb Christoph Hellwig:
> On Wed, Feb 07, 2007 at 03:22:39PM +0100, Oliver Neukum wrote:
> > Hi,
> > 
> > there's a USB mass storage device which exists in two version. One
> > reports the correct size and the other does not. Apart from that they
> > are identical and cannot be told apart. Here's a heuristic based on the
> > empirical finding that drives have even sizes. I know it's ugly, but it fixes
> > an ugly bug.
> 
> Do we really need a second flag?  Alternatively fix_capacity could be
> changed to mean fix size if odd.

Until we learn about devices which really do have an odd number of sectors.
And then we'll have a problem. I'd like to avoid heuristics when we know
for sure.

	Regards
		Oliver

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

* Re: [usb-storage] [PATCH]indistinguishable devices with broken and unbroken firmware
  2007-02-07 14:22 [PATCH]indistinguishable devices with broken and unbroken firmware Oliver Neukum
  2007-02-07 15:05 ` Christoph Hellwig
@ 2007-02-07 18:40 ` Alan Stern
  1 sibling, 0 replies; 5+ messages in thread
From: Alan Stern @ 2007-02-07 18:40 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: usb-storage, linux-scsi

On Wed, 7 Feb 2007, Oliver Neukum wrote:

> --- a/drivers/scsi/sd.c	2007-02-06 14:14:48.000000000 +0100
> +++ b/drivers/scsi/sd.c	2007-02-07 15:14:01.000000000 +0100
> @@ -1273,6 +1273,13 @@
>  	if (sdp->fix_capacity)
>  		--sdkp->capacity;
>  
> +	/* Some devices have version which report the correct sizes
> +	 * and others which do not. We guess size according to a heuristic
> +	 * and err on the side of lowering the capacity. */
> +	if (sdp->guess_capacity)
> +		if (sdkp->capacity & 0x01) /* odd sizes are odd */
> +			--sdkp->capacity;

Please make this "else if ...".  Just in case somebody ever manages to set 
both sdp->fix_capacity and sdp->guess_capacity.

Otherwise it looks reasonable to me.

Alan Stern


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

* Re: [usb-storage] [PATCH]indistinguishable devices with broken and unbroken firmware
  2007-02-07 15:16   ` Oliver Neukum
@ 2007-02-07 18:42     ` Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2007-02-07 18:42 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Christoph Hellwig, usb-storage, linux-scsi

On Wed, 7 Feb 2007, Oliver Neukum wrote:

> Am Mittwoch, 7. Februar 2007 16:05 schrieb Christoph Hellwig:
> > On Wed, Feb 07, 2007 at 03:22:39PM +0100, Oliver Neukum wrote:
> > > Hi,
> > > 
> > > there's a USB mass storage device which exists in two version. One
> > > reports the correct size and the other does not. Apart from that they
> > > are identical and cannot be told apart. Here's a heuristic based on the
> > > empirical finding that drives have even sizes. I know it's ugly, but it fixes
> > > an ugly bug.
> > 
> > Do we really need a second flag?  Alternatively fix_capacity could be
> > changed to mean fix size if odd.
> 
> Until we learn about devices which really do have an odd number of sectors.
> And then we'll have a problem. I'd like to avoid heuristics when we know
> for sure.

In fact there are devices which have an odd number of sectors.  I once 
thought that would be a good heuristic to apply to all devices, but it 
won't work.

Alan Stern


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

end of thread, other threads:[~2007-02-07 18:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-07 14:22 [PATCH]indistinguishable devices with broken and unbroken firmware Oliver Neukum
2007-02-07 15:05 ` Christoph Hellwig
2007-02-07 15:16   ` Oliver Neukum
2007-02-07 18:42     ` [usb-storage] " Alan Stern
2007-02-07 18:40 ` Alan Stern

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