Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[platform/kernel/linux-starfive.git] / drivers / scsi / lpfc / lpfc_scsi.c
index f6b8385..3b8afa9 100644 (file)
@@ -433,7 +433,7 @@ lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
                iocb->ulpClass = CLASS3;
                psb->status = IOSTAT_SUCCESS;
                /* Put it back into the SCSI buffer list */
-               psb->cur_iocbq.context1  = psb;
+               psb->cur_iocbq.io_buf = psb;
                spin_lock_init(&psb->buf_lock);
                lpfc_release_scsi_buf_s3(phba, psb);
 
@@ -3835,7 +3835,7 @@ lpfc_update_cmf_cmpl(struct lpfc_hba *phba,
                else
                        time = div_u64(time + 500, 1000); /* round it */
 
-               cgs = this_cpu_ptr(phba->cmf_stat);
+               cgs = per_cpu_ptr(phba->cmf_stat, raw_smp_processor_id());
                atomic64_add(size, &cgs->rcv_bytes);
                atomic64_add(time, &cgs->rx_latency);
                atomic_inc(&cgs->rx_io_cnt);
@@ -3879,7 +3879,7 @@ lpfc_update_cmf_cmd(struct lpfc_hba *phba, uint32_t size)
                        atomic_set(&phba->rx_max_read_cnt, size);
        }
 
-       cgs = this_cpu_ptr(phba->cmf_stat);
+       cgs = per_cpu_ptr(phba->cmf_stat, raw_smp_processor_id());
        atomic64_add(size, &cgs->total_bytes);
        return 0;
 }
@@ -4082,8 +4082,7 @@ static void
 lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
                         struct lpfc_iocbq *pwqeOut)
 {
-       struct lpfc_io_buf *lpfc_cmd =
-               (struct lpfc_io_buf *)pwqeIn->context1;
+       struct lpfc_io_buf *lpfc_cmd = pwqeIn->io_buf;
        struct lpfc_wcqe_complete *wcqe = &pwqeOut->wcqe_cmpl;
        struct lpfc_vport *vport = pwqeIn->vport;
        struct lpfc_rport_data *rdata;
@@ -4276,6 +4275,7 @@ lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
                        break;
                }
                if (lpfc_cmd->result == IOERR_INVALID_RPI ||
+                   lpfc_cmd->result == IOERR_LINK_DOWN ||
                    lpfc_cmd->result == IOERR_NO_RESOURCES ||
                    lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
                    lpfc_cmd->result == IOERR_RPI_SUSPENDED ||
@@ -4420,7 +4420,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
                        struct lpfc_iocbq *pIocbOut)
 {
        struct lpfc_io_buf *lpfc_cmd =
-               (struct lpfc_io_buf *) pIocbIn->context1;
+               (struct lpfc_io_buf *) pIocbIn->io_buf;
        struct lpfc_vport      *vport = pIocbIn->vport;
        struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
        struct lpfc_nodelist *pnode = rdata->pnode;
@@ -4743,7 +4743,7 @@ static int lpfc_scsi_prep_cmnd_buf_s3(struct lpfc_vport *vport,
                piocbq->iocb.ulpFCP2Rcvy = 0;
 
        piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
-       piocbq->context1  = lpfc_cmd;
+       piocbq->io_buf  = lpfc_cmd;
        if (!piocbq->cmd_cmpl)
                piocbq->cmd_cmpl = lpfc_scsi_cmd_iocb_cmpl;
        piocbq->iocb.ulpTimeout = tmo;
@@ -4855,8 +4855,7 @@ static int lpfc_scsi_prep_cmnd_buf_s4(struct lpfc_vport *vport,
        bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
 
        pwqeq->vport = vport;
-       pwqeq->vport = vport;
-       pwqeq->context1 = lpfc_cmd;
+       pwqeq->io_buf = lpfc_cmd;
        pwqeq->hba_wqidx = lpfc_cmd->hdwq_no;
        pwqeq->cmd_cmpl = lpfc_fcp_io_cmd_wqe_cmpl;
 
@@ -5097,8 +5096,7 @@ lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
                        struct lpfc_iocbq *cmdiocbq,
                        struct lpfc_iocbq *rspiocbq)
 {
-       struct lpfc_io_buf *lpfc_cmd =
-               (struct lpfc_io_buf *) cmdiocbq->context1;
+       struct lpfc_io_buf *lpfc_cmd = cmdiocbq->io_buf;
        if (lpfc_cmd)
                lpfc_release_scsi_buf(phba, lpfc_cmd);
        return;
@@ -5346,9 +5344,9 @@ static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
 {
        u64 *lta;
 
-       if (vport->vmid_priority_tagging)
+       if (vport->phba->pport->vmid_flag & LPFC_VMID_TYPE_PRIO)
                tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid;
-       else
+       else if (vport->phba->cfg_vmid_app_header)
                tag->app_id = vmp->un.app_id;
 
        if (cmd->sc_data_direction == DMA_TO_DEVICE)
@@ -5393,11 +5391,12 @@ static int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid, struct
                               scsi_cmnd * cmd, union lpfc_vmid_io_tag *tag)
 {
        struct lpfc_vmid *vmp = NULL;
-       int hash, len, rc, i;
+       int hash, len, rc = -EPERM, i;
 
        /* check if QFPA is complete */
-       if (lpfc_vmid_is_type_priority_tag(vport) && !(vport->vmid_flag &
-             LPFC_VMID_QFPA_CMPL)) {
+       if (lpfc_vmid_is_type_priority_tag(vport) &&
+           !(vport->vmid_flag & LPFC_VMID_QFPA_CMPL) &&
+           (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA)) {
                vport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
                return -EAGAIN;
        }
@@ -5471,7 +5470,7 @@ static int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid, struct
                        vport->vmid_inactivity_timeout ? 1 : 0;
 
                /* if type priority tag, get next available VMID */
-               if (lpfc_vmid_is_type_priority_tag(vport))
+               if (vport->phba->pport->vmid_flag & LPFC_VMID_TYPE_PRIO)
                        lpfc_vmid_assign_cs_ctl(vport, vmp);
 
                /* allocate the per cpu variable for holding */
@@ -5490,9 +5489,9 @@ static int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid, struct
                write_unlock(&vport->vmid_lock);
 
                /* complete transaction with switch */
-               if (lpfc_vmid_is_type_priority_tag(vport))
+               if (vport->phba->pport->vmid_flag & LPFC_VMID_TYPE_PRIO)
                        rc = lpfc_vmid_uvem(vport, vmp, true);
-               else
+               else if (vport->phba->cfg_vmid_app_header)
                        rc = lpfc_vmid_cmd(vport, SLI_CTAS_RAPP_IDENT, vmp);
                if (!rc) {
                        write_lock(&vport->vmid_lock);
@@ -5866,25 +5865,25 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
        if (!lpfc_cmd)
                return ret;
 
-       spin_lock_irqsave(&phba->hbalock, flags);
+       /* Guard against IO completion being called at same time */
+       spin_lock_irqsave(&lpfc_cmd->buf_lock, flags);
+
+       spin_lock(&phba->hbalock);
        /* driver queued commands are in process of being flushed */
        if (phba->hba_flag & HBA_IOQ_FLUSH) {
                lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
                        "3168 SCSI Layer abort requested I/O has been "
                        "flushed by LLD.\n");
                ret = FAILED;
-               goto out_unlock;
+               goto out_unlock_hba;
        }
 
-       /* Guard against IO completion being called at same time */
-       spin_lock(&lpfc_cmd->buf_lock);
-
        if (!lpfc_cmd->pCmd) {
                lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
                         "2873 SCSI Layer I/O Abort Request IO CMPL Status "
                         "x%x ID %d LUN %llu\n",
                         SUCCESS, cmnd->device->id, cmnd->device->lun);
-               goto out_unlock_buf;
+               goto out_unlock_hba;
        }
 
        iocb = &lpfc_cmd->cur_iocbq;
@@ -5892,7 +5891,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
                pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring;
                if (!pring_s4) {
                        ret = FAILED;
-                       goto out_unlock_buf;
+                       goto out_unlock_hba;
                }
                spin_lock(&pring_s4->ring_lock);
        }
@@ -5917,7 +5916,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
                goto out_unlock_ring;
        }
 
-       BUG_ON(iocb->context1 != lpfc_cmd);
+       WARN_ON(iocb->io_buf != lpfc_cmd);
 
        /* abort issued in recovery is still in progress */
        if (iocb->cmd_flag & LPFC_DRIVER_ABORTED) {
@@ -5925,8 +5924,8 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
                         "3389 SCSI Layer I/O Abort Request is pending\n");
                if (phba->sli_rev == LPFC_SLI_REV4)
                        spin_unlock(&pring_s4->ring_lock);
-               spin_unlock(&lpfc_cmd->buf_lock);
-               spin_unlock_irqrestore(&phba->hbalock, flags);
+               spin_unlock(&phba->hbalock);
+               spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags);
                goto wait_for_cmpl;
        }
 
@@ -5947,15 +5946,13 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
        if (ret_val != IOCB_SUCCESS) {
                /* Indicate the IO is not being aborted by the driver. */
                lpfc_cmd->waitq = NULL;
-               spin_unlock(&lpfc_cmd->buf_lock);
-               spin_unlock_irqrestore(&phba->hbalock, flags);
                ret = FAILED;
-               goto out;
+               goto out_unlock_hba;
        }
 
        /* no longer need the lock after this point */
-       spin_unlock(&lpfc_cmd->buf_lock);
-       spin_unlock_irqrestore(&phba->hbalock, flags);
+       spin_unlock(&phba->hbalock);
+       spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags);
 
        if (phba->cfg_poll & DISABLE_FCP_RING_INT)
                lpfc_sli_handle_fast_ring_event(phba,
@@ -5990,10 +5987,9 @@ wait_for_cmpl:
 out_unlock_ring:
        if (phba->sli_rev == LPFC_SLI_REV4)
                spin_unlock(&pring_s4->ring_lock);
-out_unlock_buf:
-       spin_unlock(&lpfc_cmd->buf_lock);
-out_unlock:
-       spin_unlock_irqrestore(&phba->hbalock, flags);
+out_unlock_hba:
+       spin_unlock(&phba->hbalock);
+       spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags);
 out:
        lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
                         "0749 SCSI Layer I/O Abort Request Status x%x ID %d "