Skip to contentSkip to conversation

mysterious shifts in USB storage drivers.

PATCH [email protected] 5 participants 6 messages May 15, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

These went into 2.4 over a year ago. Unfortunatly, with no comments in the logs.

drivers/usb/storage/datafab.c +1 -1
diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/datafab.c linux-2.5/drivers/usb/storage/datafab.c
@@ -670,7 +670,7 @@ int datafab_transport(Scsi_Cmnd * srb, s
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}
drivers/usb/storage/jumpshot.c +1 -1
diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/jumpshot.c linux-2.5/drivers/usb/storage/jumpshot.c
@@ -611,7 +611,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, 
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}
#1 lore raw
Quoted 3 lines · On Thu, 15 May 2003 [email protected] wrote:

These went into 2.4 over a year ago. Unfortunatly, with no comments in the logs.

There's a lot more of these than the two this patch fixes. Just do a grep for CHECK_COND in storage/*.c.

Patch dropped pending further explanation of why these two cases would be special.

Linus

#2 lore raw
In reply to [email protected]
Quoted 2 lines · On Thu, May 15, 2003 at 04:31:17AM +0100, [email protected] wrote:

These went into 2.4 over a year ago. Unfortunatly, with no comments in the logs.

My logs show this went into 2.4 with this comment:

usb-storage: ISD-200 fixes, more unusual devices, and many cleanups

(o) Fix to ISD-200 driver to work on big-endian platforms, including PPC. This has been in circulation for a while, and seems well-tested.
(o) Add several unusual_devs.h entries
(o) A couple more debugging improvements
(o) A slight improvement to the EXPERIMENTAL HP82xx driver, which should help with newer units.
(o) A _major_ cleanup of error handling code throughout the driver. Note that this is in preparation to deploy the new error-handling state machine (special thanks to Alan Sterm for this work). Right now, the optimizations are simple and straightforward (elimination of redundant code paths, etc). Nothing tremendous, but it looks kinda invasive.

So this was a tiny part of a bigger patch. I defer to Matt as to if this kind of change should be put into 2.5.

thanks,

greg k-h

Quoted 24 lines

diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/datafab.c linux-2.5/drivers/usb/storage/datafab.c

drivers/usb/storage/datafab.c +1 -1
@@ -670,7 +670,7 @@ int datafab_transport(Scsi_Cmnd * srb, s
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}

diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/jumpshot.c linux-2.5/drivers/usb/storage/jumpshot.c

drivers/usb/storage/jumpshot.c +1 -1
@@ -611,7 +611,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, 
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}
#3 lore raw

Hrm... nothing in the logs, but I remember this. Apparently, the srb->result field actually requires this format. If you look at other LLDD code in linux/drivers/scsi/ you'll see that the << 1 is common.

This should be in 2.5... I thought it already was.

Matt

Quoted 51 lines · Greg KH
Quoted 2 lines · On Thu, May 15, 2003 at 04:31:17AM +0100, [email protected] wrote:

These went into 2.4 over a year ago. Unfortunatly, with no comments in the logs.

My logs show this went into 2.4 with this comment:

usb-storage: ISD-200 fixes, more unusual devices, and many cleanups

(o) Fix to ISD-200 driver to work on big-endian platforms, including PPC. This has been in circulation for a while, and seems well-tested.
(o) Add several unusual_devs.h entries
(o) A couple more debugging improvements
(o) A slight improvement to the EXPERIMENTAL HP82xx driver, which should help with newer units.
(o) A _major_ cleanup of error handling code throughout the driver. Note that this is in preparation to deploy the new error-handling state machine (special thanks to Alan Sterm for this work). Right now, the optimizations are simple and straightforward (elimination of redundant code paths, etc). Nothing tremendous, but it looks kinda invasive.

So this was a tiny part of a bigger patch. I defer to Matt as to if this kind of change should be put into 2.5.

thanks,

greg k-h

Quoted 24 lines

diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/datafab.c linux-2.5/drivers/usb/storage/datafab.c

drivers/usb/storage/datafab.c +1 -1
@@ -670,7 +670,7 @@ int datafab_transport(Scsi_Cmnd * srb, s
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}

diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/jumpshot.c linux-2.5/drivers/usb/storage/jumpshot.c

drivers/usb/storage/jumpshot.c +1 -1
@@ -611,7 +611,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, 
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}
Signature · 6 lines
Matthew Dharm                              Home: [email protected] 
Maintainer, Linux USB Mass Storage Driver

Dudes! May the Open Source be with you.
					-- Eric S. Raymond
User Friendly, 12/3/1998
#4 lore raw
Quoted 5 lines · Matthew Dharm

Hrm... nothing in the logs, but I remember this. Apparently, the srb->result field actually requires this format. If you look at other LLDD code in linux/drivers/scsi/ you'll see that the << 1 is common.

This should be in 2.5... I thought it already was.

Nope, care to send me a patch that fixes this, and the other usages of this for 2.5?

thanks,

greg k-h

#5 lore raw
In reply to [email protected]
Quoted 8 lines · On Thu, May 15, 2003 at 04:31:17AM +0100, [email protected] wrote:

These went into 2.4 over a year ago. Unfortunatly, with no comments in the logs.

diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/usb/storage/datafab.c linux-2.5/drivers/usb/storage/datafab.c

drivers/usb/storage/datafab.c int datafab_transport(Scsi_Cmnd * srb, s · line 676

Quoted 8 lines
drivers/usb/storage/datafab.c +1 -1
@@ -670,7 +670,7 @@ int datafab_transport(Scsi_Cmnd * srb, s
 			srb->result = SUCCESS;
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = CHECK_CONDITION << 1;
+			srb->result = CHECK_CONDITION;
 		}
 		return rc;
 	}

And then you say: I have no idea what they do, let us also put them in 2.5?

Very long ago someone noticed that all status codes were even and decided to save some space in arrays by shifting them right one.

Thus, we find in drivers/scsi/scsi.h:
#define status_byte(result) (((result) >> 1) & 0x1f)

Usually the status byte is returned by the device, but everywhere where we invent a status ourselves we need the <<1. This is annoying, and the kernl, both 2.4 and 2.5, is full of mistakes here - may submit some patches against 2.5.70 in case that appears soon. These days we also have the explicit codes that have been shifted already:

/*
* SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
* T10/1561-D Revision 4 Draft dated 7th November 2002.
*/
#define SAM_STAT_GOOD 0x00
#define SAM_STAT_CHECK_CONDITION 0x02
#define SAM_STAT_CONDITION_MET 0x04
#define SAM_STAT_BUSY 0x08
...
/*

 *  Status codes. These are deprecated as they are shifted 1 bit right
 *  from those found in the SCSI standards. This causes confusion for
 *  applications that are ported to several OSes. Prefer SAM Status codes
 *  above.

*/

#define GOOD                 0x00
#define CHECK_CONDITION      0x01
#define CONDITION_GOOD       0x02
#define BUSY                 0x04

Andries