📄 lpfc_scsi.c
字号:
if (lpfc_cmd->status) { if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && (lpfc_cmd->result & IOERR_DRVR_MASK)) lpfc_cmd->status = IOSTAT_DRIVER_REJECT; else if (lpfc_cmd->status >= IOSTAT_CNT) lpfc_cmd->status = IOSTAT_DEFAULT; lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, "%d:0729 FCP cmd x%x failed <%d/%d> status: " "x%x result: x%x Data: x%x x%x\n", phba->brd_no, cmd->cmnd[0], cmd->device->id, cmd->device->lun, lpfc_cmd->status, lpfc_cmd->result, pIocbOut->iocb.ulpContext, lpfc_cmd->cur_iocbq.iocb.ulpIoTag); switch (lpfc_cmd->status) { case IOSTAT_FCP_RSP_ERROR: /* Call FCP RSP handler to determine result */ lpfc_handle_fcp_err(lpfc_cmd); break; case IOSTAT_NPORT_BSY: case IOSTAT_FABRIC_BSY: cmd->result = ScsiResult(DID_BUS_BUSY, 0); break; default: cmd->result = ScsiResult(DID_ERROR, 0); break; } if ((pnode == NULL ) || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY); } else { cmd->result = ScsiResult(DID_OK, 0); } if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { uint32_t *lp = (uint32_t *)cmd->sense_buffer; lpfc_printf_log(phba, KERN_INFO, LOG_FCP, "%d:0710 Iodone <%d/%d> cmd %p, error x%x " "SNS x%x x%x Data: x%x x%x\n", phba->brd_no, cmd->device->id, cmd->device->lun, cmd, cmd->result, *lp, *(lp + 3), cmd->retries, cmd->resid); } cmd->scsi_done(cmd); spin_lock_irqsave(phba->host->host_lock, iflag); lpfc_release_scsi_buf(phba, lpfc_cmd); spin_unlock_irqrestore(phba->host->host_lock, iflag);}static voidlpfc_scsi_prep_cmnd(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_nodelist *pnode){ struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); int datadir = scsi_cmnd->sc_data_direction; lpfc_cmd->fcp_rsp->rspSnsLen = 0; /* clear task management bits */ lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; int_to_scsilun(lpfc_cmd->pCmd->device->lun, &lpfc_cmd->fcp_cmnd->fcp_lun); memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); if (scsi_cmnd->device->tagged_supported) { switch (scsi_cmnd->tag) { case HEAD_OF_QUEUE_TAG: fcp_cmnd->fcpCntl1 = HEAD_OF_Q; break; case ORDERED_QUEUE_TAG: fcp_cmnd->fcpCntl1 = ORDERED_Q; break; default: fcp_cmnd->fcpCntl1 = SIMPLE_Q; break; } } else fcp_cmnd->fcpCntl1 = 0; /* * There are three possibilities here - use scatter-gather segment, use * the single mapping, or neither. Start the lpfc command prep by * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first * data bde entry. */ if (scsi_cmnd->use_sg) { if (datadir == DMA_TO_DEVICE) { iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; iocb_cmd->un.fcpi.fcpi_parm = 0; iocb_cmd->ulpPU = 0; fcp_cmnd->fcpCntl3 = WRITE_DATA; phba->fc4OutputRequests++; } else { iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; iocb_cmd->ulpPU = PARM_READ_CHECK; iocb_cmd->un.fcpi.fcpi_parm = scsi_cmnd->request_bufflen; fcp_cmnd->fcpCntl3 = READ_DATA; phba->fc4InputRequests++; } } else if (scsi_cmnd->request_buffer && scsi_cmnd->request_bufflen) { if (datadir == DMA_TO_DEVICE) { iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; iocb_cmd->un.fcpi.fcpi_parm = 0; iocb_cmd->ulpPU = 0; fcp_cmnd->fcpCntl3 = WRITE_DATA; phba->fc4OutputRequests++; } else { iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; iocb_cmd->ulpPU = PARM_READ_CHECK; iocb_cmd->un.fcpi.fcpi_parm = scsi_cmnd->request_bufflen; fcp_cmnd->fcpCntl3 = READ_DATA; phba->fc4InputRequests++; } } else { iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; iocb_cmd->un.fcpi.fcpi_parm = 0; iocb_cmd->ulpPU = 0; fcp_cmnd->fcpCntl3 = 0; phba->fc4ControlRequests++; } /* * Finish initializing those IOCB fields that are independent * of the scsi_cmnd request_buffer */ piocbq->iocb.ulpContext = pnode->nlp_rpi; if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) piocbq->iocb.ulpFCP2Rcvy = 1; piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); piocbq->context1 = lpfc_cmd; piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;}static intlpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, uint8_t task_mgmt_cmd){ struct lpfc_sli *psli; struct lpfc_iocbq *piocbq; IOCB_t *piocb; struct fcp_cmnd *fcp_cmnd; struct scsi_device *scsi_dev = lpfc_cmd->pCmd->device; struct lpfc_rport_data *rdata = scsi_dev->hostdata; struct lpfc_nodelist *ndlp = rdata->pnode; if ((ndlp == NULL) || (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { return 0; } psli = &phba->sli; piocbq = &(lpfc_cmd->cur_iocbq); piocb = &piocbq->iocb; fcp_cmnd = lpfc_cmd->fcp_cmnd; int_to_scsilun(lpfc_cmd->pCmd->device->lun, &lpfc_cmd->fcp_cmnd->fcp_lun); fcp_cmnd->fcpCntl2 = task_mgmt_cmd; piocb->ulpCommand = CMD_FCP_ICMND64_CR; piocb->ulpContext = ndlp->nlp_rpi; if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { piocb->ulpFCP2Rcvy = 1; } piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); /* ulpTimeout is only one byte */ if (lpfc_cmd->timeout > 0xff) { /* * Do not timeout the command at the firmware level. * The driver will provide the timeout mechanism. */ piocb->ulpTimeout = 0; } else { piocb->ulpTimeout = lpfc_cmd->timeout; } lpfc_cmd->rdata = rdata; switch (task_mgmt_cmd) { case FCP_LUN_RESET: /* Issue LUN Reset to TGT <num> LUN <num> */ lpfc_printf_log(phba, KERN_INFO, LOG_FCP, "%d:0703 Issue LUN Reset to TGT %d LUN %d " "Data: x%x x%x\n", phba->brd_no, scsi_dev->id, scsi_dev->lun, ndlp->nlp_rpi, ndlp->nlp_flag); break; case FCP_ABORT_TASK_SET: /* Issue Abort Task Set to TGT <num> LUN <num> */ lpfc_printf_log(phba, KERN_INFO, LOG_FCP, "%d:0701 Issue Abort Task Set to TGT %d LUN %d " "Data: x%x x%x\n", phba->brd_no, scsi_dev->id, scsi_dev->lun, ndlp->nlp_rpi, ndlp->nlp_flag); break; case FCP_TARGET_RESET: /* Issue Target Reset to TGT <num> */ lpfc_printf_log(phba, KERN_INFO, LOG_FCP, "%d:0702 Issue Target Reset to TGT %d " "Data: x%x x%x\n", phba->brd_no, scsi_dev->id, ndlp->nlp_rpi, ndlp->nlp_flag); break; } return (1);}static intlpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba){ struct lpfc_iocbq *iocbq; struct lpfc_iocbq *iocbqrsp; int ret; ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_TARGET_RESET); if (!ret) return FAILED; lpfc_cmd->scsi_hba = phba; iocbq = &lpfc_cmd->cur_iocbq; iocbqrsp = lpfc_sli_get_iocbq(phba); if (!iocbqrsp) return FAILED; ret = lpfc_sli_issue_iocb_wait(phba, &phba->sli.ring[phba->sli.fcp_ring], iocbq, iocbqrsp, lpfc_cmd->timeout); if (ret != IOCB_SUCCESS) { lpfc_cmd->status = IOSTAT_DRIVER_REJECT; ret = FAILED; } else { ret = SUCCESS; lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4]; lpfc_cmd->status = iocbqrsp->iocb.ulpStatus; if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && (lpfc_cmd->result & IOERR_DRVR_MASK)) lpfc_cmd->status = IOSTAT_DRIVER_REJECT; } lpfc_sli_release_iocbq(phba, iocbqrsp); return ret;}const char *lpfc_info(struct Scsi_Host *host){ struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0]; int len; static char lpfcinfobuf[384]; memset(lpfcinfobuf,0,384); if (phba && phba->pcidev){ strncpy(lpfcinfobuf, phba->ModelDesc, 256); len = strlen(lpfcinfobuf); snprintf(lpfcinfobuf + len, 384-len, " on PCI bus %02x device %02x irq %d", phba->pcidev->bus->number, phba->pcidev->devfn, phba->pcidev->irq); len = strlen(lpfcinfobuf); if (phba->Port[0]) { snprintf(lpfcinfobuf + len, 384-len, " port %s", phba->Port); } } return lpfcinfobuf;}static intlpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)){ struct lpfc_hba *phba = (struct lpfc_hba *) cmnd->device->host->hostdata[0]; struct lpfc_sli *psli = &phba->sli; struct lpfc_rport_data *rdata = cmnd->device->hostdata; struct lpfc_nodelist *ndlp = rdata->pnode; struct lpfc_scsi_buf *lpfc_cmd; struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); int err; err = fc_remote_port_chkready(rport); if (err) { cmnd->result = err; goto out_fail_command; } /* * Catch race where our node has transitioned, but the * transport is still transitioning. */ if (!ndlp) { cmnd->result = ScsiResult(DID_BUS_BUSY, 0); goto out_fail_command; } lpfc_cmd = lpfc_sli_get_scsi_buf (phba); if (lpfc_cmd == NULL) { printk(KERN_WARNING "%s: No buffer available - list empty, " "total count %d\n", __FUNCTION__, phba->total_scsi_bufs); goto out_host_busy; } /* * Store the midlayer's command structure for the completion phase * and complete the command initialization. */ lpfc_cmd->pCmd = cmnd; lpfc_cmd->rdata = rdata; lpfc_cmd->timeout = 0; cmnd->host_scribble = (unsigned char *)lpfc_cmd; cmnd->scsi_done = done; err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); if (err) goto out_host_busy_free_buf; lpfc_scsi_prep_cmnd(phba, lpfc_cmd, ndlp); err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); if (err) goto out_host_busy_free_buf; return 0; out_host_busy_free_buf: lpfc_release_scsi_buf(phba, lpfc_cmd); cmnd->host_scribble = NULL; out_host_busy: return SCSI_MLQUEUE_HOST_BUSY; out_fail_command: done(cmnd); return 0;}static int__lpfc_abort_handler(struct scsi_cmnd *cmnd){ struct lpfc_hba *phba = (struct lpfc_hba *)cmnd->device->host->hostdata[0]; struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring]; struct lpfc_iocbq *iocb; struct lpfc_iocbq *abtsiocb; struct lpfc_scsi_buf *lpfc_cmd; IOCB_t *cmd, *icmd; unsigned int loop_count = 0; int ret = SUCCESS; lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; BUG_ON(!lpfc_cmd); /* * If pCmd field of the corresponding lpfc_scsi_buf structure * points to a different SCSI command, then the driver has * already completed this command, but the midlayer did not * see the completion before the eh fired. Just return * SUCCESS. */ iocb = &lpfc_cmd->cur_iocbq; if (lpfc_cmd->pCmd != cmnd) goto out; BUG_ON(iocb->context1 != lpfc_cmd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -