Lines Matching +full:virtual +full:- +full:wire +full:- +full:mode
4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
29 #include <linux/t10-pi.h>
30 #include <linux/crc-t10dif.h>
31 #include <linux/blk-cgroup.h>
76 struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; in lpfc_rport_data_from_scsi_device()
78 if (vport->phba->cfg_fof) in lpfc_rport_data_from_scsi_device()
79 return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; in lpfc_rport_data_from_scsi_device()
81 return (struct lpfc_rport_data *)sdev->hostdata; in lpfc_rport_data_from_scsi_device()
92 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
103 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; in lpfc_sli4_set_rsp_sgl_last()
106 sgl->word2 = le32_to_cpu(sgl->word2); in lpfc_sli4_set_rsp_sgl_last()
108 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_sli4_set_rsp_sgl_last()
113 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
130 spin_lock_irqsave(&phba->hbalock, flags); in lpfc_rampdown_queue_depth()
131 atomic_inc(&phba->num_rsrc_err); in lpfc_rampdown_queue_depth()
132 phba->last_rsrc_error_time = jiffies; in lpfc_rampdown_queue_depth()
134 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; in lpfc_rampdown_queue_depth()
136 spin_unlock_irqrestore(&phba->hbalock, flags); in lpfc_rampdown_queue_depth()
140 phba->last_ramp_down_time = jiffies; in lpfc_rampdown_queue_depth()
142 spin_unlock_irqrestore(&phba->hbalock, flags); in lpfc_rampdown_queue_depth()
144 spin_lock_irqsave(&phba->pport->work_port_lock, flags); in lpfc_rampdown_queue_depth()
145 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; in lpfc_rampdown_queue_depth()
147 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; in lpfc_rampdown_queue_depth()
148 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); in lpfc_rampdown_queue_depth()
156 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
173 num_rsrc_err = atomic_read(&phba->num_rsrc_err); in lpfc_ramp_down_queue_handler()
185 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { in lpfc_ramp_down_queue_handler()
188 if (num_rsrc_err >= sdev->queue_depth) in lpfc_ramp_down_queue_handler()
191 new_queue_depth = sdev->queue_depth - in lpfc_ramp_down_queue_handler()
197 atomic_set(&phba->num_rsrc_err, 0); in lpfc_ramp_down_queue_handler()
201 * lpfc_scsi_dev_block - set all scsi hosts to block state
219 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { in lpfc_scsi_dev_block()
230 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
231 * @vport: The virtual port for which this call being executed.
234 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
236 * a SCSI I/O. The non-DMAable buffer region contains information to build
242 * int - number of scsi buffers that were allocated.
248 struct lpfc_hba *phba = vport->phba; in lpfc_new_scsi_buf_s3()
258 bpl_size = phba->cfg_sg_dma_buf_size - in lpfc_new_scsi_buf_s3()
263 num_to_alloc, phba->cfg_sg_dma_buf_size, in lpfc_new_scsi_buf_s3()
278 psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, in lpfc_new_scsi_buf_s3()
279 GFP_KERNEL, &psb->dma_handle); in lpfc_new_scsi_buf_s3()
280 if (!psb->data) { in lpfc_new_scsi_buf_s3()
286 /* Allocate iotag for psb->cur_iocbq. */ in lpfc_new_scsi_buf_s3()
287 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); in lpfc_new_scsi_buf_s3()
289 dma_pool_free(phba->lpfc_sg_dma_buf_pool, in lpfc_new_scsi_buf_s3()
290 psb->data, psb->dma_handle); in lpfc_new_scsi_buf_s3()
294 psb->cur_iocbq.cmd_flag |= LPFC_IO_FCP; in lpfc_new_scsi_buf_s3()
296 psb->fcp_cmnd = psb->data; in lpfc_new_scsi_buf_s3()
297 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); in lpfc_new_scsi_buf_s3()
298 psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) + in lpfc_new_scsi_buf_s3()
301 /* Initialize local short-hand pointers. */ in lpfc_new_scsi_buf_s3()
302 bpl = (struct ulp_bde64 *)psb->dma_sgl; in lpfc_new_scsi_buf_s3()
303 pdma_phys_fcp_cmd = psb->dma_handle; in lpfc_new_scsi_buf_s3()
304 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); in lpfc_new_scsi_buf_s3()
305 pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) + in lpfc_new_scsi_buf_s3()
330 iocb = &psb->cur_iocbq.iocb; in lpfc_new_scsi_buf_s3()
331 iocb->un.fcpi64.bdl.ulpIoTag32 = 0; in lpfc_new_scsi_buf_s3()
332 if ((phba->sli_rev == 3) && in lpfc_new_scsi_buf_s3()
333 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { in lpfc_new_scsi_buf_s3()
335 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; in lpfc_new_scsi_buf_s3()
336 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); in lpfc_new_scsi_buf_s3()
337 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, in lpfc_new_scsi_buf_s3()
339 iocb->un.fcpi64.bdl.addrHigh = 0; in lpfc_new_scsi_buf_s3()
340 iocb->ulpBdeCount = 0; in lpfc_new_scsi_buf_s3()
341 iocb->ulpLe = 0; in lpfc_new_scsi_buf_s3()
343 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = in lpfc_new_scsi_buf_s3()
345 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = in lpfc_new_scsi_buf_s3()
347 iocb->unsli3.fcp_ext.rbde.addrLow = in lpfc_new_scsi_buf_s3()
349 iocb->unsli3.fcp_ext.rbde.addrHigh = in lpfc_new_scsi_buf_s3()
352 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; in lpfc_new_scsi_buf_s3()
353 iocb->un.fcpi64.bdl.bdeSize = in lpfc_new_scsi_buf_s3()
355 iocb->un.fcpi64.bdl.addrLow = in lpfc_new_scsi_buf_s3()
357 iocb->un.fcpi64.bdl.addrHigh = in lpfc_new_scsi_buf_s3()
359 iocb->ulpBdeCount = 1; in lpfc_new_scsi_buf_s3()
360 iocb->ulpLe = 1; in lpfc_new_scsi_buf_s3()
362 iocb->ulpClass = CLASS3; in lpfc_new_scsi_buf_s3()
363 psb->status = IOSTAT_SUCCESS; in lpfc_new_scsi_buf_s3()
365 psb->cur_iocbq.io_buf = psb; in lpfc_new_scsi_buf_s3()
366 spin_lock_init(&psb->buf_lock); in lpfc_new_scsi_buf_s3()
375 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
384 struct lpfc_hba *phba = vport->phba; in lpfc_sli4_vport_delete_fcp_xri_aborted()
390 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) in lpfc_sli4_vport_delete_fcp_xri_aborted()
393 spin_lock_irqsave(&phba->hbalock, iflag); in lpfc_sli4_vport_delete_fcp_xri_aborted()
394 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { in lpfc_sli4_vport_delete_fcp_xri_aborted()
395 qp = &phba->sli4_hba.hdwq[idx]; in lpfc_sli4_vport_delete_fcp_xri_aborted()
397 spin_lock(&qp->abts_io_buf_list_lock); in lpfc_sli4_vport_delete_fcp_xri_aborted()
399 &qp->lpfc_abts_io_buf_list, list) { in lpfc_sli4_vport_delete_fcp_xri_aborted()
400 if (psb->cur_iocbq.cmd_flag & LPFC_IO_NVME) in lpfc_sli4_vport_delete_fcp_xri_aborted()
403 if (psb->rdata && psb->rdata->pnode && in lpfc_sli4_vport_delete_fcp_xri_aborted()
404 psb->rdata->pnode->vport == vport) in lpfc_sli4_vport_delete_fcp_xri_aborted()
405 psb->rdata = NULL; in lpfc_sli4_vport_delete_fcp_xri_aborted()
407 spin_unlock(&qp->abts_io_buf_list_lock); in lpfc_sli4_vport_delete_fcp_xri_aborted()
409 spin_unlock_irqrestore(&phba->hbalock, iflag); in lpfc_sli4_vport_delete_fcp_xri_aborted()
413 * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort
418 * This routine is invoked by the worker thread to process a SLI4 fast-path
434 struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; in lpfc_sli4_io_xri_aborted()
438 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) in lpfc_sli4_io_xri_aborted()
440 offline = pci_channel_offline(phba->pcidev); in lpfc_sli4_io_xri_aborted()
445 qp = &phba->sli4_hba.hdwq[idx]; in lpfc_sli4_io_xri_aborted()
446 spin_lock_irqsave(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
447 spin_lock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
449 &qp->lpfc_abts_io_buf_list, list) { in lpfc_sli4_io_xri_aborted()
451 xri = psb->cur_iocbq.sli4_xritag; in lpfc_sli4_io_xri_aborted()
452 if (psb->cur_iocbq.sli4_xritag == xri) { in lpfc_sli4_io_xri_aborted()
453 list_del_init(&psb->list); in lpfc_sli4_io_xri_aborted()
454 psb->flags &= ~LPFC_SBUF_XBUSY; in lpfc_sli4_io_xri_aborted()
455 psb->status = IOSTAT_SUCCESS; in lpfc_sli4_io_xri_aborted()
456 if (psb->cur_iocbq.cmd_flag & LPFC_IO_NVME) { in lpfc_sli4_io_xri_aborted()
457 qp->abts_nvme_io_bufs--; in lpfc_sli4_io_xri_aborted()
458 spin_unlock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
459 spin_unlock_irqrestore(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
466 spin_lock_irqsave(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
467 spin_lock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
470 qp->abts_scsi_io_bufs--; in lpfc_sli4_io_xri_aborted()
471 spin_unlock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
473 if (psb->rdata && psb->rdata->pnode) in lpfc_sli4_io_xri_aborted()
474 ndlp = psb->rdata->pnode; in lpfc_sli4_io_xri_aborted()
477 spin_unlock_irqrestore(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
479 spin_lock_irqsave(&phba->rrq_list_lock, iflag); in lpfc_sli4_io_xri_aborted()
480 rrq_empty = list_empty(&phba->active_rrq_list); in lpfc_sli4_io_xri_aborted()
481 spin_unlock_irqrestore(&phba->rrq_list_lock, iflag); in lpfc_sli4_io_xri_aborted()
484 psb->cur_iocbq.sli4_lxritag, rxid, 1); in lpfc_sli4_io_xri_aborted()
488 if (phba->cfg_fcp_wait_abts_rsp || offline) { in lpfc_sli4_io_xri_aborted()
489 spin_lock_irqsave(&psb->buf_lock, iflag); in lpfc_sli4_io_xri_aborted()
490 cmd = psb->pCmd; in lpfc_sli4_io_xri_aborted()
491 psb->pCmd = NULL; in lpfc_sli4_io_xri_aborted()
492 spin_unlock_irqrestore(&psb->buf_lock, iflag); in lpfc_sli4_io_xri_aborted()
504 spin_lock_irqsave(&psb->buf_lock, iflag); in lpfc_sli4_io_xri_aborted()
505 psb->cur_iocbq.cmd_flag &= in lpfc_sli4_io_xri_aborted()
507 if (psb->waitq) in lpfc_sli4_io_xri_aborted()
508 wake_up(psb->waitq); in lpfc_sli4_io_xri_aborted()
509 spin_unlock_irqrestore(&psb->buf_lock, iflag); in lpfc_sli4_io_xri_aborted()
517 spin_lock_irqsave(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
518 spin_lock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
522 spin_unlock(&qp->abts_io_buf_list_lock); in lpfc_sli4_io_xri_aborted()
524 for (i = 1; i <= phba->sli.last_iotag; i++) { in lpfc_sli4_io_xri_aborted()
525 iocbq = phba->sli.iocbq_lookup[i]; in lpfc_sli4_io_xri_aborted()
527 if (!(iocbq->cmd_flag & LPFC_IO_FCP) || in lpfc_sli4_io_xri_aborted()
528 (iocbq->cmd_flag & LPFC_IO_LIBDFC)) in lpfc_sli4_io_xri_aborted()
530 if (iocbq->sli4_xritag != xri) in lpfc_sli4_io_xri_aborted()
533 psb->flags &= ~LPFC_SBUF_XBUSY; in lpfc_sli4_io_xri_aborted()
534 spin_unlock_irqrestore(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
535 if (!list_empty(&pring->txq)) in lpfc_sli4_io_xri_aborted()
540 spin_unlock_irqrestore(&phba->hbalock, iflag); in lpfc_sli4_io_xri_aborted()
544 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
546 * @ndlp: pointer to a node-list data structure.
553 * NULL - Error
554 * Pointer to lpfc_scsi_buf - Success
561 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get; in lpfc_get_scsi_buf_s3()
564 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); in lpfc_get_scsi_buf_s3()
568 spin_lock(&phba->scsi_buf_list_put_lock); in lpfc_get_scsi_buf_s3()
569 list_splice(&phba->lpfc_scsi_buf_list_put, in lpfc_get_scsi_buf_s3()
570 &phba->lpfc_scsi_buf_list_get); in lpfc_get_scsi_buf_s3()
571 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); in lpfc_get_scsi_buf_s3()
574 spin_unlock(&phba->scsi_buf_list_put_lock); in lpfc_get_scsi_buf_s3()
576 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); in lpfc_get_scsi_buf_s3()
579 atomic_inc(&ndlp->cmd_pending); in lpfc_get_scsi_buf_s3()
580 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; in lpfc_get_scsi_buf_s3()
585 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from io_buf_list of the HBA
587 * @ndlp: pointer to a node-list data structure.
594 * NULL - Error
595 * Pointer to lpfc_scsi_buf - Success
611 if (cmnd && phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) { in lpfc_get_scsi_buf_s4()
615 idx = phba->sli4_hba.cpu_map[cpu].hdwq; in lpfc_get_scsi_buf_s4()
619 !phba->cfg_xri_rebalancing); in lpfc_get_scsi_buf_s4()
621 qp = &phba->sli4_hba.hdwq[idx]; in lpfc_get_scsi_buf_s4()
622 qp->empty_io_bufs++; in lpfc_get_scsi_buf_s4()
629 lpfc_cmd->cur_iocbq.cmd_flag = LPFC_IO_FCP; in lpfc_get_scsi_buf_s4()
630 lpfc_cmd->prot_seg_cnt = 0; in lpfc_get_scsi_buf_s4()
631 lpfc_cmd->seg_cnt = 0; in lpfc_get_scsi_buf_s4()
632 lpfc_cmd->timeout = 0; in lpfc_get_scsi_buf_s4()
633 lpfc_cmd->flags = 0; in lpfc_get_scsi_buf_s4()
634 lpfc_cmd->start_time = jiffies; in lpfc_get_scsi_buf_s4()
635 lpfc_cmd->waitq = NULL; in lpfc_get_scsi_buf_s4()
636 lpfc_cmd->cpu = cpu; in lpfc_get_scsi_buf_s4()
638 lpfc_cmd->prot_data_type = 0; in lpfc_get_scsi_buf_s4()
642 lpfc_release_io_buf(phba, lpfc_cmd, lpfc_cmd->hdwq); in lpfc_get_scsi_buf_s4()
646 lpfc_cmd->fcp_cmnd = tmp->fcp_cmnd; in lpfc_get_scsi_buf_s4()
647 lpfc_cmd->fcp_rsp = tmp->fcp_rsp; in lpfc_get_scsi_buf_s4()
654 sgl = (struct sli4_sge_le *)lpfc_cmd->dma_sgl; in lpfc_get_scsi_buf_s4()
655 pdma_phys_fcp_cmd = tmp->fcp_cmd_rsp_dma_handle; in lpfc_get_scsi_buf_s4()
656 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); in lpfc_get_scsi_buf_s4()
657 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); in lpfc_get_scsi_buf_s4()
659 if (cmnd && cmnd->cmd_len > LPFC_FCP_CDB_LEN) in lpfc_get_scsi_buf_s4()
660 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd32)); in lpfc_get_scsi_buf_s4()
662 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); in lpfc_get_scsi_buf_s4()
668 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); in lpfc_get_scsi_buf_s4()
669 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); in lpfc_get_scsi_buf_s4()
671 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); in lpfc_get_scsi_buf_s4()
674 atomic_inc(&ndlp->cmd_pending); in lpfc_get_scsi_buf_s4()
675 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; in lpfc_get_scsi_buf_s4()
680 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
682 * @ndlp: pointer to a node-list data structure.
689 * NULL - Error
690 * Pointer to lpfc_scsi_buf - Success
696 return phba->lpfc_get_scsi_buf(phba, ndlp, cmnd); in lpfc_get_scsi_buf()
700 * lpfc_release_scsi_buf_s3 - Return a scsi buffer back to hba scsi buf list
712 psb->seg_cnt = 0; in lpfc_release_scsi_buf_s3()
713 psb->prot_seg_cnt = 0; in lpfc_release_scsi_buf_s3()
715 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); in lpfc_release_scsi_buf_s3()
716 psb->pCmd = NULL; in lpfc_release_scsi_buf_s3()
717 psb->cur_iocbq.cmd_flag = LPFC_IO_FCP; in lpfc_release_scsi_buf_s3()
718 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); in lpfc_release_scsi_buf_s3()
719 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); in lpfc_release_scsi_buf_s3()
738 psb->seg_cnt = 0; in lpfc_release_scsi_buf_s4()
739 psb->prot_seg_cnt = 0; in lpfc_release_scsi_buf_s4()
741 qp = psb->hdwq; in lpfc_release_scsi_buf_s4()
742 if (psb->flags & LPFC_SBUF_XBUSY) { in lpfc_release_scsi_buf_s4()
743 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag); in lpfc_release_scsi_buf_s4()
744 if (!phba->cfg_fcp_wait_abts_rsp) in lpfc_release_scsi_buf_s4()
745 psb->pCmd = NULL; in lpfc_release_scsi_buf_s4()
746 list_add_tail(&psb->list, &qp->lpfc_abts_io_buf_list); in lpfc_release_scsi_buf_s4()
747 qp->abts_scsi_io_bufs++; in lpfc_release_scsi_buf_s4()
748 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag); in lpfc_release_scsi_buf_s4()
765 if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp) in lpfc_release_scsi_buf()
766 atomic_dec(&psb->ndlp->cmd_pending); in lpfc_release_scsi_buf()
768 psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH; in lpfc_release_scsi_buf()
769 phba->lpfc_release_scsi_buf(phba, psb); in lpfc_release_scsi_buf()
773 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
778 * byte swapping the data to big endian format for transmission on the wire.
792 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
796 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
797 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
802 * 1 - Error
803 * 0 - Success
808 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_scsi_prep_dma_buf_s3()
810 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_dma_buf_s3()
811 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; in lpfc_scsi_prep_dma_buf_s3()
812 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; in lpfc_scsi_prep_dma_buf_s3()
813 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; in lpfc_scsi_prep_dma_buf_s3()
814 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; in lpfc_scsi_prep_dma_buf_s3()
817 int nseg, datadir = scsi_cmnd->sc_data_direction; in lpfc_scsi_prep_dma_buf_s3()
820 * There are three possibilities here - use scatter-gather segment, use in lpfc_scsi_prep_dma_buf_s3()
829 * because this a count of dma-mappings used to map the use_sg in lpfc_scsi_prep_dma_buf_s3()
834 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), in lpfc_scsi_prep_dma_buf_s3()
839 lpfc_cmd->seg_cnt = nseg; in lpfc_scsi_prep_dma_buf_s3()
840 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { in lpfc_scsi_prep_dma_buf_s3()
844 " %d\n", __func__, phba->cfg_sg_seg_cnt, in lpfc_scsi_prep_dma_buf_s3()
845 lpfc_cmd->seg_cnt); in lpfc_scsi_prep_dma_buf_s3()
846 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); in lpfc_scsi_prep_dma_buf_s3()
847 lpfc_cmd->seg_cnt = 0; in lpfc_scsi_prep_dma_buf_s3()
853 * The driver established a maximum scatter-gather segment count in lpfc_scsi_prep_dma_buf_s3()
857 * When using SLI-3 the driver will try to fit all the BDEs into in lpfc_scsi_prep_dma_buf_s3()
859 * does for SLI-2 mode. in lpfc_scsi_prep_dma_buf_s3()
863 if (phba->sli_rev == 3 && in lpfc_scsi_prep_dma_buf_s3()
864 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && in lpfc_scsi_prep_dma_buf_s3()
865 !(iocbq->cmd_flag & DSS_SECURITY_OP) && in lpfc_scsi_prep_dma_buf_s3()
867 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; in lpfc_scsi_prep_dma_buf_s3()
868 data_bde->tus.f.bdeSize = sg_dma_len(sgel); in lpfc_scsi_prep_dma_buf_s3()
869 data_bde->addrLow = putPaddrLow(physaddr); in lpfc_scsi_prep_dma_buf_s3()
870 data_bde->addrHigh = putPaddrHigh(physaddr); in lpfc_scsi_prep_dma_buf_s3()
873 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; in lpfc_scsi_prep_dma_buf_s3()
874 bpl->tus.f.bdeSize = sg_dma_len(sgel); in lpfc_scsi_prep_dma_buf_s3()
875 bpl->tus.w = le32_to_cpu(bpl->tus.w); in lpfc_scsi_prep_dma_buf_s3()
876 bpl->addrLow = in lpfc_scsi_prep_dma_buf_s3()
878 bpl->addrHigh = in lpfc_scsi_prep_dma_buf_s3()
887 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is in lpfc_scsi_prep_dma_buf_s3()
888 * explicitly reinitialized and for SLI-3 the extended bde count is in lpfc_scsi_prep_dma_buf_s3()
891 if (phba->sli_rev == 3 && in lpfc_scsi_prep_dma_buf_s3()
892 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && in lpfc_scsi_prep_dma_buf_s3()
893 !(iocbq->cmd_flag & DSS_SECURITY_OP)) { in lpfc_scsi_prep_dma_buf_s3()
900 physaddr = lpfc_cmd->dma_handle; in lpfc_scsi_prep_dma_buf_s3()
901 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; in lpfc_scsi_prep_dma_buf_s3()
902 data_bde->tus.f.bdeSize = (num_bde * in lpfc_scsi_prep_dma_buf_s3()
907 data_bde->addrHigh = putPaddrHigh(physaddr); in lpfc_scsi_prep_dma_buf_s3()
908 data_bde->addrLow = putPaddrLow(physaddr); in lpfc_scsi_prep_dma_buf_s3()
910 iocb_cmd->unsli3.fcp_ext.ebde_count = 2; in lpfc_scsi_prep_dma_buf_s3()
913 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); in lpfc_scsi_prep_dma_buf_s3()
916 iocb_cmd->un.fcpi64.bdl.bdeSize = in lpfc_scsi_prep_dma_buf_s3()
918 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); in lpfc_scsi_prep_dma_buf_s3()
920 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); in lpfc_scsi_prep_dma_buf_s3()
923 * Due to difference in data length between DIF/non-DIF paths, in lpfc_scsi_prep_dma_buf_s3()
926 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); in lpfc_scsi_prep_dma_buf_s3()
927 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); in lpfc_scsi_prep_dma_buf_s3()
937 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
946 * lpfc_bg_err_inject - Determine if we should inject an error
978 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { in lpfc_bg_err_inject()
980 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; in lpfc_bg_err_inject()
983 if (phba->lpfc_injerr_lba < (u64)lba || in lpfc_bg_err_inject()
984 (phba->lpfc_injerr_lba >= (u64)(lba + numblks))) in lpfc_bg_err_inject()
987 blockoff = phba->lpfc_injerr_lba - (u64)lba; in lpfc_bg_err_inject()
996 rdata = lpfc_rport_data_from_scsi_device(sc->device); in lpfc_bg_err_inject()
997 if (rdata && rdata->pnode) { in lpfc_bg_err_inject()
998 ndlp = rdata->pnode; in lpfc_bg_err_inject()
1001 if (phba->lpfc_injerr_nportid && in lpfc_bg_err_inject()
1002 (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) in lpfc_bg_err_inject()
1007 * wwn[0] should be a non-zero NAA in a good WWPN. in lpfc_bg_err_inject()
1009 if (phba->lpfc_injerr_wwpn.u.wwn[0] && in lpfc_bg_err_inject()
1010 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1019 lpfc_cmd = (struct lpfc_io_buf *)sc->host_scribble; in lpfc_bg_err_inject()
1024 if (phba->lpfc_injerr_wref_cnt) { in lpfc_bg_err_inject()
1030 * to be sent on the wire. It should in lpfc_bg_err_inject()
1041 be32_to_cpu(src->ref_tag)); in lpfc_bg_err_inject()
1048 lpfc_cmd->prot_data_type = in lpfc_bg_err_inject()
1050 lpfc_cmd->prot_data_segment = in lpfc_bg_err_inject()
1052 lpfc_cmd->prot_data = in lpfc_bg_err_inject()
1053 src->ref_tag; in lpfc_bg_err_inject()
1055 src->ref_tag = cpu_to_be32(0xDEADBEEF); in lpfc_bg_err_inject()
1056 phba->lpfc_injerr_wref_cnt--; in lpfc_bg_err_inject()
1057 if (phba->lpfc_injerr_wref_cnt == 0) { in lpfc_bg_err_inject()
1058 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1059 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1061 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1072 * to be sent on the wire. It should be in lpfc_bg_err_inject()
1075 /* DEADBEEF will be the reftag on the wire */ in lpfc_bg_err_inject()
1077 phba->lpfc_injerr_wref_cnt--; in lpfc_bg_err_inject()
1078 if (phba->lpfc_injerr_wref_cnt == 0) { in lpfc_bg_err_inject()
1079 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1080 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1082 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1095 * being copied from SLI-Host to SLI-Port. in lpfc_bg_err_inject()
1098 phba->lpfc_injerr_wref_cnt--; in lpfc_bg_err_inject()
1099 if (phba->lpfc_injerr_wref_cnt == 0) { in lpfc_bg_err_inject()
1100 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1101 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1103 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1114 if (phba->lpfc_injerr_rref_cnt) { in lpfc_bg_err_inject()
1121 * error on data being read off the wire. It in lpfc_bg_err_inject()
1125 phba->lpfc_injerr_rref_cnt--; in lpfc_bg_err_inject()
1126 if (phba->lpfc_injerr_rref_cnt == 0) { in lpfc_bg_err_inject()
1127 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1128 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1130 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1145 if (phba->lpfc_injerr_wapp_cnt) { in lpfc_bg_err_inject()
1151 * to be sent on the wire. It should in lpfc_bg_err_inject()
1162 be16_to_cpu(src->app_tag)); in lpfc_bg_err_inject()
1169 lpfc_cmd->prot_data_type = in lpfc_bg_err_inject()
1171 lpfc_cmd->prot_data_segment = in lpfc_bg_err_inject()
1173 lpfc_cmd->prot_data = in lpfc_bg_err_inject()
1174 src->app_tag; in lpfc_bg_err_inject()
1176 src->app_tag = cpu_to_be16(0xDEAD); in lpfc_bg_err_inject()
1177 phba->lpfc_injerr_wapp_cnt--; in lpfc_bg_err_inject()
1178 if (phba->lpfc_injerr_wapp_cnt == 0) { in lpfc_bg_err_inject()
1179 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1180 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1182 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1192 * error to be sent on the wire. It should be in lpfc_bg_err_inject()
1195 /* DEAD will be the apptag on the wire */ in lpfc_bg_err_inject()
1197 phba->lpfc_injerr_wapp_cnt--; in lpfc_bg_err_inject()
1198 if (phba->lpfc_injerr_wapp_cnt == 0) { in lpfc_bg_err_inject()
1199 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1200 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1202 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1215 * being copied from SLI-Host to SLI-Port. in lpfc_bg_err_inject()
1218 phba->lpfc_injerr_wapp_cnt--; in lpfc_bg_err_inject()
1219 if (phba->lpfc_injerr_wapp_cnt == 0) { in lpfc_bg_err_inject()
1220 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1221 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1223 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1234 if (phba->lpfc_injerr_rapp_cnt) { in lpfc_bg_err_inject()
1241 * error on data being read off the wire. It in lpfc_bg_err_inject()
1245 phba->lpfc_injerr_rapp_cnt--; in lpfc_bg_err_inject()
1246 if (phba->lpfc_injerr_rapp_cnt == 0) { in lpfc_bg_err_inject()
1247 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1248 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1250 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1266 if (phba->lpfc_injerr_wgrd_cnt) { in lpfc_bg_err_inject()
1275 * error to be sent on the wire. It should be in lpfc_bg_err_inject()
1278 phba->lpfc_injerr_wgrd_cnt--; in lpfc_bg_err_inject()
1279 if (phba->lpfc_injerr_wgrd_cnt == 0) { in lpfc_bg_err_inject()
1280 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1281 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1283 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1288 /* Signals the caller to swap CRC->CSUM */ in lpfc_bg_err_inject()
1298 * being copied from SLI-Host to SLI-Port. in lpfc_bg_err_inject()
1300 phba->lpfc_injerr_wgrd_cnt--; in lpfc_bg_err_inject()
1301 if (phba->lpfc_injerr_wgrd_cnt == 0) { in lpfc_bg_err_inject()
1302 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1303 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1305 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1310 /* Signals the caller to swap CRC->CSUM */ in lpfc_bg_err_inject()
1318 if (phba->lpfc_injerr_rgrd_cnt) { in lpfc_bg_err_inject()
1325 * error on data being read off the wire. It in lpfc_bg_err_inject()
1328 phba->lpfc_injerr_rgrd_cnt--; in lpfc_bg_err_inject()
1329 if (phba->lpfc_injerr_rgrd_cnt == 0) { in lpfc_bg_err_inject()
1330 phba->lpfc_injerr_nportid = 0; in lpfc_bg_err_inject()
1331 phba->lpfc_injerr_lba = in lpfc_bg_err_inject()
1333 memset(&phba->lpfc_injerr_wwpn, in lpfc_bg_err_inject()
1338 /* Signals the caller to swap CRC->CSUM */ in lpfc_bg_err_inject()
1352 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1359 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1368 if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) { in lpfc_sc_to_bg_opcodes()
1432 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1439 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1447 if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) { in lpfc_bg_err_opcodes()
1503 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1518 * +-------------------------+
1519 * start of prot group --> | PDE_5 |
1520 * +-------------------------+
1522 * +-------------------------+
1524 * +-------------------------+
1526 * +-------------------------+
1542 int datadir = sc->sc_data_direction; in lpfc_bg_setup_bpl()
1573 pde5->word0 = cpu_to_le32(pde5->word0); in lpfc_bg_setup_bpl()
1574 pde5->reftag = cpu_to_le32(reftag); in lpfc_bg_setup_bpl()
1592 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) in lpfc_bg_setup_bpl()
1597 if (sc->prot_flags & SCSI_PROT_REF_CHECK) in lpfc_bg_setup_bpl()
1607 pde6->word0 = cpu_to_le32(pde6->word0); in lpfc_bg_setup_bpl()
1608 pde6->word1 = cpu_to_le32(pde6->word1); in lpfc_bg_setup_bpl()
1609 pde6->word2 = cpu_to_le32(pde6->word2); in lpfc_bg_setup_bpl()
1618 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); in lpfc_bg_setup_bpl()
1619 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); in lpfc_bg_setup_bpl()
1620 bpl->tus.f.bdeSize = sg_dma_len(sgde); in lpfc_bg_setup_bpl()
1622 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; in lpfc_bg_setup_bpl()
1624 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; in lpfc_bg_setup_bpl()
1625 bpl->tus.w = le32_to_cpu(bpl->tus.w); in lpfc_bg_setup_bpl()
1635 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1652 * +-------------------------+
1653 * start of first prot group --> | PDE_5 |
1654 * +-------------------------+
1656 * +-------------------------+
1658 * +-------------------------+
1660 * +-------------------------+
1662 * +-------------------------+
1663 * start of new prot group --> | PDE_5 |
1664 * +-------------------------+
1666 * +-------------------------+
1689 int datadir = sc->sc_data_direction; in lpfc_bg_setup_bpl_prot()
1731 if (num_bde >= (phba->cfg_total_seg_cnt - 2)) in lpfc_bg_setup_bpl_prot()
1740 pde5->word0 = cpu_to_le32(pde5->word0); in lpfc_bg_setup_bpl_prot()
1741 pde5->reftag = cpu_to_le32(reftag); in lpfc_bg_setup_bpl_prot()
1754 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) in lpfc_bg_setup_bpl_prot()
1759 if (sc->prot_flags & SCSI_PROT_REF_CHECK) in lpfc_bg_setup_bpl_prot()
1769 pde6->word0 = cpu_to_le32(pde6->word0); in lpfc_bg_setup_bpl_prot()
1770 pde6->word1 = cpu_to_le32(pde6->word1); in lpfc_bg_setup_bpl_prot()
1771 pde6->word2 = cpu_to_le32(pde6->word2); in lpfc_bg_setup_bpl_prot()
1779 protgroup_len = sg_dma_len(sgpe) - protgroup_offset; in lpfc_bg_setup_bpl_prot()
1788 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); in lpfc_bg_setup_bpl_prot()
1789 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); in lpfc_bg_setup_bpl_prot()
1795 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { in lpfc_bg_setup_bpl_prot()
1796 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); in lpfc_bg_setup_bpl_prot()
1812 if (num_bde >= phba->cfg_total_seg_cnt) in lpfc_bg_setup_bpl_prot()
1823 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); in lpfc_bg_setup_bpl_prot()
1824 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); in lpfc_bg_setup_bpl_prot()
1826 remainder = sg_dma_len(sgde) - split_offset; in lpfc_bg_setup_bpl_prot()
1830 bpl->tus.f.bdeSize = remainder; in lpfc_bg_setup_bpl_prot()
1837 bpl->tus.f.bdeSize = protgrp_bytes - subtotal; in lpfc_bg_setup_bpl_prot()
1838 split_offset += bpl->tus.f.bdeSize; in lpfc_bg_setup_bpl_prot()
1841 subtotal += bpl->tus.f.bdeSize; in lpfc_bg_setup_bpl_prot()
1844 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; in lpfc_bg_setup_bpl_prot()
1846 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; in lpfc_bg_setup_bpl_prot()
1847 bpl->tus.w = le32_to_cpu(bpl->tus.w); in lpfc_bg_setup_bpl_prot()
1889 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
1905 * +-------------------------+
1906 * start of prot group --> | DI_SEED |
1907 * +-------------------------+
1909 * +-------------------------+
1911 * +-------------------------+
1962 diseed->ref_tag = cpu_to_le32(reftag); in lpfc_bg_setup_sgl()
1963 diseed->ref_tag_tran = diseed->ref_tag; in lpfc_bg_setup_sgl()
1969 if (sc->sc_data_direction == DMA_FROM_DEVICE) { in lpfc_bg_setup_sgl()
1970 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) in lpfc_bg_setup_sgl()
1975 if (sc->prot_flags & SCSI_PROT_REF_CHECK) in lpfc_bg_setup_sgl()
1989 diseed->word2 = cpu_to_le32(diseed->word2); in lpfc_bg_setup_sgl()
1990 diseed->word3 = cpu_to_le32(diseed->word3); in lpfc_bg_setup_sgl()
2001 sgl->word2 = 0; in lpfc_bg_setup_sgl()
2004 if (!lsp_just_set && !((j + 1) % phba->border_sge_num) && in lpfc_bg_setup_sgl()
2005 ((datasegcnt - 1) != i)) { in lpfc_bg_setup_sgl()
2012 lpfc_cmd->seg_cnt = 0; in lpfc_bg_setup_sgl()
2015 sgl->addr_lo = cpu_to_le32(putPaddrLow( in lpfc_bg_setup_sgl()
2016 sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl()
2017 sgl->addr_hi = cpu_to_le32(putPaddrHigh( in lpfc_bg_setup_sgl()
2018 sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl()
2025 if ((datasegcnt - 1) == i) in lpfc_bg_setup_sgl()
2029 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); in lpfc_bg_setup_sgl()
2030 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); in lpfc_bg_setup_sgl()
2033 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_setup_sgl()
2034 sgl->sge_len = cpu_to_le32(dma_len); in lpfc_bg_setup_sgl()
2044 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_setup_sgl()
2045 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); in lpfc_bg_setup_sgl()
2047 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; in lpfc_bg_setup_sgl()
2048 i = i - 1; in lpfc_bg_setup_sgl()
2062 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2080 * +-------------------------+
2081 * start of first prot group --> | DISEED |
2082 * +-------------------------+
2084 * +-------------------------+
2086 * +-------------------------+
2088 * +-------------------------+
2089 * start of new prot group --> | DISEED |
2090 * +-------------------------+
2092 * +-------------------------+
2158 if ((num_sge >= (phba->cfg_total_seg_cnt - 2)) && in lpfc_bg_setup_sgl_prot()
2159 !(phba->cfg_xpsgl)) in lpfc_bg_setup_sgl_prot()
2163 if (!((j + 1) % phba->border_sge_num) || in lpfc_bg_setup_sgl_prot()
2164 !((j + 2) % phba->border_sge_num) || in lpfc_bg_setup_sgl_prot()
2165 !((j + 3) % phba->border_sge_num)) { in lpfc_bg_setup_sgl_prot()
2166 sgl->word2 = 0; in lpfc_bg_setup_sgl_prot()
2176 sgl->addr_lo = cpu_to_le32(putPaddrLow( in lpfc_bg_setup_sgl_prot()
2177 sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl_prot()
2178 sgl->addr_hi = cpu_to_le32(putPaddrHigh( in lpfc_bg_setup_sgl_prot()
2179 sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl_prot()
2182 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_setup_sgl_prot()
2183 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); in lpfc_bg_setup_sgl_prot()
2185 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; in lpfc_bg_setup_sgl_prot()
2195 diseed->ref_tag = cpu_to_le32(reftag); in lpfc_bg_setup_sgl_prot()
2196 diseed->ref_tag_tran = diseed->ref_tag; in lpfc_bg_setup_sgl_prot()
2198 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) { in lpfc_bg_setup_sgl_prot()
2203 * When in this mode, the hardware will replace in lpfc_bg_setup_sgl_prot()
2205 * newly generated good CRC for the wire. in lpfc_bg_setup_sgl_prot()
2206 * Switch to raw mode here to avoid this in lpfc_bg_setup_sgl_prot()
2207 * behavior. What the host sends gets put on the wire. in lpfc_bg_setup_sgl_prot()
2216 if (sc->prot_flags & SCSI_PROT_REF_CHECK) in lpfc_bg_setup_sgl_prot()
2229 diseed->word2 = cpu_to_le32(diseed->word2); in lpfc_bg_setup_sgl_prot()
2230 diseed->word3 = cpu_to_le32(diseed->word3); in lpfc_bg_setup_sgl_prot()
2240 protgroup_len = sg_dma_len(sgpe) - protgroup_offset; in lpfc_bg_setup_sgl_prot()
2246 sgl->word2 = 0; in lpfc_bg_setup_sgl_prot()
2248 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); in lpfc_bg_setup_sgl_prot()
2249 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); in lpfc_bg_setup_sgl_prot()
2250 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_setup_sgl_prot()
2251 sgl->sge_len = 0; in lpfc_bg_setup_sgl_prot()
2257 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { in lpfc_bg_setup_sgl_prot()
2258 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); in lpfc_bg_setup_sgl_prot()
2278 if ((num_sge >= phba->cfg_total_seg_cnt) && in lpfc_bg_setup_sgl_prot()
2279 !phba->cfg_xpsgl) in lpfc_bg_setup_sgl_prot()
2289 if (!((j + 1) % phba->border_sge_num)) { in lpfc_bg_setup_sgl_prot()
2290 sgl->word2 = 0; in lpfc_bg_setup_sgl_prot()
2302 sgl->addr_lo = cpu_to_le32( in lpfc_bg_setup_sgl_prot()
2303 putPaddrLow(sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl_prot()
2304 sgl->addr_hi = cpu_to_le32( in lpfc_bg_setup_sgl_prot()
2305 putPaddrHigh(sgl_xtra->dma_phys_sgl)); in lpfc_bg_setup_sgl_prot()
2308 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_setup_sgl_prot()
2309 sgl->sge_len = cpu_to_le32( in lpfc_bg_setup_sgl_prot()
2310 phba->cfg_sg_dma_buf_size); in lpfc_bg_setup_sgl_prot()
2312 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; in lpfc_bg_setup_sgl_prot()
2317 remainder = sg_dma_len(sgde) - split_offset; in lpfc_bg_setup_sgl_prot()
2331 dma_len = protgrp_bytes - subtotal; in lpfc_bg_setup_sgl_prot()
2337 sgl->word2 = 0; in lpfc_bg_setup_sgl_prot()
2338 sgl->addr_lo = cpu_to_le32(putPaddrLow( in lpfc_bg_setup_sgl_prot()
2340 sgl->addr_hi = cpu_to_le32(putPaddrHigh( in lpfc_bg_setup_sgl_prot()
2347 sgl->sge_len = cpu_to_le32(dma_len); in lpfc_bg_setup_sgl_prot()
2376 sgl--; in lpfc_bg_setup_sgl_prot()
2399 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2437 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2442 * is actually on the wire.
2450 struct scsi_cmnd *sc = lpfc_cmd->pCmd; in lpfc_bg_scsi_adjust_dl()
2455 /* Check if there is protection data on the wire */ in lpfc_bg_scsi_adjust_dl()
2456 if (sc->sc_data_direction == DMA_FROM_DEVICE) { in lpfc_bg_scsi_adjust_dl()
2468 * If we are in DIF Type 1 mode every data block has a 8 byte in lpfc_bg_scsi_adjust_dl()
2478 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2485 * RETURNS 0 - SUCCESS,
2486 * 1 - Failed DMA map, retry.
2487 * 2 - Invalid scsi cmd or prot-type. Do not rety.
2493 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_bg_scsi_prep_dma_buf_s3()
2494 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_bg_scsi_prep_dma_buf_s3()
2495 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; in lpfc_bg_scsi_prep_dma_buf_s3()
2496 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; in lpfc_bg_scsi_prep_dma_buf_s3()
2498 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; in lpfc_bg_scsi_prep_dma_buf_s3()
2502 struct lpfc_vport *vport = phba->pport; in lpfc_bg_scsi_prep_dma_buf_s3()
2512 * because this a count of dma-mappings used to map the use_sg in lpfc_bg_scsi_prep_dma_buf_s3()
2516 datasegcnt = dma_map_sg(&phba->pcidev->dev, in lpfc_bg_scsi_prep_dma_buf_s3()
2522 lpfc_cmd->seg_cnt = datasegcnt; in lpfc_bg_scsi_prep_dma_buf_s3()
2525 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { in lpfc_bg_scsi_prep_dma_buf_s3()
2526 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); in lpfc_bg_scsi_prep_dma_buf_s3()
2537 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) { in lpfc_bg_scsi_prep_dma_buf_s3()
2557 protsegcnt = dma_map_sg(&phba->pcidev->dev, in lpfc_bg_scsi_prep_dma_buf_s3()
2565 lpfc_cmd->prot_seg_cnt = protsegcnt; in lpfc_bg_scsi_prep_dma_buf_s3()
2571 if ((lpfc_cmd->prot_seg_cnt * 4) > in lpfc_bg_scsi_prep_dma_buf_s3()
2572 (phba->cfg_total_seg_cnt - 2)) { in lpfc_bg_scsi_prep_dma_buf_s3()
2581 (num_bde > phba->cfg_total_seg_cnt)) { in lpfc_bg_scsi_prep_dma_buf_s3()
2590 lpfc_cmd->seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s3()
2605 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); in lpfc_bg_scsi_prep_dma_buf_s3()
2606 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); in lpfc_bg_scsi_prep_dma_buf_s3()
2607 iocb_cmd->ulpBdeCount = 1; in lpfc_bg_scsi_prep_dma_buf_s3()
2608 iocb_cmd->ulpLe = 1; in lpfc_bg_scsi_prep_dma_buf_s3()
2611 fcp_cmnd->fcpDl = cpu_to_be32(fcpdl); in lpfc_bg_scsi_prep_dma_buf_s3()
2614 * Due to difference in data length between DIF/non-DIF paths, in lpfc_bg_scsi_prep_dma_buf_s3()
2617 iocb_cmd->un.fcpi.fcpi_parm = fcpdl; in lpfc_bg_scsi_prep_dma_buf_s3()
2623 if (iocb_cmd->un.fcpi.fcpi_XRdy && in lpfc_bg_scsi_prep_dma_buf_s3()
2624 (fcpdl < vport->cfg_first_burst_size)) in lpfc_bg_scsi_prep_dma_buf_s3()
2625 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; in lpfc_bg_scsi_prep_dma_buf_s3()
2629 if (lpfc_cmd->seg_cnt) in lpfc_bg_scsi_prep_dma_buf_s3()
2631 if (lpfc_cmd->prot_seg_cnt) in lpfc_bg_scsi_prep_dma_buf_s3()
2632 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), in lpfc_bg_scsi_prep_dma_buf_s3()
2634 scsi_cmnd->sc_data_direction); in lpfc_bg_scsi_prep_dma_buf_s3()
2639 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, in lpfc_bg_scsi_prep_dma_buf_s3()
2640 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, in lpfc_bg_scsi_prep_dma_buf_s3()
2643 lpfc_cmd->seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s3()
2644 lpfc_cmd->prot_seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s3()
2680 * what type of T10-DIF error occurred.
2687 struct scsi_cmnd *cmd = lpfc_cmd->pCmd; in lpfc_calc_bg_err()
2717 protsegcnt = lpfc_cmd->prot_seg_cnt; in lpfc_calc_bg_err()
2729 if ((data_len & (blksize - 1)) == 0) in lpfc_calc_bg_err()
2734 start_app_tag = src->app_tag; in lpfc_calc_bg_err()
2743 if ((src->ref_tag == T10_PI_REF_ESCAPE) || in lpfc_calc_bg_err()
2744 (src->app_tag == T10_PI_APP_ESCAPE)) { in lpfc_calc_bg_err()
2751 guard_tag = src->guard_tag; in lpfc_calc_bg_err()
2752 if (cmd->prot_flags in lpfc_calc_bg_err()
2766 ref_tag = be32_to_cpu(src->ref_tag); in lpfc_calc_bg_err()
2774 app_tag = src->app_tag; in lpfc_calc_bg_err()
2780 len -= sizeof(struct scsi_dif_tuple); in lpfc_calc_bg_err()
2786 data_len -= blksize; in lpfc_calc_bg_err()
2801 if ((data_len & (blksize - 1)) == 0) in lpfc_calc_bg_err()
2814 protsegcnt--; in lpfc_calc_bg_err()
2821 phba->bg_guard_err_cnt++; in lpfc_calc_bg_err()
2831 phba->bg_reftag_err_cnt++; in lpfc_calc_bg_err()
2841 phba->bg_apptag_err_cnt++; in lpfc_calc_bg_err()
2857 * 0 - No error found
2858 * 1 - BlockGuard error found
2859 * -1 - Internal error (bad profile, ...etc)
2865 struct scsi_cmnd *cmd = lpfc_cmd->pCmd; in lpfc_parse_bg_err()
2874 if (phba->sli_rev == LPFC_SLI_REV4) { in lpfc_parse_bg_err()
2875 wcqe = &pIocbOut->wcqe_cmpl; in lpfc_parse_bg_err()
2896 bghm = wcqe->total_data_placed; in lpfc_parse_bg_err()
2910 bgf = &pIocbOut->iocb.unsli3.sli3_bg; in lpfc_parse_bg_err()
2911 bghm = bgf->bghm; in lpfc_parse_bg_err()
2912 bgstat = bgf->bgstat; in lpfc_parse_bg_err()
2916 cmd->result = DID_ERROR << 16; in lpfc_parse_bg_err()
2920 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
2923 ret = (-1); in lpfc_parse_bg_err()
2928 cmd->result = DID_ERROR << 16; in lpfc_parse_bg_err()
2932 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
2935 ret = (-1); in lpfc_parse_bg_err()
2943 phba->bg_guard_err_cnt++; in lpfc_parse_bg_err()
2947 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
2956 phba->bg_reftag_err_cnt++; in lpfc_parse_bg_err()
2960 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
2969 phba->bg_apptag_err_cnt++; in lpfc_parse_bg_err()
2973 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
2980 * setup sense data descriptor 0 per SPC-4 as an information in lpfc_parse_bg_err()
2985 cmd->sense_buffer[7] = 0xc; /* Additional sense length */ in lpfc_parse_bg_err()
2986 cmd->sense_buffer[8] = 0; /* Information descriptor type */ in lpfc_parse_bg_err()
2987 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ in lpfc_parse_bg_err()
2988 cmd->sense_buffer[10] = 0x80; /* Validity bit */ in lpfc_parse_bg_err()
2990 /* bghm is a "on the wire" FC frame based count */ in lpfc_parse_bg_err()
2994 bghm /= cmd->device->sector_size; in lpfc_parse_bg_err()
3000 bghm /= (cmd->device->sector_size + in lpfc_parse_bg_err()
3009 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); in lpfc_parse_bg_err()
3013 /* No error was reported - problem in FW? */ in lpfc_parse_bg_err()
3017 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], in lpfc_parse_bg_err()
3029 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3033 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3034 * field of @lpfc_cmd for device with SLI-4 interface spec.
3037 * 2 - Error - Do not retry
3038 * 1 - Error - Retry
3039 * 0 - Success
3044 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_scsi_prep_dma_buf_s4()
3046 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_dma_buf_s4()
3047 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; in lpfc_scsi_prep_dma_buf_s4()
3049 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; in lpfc_scsi_prep_dma_buf_s4()
3050 struct lpfc_vport *vport = phba->pport; in lpfc_scsi_prep_dma_buf_s4()
3051 union lpfc_wqe128 *wqe = &pwqeq->wqe; in lpfc_scsi_prep_dma_buf_s4()
3061 * There are three possibilities here - use scatter-gather segment, use in lpfc_scsi_prep_dma_buf_s4()
3069 * because this a count of dma-mappings used to map the use_sg in lpfc_scsi_prep_dma_buf_s4()
3079 sgl->word2 = le32_to_cpu(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3081 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3084 lpfc_cmd->seg_cnt = nseg; in lpfc_scsi_prep_dma_buf_s4()
3085 if (!phba->cfg_xpsgl && in lpfc_scsi_prep_dma_buf_s4()
3086 lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { in lpfc_scsi_prep_dma_buf_s4()
3091 __func__, phba->cfg_sg_seg_cnt, in lpfc_scsi_prep_dma_buf_s4()
3092 lpfc_cmd->seg_cnt); in lpfc_scsi_prep_dma_buf_s4()
3093 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); in lpfc_scsi_prep_dma_buf_s4()
3094 lpfc_cmd->seg_cnt = 0; in lpfc_scsi_prep_dma_buf_s4()
3100 * The driver established a maximum scatter-gather segment count in lpfc_scsi_prep_dma_buf_s4()
3104 * When using SLI-3 the driver will try to fit all the BDEs into in lpfc_scsi_prep_dma_buf_s4()
3106 * does for SLI-2 mode. in lpfc_scsi_prep_dma_buf_s4()
3113 sgl->word2 = 0; in lpfc_scsi_prep_dma_buf_s4()
3123 !((j + 1) % phba->border_sge_num) && in lpfc_scsi_prep_dma_buf_s4()
3124 ((nseg - 1) != i)) { in lpfc_scsi_prep_dma_buf_s4()
3133 lpfc_cmd->seg_cnt = 0; in lpfc_scsi_prep_dma_buf_s4()
3137 sgl->addr_lo = cpu_to_le32(putPaddrLow( in lpfc_scsi_prep_dma_buf_s4()
3138 sgl_xtra->dma_phys_sgl)); in lpfc_scsi_prep_dma_buf_s4()
3139 sgl->addr_hi = cpu_to_le32(putPaddrHigh( in lpfc_scsi_prep_dma_buf_s4()
3140 sgl_xtra->dma_phys_sgl)); in lpfc_scsi_prep_dma_buf_s4()
3150 if ((nseg - 1) == i) in lpfc_scsi_prep_dma_buf_s4()
3155 sgl->addr_lo = cpu_to_le32(putPaddrLow( in lpfc_scsi_prep_dma_buf_s4()
3157 sgl->addr_hi = cpu_to_le32(putPaddrHigh( in lpfc_scsi_prep_dma_buf_s4()
3161 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3162 sgl->sge_len = cpu_to_le32(dma_len); in lpfc_scsi_prep_dma_buf_s4()
3171 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3172 sgl->sge_len = cpu_to_le32( in lpfc_scsi_prep_dma_buf_s4()
3173 phba->cfg_sg_dma_buf_size); in lpfc_scsi_prep_dma_buf_s4()
3175 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; in lpfc_scsi_prep_dma_buf_s4()
3176 i = i - 1; in lpfc_scsi_prep_dma_buf_s4()
3189 ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || in lpfc_scsi_prep_dma_buf_s4()
3190 phba->cfg_enable_pbde)) { in lpfc_scsi_prep_dma_buf_s4()
3191 /* Words 13-15 */ in lpfc_scsi_prep_dma_buf_s4()
3193 &wqe->words[13]; in lpfc_scsi_prep_dma_buf_s4()
3194 bde->addrLow = first_data_sgl->addr_lo; in lpfc_scsi_prep_dma_buf_s4()
3195 bde->addrHigh = first_data_sgl->addr_hi; in lpfc_scsi_prep_dma_buf_s4()
3196 bde->tus.f.bdeSize = in lpfc_scsi_prep_dma_buf_s4()
3197 le32_to_cpu(first_data_sgl->sge_len); in lpfc_scsi_prep_dma_buf_s4()
3198 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; in lpfc_scsi_prep_dma_buf_s4()
3199 bde->tus.w = cpu_to_le32(bde->tus.w); in lpfc_scsi_prep_dma_buf_s4()
3201 /* Word 11 - set PBDE bit */ in lpfc_scsi_prep_dma_buf_s4()
3202 bf_set(wqe_pbde, &wqe->generic.wqe_com, 1); in lpfc_scsi_prep_dma_buf_s4()
3204 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3)); in lpfc_scsi_prep_dma_buf_s4()
3205 /* Word 11 - PBDE bit disabled by default template */ in lpfc_scsi_prep_dma_buf_s4()
3210 sgl->word2 = le32_to_cpu(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3212 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_scsi_prep_dma_buf_s4()
3214 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || in lpfc_scsi_prep_dma_buf_s4()
3215 phba->cfg_enable_pbde) { in lpfc_scsi_prep_dma_buf_s4()
3217 &wqe->words[13]; in lpfc_scsi_prep_dma_buf_s4()
3224 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is in lpfc_scsi_prep_dma_buf_s4()
3228 if (scsi_cmnd->cmd_len > LPFC_FCP_CDB_LEN) in lpfc_scsi_prep_dma_buf_s4()
3229 ((struct fcp_cmnd32 *)fcp_cmnd)->fcpDl = in lpfc_scsi_prep_dma_buf_s4()
3232 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); in lpfc_scsi_prep_dma_buf_s4()
3233 /* Set first-burst provided it was successfully negotiated */ in lpfc_scsi_prep_dma_buf_s4()
3234 if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag) && in lpfc_scsi_prep_dma_buf_s4()
3235 vport->cfg_first_burst_size && in lpfc_scsi_prep_dma_buf_s4()
3236 scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) { in lpfc_scsi_prep_dma_buf_s4()
3240 init_len = min(total_len, vport->cfg_first_burst_size); in lpfc_scsi_prep_dma_buf_s4()
3243 wqe->fcp_iwrite.initial_xfer_len = init_len; in lpfc_scsi_prep_dma_buf_s4()
3244 wqe->fcp_iwrite.total_xfer_len = total_len; in lpfc_scsi_prep_dma_buf_s4()
3247 wqe->fcp_iwrite.total_xfer_len = in lpfc_scsi_prep_dma_buf_s4()
3248 be32_to_cpu(fcp_cmnd->fcpDl); in lpfc_scsi_prep_dma_buf_s4()
3255 if ((phba->cfg_fof) && ((struct lpfc_device_data *) in lpfc_scsi_prep_dma_buf_s4()
3256 scsi_cmnd->device->hostdata)->oas_enabled) { in lpfc_scsi_prep_dma_buf_s4()
3257 lpfc_cmd->cur_iocbq.cmd_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); in lpfc_scsi_prep_dma_buf_s4()
3258 lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) in lpfc_scsi_prep_dma_buf_s4()
3259 scsi_cmnd->device->hostdata)->priority; in lpfc_scsi_prep_dma_buf_s4()
3262 bf_set(wqe_oas, &wqe->generic.wqe_com, 1); in lpfc_scsi_prep_dma_buf_s4()
3263 bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1); in lpfc_scsi_prep_dma_buf_s4()
3265 if (lpfc_cmd->cur_iocbq.priority) in lpfc_scsi_prep_dma_buf_s4()
3266 bf_set(wqe_ccp, &wqe->generic.wqe_com, in lpfc_scsi_prep_dma_buf_s4()
3267 (lpfc_cmd->cur_iocbq.priority << 1)); in lpfc_scsi_prep_dma_buf_s4()
3269 bf_set(wqe_ccp, &wqe->generic.wqe_com, in lpfc_scsi_prep_dma_buf_s4()
3270 (phba->cfg_XLanePriority << 1)); in lpfc_scsi_prep_dma_buf_s4()
3277 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3285 * 2 - Error - Do not retry
3286 * 1 - Error - Retry
3287 * 0 - Success
3293 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_bg_scsi_prep_dma_buf_s4()
3294 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_bg_scsi_prep_dma_buf_s4()
3295 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl); in lpfc_bg_scsi_prep_dma_buf_s4()
3296 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; in lpfc_bg_scsi_prep_dma_buf_s4()
3297 union lpfc_wqe128 *wqe = &pwqeq->wqe; in lpfc_bg_scsi_prep_dma_buf_s4()
3299 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; in lpfc_bg_scsi_prep_dma_buf_s4()
3303 struct lpfc_vport *vport = phba->pport; in lpfc_bg_scsi_prep_dma_buf_s4()
3312 * because this a count of dma-mappings used to map the use_sg in lpfc_bg_scsi_prep_dma_buf_s4()
3316 datasegcnt = dma_map_sg(&phba->pcidev->dev, in lpfc_bg_scsi_prep_dma_buf_s4()
3324 sgl->word2 = le32_to_cpu(sgl->word2); in lpfc_bg_scsi_prep_dma_buf_s4()
3326 sgl->word2 = cpu_to_le32(sgl->word2); in lpfc_bg_scsi_prep_dma_buf_s4()
3329 lpfc_cmd->seg_cnt = datasegcnt; in lpfc_bg_scsi_prep_dma_buf_s4()
3332 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt && in lpfc_bg_scsi_prep_dma_buf_s4()
3333 !phba->cfg_xpsgl) { in lpfc_bg_scsi_prep_dma_buf_s4()
3334 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); in lpfc_bg_scsi_prep_dma_buf_s4()
3344 if (((lpfc_cmd->seg_cnt + 1) > in lpfc_bg_scsi_prep_dma_buf_s4()
3345 phba->cfg_total_seg_cnt) && in lpfc_bg_scsi_prep_dma_buf_s4()
3346 !phba->cfg_xpsgl) { in lpfc_bg_scsi_prep_dma_buf_s4()
3367 protsegcnt = dma_map_sg(&phba->pcidev->dev, in lpfc_bg_scsi_prep_dma_buf_s4()
3375 lpfc_cmd->prot_seg_cnt = protsegcnt; in lpfc_bg_scsi_prep_dma_buf_s4()
3380 if (((lpfc_cmd->prot_seg_cnt * 3) > in lpfc_bg_scsi_prep_dma_buf_s4()
3381 (phba->cfg_total_seg_cnt - 2)) && in lpfc_bg_scsi_prep_dma_buf_s4()
3382 !phba->cfg_xpsgl) { in lpfc_bg_scsi_prep_dma_buf_s4()
3392 (num_sge > phba->cfg_total_seg_cnt && in lpfc_bg_scsi_prep_dma_buf_s4()
3393 !phba->cfg_xpsgl)) { in lpfc_bg_scsi_prep_dma_buf_s4()
3402 lpfc_cmd->seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s4()
3414 lpfc_cmd->cur_iocbq.cmd_flag |= LPFC_IO_DIF_STRIP; in lpfc_bg_scsi_prep_dma_buf_s4()
3418 lpfc_cmd->cur_iocbq.cmd_flag |= LPFC_IO_DIF_INSERT; in lpfc_bg_scsi_prep_dma_buf_s4()
3422 lpfc_cmd->cur_iocbq.cmd_flag |= LPFC_IO_DIF_PASS; in lpfc_bg_scsi_prep_dma_buf_s4()
3427 if (lpfc_cmd->pCmd->cmd_len > LPFC_FCP_CDB_LEN) in lpfc_bg_scsi_prep_dma_buf_s4()
3428 ((struct fcp_cmnd32 *)fcp_cmnd)->fcpDl = cpu_to_be32(fcpdl); in lpfc_bg_scsi_prep_dma_buf_s4()
3430 fcp_cmnd->fcpDl = cpu_to_be32(fcpdl); in lpfc_bg_scsi_prep_dma_buf_s4()
3432 /* Set first-burst provided it was successfully negotiated */ in lpfc_bg_scsi_prep_dma_buf_s4()
3433 if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag) && in lpfc_bg_scsi_prep_dma_buf_s4()
3434 vport->cfg_first_burst_size && in lpfc_bg_scsi_prep_dma_buf_s4()
3435 scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) { in lpfc_bg_scsi_prep_dma_buf_s4()
3439 init_len = min(total_len, vport->cfg_first_burst_size); in lpfc_bg_scsi_prep_dma_buf_s4()
3442 wqe->fcp_iwrite.initial_xfer_len = init_len; in lpfc_bg_scsi_prep_dma_buf_s4()
3443 wqe->fcp_iwrite.total_xfer_len = total_len; in lpfc_bg_scsi_prep_dma_buf_s4()
3446 wqe->fcp_iwrite.total_xfer_len = fcpdl; in lpfc_bg_scsi_prep_dma_buf_s4()
3453 if ((phba->cfg_fof) && ((struct lpfc_device_data *) in lpfc_bg_scsi_prep_dma_buf_s4()
3454 scsi_cmnd->device->hostdata)->oas_enabled) { in lpfc_bg_scsi_prep_dma_buf_s4()
3455 lpfc_cmd->cur_iocbq.cmd_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); in lpfc_bg_scsi_prep_dma_buf_s4()
3458 bf_set(wqe_oas, &wqe->generic.wqe_com, 1); in lpfc_bg_scsi_prep_dma_buf_s4()
3459 bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1); in lpfc_bg_scsi_prep_dma_buf_s4()
3460 bf_set(wqe_ccp, &wqe->generic.wqe_com, in lpfc_bg_scsi_prep_dma_buf_s4()
3461 (phba->cfg_XLanePriority << 1)); in lpfc_bg_scsi_prep_dma_buf_s4()
3465 if (lpfc_cmd->cur_iocbq.cmd_flag & LPFC_IO_DIF_PASS) in lpfc_bg_scsi_prep_dma_buf_s4()
3466 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); in lpfc_bg_scsi_prep_dma_buf_s4()
3467 else if (lpfc_cmd->cur_iocbq.cmd_flag & LPFC_IO_DIF_STRIP) in lpfc_bg_scsi_prep_dma_buf_s4()
3468 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); in lpfc_bg_scsi_prep_dma_buf_s4()
3469 else if (lpfc_cmd->cur_iocbq.cmd_flag & LPFC_IO_DIF_INSERT) in lpfc_bg_scsi_prep_dma_buf_s4()
3470 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); in lpfc_bg_scsi_prep_dma_buf_s4()
3472 lpfc_cmd->cur_iocbq.cmd_flag &= ~(LPFC_IO_DIF_PASS | in lpfc_bg_scsi_prep_dma_buf_s4()
3477 if (lpfc_cmd->seg_cnt) in lpfc_bg_scsi_prep_dma_buf_s4()
3479 if (lpfc_cmd->prot_seg_cnt) in lpfc_bg_scsi_prep_dma_buf_s4()
3480 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), in lpfc_bg_scsi_prep_dma_buf_s4()
3482 scsi_cmnd->sc_data_direction); in lpfc_bg_scsi_prep_dma_buf_s4()
3487 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, in lpfc_bg_scsi_prep_dma_buf_s4()
3488 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, in lpfc_bg_scsi_prep_dma_buf_s4()
3491 lpfc_cmd->seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s4()
3492 lpfc_cmd->prot_seg_cnt = 0; in lpfc_bg_scsi_prep_dma_buf_s4()
3497 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3505 * 1 - Error
3506 * 0 - Success
3511 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); in lpfc_scsi_prep_dma_buf()
3515 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3524 * 1 - Error
3525 * 0 - Success
3530 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); in lpfc_bg_scsi_prep_dma_buf()
3534 * lpfc_scsi_prep_cmnd_buf - Wrapper function for IOCB/WQE mapping of scsi
3543 * 1 - Error
3544 * 0 - Success
3550 return vport->phba->lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, tmo); in lpfc_scsi_prep_cmnd_buf()
3554 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3566 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; in lpfc_send_scsi_error_event()
3567 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; in lpfc_send_scsi_error_event()
3568 uint32_t resp_info = fcprsp->rspStatus2; in lpfc_send_scsi_error_event()
3569 uint32_t scsi_status = fcprsp->rspStatus3; in lpfc_send_scsi_error_event()
3571 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; in lpfc_send_scsi_error_event()
3578 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || in lpfc_send_scsi_error_event()
3579 (cmnd->result == SAM_STAT_BUSY)) { in lpfc_send_scsi_error_event()
3583 fast_path_evt->un.scsi_evt.event_type = in lpfc_send_scsi_error_event()
3585 fast_path_evt->un.scsi_evt.subcategory = in lpfc_send_scsi_error_event()
3586 (cmnd->result == SAM_STAT_TASK_SET_FULL) ? in lpfc_send_scsi_error_event()
3588 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; in lpfc_send_scsi_error_event()
3589 memcpy(&fast_path_evt->un.scsi_evt.wwpn, in lpfc_send_scsi_error_event()
3590 &pnode->nlp_portname, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3591 memcpy(&fast_path_evt->un.scsi_evt.wwnn, in lpfc_send_scsi_error_event()
3592 &pnode->nlp_nodename, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3593 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && in lpfc_send_scsi_error_event()
3594 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { in lpfc_send_scsi_error_event()
3598 fast_path_evt->un.check_cond_evt.scsi_event.event_type = in lpfc_send_scsi_error_event()
3600 fast_path_evt->un.check_cond_evt.scsi_event.subcategory = in lpfc_send_scsi_error_event()
3602 fast_path_evt->un.check_cond_evt.scsi_event.lun = in lpfc_send_scsi_error_event()
3603 cmnd->device->lun; in lpfc_send_scsi_error_event()
3604 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, in lpfc_send_scsi_error_event()
3605 &pnode->nlp_portname, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3606 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, in lpfc_send_scsi_error_event()
3607 &pnode->nlp_nodename, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3608 fast_path_evt->un.check_cond_evt.sense_key = in lpfc_send_scsi_error_event()
3609 cmnd->sense_buffer[2] & 0xf; in lpfc_send_scsi_error_event()
3610 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; in lpfc_send_scsi_error_event()
3611 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; in lpfc_send_scsi_error_event()
3612 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && in lpfc_send_scsi_error_event()
3614 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || in lpfc_send_scsi_error_event()
3624 fast_path_evt->un.read_check_error.header.event_type = in lpfc_send_scsi_error_event()
3626 fast_path_evt->un.read_check_error.header.subcategory = in lpfc_send_scsi_error_event()
3628 memcpy(&fast_path_evt->un.read_check_error.header.wwpn, in lpfc_send_scsi_error_event()
3629 &pnode->nlp_portname, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3630 memcpy(&fast_path_evt->un.read_check_error.header.wwnn, in lpfc_send_scsi_error_event()
3631 &pnode->nlp_nodename, sizeof(struct lpfc_name)); in lpfc_send_scsi_error_event()
3632 fast_path_evt->un.read_check_error.lun = cmnd->device->lun; in lpfc_send_scsi_error_event()
3633 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; in lpfc_send_scsi_error_event()
3634 fast_path_evt->un.read_check_error.fcpiparam = in lpfc_send_scsi_error_event()
3639 fast_path_evt->vport = vport; in lpfc_send_scsi_error_event()
3640 spin_lock_irqsave(&phba->hbalock, flags); in lpfc_send_scsi_error_event()
3641 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); in lpfc_send_scsi_error_event()
3642 spin_unlock_irqrestore(&phba->hbalock, flags); in lpfc_send_scsi_error_event()
3648 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3650 * @psb: The scsi buffer which is going to be un-mapped.
3652 * This routine does DMA un-mapping of scatter gather list of scsi command
3653 * field of @lpfc_cmd for device with SLI-3 interface spec.
3660 * requested scatter-gather usage or (2) the scsi command allocated in lpfc_scsi_unprep_dma_buf()
3664 if (psb->seg_cnt > 0) in lpfc_scsi_unprep_dma_buf()
3665 scsi_dma_unmap(psb->pCmd); in lpfc_scsi_unprep_dma_buf()
3666 if (psb->prot_seg_cnt > 0) in lpfc_scsi_unprep_dma_buf()
3667 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), in lpfc_scsi_unprep_dma_buf()
3668 scsi_prot_sg_count(psb->pCmd), in lpfc_scsi_unprep_dma_buf()
3669 psb->pCmd->sc_data_direction); in lpfc_scsi_unprep_dma_buf()
3673 * lpfc_unblock_requests - allow further commands to be queued.
3686 if (phba->sli_rev == LPFC_SLI_REV4 && in lpfc_unblock_requests()
3687 !phba->sli4_hba.max_cfg_param.vpi_used) { in lpfc_unblock_requests()
3688 shost = lpfc_shost_from_vport(phba->pport); in lpfc_unblock_requests()
3695 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { in lpfc_unblock_requests()
3703 * lpfc_block_requests - prevent further commands from being queued.
3716 if (atomic_read(&phba->cmf_stop_io)) in lpfc_block_requests()
3719 if (phba->sli_rev == LPFC_SLI_REV4 && in lpfc_block_requests()
3720 !phba->sli4_hba.max_cfg_param.vpi_used) { in lpfc_block_requests()
3721 shost = lpfc_shost_from_vport(phba->pport); in lpfc_block_requests()
3728 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { in lpfc_block_requests()
3736 * lpfc_update_cmf_cmpl - Adjust CMF counters for IO completion
3761 cgs = per_cpu_ptr(phba->cmf_stat, raw_smp_processor_id()); in lpfc_update_cmf_cmpl()
3762 atomic64_add(size, &cgs->rcv_bytes); in lpfc_update_cmf_cmpl()
3763 atomic64_add(time, &cgs->rx_latency); in lpfc_update_cmf_cmpl()
3764 atomic_inc(&cgs->rx_io_cnt); in lpfc_update_cmf_cmpl()
3770 * lpfc_update_cmf_cmd - Adjust CMF counters for IO submission
3785 if (phba->cmf_active_mode == LPFC_CFG_MANAGED && in lpfc_update_cmf_cmd()
3786 phba->cmf_max_bytes_per_interval) { in lpfc_update_cmf_cmd()
3789 cgs = per_cpu_ptr(phba->cmf_stat, cpu); in lpfc_update_cmf_cmd()
3790 total += atomic64_read(&cgs->total_bytes); in lpfc_update_cmf_cmd()
3792 if (total >= phba->cmf_max_bytes_per_interval) { in lpfc_update_cmf_cmd()
3793 if (!atomic_xchg(&phba->cmf_bw_wait, 1)) { in lpfc_update_cmf_cmd()
3795 phba->cmf_last_ts = in lpfc_update_cmf_cmd()
3798 atomic_inc(&phba->cmf_busy); in lpfc_update_cmf_cmd()
3799 return -EBUSY; in lpfc_update_cmf_cmd()
3801 if (size > atomic_read(&phba->rx_max_read_cnt)) in lpfc_update_cmf_cmd()
3802 atomic_set(&phba->rx_max_read_cnt, size); in lpfc_update_cmf_cmd()
3805 cgs = per_cpu_ptr(phba->cmf_stat, raw_smp_processor_id()); in lpfc_update_cmf_cmd()
3806 atomic64_add(size, &cgs->total_bytes); in lpfc_update_cmf_cmd()
3811 * lpfc_handle_fcp_err - FCP response handler
3812 * @vport: The virtual port for which this call is being executed.
3824 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; in lpfc_handle_fcp_err()
3825 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; in lpfc_handle_fcp_err()
3826 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; in lpfc_handle_fcp_err()
3827 uint32_t resp_info = fcprsp->rspStatus2; in lpfc_handle_fcp_err()
3828 uint32_t scsi_status = fcprsp->rspStatus3; in lpfc_handle_fcp_err()
3841 if (fcpcmd->fcpCntl2) { in lpfc_handle_fcp_err()
3847 rsplen = be32_to_cpu(fcprsp->rspRspLen); in lpfc_handle_fcp_err()
3852 "x%x\n", cmnd->device->id, in lpfc_handle_fcp_err()
3853 cmnd->device->lun, cmnd->cmnd[0], in lpfc_handle_fcp_err()
3858 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { in lpfc_handle_fcp_err()
3863 cmnd->device->id, in lpfc_handle_fcp_err()
3864 cmnd->device->lun, cmnd->cmnd[0], in lpfc_handle_fcp_err()
3865 fcprsp->rspInfo3); in lpfc_handle_fcp_err()
3871 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { in lpfc_handle_fcp_err()
3872 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); in lpfc_handle_fcp_err()
3877 rsplen = be32_to_cpu(fcprsp->rspRspLen); in lpfc_handle_fcp_err()
3878 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); in lpfc_handle_fcp_err()
3880 lp = (uint32_t *)cmnd->sense_buffer; in lpfc_handle_fcp_err()
3885 if (vport->cfg_log_verbose & LOG_FCP) in lpfc_handle_fcp_err()
3888 if (vport->cfg_log_verbose & LOG_FCP_UNDER) in lpfc_handle_fcp_err()
3895 cmnd->cmnd[0], scsi_status, in lpfc_handle_fcp_err()
3897 be32_to_cpu(fcprsp->rspResId), in lpfc_handle_fcp_err()
3898 be32_to_cpu(fcprsp->rspSnsLen), in lpfc_handle_fcp_err()
3899 be32_to_cpu(fcprsp->rspRspLen), in lpfc_handle_fcp_err()
3900 fcprsp->rspInfo3); in lpfc_handle_fcp_err()
3903 if (cmnd->cmd_len > LPFC_FCP_CDB_LEN) in lpfc_handle_fcp_err()
3904 fcpDl = be32_to_cpu(((struct fcp_cmnd32 *)fcpcmd)->fcpDl); in lpfc_handle_fcp_err()
3906 fcpDl = be32_to_cpu(fcpcmd->fcpDl); in lpfc_handle_fcp_err()
3908 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); in lpfc_handle_fcp_err()
3914 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], in lpfc_handle_fcp_err()
3915 cmnd->underflow); in lpfc_handle_fcp_err()
3929 cmnd->cmnd[0]); in lpfc_handle_fcp_err()
3934 * The cmnd->underflow is the minimum number of bytes that must in lpfc_handle_fcp_err()
3941 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) in lpfc_handle_fcp_err()
3942 < cmnd->underflow)) { in lpfc_handle_fcp_err()
3947 cmnd->cmnd[0], scsi_bufflen(cmnd), in lpfc_handle_fcp_err()
3948 scsi_get_resid(cmnd), cmnd->underflow); in lpfc_handle_fcp_err()
3954 "Data: x%x x%x\n", cmnd->cmnd[0], in lpfc_handle_fcp_err()
3966 ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? in lpfc_handle_fcp_err()
3968 fcpDl, be32_to_cpu(fcprsp->rspResId), in lpfc_handle_fcp_err()
3969 fcpi_parm, cmnd->cmnd[0], scsi_status); in lpfc_handle_fcp_err()
3993 cmnd->result = host_status << 16 | scsi_status; in lpfc_handle_fcp_err()
3994 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, fcpi_parm); in lpfc_handle_fcp_err()
3998 * lpfc_fcp_io_cmd_wqe_cmpl - Complete a FCP IO
4011 struct lpfc_io_buf *lpfc_cmd = pwqeIn->io_buf; in lpfc_fcp_io_cmd_wqe_cmpl()
4012 struct lpfc_wcqe_complete *wcqe = &pwqeOut->wcqe_cmpl; in lpfc_fcp_io_cmd_wqe_cmpl()
4013 struct lpfc_vport *vport = pwqeIn->vport; in lpfc_fcp_io_cmd_wqe_cmpl()
4033 rdata = lpfc_cmd->rdata; in lpfc_fcp_io_cmd_wqe_cmpl()
4034 ndlp = rdata->pnode; in lpfc_fcp_io_cmd_wqe_cmpl()
4037 cmd = lpfc_cmd->pCmd; in lpfc_fcp_io_cmd_wqe_cmpl()
4045 spin_lock(&lpfc_cmd->buf_lock); in lpfc_fcp_io_cmd_wqe_cmpl()
4046 idx = lpfc_cmd->cur_iocbq.hba_wqidx; in lpfc_fcp_io_cmd_wqe_cmpl()
4047 if (phba->sli4_hba.hdwq) in lpfc_fcp_io_cmd_wqe_cmpl()
4048 phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++; in lpfc_fcp_io_cmd_wqe_cmpl()
4051 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) in lpfc_fcp_io_cmd_wqe_cmpl()
4052 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); in lpfc_fcp_io_cmd_wqe_cmpl()
4054 shost = cmd->device->host; in lpfc_fcp_io_cmd_wqe_cmpl()
4056 lpfc_cmd->status = bf_get(lpfc_wcqe_c_status, wcqe); in lpfc_fcp_io_cmd_wqe_cmpl()
4057 lpfc_cmd->result = (wcqe->parameter & IOERR_PARAM_MASK); in lpfc_fcp_io_cmd_wqe_cmpl()
4059 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; in lpfc_fcp_io_cmd_wqe_cmpl()
4061 lpfc_cmd->flags |= LPFC_SBUF_XBUSY; in lpfc_fcp_io_cmd_wqe_cmpl()
4062 if (phba->cfg_fcp_wait_abts_rsp) in lpfc_fcp_io_cmd_wqe_cmpl()
4067 if (lpfc_cmd->prot_data_type) { in lpfc_fcp_io_cmd_wqe_cmpl()
4070 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; in lpfc_fcp_io_cmd_wqe_cmpl()
4075 switch (lpfc_cmd->prot_data_type) { in lpfc_fcp_io_cmd_wqe_cmpl()
4077 src->ref_tag = in lpfc_fcp_io_cmd_wqe_cmpl()
4078 lpfc_cmd->prot_data; in lpfc_fcp_io_cmd_wqe_cmpl()
4081 src->app_tag = in lpfc_fcp_io_cmd_wqe_cmpl()
4082 (uint16_t)lpfc_cmd->prot_data; in lpfc_fcp_io_cmd_wqe_cmpl()
4085 src->guard_tag = in lpfc_fcp_io_cmd_wqe_cmpl()
4086 (uint16_t)lpfc_cmd->prot_data; in lpfc_fcp_io_cmd_wqe_cmpl()
4092 lpfc_cmd->prot_data = 0; in lpfc_fcp_io_cmd_wqe_cmpl()
4093 lpfc_cmd->prot_data_type = 0; in lpfc_fcp_io_cmd_wqe_cmpl()
4094 lpfc_cmd->prot_data_segment = NULL; in lpfc_fcp_io_cmd_wqe_cmpl()
4097 if (unlikely(lpfc_cmd->status)) { in lpfc_fcp_io_cmd_wqe_cmpl()
4098 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && in lpfc_fcp_io_cmd_wqe_cmpl()
4099 !lpfc_cmd->fcp_rsp->rspStatus3 && in lpfc_fcp_io_cmd_wqe_cmpl()
4100 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && in lpfc_fcp_io_cmd_wqe_cmpl()
4101 !(vport->cfg_log_verbose & LOG_FCP_UNDER)) in lpfc_fcp_io_cmd_wqe_cmpl()
4110 cmd->cmnd[0], in lpfc_fcp_io_cmd_wqe_cmpl()
4111 cmd->device ? cmd->device->id : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4112 cmd->device ? cmd->device->lun : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4113 lpfc_cmd->status, lpfc_cmd->result, in lpfc_fcp_io_cmd_wqe_cmpl()
4114 vport->fc_myDID, in lpfc_fcp_io_cmd_wqe_cmpl()
4115 (ndlp) ? ndlp->nlp_DID : 0, in lpfc_fcp_io_cmd_wqe_cmpl()
4116 lpfc_cmd->cur_iocbq.sli4_xritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4117 wcqe->parameter, wcqe->total_data_placed, in lpfc_fcp_io_cmd_wqe_cmpl()
4118 lpfc_cmd->cur_iocbq.iotag); in lpfc_fcp_io_cmd_wqe_cmpl()
4121 switch (lpfc_cmd->status) { in lpfc_fcp_io_cmd_wqe_cmpl()
4123 cmd->result = DID_OK << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4127 pwqeIn->wqe.fcp_iread.total_xfer_len - in lpfc_fcp_io_cmd_wqe_cmpl()
4128 wcqe->total_data_placed); in lpfc_fcp_io_cmd_wqe_cmpl()
4132 cmd->result = DID_TRANSPORT_DISRUPTED << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4136 fast_path_evt->un.fabric_evt.event_type = in lpfc_fcp_io_cmd_wqe_cmpl()
4138 fast_path_evt->un.fabric_evt.subcategory = in lpfc_fcp_io_cmd_wqe_cmpl()
4139 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? in lpfc_fcp_io_cmd_wqe_cmpl()
4142 memcpy(&fast_path_evt->un.fabric_evt.wwpn, in lpfc_fcp_io_cmd_wqe_cmpl()
4143 &ndlp->nlp_portname, in lpfc_fcp_io_cmd_wqe_cmpl()
4145 memcpy(&fast_path_evt->un.fabric_evt.wwnn, in lpfc_fcp_io_cmd_wqe_cmpl()
4146 &ndlp->nlp_nodename, in lpfc_fcp_io_cmd_wqe_cmpl()
4149 fast_path_evt->vport = vport; in lpfc_fcp_io_cmd_wqe_cmpl()
4150 fast_path_evt->work_evt.evt = in lpfc_fcp_io_cmd_wqe_cmpl()
4152 spin_lock_irqsave(&phba->hbalock, flags); in lpfc_fcp_io_cmd_wqe_cmpl()
4153 list_add_tail(&fast_path_evt->work_evt.evt_listp, in lpfc_fcp_io_cmd_wqe_cmpl()
4154 &phba->work_list); in lpfc_fcp_io_cmd_wqe_cmpl()
4155 spin_unlock_irqrestore(&phba->hbalock, flags); in lpfc_fcp_io_cmd_wqe_cmpl()
4163 cmd->cmnd[0], in lpfc_fcp_io_cmd_wqe_cmpl()
4164 cmd->device ? cmd->device->id : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4165 cmd->device ? cmd->device->lun : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4166 lpfc_cmd->status, lpfc_cmd->result, in lpfc_fcp_io_cmd_wqe_cmpl()
4167 vport->fc_myDID, in lpfc_fcp_io_cmd_wqe_cmpl()
4168 (ndlp) ? ndlp->nlp_DID : 0, in lpfc_fcp_io_cmd_wqe_cmpl()
4169 lpfc_cmd->cur_iocbq.sli4_xritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4170 wcqe->parameter, in lpfc_fcp_io_cmd_wqe_cmpl()
4171 wcqe->total_data_placed, in lpfc_fcp_io_cmd_wqe_cmpl()
4172 lpfc_cmd->cur_iocbq.iocb.ulpIoTag); in lpfc_fcp_io_cmd_wqe_cmpl()
4176 lpfc_cmd->result = IOERR_RX_DMA_FAILED; in lpfc_fcp_io_cmd_wqe_cmpl()
4178 lpfc_cmd->result = IOERR_TX_DMA_FAILED; in lpfc_fcp_io_cmd_wqe_cmpl()
4182 lpfc_cmd->cur_iocbq.sli4_xritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4183 lpfc_cmd->status, wcqe->parameter, in lpfc_fcp_io_cmd_wqe_cmpl()
4184 wcqe->total_data_placed); in lpfc_fcp_io_cmd_wqe_cmpl()
4190 cmd->result = DID_ERROR << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4201 lpfc_cmd->cur_iocbq.sli4_lxritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4206 if (lpfc_cmd->result & IOERR_DRVR_MASK) in lpfc_fcp_io_cmd_wqe_cmpl()
4207 lpfc_cmd->status = IOSTAT_DRIVER_REJECT; in lpfc_fcp_io_cmd_wqe_cmpl()
4208 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || in lpfc_fcp_io_cmd_wqe_cmpl()
4209 lpfc_cmd->result == in lpfc_fcp_io_cmd_wqe_cmpl()
4211 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || in lpfc_fcp_io_cmd_wqe_cmpl()
4212 lpfc_cmd->result == in lpfc_fcp_io_cmd_wqe_cmpl()
4214 cmd->result = DID_NO_CONNECT << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4217 if (lpfc_cmd->result == IOERR_INVALID_RPI || in lpfc_fcp_io_cmd_wqe_cmpl()
4218 lpfc_cmd->result == IOERR_LINK_DOWN || in lpfc_fcp_io_cmd_wqe_cmpl()
4219 lpfc_cmd->result == IOERR_NO_RESOURCES || in lpfc_fcp_io_cmd_wqe_cmpl()
4220 lpfc_cmd->result == IOERR_ABORT_REQUESTED || in lpfc_fcp_io_cmd_wqe_cmpl()
4221 lpfc_cmd->result == IOERR_RPI_SUSPENDED || in lpfc_fcp_io_cmd_wqe_cmpl()
4222 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { in lpfc_fcp_io_cmd_wqe_cmpl()
4223 cmd->result = DID_TRANSPORT_DISRUPTED << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4232 cmd->cmnd[0], in lpfc_fcp_io_cmd_wqe_cmpl()
4233 cmd->device ? cmd->device->id : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4234 cmd->device ? cmd->device->lun : 0xffff, in lpfc_fcp_io_cmd_wqe_cmpl()
4235 lpfc_cmd->status, lpfc_cmd->result, in lpfc_fcp_io_cmd_wqe_cmpl()
4236 vport->fc_myDID, in lpfc_fcp_io_cmd_wqe_cmpl()
4237 (ndlp) ? ndlp->nlp_DID : 0, in lpfc_fcp_io_cmd_wqe_cmpl()
4238 lpfc_cmd->cur_iocbq.sli4_xritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4239 wcqe->parameter, in lpfc_fcp_io_cmd_wqe_cmpl()
4240 wcqe->total_data_placed, in lpfc_fcp_io_cmd_wqe_cmpl()
4241 lpfc_cmd->cur_iocbq.iocb.ulpIoTag); in lpfc_fcp_io_cmd_wqe_cmpl()
4244 cmd->result = DID_ERROR << 16; in lpfc_fcp_io_cmd_wqe_cmpl()
4249 lpfc_cmd->cur_iocbq.sli4_xritag, in lpfc_fcp_io_cmd_wqe_cmpl()
4250 lpfc_cmd->status, lpfc_cmd->result, in lpfc_fcp_io_cmd_wqe_cmpl()
4251 wcqe->parameter, in lpfc_fcp_io_cmd_wqe_cmpl()
4252 wcqe->total_data_placed); in lpfc_fcp_io_cmd_wqe_cmpl()
4254 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { in lpfc_fcp_io_cmd_wqe_cmpl()
4255 u32 *lp = (u32 *)cmd->sense_buffer; in lpfc_fcp_io_cmd_wqe_cmpl()
4260 cmd->device->id, cmd->device->lun, cmd, in lpfc_fcp_io_cmd_wqe_cmpl()
4261 cmd->result, *lp, *(lp + 3), in lpfc_fcp_io_cmd_wqe_cmpl()
4262 (cmd->device->sector_size) ? in lpfc_fcp_io_cmd_wqe_cmpl()
4264 cmd->retries, scsi_get_resid(cmd)); in lpfc_fcp_io_cmd_wqe_cmpl()
4267 if (vport->cfg_max_scsicmpl_time && in lpfc_fcp_io_cmd_wqe_cmpl()
4268 time_after(jiffies, lpfc_cmd->start_time + in lpfc_fcp_io_cmd_wqe_cmpl()
4269 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { in lpfc_fcp_io_cmd_wqe_cmpl()
4270 spin_lock_irqsave(shost->host_lock, flags); in lpfc_fcp_io_cmd_wqe_cmpl()
4272 if (ndlp->cmd_qdepth > in lpfc_fcp_io_cmd_wqe_cmpl()
4273 atomic_read(&ndlp->cmd_pending) && in lpfc_fcp_io_cmd_wqe_cmpl()
4274 (atomic_read(&ndlp->cmd_pending) > in lpfc_fcp_io_cmd_wqe_cmpl()
4276 (cmd->cmnd[0] == READ_10 || in lpfc_fcp_io_cmd_wqe_cmpl()
4277 cmd->cmnd[0] == WRITE_10)) in lpfc_fcp_io_cmd_wqe_cmpl()
4278 ndlp->cmd_qdepth = in lpfc_fcp_io_cmd_wqe_cmpl()
4279 atomic_read(&ndlp->cmd_pending); in lpfc_fcp_io_cmd_wqe_cmpl()
4281 ndlp->last_change_time = jiffies; in lpfc_fcp_io_cmd_wqe_cmpl()
4283 spin_unlock_irqrestore(shost->host_lock, flags); in lpfc_fcp_io_cmd_wqe_cmpl()
4288 if (lpfc_cmd->ts_cmd_start) { in lpfc_fcp_io_cmd_wqe_cmpl()
4289 lpfc_cmd->ts_isr_cmpl = lpfc_cmd->cur_iocbq.isr_timestamp; in lpfc_fcp_io_cmd_wqe_cmpl()
4290 lpfc_cmd->ts_data_io = ktime_get_ns(); in lpfc_fcp_io_cmd_wqe_cmpl()
4291 phba->ktime_last_cmd = lpfc_cmd->ts_data_io; in lpfc_fcp_io_cmd_wqe_cmpl()
4296 lpfc_cmd->pCmd = NULL; in lpfc_fcp_io_cmd_wqe_cmpl()
4297 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_fcp_io_cmd_wqe_cmpl()
4300 if (phba->cmf_active_mode != LPFC_CFG_OFF && in lpfc_fcp_io_cmd_wqe_cmpl()
4301 cmd->sc_data_direction == DMA_FROM_DEVICE && in lpfc_fcp_io_cmd_wqe_cmpl()
4304 lat = ktime_get_ns() - lpfc_cmd->rx_cmd_start; in lpfc_fcp_io_cmd_wqe_cmpl()
4318 spin_lock(&lpfc_cmd->buf_lock); in lpfc_fcp_io_cmd_wqe_cmpl()
4319 lpfc_cmd->cur_iocbq.cmd_flag &= ~LPFC_DRIVER_ABORTED; in lpfc_fcp_io_cmd_wqe_cmpl()
4320 if (lpfc_cmd->waitq) in lpfc_fcp_io_cmd_wqe_cmpl()
4321 wake_up(lpfc_cmd->waitq); in lpfc_fcp_io_cmd_wqe_cmpl()
4322 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_fcp_io_cmd_wqe_cmpl()
4328 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
4342 (struct lpfc_io_buf *) pIocbIn->io_buf; in lpfc_scsi_cmd_iocb_cmpl()
4343 struct lpfc_vport *vport = pIocbIn->vport; in lpfc_scsi_cmd_iocb_cmpl()
4344 struct lpfc_rport_data *rdata = lpfc_cmd->rdata; in lpfc_scsi_cmd_iocb_cmpl()
4345 struct lpfc_nodelist *pnode = rdata->pnode; in lpfc_scsi_cmd_iocb_cmpl()
4354 spin_lock(&lpfc_cmd->buf_lock); in lpfc_scsi_cmd_iocb_cmpl()
4357 cmd = lpfc_cmd->pCmd; in lpfc_scsi_cmd_iocb_cmpl()
4361 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_scsi_cmd_iocb_cmpl()
4365 idx = lpfc_cmd->cur_iocbq.hba_wqidx; in lpfc_scsi_cmd_iocb_cmpl()
4366 if (phba->sli4_hba.hdwq) in lpfc_scsi_cmd_iocb_cmpl()
4367 phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++; in lpfc_scsi_cmd_iocb_cmpl()
4370 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) in lpfc_scsi_cmd_iocb_cmpl()
4371 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); in lpfc_scsi_cmd_iocb_cmpl()
4373 shost = cmd->device->host; in lpfc_scsi_cmd_iocb_cmpl()
4375 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); in lpfc_scsi_cmd_iocb_cmpl()
4376 lpfc_cmd->status = pIocbOut->iocb.ulpStatus; in lpfc_scsi_cmd_iocb_cmpl()
4378 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; in lpfc_scsi_cmd_iocb_cmpl()
4379 if (pIocbOut->cmd_flag & LPFC_EXCHANGE_BUSY) in lpfc_scsi_cmd_iocb_cmpl()
4380 lpfc_cmd->flags |= LPFC_SBUF_XBUSY; in lpfc_scsi_cmd_iocb_cmpl()
4383 if (lpfc_cmd->prot_data_type) { in lpfc_scsi_cmd_iocb_cmpl()
4386 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; in lpfc_scsi_cmd_iocb_cmpl()
4391 switch (lpfc_cmd->prot_data_type) { in lpfc_scsi_cmd_iocb_cmpl()
4393 src->ref_tag = in lpfc_scsi_cmd_iocb_cmpl()
4394 lpfc_cmd->prot_data; in lpfc_scsi_cmd_iocb_cmpl()
4397 src->app_tag = in lpfc_scsi_cmd_iocb_cmpl()
4398 (uint16_t)lpfc_cmd->prot_data; in lpfc_scsi_cmd_iocb_cmpl()
4401 src->guard_tag = in lpfc_scsi_cmd_iocb_cmpl()
4402 (uint16_t)lpfc_cmd->prot_data; in lpfc_scsi_cmd_iocb_cmpl()
4408 lpfc_cmd->prot_data = 0; in lpfc_scsi_cmd_iocb_cmpl()
4409 lpfc_cmd->prot_data_type = 0; in lpfc_scsi_cmd_iocb_cmpl()
4410 lpfc_cmd->prot_data_segment = NULL; in lpfc_scsi_cmd_iocb_cmpl()
4414 if (unlikely(lpfc_cmd->status)) { in lpfc_scsi_cmd_iocb_cmpl()
4415 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && in lpfc_scsi_cmd_iocb_cmpl()
4416 (lpfc_cmd->result & IOERR_DRVR_MASK)) in lpfc_scsi_cmd_iocb_cmpl()
4417 lpfc_cmd->status = IOSTAT_DRIVER_REJECT; in lpfc_scsi_cmd_iocb_cmpl()
4418 else if (lpfc_cmd->status >= IOSTAT_CNT) in lpfc_scsi_cmd_iocb_cmpl()
4419 lpfc_cmd->status = IOSTAT_DEFAULT; in lpfc_scsi_cmd_iocb_cmpl()
4420 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && in lpfc_scsi_cmd_iocb_cmpl()
4421 !lpfc_cmd->fcp_rsp->rspStatus3 && in lpfc_scsi_cmd_iocb_cmpl()
4422 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && in lpfc_scsi_cmd_iocb_cmpl()
4423 !(vport->cfg_log_verbose & LOG_FCP_UNDER)) in lpfc_scsi_cmd_iocb_cmpl()
4432 cmd->cmnd[0], in lpfc_scsi_cmd_iocb_cmpl()
4433 cmd->device ? cmd->device->id : 0xffff, in lpfc_scsi_cmd_iocb_cmpl()
4434 cmd->device ? cmd->device->lun : 0xffff, in lpfc_scsi_cmd_iocb_cmpl()
4435 lpfc_cmd->status, lpfc_cmd->result, in lpfc_scsi_cmd_iocb_cmpl()
4436 vport->fc_myDID, in lpfc_scsi_cmd_iocb_cmpl()
4437 (pnode) ? pnode->nlp_DID : 0, in lpfc_scsi_cmd_iocb_cmpl()
4438 phba->sli_rev == LPFC_SLI_REV4 ? in lpfc_scsi_cmd_iocb_cmpl()
4439 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, in lpfc_scsi_cmd_iocb_cmpl()
4440 pIocbOut->iocb.ulpContext, in lpfc_scsi_cmd_iocb_cmpl()
4441 lpfc_cmd->cur_iocbq.iocb.ulpIoTag); in lpfc_scsi_cmd_iocb_cmpl()
4443 switch (lpfc_cmd->status) { in lpfc_scsi_cmd_iocb_cmpl()
4447 pIocbOut->iocb.un.fcpi.fcpi_parm); in lpfc_scsi_cmd_iocb_cmpl()
4451 cmd->result = DID_TRANSPORT_DISRUPTED << 16; in lpfc_scsi_cmd_iocb_cmpl()
4455 fast_path_evt->un.fabric_evt.event_type = in lpfc_scsi_cmd_iocb_cmpl()
4457 fast_path_evt->un.fabric_evt.subcategory = in lpfc_scsi_cmd_iocb_cmpl()
4458 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? in lpfc_scsi_cmd_iocb_cmpl()
4461 memcpy(&fast_path_evt->un.fabric_evt.wwpn, in lpfc_scsi_cmd_iocb_cmpl()
4462 &pnode->nlp_portname, in lpfc_scsi_cmd_iocb_cmpl()
4464 memcpy(&fast_path_evt->un.fabric_evt.wwnn, in lpfc_scsi_cmd_iocb_cmpl()
4465 &pnode->nlp_nodename, in lpfc_scsi_cmd_iocb_cmpl()
4468 fast_path_evt->vport = vport; in lpfc_scsi_cmd_iocb_cmpl()
4469 fast_path_evt->work_evt.evt = in lpfc_scsi_cmd_iocb_cmpl()
4471 spin_lock_irqsave(&phba->hbalock, flags); in lpfc_scsi_cmd_iocb_cmpl()
4472 list_add_tail(&fast_path_evt->work_evt.evt_listp, in lpfc_scsi_cmd_iocb_cmpl()
4473 &phba->work_list); in lpfc_scsi_cmd_iocb_cmpl()
4474 spin_unlock_irqrestore(&phba->hbalock, flags); in lpfc_scsi_cmd_iocb_cmpl()
4479 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || in lpfc_scsi_cmd_iocb_cmpl()
4480 lpfc_cmd->result == in lpfc_scsi_cmd_iocb_cmpl()
4482 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || in lpfc_scsi_cmd_iocb_cmpl()
4483 lpfc_cmd->result == in lpfc_scsi_cmd_iocb_cmpl()
4485 cmd->result = DID_NO_CONNECT << 16; in lpfc_scsi_cmd_iocb_cmpl()
4488 if (lpfc_cmd->result == IOERR_INVALID_RPI || in lpfc_scsi_cmd_iocb_cmpl()
4489 lpfc_cmd->result == IOERR_NO_RESOURCES || in lpfc_scsi_cmd_iocb_cmpl()
4490 lpfc_cmd->result == IOERR_ABORT_REQUESTED || in lpfc_scsi_cmd_iocb_cmpl()
4491 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { in lpfc_scsi_cmd_iocb_cmpl()
4492 cmd->result = DID_TRANSPORT_DISRUPTED << 16; in lpfc_scsi_cmd_iocb_cmpl()
4495 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || in lpfc_scsi_cmd_iocb_cmpl()
4496 lpfc_cmd->result == IOERR_TX_DMA_FAILED) && in lpfc_scsi_cmd_iocb_cmpl()
4497 pIocbOut->iocb.unsli3.sli3_bg.bgstat) { in lpfc_scsi_cmd_iocb_cmpl()
4509 "9031 non-zero BGSTAT " in lpfc_scsi_cmd_iocb_cmpl()
4513 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) in lpfc_scsi_cmd_iocb_cmpl()
4514 && (phba->sli_rev == LPFC_SLI_REV4) in lpfc_scsi_cmd_iocb_cmpl()
4521 lpfc_cmd->cur_iocbq.sli4_lxritag, in lpfc_scsi_cmd_iocb_cmpl()
4526 cmd->result = DID_ERROR << 16; in lpfc_scsi_cmd_iocb_cmpl()
4530 if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) in lpfc_scsi_cmd_iocb_cmpl()
4531 cmd->result = DID_TRANSPORT_DISRUPTED << 16 | in lpfc_scsi_cmd_iocb_cmpl()
4534 cmd->result = DID_OK << 16; in lpfc_scsi_cmd_iocb_cmpl()
4536 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { in lpfc_scsi_cmd_iocb_cmpl()
4537 uint32_t *lp = (uint32_t *)cmd->sense_buffer; in lpfc_scsi_cmd_iocb_cmpl()
4542 cmd->device->id, cmd->device->lun, cmd, in lpfc_scsi_cmd_iocb_cmpl()
4543 cmd->result, *lp, *(lp + 3), cmd->retries, in lpfc_scsi_cmd_iocb_cmpl()
4547 if (vport->cfg_max_scsicmpl_time && in lpfc_scsi_cmd_iocb_cmpl()
4548 time_after(jiffies, lpfc_cmd->start_time + in lpfc_scsi_cmd_iocb_cmpl()
4549 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { in lpfc_scsi_cmd_iocb_cmpl()
4550 spin_lock_irqsave(shost->host_lock, flags); in lpfc_scsi_cmd_iocb_cmpl()
4552 if (pnode->cmd_qdepth > in lpfc_scsi_cmd_iocb_cmpl()
4553 atomic_read(&pnode->cmd_pending) && in lpfc_scsi_cmd_iocb_cmpl()
4554 (atomic_read(&pnode->cmd_pending) > in lpfc_scsi_cmd_iocb_cmpl()
4556 ((cmd->cmnd[0] == READ_10) || in lpfc_scsi_cmd_iocb_cmpl()
4557 (cmd->cmnd[0] == WRITE_10))) in lpfc_scsi_cmd_iocb_cmpl()
4558 pnode->cmd_qdepth = in lpfc_scsi_cmd_iocb_cmpl()
4559 atomic_read(&pnode->cmd_pending); in lpfc_scsi_cmd_iocb_cmpl()
4561 pnode->last_change_time = jiffies; in lpfc_scsi_cmd_iocb_cmpl()
4563 spin_unlock_irqrestore(shost->host_lock, flags); in lpfc_scsi_cmd_iocb_cmpl()
4567 lpfc_cmd->pCmd = NULL; in lpfc_scsi_cmd_iocb_cmpl()
4568 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_scsi_cmd_iocb_cmpl()
4571 if (lpfc_cmd->ts_cmd_start) { in lpfc_scsi_cmd_iocb_cmpl()
4572 lpfc_cmd->ts_isr_cmpl = pIocbIn->isr_timestamp; in lpfc_scsi_cmd_iocb_cmpl()
4573 lpfc_cmd->ts_data_io = ktime_get_ns(); in lpfc_scsi_cmd_iocb_cmpl()
4574 phba->ktime_last_cmd = lpfc_cmd->ts_data_io; in lpfc_scsi_cmd_iocb_cmpl()
4586 spin_lock(&lpfc_cmd->buf_lock); in lpfc_scsi_cmd_iocb_cmpl()
4587 lpfc_cmd->cur_iocbq.cmd_flag &= ~LPFC_DRIVER_ABORTED; in lpfc_scsi_cmd_iocb_cmpl()
4588 if (lpfc_cmd->waitq) in lpfc_scsi_cmd_iocb_cmpl()
4589 wake_up(lpfc_cmd->waitq); in lpfc_scsi_cmd_iocb_cmpl()
4590 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_scsi_cmd_iocb_cmpl()
4596 * lpfc_scsi_prep_cmnd_buf_s3 - SLI-3 IOCB init for the IO
4601 * Based on the data-direction of the command, initialize IOCB
4605 * RETURNS 0 - SUCCESS,
4611 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; in lpfc_scsi_prep_cmnd_buf_s3()
4612 struct lpfc_iocbq *piocbq = &lpfc_cmd->cur_iocbq; in lpfc_scsi_prep_cmnd_buf_s3()
4613 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_scsi_prep_cmnd_buf_s3()
4614 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_cmnd_buf_s3()
4615 struct lpfc_nodelist *pnode = lpfc_cmd->ndlp; in lpfc_scsi_prep_cmnd_buf_s3()
4616 int datadir = scsi_cmnd->sc_data_direction; in lpfc_scsi_prep_cmnd_buf_s3()
4619 piocbq->iocb.un.fcpi.fcpi_XRdy = 0; in lpfc_scsi_prep_cmnd_buf_s3()
4622 * There are three possibilities here - use scatter-gather segment, use in lpfc_scsi_prep_cmnd_buf_s3()
4629 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; in lpfc_scsi_prep_cmnd_buf_s3()
4630 iocb_cmd->ulpPU = PARM_READ_CHECK; in lpfc_scsi_prep_cmnd_buf_s3()
4631 if (vport->cfg_first_burst_size && in lpfc_scsi_prep_cmnd_buf_s3()
4632 test_bit(NLP_FIRSTBURST, &pnode->nlp_flag)) { in lpfc_scsi_prep_cmnd_buf_s3()
4637 vport->cfg_first_burst_size); in lpfc_scsi_prep_cmnd_buf_s3()
4638 piocbq->iocb.un.fcpi.fcpi_XRdy = xrdy_len; in lpfc_scsi_prep_cmnd_buf_s3()
4640 fcp_cmnd->fcpCntl3 = WRITE_DATA; in lpfc_scsi_prep_cmnd_buf_s3()
4642 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; in lpfc_scsi_prep_cmnd_buf_s3()
4643 iocb_cmd->ulpPU = PARM_READ_CHECK; in lpfc_scsi_prep_cmnd_buf_s3()
4644 fcp_cmnd->fcpCntl3 = READ_DATA; in lpfc_scsi_prep_cmnd_buf_s3()
4647 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; in lpfc_scsi_prep_cmnd_buf_s3()
4648 iocb_cmd->un.fcpi.fcpi_parm = 0; in lpfc_scsi_prep_cmnd_buf_s3()
4649 iocb_cmd->ulpPU = 0; in lpfc_scsi_prep_cmnd_buf_s3()
4650 fcp_cmnd->fcpCntl3 = 0; in lpfc_scsi_prep_cmnd_buf_s3()
4657 piocbq->iocb.ulpContext = pnode->nlp_rpi; in lpfc_scsi_prep_cmnd_buf_s3()
4658 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) in lpfc_scsi_prep_cmnd_buf_s3()
4659 piocbq->iocb.ulpFCP2Rcvy = 1; in lpfc_scsi_prep_cmnd_buf_s3()
4661 piocbq->iocb.ulpFCP2Rcvy = 0; in lpfc_scsi_prep_cmnd_buf_s3()
4663 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); in lpfc_scsi_prep_cmnd_buf_s3()
4664 piocbq->io_buf = lpfc_cmd; in lpfc_scsi_prep_cmnd_buf_s3()
4665 if (!piocbq->cmd_cmpl) in lpfc_scsi_prep_cmnd_buf_s3()
4666 piocbq->cmd_cmpl = lpfc_scsi_cmd_iocb_cmpl; in lpfc_scsi_prep_cmnd_buf_s3()
4667 piocbq->iocb.ulpTimeout = tmo; in lpfc_scsi_prep_cmnd_buf_s3()
4668 piocbq->vport = vport; in lpfc_scsi_prep_cmnd_buf_s3()
4673 * lpfc_scsi_prep_cmnd_buf_s4 - SLI-4 WQE init for the IO
4678 * Based on the data-direction of the command copy WQE template
4682 * RETURNS 0 - SUCCESS,
4688 struct lpfc_hba *phba = vport->phba; in lpfc_scsi_prep_cmnd_buf_s4()
4689 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_scsi_prep_cmnd_buf_s4()
4690 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_cmnd_buf_s4()
4692 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; in lpfc_scsi_prep_cmnd_buf_s4()
4693 struct lpfc_nodelist *pnode = lpfc_cmd->ndlp; in lpfc_scsi_prep_cmnd_buf_s4()
4694 union lpfc_wqe128 *wqe = &pwqeq->wqe; in lpfc_scsi_prep_cmnd_buf_s4()
4695 u16 idx = lpfc_cmd->hdwq_no; in lpfc_scsi_prep_cmnd_buf_s4()
4696 int datadir = scsi_cmnd->sc_data_direction; in lpfc_scsi_prep_cmnd_buf_s4()
4698 hdwq = &phba->sli4_hba.hdwq[idx]; in lpfc_scsi_prep_cmnd_buf_s4()
4704 * There are three possibilities here - use scatter-gather segment, use in lpfc_scsi_prep_cmnd_buf_s4()
4709 /* From the iwrite template, initialize words 7 - 11 */ in lpfc_scsi_prep_cmnd_buf_s4()
4710 memcpy(&wqe->words[7], in lpfc_scsi_prep_cmnd_buf_s4()
4714 fcp_cmnd->fcpCntl3 = WRITE_DATA; in lpfc_scsi_prep_cmnd_buf_s4()
4716 hdwq->scsi_cstat.output_requests++; in lpfc_scsi_prep_cmnd_buf_s4()
4718 /* From the iread template, initialize words 7 - 11 */ in lpfc_scsi_prep_cmnd_buf_s4()
4719 memcpy(&wqe->words[7], in lpfc_scsi_prep_cmnd_buf_s4()
4724 bf_set(wqe_tmo, &wqe->fcp_iread.wqe_com, tmo); in lpfc_scsi_prep_cmnd_buf_s4()
4726 fcp_cmnd->fcpCntl3 = READ_DATA; in lpfc_scsi_prep_cmnd_buf_s4()
4728 hdwq->scsi_cstat.input_requests++; in lpfc_scsi_prep_cmnd_buf_s4()
4731 if (phba->cmf_active_mode == LPFC_CFG_MANAGED) in lpfc_scsi_prep_cmnd_buf_s4()
4732 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, in lpfc_scsi_prep_cmnd_buf_s4()
4737 * LPFC_FCP_CDB_LEN_32 - normal 16 byte cdb length, in lpfc_scsi_prep_cmnd_buf_s4()
4741 if (scsi_cmnd->cmd_len > LPFC_FCP_CDB_LEN) in lpfc_scsi_prep_cmnd_buf_s4()
4742 fcp_cmnd->fcpCntl3 |= 4 << 2; in lpfc_scsi_prep_cmnd_buf_s4()
4744 /* From the icmnd template, initialize words 4 - 11 */ in lpfc_scsi_prep_cmnd_buf_s4()
4745 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4], in lpfc_scsi_prep_cmnd_buf_s4()
4749 bf_set(wqe_tmo, &wqe->fcp_icmd.wqe_com, tmo); in lpfc_scsi_prep_cmnd_buf_s4()
4751 fcp_cmnd->fcpCntl3 = 0; in lpfc_scsi_prep_cmnd_buf_s4()
4753 hdwq->scsi_cstat.control_requests++; in lpfc_scsi_prep_cmnd_buf_s4()
4762 bf_set(payload_offset_len, &wqe->fcp_icmd, in lpfc_scsi_prep_cmnd_buf_s4()
4766 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, in lpfc_scsi_prep_cmnd_buf_s4()
4767 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]); in lpfc_scsi_prep_cmnd_buf_s4()
4768 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); in lpfc_scsi_prep_cmnd_buf_s4()
4771 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) in lpfc_scsi_prep_cmnd_buf_s4()
4772 bf_set(wqe_erp, &wqe->generic.wqe_com, 1); in lpfc_scsi_prep_cmnd_buf_s4()
4774 bf_set(wqe_class, &wqe->generic.wqe_com, in lpfc_scsi_prep_cmnd_buf_s4()
4775 (pnode->nlp_fcp_info & 0x0f)); in lpfc_scsi_prep_cmnd_buf_s4()
4778 wqe->generic.wqe_com.abort_tag = pwqeq->iotag; in lpfc_scsi_prep_cmnd_buf_s4()
4781 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); in lpfc_scsi_prep_cmnd_buf_s4()
4783 pwqeq->vport = vport; in lpfc_scsi_prep_cmnd_buf_s4()
4784 pwqeq->io_buf = lpfc_cmd; in lpfc_scsi_prep_cmnd_buf_s4()
4785 pwqeq->hba_wqidx = lpfc_cmd->hdwq_no; in lpfc_scsi_prep_cmnd_buf_s4()
4786 pwqeq->cmd_cmpl = lpfc_fcp_io_cmd_wqe_cmpl; in lpfc_scsi_prep_cmnd_buf_s4()
4792 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4793 * @vport: The virtual port for which this call is being executed.
4804 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; in lpfc_scsi_prep_cmnd()
4805 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_cmnd()
4811 lpfc_cmd->fcp_rsp->rspSnsLen = 0; in lpfc_scsi_prep_cmnd()
4813 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; in lpfc_scsi_prep_cmnd()
4815 int_to_scsilun(lpfc_cmd->pCmd->device->lun, in lpfc_scsi_prep_cmnd()
4816 &lpfc_cmd->fcp_cmnd->fcp_lun); in lpfc_scsi_prep_cmnd()
4818 ptr = &((struct fcp_cmnd32 *)fcp_cmnd)->fcpCdb[0]; in lpfc_scsi_prep_cmnd()
4819 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); in lpfc_scsi_prep_cmnd()
4820 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { in lpfc_scsi_prep_cmnd()
4821 ptr += scsi_cmnd->cmd_len; in lpfc_scsi_prep_cmnd()
4822 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); in lpfc_scsi_prep_cmnd()
4825 fcp_cmnd->fcpCntl1 = SIMPLE_Q; in lpfc_scsi_prep_cmnd()
4827 lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, lpfc_cmd->timeout); in lpfc_scsi_prep_cmnd()
4833 * lpfc_scsi_prep_task_mgmt_cmd_s3 - Convert SLI3 scsi TM cmd to FCP info unit
4834 * @vport: The virtual port for which this call is being executed.
4840 * for device with SLI-3 interface spec.
4843 * 0 - Error
4844 * 1 - Success
4854 struct lpfc_rport_data *rdata = lpfc_cmd->rdata; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4855 struct lpfc_nodelist *ndlp = rdata->pnode; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4857 if (!ndlp || ndlp->nlp_state != NLP_STE_MAPPED_NODE) in lpfc_scsi_prep_task_mgmt_cmd_s3()
4860 piocbq = &(lpfc_cmd->cur_iocbq); in lpfc_scsi_prep_task_mgmt_cmd_s3()
4861 piocbq->vport = vport; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4863 piocb = &piocbq->iocb; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4865 fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4868 int_to_scsilun(lun, &fcp_cmnd->fcp_lun); in lpfc_scsi_prep_task_mgmt_cmd_s3()
4869 fcp_cmnd->fcpCntl2 = task_mgmt_cmd; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4870 if (!(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) in lpfc_scsi_prep_task_mgmt_cmd_s3()
4871 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); in lpfc_scsi_prep_task_mgmt_cmd_s3()
4872 piocb->ulpCommand = CMD_FCP_ICMND64_CR; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4873 piocb->ulpContext = ndlp->nlp_rpi; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4874 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4875 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); in lpfc_scsi_prep_task_mgmt_cmd_s3()
4876 piocb->ulpPU = 0; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4877 piocb->un.fcpi.fcpi_parm = 0; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4880 if (lpfc_cmd->timeout > 0xff) { in lpfc_scsi_prep_task_mgmt_cmd_s3()
4885 piocb->ulpTimeout = 0; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4887 piocb->ulpTimeout = lpfc_cmd->timeout; in lpfc_scsi_prep_task_mgmt_cmd_s3()
4893 * lpfc_scsi_prep_task_mgmt_cmd_s4 - Convert SLI4 scsi TM cmd to FCP info unit
4894 * @vport: The virtual port for which this call is being executed.
4900 * for device with SLI-4 interface spec.
4903 * 0 - Error
4904 * 1 - Success
4911 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4912 union lpfc_wqe128 *wqe = &pwqeq->wqe; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4914 struct lpfc_rport_data *rdata = lpfc_cmd->rdata; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4915 struct lpfc_nodelist *ndlp = rdata->pnode; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4917 if (!ndlp || ndlp->nlp_state != NLP_STE_MAPPED_NODE) in lpfc_scsi_prep_task_mgmt_cmd_s4()
4920 pwqeq->vport = vport; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4924 /* From the icmnd template, initialize words 4 - 11 */ in lpfc_scsi_prep_task_mgmt_cmd_s4()
4925 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4], in lpfc_scsi_prep_task_mgmt_cmd_s4()
4928 fcp_cmnd = lpfc_cmd->fcp_cmnd; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4931 int_to_scsilun(lun, &fcp_cmnd->fcp_lun); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4932 fcp_cmnd->fcpCntl3 = 0; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4933 fcp_cmnd->fcpCntl2 = task_mgmt_cmd; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4935 bf_set(payload_offset_len, &wqe->fcp_icmd, in lpfc_scsi_prep_task_mgmt_cmd_s4()
4937 bf_set(cmd_buff_len, &wqe->fcp_icmd, 0); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4938 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, /* ulpContext */ in lpfc_scsi_prep_task_mgmt_cmd_s4()
4939 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4940 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, in lpfc_scsi_prep_task_mgmt_cmd_s4()
4941 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0)); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4942 bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, in lpfc_scsi_prep_task_mgmt_cmd_s4()
4943 (ndlp->nlp_fcp_info & 0x0f)); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4946 if (lpfc_cmd->timeout > 0xff) { in lpfc_scsi_prep_task_mgmt_cmd_s4()
4951 bf_set(wqe_tmo, &wqe->fcp_icmd.wqe_com, 0); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4953 bf_set(wqe_tmo, &wqe->fcp_icmd.wqe_com, lpfc_cmd->timeout); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4956 lpfc_prep_embed_io(vport->phba, lpfc_cmd); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4957 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4958 wqe->generic.wqe_com.abort_tag = pwqeq->iotag; in lpfc_scsi_prep_task_mgmt_cmd_s4()
4959 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4961 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); in lpfc_scsi_prep_task_mgmt_cmd_s4()
4967 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4969 * @dev_grp: The HBA PCI-Device group number.
4973 * Returns: 0 - success, -ENODEV - failure.
4979 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; in lpfc_scsi_api_table_setup()
4983 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; in lpfc_scsi_api_table_setup()
4984 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3; in lpfc_scsi_api_table_setup()
4985 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; in lpfc_scsi_api_table_setup()
4986 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; in lpfc_scsi_api_table_setup()
4987 phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s3; in lpfc_scsi_api_table_setup()
4988 phba->lpfc_scsi_prep_task_mgmt_cmd = in lpfc_scsi_api_table_setup()
4992 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; in lpfc_scsi_api_table_setup()
4993 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4; in lpfc_scsi_api_table_setup()
4994 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; in lpfc_scsi_api_table_setup()
4995 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; in lpfc_scsi_api_table_setup()
4996 phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s4; in lpfc_scsi_api_table_setup()
4997 phba->lpfc_scsi_prep_task_mgmt_cmd = in lpfc_scsi_api_table_setup()
5002 "1418 Invalid HBA PCI-device group: 0x%x\n", in lpfc_scsi_api_table_setup()
5004 return -ENODEV; in lpfc_scsi_api_table_setup()
5006 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; in lpfc_scsi_api_table_setup()
5011 * lpfc_tskmgmt_def_cmpl - IOCB completion routine for task management command
5024 struct lpfc_io_buf *lpfc_cmd = cmdiocbq->io_buf; in lpfc_tskmgmt_def_cmpl()
5031 * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check
5041 * -EBADSLT, detected invalid device
5047 const struct pci_dev *pdev = phba->pcidev; in lpfc_check_pci_resettable()
5052 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) { in lpfc_check_pci_resettable()
5054 if (ptr->vendor != PCI_VENDOR_ID_EMULEX) { in lpfc_check_pci_resettable()
5056 "8346 Non-Emulex vendor found: " in lpfc_check_pci_resettable()
5057 "0x%04x\n", ptr->vendor); in lpfc_check_pci_resettable()
5058 return -EBADSLT; in lpfc_check_pci_resettable()
5062 if (phba->sli_rev != LPFC_SLI_REV4 || in lpfc_check_pci_resettable()
5063 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) { in lpfc_check_pci_resettable()
5066 "0x%04x\n", ptr->device); in lpfc_check_pci_resettable()
5067 return -EBADSLT; in lpfc_check_pci_resettable()
5073 if (ptr->devfn == 0) { in lpfc_check_pci_resettable()
5078 return -EBADSLT; in lpfc_check_pci_resettable()
5087 * lpfc_info - Info entry point of scsi_host_template data structure
5093 * Pointer to char - Success.
5098 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; in lpfc_info()
5099 struct lpfc_hba *phba = vport->phba; in lpfc_info()
5105 if (phba && phba->pcidev){ in lpfc_info()
5107 scnprintf(tmp, sizeof(tmp), phba->ModelDesc); in lpfc_info()
5115 phba->pcidev->bus->number, phba->pcidev->devfn, in lpfc_info()
5116 phba->pcidev->irq); in lpfc_info()
5122 if (phba->Port[0]) { in lpfc_info()
5123 scnprintf(tmp, sizeof(tmp), " port %s", phba->Port); in lpfc_info()
5157 * lpfc_poll_rearm_timer - Routine to modify fcp_poll timer of hba
5166 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); in lpfc_poll_rearm_timer()
5168 if (!list_empty(&phba->sli.sli3_ring[LPFC_FCP_RING].txcmplq)) in lpfc_poll_rearm_timer()
5169 mod_timer(&phba->fcp_poll_timer, in lpfc_poll_rearm_timer()
5174 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
5185 * lpfc_poll_timeout - Restart polling timer
5195 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { in lpfc_poll_timeout()
5197 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); in lpfc_poll_timeout()
5199 if (phba->cfg_poll & DISABLE_FCP_RING_INT) in lpfc_poll_timeout()
5205 * lpfc_is_command_vm_io - get the UUID from blk cgroup
5211 struct bio *bio = scsi_cmd_to_rq(cmd)->bio; in lpfc_is_command_vm_io()
5219 * lpfc_queuecommand - scsi_host_template queuecommand entry point
5228 * 0 - Success
5229 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
5234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; in lpfc_queuecommand()
5235 struct lpfc_hba *phba = vport->phba; in lpfc_queuecommand()
5240 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in lpfc_queuecommand()
5246 rdata = lpfc_rport_data_from_scsi_device(cmnd->device); in lpfc_queuecommand()
5254 cmnd->result = err; in lpfc_queuecommand()
5257 ndlp = rdata->pnode; in lpfc_queuecommand()
5260 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { in lpfc_queuecommand()
5265 " BlockGuard - Rejecting command\n", in lpfc_queuecommand()
5266 cmnd->cmnd[0], scsi_get_prot_op(cmnd), in lpfc_queuecommand()
5279 if (phba->cmf_active_mode != LPFC_CFG_OFF && in lpfc_queuecommand()
5280 cmnd->sc_data_direction == DMA_FROM_DEVICE && in lpfc_queuecommand()
5289 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { in lpfc_queuecommand()
5297 ndlp->nlp_sid, ndlp->cmd_qdepth, in lpfc_queuecommand()
5298 atomic_read(&ndlp->cmd_pending), in lpfc_queuecommand()
5299 ndlp->nlp_nodename.u.wwn[0], in lpfc_queuecommand()
5300 ndlp->nlp_nodename.u.wwn[1], in lpfc_queuecommand()
5301 ndlp->nlp_nodename.u.wwn[2], in lpfc_queuecommand()
5302 ndlp->nlp_nodename.u.wwn[3], in lpfc_queuecommand()
5303 ndlp->nlp_nodename.u.wwn[4], in lpfc_queuecommand()
5304 ndlp->nlp_nodename.u.wwn[5], in lpfc_queuecommand()
5305 ndlp->nlp_nodename.u.wwn[6], in lpfc_queuecommand()
5306 ndlp->nlp_nodename.u.wwn[7], in lpfc_queuecommand()
5307 ndlp->nlp_portname.u.wwn[0], in lpfc_queuecommand()
5308 ndlp->nlp_portname.u.wwn[1], in lpfc_queuecommand()
5309 ndlp->nlp_portname.u.wwn[2], in lpfc_queuecommand()
5310 ndlp->nlp_portname.u.wwn[3], in lpfc_queuecommand()
5311 ndlp->nlp_portname.u.wwn[4], in lpfc_queuecommand()
5312 ndlp->nlp_portname.u.wwn[5], in lpfc_queuecommand()
5313 ndlp->nlp_portname.u.wwn[6], in lpfc_queuecommand()
5314 ndlp->nlp_portname.u.wwn[7]); in lpfc_queuecommand()
5328 lpfc_cmd->rx_cmd_start = start; in lpfc_queuecommand()
5330 cur_iocbq = &lpfc_cmd->cur_iocbq; in lpfc_queuecommand()
5335 lpfc_cmd->pCmd = cmnd; in lpfc_queuecommand()
5336 lpfc_cmd->rdata = rdata; in lpfc_queuecommand()
5337 lpfc_cmd->ndlp = ndlp; in lpfc_queuecommand()
5338 cur_iocbq->cmd_cmpl = NULL; in lpfc_queuecommand()
5339 cmnd->host_scribble = (unsigned char *)lpfc_cmd; in lpfc_queuecommand()
5346 if (vport->phba->cfg_enable_bg) { in lpfc_queuecommand()
5352 cmnd->cmnd[0], in lpfc_queuecommand()
5364 cmnd->result = DID_ERROR << 16; in lpfc_queuecommand()
5372 (ndlp->vmid_support || in lpfc_queuecommand()
5373 phba->pport->vmid_priority_tagging == in lpfc_queuecommand()
5375 /* is the I/O generated by a VM, get the associated virtual */ in lpfc_queuecommand()
5381 cmnd->sc_data_direction, in lpfc_queuecommand()
5383 &cur_iocbq->vmid_tag); in lpfc_queuecommand()
5385 cur_iocbq->cmd_flag |= LPFC_IO_VMID; in lpfc_queuecommand()
5390 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) in lpfc_queuecommand()
5391 this_cpu_inc(phba->sli4_hba.c_stat->xmt_io); in lpfc_queuecommand()
5398 lpfc_cmd->ts_cmd_start = start; in lpfc_queuecommand()
5399 lpfc_cmd->ts_last_cmd = phba->ktime_last_cmd; in lpfc_queuecommand()
5400 lpfc_cmd->ts_cmd_wqput = ktime_get_ns(); in lpfc_queuecommand()
5402 lpfc_cmd->ts_cmd_start = 0; in lpfc_queuecommand()
5411 err, cmnd->cmnd[0], in lpfc_queuecommand()
5412 cmnd->device ? cmnd->device->id : 0xffff, in lpfc_queuecommand()
5413 cmnd->device ? cmnd->device->lun : (u64)-1, in lpfc_queuecommand()
5414 vport->fc_myDID, ndlp->nlp_DID, in lpfc_queuecommand()
5415 phba->sli_rev == LPFC_SLI_REV4 ? in lpfc_queuecommand()
5416 cur_iocbq->sli4_xritag : 0xffff, in lpfc_queuecommand()
5417 phba->sli_rev == LPFC_SLI_REV4 ? in lpfc_queuecommand()
5418 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi] : in lpfc_queuecommand()
5419 cur_iocbq->iocb.ulpContext, in lpfc_queuecommand()
5420 cur_iocbq->iotag, in lpfc_queuecommand()
5421 phba->sli_rev == LPFC_SLI_REV4 ? in lpfc_queuecommand()
5423 &cur_iocbq->wqe.generic.wqe_com) : in lpfc_queuecommand()
5424 cur_iocbq->iocb.ulpTimeout, in lpfc_queuecommand()
5425 (uint32_t)(scsi_cmd_to_rq(cmnd)->timeout / 1000)); in lpfc_queuecommand()
5430 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { in lpfc_queuecommand()
5432 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); in lpfc_queuecommand()
5434 if (phba->cfg_poll & DISABLE_FCP_RING_INT) in lpfc_queuecommand()
5438 if (phba->cfg_xri_rebalancing) in lpfc_queuecommand()
5439 lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_cmd->hdwq_no); in lpfc_queuecommand()
5444 idx = lpfc_cmd->hdwq_no; in lpfc_queuecommand()
5446 if (phba->sli4_hba.hdwq) { in lpfc_queuecommand()
5447 switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { in lpfc_queuecommand()
5449 phba->sli4_hba.hdwq[idx].scsi_cstat.output_requests--; in lpfc_queuecommand()
5452 phba->sli4_hba.hdwq[idx].scsi_cstat.input_requests--; in lpfc_queuecommand()
5455 phba->sli4_hba.hdwq[idx].scsi_cstat.control_requests--; in lpfc_queuecommand()
5482 * lpfc_vmid_vport_cleanup - cleans up the resources associated with a vport
5483 * @vport: The virtual port for which this call is being executed.
5490 if (vport->port_type == LPFC_PHYSICAL_PORT) in lpfc_vmid_vport_cleanup()
5491 timer_delete_sync(&vport->phba->inactive_vmid_poll); in lpfc_vmid_vport_cleanup()
5493 kfree(vport->qfpa_res); in lpfc_vmid_vport_cleanup()
5494 kfree(vport->vmid_priority.vmid_range); in lpfc_vmid_vport_cleanup()
5495 kfree(vport->vmid); in lpfc_vmid_vport_cleanup()
5497 if (!hash_empty(vport->hash_table)) in lpfc_vmid_vport_cleanup()
5498 hash_for_each(vport->hash_table, bucket, cur, hnode) in lpfc_vmid_vport_cleanup()
5499 hash_del(&cur->hnode); in lpfc_vmid_vport_cleanup()
5501 vport->qfpa_res = NULL; in lpfc_vmid_vport_cleanup()
5502 vport->vmid_priority.vmid_range = NULL; in lpfc_vmid_vport_cleanup()
5503 vport->vmid = NULL; in lpfc_vmid_vport_cleanup()
5504 vport->cur_vmid_cnt = 0; in lpfc_vmid_vport_cleanup()
5508 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
5514 * 0x2003 - Error
5515 * 0x2002 - Success
5520 struct Scsi_Host *shost = cmnd->device->host; in lpfc_abort_handler()
5521 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in lpfc_abort_handler()
5522 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; in lpfc_abort_handler()
5523 struct lpfc_hba *phba = vport->phba; in lpfc_abort_handler()
5537 lpfc_cmd = (struct lpfc_io_buf *)cmnd->host_scribble; in lpfc_abort_handler()
5542 spin_lock_irqsave(&lpfc_cmd->buf_lock, flags); in lpfc_abort_handler()
5544 spin_lock(&phba->hbalock); in lpfc_abort_handler()
5546 if (test_bit(HBA_IOQ_FLUSH, &phba->hba_flag)) { in lpfc_abort_handler()
5554 if (!lpfc_cmd->pCmd) { in lpfc_abort_handler()
5558 SUCCESS, cmnd->device->id, cmnd->device->lun); in lpfc_abort_handler()
5562 iocb = &lpfc_cmd->cur_iocbq; in lpfc_abort_handler()
5563 if (phba->sli_rev == LPFC_SLI_REV4) { in lpfc_abort_handler()
5565 if (!phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq || in lpfc_abort_handler()
5566 !phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring) { in lpfc_abort_handler()
5571 cmnd->device->id, in lpfc_abort_handler()
5572 (u64)cmnd->device->lun, in lpfc_abort_handler()
5573 test_bit(HBA_SETUP, &phba->hba_flag)); in lpfc_abort_handler()
5577 pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring; in lpfc_abort_handler()
5578 spin_lock(&pring_s4->ring_lock); in lpfc_abort_handler()
5581 if (!(iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ)) { in lpfc_abort_handler()
5594 if (lpfc_cmd->pCmd != cmnd) { in lpfc_abort_handler()
5601 WARN_ON(iocb->io_buf != lpfc_cmd); in lpfc_abort_handler()
5604 if (iocb->cmd_flag & LPFC_DRIVER_ABORTED) { in lpfc_abort_handler()
5607 if (phba->sli_rev == LPFC_SLI_REV4) in lpfc_abort_handler()
5608 spin_unlock(&pring_s4->ring_lock); in lpfc_abort_handler()
5609 spin_unlock(&phba->hbalock); in lpfc_abort_handler()
5610 spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags); in lpfc_abort_handler()
5614 lpfc_cmd->waitq = &waitq; in lpfc_abort_handler()
5615 if (phba->sli_rev == LPFC_SLI_REV4) { in lpfc_abort_handler()
5616 spin_unlock(&pring_s4->ring_lock); in lpfc_abort_handler()
5620 pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; in lpfc_abort_handler()
5630 lpfc_cmd->waitq = NULL; in lpfc_abort_handler()
5636 spin_unlock(&phba->hbalock); in lpfc_abort_handler()
5637 spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags); in lpfc_abort_handler()
5639 if (phba->cfg_poll & DISABLE_FCP_RING_INT) in lpfc_abort_handler()
5641 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); in lpfc_abort_handler()
5648 wait_event_timeout(waitq, (lpfc_cmd->pCmd != cmnd), in lpfc_abort_handler()
5649 secs_to_jiffies(2*vport->cfg_devloss_tmo)); in lpfc_abort_handler()
5651 spin_lock(&lpfc_cmd->buf_lock); in lpfc_abort_handler()
5653 if (lpfc_cmd->pCmd == cmnd) { in lpfc_abort_handler()
5659 iocb->sli4_xritag, ret, in lpfc_abort_handler()
5660 cmnd->device->id, cmnd->device->lun); in lpfc_abort_handler()
5663 lpfc_cmd->waitq = NULL; in lpfc_abort_handler()
5665 spin_unlock(&lpfc_cmd->buf_lock); in lpfc_abort_handler()
5669 if (phba->sli_rev == LPFC_SLI_REV4) in lpfc_abort_handler()
5670 spin_unlock(&pring_s4->ring_lock); in lpfc_abort_handler()
5672 spin_unlock(&phba->hbalock); in lpfc_abort_handler()
5673 spin_unlock_irqrestore(&lpfc_cmd->buf_lock, flags); in lpfc_abort_handler()
5677 "LUN %llu\n", ret, cmnd->device->id, in lpfc_abort_handler()
5678 cmnd->device->lun); in lpfc_abort_handler()
5707 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
5708 * @vport: The virtual port for which this call is being executed.
5714 * 0x2003 - Error
5715 * 0x2002 - Success
5720 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; in lpfc_check_fcp_rsp()
5731 rsp_info = fcprsp->rspStatus2; in lpfc_check_fcp_rsp()
5732 rsp_len = be32_to_cpu(fcprsp->rspRspLen); in lpfc_check_fcp_rsp()
5733 rsp_info_code = fcprsp->rspInfo3; in lpfc_check_fcp_rsp()
5747 if ((fcprsp->rspStatus2 & RSP_LEN_VALID) && in lpfc_check_fcp_rsp()
5778 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
5779 * @vport: The virtual port for which this call is being executed.
5789 * 0x2003 - Error
5790 * 0x2002 - Success.
5797 struct lpfc_hba *phba = vport->phba; in lpfc_send_taskmgmt()
5806 rdata = rport->dd_data; in lpfc_send_taskmgmt()
5807 if (!rdata || !rdata->pnode) in lpfc_send_taskmgmt()
5809 pnode = rdata->pnode; in lpfc_send_taskmgmt()
5811 lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode, NULL); in lpfc_send_taskmgmt()
5814 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; in lpfc_send_taskmgmt()
5815 lpfc_cmd->rdata = rdata; in lpfc_send_taskmgmt()
5816 lpfc_cmd->pCmd = NULL; in lpfc_send_taskmgmt()
5817 lpfc_cmd->ndlp = pnode; in lpfc_send_taskmgmt()
5819 status = phba->lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, in lpfc_send_taskmgmt()
5826 iocbq = &lpfc_cmd->cur_iocbq; in lpfc_send_taskmgmt()
5832 iocbq->cmd_cmpl = lpfc_tskmgmt_def_cmpl; in lpfc_send_taskmgmt()
5833 iocbq->vport = vport; in lpfc_send_taskmgmt()
5839 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, in lpfc_send_taskmgmt()
5840 iocbq->cmd_flag); in lpfc_send_taskmgmt()
5843 iocbq, iocbqrsp, lpfc_cmd->timeout); in lpfc_send_taskmgmt()
5855 iocbq->cmd_flag); in lpfc_send_taskmgmt()
5883 * lpfc_chk_tgt_mapped -
5884 * @vport: The virtual port to check on
5888 * command exists (is present and logged in) or we declare it non-existent.
5891 * 0x2003 - Error
5892 * 0x2002 - Success
5901 rdata = rport->dd_data; in lpfc_chk_tgt_mapped()
5907 pnode = rdata->pnode; in lpfc_chk_tgt_mapped()
5913 later = secs_to_jiffies(2 * vport->cfg_devloss_tmo) + jiffies; in lpfc_chk_tgt_mapped()
5917 if (pnode->nlp_state == NLP_STE_MAPPED_NODE) in lpfc_chk_tgt_mapped()
5920 rdata = rport->dd_data; in lpfc_chk_tgt_mapped()
5923 pnode = rdata->pnode; in lpfc_chk_tgt_mapped()
5925 if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) in lpfc_chk_tgt_mapped()
5931 * lpfc_reset_flush_io_context -
5932 * @vport: The virtual port (scsi_host) for the flush context
5933 * @tgt_id: If aborting by Target contect - specifies the target id
5934 * @lun_id: If aborting by Lun context - specifies the lun id
5943 * 0x2003 - Error
5944 * 0x2002 - Success
5950 struct lpfc_hba *phba = vport->phba; in lpfc_reset_flush_io_context()
5957 &phba->sli.sli3_ring[LPFC_FCP_RING], in lpfc_reset_flush_io_context()
5959 later = secs_to_jiffies(2 * vport->cfg_devloss_tmo) + jiffies; in lpfc_reset_flush_io_context()
5977 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5984 * 0x2003 - Error
5985 * 0x2002 - Success
5990 struct Scsi_Host *shost = cmnd->device->host; in lpfc_device_reset_handler()
5991 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in lpfc_device_reset_handler()
5992 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; in lpfc_device_reset_handler()
5995 unsigned tgt_id = cmnd->device->id; in lpfc_device_reset_handler()
5996 uint64_t lun_id = cmnd->device->lun; in lpfc_device_reset_handler()
6004 rdata = rport->dd_data; in lpfc_device_reset_handler()
6005 if (!rdata || !rdata->pnode) { in lpfc_device_reset_handler()
6011 pnode = rdata->pnode; in lpfc_device_reset_handler()
6026 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); in lpfc_device_reset_handler()
6027 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); in lpfc_device_reset_handler()
6055 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
6062 * 0x2003 - Error
6063 * 0x2002 - Success
6068 struct Scsi_Host *shost = cmnd->device->host; in lpfc_target_reset_handler()
6069 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in lpfc_target_reset_handler()
6070 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; in lpfc_target_reset_handler()
6073 unsigned tgt_id = cmnd->device->id; in lpfc_target_reset_handler()
6074 uint64_t lun_id = cmnd->device->lun; in lpfc_target_reset_handler()
6078 u32 dev_loss_tmo = vport->cfg_devloss_tmo; in lpfc_target_reset_handler()
6085 rdata = rport->dd_data; in lpfc_target_reset_handler()
6086 if (!rdata || !rdata->pnode) { in lpfc_target_reset_handler()
6092 pnode = rdata->pnode; in lpfc_target_reset_handler()
6102 clear_bit(NLP_NPR_ADISC, &pnode->nlp_flag); in lpfc_target_reset_handler()
6103 spin_lock_irqsave(&pnode->lock, flags); in lpfc_target_reset_handler()
6104 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; in lpfc_target_reset_handler()
6105 spin_unlock_irqrestore(&pnode->lock, flags); in lpfc_target_reset_handler()
6115 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); in lpfc_target_reset_handler()
6116 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); in lpfc_target_reset_handler()
6127 spin_lock_irqsave(&pnode->lock, flags); in lpfc_target_reset_handler()
6128 if (!test_bit(NLP_WAIT_FOR_LOGO, &pnode->save_flags) && in lpfc_target_reset_handler()
6129 !pnode->logo_waitq) { in lpfc_target_reset_handler()
6130 pnode->logo_waitq = &waitq; in lpfc_target_reset_handler()
6131 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; in lpfc_target_reset_handler()
6132 spin_unlock_irqrestore(&pnode->lock, flags); in lpfc_target_reset_handler()
6133 set_bit(NLP_ISSUE_LOGO, &pnode->nlp_flag); in lpfc_target_reset_handler()
6134 set_bit(NLP_WAIT_FOR_LOGO, &pnode->save_flags); in lpfc_target_reset_handler()
6138 &pnode->save_flags), in lpfc_target_reset_handler()
6142 &pnode->save_flags)) in lpfc_target_reset_handler()
6148 spin_lock_irqsave(&pnode->lock, flags); in lpfc_target_reset_handler()
6149 pnode->logo_waitq = NULL; in lpfc_target_reset_handler()
6150 spin_unlock_irqrestore(&pnode->lock, flags); in lpfc_target_reset_handler()
6154 spin_unlock_irqrestore(&pnode->lock, flags); in lpfc_target_reset_handler()
6176 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
6183 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
6188 * 0x2003 - Error
6189 * 0x2002 - Success
6194 struct Scsi_Host *shost = cmnd->device->host; in lpfc_host_reset_handler()
6195 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; in lpfc_host_reset_handler()
6196 struct lpfc_hba *phba = vport->phba; in lpfc_host_reset_handler()
6209 if (phba->sli_rev < LPFC_SLI_REV4) { in lpfc_host_reset_handler()
6230 * lpfc_sdev_init - scsi_host_template sdev_init entry point
6239 * non-0 - Error
6240 * 0 - Success
6245 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; in lpfc_sdev_init()
6246 struct lpfc_hba *phba = vport->phba; in lpfc_sdev_init()
6257 return -ENXIO; in lpfc_sdev_init()
6259 if (phba->cfg_fof) { in lpfc_sdev_init()
6266 u64_to_wwn(rport->port_name, target_wwpn.u.wwn); in lpfc_sdev_init()
6267 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_sdev_init()
6269 &phba->luns, in lpfc_sdev_init()
6270 &vport->fc_portname, in lpfc_sdev_init()
6272 sdev->lun); in lpfc_sdev_init()
6274 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_sdev_init()
6276 &vport->fc_portname, in lpfc_sdev_init()
6278 sdev->lun, in lpfc_sdev_init()
6279 phba->cfg_XLanePriority, in lpfc_sdev_init()
6282 return -ENOMEM; in lpfc_sdev_init()
6283 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_sdev_init()
6284 list_add_tail(&device_data->listentry, &phba->luns); in lpfc_sdev_init()
6286 device_data->rport_data = rport->dd_data; in lpfc_sdev_init()
6287 device_data->available = true; in lpfc_sdev_init()
6288 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_sdev_init()
6289 sdev->hostdata = device_data; in lpfc_sdev_init()
6291 sdev->hostdata = rport->dd_data; in lpfc_sdev_init()
6293 sdev_cnt = atomic_inc_return(&phba->sdev_cnt); in lpfc_sdev_init()
6295 /* For SLI4, all IO buffers are pre-allocated */ in lpfc_sdev_init()
6296 if (phba->sli_rev == LPFC_SLI_REV4) in lpfc_sdev_init()
6308 total = phba->total_scsi_bufs; in lpfc_sdev_init()
6309 num_to_alloc = vport->cfg_lun_queue_depth + 2; in lpfc_sdev_init()
6312 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) in lpfc_sdev_init()
6316 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { in lpfc_sdev_init()
6323 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { in lpfc_sdev_init()
6328 num_to_alloc, phba->cfg_hba_queue_depth, in lpfc_sdev_init()
6329 (phba->cfg_hba_queue_depth - total)); in lpfc_sdev_init()
6330 num_to_alloc = phba->cfg_hba_queue_depth - total; in lpfc_sdev_init()
6341 phba->total_scsi_bufs += num_allocated; in lpfc_sdev_init()
6346 * lpfc_sdev_configure - scsi_host_template sdev_configure entry point
6351 * - Tag command queuing support for @sdev if supported.
6352 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
6355 * 0 - Success
6360 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; in lpfc_sdev_configure()
6361 struct lpfc_hba *phba = vport->phba; in lpfc_sdev_configure()
6363 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); in lpfc_sdev_configure()
6365 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { in lpfc_sdev_configure()
6367 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); in lpfc_sdev_configure()
6368 if (phba->cfg_poll & DISABLE_FCP_RING_INT) in lpfc_sdev_configure()
6376 * lpfc_sdev_destroy - sdev_destroy entry point of SHT data structure
6384 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; in lpfc_sdev_destroy()
6385 struct lpfc_hba *phba = vport->phba; in lpfc_sdev_destroy()
6387 struct lpfc_device_data *device_data = sdev->hostdata; in lpfc_sdev_destroy()
6389 atomic_dec(&phba->sdev_cnt); in lpfc_sdev_destroy()
6390 if ((phba->cfg_fof) && (device_data)) { in lpfc_sdev_destroy()
6391 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_sdev_destroy()
6392 device_data->available = false; in lpfc_sdev_destroy()
6393 if (!device_data->oas_enabled) in lpfc_sdev_destroy()
6395 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_sdev_destroy()
6397 sdev->hostdata = NULL; in lpfc_sdev_destroy()
6402 * lpfc_create_device_data - creates and initializes device data structure for OAS
6417 * NULL - Error
6418 * Pointer to lpfc_device_data - Success
6430 !(phba->cfg_fof)) in lpfc_create_device_data()
6439 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); in lpfc_create_device_data()
6442 INIT_LIST_HEAD(&lun_info->listentry); in lpfc_create_device_data()
6443 lun_info->rport_data = NULL; in lpfc_create_device_data()
6444 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, in lpfc_create_device_data()
6446 memcpy(&lun_info->device_id.target_wwpn, target_wwpn, in lpfc_create_device_data()
6448 lun_info->device_id.lun = lun; in lpfc_create_device_data()
6449 lun_info->oas_enabled = false; in lpfc_create_device_data()
6450 lun_info->priority = pri; in lpfc_create_device_data()
6451 lun_info->available = false; in lpfc_create_device_data()
6456 * lpfc_delete_device_data - frees a device data structure for OAS
6469 !(phba->cfg_fof)) in lpfc_delete_device_data()
6472 if (!list_empty(&lun_info->listentry)) in lpfc_delete_device_data()
6473 list_del(&lun_info->listentry); in lpfc_delete_device_data()
6474 mempool_free(lun_info, phba->device_data_mem_pool); in lpfc_delete_device_data()
6479 * __lpfc_get_device_data - returns the device data for the specified lun
6491 * NULL - Error
6492 * Pointer to lpfc_device_data - Success
6503 !phba->cfg_fof) in __lpfc_get_device_data()
6509 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, in __lpfc_get_device_data()
6511 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, in __lpfc_get_device_data()
6513 (lun_info->device_id.lun == lun)) in __lpfc_get_device_data()
6521 * lpfc_find_next_oas_lun - searches for the next oas lun
6544 * non-0 - Error
6545 * 0 - Success
6567 !phba->cfg_fof) in lpfc_find_next_oas_lun()
6576 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_find_next_oas_lun()
6577 list_for_each_entry(lun_info, &phba->luns, listentry) { in lpfc_find_next_oas_lun()
6578 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || in lpfc_find_next_oas_lun()
6579 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, in lpfc_find_next_oas_lun()
6581 ((wwn_to_u64(target_wwpn->u.wwn) == 0) || in lpfc_find_next_oas_lun()
6582 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, in lpfc_find_next_oas_lun()
6584 (lun_info->oas_enabled)) { in lpfc_find_next_oas_lun()
6585 device_id = &lun_info->device_id; in lpfc_find_next_oas_lun()
6588 (device_id->lun == lun))) { in lpfc_find_next_oas_lun()
6589 *found_lun = device_id->lun; in lpfc_find_next_oas_lun()
6591 &device_id->vport_wwpn, in lpfc_find_next_oas_lun()
6594 &device_id->target_wwpn, in lpfc_find_next_oas_lun()
6596 if (lun_info->available) in lpfc_find_next_oas_lun()
6601 *found_lun_pri = lun_info->priority; in lpfc_find_next_oas_lun()
6602 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) in lpfc_find_next_oas_lun()
6605 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) in lpfc_find_next_oas_lun()
6610 *starting_lun = device_id->lun; in lpfc_find_next_oas_lun()
6611 memcpy(vport_wwpn, &device_id->vport_wwpn, in lpfc_find_next_oas_lun()
6613 memcpy(target_wwpn, &device_id->target_wwpn, in lpfc_find_next_oas_lun()
6619 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_find_next_oas_lun()
6624 * lpfc_enable_oas_lun - enables a lun for OAS operations
6641 * false - Error
6642 * true - Success
6653 !phba->cfg_fof) in lpfc_enable_oas_lun()
6656 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_enable_oas_lun()
6659 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, in lpfc_enable_oas_lun()
6662 if (!lun_info->oas_enabled) in lpfc_enable_oas_lun()
6663 lun_info->oas_enabled = true; in lpfc_enable_oas_lun()
6664 lun_info->priority = pri; in lpfc_enable_oas_lun()
6665 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_enable_oas_lun()
6673 lun_info->oas_enabled = true; in lpfc_enable_oas_lun()
6674 lun_info->priority = pri; in lpfc_enable_oas_lun()
6675 lun_info->available = false; in lpfc_enable_oas_lun()
6676 list_add_tail(&lun_info->listentry, &phba->luns); in lpfc_enable_oas_lun()
6677 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_enable_oas_lun()
6680 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_enable_oas_lun()
6685 * lpfc_disable_oas_lun - disables a lun for OAS operations
6701 * false - Error
6702 * true - Success
6713 !phba->cfg_fof) in lpfc_disable_oas_lun()
6716 spin_lock_irqsave(&phba->devicelock, flags); in lpfc_disable_oas_lun()
6720 &phba->luns, vport_wwpn, in lpfc_disable_oas_lun()
6723 lun_info->oas_enabled = false; in lpfc_disable_oas_lun()
6724 lun_info->priority = pri; in lpfc_disable_oas_lun()
6725 if (!lun_info->available) in lpfc_disable_oas_lun()
6727 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_disable_oas_lun()
6731 spin_unlock_irqrestore(&phba->devicelock, flags); in lpfc_disable_oas_lun()
6744 return -ENODEV; in lpfc_init_no_sdev()
6750 return -ENODEV; in lpfc_config_no_sdev()
6762 .this_id = -1,
6787 .this_id = -1,
6814 .this_id = -1,