Skip to contentSkip to conversation

scsi_status() macro

PATCH In review Douglas Gilbert 2 participants 3 messages May 15, 2003 – May 16, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_status() macro

Here is a replacement macro for status_byte(). Leave the status_byte() macro and mark it as deprecated.

Doug Gilbert

drivers/scsi/scsi.h2569bk8cc renamed from drivers/scsi/scsi.h +9 -2
@@ -90,12 +90,19 @@
  *
  *  These are set by:
  *
- *      status byte = set from target device
+ *      status byte = set from target device (SCSI status value)
  *      msg_byte    = return status from host adapter itself.
  *      host_byte   = set by low-level driver to indicate status.
  *      driver_byte = set by mid-level.
+ *
+ *  Notes about following macros:
+ *	scsi_status() returns a standard SCSI status value that may
+ *	be compared with the SAM_STAT_... series of defines.
+ *	status_byte() returns a shifted SCSI status value that matches
+ *	CHECK_CONDITION and friends. status_byte() is deprecated.
  */
-#define status_byte(result) (((result) >> 1) & 0x1f)
+#define scsi_status(result) ((result) & 0x7e)
+#define status_byte(result) (((result) >> 1) & 0x1f)	/* deprecated */
 #define msg_byte(result)    (((result) >> 8) & 0xff)
 #define host_byte(result)   (((result) >> 16) & 0xff)
 #define driver_byte(result) (((result) >> 24) & 0xff)
#1 lore raw

If you're doing this:

Quoted 1 line · Douglas Gilbert

+#define scsi_status(result) ((result) & 0x7e)

because bit0 is reserved in SCSI-2, then it should be 0x3e because bits 6 and 7 are also reserved. Of course, this would clash with the SCSI-3 definition of TASK ABORTED, sigh.

Perhaps it's better just not to bother with the mask?

James

#2 lore raw
Quoted 4 lines · James Bottomley

If you're doing this:

On Thu, 2003-05-15 at 18:50, Douglas Gilbert wrote:

Quoted 8 lines
Quoted 1 line

+#define scsi_status(result) ((result) & 0x7e)

because bit0 is reserved in SCSI-2, then it should be 0x3e because bits 6 and 7 are also reserved. Of course, this would clash with the SCSI-3 definition of TASK ABORTED, sigh.

Perhaps it's better just not to bother with the mask?

James,
The macro still gets rid of the upper bytes in
scsi_cmnd::result so in needs to be at least
a mask of 0xff.

With a mask of 0x7e it is correct for SCSI-3, bit 6 is reserved ** in SCSI-2 and "vendor unique" in SCSI-1 and SCSI_1_CCS. I dug up a SCSI 1 draft and the Status byte table is attached. So as far as I can see our only exposure is to SCSI 1 and CCS devices.

A possible source of confusion with this proposed patch is that 'scsi_status' is probably one of the most common variable names in the SCSI subsystem. As a macro it shouldn't clash but it may confuse. Alternate patch using get_scsi_status() attached.

** SCSI-2 defines reserved as "set aside for future standardization" but SPC-3 (spc3r12) nails it down:
"A reserved bit, byte, word or field shall be set to zero, ...".

Doug Gilbert

14. Status

A status byte shall be sent from the target to the initiator during the STATUS phase at the termination of each command as specified in Tables 14-1 and 14-2 unless the command is cleared by an ABORT message, by a BUS DEVICE RESET message, or by a "hard" RESET condition.

                                  Table 14-1
                                 Status Byte 

==============================================================================

  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
Byte |        |        |        |        |        |        |        |        |

==============================================================================
0 |Reserved| Vendor Unique | Status Byte Code | V |
==============================================================================

drivers/scsi/scsi.h2569bk8cc renamed from drivers/scsi/scsi.h +9 -2
@@ -90,12 +90,19 @@
  *
  *  These are set by:
  *
- *      status byte = set from target device
+ *      status byte = set from target device (SCSI status value)
  *      msg_byte    = return status from host adapter itself.
  *      host_byte   = set by low-level driver to indicate status.
  *      driver_byte = set by mid-level.
+ *
+ *  Notes about following macros:
+ *	get_scsi_status() returns a standard SCSI status value that
+ *	may be compared with the SAM_STAT_... series of defines.
+ *	status_byte() returns a shifted SCSI status value that matches
+ *	CHECK_CONDITION and friends. status_byte() is deprecated.
  */
-#define status_byte(result) (((result) >> 1) & 0x1f)
+#define get_scsi_status(result) ((result) & 0x7e)
+#define status_byte(result) (((result) >> 1) & 0x1f)	/* deprecated */
 #define msg_byte(result)    (((result) >> 8) & 0xff)
 #define host_byte(result)   (((result) >> 16) & 0xff)
 #define driver_byte(result) (((result) >> 24) & 0xff)