From patchwork Wed Apr 18 15:01:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 10348361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6954860216 for ; Wed, 18 Apr 2018 15:03:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5689620182 for ; Wed, 18 Apr 2018 15:03:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AAD02236A; Wed, 18 Apr 2018 15:03:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60E872040D for ; Wed, 18 Apr 2018 15:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753507AbeDRPDp (ORCPT ); Wed, 18 Apr 2018 11:03:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:39721 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753424AbeDRPDc (ORCPT ); Wed, 18 Apr 2018 11:03:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AD580AF70; Wed, 18 Apr 2018 15:03:26 +0000 (UTC) From: Johannes Thumshirn To: "Martin K . Petersen" Cc: Bart Van Assche , Hannes Reinecke , James Bottomley , Linux SCSI Mailinglist , Douglas Gilbert , Johannes Thumshirn Subject: [VERY EARLY RFC 13/13] scsi: introduce struct scsi_result Date: Wed, 18 Apr 2018 17:01:16 +0200 Message-Id: <20180418150116.18807-14-jthumshirn@suse.de> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180418150116.18807-1-jthumshirn@suse.de> References: <20180418150116.18807-1-jthumshirn@suse.de> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce struct scsi_result. Signed-off-by: Johannes Thumshirn Suggested-by: Bart Van Assche --- block/bsg-lib.c | 8 ++++-- block/bsg.c | 8 ++++-- block/scsi_ioctl.c | 12 ++++---- drivers/ata/libata-scsi.c | 12 +++++--- drivers/firewire/sbp2.c | 2 +- drivers/infiniband/ulp/srp/ib_srp.c | 11 ++++---- drivers/message/fusion/mptfc.c | 2 +- drivers/message/fusion/mptscsih.c | 10 ++++--- drivers/scsi/BusLogic.c | 4 +-- drivers/scsi/NCR5380.c | 2 +- drivers/scsi/aha152x.c | 2 +- drivers/scsi/bfa/bfad_im.c | 10 +++---- drivers/scsi/bnx2fc/bnx2fc_io.c | 2 +- drivers/scsi/ch.c | 2 +- drivers/scsi/constants.c | 4 +-- drivers/scsi/csiostor/csio_scsi.c | 2 +- drivers/scsi/dc395x.c | 11 ++++---- drivers/scsi/device_handler/scsi_dh_alua.c | 10 +++++-- drivers/scsi/dpt_i2o.c | 2 +- drivers/scsi/esp_scsi.c | 2 +- drivers/scsi/fnic/fnic_scsi.c | 2 +- drivers/scsi/hpsa.c | 2 +- drivers/scsi/libfc/fc_fcp.c | 2 +- drivers/scsi/libiscsi.c | 6 ++-- drivers/scsi/lpfc/lpfc_scsi.c | 19 +++++++------ drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 ++-- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 6 ++-- drivers/scsi/osst.c | 3 +- drivers/scsi/pmcraid.c | 4 +-- drivers/scsi/qedf/qedf_io.c | 8 +++--- drivers/scsi/qedi/qedi_fw.c | 2 +- drivers/scsi/qla1280.c | 4 +-- drivers/scsi/qla2xxx/qla_isr.c | 6 ++-- drivers/scsi/qla2xxx/qla_mr.c | 4 +-- drivers/scsi/qla2xxx/qla_os.c | 8 +++--- drivers/scsi/qla4xxx/ql4_os.c | 10 ++++--- drivers/scsi/qlogicfas408.c | 2 +- drivers/scsi/scsi.c | 5 ++-- drivers/scsi/scsi_debug.c | 23 +++++++++------ drivers/scsi/scsi_debugfs.c | 2 +- drivers/scsi/scsi_error.c | 12 ++++---- drivers/scsi/scsi_ioctl.c | 2 +- drivers/scsi/scsi_lib.c | 21 ++++++++------ drivers/scsi/scsi_logging.c | 5 ++-- drivers/scsi/scsi_scan.c | 2 +- drivers/scsi/scsi_transport_spi.c | 2 +- drivers/scsi/sd.c | 22 +++++++-------- drivers/scsi/sd_zbc.c | 4 +-- drivers/scsi/sg.c | 10 +++---- drivers/scsi/snic/snic_scsi.c | 2 +- drivers/scsi/sr.c | 4 +-- drivers/scsi/sr_ioctl.c | 2 +- drivers/scsi/st.c | 2 +- drivers/scsi/stex.c | 2 +- drivers/scsi/storvsc_drv.c | 2 +- drivers/scsi/sym53c8xx_2/sym_glue.h | 1 - drivers/scsi/ufs/ufshcd.c | 6 ++-- drivers/scsi/vmw_pvscsi.c | 3 +- drivers/scsi/xen-scsifront.c | 2 +- drivers/staging/unisys/visorhba/visorhba_main.c | 4 +-- drivers/target/target_core_pscsi.c | 12 +++++--- drivers/usb/image/microtek.c | 11 +++++--- drivers/usb/storage/cypress_atacb.c | 8 +++--- drivers/usb/storage/transport.c | 3 +- drivers/usb/storage/uas.c | 2 +- drivers/usb/storage/usb.c | 4 +-- drivers/xen/xen-scsiback.c | 6 ++-- include/scsi/scsi.h | 37 +++++++++++++++++++------ include/scsi/scsi_cmnd.h | 18 +++++++----- include/trace/events/scsi.h | 2 +- 70 files changed, 262 insertions(+), 193 deletions(-) diff --git a/block/bsg-lib.c b/block/bsg-lib.c index fc2e5ff2c4b9..6231cf710b8d 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -57,14 +57,16 @@ static int bsg_transport_complete_rq(struct request *rq, struct sg_io_v4 *hdr) { struct bsg_job *job = blk_mq_rq_to_pdu(rq); int ret = 0; + struct scsi_result sres = { 0 }; /* * The assignments below don't make much sense, but are kept for * bug by bug backwards compatibility: */ - hdr->device_status = job->result & 0xff; - hdr->transport_status = host_byte(job->result); - hdr->driver_status = driver_byte(job->result); + to_scsi_result(sres, job->result); + hdr->device_status = status_byte(sres); + hdr->transport_status = host_byte(sres); + hdr->driver_status = driver_byte(sres); hdr->info = 0; if (hdr->device_status || hdr->transport_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/block/bsg.c b/block/bsg.c index defa06c11858..060959cdcc41 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -162,14 +162,16 @@ static int bsg_scsi_fill_hdr(struct request *rq, struct sg_io_v4 *hdr, static int bsg_scsi_complete_rq(struct request *rq, struct sg_io_v4 *hdr) { struct scsi_request *sreq = scsi_req(rq); + struct scsi_result scsi_res = { 0 }; int ret = 0; /* * fill in all the output members */ - hdr->device_status = sreq->result & 0xff; - hdr->transport_status = host_byte(sreq->result); - hdr->driver_status = driver_byte(sreq->result); + to_scsi_result(scsi_res, sreq->result); + hdr->device_status = status_byte(scsi_res); + hdr->transport_status = host_byte(scsi_res); + hdr->driver_status = driver_byte(scsi_res); hdr->info = 0; if (hdr->device_status || hdr->transport_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 60b471f8621b..132c7a67e867 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -257,16 +257,18 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, struct bio *bio) { struct scsi_request *req = scsi_req(rq); + struct scsi_result sres = { 0 }; int r, ret = 0; /* * fill in all the output members */ - hdr->status = req->result & 0xff; - hdr->masked_status = status_byte(req->result); - hdr->msg_status = msg_byte(req->result); - hdr->host_status = host_byte(req->result); - hdr->driver_status = driver_byte(req->result); + to_scsi_result(sres, req->result); + hdr->status = status_byte(sres); + hdr->masked_status = status_byte(sres) >> 1; + hdr->msg_status = msg_byte(sres); + hdr->host_status = host_byte(sres); + hdr->driver_status = driver_byte(sres); hdr->info = 0; if (hdr->masked_status || hdr->host_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index b8fcb8442f97..80c51b59e927 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -602,6 +602,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) int argsize = 0; enum dma_data_direction data_dir; struct scsi_sense_hdr sshdr; + struct scsi_result sres; int cmd_result; if (arg == NULL) @@ -651,14 +652,15 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) from scsi_ioctl_send_command() for default case... */ cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); + to_scsi_result(sres, cmd_result); /* FIXME */ - if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ + if (driver_byte(sres) == DRIVER_SENSE) {/* sense data available */ u8 *desc = sensebuf + 8; cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ /* If we set cc then ATA pass-through will cause a * check condition even if no error. Filter that. */ - if (cmd_result & SAM_STAT_CHECK_CONDITION) { + if (status_byte(sres) == SAM_STAT_CHECK_CONDITION) { if (sshdr.sense_key == RECOVERED_ERROR && sshdr.asc == 0 && sshdr.ascq == 0x1d) cmd_result &= ~SAM_STAT_CHECK_CONDITION; @@ -707,6 +709,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) u8 scsi_cmd[MAX_COMMAND_SIZE]; u8 args[7], *sensebuf = NULL; struct scsi_sense_hdr sshdr; + struct scsi_result sres; int cmd_result; if (arg == NULL) @@ -736,13 +739,14 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); - if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ + to_scsi_result(sres, cmd_result); /* FIXME */ + if (driver_byte(sres) == DRIVER_SENSE) {/* sense data available */ u8 *desc = sensebuf + 8; cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ /* If we set cc then ATA pass-through will cause a * check condition even if no error. Filter that. */ - if (cmd_result & SAM_STAT_CHECK_CONDITION) { + if (status_byte(sres) == SAM_STAT_CHECK_CONDITION) { if (sshdr.sense_key == RECOVERED_ERROR && sshdr.asc == 0 && sshdr.ascq == 0x1d) cmd_result &= ~SAM_STAT_CHECK_CONDITION; diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c index 6bac03999fd4..8f10cc926258 100644 --- a/drivers/firewire/sbp2.c +++ b/drivers/firewire/sbp2.c @@ -1391,7 +1391,7 @@ static void complete_command_orb(struct sbp2_orb *base_orb, sizeof(orb->request), DMA_TO_DEVICE); sbp2_unmap_scatterlist(device->card->device, orb); - orb->cmd->result = result; + to_scsi_result(orb->cmd->result, result); orb->cmd->scsi_done(orb->cmd); } diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 007af14734ed..23e2bb53bb5b 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -1323,7 +1323,7 @@ static void srp_finish_req(struct srp_rdma_ch *ch, struct srp_request *req, if (scmnd) { srp_free_req(ch, req, scmnd, 0); - scmnd->result = result; + to_scsi_result(scmnd->result, result); scmnd->scsi_done(scmnd); } } @@ -2291,7 +2291,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) unsigned long flags; u32 tag; u16 idx; - int len, ret; + int len, ret, scsi_res; const bool in_scsi_eh = !in_interrupt() && current == shost->ehandler; /* @@ -2303,10 +2303,11 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) if (in_scsi_eh) mutex_lock(&rport->mutex); - scmnd->result = srp_chkready(target->rport); - if (unlikely(scmnd->result)) + scsi_res = srp_chkready(target->rport); + if (unlikely(scsi_res)) goto err; + to_scsi_result(scmnd->result, scsi_res); WARN_ON_ONCE(scmnd->request->tag < 0); tag = blk_mq_unique_tag(scmnd->request); ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)]; @@ -2387,7 +2388,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) req->scmnd = NULL; err: - if (scmnd->result) { + if (from_scsi_result(scmnd->result)) { scmnd->scsi_done(scmnd); ret = 0; } else { diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c index 0e2775c21b3b..2a63cab5420e 100644 --- a/drivers/message/fusion/mptfc.c +++ b/drivers/message/fusion/mptfc.c @@ -657,7 +657,7 @@ mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt) err = fc_remote_port_chkready(rport); if (unlikely(err)) { - SCpnt->result = err; + to_scsi_result(SCpnt->result, err); SCpnt->scsi_done(SCpnt); return 0; } diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c index b3f81f8a8b7c..efe6a2336ce6 100644 --- a/drivers/message/fusion/mptscsih.c +++ b/drivers/message/fusion/mptscsih.c @@ -543,7 +543,7 @@ mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pSc scsi_get_resid(sc)); printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, " "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag), - le32_to_cpu(pScsiReply->TransferCount), sc->result); + le32_to_cpu(pScsiReply->TransferCount), from_scsi_result(sc->result)); printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), " "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n", @@ -824,7 +824,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) set_scsi_result(sc, 0, DID_OK, 0, scsi_status); dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n", - ioc->name, sc->result, sc->device->channel, sc->device->id)); + ioc->name, from_scsi_result(sc->result), + sc->device->channel, sc->device->id)); break; case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ @@ -992,7 +993,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) * Not real sure here either so do nothing... */ } - if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL) + if (status_byte(sc->result) == SAM_STAT_TASK_SET_FULL) mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); /* Add handling of: @@ -1025,7 +1026,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) } /* switch(status) */ #ifdef CONFIG_FUSION_LOGGING - if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY)) + if (from_scsi_result(sc->result) != 0 + && (ioc->debug_level & MPT_DEBUG_REPLY)) mptscsih_info_scsiio(ioc, sc, pScsiReply); #endif diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c index 3c0db9dbd50d..eb441acbedd1 100644 --- a/drivers/scsi/BusLogic.c +++ b/drivers/scsi/BusLogic.c @@ -2828,8 +2828,8 @@ static void blogic_process_ccbs(struct blogic_adapter *adapter) set_host_byte(command, DID_ABORT); break; case BLOGIC_CMD_COMPLETE_ERROR: - command->result = blogic_resultcode(adapter, - ccb->adapter_status, ccb->tgt_status); + to_scsi_result(command->result, blogic_resultcode(adapter, + ccb->adapter_status, ccb->tgt_status)); if (ccb->adapter_status != BLOGIC_SELECT_TIMEOUT) { adapter->tgt_stats[ccb->tgt_id] .cmds_complete++; diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c index 5c94425486f8..b5651c7f14d7 100644 --- a/drivers/scsi/NCR5380.c +++ b/drivers/scsi/NCR5380.c @@ -513,7 +513,7 @@ static void complete_cmd(struct Scsi_Host *instance, if (hostdata->sensing == cmd) { /* Autosense processing ends here */ - if ((cmd->result & 0xff) != SAM_STAT_GOOD) { + if (status_byte(cmd->result) != SAM_STAT_GOOD) { scsi_eh_restore_cmnd(cmd, &hostdata->ses); set_host_byte(cmd, DID_ERROR); } else diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c index 1401f772a5ca..ed7592aab76b 100644 --- a/drivers/scsi/aha152x.c +++ b/drivers/scsi/aha152x.c @@ -1295,7 +1295,7 @@ static void done(struct Scsi_Host *shpnt, int error) DONE_SC = CURRENT_SC; CURRENT_SC = NULL; - DONE_SC->result = error; + to_scsi_result(DONE_SC->result, error); } else printk(KERN_ERR "aha152x: done() called outside of command\n"); } diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c index 5d9d97619043..fc7722caa0c2 100644 --- a/drivers/scsi/bfa/bfad_im.c +++ b/drivers/scsi/bfa/bfad_im.c @@ -92,16 +92,16 @@ bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio, scsi_dma_unmap(cmnd); cmnd->host_scribble = NULL; - bfa_trc(bfad, cmnd->result); + bfa_trc(bfad, from_scsi_result(cmnd->result)); itnim_data = cmnd->device->hostdata; if (itnim_data) { itnim = itnim_data->itnim; - if (!cmnd->result && itnim && + if (from_scsi_result(cmnd->result) == 0 && itnim && (bfa_lun_queue_depth > cmnd->device->queue_depth)) { /* Queue depth adjustment for good status completion */ bfad_ramp_up_qdepth(itnim, cmnd->device); - } else if (cmnd->result == SAM_STAT_TASK_SET_FULL && itnim) { + } else if (status_byte(cmnd->result) == SAM_STAT_TASK_SET_FULL && itnim) { /* qfull handling */ bfad_handle_qfull(itnim, cmnd->device); } @@ -150,7 +150,7 @@ bfa_cb_ioim_abort(void *drv, struct bfad_ioim_s *dio) if (cmnd->device->host != NULL) scsi_dma_unmap(cmnd); - bfa_trc(bfad, cmnd->result); + bfa_trc(bfad, from_scsi_result(cmnd->result)); cmnd->host_scribble = NULL; } @@ -1228,7 +1228,7 @@ bfad_im_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd rc = fc_remote_port_chkready(rport); if (rc) { - cmnd->result = rc; + to_scsi_result(cmnd->result, rc); done(cmnd); return 0; } diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c index e2d896409eb1..7dee56f97a5c 100644 --- a/drivers/scsi/bnx2fc/bnx2fc_io.c +++ b/drivers/scsi/bnx2fc/bnx2fc_io.c @@ -1824,7 +1824,7 @@ int bnx2fc_queuecommand(struct Scsi_Host *host, rval = fc_remote_port_chkready(rport); if (rval) { - sc_cmd->result = rval; + to_scsi_result(sc_cmd->result, rval); sc_cmd->scsi_done(sc_cmd); return 0; } diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index c535c52e72e5..cb352faf6080 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -199,7 +199,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, buflength, &sshdr, timeout * HZ, MAX_RETRIES, NULL); - if (driver_byte(result) & DRIVER_SENSE) { + if ((result >> 24) == DRIVER_SENSE) { if (debug) scsi_print_sense_hdr(ch->device, ch->name, &sshdr); errno = ch_find_errno(&sshdr); diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c index d4c2a2e4c5d4..9ed2e7eb7516 100644 --- a/drivers/scsi/constants.c +++ b/drivers/scsi/constants.c @@ -413,7 +413,7 @@ static const char * const driverbyte_table[]={ const char *scsi_hostbyte_string(int result) { const char *hb_string = NULL; - int hb = host_byte(result); + int hb = result >> 16; if (hb < ARRAY_SIZE(hostbyte_table)) hb_string = hostbyte_table[hb]; @@ -424,7 +424,7 @@ EXPORT_SYMBOL(scsi_hostbyte_string); const char *scsi_driverbyte_string(int result) { const char *db_string = NULL; - int db = driver_byte(result); + int db = result >> 24; if (db < ARRAY_SIZE(driverbyte_table)) db_string = driverbyte_table[db]; diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c index 5c923e9aec8c..68c74aa773ae 100644 --- a/drivers/scsi/csiostor/csio_scsi.c +++ b/drivers/scsi/csiostor/csio_scsi.c @@ -1793,7 +1793,7 @@ csio_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmnd) nr = fc_remote_port_chkready(rport); if (nr) { - cmnd->result = nr; + to_scsi_result(cmnd->result, nr); CSIO_INC_STATS(scsim, n_rn_nr_error); goto err_done; } diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c index a71f6cc5ff97..85e6d9d68aec 100644 --- a/drivers/scsi/dc395x.c +++ b/drivers/scsi/dc395x.c @@ -164,7 +164,6 @@ #define RES_TARGET 0x000000FF /* Target State */ #define RES_TARGET_LNX STATUS_MASK /* Only official ... */ #define RES_ENDMSG 0x0000FF00 /* End Message */ -#define RES_DID 0x00FF0000 /* DID_ codes */ #define RES_DRV 0xFF000000 /* DRIVER_ codes */ #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) @@ -3400,10 +3399,10 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, /* * target status.......................... */ - if (status_byte(status) == CHECK_CONDITION) { + if ((status & 0xff) == SAM_STAT_CHECK_CONDITION) { request_sense(acb, dcb, srb); return; - } else if (status_byte(status) == QUEUE_FULL) { + } else if ((status & 0xff) == SAM_STAT_TASK_SET_FULL) { tempcnt = (u8)list_size(&dcb->srb_going_list); dprintkl(KERN_INFO, "QUEUE_FULL for dev <%02i-%i> with %i cmnds\n", dcb->target_id, dcb->target_lun, tempcnt); @@ -3464,7 +3463,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, base = scsi_kmap_atomic_sg(sg, scsi_sg_count(cmd), &offset, &len); ptr = (struct ScsiInqData *)(base + offset); - if (!ckc_only && (cmd->result & RES_DID) == 0 + if (!ckc_only && host_byte(cmd->result) == DID_OK && cmd->cmnd[2] == 0 && scsi_bufflen(cmd) >= 8 && dir != PCI_DMA_NONE && ptr && (ptr->Vers & 0x07) >= 2) dcb->inquiry7 = ptr->Flags; @@ -3537,7 +3536,7 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag, srb_going_remove(dcb, srb); free_tag(dcb, srb); srb_free_insert(acb, srb); - p->result = result; + to_scsi_result(p->result, result); pci_unmap_srb_sense(acb, srb); pci_unmap_srb(acb, srb); if (force) { @@ -3566,7 +3565,7 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag, (u8)p->device->lun); srb_waiting_remove(dcb, srb); srb_free_insert(acb, srb); - p->result = result; + to_scsi_result(p->result, result); pci_unmap_srb_sense(acb, srb); pci_unmap_srb(acb, srb); if (force) { diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index 12dc7100bb4c..b9498db4c10f 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -544,6 +544,10 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) retval = submit_rtpg(sdev, buff, bufflen, &sense_hdr, pg->flags); if (retval) { + struct scsi_result scsi_res; + + to_scsi_result(scsi_res, retval); + /* * Some (broken) implementations have a habit of returning * an error during things like firmware update etc. @@ -565,7 +569,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) "%s: rtpg failed, result %d\n", ALUA_DH_NAME, retval); kfree(buff); - if (driver_byte(retval) == DRIVER_ERROR) + if ((retval >> 24) == DRIVER_ERROR) return SCSI_DH_DEV_TEMP_BUSY; return SCSI_DH_IO; } @@ -745,6 +749,7 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) { int retval; struct scsi_sense_hdr sense_hdr; + struct scsi_result scsi_result; if (!(pg->tpgs & TPGS_MODE_EXPLICIT)) { /* Only implicit ALUA supported, retry */ @@ -773,13 +778,14 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) return SCSI_DH_NOSYS; } retval = submit_stpg(sdev, pg->group_id, &sense_hdr); + to_scsi_result(scsi_result, retval); if (retval) { if (!scsi_sense_valid(&sense_hdr)) { sdev_printk(KERN_INFO, sdev, "%s: stpg failed, result %d", ALUA_DH_NAME, retval); - if (driver_byte(retval) == DRIVER_ERROR) + if (driver_byte(scsi_result) == DRIVER_ERROR) return SCSI_DH_DEV_TEMP_BUSY; } else { sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n", diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c index cb233d4825ad..c6c6662a43bf 100644 --- a/drivers/scsi/dpt_i2o.c +++ b/drivers/scsi/dpt_i2o.c @@ -2501,7 +2501,7 @@ static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd) if(cmd->scsi_done != NULL){ cmd->scsi_done(cmd); } - return cmd->result; + return from_scsi_result(cmd->result); } diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c index 40862584a5e2..2c6d73008942 100644 --- a/drivers/scsi/esp_scsi.c +++ b/drivers/scsi/esp_scsi.c @@ -894,7 +894,7 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent, esp->active_cmd = NULL; esp_unmap_dma(esp, cmd); esp_free_lun_tag(ent, dev->hostdata); - cmd->result = result; + to_scsi_result(cmd->result, result); if (ent->eh_done) { complete(ent->eh_done); diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c index 7e2a77c9e9c8..266488db5517 100644 --- a/drivers/scsi/fnic/fnic_scsi.c +++ b/drivers/scsi/fnic/fnic_scsi.c @@ -461,7 +461,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_ FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "rport is not ready\n"); atomic64_inc(&fnic_stats->misc_stats.rport_not_ready); - sc->result = ret; + to_scsi_result(sc->result, ret); done(sc); return 0; } diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 5221412c3163..46a954e99032 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -2667,7 +2667,7 @@ static void complete_scsi_command(struct CommandList *cp) "Returning result: 0x%x\n", cp, ei->ScsiStatus, sense_key, asc, ascq, - cmd->result); + from_scsi_result(cmd->result)); } else { /* scsi status is zero??? How??? */ dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. " "Returning no connection.\n", cp), diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c index f86fd13e1c2b..17af57948eb1 100644 --- a/drivers/scsi/libfc/fc_fcp.c +++ b/drivers/scsi/libfc/fc_fcp.c @@ -1879,7 +1879,7 @@ int fc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *sc_cmd) rval = fc_remote_port_chkready(rport); if (rval) { - sc_cmd->result = rval; + to_scsi_result(sc_cmd->result, rval); sc_cmd->scsi_done(sc_cmd); return 0; } diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 1c12942b98fd..de97cffe020e 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -927,7 +927,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, } out: ISCSI_DBG_SESSION(session, "cmd rsp done [sc %p res %d itt 0x%x]\n", - sc, sc->result, task->itt); + sc, from_scsi_result(sc->result), task->itt); conn->scsirsp_pdus_cnt++; iscsi_complete_task(task, ISCSI_TASK_COMPLETED); } @@ -966,7 +966,7 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, ISCSI_DBG_SESSION(conn->session, "data in with status done " "[sc %p res %d itt 0x%x]\n", - sc, sc->result, task->itt); + sc, from_scsi_result(sc->result), task->itt); conn->scsirsp_pdus_cnt++; iscsi_complete_task(task, ISCSI_TASK_COMPLETED); } @@ -1690,7 +1690,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) reason = iscsi_session_chkready(cls_session); if (reason) { - sc->result = reason; + to_scsi_result(sc->result, reason); goto fault; } diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c index 101bce993b3c..1c3e9b314367 100644 --- a/drivers/scsi/lpfc/lpfc_scsi.c +++ b/drivers/scsi/lpfc/lpfc_scsi.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "lpfc_version.h" #include "lpfc_hw4.h" @@ -211,7 +212,7 @@ lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) unsigned long latency; int i; - if (cmd->result) + if (from_scsi_result(cmd->result)) return; latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); @@ -3586,22 +3587,22 @@ lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; struct lpfc_fast_path_event *fast_path_evt = NULL; struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; + enum scsi_status_byte sb = status_byte(cmnd->result); unsigned long flags; if (!pnode || !NLP_CHK_NODE_ACT(pnode)) return; /* If there is queuefull or busy condition send a scsi event */ - if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || - (cmnd->result == SAM_STAT_BUSY)) { + if (sb == SAM_STAT_TASK_SET_FULL || sb == SAM_STAT_BUSY) { fast_path_evt = lpfc_alloc_fast_evt(phba); if (!fast_path_evt) return; fast_path_evt->un.scsi_evt.event_type = FC_REG_SCSI_EVENT; fast_path_evt->un.scsi_evt.subcategory = - (cmnd->result == SAM_STAT_TASK_SET_FULL) ? - LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; + (sb == SAM_STAT_TASK_SET_FULL) ? + LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; memcpy(&fast_path_evt->un.scsi_evt.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); @@ -4113,15 +4114,15 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, } else set_scsi_result(cmd, 0, DID_OK, 0, 0); - if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { + if (from_scsi_result(cmd->result) || lpfc_cmd->fcp_rsp->rspSnsLen) { uint32_t *lp = (uint32_t *)cmd->sense_buffer; lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, "0710 Iodone <%d/%llu> cmd %p, error " "x%x SNS x%x x%x Data: x%x x%x\n", cmd->device->id, cmd->device->lun, cmd, - cmd->result, *lp, *(lp + 3), cmd->retries, - scsi_get_resid(cmd)); + from_scsi_result(cmd->result), *lp, *(lp + 3), + cmd->retries, scsi_get_resid(cmd)); } lpfc_update_stats(phba, lpfc_cmd); @@ -4547,7 +4548,7 @@ lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) rdata = lpfc_rport_data_from_scsi_device(cmnd->device); err = fc_remote_port_chkready(rport); if (err) { - cmnd->result = err; + to_scsi_result(cmnd->result, err); goto out_fail_command; } ndlp = rdata->pnode; diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 2dc5066682dd..1db4fd9cb2d5 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -4580,9 +4580,9 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason) scsi_print_command(cmd_fusion->scmd); } - scmd_local->result = - megasas_check_mpio_paths(instance, - scmd_local); + to_scsi_result(scmd_local->result, + megasas_check_mpio_paths(instance, + scmd_local)); if (instance->ldio_threshold && megasas_cmd_type(scmd_local) == READ_WRITE_LDIO) atomic_dec(&instance->ldio_outstanding); diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 36f71379c350..5a7122476931 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -4973,7 +4973,8 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, pr_warn(MPT3SAS_FMT "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), - le32_to_cpu(mpi_reply->TransferCount), scmd->result); + le32_to_cpu(mpi_reply->TransferCount), + from_scsi_result(scmd->result)); pr_warn(MPT3SAS_FMT "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, @@ -5429,7 +5430,8 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) } - if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) + if (from_scsi_result(scmd->result) && + (ioc->logging_level & MPT_DEBUG_REPLY)) _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); out: diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c index 20ec1c01dbd5..5324140566ba 100644 --- a/drivers/scsi/osst.c +++ b/drivers/scsi/osst.c @@ -284,8 +284,7 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt) printk(KERN_WARNING "%s:W: Warning %x (driver bt 0x%x, host bt 0x%x).\n", - name, result, driver_byte(result), - host_byte(result)); + name, result, result >> 24, result >> 16); if (notyetprinted) { notyetprinted = 0; printk(KERN_INFO diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c index af751bb45ddf..0c222ef19119 100644 --- a/drivers/scsi/pmcraid.c +++ b/drivers/scsi/pmcraid.c @@ -2045,7 +2045,7 @@ static void pmcraid_fail_outstanding_cmds(struct pmcraid_instance *pinstance) pmcraid_info("failing(%d) CDB[0] = %x result: %x\n", le32_to_cpu(resp) >> 2, cmd->ioa_cb->ioarcb.cdb[0], - scsi_cmd->result); + from_scsi_result(scsi_cmd->result)); scsi_cmd->scsi_done(scsi_cmd); } else if (cmd->cmd_done == pmcraid_internal_done || cmd->cmd_done == pmcraid_erp_done) { @@ -2838,7 +2838,7 @@ static int _pmcraid_io_done(struct pmcraid_cmd *cmd, int reslen, int ioasc) pmcraid_info("response(%d) CDB[0] = %x ioasc:result: %x:%x\n", le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, cmd->ioa_cb->ioarcb.cdb[0], - ioasc, scsi_cmd->result); + ioasc, from_scsi_result(scsi_cmd->result)); if (PMCRAID_IOASC_SENSE_KEY(ioasc) != 0) rc = pmcraid_error_handler(cmd); diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c index 045c85d922be..0e06532bf703 100644 --- a/drivers/scsi/qedf/qedf_io.c +++ b/drivers/scsi/qedf/qedf_io.c @@ -814,7 +814,7 @@ static void qedf_trace_io(struct qedf_rport *fcport, struct qedf_ioreq *io_req, io_log->lba[3] = sc_cmd->cmnd[5]; io_log->bufflen = scsi_bufflen(sc_cmd); io_log->sg_count = scsi_sg_count(sc_cmd); - io_log->result = sc_cmd->result; + io_log->result = from_scsi_result(sc_cmd->result); io_log->jiffies = jiffies; io_log->refcount = kref_read(&io_req->refcount); @@ -934,7 +934,7 @@ qedf_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc_cmd) rval = fc_remote_port_chkready(rport); if (rval) { - sc_cmd->result = rval; + to_scsi_result(sc_cmd->result, rval); sc_cmd->scsi_done(sc_cmd); return 0; } @@ -1262,8 +1262,8 @@ void qedf_scsi_done(struct qedf_ctx *qedf, struct qedf_ioreq *io_req, "sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, " "allowed=%d retries=%d refcount=%d.\n", qedf->lport->host->host_no, sc_cmd->device->id, - sc_cmd->device->lun, sc_cmd, sc_cmd->result, sc_cmd->cmnd[0], - sc_cmd->cmnd[2], sc_cmd->cmnd[3], sc_cmd->cmnd[4], + sc_cmd->device->lun, sc_cmd, from_scsi_result(sc_cmd->result), + sc_cmd->cmnd[0], sc_cmd->cmnd[2], sc_cmd->cmnd[3], sc_cmd->cmnd[4], sc_cmd->cmnd[5], sc_cmd->allowed, sc_cmd->retries, refcount); diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c index 25d763ae5d5a..971bf69a79f1 100644 --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -2014,7 +2014,7 @@ void qedi_trace_io(struct qedi_ctx *qedi, struct iscsi_task *task, io_log->cached_sge = qedi->use_cached_sge; io_log->slow_sge = qedi->use_slow_sge; io_log->fast_sge = qedi->use_fast_sge; - io_log->result = sc_cmd->result; + io_log->result = from_scsi_result(sc_cmd->result); io_log->jiffies = jiffies; io_log->blk_req_cpu = smp_processor_id(); diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c index c69410da536b..e99d8866a487 100644 --- a/drivers/scsi/qla1280.c +++ b/drivers/scsi/qla1280.c @@ -1286,7 +1286,7 @@ qla1280_done(struct scsi_qla_host *ha) target = SCSI_TCN_32(cmd); lun = SCSI_LUN_32(cmd); - switch ((CMD_RESULT(cmd) >> 16)) { + switch ((host_byte(cmd->result))) { case DID_RESET: /* Issue marker command. */ if (!ha->flags.abort_isp_active) @@ -3711,7 +3711,7 @@ qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt, } else { /* Save ISP completion status */ - CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd); + to_scsi_result(cmd->result, qla1280_return_status(pkt, cmd)); if (scsi_status & SAM_STAT_CHECK_CONDITION) { if (comp_status != CS_ARS_FAILED) { diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c index 6b247c7cbeab..ddc99b0f6a8c 100644 --- a/drivers/scsi/qla2xxx/qla_isr.c +++ b/drivers/scsi/qla2xxx/qla_isr.c @@ -2054,7 +2054,7 @@ qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len, if (track_sense_len != 0) { rsp->status_srb = sp; - cp->result = res; + to_scsi_result(cp->result, res); } if (sense_len) { @@ -2695,7 +2695,7 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) case CS_DIF_ERROR: logit = qla2x00_handle_dif_error(sp, sts24); - res = cp->result; + res = from_scsi_result(cp->result); break; case CS_TRANSPORT: @@ -2785,7 +2785,7 @@ qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt) /* Place command on done queue. */ if (sense_len == 0) { rsp->status_srb = NULL; - sp->done(sp, cp->result); + sp->done(sp, from_scsi_result(cp->result)); } } diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c index 521a51370554..5d4d3eb5b4f2 100644 --- a/drivers/scsi/qla2xxx/qla_mr.c +++ b/drivers/scsi/qla2xxx/qla_mr.c @@ -2158,7 +2158,7 @@ qlafx00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len, sense_len, par_sense_len, track_sense_len); if (GET_FW_SENSE_LEN(sp) > 0) { rsp->status_srb = sp; - cp->result = res; + to_scsi_result(cp->result, res); } if (sense_len) { @@ -2616,7 +2616,7 @@ qlafx00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt) /* Place command on done queue. */ if (sense_len == 0) { rsp->status_srb = NULL; - sp->done(sp, cp->result); + sp->done(sp, from_scsi_result(cp->result)); } } diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index 1757045901a5..8eb73f3f3c9c 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -740,7 +740,7 @@ qla2x00_sp_compl(void *ptr, int res) srb_t *sp = ptr; struct scsi_cmnd *cmd = GET_CMD_SP(sp); - cmd->result = res; + to_scsi_result(cmd->result, res); if (atomic_read(&sp->ref_count) == 0) { ql_dbg(ql_dbg_io, sp->vha, 0x3015, @@ -812,7 +812,7 @@ qla2xxx_qpair_sp_compl(void *ptr, int res) srb_t *sp = ptr; struct scsi_cmnd *cmd = GET_CMD_SP(sp); - cmd->result = res; + to_scsi_result(cmd->result, res); if (atomic_read(&sp->ref_count) == 0) { ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079, @@ -883,7 +883,7 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) rval = fc_remote_port_chkready(rport); if (rval) { - cmd->result = rval; + to_scsi_result(cmd->result, rval); ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003, "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n", cmd, rval); @@ -981,7 +981,7 @@ qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd, rval = fc_remote_port_chkready(rport); if (rval) { - cmd->result = rval; + to_scsi_result(cmd->result, rval); ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076, "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n", cmd, rval); diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 0992e59b7d34..229a0a6f088b 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -4097,7 +4097,7 @@ static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) rval = iscsi_session_chkready(sess); if (rval) { - cmd->result = rval; + to_scsi_result(cmd->result, rval); goto qc_fail_command; } @@ -4788,7 +4788,7 @@ static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res) for (i = 0; i < ha->host->can_queue; i++) { srb = qla4xxx_del_from_active_array(ha, i); if (srb != NULL) { - srb->cmd->result = res; + to_scsi_result(srb->cmd->result, res); kref_put(&srb->srb_ref, qla4xxx_srb_compl); } } @@ -9287,7 +9287,8 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, - ha->dpc_flags, cmd->result, cmd->allowed)); + ha->dpc_flags, from_scsi_result(cmd->result), + cmd->allowed)); rval = qla4xxx_isp_check_reg(ha); if (rval != QLA_SUCCESS) { @@ -9354,7 +9355,8 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, - ha->dpc_flags, cmd->result, cmd->allowed)); + ha->dpc_flags, from_scsi_result(cmd->result), + cmd->allowed)); rval = qla4xxx_isp_check_reg(ha); if (rval != QLA_SUCCESS) { diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c index 8c706430acee..2d3285618a70 100644 --- a/drivers/scsi/qlogicfas408.c +++ b/drivers/scsi/qlogicfas408.c @@ -415,7 +415,7 @@ static void ql_ihandl(void *dev_id) return; } icmd = priv->qlcmd; - icmd->result = ql_pcmd(icmd); + to_scsi_result(icmd->result, ql_pcmd(icmd)); priv->qlcmd = NULL; /* * If result is CHECK CONDITION done calls qcommand to request diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index e68b9f941e8a..2555efd32fc8 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -158,7 +158,8 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition) if (unlikely(scsi_logging_level)) { level = SCSI_LOG_LEVEL(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS); - if (((level > 0) && (cmd->result || disposition != SUCCESS)) || + if (((level > 0) && (from_scsi_result(cmd->result) || + disposition != SUCCESS)) || (level > 1)) { scsi_print_result(cmd, "Done", disposition); scsi_print_command(cmd); @@ -228,7 +229,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd) SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev, "Notifying upper driver of completion " - "(result %x)\n", cmd->result)); + "(result %x)\n", from_scsi_result(cmd->result))); good_bytes = scsi_bufflen(cmd); if (!blk_rq_is_passthrough(cmd->request)) { diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9ef5e3b810f6..fdf4dabedd72 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4398,7 +4398,10 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, return SCSI_MLQUEUE_HOST_BUSY; } - cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; + if (pfp != NULL) + to_scsi_result(cmnd->result, pfp(cmnd, devip)); + else + clear_scsi_result(cmnd); if (cmnd->result & SDEG_RES_IMMED_MASK) { /* * This is the F_DELAY_OVERR case. No delay. @@ -4406,12 +4409,12 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, cmnd->result &= ~SDEG_RES_IMMED_MASK; delta_jiff = ndelay = 0; } - if (cmnd->result == 0 && scsi_result != 0) - cmnd->result = scsi_result; + if (from_scsi_result(cmnd->result) == 0 && scsi_result != 0) + to_scsi_result(cmnd->result, scsi_result); - if (unlikely(sdebug_verbose && cmnd->result)) + if (unlikely(sdebug_verbose && from_scsi_result(cmnd->result))) sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", - __func__, cmnd->result); + __func__, from_scsi_result(cmnd->result)); if (delta_jiff > 0 || ndelay > 0) { ktime_t kt; @@ -4455,10 +4458,14 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, return 0; respond_in_thread: /* call back to mid-layer using invocation thread */ - cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; + if (pfp != NULL) + to_scsi_result(cmnd->result, pfp(cmnd, devip)); + else + clear_scsi_result(cmnd); + cmnd->result &= ~SDEG_RES_IMMED_MASK; - if (cmnd->result == 0 && scsi_result != 0) - cmnd->result = scsi_result; + if (from_scsi_result(cmnd->result) == 0 && scsi_result != 0) + to_scsi_result(cmnd->result, scsi_result); cmnd->scsi_done(cmnd); return 0; } diff --git a/drivers/scsi/scsi_debugfs.c b/drivers/scsi/scsi_debugfs.c index b784002ef0bd..24ad7e1cc690 100644 --- a/drivers/scsi/scsi_debugfs.c +++ b/drivers/scsi/scsi_debugfs.c @@ -43,7 +43,7 @@ void scsi_show_rq(struct seq_file *m, struct request *rq) if (cdb) __scsi_format_command(buf, sizeof(buf), cdb, cmd->cmd_len); seq_printf(m, ", .cmd=%s, .retries=%d, .result = %#x, .flags=", buf, - cmd->retries, cmd->result); + cmd->retries, from_scsi_result(cmd->result)); scsi_flags_show(m, cmd->flags, scsi_cmd_flags, ARRAY_SIZE(scsi_cmd_flags)); seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 33069cd3bd3b..001e17ac30c4 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -754,7 +754,7 @@ static void scsi_eh_done(struct scsi_cmnd *scmd) struct completion *eh_action; SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, - "%s result: %x\n", __func__, scmd->result)); + "%s result: %x\n", __func__, from_scsi_result(scmd->result))); eh_action = scmd->device->host->eh_action; if (eh_action) @@ -948,7 +948,7 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses, ses->data_direction = scmd->sc_data_direction; ses->sdb = scmd->sdb; ses->next_rq = scmd->request->next_rq; - ses->result = scmd->result; + ses->result = from_scsi_result(scmd->result); ses->underflow = scmd->underflow; ses->prot_op = scmd->prot_op; ses->eh_eflags = scmd->eh_eflags; @@ -1012,7 +1012,7 @@ void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses) scmd->sc_data_direction = ses->data_direction; scmd->sdb = ses->sdb; scmd->request->next_rq = ses->next_rq; - scmd->result = ses->result; + to_scsi_result(scmd->result, ses->result); scmd->underflow = ses->underflow; scmd->prot_op = ses->prot_op; scmd->eh_eflags = ses->eh_eflags; @@ -1213,7 +1213,7 @@ int scsi_eh_get_sense(struct list_head *work_q, continue; SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, - "sense requested, result %x\n", scmd->result)); + "sense requested, result %x\n", from_scsi_result(scmd->result))); SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd)); rtn = scsi_decide_disposition(scmd); @@ -1757,7 +1757,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd) * nuke this special code so that it looks like we are saying * did_ok. */ - scmd->result &= 0xff00ffff; + set_host_byte(scmd, DID_OK); return SUCCESS; case DID_OK: /* @@ -2067,7 +2067,7 @@ void scsi_eh_flush_done_q(struct list_head *done_q) * scsi_eh_get_sense), scmd->result is already * set, do not set DRIVER_TIMEOUT. */ - if (!scmd->result) + if (!from_scsi_result(scmd->result)) set_driver_byte(scmd, DRIVER_TIMEOUT); SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 0a875491f5a7..170a3f2b19de 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -100,7 +100,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev, "Ioctl returned 0x%x\n", result)); - if ((driver_byte(result) & DRIVER_SENSE) && + if (((result >> 24) == DRIVER_SENSE) && (scsi_sense_valid(&sshdr))) { switch (sshdr.sense_key) { case ILLEGAL_REQUEST: diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 69420eb6d68d..1cf6ba7570e7 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -732,7 +732,10 @@ static bool scsi_end_request(struct request *req, blk_status_t error, */ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result) { - switch (host_byte(result)) { + struct scsi_result scsi_result = { 0 }; + + to_scsi_result(scsi_result, result); + switch (host_byte(scsi_result)) { case DID_OK: /* * Also check the other bytes than the status byte in result @@ -791,7 +794,7 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result) */ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) { - int result = cmd->result; + int result = from_scsi_result(cmd->result); struct request_queue *q = cmd->device->request_queue; struct request *req = cmd->request; blk_status_t error = BLK_STS_OK; @@ -824,7 +827,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) /* * scsi_result_to_blk_status may have reset the host_byte */ - scsi_req(req)->result = cmd->result; + scsi_req(req)->result = result; scsi_req(req)->resid_len = scsi_get_resid(cmd); if (scsi_bidi_cmnd(cmd)) { @@ -884,7 +887,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) * if it can't fit). Treat SAM_STAT_CONDITION_MET and the related * intermediate statuses (both obsolete in SAM-4) as good. */ - if (status_byte(result) && scsi_status_is_good(result)) { + if (status_byte(cmd->result) && scsi_status_is_good(result)) { result = 0; error = BLK_STS_OK; } @@ -916,7 +919,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) error = scsi_result_to_blk_status(cmd, result); - if (host_byte(result) == DID_RESET) { + if (host_byte(cmd->result) == DID_RESET) { /* Third party bus reset or reset for error recovery * reasons. Just retry the command and see what * happens. @@ -1027,7 +1030,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) */ if (!level && __ratelimit(&_rs)) { scsi_print_result(cmd, NULL, FAILED); - if (driver_byte(result) & DRIVER_SENSE) + if (driver_byte(cmd->result) & DRIVER_SENSE) scsi_print_sense(cmd); scsi_print_command(cmd); } @@ -1665,7 +1668,7 @@ static void scsi_softirq_done(struct request *rq) INIT_LIST_HEAD(&cmd->eh_entry); atomic_inc(&cmd->device->iodone_cnt); - if (cmd->result) + if (from_scsi_result(cmd->result)) atomic_inc(&cmd->device->ioerr_cnt); disposition = scsi_decide_disposition(cmd); @@ -2575,7 +2578,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, * ILLEGAL REQUEST if the code page isn't supported */ if (use_10_for_ms && !scsi_status_is_good(result) && - (driver_byte(result) & DRIVER_SENSE)) { + ((result >> 24) == DRIVER_SENSE)) { if (scsi_sense_valid(sshdr)) { if ((sshdr->sense_key == ILLEGAL_REQUEST) && (sshdr->asc == 0x20) && (sshdr->ascq == 0)) { @@ -2612,7 +2615,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, data->block_descriptor_length = buffer[3]; } data->header_length = header_length; - } else if ((status_byte(result) == CHECK_CONDITION) && + } else if (((result & 0xff) == SAM_STAT_CHECK_CONDITION) && scsi_sense_valid(sshdr) && sshdr->sense_key == UNIT_ATTENTION && retry_count) { retry_count--; diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c index bd70339c1242..6e5ef3c25fcd 100644 --- a/drivers/scsi/scsi_logging.c +++ b/drivers/scsi/scsi_logging.c @@ -431,8 +431,9 @@ void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg, char *logbuf; size_t off, logbuf_len; const char *mlret_string = scsi_mlreturn_string(disposition); - const char *hb_string = scsi_hostbyte_string(cmd->result); - const char *db_string = scsi_driverbyte_string(cmd->result); + int result = from_scsi_result(cmd->result); + const char *hb_string = scsi_hostbyte_string(result); + const char *db_string = scsi_driverbyte_string(result); logbuf = scsi_log_reserve_buffer(&logbuf_len); if (!logbuf) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 0880d975eed3..67e34f5c10c5 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -614,7 +614,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result, * INQUIRY should not yield UNIT_ATTENTION * but many buggy devices do so anyway. */ - if ((driver_byte(result) & DRIVER_SENSE) && + if (((result >> 24) == DRIVER_SENSE) && scsi_sense_valid(&sshdr)) { if ((sshdr.sense_key == UNIT_ATTENTION) && ((sshdr.asc == 0x28) || diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index 2ca150b16764..999685b07458 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -136,7 +136,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER, 0, NULL); - if (!(driver_byte(result) & DRIVER_SENSE) || + if (!((result >> 24) == DRIVER_SENSE) || sshdr->sense_key != UNIT_ATTENTION) break; } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index ae689877528c..9e0ab6d9e6f1 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1574,7 +1574,7 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing) &sshdr); /* failed to execute TUR, assume media not present */ - if (host_byte(retval)) { + if (retval >> 16) { set_media_not_present(sdkp); goto out; } @@ -1635,7 +1635,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr) if (res) { sd_print_result(sdkp, "Synchronize Cache(10) failed", res); - if (driver_byte(res) & DRIVER_SENSE) + if ((res >> 24) == DRIVER_SENSE) sd_print_sense_hdr(sdkp, sshdr); /* we need to evaluate the error return */ @@ -1645,7 +1645,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr) /* this is no error here */ return 0; - switch (host_byte(res)) { + switch (res >> 16) { /* ignore errors due to racing a disconnection */ case DID_BAD_TARGET: case DID_NO_CONNECT: @@ -1737,7 +1737,7 @@ static int sd_pr_command(struct block_device *bdev, u8 sa, result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, &data, sizeof(data), &sshdr, SD_TIMEOUT, SD_MAX_RETRIES, NULL); - if ((driver_byte(result) & DRIVER_SENSE) && + if (((result >> 24) == DRIVER_SENSE) && (scsi_sense_valid(&sshdr))) { sdev_printk(KERN_INFO, sdev, "PR command failed: %d\n", result); scsi_print_sense_hdr(sdev, NULL, &sshdr); @@ -1929,7 +1929,7 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) **/ static int sd_done(struct scsi_cmnd *SCpnt) { - int result = SCpnt->result; + int result = from_scsi_result(SCpnt->result); unsigned int good_bytes = result ? 0 : scsi_bufflen(SCpnt); unsigned int sector_size = SCpnt->device->sector_size; unsigned int resid; @@ -1986,7 +1986,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) } sdkp->medium_access_timed_out = 0; - if (driver_byte(result) != DRIVER_SENSE && + if ((result >> 24) != DRIVER_SENSE && (!sense_valid || sense_deferred)) goto out; @@ -2095,10 +2095,10 @@ sd_spinup_disk(struct scsi_disk *sdkp) retries++; } while (retries < 3 && (!scsi_status_is_good(the_result) || - ((driver_byte(the_result) & DRIVER_SENSE) && + (((the_result >> 24) & DRIVER_SENSE) && sense_valid && sshdr.sense_key == UNIT_ATTENTION))); - if ((driver_byte(the_result) & DRIVER_SENSE) == 0) { + if (((the_result >> 24) & DRIVER_SENSE) == 0) { /* no sense, TUR either succeeded or failed * with a status error */ if(!spintime && !scsi_status_is_good(the_result)) { @@ -2222,7 +2222,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, struct scsi_sense_hdr *sshdr, int sense_valid, int the_result) { - if (driver_byte(the_result) & DRIVER_SENSE) + if ((the_result >> 24) & DRIVER_SENSE) sd_print_sense_hdr(sdkp, sshdr); else sd_printk(KERN_NOTICE, sdkp, "Sense not available.\n"); @@ -3488,7 +3488,7 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start) SD_TIMEOUT, SD_MAX_RETRIES, 0, RQF_PM, NULL); if (res) { sd_print_result(sdkp, "Start/Stop Unit failed", res); - if (driver_byte(res) & DRIVER_SENSE) + if ((res >> 24) & DRIVER_SENSE) sd_print_sense_hdr(sdkp, &sshdr); if (scsi_sense_valid(&sshdr) && /* 0x3a is medium not present */ @@ -3708,6 +3708,6 @@ static void sd_print_result(const struct scsi_disk *sdkp, const char *msg, else sd_printk(KERN_INFO, sdkp, "%s: Result: hostbyte=0x%02x driverbyte=0x%02x\n", - msg, host_byte(result), driver_byte(result)); + msg, result >> 16, result >> 24); } diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 41df75eea57b..32e656de7541 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -94,7 +94,7 @@ static int sd_zbc_report_zones(struct scsi_disk *sdkp, unsigned char *buf, sd_printk(KERN_ERR, sdkp, "REPORT ZONES lba %llu failed with %d/%d\n", (unsigned long long)lba, - host_byte(result), driver_byte(result)); + result >> 16, result >> 24); return -EIO; } @@ -279,7 +279,7 @@ int sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd) void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, struct scsi_sense_hdr *sshdr) { - int result = cmd->result; + int result = from_scsi_result(cmd->result); struct request *rq = cmd->request; switch (req_op(rq)) { diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index c198b96368dd..000a1db8ffae 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1327,10 +1327,10 @@ sg_rq_end_io(struct request *rq, blk_status_t status) struct scsi_sense_hdr sshdr; srp->header.status = 0xff & result; - srp->header.masked_status = status_byte(result); - srp->header.msg_status = msg_byte(result); - srp->header.host_status = host_byte(result); - srp->header.driver_status = driver_byte(result); + srp->header.masked_status = result >> 1; + srp->header.msg_status = result >> 8; + srp->header.host_status = result >> 16; + srp->header.driver_status = result >> 24; if ((sdp->sgdebug > 0) && ((CHECK_CONDITION == srp->header.masked_status) || (COMMAND_TERMINATED == srp->header.masked_status))) @@ -1338,7 +1338,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status) SCSI_SENSE_BUFFERSIZE); /* Following if statement is a patch supplied by Eric Youngdale */ - if (driver_byte(result) != 0 + if ((result >> 24) != 0 && scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr) && !scsi_sense_is_deferred(&sshdr) && sshdr.sense_key == UNIT_ATTENTION diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c index 1b1a8f020687..9152cc5e6a58 100644 --- a/drivers/scsi/snic/snic_scsi.c +++ b/drivers/scsi/snic/snic_scsi.c @@ -342,7 +342,7 @@ snic_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *sc) if (ret) { SNIC_HOST_ERR(shost, "Tgt %p id %d Not Ready.\n", tgt, tgt->id); atomic64_inc(&snic->s_stats.misc.tgt_not_rdy); - sc->result = ret; + to_scsi_result(sc->result, ret); sc->scsi_done(sc); return 0; diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 3f3cb72e0c0c..dff9504762fa 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -317,7 +317,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, */ static int sr_done(struct scsi_cmnd *SCpnt) { - int result = SCpnt->result; + int result = from_scsi_result(SCpnt->result); int this_count = scsi_bufflen(SCpnt); int good_bytes = (result == 0 ? this_count : 0); int block_sectors = 0; @@ -334,7 +334,7 @@ static int sr_done(struct scsi_cmnd *SCpnt) * care is taken to avoid unnecessary additional work such as * memcpy's that could be avoided. */ - if (driver_byte(result) != 0 && /* An error occurred */ + if ((result >> 24) != 0 && /* An error occurred */ (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */ switch (SCpnt->sense_buffer[2]) { case MEDIUM_ERROR: diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index 2a21f2d48592..6a497cad2df3 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c @@ -203,7 +203,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) cgc->timeout, IOCTL_RETRIES, 0, 0, NULL); /* Minimal error checking. Ignore cases we know about, and report the rest. */ - if (driver_byte(result) != 0) { + if ((result >> 24) != 0) { switch (sshdr.sense_key) { case UNIT_ATTENTION: SDev->changed = 1; diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 6c399480783d..9bd240cdd197 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -387,7 +387,7 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) if (!cmdstatp->have_sense) st_printk(KERN_WARNING, STp, "Error %x (driver bt 0x%x, host bt 0x%x).\n", - result, driver_byte(result), host_byte(result)); + result, result >> 24, result >> 16); else if (cmdstatp->have_sense && scode != NO_SENSE && scode != RECOVERED_ERROR && diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index 094f98650884..27d9f2b23405 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -775,7 +775,7 @@ static void stex_scsi_done(struct st_ccb *ccb) break; } - cmd->result = result; + to_scsi_result(cmd->result, result); cmd->scsi_done(cmd); } diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index e62b9e434bbe..5c2f48c3350a 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1012,7 +1012,7 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request, set_status_byte(scmnd, vm_srb->scsi_status); - if (scmnd->result) { + if (from_scsi_result(scmnd->result) != 0) { if (scsi_normalize_sense(scmnd->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr) && !(sense_hdr.sense_key == NOT_READY && diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.h b/drivers/scsi/sym53c8xx_2/sym_glue.h index c12057b5549f..e9f153c4a574 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.h +++ b/drivers/scsi/sym53c8xx_2/sym_glue.h @@ -237,7 +237,6 @@ static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host) static inline void sym_set_cam_status(struct scsi_cmnd *cmd, int status) { - cmd->result &= ~(0xff << 16); set_host_byte(cmd, status); } diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c5b1bf1cadcb..99e150fe2a2c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4552,7 +4552,7 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) break; } /* end of switch */ - if (host_byte(result) != DID_OK) + if ((result >> 16) != DID_OK) ufshcd_print_trs(hba, 1 << lrbp->task_tag, true); return result; } @@ -4596,7 +4596,7 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, ufshcd_add_command_trace(hba, index, "complete"); result = ufshcd_transfer_rsp_status(hba, lrbp); scsi_dma_unmap(cmd); - cmd->result = result; + to_scsi_result(cmd->result, result); /* Mark completed command as NULL in LRB */ lrbp->cmd = NULL; clear_bit_unlock(index, &hba->lrb_in_use); @@ -7050,7 +7050,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, sdev_printk(KERN_WARNING, sdp, "START_STOP failed for power mode: %d, result %x\n", pwr_mode, ret); - if (driver_byte(ret) & DRIVER_SENSE) + if ((ret >> 24) == DRIVER_SENSE) scsi_print_sense_hdr(sdp, NULL, &sshdr); } diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c index 7f96730cc123..0b8b752449af 100644 --- a/drivers/scsi/vmw_pvscsi.c +++ b/drivers/scsi/vmw_pvscsi.c @@ -632,7 +632,8 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter, dev_dbg(&cmd->device->sdev_gendev, "cmd=%p %x ctx=%p result=0x%x status=0x%x,%x\n", - cmd, cmd->cmnd[0], ctx, cmd->result, btstat, sdstat); + cmd, cmd->cmnd[0], ctx, from_scsi_result(cmd->result), + btstat, sdstat); cmd->scsi_done(cmd); } diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c index e619470cfe49..113cb172c1d3 100644 --- a/drivers/scsi/xen-scsifront.c +++ b/drivers/scsi/xen-scsifront.c @@ -261,7 +261,7 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_info *info, scsifront_gnttab_done(info, shadow); scsifront_put_rqid(info, id); - sc->result = ring_rsp->rslt; + to_scsi_result(sc->result, ring_rsp->rslt); scsi_set_resid(sc, ring_rsp->residual_len); sense_len = min_t(uint8_t, VSCSIIF_SENSE_BUFFERSIZE, diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c index 9c4fec4f6bae..9b22204d158d 100644 --- a/drivers/staging/unisys/visorhba/visorhba_main.c +++ b/drivers/staging/unisys/visorhba/visorhba_main.c @@ -815,7 +815,7 @@ static void do_scsi_linuxstat(struct uiscmdrsp *cmdrsp, /* Do not log errors for disk-not-present inquiries */ if (cmdrsp->scsi.cmnd[0] == INQUIRY && - (host_byte(cmdrsp->scsi.linuxstat) == DID_NO_CONNECT) && + ((cmdrsp->scsi.linuxstat >> 16) == DID_NO_CONNECT) && cmdrsp->scsi.addlstat == ADDL_SEL_TIMEOUT) return; /* Okay see what our error_count is here.... */ @@ -919,7 +919,7 @@ static void complete_scsi_command(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd) { /* take what we need out of cmdrsp and complete the scsicmd */ - scsicmd->result = cmdrsp->scsi.linuxstat; + to_scsi_result(scsicmd->result, cmdrsp->scsi.linuxstat); if (cmdrsp->scsi.linuxstat) do_scsi_linuxstat(cmdrsp, scsicmd); else diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 0d99b242e82e..88af752dee82 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -1048,13 +1049,16 @@ static void pscsi_req_done(struct request *req, blk_status_t status) { struct se_cmd *cmd = req->end_io_data; struct pscsi_plugin_task *pt = cmd->priv; - int result = scsi_req(req)->result; - u8 scsi_status = status_byte(result) << 1; + struct scsi_result result = { 0 }; + enum scsi_status_byte scsi_status; + + to_scsi_result(result, scsi_req(req)->result); + scsi_status = status_byte(result); if (scsi_status) { pr_debug("PSCSI Status Byte exception at cmd: %p CDB:" " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0], - result); + from_scsi_result(result)); } pscsi_complete_cmd(cmd, scsi_status, scsi_req(req)->sense); @@ -1066,7 +1070,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status) default: pr_debug("PSCSI Host Byte exception at cmd: %p CDB:" " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0], - result); + from_scsi_result(result)); target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION); break; } diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 37b799c1681c..ac5a88fec6ef 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c @@ -135,6 +135,7 @@ #include #include "../../scsi/scsi.h" #include +#include #include "microtek.h" @@ -406,10 +407,10 @@ static void mts_transfer_cleanup( struct urb *transfer ) static void mts_transfer_done( struct urb *transfer ) { - enum status_byte scsi_stauts; + enum scsi_status_byte scsi_status; MTS_INT_INIT(); - scsi_status = (enum status_byte)(*context->scsi_status) << 1); + scsi_status = (enum scsi_status_byte)(*context->scsi_status) << 1; set_status_byte(context->srb, scsi_status); mts_transfer_cleanup(transfer); @@ -439,8 +440,9 @@ static void mts_data_done( struct urb* transfer ) scsi_set_resid(context->srb, context->data_length - transfer->actual_length); } else if ( unlikely(status) ) { - enum host_byte shb = status == -ENOENT ? DID_ABORT : DID_ERROR; + enum scsi_host_byte shb; + shb = status == -ENOENT ? DID_ABORT : DID_ERROR; set_host_byte(context->srb, shb); } @@ -499,8 +501,9 @@ static void mts_do_sg (struct urb* transfer) scsi_sg_count(context->srb)); if (unlikely(status)) { - enum host_byte shb = status == -ENOENT ? DID_ABORT : DID_ERROR; + enum scsi_host_byte shb; + shb = status == -ENOENT ? DID_ABORT : DID_ERROR; set_host_byte(context->srb, shb); mts_transfer_cleanup(transfer); } diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c index 4dfaa0e0d3eb..4162422da8b9 100644 --- a/drivers/usb/storage/cypress_atacb.c +++ b/drivers/usb/storage/cypress_atacb.c @@ -147,7 +147,7 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) usb_stor_transparent_scsi_command(srb, us); /* if the device doesn't support ATACB */ - if (srb->result == SAM_STAT_CHECK_CONDITION && + if (status_byte(srb->result) == SAM_STAT_CHECK_CONDITION && memcmp(srb->sense_buffer, usb_stor_sense_invalidCDB, sizeof(usb_stor_sense_invalidCDB)) == 0) { usb_stor_dbg(us, "cypress atacb not supported ???\n"); @@ -158,8 +158,8 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) * if ck_cond flags is set, and there wasn't critical error, * build the special sense */ - if ((srb->result != (DID_ERROR << 16) && - srb->result != (DID_ABORT << 16)) && + if ((host_byte(srb->result) != DID_ERROR && + host_byte(srb->result) != DID_ABORT) && save_cmnd[2] & 0x20) { struct scsi_eh_save ses; unsigned char regs[8]; @@ -181,7 +181,7 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) usb_stor_transparent_scsi_command(srb, us); memcpy(regs, srb->sense_buffer, sizeof(regs)); - tmp_result = srb->result; + tmp_result = from_scsi_result(srb->result); scsi_eh_restore_cmnd(srb, &ses); /* we fail to get registers, report invalid command */ if (tmp_result != SAM_STAT_GOOD) diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c index fefe93108577..644640ef25af 100644 --- a/drivers/usb/storage/transport.c +++ b/drivers/usb/storage/transport.c @@ -555,7 +555,8 @@ static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb) if (sector + 1 != sdkp->capacity) goto done; - if (srb->result == SAM_STAT_GOOD && scsi_get_resid(srb) == 0) { + if (status_byte(srb->result) == SAM_STAT_GOOD + && scsi_get_resid(srb) == 0) { /* * The command succeeded. We know this device doesn't diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 3c4903b16769..d608920d65b6 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -316,7 +316,7 @@ static void uas_stat_cmplt(struct urb *urb) switch (iu->iu_id) { case IU_ID_STATUS: uas_sense(urb, cmnd); - if (cmnd->result != 0) { + if (from_scsi_result(cmnd->result) != 0) { /* cancel data transfers on error */ data_in_urb = usb_get_urb(cmdinfo->data_in_urb); data_out_urb = usb_get_urb(cmdinfo->data_out_urb); diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 09ac2d6cdd01..1a0dd1bcfe9b 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -389,7 +389,7 @@ static int usb_stor_control_thread(void * __us) scsi_lock(host); /* was the command aborted? */ - if (srb->result == DID_ABORT << 16) { + if (host_byte(srb->result) == DID_ABORT << 16) { SkipForAbort: usb_stor_dbg(us, "scsi command aborted\n"); srb = NULL; /* Don't call srb->scsi_done() */ @@ -420,7 +420,7 @@ static int usb_stor_control_thread(void * __us) /* now that the locks are released, notify the SCSI core */ if (srb) { usb_stor_dbg(us, "scsi cmd done, result=0x%x\n", - srb->result); + from_scsi_result(srb->result)); srb->scsi_done(srb); } } /* for (;;) */ diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 7bc88fd43cfc..5632c8933653 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -259,11 +259,13 @@ static void scsiback_print_status(char *sense_buffer, int errors, struct vscsibk_pend *pending_req) { struct scsiback_tpg *tpg = pending_req->v2p->tpg; + struct scsi_result res = { 0 }; + to_scsi_result(res, errors); pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x drv=%02x\n", tpg->tport->tport_name, pending_req->v2p->lun, - pending_req->cmnd[0], status_byte(errors), msg_byte(errors), - host_byte(errors), driver_byte(errors)); + pending_req->cmnd[0], status_byte(res), msg_byte(res), + host_byte(res), driver_byte(res)); } static void scsiback_fast_flush_area(struct vscsibk_pend *req) diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index bec7c345191c..c354b169cf79 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -203,6 +203,27 @@ enum scsi_driver_byte { #define SCSI_MLQUEUE_EH_RETRY 0x1057 #define SCSI_MLQUEUE_TARGET_BUSY 0x1058 +struct scsi_result { + u8 driver_byte; + u8 host_byte; + u8 msg_byte; + u8 status_byte; +}; + +static inline int from_scsi_result(struct scsi_result r) +{ + return r.driver_byte << 24 | r.host_byte << 16 | r.msg_byte << 8 + | r.status_byte; +} + +static inline void to_scsi_result(struct scsi_result r, int res) +{ + r.driver_byte = (res & 0xff000000) << 24; + r.host_byte = (res & 0x00ff0000) << 16; + r.msg_byte = (res & 0x0000ff00) << 8; + r.status_byte = res & 0xff; +} + /* * Use these to separate status msg and our bytes * @@ -213,24 +234,24 @@ enum scsi_driver_byte { * host_byte = set by low-level driver to indicate status. * driver_byte = set by mid-level. */ -static inline enum scsi_status_byte status_byte(int result) +static inline enum scsi_status_byte status_byte(struct scsi_result result) { - return (result >> 1) & 0x7f; + return result.status_byte; } -static inline enum scsi_msg_byte msg_byte(int result) +static inline enum scsi_msg_byte msg_byte(struct scsi_result result) { - return (result >> 8) & 0xff; + return result.msg_byte; } -static inline enum scsi_host_byte host_byte(int result) +static inline enum scsi_host_byte host_byte(struct scsi_result result) { - return (result >> 16) & 0xff; + return result.host_byte; } -static inline enum scsi_driver_byte driver_byte(int result) +static inline enum scsi_driver_byte driver_byte(struct scsi_result result) { - return (result >> 24) & 0xff; + return result.driver_byte; } #define sense_class(sense) (((sense) >> 4) & 0x7) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index f1baac59dc16..a34ee63377ed 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -10,6 +10,7 @@ #include #include #include +#include struct Scsi_Host; struct scsi_driver; @@ -144,7 +145,7 @@ struct scsi_cmnd { * obtained by scsi_malloc is guaranteed * to be at an address < 16Mb). */ - int result; /* Status code from lower level driver */ + struct scsi_result result; /* Status code from LLDD */ int flags; /* Command flags */ unsigned char tag; /* SCSI-II queued command tag */ @@ -340,25 +341,25 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd) static inline void set_msg_byte(struct scsi_cmnd *cmd, enum scsi_msg_byte status) { - cmd->result = (cmd->result & 0xffff00ff) | (status << 8); + cmd->result.msg_byte = status; } static inline void set_host_byte(struct scsi_cmnd *cmd, enum scsi_host_byte status) { - cmd->result = (cmd->result & 0xff00ffff) | (status << 16); + cmd->result.host_byte = status; } static inline void set_driver_byte(struct scsi_cmnd *cmd, enum scsi_driver_byte status) { - cmd->result = (cmd->result & 0x00ffffff) | (status << 24); + cmd->result.driver_byte = status; } static inline void set_status_byte(struct scsi_cmnd *cmd, char status) { - cmd->result = (cmd->result & 0xffffff00) | status; + cmd->result.status_byte = status; } static inline void set_scsi_result(struct scsi_cmnd *cmd, @@ -366,12 +367,15 @@ static inline void set_scsi_result(struct scsi_cmnd *cmd, enum scsi_host_byte hb, enum scsi_msg_byte mb, char status) { - cmd->result = db << 24 | hb << 16 | mb << 8 | status; + cmd->result.driver_byte = db; + cmd->result.host_byte = hb; + cmd->result.msg_byte = mb; + cmd->result.status_byte = status; } static inline void clear_scsi_result(struct scsi_cmnd *cmd) { - cmd->result = 0; + memset(&cmd->result, 0, FIELD_SIZEOF(struct scsi_cmnd, result)); } static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index f624969a4f14..40a5594c967a 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -309,7 +309,7 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template, __entry->channel = cmd->device->channel; __entry->id = cmd->device->id; __entry->lun = cmd->device->lun; - __entry->result = cmd->result; + __entry->result = from_scsi_result(cmd->result); __entry->opcode = cmd->cmnd[0]; __entry->cmd_len = cmd->cmd_len; __entry->data_sglen = scsi_sg_count(cmd);