linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason J. Herne" <hernejj@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: linux-usb@vger.kernel.org, stern@rowland.harvard.edu,
	"Jason J. Herne" <hernejj@gmail.com>
Subject: [PATCH] USB enclosures seem to require read(16) with >2TB drives
Date: Fri,  9 Nov 2012 11:08:09 -0500	[thread overview]
Message-ID: <1352477289-8133-1-git-send-email-hernejj@gmail.com> (raw)

From: "Jason J. Herne" <hernejj@gmail.com>

Force large capacity (> 2TB) drives in USB enclosures to use READ(16) instead
of READ(10).  Some(most/all?) enclosures do not like READ(10) commands when a
large capacity drive is installed.

Signed-off-by: Jason J. Herne <hernejj@gmail.com>
---
 drivers/scsi/sd.c              |    7 +++++--
 drivers/usb/storage/scsiglue.c |    5 +++++
 include/scsi/scsi_device.h     |    1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4b63c73..9b65ddf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -649,7 +649,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	sector_t block = blk_rq_pos(rq);
 	sector_t threshold;
 	unsigned int this_count = blk_rq_sectors(rq);
-	int ret, host_dif;
+	int ret, host_dif, force_read16;
 	unsigned char protect;
 
 	/*
@@ -797,6 +797,9 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	else
 		protect = 0;
 
+	/* Many large capacity USB drives/controllers require the use of read(16). */
+	force_read16 = (sdkp->capacity > 0xffffffffULL && sdp->force_read_16);
+
 	if (host_dif == SD_DIF_TYPE2_PROTECTION) {
 		SCpnt->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC);
 
@@ -833,7 +836,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 		SCpnt->cmnd[29] = (unsigned char) (this_count >> 16) & 0xff;
 		SCpnt->cmnd[30] = (unsigned char) (this_count >> 8) & 0xff;
 		SCpnt->cmnd[31] = (unsigned char) this_count & 0xff;
-	} else if (block > 0xffffffff) {
+	} else if (block > 0xffffffff || force_read16) {
 		SCpnt->cmnd[0] += READ_16 - READ_6;
 		SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0);
 		SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0;
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 13b8bcd..6ff785e 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -251,6 +251,11 @@ static int slave_configure(struct scsi_device *sdev)
 					US_FL_SCM_MULT_TARG)) &&
 				us->protocol == USB_PR_BULK)
 			us->use_last_sector_hacks = 1;
+
+		/* Force read-16 for large capacity drives. */
+		sdev->force_read_16 = 1;
+
+
 	} else {
 
 		/* Non-disk-type devices don't need to blacklist any pages
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 5591ed5..e92b846 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -134,6 +134,7 @@ struct scsi_device {
 				     * because we did a bus reset. */
 	unsigned use_10_for_rw:1; /* first try 10-byte read / write */
 	unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
+	unsigned force_read_16:1; /* Use read(16) over read(10) */
 	unsigned skip_ms_page_8:1;	/* do not use MODE SENSE page 0x08 */
 	unsigned skip_ms_page_3f:1;	/* do not use MODE SENSE page 0x3f */
 	unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
-- 
1.7.9.5


             reply	other threads:[~2012-11-09 16:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09 16:08 Jason J. Herne [this message]
2012-11-09 16:33 ` [PATCH] USB enclosures seem to require read(16) with >2TB drives Elliott, Robert (Server Storage)
     [not found]   ` <94D0CD8314A33A4D9D801C0FE68B40294C344C61-NSOR0jG+XgMSZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2012-11-11 11:17     ` Stefan Richter
2012-11-12  8:18       ` Stefan Richter
2012-11-12 11:17     ` James Bottomley
2012-11-12 11:33 ` James Bottomley
     [not found]   ` <1352719990.2449.23.camel-sFMDBYUN5F8GjUHQrlYNx2Wm91YjaHnnhRte9Li2A+AAvxtiuMwx3w@public.gmane.org>
2012-11-12 14:31     ` Paolo Bonzini
     [not found]       ` <50A10856.6090009-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-12 15:01         ` Jason J. Herne
2012-11-12 15:28           ` James Bottomley
2012-11-12 15:10         ` James Bottomley
2012-11-12 15:22           ` Jason J. Herne
2012-11-12 15:35           ` Paolo Bonzini
     [not found]             ` <50A1173D.8090603-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-12 16:06               ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352477289-8133-1-git-send-email-hernejj@gmail.com \
    --to=hernejj@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).