kernel/usb-storage-try-read_capacity-10-first.patch

131 lines
5.8 KiB
Diff

Path: news.gmane.org!not-for-mail
From: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Newsgroups: gmane.linux.usb.general
Subject: Re: USB mass-storage devices and READ CAPACITY(16)
Date: Sun, 17 Jun 2012 11:26:31 -0400 (EDT)
Lines: 81
Approved: news@gmane.org
Message-ID: <Pine.LNX.4.44L0.1206171123390.16446-100000@netrider.rowland.org>
References: <Pine.LNX.4.44L0.1206151703110.1190-100000@iolanthe.rowland.org>
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Trace: dough.gmane.org 1339946799 1694 80.91.229.3 (17 Jun 2012 15:26:39 GMT)
X-Complaints-To: usenet@dough.gmane.org
NNTP-Posting-Date: Sun, 17 Jun 2012 15:26:39 +0000 (UTC)
Cc: Torsten Wohlfarth <towo-BOgDY73gMKaEi8DpZVb4nw@public.gmane.org>,
Sturm Flut <sturmflut-Q2DnxKCD/W3WAjrKYNhlQQ@public.gmane.org>,
Sergey <sergeyn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Philippe Valembois - Phil
<lephilousophe-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
USB list <linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
To: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Original-X-From: linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Sun Jun 17 17:26:37 2012
Return-path: <linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Envelope-to: glug-linux-usb-wOFGN7rlS/M9smdsby/KFg@public.gmane.org
Original-Received: from vger.kernel.org ([209.132.180.67])
by plane.gmane.org with esmtp (Exim 4.69)
(envelope-from <linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>)
id 1SgHN3-0002d5-Pq
for glug-linux-usb-wOFGN7rlS/M9smdsby/KFg@public.gmane.org; Sun, 17 Jun 2012 17:26:34 +0200
Original-Received: (majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org) by vger.kernel.org via listexpand
id S1757469Ab2FQP0d (ORCPT <rfc822;glug-linux-usb@m.gmane.org>);
Sun, 17 Jun 2012 11:26:33 -0400
Original-Received: from netrider.rowland.org ([192.131.102.5]:55086 "HELO
netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with SMTP id S1757447Ab2FQP0c (ORCPT
<rfc822;linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>); Sun, 17 Jun 2012 11:26:32 -0400
Original-Received: (qmail 16789 invoked by uid 500); 17 Jun 2012 11:26:31 -0400
Original-Received: from localhost (sendmail-bs-savSHZN5Fh8qMp+WYRx65w@public.gmane.org)
by localhost with SMTP; 17 Jun 2012 11:26:31 -0400
X-X-Sender: stern-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org
In-Reply-To: <Pine.LNX.4.44L0.1206151703110.1190-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
Original-Sender: linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Precedence: bulk
List-ID: <linux-usb.vger.kernel.org>
X-Mailing-List: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Xref: news.gmane.org gmane.linux.usb.general:65976
Archived-At: <http://permalink.gmane.org/gmane.linux.usb.general/65976>
On Fri, 15 Jun 2012, Alan Stern wrote:
> On Fri, 15 Jun 2012, Hans de Goede wrote:
>
> > Hi,
> >
> > On 06/15/2012 08:20 PM, Alan Stern wrote:
> > > As we can see from recent bug reports, a lot of USB mass-storage
> > > devices cannot handle READ CAPACITY(16) commands properly. They send
> > > back garbage and are unusable as a result.
> > >
> > > Should we go ahead and set a flag on all these devices, telling the sd
> > > driver to try READ CAPACITY(10) first? That's a lot easier than adding
> > > more and more entries to unusual_devs.h.
> >
> > That certainly sound reasonable to me. Note that the 071b:3203 really
> > needs the US_FL_NO_READ_CAPACITY_16 flag though, as it wrongly reports
> > a capacity of -1 when there is no sd card in its slot, and in response
> > to that the kernel tries READ CAPACITY(16) and things go downhill
> > from there...
>
> Yes, we need to be able to have both flags set for the same device.
> For that card reader they would mean try READ CAPACITY(10) first, and
> if it fails, don't try READ CAPACITY(16).
In other words, I'm suggesting we adopt this patch and get rid Hans's
new unusual_devs entry.
Alan Stern
Index: usb-3.4/include/scsi/scsi_device.h
===================================================================
--- usb-3.4.orig/include/scsi/scsi_device.h
+++ usb-3.4/include/scsi/scsi_device.h
@@ -151,6 +151,7 @@ struct scsi_device {
SD_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 try_rc_10_first:1; /* Try READ_CAPACACITY_10 first */
unsigned is_visible:1; /* is the device visible in sysfs */
DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */
Index: usb-3.4/drivers/scsi/sd.c
===================================================================
--- usb-3.4.orig/drivers/scsi/sd.c
+++ usb-3.4/drivers/scsi/sd.c
@@ -1899,6 +1899,8 @@ static int sd_try_rc16_first(struct scsi
{
if (sdp->host->max_cmd_len < 16)
return 0;
+ if (sdp->try_rc_10_first)
+ return 0;
if (sdp->scsi_level > SCSI_SPC_2)
return 1;
if (scsi_device_protection(sdp))
Index: usb-3.4/drivers/usb/storage/scsiglue.c
===================================================================
--- usb-3.4.orig/drivers/usb/storage/scsiglue.c
+++ usb-3.4/drivers/usb/storage/scsiglue.c
@@ -202,6 +202,12 @@ static int slave_configure(struct scsi_d
if (us->fflags & US_FL_NO_READ_CAPACITY_16)
sdev->no_read_capacity_16 = 1;
+ /*
+ * Many devices do not respond properly to READ_CAPACITY_16.
+ * Tell the SCSI layer to try READ_CAPACITY_10 first.
+ */
+ sdev->try_rc_10_first = 1;
+
/* assume SPC3 or latter devices support sense size > 18 */
if (sdev->scsi_level > SCSI_SPC_2)
us->fflags |= US_FL_SANE_SENSE;
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html