Skip to contentSkip to conversation

Use SCSI read/write(16) with >2TB drives

PATCH In review Jason J. Herne 2 participants 2 messages Nov 14, 2012 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use SCSI read/write(16) with >2TB drives

From: "Jason J. Herne" <[email protected]>

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

---
 drivers/scsi/sd.c          |    5 ++++-
 include/scsi/scsi_device.h |    1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +4 -1
index 12f6fdf..0790f69 100644
@@ -887,7 +887,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 (sdp->use_16_for_rw) {
 		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;
@@ -2067,6 +2067,9 @@ got_data:
 	blk_queue_physical_block_size(sdp->request_queue,
 				      sdkp->physical_block_size);
 	sdkp->device->sector_size = sector_size;
+
+	/* Use read/write(16) for > 2TB disks */
+	sdp->use_16_for_rw = (sdkp->capacity > 0xffffffff);
 }
 
 /* called with buffer of length 512 */
include/scsi/scsi_device.h +1 -0
index 88fae8d..19ab8f1 100644
@@ -135,6 +135,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 use_16_for_rw:1; /* Use read/write(16) over read/write(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 skip_vpd_pages:1;	/* do not read VPD pages */
Signature · 1 line
1.7.9.5
#1 lore raw

Il 14/11/2012 01:54, Jason J. Herne ha scritto:

drivers/scsi/sd.c got_data: · line 2073

Quoted 7 lines
drivers/scsi/sd.c +3 -0
 	blk_queue_physical_block_size(sdp->request_queue,
 				      sdkp->physical_block_size);
 	sdkp->device->sector_size = sector_size;
+
+	/* Use read/write(16) for > 2TB disks */
+	sdp->use_16_for_rw = (sdkp->capacity > 0xffffffff);
 }

This needs to be done before this bit:

        /* Rescale capacity to 512-byte units */
        if (sector_size == 4096)
                sdkp->capacity <<= 3;
        else if (sector_size == 2048)
                sdkp->capacity <<= 2;
        else if (sector_size == 1024)
                sdkp->capacity <<= 1;
        else if (sector_size == 256)
                sdkp->capacity >>= 1;

For example, for a 4K-sector disk the "threshold" would be 16TB (2^12 * 2^32).

Paolo