Skip to contentSkip to conversation

Suggestion for addition to Documentation/scsi/scsi_mid_low_api.txt

DISCUSSION Alan Stern 1 participant 2 messages Jul 2, 2004 – Aug 3, 2004 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Alan Stern

author
#1 lore raw
In reply to a message not in the archive
Quoted 6 lines · On Thu, 1 Jul 2004 [email protected] wrote:

Quoting Alan Stern <[email protected]>:

Quoted 3 lines

The test given for valid data in the sense_buffer isn't correct. The actual test used is ((cmd->sense_buffer[0] & 0x7f) == 0x70). This is mentioned in a couple of places in the document.

Quoted 7 lines

If that comparison is in linux code then the comparison is wrong! The comparison that is correct is bits 4, 5 and 6 all being set. So we don't care about bit 7 and the bottom two bits can be 0x0, 0x1, 0x2 or 0x3. The fact that linux can't handle sense buffer "descriptor" format is an issue that needs to be addressed soon (but is unlikely to be an issue for usb-storage devices for some time).

Hmmm... I see the test being done two different ways, sometimes masked with 0x70 and sometimes with 0x7f. The latter form is used in scsi_lib.c, sd.c, sr.c, and sg.c. Maybe a patch is in order.

Quoted 4 lines
Quoted 1 line
	You didn't mention cmd->underflow.

I thought that 'resid' superseded 'underflow'. I'll look into it.

Look at http://marc.theaimsgroup.com/?l=linux-scsi&m=108671007701796&w=2
and followup messages.

Quoted 8 lines
Quoted 3 lines
	Although it's pretty obvious, you might want to add that 
	cmd->device points to the scsi_device for which the command was 
	queued.

Thought about that. In lk 2.6 I don't think there is a 'device' (I need to check) but there is an access function (that bumps the usage counter on the scsi_device object in question).

No, there definitely is a device.

Alan Stern

author
#2 lore raw

PATCH: (as355) Fix test for valid sense data present

In reply to a message not in the archive

James:

This patch fixes a bug in several upper-level SCSI drivers. According to Douglas Gilbert, masking with 0x7f is wrong. Note that in several other places we already have code that masks the first sense_buffer byte with 0x70.

Alan Stern

Quoted 11 lines · On Thu, 1 Jul 2004 [email protected] wrote:
Quoted 3 lines

The test given for valid data in the sense_buffer isn't correct. The actual test used is ((cmd->sense_buffer[0] & 0x7f) == 0x70). This is mentioned in a couple of places in the document.

If that comparison is in linux code then the comparison is wrong! The comparison that is correct is bits 4, 5 and 6 all being set. So we don't care about bit 7 and the bottom two bits can be 0x0, 0x1, 0x2 or 0x3. The fact that linux can't handle sense buffer "descriptor" format is an issue that needs to be addressed soon (but is unlikely to be an issue for usb-storage devices for some time).

===== drivers/scsi/scsi_lib.c 1.56 vs edited =====

drivers/scsi/scsi_lib.c +1 -1
@@ -774,7 +774,7 @@
 	 * can choose a block to remap, etc.
 	 */
 	if (driver_byte(result) != 0) {
-		if ((cmd->sense_buffer[0] & 0x7f) == 0x70) {
+		if ((cmd->sense_buffer[0] & 0x70) == 0x70) {
 			/*
 			 * If the device is in the process of becoming ready,
 			 * retry.

===== drivers/scsi/sd.c 1.68 vs edited =====

drivers/scsi/sd.c +1 -1
@@ -723,7 +723,7 @@
 
 	/* An error occurred */
 	if (driver_byte(result) != 0 && 	/* An error occurred */
-	    (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
+	    (SCpnt->sense_buffer[0] & 0x70) == 0x70) { /* Sense current */
 		switch (SCpnt->sense_buffer[2]) {
 		case MEDIUM_ERROR:
 			if (!(SCpnt->sense_buffer[0] & 0x80))

===== drivers/scsi/sg.c 1.66 vs edited =====

drivers/scsi/sg.c +1 -1
@@ -1280,7 +1280,7 @@
 
 		/* Following if statement is a patch supplied by Eric Youngdale */
 		if (driver_byte(SRpnt->sr_result) != 0
-		    && (SRpnt->sr_sense_buffer[0] & 0x7f) == 0x70
+		    && (SRpnt->sr_sense_buffer[0] & 0x70) == 0x70
 		    && (SRpnt->sr_sense_buffer[2] & 0xf) == UNIT_ATTENTION
 		    && sdp->device->removable) {
 			/* Detected disc change. Set the bit - this may be used if */

===== drivers/scsi/sr.c 1.72 vs edited =====

drivers/scsi/sr.c +1 -1
@@ -241,7 +241,7 @@
 	 * memcpy's that could be avoided.
 	 */
 	if (driver_byte(result) != 0 &&		/* An error occurred */
-	    (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
+	    (SCpnt->sense_buffer[0] & 0x70) == 0x70) { /* Sense current */
 		switch (SCpnt->sense_buffer[2]) {
 		case MEDIUM_ERROR:
 		case VOLUME_OVERFLOW: