public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* PATCH; make sr.c respect use_10_for_ms
@ 2003-06-21 23:59 Matthew Dharm
  2003-06-22  0:07 ` Linus Torvalds
  2003-06-22  0:25 ` James Bottomley
  0 siblings, 2 replies; 19+ messages in thread
From: Matthew Dharm @ 2003-06-21 23:59 UTC (permalink / raw)
  To: torvalds, Linux SCSI list; +Cc: Greg KH, USB Developers

[-- Attachment #1: Type: text/plain, Size: 3375 bytes --]

This patch makes sr.c respect the use_10_for_ms flag.

The old behavior was to try the 6-byte command, and if it fails make some
assumptions.

The new behavior is to first try the 10-bit version (only if use_10_for_ms
is set), the fall back to the old behavior.

With this patch, we should be able to cut out a few hundred lines of
problematic code in usb-storage.

Linus, please apply.

Matt

# This is a BitKeeper generated patch for the following project:
# Project Name: greg k-h's linux 2.5 USB kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.709   -> 1.710  
#	   drivers/scsi/sr.c	1.47    -> 1.48   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/20	mdharm@zen.san.one-eyed-alien.net	1.710
# Make SCSI CD-ROM driver respect the use_10_for_ms flag.
# --------------------------------------------
#
diff -Nru a/drivers/scsi/sr.c b/drivers/scsi/sr.c
--- a/drivers/scsi/sr.c	Fri Jun 20 17:34:56 2003
+++ b/drivers/scsi/sr.c	Fri Jun 20 17:34:56 2003
@@ -663,7 +663,7 @@
 {
 	struct cdrom_generic_command cgc;
 	unsigned char *buffer;
-	int rc, n;
+	int n, rc = 0;
 
 	static char *loadmech[] =
 	{
@@ -682,16 +682,38 @@
 		printk(KERN_ERR "sr: out of memory.\n");
 		return;
 	}
-	memset(&cgc, 0, sizeof(struct cdrom_generic_command));
-	cgc.cmd[0] = MODE_SENSE;
-	cgc.cmd[2] = 0x2a;
-	cgc.cmd[4] = 128;
-	cgc.buffer = buffer;
-	cgc.buflen = 128;
-	cgc.quiet = 1;
-	cgc.data_direction = SCSI_DATA_READ;
-	cgc.timeout = SR_TIMEOUT;
-	rc = sr_do_ioctl(cd, &cgc);
+
+	/* first, attempt 10-byte command */
+	if (cd->device->use_10_for_ms) {
+		memset(&cgc, 0, sizeof(struct cdrom_generic_command));
+		cgc.cmd[0] = MODE_SENSE_10;
+		cgc.cmd[2] = 0x2a;		/* page code */
+		cgc.cmd[8] = 128;		/* allocation length */
+		cgc.buffer = buffer;
+		cgc.buflen = 128;
+		cgc.quiet = 1;
+		cgc.data_direction = SCSI_DATA_READ;
+		cgc.timeout = SR_TIMEOUT;
+		rc = sr_do_ioctl(cd, &cgc);
+	}
+
+	/* if we got an error, return to old behavior */
+	if (rc)
+		cd->device->use_10_for_ms = 0;
+
+	/* issue 6-byte command */
+	if (!cd->device->use_10_for_ms) {
+		memset(&cgc, 0, sizeof(struct cdrom_generic_command));
+		cgc.cmd[0] = MODE_SENSE;
+		cgc.cmd[2] = 0x2a;		/* page code */
+		cgc.cmd[4] = 128;		/* allocation length */
+		cgc.buffer = buffer;
+		cgc.buflen = 128;
+		cgc.quiet = 1;
+		cgc.data_direction = SCSI_DATA_READ;
+		cgc.timeout = SR_TIMEOUT;
+		rc = sr_do_ioctl(cd, &cgc);
+	}
 
 	if (rc) {
 		/* failed, drive doesn't have capabilities mode page */
@@ -703,7 +725,13 @@
 		printk("%s: scsi-1 drive\n", cd->cdi.name);
 		return;
 	}
-	n = buffer[3] + 4;
+
+	/* calculate the start of the page */
+	if (cd->device->use_10_for_ms)
+		n = (buffer[6] << 8) + buffer[7] + 8;
+	else
+		n = buffer[3] + 4;
+
 	cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
 	cd->readcd_known = 1;
 	cd->readcd_cdda = buffer[n + 5] & 0x01;

-- 
Matthew Dharm                              Home: mdharm-usb@one-eyed-alien.net 
Maintainer, Linux USB Mass Storage Driver

P:  How about "Web Designer"?
DP: I'd like a name that people won't laugh at.
					-- Pitr and Dust Puppy
User Friendly, 12/6/1997

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

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

end of thread, other threads:[~2003-06-23 17:16 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-21 23:59 PATCH; make sr.c respect use_10_for_ms Matthew Dharm
2003-06-22  0:07 ` Linus Torvalds
2003-06-22  0:12   ` Matthew Dharm
2003-06-22  0:21     ` Linus Torvalds
2003-06-22  0:30       ` Matthew Dharm
2003-06-22  0:38         ` Linus Torvalds
2003-06-22  0:46           ` Matthew Dharm
2003-06-22  0:25 ` James Bottomley
2003-06-22  0:46   ` Matthew Dharm
2003-06-22  2:54     ` James Bottomley
2003-06-22  4:24       ` Matthew Dharm
2003-06-22  5:05         ` Douglas Gilbert
2003-06-22 13:58         ` James Bottomley
2003-06-22 19:49           ` Matthew Dharm
2003-06-22 19:56             ` Matthew Dharm
2003-06-22 20:37               ` James Bottomley
2003-06-22 21:06                 ` Matthew Dharm
2003-06-23 14:33                   ` James Bottomley
2003-06-23 17:30                     ` Matthew Dharm

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