Skip to content
Permalink
Browse files
Make struct scsi_status a union
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
  • Loading branch information
bvanassche committed Apr 12, 2021
1 parent 7b257ec commit e17a25413564a1fbcd3ad16300ef0b4803c09d31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
@@ -768,6 +768,8 @@ static int __init init_scsi(void)
int error;

BUILD_BUG_ON(sizeof(struct scsi_status) != 4);
BUILD_BUG_ON(((struct scsi_status){.b = {.status = 4, .msg = 3,
.host = 2, .driver = 1}}.combined != 0x01020304));
error = scsi_init_procfs();
if (error)
goto cleanup_queue;
@@ -316,22 +316,22 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)

static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xffffff00) | status;
cmd->result.b.status = status;
}

static inline void set_msg_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xffff00ff) | (status << 8);
cmd->result.b.msg = status;
}

static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xff00ffff) | (status << 16);
cmd->result.b.host = status;
}

static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0x00ffffff) | (status << 24);
cmd->result.b.driver = status;
}

static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
@@ -91,9 +91,18 @@ enum driver_status {
* - A negative Unix error code.
* - In the IDE code, a positive value that represents an error code, an
* error counter or a bitfield.
* @b: SCSI status code.
*/
struct scsi_status {
int32_t combined;
union {
int32_t combined;
struct {
enum sam_status status : 8;
enum msg_byte msg : 8;
enum host_status host : 8;
enum driver_status driver : 8;
} b;
};
};

#endif /* _SCSI_SCSI_STATUS_H */

0 comments on commit e17a254

Please sign in to comment.