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

scsi: core: Drop obsolete Linux-specific SCSI status codes

Originally the SCSI subsystem has been using 'special' SCSI status codes,
which were the SAM-specified ones but shifted by 1. As most drivers have
now been modified to use the SAM-specified ones, having two nearly
identical sets of definitions only causes confusion.

The Linux-specifed SCSI status codes have been marked obsolete for several
years so drop them and use the SAM-specified status codes throughout.

Link: https://lore.kernel.org/r/20210427083046.31620-41-hare@suse.de
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Hannes Reinecke and committed by
Martin K. Petersen
3d45cefc 50207148

+65 -66
+1 -1
drivers/ata/libata-scsi.c
··· 642 642 if (cmd->request->rq_flags & RQF_QUIET) 643 643 qc->flags |= ATA_QCFLAG_QUIET; 644 644 } else { 645 - cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); 645 + cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL; 646 646 cmd->scsi_done(cmd); 647 647 } 648 648
+1 -1
drivers/infiniband/ulp/srp/ib_srp.c
··· 2232 2232 * to reduce queue depth temporarily. 2233 2233 */ 2234 2234 scmnd->result = len == -ENOMEM ? 2235 - DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16; 2235 + DID_OK << 16 | SAM_STAT_TASK_SET_FULL : DID_ERROR << 16; 2236 2236 goto err_iu; 2237 2237 } 2238 2238
+1 -1
drivers/scsi/3w-9xxx.c
··· 1338 1338 /* If error, command failed */ 1339 1339 if (error == 1) { 1340 1340 /* Ask for a host reset */ 1341 - cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); 1341 + cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; 1342 1342 } 1343 1343 1344 1344 /* Report residual bytes for single sgl */
+2 -2
drivers/scsi/3w-xxxx.c
··· 429 429 /* Additional sense code qualifier */ 430 430 tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3]; 431 431 432 - tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); 432 + tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; 433 433 return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */ 434 434 } 435 435 } ··· 2159 2159 /* If error, command failed */ 2160 2160 if (error == 1) { 2161 2161 /* Ask for a host reset */ 2162 - tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); 2162 + tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; 2163 2163 } 2164 2164 2165 2165 /* Now complete the io */
+3 -3
drivers/scsi/53c700.c
··· 978 978 if (NCR_700_get_tag_neg_state(SCp->device) == NCR_700_DURING_TAG_NEGOTIATION) 979 979 NCR_700_set_tag_neg_state(SCp->device, 980 980 NCR_700_FINISHED_TAG_NEGOTIATION); 981 - 981 + 982 982 /* check for contingent allegiance conditions */ 983 - if (hostdata->status[0] >> 1 == CHECK_CONDITION || 984 - hostdata->status[0] >> 1 == COMMAND_TERMINATED) { 983 + if (hostdata->status[0] == SAM_STAT_CHECK_CONDITION || 984 + hostdata->status[0] == SAM_STAT_COMMAND_TERMINATED) { 985 985 struct NCR_700_command_slot *slot = 986 986 (struct NCR_700_command_slot *)SCp->host_scribble; 987 987 if(slot->flags == NCR_700_FLAG_AUTOSENSE) {
+1 -1
drivers/scsi/NCR5380.c
··· 538 538 539 539 if (hostdata->sensing == cmd) { 540 540 /* Autosense processing ends here */ 541 - if (status_byte(cmd->result) != GOOD) { 541 + if (get_status_byte(cmd) != SAM_STAT_GOOD) { 542 542 scsi_eh_restore_cmnd(cmd, &hostdata->ses); 543 543 } else { 544 544 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
+2 -2
drivers/scsi/arcmsr/arcmsr_hba.c
··· 1326 1326 1327 1327 struct scsi_cmnd *pcmd = ccb->pcmd; 1328 1328 struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer; 1329 - pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); 1329 + pcmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; 1330 1330 if (sensebuffer) { 1331 1331 int sense_data_length = 1332 1332 sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE ··· 3253 3253 if (!ccb) 3254 3254 return SCSI_MLQUEUE_HOST_BUSY; 3255 3255 if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) { 3256 - cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1); 3256 + cmd->result = (DID_ERROR << 16) | SAM_STAT_RESERVATION_CONFLICT; 3257 3257 cmd->scsi_done(cmd); 3258 3258 return 0; 3259 3259 }
+1 -1
drivers/scsi/esas2r/esas2r_main.c
··· 1525 1525 1526 1526 rq->cmd->result = 1527 1527 ((esas2r_req_status_to_error(rq->req_stat) << 16) 1528 - | (rq->func_rsp.scsi_rsp.scsi_stat & STATUS_MASK)); 1528 + | rq->func_rsp.scsi_rsp.scsi_stat); 1529 1529 1530 1530 if (rq->req_stat == RS_UNDERRUN) 1531 1531 scsi_set_resid(rq->cmd,
+2 -2
drivers/scsi/megaraid.c
··· 1611 1611 */ 1612 1612 if( cmd->cmnd[0] == TEST_UNIT_READY ) { 1613 1613 cmd->result |= (DID_ERROR << 16) | 1614 - (RESERVATION_CONFLICT << 1); 1614 + SAM_STAT_RESERVATION_CONFLICT; 1615 1615 } 1616 1616 else 1617 1617 /* ··· 1623 1623 cmd->cmnd[0] == RELEASE) ) { 1624 1624 1625 1625 cmd->result |= (DID_ERROR << 16) | 1626 - (RESERVATION_CONFLICT << 1); 1626 + SAM_STAT_RESERVATION_CONFLICT; 1627 1627 } 1628 1628 else 1629 1629 #endif
+2 -2
drivers/scsi/megaraid/megaraid_mbox.c
··· 2327 2327 */ 2328 2328 if (scp->cmnd[0] == TEST_UNIT_READY) { 2329 2329 scp->result = DID_ERROR << 16 | 2330 - RESERVATION_CONFLICT << 1; 2330 + SAM_STAT_RESERVATION_CONFLICT; 2331 2331 } 2332 2332 else 2333 2333 /* ··· 2338 2338 scp->cmnd[0] == RELEASE)) { 2339 2339 2340 2340 scp->result = DID_ERROR << 16 | 2341 - RESERVATION_CONFLICT << 1; 2341 + SAM_STAT_RESERVATION_CONFLICT; 2342 2342 } 2343 2343 else { 2344 2344 scp->result = DID_BAD_TARGET << 16 | status;
+24 -24
drivers/scsi/scsi_error.c
··· 745 745 * now, check the status byte to see if this indicates 746 746 * anything special. 747 747 */ 748 - switch (status_byte(scmd->result)) { 749 - case GOOD: 748 + switch (get_status_byte(scmd)) { 749 + case SAM_STAT_GOOD: 750 750 scsi_handle_queue_ramp_up(scmd->device); 751 751 fallthrough; 752 - case COMMAND_TERMINATED: 752 + case SAM_STAT_COMMAND_TERMINATED: 753 753 return SUCCESS; 754 - case CHECK_CONDITION: 754 + case SAM_STAT_CHECK_CONDITION: 755 755 return scsi_check_sense(scmd); 756 - case CONDITION_GOOD: 757 - case INTERMEDIATE_GOOD: 758 - case INTERMEDIATE_C_GOOD: 756 + case SAM_STAT_CONDITION_MET: 757 + case SAM_STAT_INTERMEDIATE: 758 + case SAM_STAT_INTERMEDIATE_CONDITION_MET: 759 759 /* 760 760 * who knows? FIXME(eric) 761 761 */ 762 762 return SUCCESS; 763 - case RESERVATION_CONFLICT: 763 + case SAM_STAT_RESERVATION_CONFLICT: 764 764 if (scmd->cmnd[0] == TEST_UNIT_READY) 765 765 /* it is a success, we probed the device and 766 766 * found it */ 767 767 return SUCCESS; 768 768 /* otherwise, we failed to send the command */ 769 769 return FAILED; 770 - case QUEUE_FULL: 770 + case SAM_STAT_TASK_SET_FULL: 771 771 scsi_handle_queue_full(scmd->device); 772 772 fallthrough; 773 - case BUSY: 773 + case SAM_STAT_BUSY: 774 774 return NEEDS_RETRY; 775 775 default: 776 776 return FAILED; ··· 1760 1760 case DID_PARITY: 1761 1761 return (scmd->request->cmd_flags & REQ_FAILFAST_DEV); 1762 1762 case DID_ERROR: 1763 - if (status_byte(scmd->result) == RESERVATION_CONFLICT) 1763 + if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) 1764 1764 return 0; 1765 1765 fallthrough; 1766 1766 case DID_SOFT_ERROR: ··· 1876 1876 */ 1877 1877 return SUCCESS; 1878 1878 case DID_ERROR: 1879 - if (status_byte(scmd->result) == RESERVATION_CONFLICT) 1879 + if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) 1880 1880 /* 1881 1881 * execute reservation conflict processing code 1882 1882 * lower down ··· 1907 1907 /* 1908 1908 * check the status byte to see if this indicates anything special. 1909 1909 */ 1910 - switch (status_byte(scmd->result)) { 1911 - case QUEUE_FULL: 1910 + switch (get_status_byte(scmd)) { 1911 + case SAM_STAT_TASK_SET_FULL: 1912 1912 scsi_handle_queue_full(scmd->device); 1913 1913 /* 1914 1914 * the case of trying to send too many commands to a 1915 1915 * tagged queueing device. 1916 1916 */ 1917 1917 fallthrough; 1918 - case BUSY: 1918 + case SAM_STAT_BUSY: 1919 1919 /* 1920 1920 * device can't talk to us at the moment. Should only 1921 1921 * occur (SAM-3) when the task queue is empty, so will cause ··· 1923 1923 * device. 1924 1924 */ 1925 1925 return ADD_TO_MLQUEUE; 1926 - case GOOD: 1926 + case SAM_STAT_GOOD: 1927 1927 if (scmd->cmnd[0] == REPORT_LUNS) 1928 1928 scmd->device->sdev_target->expecting_lun_change = 0; 1929 1929 scsi_handle_queue_ramp_up(scmd->device); 1930 1930 fallthrough; 1931 - case COMMAND_TERMINATED: 1931 + case SAM_STAT_COMMAND_TERMINATED: 1932 1932 return SUCCESS; 1933 - case TASK_ABORTED: 1933 + case SAM_STAT_TASK_ABORTED: 1934 1934 goto maybe_retry; 1935 - case CHECK_CONDITION: 1935 + case SAM_STAT_CHECK_CONDITION: 1936 1936 rtn = scsi_check_sense(scmd); 1937 1937 if (rtn == NEEDS_RETRY) 1938 1938 goto maybe_retry; ··· 1941 1941 * to collect the sense and redo the decide 1942 1942 * disposition */ 1943 1943 return rtn; 1944 - case CONDITION_GOOD: 1945 - case INTERMEDIATE_GOOD: 1946 - case INTERMEDIATE_C_GOOD: 1947 - case ACA_ACTIVE: 1944 + case SAM_STAT_CONDITION_MET: 1945 + case SAM_STAT_INTERMEDIATE: 1946 + case SAM_STAT_INTERMEDIATE_CONDITION_MET: 1947 + case SAM_STAT_ACA_ACTIVE: 1948 1948 /* 1949 1949 * who knows? FIXME(eric) 1950 1950 */ 1951 1951 return SUCCESS; 1952 1952 1953 - case RESERVATION_CONFLICT: 1953 + case SAM_STAT_RESERVATION_CONFLICT: 1954 1954 sdev_printk(KERN_INFO, scmd->device, 1955 1955 "reservation conflict\n"); 1956 1956 set_host_byte(scmd, DID_NEXUS_FAILURE);
+1 -1
drivers/scsi/scsi_lib.c
··· 873 873 * if it can't fit). Treat SAM_STAT_CONDITION_MET and the related 874 874 * intermediate statuses (both obsolete in SAM-4) as good. 875 875 */ 876 - if (status_byte(result) && scsi_status_is_good(result)) { 876 + if ((result & 0xff) && scsi_status_is_good(result)) { 877 877 result = 0; 878 878 *blk_statp = BLK_STS_OK; 879 879 }
+1 -1
drivers/scsi/sr.c
··· 338 338 * care is taken to avoid unnecessary additional work such as 339 339 * memcpy's that could be avoided. 340 340 */ 341 - if (status_byte(result) == SAM_STAT_CHECK_CONDITION && 341 + if (scsi_status_is_check_condition(result) && 342 342 (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */ 343 343 switch (SCpnt->sense_buffer[2]) { 344 344 case MEDIUM_ERROR:
+1 -1
drivers/scsi/sr_ioctl.c
··· 205 205 err = result; 206 206 goto out; 207 207 } 208 - if (status_byte(result) == SAM_STAT_CHECK_CONDITION) { 208 + if (scsi_status_is_check_condition(result)) { 209 209 switch (sshdr->sense_key) { 210 210 case UNIT_ATTENTION: 211 211 SDev->changed = 1;
+1 -1
drivers/xen/xen-scsiback.c
··· 224 224 225 225 pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x\n", 226 226 tpg->tport->tport_name, pending_req->v2p->lun, 227 - pending_req->cmnd[0], status_byte(errors), COMMAND_COMPLETE, 227 + pending_req->cmnd[0], errors & 0xff, COMMAND_COMPLETE, 228 228 host_byte(errors)); 229 229 } 230 230
-1
include/scsi/scsi.h
··· 184 184 * msg_byte (unused) 185 185 * host_byte = set by low-level driver to indicate status. 186 186 */ 187 - #define status_byte(result) (((result) >> 1) & 0x7f) 188 187 #define host_byte(result) (((result) >> 16) & 0xff) 189 188 190 189 #define sense_class(sense) (((sense) >> 4) & 0x7)
+1 -21
include/scsi/scsi_proto.h
··· 202 202 #define SAM_STAT_ACA_ACTIVE 0x30 203 203 #define SAM_STAT_TASK_ABORTED 0x40 204 204 205 - /* 206 - * Status codes. These are deprecated as they are shifted 1 bit right 207 - * from those found in the SCSI standards. This causes confusion for 208 - * applications that are ported to several OSes. Prefer SAM Status codes 209 - * above. 210 - */ 211 - 212 - #define GOOD 0x00 213 - #define CHECK_CONDITION 0x01 214 - #define CONDITION_GOOD 0x02 215 - #define BUSY 0x04 216 - #define INTERMEDIATE_GOOD 0x08 217 - #define INTERMEDIATE_C_GOOD 0x0a 218 - #define RESERVATION_CONFLICT 0x0c 219 - #define COMMAND_TERMINATED 0x11 220 - #define QUEUE_FULL 0x14 221 - #define ACA_ACTIVE 0x18 222 - #define TASK_ABORTED 0x20 223 - 224 - #define STATUS_MASK 0xfe 225 - 205 + #define STATUS_MASK 0xfe 226 206 /* 227 207 * SENSE KEYS 228 208 */
+20
include/scsi/sg.h
··· 145 145 /* Obsolete driver_byte() declaration */ 146 146 #define driver_byte(result) (((result) >> 24) & 0xff) 147 147 148 + /* 149 + * Original linux SCSI Status codes. They are shifted 1 bit right 150 + * from those found in the SCSI standards. 151 + */ 152 + 153 + #define GOOD 0x00 154 + #define CHECK_CONDITION 0x01 155 + #define CONDITION_GOOD 0x02 156 + #define BUSY 0x04 157 + #define INTERMEDIATE_GOOD 0x08 158 + #define INTERMEDIATE_C_GOOD 0x0a 159 + #define RESERVATION_CONFLICT 0x0c 160 + #define COMMAND_TERMINATED 0x11 161 + #define QUEUE_FULL 0x14 162 + #define ACA_ACTIVE 0x18 163 + #define TASK_ABORTED 0x20 164 + 165 + /* Obsolete status_byte() declaration */ 166 + #define status_byte(result) (((result) >> 1) & 0x7f) 167 + 148 168 typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ 149 169 int host_no; /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */ 150 170 int channel;