Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: core: Introduce enums for the SAM and host status codes

Make it possible for the compiler to verify whether SAM and host
status codes are used correctly.

[mkp: resolve conflicts with Hannes' SCSI result series]

Link: https://lore.kernel.org/r/20210524025457.11299-3-bvanassche@acm.org
Cc: Hannes Reinecke <hare@suse.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
149d0e48 d377f415

+91 -78
+1 -1
drivers/scsi/constants.c
··· 408 408 409 409 const char *scsi_hostbyte_string(int result) 410 410 { 411 + enum scsi_host_status hb = host_byte(result); 411 412 const char *hb_string = NULL; 412 - int hb = host_byte(result); 413 413 414 414 if (hb < ARRAY_SIZE(hostbyte_table)) 415 415 hb_string = hostbyte_table[hb];
+1 -1
drivers/target/target_core_pscsi.c
··· 1044 1044 struct se_cmd *cmd = req->end_io_data; 1045 1045 struct pscsi_plugin_task *pt = cmd->priv; 1046 1046 int result = scsi_req(req)->result; 1047 - u8 scsi_status = result & 0xff; 1047 + enum sam_status scsi_status = result & 0xff; 1048 1048 1049 1049 if (scsi_status != SAM_STAT_GOOD) { 1050 1050 pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
+2 -65
include/scsi/scsi.h
··· 11 11 #include <linux/kernel.h> 12 12 #include <scsi/scsi_common.h> 13 13 #include <scsi/scsi_proto.h> 14 + #include <scsi/scsi_status.h> 14 15 15 16 struct scsi_cmnd; 16 17 ··· 80 79 } 81 80 82 81 /* 83 - * MESSAGE CODES 82 + * Extended message codes. 84 83 */ 85 - 86 - #define COMMAND_COMPLETE 0x00 87 - #define EXTENDED_MESSAGE 0x01 88 84 #define EXTENDED_MODIFY_DATA_POINTER 0x00 89 85 #define EXTENDED_SDTR 0x01 90 86 #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ 91 87 #define EXTENDED_WDTR 0x03 92 88 #define EXTENDED_PPR 0x04 93 89 #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 94 - #define SAVE_POINTERS 0x02 95 - #define RESTORE_POINTERS 0x03 96 - #define DISCONNECT 0x04 97 - #define INITIATOR_ERROR 0x05 98 - #define ABORT_TASK_SET 0x06 99 - #define MESSAGE_REJECT 0x07 100 - #define NOP 0x08 101 - #define MSG_PARITY_ERROR 0x09 102 - #define LINKED_CMD_COMPLETE 0x0a 103 - #define LINKED_FLG_CMD_COMPLETE 0x0b 104 - #define TARGET_RESET 0x0c 105 - #define ABORT_TASK 0x0d 106 - #define CLEAR_TASK_SET 0x0e 107 - #define INITIATE_RECOVERY 0x0f /* SCSI-II only */ 108 - #define RELEASE_RECOVERY 0x10 /* SCSI-II only */ 109 - #define TERMINATE_IO_PROC 0x11 /* SCSI-II only */ 110 - #define CLEAR_ACA 0x16 111 - #define LOGICAL_UNIT_RESET 0x17 112 - #define SIMPLE_QUEUE_TAG 0x20 113 - #define HEAD_OF_QUEUE_TAG 0x21 114 - #define ORDERED_QUEUE_TAG 0x22 115 - #define IGNORE_WIDE_RESIDUE 0x23 116 - #define ACA 0x24 117 - #define QAS_REQUEST 0x55 118 - 119 - /* Old SCSI2 names, don't use in new code */ 120 - #define BUS_DEVICE_RESET TARGET_RESET 121 - #define ABORT ABORT_TASK_SET 122 - 123 - /* 124 - * Host byte codes 125 - */ 126 - 127 - #define DID_OK 0x00 /* NO error */ 128 - #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ 129 - #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ 130 - #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ 131 - #define DID_BAD_TARGET 0x04 /* BAD target. */ 132 - #define DID_ABORT 0x05 /* Told to abort for some other reason */ 133 - #define DID_PARITY 0x06 /* Parity error */ 134 - #define DID_ERROR 0x07 /* Internal error */ 135 - #define DID_RESET 0x08 /* Reset by somebody. */ 136 - #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ 137 - #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ 138 - #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ 139 - #define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ 140 - #define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also 141 - * without decrementing the retry count */ 142 - #define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution 143 - * and the driver blocked the port to 144 - * recover the link. Transport class will 145 - * retry or fail IO */ 146 - #define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ 147 - #define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on 148 - * other paths */ 149 - #define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other 150 - * paths might yield different results */ 151 - #define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */ 152 - #define DID_MEDIUM_ERROR 0x13 /* Medium error */ 153 - #define DID_TRANSPORT_MARGINAL 0x14 /* Transport marginal errors */ 154 - #define DRIVER_OK 0x00 /* Driver status */ 155 90 156 91 /* 157 92 * Internal return values.
+13 -11
include/scsi/scsi_proto.h
··· 190 190 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 191 191 * T10/1561-D Revision 4 Draft dated 7th November 2002. 192 192 */ 193 - #define SAM_STAT_GOOD 0x00 194 - #define SAM_STAT_CHECK_CONDITION 0x02 195 - #define SAM_STAT_CONDITION_MET 0x04 196 - #define SAM_STAT_BUSY 0x08 197 - #define SAM_STAT_INTERMEDIATE 0x10 198 - #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 199 - #define SAM_STAT_RESERVATION_CONFLICT 0x18 200 - #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ 201 - #define SAM_STAT_TASK_SET_FULL 0x28 202 - #define SAM_STAT_ACA_ACTIVE 0x30 203 - #define SAM_STAT_TASK_ABORTED 0x40 193 + enum sam_status { 194 + SAM_STAT_GOOD = 0x00, 195 + SAM_STAT_CHECK_CONDITION = 0x02, 196 + SAM_STAT_CONDITION_MET = 0x04, 197 + SAM_STAT_BUSY = 0x08, 198 + SAM_STAT_INTERMEDIATE = 0x10, 199 + SAM_STAT_INTERMEDIATE_CONDITION_MET = 0x14, 200 + SAM_STAT_RESERVATION_CONFLICT = 0x18, 201 + SAM_STAT_COMMAND_TERMINATED = 0x22, /* obsolete in SAM-3 */ 202 + SAM_STAT_TASK_SET_FULL = 0x28, 203 + SAM_STAT_ACA_ACTIVE = 0x30, 204 + SAM_STAT_TASK_ABORTED = 0x40, 205 + }; 204 206 205 207 #define STATUS_MASK 0xfe 206 208 /*
+74
include/scsi/scsi_status.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef _SCSI_SCSI_STATUS_H 4 + #define _SCSI_SCSI_STATUS_H 5 + 6 + #include <linux/types.h> 7 + #include <scsi/scsi_proto.h> 8 + 9 + /* Message codes. */ 10 + enum scsi_msg_byte { 11 + COMMAND_COMPLETE = 0x00, 12 + EXTENDED_MESSAGE = 0x01, 13 + SAVE_POINTERS = 0x02, 14 + RESTORE_POINTERS = 0x03, 15 + DISCONNECT = 0x04, 16 + INITIATOR_ERROR = 0x05, 17 + ABORT_TASK_SET = 0x06, 18 + MESSAGE_REJECT = 0x07, 19 + NOP = 0x08, 20 + MSG_PARITY_ERROR = 0x09, 21 + LINKED_CMD_COMPLETE = 0x0a, 22 + LINKED_FLG_CMD_COMPLETE = 0x0b, 23 + TARGET_RESET = 0x0c, 24 + ABORT_TASK = 0x0d, 25 + CLEAR_TASK_SET = 0x0e, 26 + INITIATE_RECOVERY = 0x0f, /* SCSI-II only */ 27 + RELEASE_RECOVERY = 0x10, /* SCSI-II only */ 28 + TERMINATE_IO_PROC = 0x11, /* SCSI-II only */ 29 + CLEAR_ACA = 0x16, 30 + LOGICAL_UNIT_RESET = 0x17, 31 + SIMPLE_QUEUE_TAG = 0x20, 32 + HEAD_OF_QUEUE_TAG = 0x21, 33 + ORDERED_QUEUE_TAG = 0x22, 34 + IGNORE_WIDE_RESIDUE = 0x23, 35 + ACA = 0x24, 36 + QAS_REQUEST = 0x55, 37 + 38 + /* Old SCSI2 names, don't use in new code */ 39 + BUS_DEVICE_RESET = TARGET_RESET, 40 + ABORT = ABORT_TASK_SET, 41 + }; 42 + 43 + /* Host byte codes. */ 44 + enum scsi_host_status { 45 + DID_OK = 0x00, /* NO error */ 46 + DID_NO_CONNECT = 0x01, /* Couldn't connect before timeout period */ 47 + DID_BUS_BUSY = 0x02, /* BUS stayed busy through time out period */ 48 + DID_TIME_OUT = 0x03, /* TIMED OUT for other reason */ 49 + DID_BAD_TARGET = 0x04, /* BAD target. */ 50 + DID_ABORT = 0x05, /* Told to abort for some other reason */ 51 + DID_PARITY = 0x06, /* Parity error */ 52 + DID_ERROR = 0x07, /* Internal error */ 53 + DID_RESET = 0x08, /* Reset by somebody. */ 54 + DID_BAD_INTR = 0x09, /* Got an interrupt we weren't expecting. */ 55 + DID_PASSTHROUGH = 0x0a, /* Force command past mid-layer */ 56 + DID_SOFT_ERROR = 0x0b, /* The low level driver just wish a retry */ 57 + DID_IMM_RETRY = 0x0c, /* Retry without decrementing retry count */ 58 + DID_REQUEUE = 0x0d, /* Requeue command (no immediate retry) also 59 + * without decrementing the retry count */ 60 + DID_TRANSPORT_DISRUPTED = 0x0e, /* Transport error disrupted execution 61 + * and the driver blocked the port to 62 + * recover the link. Transport class will 63 + * retry or fail IO */ 64 + DID_TRANSPORT_FAILFAST = 0x0f, /* Transport class fastfailed the io */ 65 + DID_TARGET_FAILURE = 0x10, /* Permanent target failure, do not retry on 66 + * other paths */ 67 + DID_NEXUS_FAILURE = 0x11, /* Permanent nexus failure, retry on other 68 + * paths might yield different results */ 69 + DID_ALLOC_FAILURE = 0x12, /* Space allocation on the device failed */ 70 + DID_MEDIUM_ERROR = 0x13, /* Medium error */ 71 + DID_TRANSPORT_MARGINAL = 0x14, /* Transport marginal errors */ 72 + }; 73 + 74 + #endif /* _SCSI_SCSI_STATUS_H */