diff options
author | Martin K. Petersen <martin.petersen@oracle.com> | 2021-06-02 08:33:12 +0300 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2021-06-02 08:37:04 +0300 |
commit | 1ff28f229bc7fe36735684b25e63b528dbb962a5 (patch) | |
tree | 2c1371434da0e190d8dfdb7709b41b643ce5635e /include/scsi | |
parent | ed1b86ba0fba3d586cd53057551a95197b0a37ad (diff) | |
parent | 3d45cefc8edd7f560e6c97a8d9928ad571f76dec (diff) | |
download | linux-1ff28f229bc7fe36735684b25e63b528dbb962a5.tar.xz |
Merge branch '5.14/scsi-result' into 5.14/scsi-staging
Include Hannes' SCSI command result rework in the staging branch.
[mkp: remove DRIVER_SENSE from mpi3mr]
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'include/scsi')
-rw-r--r-- | include/scsi/scsi.h | 42 | ||||
-rw-r--r-- | include/scsi/scsi_cmnd.h | 38 | ||||
-rw-r--r-- | include/scsi/scsi_proto.h | 22 | ||||
-rw-r--r-- | include/scsi/sg.h | 33 |
4 files changed, 89 insertions, 46 deletions
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index 7f392405991b..358f969f368f 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -62,6 +62,21 @@ static inline int scsi_is_wlun(u64 lun) return (lun & 0xff00) == SCSI_W_LUN_BASE; } +/** + * scsi_status_is_check_condition - check the status return. + * + * @status: the status passed up from the driver (including host and + * driver components) + * + * This returns true if the status code is SAM_STAT_CHECK_CONDITION. + */ +static inline int scsi_status_is_check_condition(int status) +{ + if (status < 0) + return false; + status &= 0xfe; + return status == SAM_STAT_CHECK_CONDITION; +} /* * MESSAGE CODES @@ -138,20 +153,6 @@ static inline int scsi_is_wlun(u64 lun) #define DRIVER_OK 0x00 /* Driver status */ /* - * These indicate the error that occurred, and what is available. - */ - -#define DRIVER_BUSY 0x01 -#define DRIVER_SOFT 0x02 -#define DRIVER_MEDIA 0x03 -#define DRIVER_ERROR 0x04 - -#define DRIVER_INVALID 0x05 -#define DRIVER_TIMEOUT 0x06 -#define DRIVER_HARD 0x07 -#define DRIVER_SENSE 0x08 - -/* * Internal return values. */ enum scsi_disposition { @@ -180,14 +181,10 @@ enum scsi_disposition { * These are set by: * * status byte = set from target device - * msg_byte = return status from host adapter itself. + * msg_byte (unused) * host_byte = set by low-level driver to indicate status. - * driver_byte = set by mid-level. */ -#define status_byte(result) (((result) >> 1) & 0x7f) -#define msg_byte(result) (((result) >> 8) & 0xff) #define host_byte(result) (((result) >> 16) & 0xff) -#define driver_byte(result) (((result) >> 24) & 0xff) #define sense_class(sense) (((sense) >> 4) & 0x7) #define sense_error(sense) ((sense) & 0xf) @@ -259,10 +256,13 @@ enum scsi_disposition { * This returns true for known good conditions that may be treated as * command completed normally */ -static inline int scsi_status_is_good(int status) +static inline bool scsi_status_is_good(int status) { + if (status < 0) + return false; + if (host_byte(status) == DID_NO_CONNECT) - return 0; + return false; /* * FIXME: bit0 is listed as reserved in SCSI-2, but is diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index fed024f4c02a..779a59fe8676 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -315,9 +315,9 @@ static inline void set_status_byte(struct scsi_cmnd *cmd, char status) cmd->result = (cmd->result & 0xffffff00) | status; } -static inline void set_msg_byte(struct scsi_cmnd *cmd, char status) +static inline u8 get_status_byte(struct scsi_cmnd *cmd) { - cmd->result = (cmd->result & 0xffff00ff) | (status << 8); + return cmd->result & 0xff; } static inline void set_host_byte(struct scsi_cmnd *cmd, char status) @@ -325,9 +325,36 @@ static inline void set_host_byte(struct scsi_cmnd *cmd, char status) cmd->result = (cmd->result & 0xff00ffff) | (status << 16); } -static inline void set_driver_byte(struct scsi_cmnd *cmd, char status) +static inline u8 get_host_byte(struct scsi_cmnd *cmd) { - cmd->result = (cmd->result & 0x00ffffff) | (status << 24); + return (cmd->result >> 16) & 0xff; +} + +/** + * scsi_msg_to_host_byte() - translate message byte + * + * Translate the SCSI parallel message byte to a matching + * host byte setting. A message of COMMAND_COMPLETE indicates + * a successful command execution, any other message indicate + * an error. As the messages themselves only have a meaning + * for the SCSI parallel protocol this function translates + * them into a matching host byte value for SCSI EH. + */ +static inline void scsi_msg_to_host_byte(struct scsi_cmnd *cmd, u8 msg) +{ + switch (msg) { + case COMMAND_COMPLETE: + break; + case ABORT_TASK_SET: + set_host_byte(cmd, DID_ABORT); + break; + case TARGET_RESET: + set_host_byte(cmd, DID_RESET); + break; + default: + set_host_byte(cmd, DID_ERROR); + break; + } } static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) @@ -341,4 +368,7 @@ static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) return xfer_len; } +extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc, + u8 key, u8 asc, u8 ascq); + #endif /* _SCSI_SCSI_CMND_H */ diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 5c106c4f249e..cb218a576bcf 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -202,27 +202,7 @@ struct scsi_varlen_cdb_hdr { #define SAM_STAT_ACA_ACTIVE 0x30 #define SAM_STAT_TASK_ABORTED 0x40 -/* - * 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 -#define INTERMEDIATE_GOOD 0x08 -#define INTERMEDIATE_C_GOOD 0x0a -#define RESERVATION_CONFLICT 0x0c -#define COMMAND_TERMINATED 0x11 -#define QUEUE_FULL 0x14 -#define ACA_ACTIVE 0x18 -#define TASK_ABORTED 0x20 - -#define STATUS_MASK 0xfe - +#define STATUS_MASK 0xfe /* * SENSE KEYS */ diff --git a/include/scsi/sg.h b/include/scsi/sg.h index e1a42c2409cc..843cefb8efce 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -131,6 +131,39 @@ struct compat_sg_io_hdr { #define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ #define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */ +/* + * Obsolete DRIVER_SENSE driver byte + * + * Originally the SCSI midlayer would set the DRIVER_SENSE driver byte when + * a sense code was generated and a sense buffer was allocated. + * However, as nowadays every scsi command has a sense code allocated this + * distinction became moot as one could check the sense buffer directly. + * Consequently this byte is not set anymore from the midlayer, but SG will + * keep setting this byte to be compatible with previous releases. + */ +#define DRIVER_SENSE 0x08 +/* Obsolete driver_byte() declaration */ +#define driver_byte(result) (((result) >> 24) & 0xff) + +/* + * Original linux SCSI Status codes. They are shifted 1 bit right + * from those found in the SCSI standards. + */ + +#define GOOD 0x00 +#define CHECK_CONDITION 0x01 +#define CONDITION_GOOD 0x02 +#define BUSY 0x04 +#define INTERMEDIATE_GOOD 0x08 +#define INTERMEDIATE_C_GOOD 0x0a +#define RESERVATION_CONFLICT 0x0c +#define COMMAND_TERMINATED 0x11 +#define QUEUE_FULL 0x14 +#define ACA_ACTIVE 0x18 +#define TASK_ABORTED 0x20 + +/* Obsolete status_byte() declaration */ +#define status_byte(result) (((result) >> 1) & 0x7f) typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ int host_no; /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */ |