1d613b6a7SJames Smart /******************************************************************* 2d613b6a7SJames Smart * This file is part of the Emulex Linux Device Driver for * 3d613b6a7SJames Smart * Fibre Channsel Host Bus Adapters. * 4d080abe0SJames Smart * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * 5d080abe0SJames Smart * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * 6d613b6a7SJames Smart * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7d613b6a7SJames Smart * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 9d613b6a7SJames Smart * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10d613b6a7SJames Smart * * 11d613b6a7SJames Smart * This program is free software; you can redistribute it and/or * 12d613b6a7SJames Smart * modify it under the terms of version 2 of the GNU General * 13d613b6a7SJames Smart * Public License as published by the Free Software Foundation. * 14d613b6a7SJames Smart * This program is distributed in the hope that it will be useful. * 15d613b6a7SJames Smart * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16d613b6a7SJames Smart * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17d613b6a7SJames Smart * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18d613b6a7SJames Smart * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19d613b6a7SJames Smart * TO BE LEGALLY INVALID. See the GNU General Public License for * 20d613b6a7SJames Smart * more details, a copy of which can be found in the file COPYING * 21d613b6a7SJames Smart * included with this package. * 22d613b6a7SJames Smart ********************************************************************/ 23d613b6a7SJames Smart #include <linux/pci.h> 24d613b6a7SJames Smart #include <linux/slab.h> 25d613b6a7SJames Smart #include <linux/interrupt.h> 26d613b6a7SJames Smart #include <linux/delay.h> 27d613b6a7SJames Smart #include <asm/unaligned.h> 28d613b6a7SJames Smart #include <linux/crc-t10dif.h> 29d613b6a7SJames Smart #include <net/checksum.h> 30d613b6a7SJames Smart 31d613b6a7SJames Smart #include <scsi/scsi.h> 32d613b6a7SJames Smart #include <scsi/scsi_device.h> 33d613b6a7SJames Smart #include <scsi/scsi_eh.h> 34d613b6a7SJames Smart #include <scsi/scsi_host.h> 35d613b6a7SJames Smart #include <scsi/scsi_tcq.h> 36d613b6a7SJames Smart #include <scsi/scsi_transport_fc.h> 37d613b6a7SJames Smart #include <scsi/fc/fc_fs.h> 38d613b6a7SJames Smart 39d613b6a7SJames Smart #include <../drivers/nvme/host/nvme.h> 40d613b6a7SJames Smart #include <linux/nvme-fc-driver.h> 41d613b6a7SJames Smart 42d613b6a7SJames Smart #include "lpfc_version.h" 43d613b6a7SJames Smart #include "lpfc_hw4.h" 44d613b6a7SJames Smart #include "lpfc_hw.h" 45d613b6a7SJames Smart #include "lpfc_sli.h" 46d613b6a7SJames Smart #include "lpfc_sli4.h" 47d613b6a7SJames Smart #include "lpfc_nl.h" 48d613b6a7SJames Smart #include "lpfc_disc.h" 49d613b6a7SJames Smart #include "lpfc.h" 50d613b6a7SJames Smart #include "lpfc_scsi.h" 51d613b6a7SJames Smart #include "lpfc_nvme.h" 52d613b6a7SJames Smart #include "lpfc_nvmet.h" 53d613b6a7SJames Smart #include "lpfc_logmsg.h" 54d613b6a7SJames Smart #include "lpfc_crtn.h" 55d613b6a7SJames Smart #include "lpfc_vport.h" 562b65e182SJames Smart #include "lpfc_debugfs.h" 57d613b6a7SJames Smart 58d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *, 59d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 60d613b6a7SJames Smart dma_addr_t rspbuf, 61d613b6a7SJames Smart uint16_t rspsize); 62d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *, 63d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *); 64d613b6a7SJames Smart static int lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *, 65d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 66d613b6a7SJames Smart uint32_t, uint16_t); 67d613b6a7SJames Smart static int lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *, 68d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 69d613b6a7SJames Smart uint32_t, uint16_t); 70d613b6a7SJames Smart static int lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *, 71d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 72d613b6a7SJames Smart uint32_t, uint16_t); 73d613b6a7SJames Smart 7486c67379SJames Smart void 7586c67379SJames Smart lpfc_nvmet_defer_release(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp) 7686c67379SJames Smart { 7786c67379SJames Smart unsigned long iflag; 7886c67379SJames Smart 7986c67379SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 8086c67379SJames Smart "6313 NVMET Defer ctx release xri x%x flg x%x\n", 8186c67379SJames Smart ctxp->oxid, ctxp->flag); 8286c67379SJames Smart 8386c67379SJames Smart spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 8486c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS) { 8586c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, 8686c67379SJames Smart iflag); 8786c67379SJames Smart return; 8886c67379SJames Smart } 8986c67379SJames Smart ctxp->flag |= LPFC_NVMET_CTX_RLS; 9086c67379SJames Smart list_add_tail(&ctxp->list, &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); 9186c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 9286c67379SJames Smart } 9386c67379SJames Smart 94d613b6a7SJames Smart /** 95d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response 96d613b6a7SJames Smart * @phba: Pointer to HBA context object. 97d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 98d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 99d613b6a7SJames Smart * 100d613b6a7SJames Smart * The function is called from SLI ring event handler with no 101d613b6a7SJames Smart * lock held. This function is the completion handler for NVME LS commands 102d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 103d613b6a7SJames Smart **/ 104d613b6a7SJames Smart static void 105d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 106d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 107d613b6a7SJames Smart { 108d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 109d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp; 110d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 111d613b6a7SJames Smart uint32_t status, result; 112d613b6a7SJames Smart 113d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 114d613b6a7SJames Smart result = wcqe->parameter; 115d613b6a7SJames Smart if (!phba->targetport) 116d613b6a7SJames Smart goto out; 117d613b6a7SJames Smart 118d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 119d613b6a7SJames Smart 120d613b6a7SJames Smart if (status) 121d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_error); 122d613b6a7SJames Smart else 123d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_cmpl); 124d613b6a7SJames Smart 125d613b6a7SJames Smart out: 126d613b6a7SJames Smart ctxp = cmdwqe->context2; 127d613b6a7SJames Smart rsp = &ctxp->ctx.ls_req; 128d613b6a7SJames Smart 1292b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS CMPL: xri x%x stat x%x result x%x\n", 1302b65e182SJames Smart ctxp->oxid, status, result); 1312b65e182SJames Smart 132d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 133d613b6a7SJames Smart "6038 %s: Entrypoint: ctx %p status %x/%x\n", __func__, 134d613b6a7SJames Smart ctxp, status, result); 135d613b6a7SJames Smart 136d613b6a7SJames Smart lpfc_nlp_put(cmdwqe->context1); 137d613b6a7SJames Smart cmdwqe->context2 = NULL; 138d613b6a7SJames Smart cmdwqe->context3 = NULL; 139d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 140d613b6a7SJames Smart rsp->done(rsp); 141d613b6a7SJames Smart kfree(ctxp); 142d613b6a7SJames Smart } 143d613b6a7SJames Smart 144d613b6a7SJames Smart /** 145d613b6a7SJames Smart * lpfc_nvmet_rq_post - Repost a NVMET RQ DMA buffer and clean up context 146d613b6a7SJames Smart * @phba: HBA buffer is associated with 147d613b6a7SJames Smart * @ctxp: context to clean up 148d613b6a7SJames Smart * @mp: Buffer to free 149d613b6a7SJames Smart * 150d613b6a7SJames Smart * Description: Frees the given DMA buffer in the appropriate way given by 151d613b6a7SJames Smart * reposting it to its associated RQ so it can be reused. 152d613b6a7SJames Smart * 153d613b6a7SJames Smart * Notes: Takes phba->hbalock. Can be called with or without other locks held. 154d613b6a7SJames Smart * 155d613b6a7SJames Smart * Returns: None 156d613b6a7SJames Smart **/ 157d613b6a7SJames Smart void 158d613b6a7SJames Smart lpfc_nvmet_rq_post(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp, 159d613b6a7SJames Smart struct lpfc_dmabuf *mp) 160d613b6a7SJames Smart { 161d613b6a7SJames Smart if (ctxp) { 16286c67379SJames Smart if (ctxp->flag) 16386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 16486c67379SJames Smart "6314 rq_post ctx xri x%x flag x%x\n", 16586c67379SJames Smart ctxp->oxid, ctxp->flag); 16686c67379SJames Smart 167d613b6a7SJames Smart if (ctxp->txrdy) { 168d613b6a7SJames Smart pci_pool_free(phba->txrdy_payload_pool, ctxp->txrdy, 169d613b6a7SJames Smart ctxp->txrdy_phys); 170d613b6a7SJames Smart ctxp->txrdy = NULL; 171d613b6a7SJames Smart ctxp->txrdy_phys = 0; 172d613b6a7SJames Smart } 173d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_FREE; 174d613b6a7SJames Smart } 175d613b6a7SJames Smart lpfc_rq_buf_free(phba, mp); 176d613b6a7SJames Smart } 177d613b6a7SJames Smart 1782b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1792b65e182SJames Smart static void 1802b65e182SJames Smart lpfc_nvmet_ktime(struct lpfc_hba *phba, 1812b65e182SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 1822b65e182SJames Smart { 1832b65e182SJames Smart uint64_t seg1, seg2, seg3, seg4, seg5; 1842b65e182SJames Smart uint64_t seg6, seg7, seg8, seg9, seg10; 1852b65e182SJames Smart 1862b65e182SJames Smart if (!phba->ktime_on) 1872b65e182SJames Smart return; 1882b65e182SJames Smart 1892b65e182SJames Smart if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme || 1902b65e182SJames Smart !ctxp->ts_nvme_data || !ctxp->ts_data_wqput || 1912b65e182SJames Smart !ctxp->ts_isr_data || !ctxp->ts_data_nvme || 1922b65e182SJames Smart !ctxp->ts_nvme_status || !ctxp->ts_status_wqput || 1932b65e182SJames Smart !ctxp->ts_isr_status || !ctxp->ts_status_nvme) 1942b65e182SJames Smart return; 1952b65e182SJames Smart 1962b65e182SJames Smart if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme) 1972b65e182SJames Smart return; 1982b65e182SJames Smart if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data) 1992b65e182SJames Smart return; 2002b65e182SJames Smart if (ctxp->ts_nvme_data > ctxp->ts_data_wqput) 2012b65e182SJames Smart return; 2022b65e182SJames Smart if (ctxp->ts_data_wqput > ctxp->ts_isr_data) 2032b65e182SJames Smart return; 2042b65e182SJames Smart if (ctxp->ts_isr_data > ctxp->ts_data_nvme) 2052b65e182SJames Smart return; 2062b65e182SJames Smart if (ctxp->ts_data_nvme > ctxp->ts_nvme_status) 2072b65e182SJames Smart return; 2082b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_status_wqput) 2092b65e182SJames Smart return; 2102b65e182SJames Smart if (ctxp->ts_status_wqput > ctxp->ts_isr_status) 2112b65e182SJames Smart return; 2122b65e182SJames Smart if (ctxp->ts_isr_status > ctxp->ts_status_nvme) 2132b65e182SJames Smart return; 2142b65e182SJames Smart /* 2152b65e182SJames Smart * Segment 1 - Time from FCP command received by MSI-X ISR 2162b65e182SJames Smart * to FCP command is passed to NVME Layer. 2172b65e182SJames Smart * Segment 2 - Time from FCP command payload handed 2182b65e182SJames Smart * off to NVME Layer to Driver receives a Command op 2192b65e182SJames Smart * from NVME Layer. 2202b65e182SJames Smart * Segment 3 - Time from Driver receives a Command op 2212b65e182SJames Smart * from NVME Layer to Command is put on WQ. 2222b65e182SJames Smart * Segment 4 - Time from Driver WQ put is done 2232b65e182SJames Smart * to MSI-X ISR for Command cmpl. 2242b65e182SJames Smart * Segment 5 - Time from MSI-X ISR for Command cmpl to 2252b65e182SJames Smart * Command cmpl is passed to NVME Layer. 2262b65e182SJames Smart * Segment 6 - Time from Command cmpl is passed to NVME 2272b65e182SJames Smart * Layer to Driver receives a RSP op from NVME Layer. 2282b65e182SJames Smart * Segment 7 - Time from Driver receives a RSP op from 2292b65e182SJames Smart * NVME Layer to WQ put is done on TRSP FCP Status. 2302b65e182SJames Smart * Segment 8 - Time from Driver WQ put is done on TRSP 2312b65e182SJames Smart * FCP Status to MSI-X ISR for TRSP cmpl. 2322b65e182SJames Smart * Segment 9 - Time from MSI-X ISR for TRSP cmpl to 2332b65e182SJames Smart * TRSP cmpl is passed to NVME Layer. 2342b65e182SJames Smart * Segment 10 - Time from FCP command received by 2352b65e182SJames Smart * MSI-X ISR to command is completed on wire. 2362b65e182SJames Smart * (Segments 1 thru 8) for READDATA / WRITEDATA 2372b65e182SJames Smart * (Segments 1 thru 4) for READDATA_RSP 2382b65e182SJames Smart */ 2392b65e182SJames Smart seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd; 2402b65e182SJames Smart seg2 = (ctxp->ts_nvme_data - ctxp->ts_isr_cmd) - seg1; 2412b65e182SJames Smart seg3 = (ctxp->ts_data_wqput - ctxp->ts_isr_cmd) - 2422b65e182SJames Smart seg1 - seg2; 2432b65e182SJames Smart seg4 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd) - 2442b65e182SJames Smart seg1 - seg2 - seg3; 2452b65e182SJames Smart seg5 = (ctxp->ts_data_nvme - ctxp->ts_isr_cmd) - 2462b65e182SJames Smart seg1 - seg2 - seg3 - seg4; 2472b65e182SJames Smart 2482b65e182SJames Smart /* For auto rsp commands seg6 thru seg10 will be 0 */ 2492b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) { 2502b65e182SJames Smart seg6 = (ctxp->ts_nvme_status - 2512b65e182SJames Smart ctxp->ts_isr_cmd) - 2522b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - seg5; 2532b65e182SJames Smart seg7 = (ctxp->ts_status_wqput - 2542b65e182SJames Smart ctxp->ts_isr_cmd) - 2552b65e182SJames Smart seg1 - seg2 - seg3 - 2562b65e182SJames Smart seg4 - seg5 - seg6; 2572b65e182SJames Smart seg8 = (ctxp->ts_isr_status - 2582b65e182SJames Smart ctxp->ts_isr_cmd) - 2592b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - 2602b65e182SJames Smart seg5 - seg6 - seg7; 2612b65e182SJames Smart seg9 = (ctxp->ts_status_nvme - 2622b65e182SJames Smart ctxp->ts_isr_cmd) - 2632b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - 2642b65e182SJames Smart seg5 - seg6 - seg7 - seg8; 2652b65e182SJames Smart seg10 = (ctxp->ts_isr_status - 2662b65e182SJames Smart ctxp->ts_isr_cmd); 2672b65e182SJames Smart } else { 2682b65e182SJames Smart seg6 = 0; 2692b65e182SJames Smart seg7 = 0; 2702b65e182SJames Smart seg8 = 0; 2712b65e182SJames Smart seg9 = 0; 2722b65e182SJames Smart seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd); 2732b65e182SJames Smart } 2742b65e182SJames Smart 2752b65e182SJames Smart phba->ktime_seg1_total += seg1; 2762b65e182SJames Smart if (seg1 < phba->ktime_seg1_min) 2772b65e182SJames Smart phba->ktime_seg1_min = seg1; 2782b65e182SJames Smart else if (seg1 > phba->ktime_seg1_max) 2792b65e182SJames Smart phba->ktime_seg1_max = seg1; 2802b65e182SJames Smart 2812b65e182SJames Smart phba->ktime_seg2_total += seg2; 2822b65e182SJames Smart if (seg2 < phba->ktime_seg2_min) 2832b65e182SJames Smart phba->ktime_seg2_min = seg2; 2842b65e182SJames Smart else if (seg2 > phba->ktime_seg2_max) 2852b65e182SJames Smart phba->ktime_seg2_max = seg2; 2862b65e182SJames Smart 2872b65e182SJames Smart phba->ktime_seg3_total += seg3; 2882b65e182SJames Smart if (seg3 < phba->ktime_seg3_min) 2892b65e182SJames Smart phba->ktime_seg3_min = seg3; 2902b65e182SJames Smart else if (seg3 > phba->ktime_seg3_max) 2912b65e182SJames Smart phba->ktime_seg3_max = seg3; 2922b65e182SJames Smart 2932b65e182SJames Smart phba->ktime_seg4_total += seg4; 2942b65e182SJames Smart if (seg4 < phba->ktime_seg4_min) 2952b65e182SJames Smart phba->ktime_seg4_min = seg4; 2962b65e182SJames Smart else if (seg4 > phba->ktime_seg4_max) 2972b65e182SJames Smart phba->ktime_seg4_max = seg4; 2982b65e182SJames Smart 2992b65e182SJames Smart phba->ktime_seg5_total += seg5; 3002b65e182SJames Smart if (seg5 < phba->ktime_seg5_min) 3012b65e182SJames Smart phba->ktime_seg5_min = seg5; 3022b65e182SJames Smart else if (seg5 > phba->ktime_seg5_max) 3032b65e182SJames Smart phba->ktime_seg5_max = seg5; 3042b65e182SJames Smart 3052b65e182SJames Smart phba->ktime_data_samples++; 3062b65e182SJames Smart if (!seg6) 3072b65e182SJames Smart goto out; 3082b65e182SJames Smart 3092b65e182SJames Smart phba->ktime_seg6_total += seg6; 3102b65e182SJames Smart if (seg6 < phba->ktime_seg6_min) 3112b65e182SJames Smart phba->ktime_seg6_min = seg6; 3122b65e182SJames Smart else if (seg6 > phba->ktime_seg6_max) 3132b65e182SJames Smart phba->ktime_seg6_max = seg6; 3142b65e182SJames Smart 3152b65e182SJames Smart phba->ktime_seg7_total += seg7; 3162b65e182SJames Smart if (seg7 < phba->ktime_seg7_min) 3172b65e182SJames Smart phba->ktime_seg7_min = seg7; 3182b65e182SJames Smart else if (seg7 > phba->ktime_seg7_max) 3192b65e182SJames Smart phba->ktime_seg7_max = seg7; 3202b65e182SJames Smart 3212b65e182SJames Smart phba->ktime_seg8_total += seg8; 3222b65e182SJames Smart if (seg8 < phba->ktime_seg8_min) 3232b65e182SJames Smart phba->ktime_seg8_min = seg8; 3242b65e182SJames Smart else if (seg8 > phba->ktime_seg8_max) 3252b65e182SJames Smart phba->ktime_seg8_max = seg8; 3262b65e182SJames Smart 3272b65e182SJames Smart phba->ktime_seg9_total += seg9; 3282b65e182SJames Smart if (seg9 < phba->ktime_seg9_min) 3292b65e182SJames Smart phba->ktime_seg9_min = seg9; 3302b65e182SJames Smart else if (seg9 > phba->ktime_seg9_max) 3312b65e182SJames Smart phba->ktime_seg9_max = seg9; 3322b65e182SJames Smart out: 3332b65e182SJames Smart phba->ktime_seg10_total += seg10; 3342b65e182SJames Smart if (seg10 < phba->ktime_seg10_min) 3352b65e182SJames Smart phba->ktime_seg10_min = seg10; 3362b65e182SJames Smart else if (seg10 > phba->ktime_seg10_max) 3372b65e182SJames Smart phba->ktime_seg10_max = seg10; 3382b65e182SJames Smart phba->ktime_status_samples++; 3392b65e182SJames Smart } 3402b65e182SJames Smart #endif 3412b65e182SJames Smart 342d613b6a7SJames Smart /** 343d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response 344d613b6a7SJames Smart * @phba: Pointer to HBA context object. 345d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 346d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 347d613b6a7SJames Smart * 348d613b6a7SJames Smart * The function is called from SLI ring event handler with no 349d613b6a7SJames Smart * lock held. This function is the completion handler for NVME FCP commands 350d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 351d613b6a7SJames Smart **/ 352d613b6a7SJames Smart static void 353d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 354d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 355d613b6a7SJames Smart { 356d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 357d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp; 358d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 359d613b6a7SJames Smart uint32_t status, result, op, start_clean; 3602b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 3612b65e182SJames Smart uint32_t id; 3622b65e182SJames Smart #endif 363d613b6a7SJames Smart 364d613b6a7SJames Smart ctxp = cmdwqe->context2; 36586c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_IO_INP; 36686c67379SJames Smart 367d613b6a7SJames Smart rsp = &ctxp->ctx.fcp_req; 368d613b6a7SJames Smart op = rsp->op; 369d613b6a7SJames Smart 370d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 371d613b6a7SJames Smart result = wcqe->parameter; 372d613b6a7SJames Smart 37386c67379SJames Smart if (phba->targetport) 37486c67379SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 37586c67379SJames Smart else 37686c67379SJames Smart tgtp = NULL; 377d613b6a7SJames Smart 3782b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n", 3792b65e182SJames Smart ctxp->oxid, op, status); 3802b65e182SJames Smart 381d613b6a7SJames Smart if (status) { 382d613b6a7SJames Smart rsp->fcp_error = NVME_SC_DATA_XFER_ERROR; 383d613b6a7SJames Smart rsp->transferred_length = 0; 38486c67379SJames Smart if (tgtp) 385d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_error); 38686c67379SJames Smart 38786c67379SJames Smart /* pick up SLI4 exhange busy condition */ 38886c67379SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) { 38986c67379SJames Smart ctxp->flag |= LPFC_NVMET_XBUSY; 39086c67379SJames Smart 39186c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 39286c67379SJames Smart "6315 IO Cmpl XBUSY: xri x%x: %x/%x\n", 39386c67379SJames Smart ctxp->oxid, status, result); 39486c67379SJames Smart } else { 39586c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 39686c67379SJames Smart } 39786c67379SJames Smart 398d613b6a7SJames Smart } else { 399d613b6a7SJames Smart rsp->fcp_error = NVME_SC_SUCCESS; 400d613b6a7SJames Smart if (op == NVMET_FCOP_RSP) 401d613b6a7SJames Smart rsp->transferred_length = rsp->rsplen; 402d613b6a7SJames Smart else 403d613b6a7SJames Smart rsp->transferred_length = rsp->transfer_length; 40486c67379SJames Smart if (tgtp) 405d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_cmpl); 406d613b6a7SJames Smart } 407d613b6a7SJames Smart 408d613b6a7SJames Smart if ((op == NVMET_FCOP_READDATA_RSP) || 409d613b6a7SJames Smart (op == NVMET_FCOP_RSP)) { 410d613b6a7SJames Smart /* Sanity check */ 411d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 412d613b6a7SJames Smart ctxp->entry_cnt++; 41386c67379SJames Smart 4142b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4152b65e182SJames Smart if (phba->ktime_on) { 4162b65e182SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 4172b65e182SJames Smart ctxp->ts_isr_data = 4182b65e182SJames Smart cmdwqe->isr_timestamp; 4192b65e182SJames Smart ctxp->ts_data_nvme = 4202b65e182SJames Smart ktime_get_ns(); 4212b65e182SJames Smart ctxp->ts_nvme_status = 4222b65e182SJames Smart ctxp->ts_data_nvme; 4232b65e182SJames Smart ctxp->ts_status_wqput = 4242b65e182SJames Smart ctxp->ts_data_nvme; 4252b65e182SJames Smart ctxp->ts_isr_status = 4262b65e182SJames Smart ctxp->ts_data_nvme; 4272b65e182SJames Smart ctxp->ts_status_nvme = 4282b65e182SJames Smart ctxp->ts_data_nvme; 4292b65e182SJames Smart } else { 4302b65e182SJames Smart ctxp->ts_isr_status = 4312b65e182SJames Smart cmdwqe->isr_timestamp; 4322b65e182SJames Smart ctxp->ts_status_nvme = 4332b65e182SJames Smart ktime_get_ns(); 4342b65e182SJames Smart } 4352b65e182SJames Smart } 4362b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 4372b65e182SJames Smart id = smp_processor_id(); 4382b65e182SJames Smart if (ctxp->cpu != id) 4392b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 4402b65e182SJames Smart "6703 CPU Check cmpl: " 4412b65e182SJames Smart "cpu %d expect %d\n", 4422b65e182SJames Smart id, ctxp->cpu); 4432b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 4442b65e182SJames Smart phba->cpucheck_cmpl_io[id]++; 4452b65e182SJames Smart } 4462b65e182SJames Smart #endif 447d613b6a7SJames Smart rsp->done(rsp); 4482b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4492b65e182SJames Smart if (phba->ktime_on) 4502b65e182SJames Smart lpfc_nvmet_ktime(phba, ctxp); 4512b65e182SJames Smart #endif 45219b58d94SJames Smart /* lpfc_nvmet_xmt_fcp_release() will recycle the context */ 453d613b6a7SJames Smart } else { 454d613b6a7SJames Smart ctxp->entry_cnt++; 455d613b6a7SJames Smart start_clean = offsetof(struct lpfc_iocbq, wqe); 456d613b6a7SJames Smart memset(((char *)cmdwqe) + start_clean, 0, 457d613b6a7SJames Smart (sizeof(struct lpfc_iocbq) - start_clean)); 4582b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4592b65e182SJames Smart if (phba->ktime_on) { 4602b65e182SJames Smart ctxp->ts_isr_data = cmdwqe->isr_timestamp; 4612b65e182SJames Smart ctxp->ts_data_nvme = ktime_get_ns(); 4622b65e182SJames Smart } 4632b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 4642b65e182SJames Smart id = smp_processor_id(); 4652b65e182SJames Smart if (ctxp->cpu != id) 4662b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 4672b65e182SJames Smart "6704 CPU Check cmdcmpl: " 4682b65e182SJames Smart "cpu %d expect %d\n", 4692b65e182SJames Smart id, ctxp->cpu); 4702b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 4712b65e182SJames Smart phba->cpucheck_ccmpl_io[id]++; 4722b65e182SJames Smart } 4732b65e182SJames Smart #endif 474d613b6a7SJames Smart rsp->done(rsp); 475d613b6a7SJames Smart } 476d613b6a7SJames Smart } 477d613b6a7SJames Smart 478d613b6a7SJames Smart static int 479d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport, 480d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp) 481d613b6a7SJames Smart { 482d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 483d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.ls_req); 484d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 485d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf = 486d613b6a7SJames Smart (struct hbq_dmabuf *)ctxp->rqb_buffer; 487d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 488d613b6a7SJames Smart struct lpfc_nvmet_tgtport *nvmep = tgtport->private; 489d613b6a7SJames Smart struct lpfc_dmabuf dmabuf; 490d613b6a7SJames Smart struct ulp_bde64 bpl; 491d613b6a7SJames Smart int rc; 492d613b6a7SJames Smart 493d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 494d613b6a7SJames Smart "6023 %s: Entrypoint ctx %p %p\n", __func__, 495d613b6a7SJames Smart ctxp, tgtport); 496d613b6a7SJames Smart 497d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, ctxp, rsp->rspdma, 498d613b6a7SJames Smart rsp->rsplen); 499d613b6a7SJames Smart if (nvmewqeq == NULL) { 500d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 501d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 502d613b6a7SJames Smart "6150 LS Drop IO x%x: Prep\n", 503d613b6a7SJames Smart ctxp->oxid); 504d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 505547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 506d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, 507d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 508d613b6a7SJames Smart return -ENOMEM; 509d613b6a7SJames Smart } 510d613b6a7SJames Smart 511d613b6a7SJames Smart /* Save numBdes for bpl2sgl */ 512d613b6a7SJames Smart nvmewqeq->rsvd2 = 1; 513d613b6a7SJames Smart nvmewqeq->hba_wqidx = 0; 514d613b6a7SJames Smart nvmewqeq->context3 = &dmabuf; 515d613b6a7SJames Smart dmabuf.virt = &bpl; 516d613b6a7SJames Smart bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow; 517d613b6a7SJames Smart bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh; 518d613b6a7SJames Smart bpl.tus.f.bdeSize = rsp->rsplen; 519d613b6a7SJames Smart bpl.tus.f.bdeFlags = 0; 520d613b6a7SJames Smart bpl.tus.w = le32_to_cpu(bpl.tus.w); 521d613b6a7SJames Smart 522d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_rsp_cmp; 523d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 524d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 525d613b6a7SJames Smart 5262b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RESP: xri x%x wqidx x%x len x%x\n", 5272b65e182SJames Smart ctxp->oxid, nvmewqeq->hba_wqidx, rsp->rsplen); 5282b65e182SJames Smart 529d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, nvmewqeq); 530d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 531d613b6a7SJames Smart /* 532d613b6a7SJames Smart * Okay to repost buffer here, but wait till cmpl 533d613b6a7SJames Smart * before freeing ctxp and iocbq. 534d613b6a7SJames Smart */ 535d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 536d613b6a7SJames Smart ctxp->rqb_buffer = 0; 537d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_rsp); 538d613b6a7SJames Smart return 0; 539d613b6a7SJames Smart } 540d613b6a7SJames Smart /* Give back resources */ 541d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 542d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 543d613b6a7SJames Smart "6151 LS Drop IO x%x: Issue %d\n", 544d613b6a7SJames Smart ctxp->oxid, rc); 545d613b6a7SJames Smart 546d613b6a7SJames Smart lpfc_nlp_put(nvmewqeq->context1); 547d613b6a7SJames Smart 548d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 549547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 550d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid); 551d613b6a7SJames Smart return -ENXIO; 552d613b6a7SJames Smart } 553d613b6a7SJames Smart 554d613b6a7SJames Smart static int 555d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport, 556d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp) 557d613b6a7SJames Smart { 558d613b6a7SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 559d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 560d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 561d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 562d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 563223b78eaSArnd Bergmann int rc; 5642b65e182SJames Smart 5652b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 5662b65e182SJames Smart if (phba->ktime_on) { 5672b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 5682b65e182SJames Smart ctxp->ts_nvme_status = ktime_get_ns(); 5692b65e182SJames Smart else 5702b65e182SJames Smart ctxp->ts_nvme_data = ktime_get_ns(); 5712b65e182SJames Smart } 5722b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 573223b78eaSArnd Bergmann int id = smp_processor_id(); 5742b65e182SJames Smart ctxp->cpu = id; 5752b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 5762b65e182SJames Smart phba->cpucheck_xmt_io[id]++; 5772b65e182SJames Smart if (rsp->hwqid != id) { 5782b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 5792b65e182SJames Smart "6705 CPU Check OP: " 5802b65e182SJames Smart "cpu %d expect %d\n", 5812b65e182SJames Smart id, rsp->hwqid); 5822b65e182SJames Smart ctxp->cpu = rsp->hwqid; 5832b65e182SJames Smart } 5842b65e182SJames Smart } 5852b65e182SJames Smart #endif 586d613b6a7SJames Smart 587d613b6a7SJames Smart /* Sanity check */ 58886c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABTS_RCV) || 58986c67379SJames Smart (ctxp->state == LPFC_NVMET_STE_ABORT)) { 590d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 591d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 59286c67379SJames Smart "6102 IO xri x%x aborted\n", 593d613b6a7SJames Smart ctxp->oxid); 594a5068b46SJames Smart rc = -ENXIO; 595d613b6a7SJames Smart goto aerr; 596d613b6a7SJames Smart } 597d613b6a7SJames Smart 598d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp); 599d613b6a7SJames Smart if (nvmewqeq == NULL) { 600d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 601d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 602d613b6a7SJames Smart "6152 FCP Drop IO x%x: Prep\n", 603d613b6a7SJames Smart ctxp->oxid); 604a5068b46SJames Smart rc = -ENXIO; 605d613b6a7SJames Smart goto aerr; 606d613b6a7SJames Smart } 607d613b6a7SJames Smart 608d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp; 609d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 610d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 611d613b6a7SJames Smart nvmewqeq->iocb_flag |= LPFC_IO_NVMET; 612d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = rsp->hwqid; 613d613b6a7SJames Smart 6142b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n", 6152b65e182SJames Smart ctxp->oxid, rsp->op, rsp->rsplen); 6162b65e182SJames Smart 61761f3d4bfSJames Smart ctxp->flag |= LPFC_NVMET_IO_INP; 618d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq); 619d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 6202b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 6212b65e182SJames Smart if (!phba->ktime_on) 6222b65e182SJames Smart return 0; 6232b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 6242b65e182SJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 6252b65e182SJames Smart else 6262b65e182SJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 6272b65e182SJames Smart #endif 628d613b6a7SJames Smart return 0; 629d613b6a7SJames Smart } 630d613b6a7SJames Smart 631d613b6a7SJames Smart /* Give back resources */ 632d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 633d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 634d613b6a7SJames Smart "6153 FCP Drop IO x%x: Issue: %d\n", 635d613b6a7SJames Smart ctxp->oxid, rc); 636d613b6a7SJames Smart 637d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 638d613b6a7SJames Smart nvmewqeq->context2 = NULL; 639d613b6a7SJames Smart nvmewqeq->context3 = NULL; 640a5068b46SJames Smart rc = -EBUSY; 641d613b6a7SJames Smart aerr: 642a5068b46SJames Smart return rc; 643d613b6a7SJames Smart } 644d613b6a7SJames Smart 645d613b6a7SJames Smart static void 646d613b6a7SJames Smart lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) 647d613b6a7SJames Smart { 648d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tport = targetport->private; 649d613b6a7SJames Smart 650d613b6a7SJames Smart /* release any threads waiting for the unreg to complete */ 651d613b6a7SJames Smart complete(&tport->tport_unreg_done); 652d613b6a7SJames Smart } 653d613b6a7SJames Smart 65419b58d94SJames Smart static void 655a97ec51bSJames Smart lpfc_nvmet_xmt_fcp_abort(struct nvmet_fc_target_port *tgtport, 656a97ec51bSJames Smart struct nvmefc_tgt_fcp_req *req) 657a97ec51bSJames Smart { 658a97ec51bSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 659a97ec51bSJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 660a97ec51bSJames Smart container_of(req, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 661a97ec51bSJames Smart struct lpfc_hba *phba = ctxp->phba; 66286c67379SJames Smart unsigned long flags; 663a97ec51bSJames Smart 664a97ec51bSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 66586c67379SJames Smart "6103 Abort op: oxri x%x flg x%x cnt %d\n", 66686c67379SJames Smart ctxp->oxid, ctxp->flag, ctxp->entry_cnt); 667a97ec51bSJames Smart 66886c67379SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP ABRT: " 66986c67379SJames Smart "xri x%x flg x%x cnt x%x\n", 67086c67379SJames Smart ctxp->oxid, ctxp->flag, ctxp->entry_cnt); 671a97ec51bSJames Smart 672a97ec51bSJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_abort); 673a97ec51bSJames Smart ctxp->entry_cnt++; 67486c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 67586c67379SJames Smart 67686c67379SJames Smart /* Since iaab/iaar are NOT set, we need to check 67786c67379SJames Smart * if the firmware is in process of aborting IO 67886c67379SJames Smart */ 67986c67379SJames Smart if (ctxp->flag & LPFC_NVMET_XBUSY) { 68086c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 68186c67379SJames Smart return; 68286c67379SJames Smart } 683a97ec51bSJames Smart ctxp->flag |= LPFC_NVMET_ABORT_OP; 684a97ec51bSJames Smart if (ctxp->flag & LPFC_NVMET_IO_INP) 685a97ec51bSJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 686a97ec51bSJames Smart ctxp->oxid); 687a97ec51bSJames Smart else 688a97ec51bSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 689a97ec51bSJames Smart ctxp->oxid); 69086c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 691a97ec51bSJames Smart } 692a97ec51bSJames Smart 693a97ec51bSJames Smart static void 69419b58d94SJames Smart lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, 69519b58d94SJames Smart struct nvmefc_tgt_fcp_req *rsp) 69619b58d94SJames Smart { 697547077a4SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 69819b58d94SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 69919b58d94SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 70019b58d94SJames Smart struct lpfc_hba *phba = ctxp->phba; 70119b58d94SJames Smart unsigned long flags; 70219b58d94SJames Smart bool aborting = false; 70319b58d94SJames Smart 70419b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 70586c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABORT_OP) || 70686c67379SJames Smart (ctxp->flag & LPFC_NVMET_XBUSY)) { 70719b58d94SJames Smart aborting = true; 70886c67379SJames Smart /* let the abort path do the real release */ 70986c67379SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 71019b58d94SJames Smart } 71119b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 71219b58d94SJames Smart 71319b58d94SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d\n", ctxp->oxid, 71419b58d94SJames Smart ctxp->state, 0); 71519b58d94SJames Smart 716547077a4SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_release); 717547077a4SJames Smart 71886c67379SJames Smart if (aborting) 71986c67379SJames Smart return; 72086c67379SJames Smart 72119b58d94SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 72219b58d94SJames Smart } 72319b58d94SJames Smart 724d613b6a7SJames Smart static struct nvmet_fc_target_template lpfc_tgttemplate = { 725d613b6a7SJames Smart .targetport_delete = lpfc_nvmet_targetport_delete, 726d613b6a7SJames Smart .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp, 727d613b6a7SJames Smart .fcp_op = lpfc_nvmet_xmt_fcp_op, 728a97ec51bSJames Smart .fcp_abort = lpfc_nvmet_xmt_fcp_abort, 72919b58d94SJames Smart .fcp_req_release = lpfc_nvmet_xmt_fcp_release, 730d613b6a7SJames Smart 731d613b6a7SJames Smart .max_hw_queues = 1, 732d613b6a7SJames Smart .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 733d613b6a7SJames Smart .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 734d613b6a7SJames Smart .dma_boundary = 0xFFFFFFFF, 735d613b6a7SJames Smart 736d613b6a7SJames Smart /* optional features */ 737d613b6a7SJames Smart .target_features = 0, 738d613b6a7SJames Smart /* sizes of additional private data for data structures */ 739d613b6a7SJames Smart .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport), 740d613b6a7SJames Smart }; 741d613b6a7SJames Smart 742d613b6a7SJames Smart int 743d613b6a7SJames Smart lpfc_nvmet_create_targetport(struct lpfc_hba *phba) 744d613b6a7SJames Smart { 745d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 746d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 747d613b6a7SJames Smart struct nvmet_fc_port_info pinfo; 748d613b6a7SJames Smart int error = 0; 749d613b6a7SJames Smart 750d613b6a7SJames Smart if (phba->targetport) 751d613b6a7SJames Smart return 0; 752d613b6a7SJames Smart 753d613b6a7SJames Smart memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info)); 754d613b6a7SJames Smart pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 755d613b6a7SJames Smart pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 756d613b6a7SJames Smart pinfo.port_id = vport->fc_myDID; 757d613b6a7SJames Smart 7584d4c4a4aSJames Smart /* Limit to LPFC_MAX_NVME_SEG_CNT. 7594d4c4a4aSJames Smart * For now need + 1 to get around NVME transport logic. 7604d4c4a4aSJames Smart */ 7614d4c4a4aSJames Smart if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { 7624d4c4a4aSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 7634d4c4a4aSJames Smart "6400 Reducing sg segment cnt to %d\n", 7644d4c4a4aSJames Smart LPFC_MAX_NVME_SEG_CNT); 7654d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; 7664d4c4a4aSJames Smart } else { 7674d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; 7684d4c4a4aSJames Smart } 7694d4c4a4aSJames Smart lpfc_tgttemplate.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 770d613b6a7SJames Smart lpfc_tgttemplate.max_hw_queues = phba->cfg_nvme_io_channel; 771d613b6a7SJames Smart lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP | 77239498faeSJames Smart NVMET_FCTGTFEAT_NEEDS_CMD_CPUSCHED | 77339498faeSJames Smart NVMET_FCTGTFEAT_CMD_IN_ISR | 77439498faeSJames Smart NVMET_FCTGTFEAT_OPDONE_IN_ISR; 775d613b6a7SJames Smart 7767d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 777d613b6a7SJames Smart error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 778d613b6a7SJames Smart &phba->pcidev->dev, 779d613b6a7SJames Smart &phba->targetport); 780166d7211SJames Smart #else 781166d7211SJames Smart error = -ENOMEM; 782166d7211SJames Smart #endif 783d613b6a7SJames Smart if (error) { 784d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 785d613b6a7SJames Smart "6025 Cannot register NVME targetport " 786d613b6a7SJames Smart "x%x\n", error); 787d613b6a7SJames Smart phba->targetport = NULL; 788d613b6a7SJames Smart } else { 789d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *) 790d613b6a7SJames Smart phba->targetport->private; 791d613b6a7SJames Smart tgtp->phba = phba; 792d613b6a7SJames Smart 793d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 794d613b6a7SJames Smart "6026 Registered NVME " 795d613b6a7SJames Smart "targetport: %p, private %p " 796d613b6a7SJames Smart "portnm %llx nodenm %llx\n", 797d613b6a7SJames Smart phba->targetport, tgtp, 798d613b6a7SJames Smart pinfo.port_name, pinfo.node_name); 799d613b6a7SJames Smart 800d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_in, 0); 801d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_out, 0); 802d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_drop, 0); 803d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_abort, 0); 804547077a4SJames Smart atomic_set(&tgtp->xmt_ls_abort_cmpl, 0); 805d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp, 0); 806d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_drop, 0); 807d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_error, 0); 808d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0); 809d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_in, 0); 810d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_out, 0); 811d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_drop, 0); 812d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_drop, 0); 813d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read_rsp, 0); 814d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read, 0); 815d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_write, 0); 816d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp, 0); 817547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_release, 0); 818d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0); 819d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_error, 0); 820d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_drop, 0); 821547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort, 0); 822547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0); 823547077a4SJames Smart atomic_set(&tgtp->xmt_abort_unsol, 0); 824547077a4SJames Smart atomic_set(&tgtp->xmt_abort_sol, 0); 825d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp, 0); 826d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp_error, 0); 827d613b6a7SJames Smart } 828d613b6a7SJames Smart return error; 829d613b6a7SJames Smart } 830d613b6a7SJames Smart 831d613b6a7SJames Smart int 832d613b6a7SJames Smart lpfc_nvmet_update_targetport(struct lpfc_hba *phba) 833d613b6a7SJames Smart { 834d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 835d613b6a7SJames Smart 836d613b6a7SJames Smart if (!phba->targetport) 837d613b6a7SJames Smart return 0; 838d613b6a7SJames Smart 839d613b6a7SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 840d613b6a7SJames Smart "6007 Update NVMET port %p did x%x\n", 841d613b6a7SJames Smart phba->targetport, vport->fc_myDID); 842d613b6a7SJames Smart 843d613b6a7SJames Smart phba->targetport->port_id = vport->fc_myDID; 844d613b6a7SJames Smart return 0; 845d613b6a7SJames Smart } 846d613b6a7SJames Smart 847318083adSJames Smart /** 848318083adSJames Smart * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort 849318083adSJames Smart * @phba: pointer to lpfc hba data structure. 850318083adSJames Smart * @axri: pointer to the nvmet xri abort wcqe structure. 851318083adSJames Smart * 852318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 853318083adSJames Smart * NVMET aborted xri. 854318083adSJames Smart **/ 855318083adSJames Smart void 856318083adSJames Smart lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba, 857318083adSJames Smart struct sli4_wcqe_xri_aborted *axri) 858318083adSJames Smart { 85986c67379SJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 86086c67379SJames Smart uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 86186c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 86286c67379SJames Smart struct lpfc_nodelist *ndlp; 86386c67379SJames Smart unsigned long iflag = 0; 86486c67379SJames Smart int rrq_empty = 0; 86586c67379SJames Smart bool released = false; 86686c67379SJames Smart 86786c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 86886c67379SJames Smart "6317 XB aborted xri x%x rxid x%x\n", xri, rxid); 86986c67379SJames Smart 87086c67379SJames Smart if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) 87186c67379SJames Smart return; 87286c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 87386c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 87486c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 87586c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 87686c67379SJames Smart list) { 87786c67379SJames Smart if (ctxp->rqb_buffer->sglq->sli4_xritag != xri) 87886c67379SJames Smart continue; 87986c67379SJames Smart 88086c67379SJames Smart /* Check if we already received a free context call 88186c67379SJames Smart * and we have completed processing an abort situation. 88286c67379SJames Smart */ 88386c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS && 88486c67379SJames Smart !(ctxp->flag & LPFC_NVMET_ABORT_OP)) { 88586c67379SJames Smart list_del(&ctxp->list); 88686c67379SJames Smart released = true; 88786c67379SJames Smart } 88886c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 88986c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 89086c67379SJames Smart 89186c67379SJames Smart rrq_empty = list_empty(&phba->active_rrq_list); 89286c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 89386c67379SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 89486c67379SJames Smart if (ndlp && NLP_CHK_NODE_ACT(ndlp) && 89586c67379SJames Smart (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || 89686c67379SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 89786c67379SJames Smart lpfc_set_rrq_active(phba, ndlp, 89886c67379SJames Smart ctxp->rqb_buffer->sglq->sli4_lxritag, 89986c67379SJames Smart rxid, 1); 90086c67379SJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 90186c67379SJames Smart } 90286c67379SJames Smart 90386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 90486c67379SJames Smart "6318 XB aborted %x flg x%x (%x)\n", 90586c67379SJames Smart ctxp->oxid, ctxp->flag, released); 90686c67379SJames Smart if (released) 90786c67379SJames Smart lpfc_nvmet_rq_post(phba, ctxp, 90886c67379SJames Smart &ctxp->rqb_buffer->hbuf); 90986c67379SJames Smart if (rrq_empty) 91086c67379SJames Smart lpfc_worker_wake_up(phba); 91186c67379SJames Smart return; 91286c67379SJames Smart } 91386c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 91486c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 91586c67379SJames Smart } 91686c67379SJames Smart 91786c67379SJames Smart int 91886c67379SJames Smart lpfc_nvmet_rcv_unsol_abort(struct lpfc_vport *vport, 91986c67379SJames Smart struct fc_frame_header *fc_hdr) 92086c67379SJames Smart 92186c67379SJames Smart { 92286c67379SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 92386c67379SJames Smart struct lpfc_hba *phba = vport->phba; 92486c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 92586c67379SJames Smart struct nvmefc_tgt_fcp_req *rsp; 92686c67379SJames Smart uint16_t xri; 92786c67379SJames Smart unsigned long iflag = 0; 92886c67379SJames Smart 92986c67379SJames Smart xri = be16_to_cpu(fc_hdr->fh_ox_id); 93086c67379SJames Smart 93186c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 93286c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 93386c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 93486c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 93586c67379SJames Smart list) { 93686c67379SJames Smart if (ctxp->rqb_buffer->sglq->sli4_xritag != xri) 93786c67379SJames Smart continue; 93886c67379SJames Smart 93986c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 94086c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 94186c67379SJames Smart 94286c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 94386c67379SJames Smart ctxp->flag |= LPFC_NVMET_ABTS_RCV; 94486c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 94586c67379SJames Smart 94686c67379SJames Smart lpfc_nvmeio_data(phba, 94786c67379SJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 94886c67379SJames Smart xri, smp_processor_id(), 0); 94986c67379SJames Smart 95086c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 95186c67379SJames Smart "6319 NVMET Rcv ABTS:acc xri x%x\n", xri); 95286c67379SJames Smart 95386c67379SJames Smart rsp = &ctxp->ctx.fcp_req; 95486c67379SJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, rsp); 95586c67379SJames Smart 95686c67379SJames Smart /* Respond with BA_ACC accordingly */ 95786c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 95886c67379SJames Smart return 0; 95986c67379SJames Smart } 96086c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 96186c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 96286c67379SJames Smart 96386c67379SJames Smart lpfc_nvmeio_data(phba, "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 96486c67379SJames Smart xri, smp_processor_id(), 1); 96586c67379SJames Smart 96686c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 96786c67379SJames Smart "6320 NVMET Rcv ABTS:rjt xri x%x\n", xri); 96886c67379SJames Smart 96986c67379SJames Smart /* Respond with BA_RJT accordingly */ 97086c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 0); 97186c67379SJames Smart #endif 972b06e13c3SJens Axboe return 0; 973318083adSJames Smart } 974318083adSJames Smart 975d613b6a7SJames Smart void 976d613b6a7SJames Smart lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 977d613b6a7SJames Smart { 9787d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 979d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 980d613b6a7SJames Smart 981d613b6a7SJames Smart if (phba->nvmet_support == 0) 982d613b6a7SJames Smart return; 983d613b6a7SJames Smart if (phba->targetport) { 984d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 985d613b6a7SJames Smart init_completion(&tgtp->tport_unreg_done); 986d613b6a7SJames Smart nvmet_fc_unregister_targetport(phba->targetport); 987d613b6a7SJames Smart wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); 988d613b6a7SJames Smart } 989d613b6a7SJames Smart phba->targetport = NULL; 990166d7211SJames Smart #endif 991d613b6a7SJames Smart } 992d613b6a7SJames Smart 993d613b6a7SJames Smart /** 994d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer - Process an unsolicited event data buffer 995d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 996d613b6a7SJames Smart * @pring: pointer to a SLI ring. 997d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 998d613b6a7SJames Smart * 999d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1000d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1001d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1002d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1003d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1004d613b6a7SJames Smart * of the discovery state machine. 1005d613b6a7SJames Smart **/ 1006d613b6a7SJames Smart static void 1007d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1008d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf) 1009d613b6a7SJames Smart { 10107d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1011d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1012d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 1013d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1014d613b6a7SJames Smart uint32_t *payload; 1015d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 1016d613b6a7SJames Smart 1017d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1018d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1019d613b6a7SJames Smart "6154 LS Drop IO\n"); 10202b65e182SJames Smart oxid = 0; 10212b65e182SJames Smart size = 0; 10222b65e182SJames Smart sid = 0; 1023547077a4SJames Smart ctxp = NULL; 1024d613b6a7SJames Smart goto dropit; 1025d613b6a7SJames Smart } 1026d613b6a7SJames Smart 1027d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1028d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1029d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1030d613b6a7SJames Smart size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); 1031d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1032d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1033d613b6a7SJames Smart 1034d613b6a7SJames Smart ctxp = kzalloc(sizeof(struct lpfc_nvmet_rcv_ctx), GFP_ATOMIC); 1035d613b6a7SJames Smart if (ctxp == NULL) { 1036d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1037d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1038d613b6a7SJames Smart "6155 LS Drop IO x%x: Alloc\n", 1039d613b6a7SJames Smart oxid); 1040d613b6a7SJames Smart dropit: 10412b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: " 10422b65e182SJames Smart "xri x%x sz %d from %06x\n", 10432b65e182SJames Smart oxid, size, sid); 1044d613b6a7SJames Smart if (nvmebuf) 1045d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1046d613b6a7SJames Smart return; 1047d613b6a7SJames Smart } 1048d613b6a7SJames Smart ctxp->phba = phba; 1049d613b6a7SJames Smart ctxp->size = size; 1050d613b6a7SJames Smart ctxp->oxid = oxid; 1051d613b6a7SJames Smart ctxp->sid = sid; 1052d613b6a7SJames Smart ctxp->wqeq = NULL; 1053d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 1054d613b6a7SJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 10552b65e182SJames Smart 10562b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RCV: xri x%x sz %d from %06x\n", 10572b65e182SJames Smart oxid, size, sid); 1058d613b6a7SJames Smart /* 1059d613b6a7SJames Smart * The calling sequence should be: 1060d613b6a7SJames Smart * nvmet_fc_rcv_ls_req -> lpfc_nvmet_xmt_ls_rsp/cmp ->_req->done 1061d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp should free the allocated ctxp. 1062d613b6a7SJames Smart */ 1063d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_in); 1064d613b6a7SJames Smart rc = nvmet_fc_rcv_ls_req(phba->targetport, &ctxp->ctx.ls_req, 1065d613b6a7SJames Smart payload, size); 1066d613b6a7SJames Smart 1067d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1068d613b6a7SJames Smart "6037 %s: ctx %p sz %d rc %d: %08x %08x %08x " 1069d613b6a7SJames Smart "%08x %08x %08x\n", __func__, ctxp, size, rc, 1070d613b6a7SJames Smart *payload, *(payload+1), *(payload+2), 1071d613b6a7SJames Smart *(payload+3), *(payload+4), *(payload+5)); 10722b65e182SJames Smart 1073d613b6a7SJames Smart if (rc == 0) { 1074d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_out); 1075d613b6a7SJames Smart return; 1076d613b6a7SJames Smart } 10772b65e182SJames Smart 10782b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: xri x%x sz %d from %06x\n", 10792b65e182SJames Smart oxid, size, sid); 10802b65e182SJames Smart 1081d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1082d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1083d613b6a7SJames Smart "6156 LS Drop IO x%x: nvmet_fc_rcv_ls_req %d\n", 1084d613b6a7SJames Smart ctxp->oxid, rc); 1085d613b6a7SJames Smart 1086d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 1087d613b6a7SJames Smart if (nvmebuf) 1088d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1089d613b6a7SJames Smart 1090d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_abort); 1091d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid); 1092166d7211SJames Smart #endif 1093d613b6a7SJames Smart } 1094d613b6a7SJames Smart 1095d613b6a7SJames Smart /** 1096d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer 1097d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1098d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1099d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 1100d613b6a7SJames Smart * 1101d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1102d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1103d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1104d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1105d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1106d613b6a7SJames Smart * of the discovery state machine. 1107d613b6a7SJames Smart **/ 1108d613b6a7SJames Smart static void 1109d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba, 1110d613b6a7SJames Smart struct lpfc_sli_ring *pring, 1111d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1112d613b6a7SJames Smart uint64_t isr_timestamp) 1113d613b6a7SJames Smart { 11147d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1115d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1116d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1117d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 1118d613b6a7SJames Smart uint32_t *payload; 1119d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 11202b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 11212b65e182SJames Smart uint32_t id; 11222b65e182SJames Smart #endif 1123d613b6a7SJames Smart 1124d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1125d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1126d613b6a7SJames Smart "6157 FCP Drop IO\n"); 11272b65e182SJames Smart oxid = 0; 11282b65e182SJames Smart size = 0; 11292b65e182SJames Smart sid = 0; 1130547077a4SJames Smart ctxp = NULL; 1131d613b6a7SJames Smart goto dropit; 1132d613b6a7SJames Smart } 1133d613b6a7SJames Smart 1134d613b6a7SJames Smart 1135d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1136d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1137d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1138d613b6a7SJames Smart size = nvmebuf->bytes_recv; 1139d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1140d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1141d613b6a7SJames Smart 1142d613b6a7SJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)nvmebuf->context; 1143d613b6a7SJames Smart if (ctxp == NULL) { 1144d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 1145d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1146d613b6a7SJames Smart "6158 FCP Drop IO x%x: Alloc\n", 1147d613b6a7SJames Smart oxid); 1148d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 1149d613b6a7SJames Smart /* Cannot send ABTS without context */ 1150d613b6a7SJames Smart return; 1151d613b6a7SJames Smart } 1152d613b6a7SJames Smart memset(ctxp, 0, sizeof(ctxp->ctx)); 1153d613b6a7SJames Smart ctxp->wqeq = NULL; 1154d613b6a7SJames Smart ctxp->txrdy = NULL; 1155d613b6a7SJames Smart ctxp->offset = 0; 1156d613b6a7SJames Smart ctxp->phba = phba; 1157d613b6a7SJames Smart ctxp->size = size; 1158d613b6a7SJames Smart ctxp->oxid = oxid; 1159d613b6a7SJames Smart ctxp->sid = sid; 1160d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 1161d613b6a7SJames Smart ctxp->rqb_buffer = nvmebuf; 1162d613b6a7SJames Smart ctxp->entry_cnt = 1; 1163d613b6a7SJames Smart ctxp->flag = 0; 11642b7824d0SJames Smart spin_lock_init(&ctxp->ctxlock); 1165d613b6a7SJames Smart 11662b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 11672b65e182SJames Smart if (phba->ktime_on) { 11682b65e182SJames Smart ctxp->ts_isr_cmd = isr_timestamp; 11692b65e182SJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 11702b65e182SJames Smart ctxp->ts_nvme_data = 0; 11712b65e182SJames Smart ctxp->ts_data_wqput = 0; 11722b65e182SJames Smart ctxp->ts_isr_data = 0; 11732b65e182SJames Smart ctxp->ts_data_nvme = 0; 11742b65e182SJames Smart ctxp->ts_nvme_status = 0; 11752b65e182SJames Smart ctxp->ts_status_wqput = 0; 11762b65e182SJames Smart ctxp->ts_isr_status = 0; 11772b65e182SJames Smart ctxp->ts_status_nvme = 0; 11782b65e182SJames Smart } 11792b65e182SJames Smart 11802b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV) { 11812b65e182SJames Smart id = smp_processor_id(); 11822b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 11832b65e182SJames Smart phba->cpucheck_rcv_io[id]++; 11842b65e182SJames Smart } 11852b65e182SJames Smart #endif 11862b65e182SJames Smart 11872b7824d0SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d CPU %02x\n", 11882b7824d0SJames Smart oxid, size, smp_processor_id()); 11892b65e182SJames Smart 1190d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 1191d613b6a7SJames Smart /* 1192d613b6a7SJames Smart * The calling sequence should be: 1193d613b6a7SJames Smart * nvmet_fc_rcv_fcp_req -> lpfc_nvmet_xmt_fcp_op/cmp -> req->done 1194d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 1195d613b6a7SJames Smart */ 1196d613b6a7SJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 1197d613b6a7SJames Smart payload, size); 1198d613b6a7SJames Smart 1199d613b6a7SJames Smart /* Process FCP command */ 1200d613b6a7SJames Smart if (rc == 0) { 1201d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 1202d613b6a7SJames Smart return; 1203d613b6a7SJames Smart } 1204d613b6a7SJames Smart 1205d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 1206d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1207547077a4SJames Smart "6159 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 1208547077a4SJames Smart ctxp->oxid, rc, 1209547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 1210547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 1211547077a4SJames Smart atomic_read(&tgtp->xmt_fcp_release)); 1212d613b6a7SJames Smart dropit: 12132b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 12142b65e182SJames Smart oxid, size, sid); 1215d613b6a7SJames Smart if (oxid) { 1216d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 1217d613b6a7SJames Smart return; 1218d613b6a7SJames Smart } 1219d613b6a7SJames Smart 1220d613b6a7SJames Smart if (nvmebuf) { 1221d613b6a7SJames Smart nvmebuf->iocbq->hba_wqidx = 0; 1222d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 1223547077a4SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &nvmebuf->hbuf); 1224d613b6a7SJames Smart } 1225166d7211SJames Smart #endif 1226d613b6a7SJames Smart } 1227d613b6a7SJames Smart 1228d613b6a7SJames Smart /** 1229d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_event - Process an unsolicited event from an nvme nport 1230d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1231d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1232d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1233d613b6a7SJames Smart * 1234d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1235d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1236d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1237d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer() after properly set up the buffer from the 1238d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1239d613b6a7SJames Smart **/ 1240d613b6a7SJames Smart void 1241d613b6a7SJames Smart lpfc_nvmet_unsol_ls_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1242d613b6a7SJames Smart struct lpfc_iocbq *piocb) 1243d613b6a7SJames Smart { 1244d613b6a7SJames Smart struct lpfc_dmabuf *d_buf; 1245d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf; 1246d613b6a7SJames Smart 1247d613b6a7SJames Smart d_buf = piocb->context2; 1248d613b6a7SJames Smart nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); 1249d613b6a7SJames Smart 1250d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1251d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1252d613b6a7SJames Smart return; 1253d613b6a7SJames Smart } 1254d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(phba, pring, nvmebuf); 1255d613b6a7SJames Smart } 1256d613b6a7SJames Smart 1257d613b6a7SJames Smart /** 1258d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport 1259d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1260d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1261d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1262d613b6a7SJames Smart * 1263d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1264d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1265d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1266d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the 1267d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1268d613b6a7SJames Smart **/ 1269d613b6a7SJames Smart void 1270d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba, 1271d613b6a7SJames Smart struct lpfc_sli_ring *pring, 1272d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1273d613b6a7SJames Smart uint64_t isr_timestamp) 1274d613b6a7SJames Smart { 1275d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1276d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 1277d613b6a7SJames Smart return; 1278d613b6a7SJames Smart } 1279d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(phba, pring, nvmebuf, 1280d613b6a7SJames Smart isr_timestamp); 1281d613b6a7SJames Smart } 1282d613b6a7SJames Smart 1283d613b6a7SJames Smart /** 1284d613b6a7SJames Smart * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure 1285d613b6a7SJames Smart * @phba: pointer to a host N_Port data structure. 1286d613b6a7SJames Smart * @ctxp: Context info for NVME LS Request 1287d613b6a7SJames Smart * @rspbuf: DMA buffer of NVME command. 1288d613b6a7SJames Smart * @rspsize: size of the NVME command. 1289d613b6a7SJames Smart * 1290d613b6a7SJames Smart * This routine is used for allocating a lpfc-WQE data structure from 1291d613b6a7SJames Smart * the driver lpfc-WQE free-list and prepare the WQE with the parameters 1292d613b6a7SJames Smart * passed into the routine for discovery state machine to issue an Extended 1293d613b6a7SJames Smart * Link Service (NVME) commands. It is a generic lpfc-WQE allocation 1294d613b6a7SJames Smart * and preparation routine that is used by all the discovery state machine 1295d613b6a7SJames Smart * routines and the NVME command-specific fields will be later set up by 1296d613b6a7SJames Smart * the individual discovery machine routines after calling this routine 1297d613b6a7SJames Smart * allocating and preparing a generic WQE data structure. It fills in the 1298d613b6a7SJames Smart * Buffer Descriptor Entries (BDEs), allocates buffers for both command 1299d613b6a7SJames Smart * payload and response payload (if expected). The reference count on the 1300d613b6a7SJames Smart * ndlp is incremented by 1 and the reference to the ndlp is put into 1301d613b6a7SJames Smart * context1 of the WQE data structure for this WQE to hold the ndlp 1302d613b6a7SJames Smart * reference for the command's callback function to access later. 1303d613b6a7SJames Smart * 1304d613b6a7SJames Smart * Return code 1305d613b6a7SJames Smart * Pointer to the newly allocated/prepared nvme wqe data structure 1306d613b6a7SJames Smart * NULL - when nvme wqe data structure allocation/preparation failed 1307d613b6a7SJames Smart **/ 1308d613b6a7SJames Smart static struct lpfc_iocbq * 1309d613b6a7SJames Smart lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba, 1310d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1311d613b6a7SJames Smart dma_addr_t rspbuf, uint16_t rspsize) 1312d613b6a7SJames Smart { 1313d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1314d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1315d613b6a7SJames Smart union lpfc_wqe *wqe; 1316d613b6a7SJames Smart 1317d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1318d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1319d613b6a7SJames Smart "6104 lpfc_nvmet_prep_ls_wqe: link err: " 1320d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1321d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1322d613b6a7SJames Smart return NULL; 1323d613b6a7SJames Smart } 1324d613b6a7SJames Smart 1325d613b6a7SJames Smart /* Allocate buffer for command wqe */ 1326d613b6a7SJames Smart nvmewqe = lpfc_sli_get_iocbq(phba); 1327d613b6a7SJames Smart if (nvmewqe == NULL) { 1328d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1329d613b6a7SJames Smart "6105 lpfc_nvmet_prep_ls_wqe: No WQE: " 1330d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1331d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1332d613b6a7SJames Smart return NULL; 1333d613b6a7SJames Smart } 1334d613b6a7SJames Smart 1335d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1336d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1337d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1338d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1339d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1340d613b6a7SJames Smart "6106 lpfc_nvmet_prep_ls_wqe: No ndlp: " 1341d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1342d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1343d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1344d613b6a7SJames Smart } 1345d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1346d613b6a7SJames Smart 1347d613b6a7SJames Smart /* prevent preparing wqe with NULL ndlp reference */ 1348d613b6a7SJames Smart nvmewqe->context1 = lpfc_nlp_get(ndlp); 1349d613b6a7SJames Smart if (nvmewqe->context1 == NULL) 1350d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1351d613b6a7SJames Smart nvmewqe->context2 = ctxp; 1352d613b6a7SJames Smart 1353d613b6a7SJames Smart wqe = &nvmewqe->wqe; 1354d613b6a7SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 1355d613b6a7SJames Smart 1356d613b6a7SJames Smart /* Words 0 - 2 */ 1357d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1358d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize; 1359d613b6a7SJames Smart wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf)); 1360d613b6a7SJames Smart wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf)); 1361d613b6a7SJames Smart 1362d613b6a7SJames Smart /* Word 3 */ 1363d613b6a7SJames Smart 1364d613b6a7SJames Smart /* Word 4 */ 1365d613b6a7SJames Smart 1366d613b6a7SJames Smart /* Word 5 */ 1367d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 1368d613b6a7SJames Smart bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 1369d613b6a7SJames Smart bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 13708b361639SJames Smart bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP); 1371d613b6a7SJames Smart bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 1372d613b6a7SJames Smart 1373d613b6a7SJames Smart /* Word 6 */ 1374d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, 1375d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1376d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag); 1377d613b6a7SJames Smart 1378d613b6a7SJames Smart /* Word 7 */ 1379d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com, 1380d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 1381d613b6a7SJames Smart bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI); 1382d613b6a7SJames Smart bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3); 1383d613b6a7SJames Smart bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); 1384d613b6a7SJames Smart 1385d613b6a7SJames Smart /* Word 8 */ 1386d613b6a7SJames Smart wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag; 1387d613b6a7SJames Smart 1388d613b6a7SJames Smart /* Word 9 */ 1389d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag); 1390d613b6a7SJames Smart /* Needs to be set by caller */ 1391d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid); 1392d613b6a7SJames Smart 1393d613b6a7SJames Smart /* Word 10 */ 1394d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); 1395d613b6a7SJames Smart bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 1396d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, 1397d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1398d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); 1399d613b6a7SJames Smart 1400d613b6a7SJames Smart /* Word 11 */ 1401d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com, 1402d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1403d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com, 1404d613b6a7SJames Smart OTHER_COMMAND); 1405d613b6a7SJames Smart 1406d613b6a7SJames Smart /* Word 12 */ 1407d613b6a7SJames Smart wqe->xmit_sequence.xmit_len = rspsize; 1408d613b6a7SJames Smart 1409d613b6a7SJames Smart nvmewqe->retry = 1; 1410d613b6a7SJames Smart nvmewqe->vport = phba->pport; 1411d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 1412d613b6a7SJames Smart nvmewqe->iocb_flag |= LPFC_IO_NVME_LS; 1413d613b6a7SJames Smart 1414d613b6a7SJames Smart /* Xmit NVME response to remote NPORT <did> */ 1415d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1416d613b6a7SJames Smart "6039 Xmit NVME LS response to remote " 1417d613b6a7SJames Smart "NPORT x%x iotag:x%x oxid:x%x size:x%x\n", 1418d613b6a7SJames Smart ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid, 1419d613b6a7SJames Smart rspsize); 1420d613b6a7SJames Smart return nvmewqe; 1421d613b6a7SJames Smart 1422d613b6a7SJames Smart nvme_wqe_free_wqeq_exit: 1423d613b6a7SJames Smart nvmewqe->context2 = NULL; 1424d613b6a7SJames Smart nvmewqe->context3 = NULL; 1425d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, nvmewqe); 1426d613b6a7SJames Smart return NULL; 1427d613b6a7SJames Smart } 1428d613b6a7SJames Smart 1429d613b6a7SJames Smart 1430d613b6a7SJames Smart static struct lpfc_iocbq * 1431d613b6a7SJames Smart lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba, 1432d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 1433d613b6a7SJames Smart { 1434d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp = &ctxp->ctx.fcp_req; 1435d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1436d613b6a7SJames Smart struct sli4_sge *sgl; 1437d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1438d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1439d613b6a7SJames Smart struct scatterlist *sgel; 1440d613b6a7SJames Smart union lpfc_wqe128 *wqe; 1441d613b6a7SJames Smart uint32_t *txrdy; 1442d613b6a7SJames Smart dma_addr_t physaddr; 1443d613b6a7SJames Smart int i, cnt; 1444d613b6a7SJames Smart int xc = 1; 1445d613b6a7SJames Smart 1446d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1447d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1448d613b6a7SJames Smart "6107 lpfc_nvmet_prep_fcp_wqe: link err:" 1449d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", ctxp->sid, 1450d613b6a7SJames Smart ctxp->oxid); 1451d613b6a7SJames Smart return NULL; 1452d613b6a7SJames Smart } 1453d613b6a7SJames Smart 1454d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1455d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1456d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1457d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1458d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1459d613b6a7SJames Smart "6108 lpfc_nvmet_prep_fcp_wqe: no ndlp: " 1460d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1461d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1462d613b6a7SJames Smart return NULL; 1463d613b6a7SJames Smart } 1464d613b6a7SJames Smart 14654d4c4a4aSJames Smart if (rsp->sg_cnt > phba->cfg_nvme_seg_cnt) { 1466d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1467d613b6a7SJames Smart "6109 lpfc_nvmet_prep_fcp_wqe: seg cnt err: " 14684d4c4a4aSJames Smart "NPORT x%x oxid:x%x cnt %d\n", 14694d4c4a4aSJames Smart ctxp->sid, ctxp->oxid, phba->cfg_nvme_seg_cnt); 1470d613b6a7SJames Smart return NULL; 1471d613b6a7SJames Smart } 1472d613b6a7SJames Smart 1473d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1474d613b6a7SJames Smart nvmewqe = ctxp->wqeq; 1475d613b6a7SJames Smart if (nvmewqe == NULL) { 1476d613b6a7SJames Smart /* Allocate buffer for command wqe */ 1477d613b6a7SJames Smart nvmewqe = ctxp->rqb_buffer->iocbq; 1478d613b6a7SJames Smart if (nvmewqe == NULL) { 1479d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1480d613b6a7SJames Smart "6110 lpfc_nvmet_prep_fcp_wqe: No " 1481d613b6a7SJames Smart "WQE: NPORT x%x oxid:x%x\n", 1482d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1483d613b6a7SJames Smart return NULL; 1484d613b6a7SJames Smart } 1485d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1486d613b6a7SJames Smart xc = 0; /* create new XRI */ 1487d613b6a7SJames Smart nvmewqe->sli4_lxritag = NO_XRI; 1488d613b6a7SJames Smart nvmewqe->sli4_xritag = NO_XRI; 1489d613b6a7SJames Smart } 1490d613b6a7SJames Smart 1491d613b6a7SJames Smart /* Sanity check */ 1492d613b6a7SJames Smart if (((ctxp->state == LPFC_NVMET_STE_RCV) && 1493d613b6a7SJames Smart (ctxp->entry_cnt == 1)) || 1494d613b6a7SJames Smart ((ctxp->state == LPFC_NVMET_STE_DATA) && 1495d613b6a7SJames Smart (ctxp->entry_cnt > 1))) { 1496d613b6a7SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 1497d613b6a7SJames Smart } else { 1498d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1499d613b6a7SJames Smart "6111 Wrong state %s: %d cnt %d\n", 1500d613b6a7SJames Smart __func__, ctxp->state, ctxp->entry_cnt); 1501d613b6a7SJames Smart return NULL; 1502d613b6a7SJames Smart } 1503d613b6a7SJames Smart 1504d613b6a7SJames Smart sgl = (struct sli4_sge *)ctxp->rqb_buffer->sglq->sgl; 1505d613b6a7SJames Smart switch (rsp->op) { 1506d613b6a7SJames Smart case NVMET_FCOP_READDATA: 1507d613b6a7SJames Smart case NVMET_FCOP_READDATA_RSP: 1508d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 1509d613b6a7SJames Smart sgel = &rsp->sg[0]; 1510d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 1511d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1512d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel); 1513d613b6a7SJames Smart wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr)); 1514d613b6a7SJames Smart wqe->fcp_tsend.bde.addrHigh = 1515d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1516d613b6a7SJames Smart 1517d613b6a7SJames Smart /* Word 3 */ 1518d613b6a7SJames Smart wqe->fcp_tsend.payload_offset_len = 0; 1519d613b6a7SJames Smart 1520d613b6a7SJames Smart /* Word 4 */ 1521d613b6a7SJames Smart wqe->fcp_tsend.relative_offset = ctxp->offset; 1522d613b6a7SJames Smart 1523d613b6a7SJames Smart /* Word 5 */ 1524d613b6a7SJames Smart 1525d613b6a7SJames Smart /* Word 6 */ 1526d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com, 1527d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1528d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com, 1529d613b6a7SJames Smart nvmewqe->sli4_xritag); 1530d613b6a7SJames Smart 1531d613b6a7SJames Smart /* Word 7 */ 1532d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE); 1533d613b6a7SJames Smart 1534d613b6a7SJames Smart /* Word 8 */ 1535d613b6a7SJames Smart wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag; 1536d613b6a7SJames Smart 1537d613b6a7SJames Smart /* Word 9 */ 1538d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag); 1539d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid); 1540d613b6a7SJames Smart 1541d613b6a7SJames Smart /* Word 10 */ 1542d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 1543d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1); 1544d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE); 1545d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com, 1546d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1547d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->fcp_tsend.wqe_com, 0); 1548d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, xc); 1549d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 1550d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1551d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_tsend.wqe_com, 1); 1552d613b6a7SJames Smart 1553d613b6a7SJames Smart /* Word 11 */ 1554d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com, 1555d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1556d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com, 1557d613b6a7SJames Smart FCP_COMMAND_TSEND); 1558d613b6a7SJames Smart 1559d613b6a7SJames Smart /* Word 12 */ 1560d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 1561d613b6a7SJames Smart 1562d613b6a7SJames Smart /* Setup 2 SKIP SGEs */ 1563d613b6a7SJames Smart sgl->addr_hi = 0; 1564d613b6a7SJames Smart sgl->addr_lo = 0; 1565d613b6a7SJames Smart sgl->word2 = 0; 1566d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1567d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1568d613b6a7SJames Smart sgl->sge_len = 0; 1569d613b6a7SJames Smart sgl++; 1570d613b6a7SJames Smart sgl->addr_hi = 0; 1571d613b6a7SJames Smart sgl->addr_lo = 0; 1572d613b6a7SJames Smart sgl->word2 = 0; 1573d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1574d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1575d613b6a7SJames Smart sgl->sge_len = 0; 1576d613b6a7SJames Smart sgl++; 1577d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 1578d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read_rsp); 1579d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1); 1580d613b6a7SJames Smart if ((ndlp->nlp_flag & NLP_SUPPRESS_RSP) && 1581d613b6a7SJames Smart (rsp->rsplen == 12)) { 1582d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 1); 1583d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 1584d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 1585d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 1586d613b6a7SJames Smart } else { 1587d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1588d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1); 1589d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1); 1590d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 1591d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 1592d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, 1593d613b6a7SJames Smart rsp->rsplen); 1594d613b6a7SJames Smart } 1595d613b6a7SJames Smart } else { 1596d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read); 1597d613b6a7SJames Smart 1598d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1599d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 1600d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 1601d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0); 1602d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 1603d613b6a7SJames Smart } 1604d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 1605d613b6a7SJames Smart break; 1606d613b6a7SJames Smart 1607d613b6a7SJames Smart case NVMET_FCOP_WRITEDATA: 1608d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 1609d613b6a7SJames Smart txrdy = pci_pool_alloc(phba->txrdy_payload_pool, 1610d613b6a7SJames Smart GFP_KERNEL, &physaddr); 1611d613b6a7SJames Smart if (!txrdy) { 1612d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1613d613b6a7SJames Smart "6041 Bad txrdy buffer: oxid x%x\n", 1614d613b6a7SJames Smart ctxp->oxid); 1615d613b6a7SJames Smart return NULL; 1616d613b6a7SJames Smart } 1617d613b6a7SJames Smart ctxp->txrdy = txrdy; 1618d613b6a7SJames Smart ctxp->txrdy_phys = physaddr; 1619d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1620d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeSize = TXRDY_PAYLOAD_LEN; 1621d613b6a7SJames Smart wqe->fcp_treceive.bde.addrLow = 1622d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 1623d613b6a7SJames Smart wqe->fcp_treceive.bde.addrHigh = 1624d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1625d613b6a7SJames Smart 1626d613b6a7SJames Smart /* Word 3 */ 1627d613b6a7SJames Smart wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN; 1628d613b6a7SJames Smart 1629d613b6a7SJames Smart /* Word 4 */ 1630d613b6a7SJames Smart wqe->fcp_treceive.relative_offset = ctxp->offset; 1631d613b6a7SJames Smart 1632d613b6a7SJames Smart /* Word 5 */ 1633d613b6a7SJames Smart 1634d613b6a7SJames Smart /* Word 6 */ 1635d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com, 1636d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1637d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com, 1638d613b6a7SJames Smart nvmewqe->sli4_xritag); 1639d613b6a7SJames Smart 1640d613b6a7SJames Smart /* Word 7 */ 1641d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0); 1642d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com, 1643d613b6a7SJames Smart CMD_FCP_TRECEIVE64_WQE); 1644d613b6a7SJames Smart 1645d613b6a7SJames Smart /* Word 8 */ 1646d613b6a7SJames Smart wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag; 1647d613b6a7SJames Smart 1648d613b6a7SJames Smart /* Word 9 */ 1649d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag); 1650d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid); 1651d613b6a7SJames Smart 1652d613b6a7SJames Smart /* Word 10 */ 1653d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 1654d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1); 1655d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ); 1656d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com, 1657d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1658d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, xc); 1659d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0); 1660d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0); 1661d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0); 1662d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 1663d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1664d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_treceive.wqe_com, 1); 1665d613b6a7SJames Smart 1666d613b6a7SJames Smart /* Word 11 */ 1667d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com, 1668d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1669d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com, 1670d613b6a7SJames Smart FCP_COMMAND_TRECEIVE); 1671d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1672d613b6a7SJames Smart 1673d613b6a7SJames Smart /* Word 12 */ 1674d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 1675d613b6a7SJames Smart 1676d613b6a7SJames Smart /* Setup 1 TXRDY and 1 SKIP SGE */ 1677d613b6a7SJames Smart txrdy[0] = 0; 1678d613b6a7SJames Smart txrdy[1] = cpu_to_be32(rsp->transfer_length); 1679d613b6a7SJames Smart txrdy[2] = 0; 1680d613b6a7SJames Smart 1681d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 1682d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 1683d613b6a7SJames Smart sgl->word2 = 0; 1684d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 1685d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1686d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(TXRDY_PAYLOAD_LEN); 1687d613b6a7SJames Smart sgl++; 1688d613b6a7SJames Smart sgl->addr_hi = 0; 1689d613b6a7SJames Smart sgl->addr_lo = 0; 1690d613b6a7SJames Smart sgl->word2 = 0; 1691d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1692d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1693d613b6a7SJames Smart sgl->sge_len = 0; 1694d613b6a7SJames Smart sgl++; 1695d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 1696d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_write); 1697d613b6a7SJames Smart break; 1698d613b6a7SJames Smart 1699d613b6a7SJames Smart case NVMET_FCOP_RSP: 1700d613b6a7SJames Smart /* Words 0 - 2 */ 1701d613b6a7SJames Smart physaddr = rsp->rspdma; 1702d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1703d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 1704d613b6a7SJames Smart wqe->fcp_trsp.bde.addrLow = 1705d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 1706d613b6a7SJames Smart wqe->fcp_trsp.bde.addrHigh = 1707d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1708d613b6a7SJames Smart 1709d613b6a7SJames Smart /* Word 3 */ 1710d613b6a7SJames Smart wqe->fcp_trsp.response_len = rsp->rsplen; 1711d613b6a7SJames Smart 1712d613b6a7SJames Smart /* Word 4 */ 1713d613b6a7SJames Smart wqe->fcp_trsp.rsvd_4_5[0] = 0; 1714d613b6a7SJames Smart 1715d613b6a7SJames Smart 1716d613b6a7SJames Smart /* Word 5 */ 1717d613b6a7SJames Smart 1718d613b6a7SJames Smart /* Word 6 */ 1719d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com, 1720d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1721d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com, 1722d613b6a7SJames Smart nvmewqe->sli4_xritag); 1723d613b6a7SJames Smart 1724d613b6a7SJames Smart /* Word 7 */ 1725d613b6a7SJames Smart bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1); 1726d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE); 1727d613b6a7SJames Smart 1728d613b6a7SJames Smart /* Word 8 */ 1729d613b6a7SJames Smart wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag; 1730d613b6a7SJames Smart 1731d613b6a7SJames Smart /* Word 9 */ 1732d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag); 1733d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid); 1734d613b6a7SJames Smart 1735d613b6a7SJames Smart /* Word 10 */ 1736d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 1737d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 0); 1738d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_WRITE); 1739d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com, 1740d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD3); 1741d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, xc); 1742d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 1743d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1744d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_trsp.wqe_com, 1); 1745d613b6a7SJames Smart 1746d613b6a7SJames Smart /* Word 11 */ 1747d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com, 1748d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1749d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com, 1750d613b6a7SJames Smart FCP_COMMAND_TRSP); 1751d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1752d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RSP; 1753d613b6a7SJames Smart 1754d613b6a7SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 1755d613b6a7SJames Smart /* Good response - all zero's on wire */ 1756d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0); 1757d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0); 1758d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0); 1759d613b6a7SJames Smart } else { 1760d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1); 1761d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1); 1762d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 1763d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 1764d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen); 1765d613b6a7SJames Smart } 1766d613b6a7SJames Smart 1767d613b6a7SJames Smart /* Use rspbuf, NOT sg list */ 1768d613b6a7SJames Smart rsp->sg_cnt = 0; 1769d613b6a7SJames Smart sgl->word2 = 0; 1770d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp); 1771d613b6a7SJames Smart break; 1772d613b6a7SJames Smart 1773d613b6a7SJames Smart default: 1774d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 1775d613b6a7SJames Smart "6064 Unknown Rsp Op %d\n", 1776d613b6a7SJames Smart rsp->op); 1777d613b6a7SJames Smart return NULL; 1778d613b6a7SJames Smart } 1779d613b6a7SJames Smart 1780d613b6a7SJames Smart nvmewqe->retry = 1; 1781d613b6a7SJames Smart nvmewqe->vport = phba->pport; 1782d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 1783d613b6a7SJames Smart nvmewqe->context1 = ndlp; 1784d613b6a7SJames Smart 1785d613b6a7SJames Smart for (i = 0; i < rsp->sg_cnt; i++) { 1786d613b6a7SJames Smart sgel = &rsp->sg[i]; 1787d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 1788d613b6a7SJames Smart cnt = sg_dma_len(sgel); 1789d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 1790d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 1791d613b6a7SJames Smart sgl->word2 = 0; 1792d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 1793d613b6a7SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset); 1794d613b6a7SJames Smart if ((i+1) == rsp->sg_cnt) 1795d613b6a7SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1796d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1797d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(cnt); 1798d613b6a7SJames Smart sgl++; 1799d613b6a7SJames Smart ctxp->offset += cnt; 1800d613b6a7SJames Smart } 1801d613b6a7SJames Smart return nvmewqe; 1802d613b6a7SJames Smart } 1803d613b6a7SJames Smart 1804d613b6a7SJames Smart /** 1805d613b6a7SJames Smart * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS 1806d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1807d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1808d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1809d613b6a7SJames Smart * 1810d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1811d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 1812d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1813d613b6a7SJames Smart **/ 1814d613b6a7SJames Smart static void 1815d613b6a7SJames Smart lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1816d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1817d613b6a7SJames Smart { 1818d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1819d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1820d613b6a7SJames Smart uint32_t status, result; 182119b58d94SJames Smart unsigned long flags; 182219b58d94SJames Smart bool released = false; 1823d613b6a7SJames Smart 1824d613b6a7SJames Smart ctxp = cmdwqe->context2; 1825d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1826d613b6a7SJames Smart result = wcqe->parameter; 1827d613b6a7SJames Smart 1828d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1829547077a4SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 1830547077a4SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 1831d613b6a7SJames Smart 1832d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 183386c67379SJames Smart 183486c67379SJames Smart /* Check if we already received a free context call 183586c67379SJames Smart * and we have completed processing an abort situation. 183686c67379SJames Smart */ 183719b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 183886c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 183986c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 184086c67379SJames Smart list_del(&ctxp->list); 184119b58d94SJames Smart released = true; 184286c67379SJames Smart } 184319b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 184419b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 1845547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 184619b58d94SJames Smart 184786c67379SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 184886c67379SJames Smart "6165 ABORT cmpl: xri x%x flg x%x (%d) " 184986c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 185086c67379SJames Smart ctxp->oxid, ctxp->flag, released, 185186c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 185286c67379SJames Smart result, wcqe->word3); 185386c67379SJames Smart 185419b58d94SJames Smart /* 185519b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 185619b58d94SJames Smart * will be recycled by transport release call. 185719b58d94SJames Smart */ 185819b58d94SJames Smart if (released) 1859d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 1860d613b6a7SJames Smart 1861d613b6a7SJames Smart cmdwqe->context2 = NULL; 1862d613b6a7SJames Smart cmdwqe->context3 = NULL; 1863d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 186486c67379SJames Smart 186586c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 186686c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 186786c67379SJames Smart * should have been called already. 186886c67379SJames Smart */ 1869d613b6a7SJames Smart } 1870d613b6a7SJames Smart 1871d613b6a7SJames Smart /** 187286c67379SJames Smart * lpfc_nvmet_unsol_fcp_abort_cmp - Completion handler for ABTS 1873d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1874d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1875d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1876d613b6a7SJames Smart * 1877d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1878d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 1879d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1880d613b6a7SJames Smart **/ 1881d613b6a7SJames Smart static void 188286c67379SJames Smart lpfc_nvmet_unsol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1883d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1884d613b6a7SJames Smart { 1885d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1886d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 188719b58d94SJames Smart unsigned long flags; 1888d613b6a7SJames Smart uint32_t status, result; 188919b58d94SJames Smart bool released = false; 1890d613b6a7SJames Smart 1891d613b6a7SJames Smart ctxp = cmdwqe->context2; 1892d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1893d613b6a7SJames Smart result = wcqe->parameter; 1894d613b6a7SJames Smart 1895d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1896547077a4SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 1897547077a4SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 1898d613b6a7SJames Smart 189986c67379SJames Smart if (!ctxp) { 190086c67379SJames Smart /* if context is clear, related io alrady complete */ 1901d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 190286c67379SJames Smart "6070 ABTS cmpl: WCQE: %08x %08x %08x %08x\n", 190386c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 1904d613b6a7SJames Smart result, wcqe->word3); 190586c67379SJames Smart return; 190686c67379SJames Smart } 1907d613b6a7SJames Smart 1908d613b6a7SJames Smart /* Sanity check */ 1909d613b6a7SJames Smart if (ctxp->state != LPFC_NVMET_STE_ABORT) { 1910d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 191186c67379SJames Smart "6112 ABTS Wrong state:%d oxid x%x\n", 1912d613b6a7SJames Smart ctxp->state, ctxp->oxid); 1913d613b6a7SJames Smart } 191486c67379SJames Smart 191586c67379SJames Smart /* Check if we already received a free context call 191686c67379SJames Smart * and we have completed processing an abort situation. 191786c67379SJames Smart */ 1918d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 191919b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 192086c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 192186c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 192286c67379SJames Smart list_del(&ctxp->list); 192319b58d94SJames Smart released = true; 192486c67379SJames Smart } 192519b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 192619b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 1927547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 192819b58d94SJames Smart 192986c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 193086c67379SJames Smart "6316 ABTS cmpl xri x%x flg x%x (%x) " 193186c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 193286c67379SJames Smart ctxp->oxid, ctxp->flag, released, 193386c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 193486c67379SJames Smart result, wcqe->word3); 193519b58d94SJames Smart /* 193619b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 193719b58d94SJames Smart * will be recycled by transport release call. 193819b58d94SJames Smart */ 193919b58d94SJames Smart if (released) 1940d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 194119b58d94SJames Smart 1942d613b6a7SJames Smart cmdwqe->context2 = NULL; 1943d613b6a7SJames Smart cmdwqe->context3 = NULL; 194486c67379SJames Smart 194586c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 194686c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 194786c67379SJames Smart * should have been called already. 194886c67379SJames Smart */ 1949d613b6a7SJames Smart } 1950d613b6a7SJames Smart 1951d613b6a7SJames Smart /** 1952d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS 1953d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1954d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1955d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1956d613b6a7SJames Smart * 1957d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1958d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for LS cmds 1959d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1960d613b6a7SJames Smart **/ 1961d613b6a7SJames Smart static void 1962d613b6a7SJames Smart lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1963d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1964d613b6a7SJames Smart { 1965d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1966d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1967d613b6a7SJames Smart uint32_t status, result; 1968d613b6a7SJames Smart 1969d613b6a7SJames Smart ctxp = cmdwqe->context2; 1970d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1971d613b6a7SJames Smart result = wcqe->parameter; 1972d613b6a7SJames Smart 1973d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1974547077a4SJames Smart atomic_inc(&tgtp->xmt_ls_abort_cmpl); 1975d613b6a7SJames Smart 1976d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1977d613b6a7SJames Smart "6083 Abort cmpl: ctx %p WCQE: %08x %08x %08x %08x\n", 1978d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 1979d613b6a7SJames Smart result, wcqe->word3); 1980d613b6a7SJames Smart 1981d613b6a7SJames Smart if (ctxp) { 1982d613b6a7SJames Smart cmdwqe->context2 = NULL; 1983d613b6a7SJames Smart cmdwqe->context3 = NULL; 1984d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 1985d613b6a7SJames Smart kfree(ctxp); 1986d613b6a7SJames Smart } else 1987d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 1988d613b6a7SJames Smart } 1989d613b6a7SJames Smart 1990d613b6a7SJames Smart static int 1991d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba, 1992d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1993d613b6a7SJames Smart uint32_t sid, uint16_t xri) 1994d613b6a7SJames Smart { 1995d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1996d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 1997d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 1998d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1999d613b6a7SJames Smart 2000d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 200186c67379SJames Smart "6067 ABTS: sid %x xri x%x/x%x\n", 2002318083adSJames Smart sid, xri, ctxp->wqeq->sli4_xritag); 2003d613b6a7SJames Smart 2004d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 200586c67379SJames Smart if (!ctxp->wqeq) { 200686c67379SJames Smart ctxp->wqeq = ctxp->rqb_buffer->iocbq; 200786c67379SJames Smart ctxp->wqeq->hba_wqidx = 0; 200886c67379SJames Smart } 2009d613b6a7SJames Smart 2010d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2011d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2012d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2013d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2014d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2015d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 2016d613b6a7SJames Smart "6134 Drop ABTS - wrong NDLP state x%x.\n", 2017b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2018d613b6a7SJames Smart 2019d613b6a7SJames Smart /* No failure to an ABTS request. */ 2020d613b6a7SJames Smart return 0; 2021d613b6a7SJames Smart } 2022d613b6a7SJames Smart 2023d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 2024d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 2025d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 2026d613b6a7SJames Smart 2027d613b6a7SJames Smart /* 2028d613b6a7SJames Smart * Since we zero the whole WQE, we need to ensure we set the WQE fields 2029d613b6a7SJames Smart * that were initialized in lpfc_sli4_nvmet_alloc. 2030d613b6a7SJames Smart */ 2031d613b6a7SJames Smart memset(wqe_abts, 0, sizeof(union lpfc_wqe)); 2032d613b6a7SJames Smart 2033d613b6a7SJames Smart /* Word 5 */ 2034d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0); 2035d613b6a7SJames Smart bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1); 2036d613b6a7SJames Smart bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0); 2037d613b6a7SJames Smart bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS); 2038d613b6a7SJames Smart bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS); 2039d613b6a7SJames Smart 2040d613b6a7SJames Smart /* Word 6 */ 2041d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com, 2042d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2043d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com, 2044d613b6a7SJames Smart abts_wqeq->sli4_xritag); 2045d613b6a7SJames Smart 2046d613b6a7SJames Smart /* Word 7 */ 2047d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com, 2048d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 2049d613b6a7SJames Smart bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI); 2050d613b6a7SJames Smart bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3); 2051d613b6a7SJames Smart bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0); 2052d613b6a7SJames Smart 2053d613b6a7SJames Smart /* Word 8 */ 2054d613b6a7SJames Smart wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag; 2055d613b6a7SJames Smart 2056d613b6a7SJames Smart /* Word 9 */ 2057d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag); 2058d613b6a7SJames Smart /* Needs to be set by caller */ 2059d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri); 2060d613b6a7SJames Smart 2061d613b6a7SJames Smart /* Word 10 */ 2062d613b6a7SJames Smart bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1); 2063d613b6a7SJames Smart bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 2064d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com, 2065d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2066d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0); 2067d613b6a7SJames Smart bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0); 2068d613b6a7SJames Smart 2069d613b6a7SJames Smart /* Word 11 */ 2070d613b6a7SJames Smart bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com, 2071d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2072d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com, 2073d613b6a7SJames Smart OTHER_COMMAND); 2074d613b6a7SJames Smart 2075d613b6a7SJames Smart abts_wqeq->vport = phba->pport; 2076d613b6a7SJames Smart abts_wqeq->context1 = ndlp; 2077d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 2078d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2079d613b6a7SJames Smart abts_wqeq->rsvd2 = 0; 2080d613b6a7SJames Smart /* hba_wqidx should already be setup from command we are aborting */ 2081d613b6a7SJames Smart abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR; 2082d613b6a7SJames Smart abts_wqeq->iocb.ulpLe = 1; 2083d613b6a7SJames Smart 2084d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2085d613b6a7SJames Smart "6069 Issue ABTS to xri x%x reqtag x%x\n", 2086d613b6a7SJames Smart xri, abts_wqeq->iotag); 2087d613b6a7SJames Smart return 1; 2088d613b6a7SJames Smart } 2089d613b6a7SJames Smart 2090d613b6a7SJames Smart static int 2091d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba, 2092d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2093d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2094d613b6a7SJames Smart { 2095d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2096d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2097d613b6a7SJames Smart union lpfc_wqe *abts_wqe; 2098d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2099d613b6a7SJames Smart unsigned long flags; 2100d613b6a7SJames Smart int rc; 2101d613b6a7SJames Smart 2102d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2103d613b6a7SJames Smart if (!ctxp->wqeq) { 2104d613b6a7SJames Smart ctxp->wqeq = ctxp->rqb_buffer->iocbq; 2105d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2106d613b6a7SJames Smart } 2107d613b6a7SJames Smart 2108d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2109d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2110d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2111d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2112d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2113d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 211486c67379SJames Smart "6160 Drop ABORT - wrong NDLP state x%x.\n", 2115b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2116d613b6a7SJames Smart 2117d613b6a7SJames Smart /* No failure to an ABTS request. */ 211886c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2119d613b6a7SJames Smart return 0; 2120d613b6a7SJames Smart } 2121d613b6a7SJames Smart 2122d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 2123d613b6a7SJames Smart ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba); 2124d613b6a7SJames Smart if (!ctxp->abort_wqeq) { 2125547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2126d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 212786c67379SJames Smart "6161 ABORT failed: No wqeqs: " 2128d613b6a7SJames Smart "xri: x%x\n", ctxp->oxid); 2129d613b6a7SJames Smart /* No failure to an ABTS request. */ 213086c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2131d613b6a7SJames Smart return 0; 2132d613b6a7SJames Smart } 2133d613b6a7SJames Smart abts_wqeq = ctxp->abort_wqeq; 2134d613b6a7SJames Smart abts_wqe = &abts_wqeq->wqe; 2135d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 2136d613b6a7SJames Smart 2137d613b6a7SJames Smart /* Announce entry to new IO submit field. */ 213886c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 213986c67379SJames Smart "6162 ABORT Request to rport DID x%06x " 2140d613b6a7SJames Smart "for xri x%x x%x\n", 2141d613b6a7SJames Smart ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag); 2142d613b6a7SJames Smart 2143d613b6a7SJames Smart /* If the hba is getting reset, this flag is set. It is 2144d613b6a7SJames Smart * cleared when the reset is complete and rings reestablished. 2145d613b6a7SJames Smart */ 2146d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2147d613b6a7SJames Smart /* driver queued commands are in process of being flushed */ 2148d613b6a7SJames Smart if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) { 2149d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2150547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2151d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2152d613b6a7SJames Smart "6163 Driver in reset cleanup - flushing " 2153d613b6a7SJames Smart "NVME Req now. hba_flag x%x oxid x%x\n", 2154d613b6a7SJames Smart phba->hba_flag, ctxp->oxid); 2155d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 215686c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2157d613b6a7SJames Smart return 0; 2158d613b6a7SJames Smart } 2159d613b6a7SJames Smart 2160d613b6a7SJames Smart /* Outstanding abort is in progress */ 2161d613b6a7SJames Smart if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) { 2162d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2163547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2164d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2165d613b6a7SJames Smart "6164 Outstanding NVME I/O Abort Request " 2166d613b6a7SJames Smart "still pending on oxid x%x\n", 2167d613b6a7SJames Smart ctxp->oxid); 2168d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 216986c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2170d613b6a7SJames Smart return 0; 2171d613b6a7SJames Smart } 2172d613b6a7SJames Smart 2173d613b6a7SJames Smart /* Ready - mark outstanding as aborted by driver. */ 2174d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED; 2175d613b6a7SJames Smart 2176d613b6a7SJames Smart /* WQEs are reused. Clear stale data and set key fields to 2177d613b6a7SJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 2178d613b6a7SJames Smart */ 2179d613b6a7SJames Smart memset(abts_wqe, 0, sizeof(union lpfc_wqe)); 2180d613b6a7SJames Smart 2181d613b6a7SJames Smart /* word 3 */ 2182d613b6a7SJames Smart bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); 2183d613b6a7SJames Smart 2184d613b6a7SJames Smart /* word 7 */ 2185d613b6a7SJames Smart bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); 2186d613b6a7SJames Smart bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 2187d613b6a7SJames Smart 2188d613b6a7SJames Smart /* word 8 - tell the FW to abort the IO associated with this 2189d613b6a7SJames Smart * outstanding exchange ID. 2190d613b6a7SJames Smart */ 2191d613b6a7SJames Smart abts_wqe->abort_cmd.wqe_com.abort_tag = ctxp->wqeq->sli4_xritag; 2192d613b6a7SJames Smart 2193d613b6a7SJames Smart /* word 9 - this is the iotag for the abts_wqe completion. */ 2194d613b6a7SJames Smart bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, 2195d613b6a7SJames Smart abts_wqeq->iotag); 2196d613b6a7SJames Smart 2197d613b6a7SJames Smart /* word 10 */ 2198d613b6a7SJames Smart bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); 2199d613b6a7SJames Smart bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 2200d613b6a7SJames Smart 2201d613b6a7SJames Smart /* word 11 */ 2202d613b6a7SJames Smart bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); 2203d613b6a7SJames Smart bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); 2204d613b6a7SJames Smart bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 2205d613b6a7SJames Smart 2206d613b6a7SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 2207d613b6a7SJames Smart abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx; 2208d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp; 2209d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 2210d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME; 2211d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 2212d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 2213d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2214547077a4SJames Smart if (rc == WQE_SUCCESS) { 2215547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_sol); 2216d613b6a7SJames Smart return 0; 2217547077a4SJames Smart } 2218d613b6a7SJames Smart 2219547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 222086c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2221d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 222286c67379SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 222386c67379SJames Smart "6166 Failed ABORT issue_wqe with status x%x " 2224d613b6a7SJames Smart "for oxid x%x.\n", 2225d613b6a7SJames Smart rc, ctxp->oxid); 2226d613b6a7SJames Smart return 1; 2227d613b6a7SJames Smart } 2228d613b6a7SJames Smart 2229d613b6a7SJames Smart 2230d613b6a7SJames Smart static int 2231d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba, 2232d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2233d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2234d613b6a7SJames Smart { 2235d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2236d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2237d613b6a7SJames Smart unsigned long flags; 2238d613b6a7SJames Smart int rc; 2239d613b6a7SJames Smart 2240d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2241d613b6a7SJames Smart if (!ctxp->wqeq) { 2242d613b6a7SJames Smart ctxp->wqeq = ctxp->rqb_buffer->iocbq; 2243d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2244d613b6a7SJames Smart } 2245d613b6a7SJames Smart 2246d613b6a7SJames Smart rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 2247d613b6a7SJames Smart if (rc == 0) 2248d613b6a7SJames Smart goto aerr; 2249d613b6a7SJames Smart 2250d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2251d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 225286c67379SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_unsol_fcp_abort_cmp; 225386c67379SJames Smart abts_wqeq->iocb_cmpl = NULL; 2254d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVMET; 2255d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 2256d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2257d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 2258d613b6a7SJames Smart return 0; 2259d613b6a7SJames Smart } 2260d613b6a7SJames Smart 2261d613b6a7SJames Smart aerr: 2262547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 226386c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2264d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2265d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 2266d613b6a7SJames Smart "6135 Failed to Issue ABTS for oxid x%x. Status x%x\n", 2267d613b6a7SJames Smart ctxp->oxid, rc); 2268d613b6a7SJames Smart return 1; 2269d613b6a7SJames Smart } 2270d613b6a7SJames Smart 2271d613b6a7SJames Smart static int 2272d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *phba, 2273d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2274d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2275d613b6a7SJames Smart { 2276d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2277d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2278d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 2279d613b6a7SJames Smart unsigned long flags; 2280d613b6a7SJames Smart int rc; 2281d613b6a7SJames Smart 2282d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2283d613b6a7SJames Smart if (!ctxp->wqeq) { 2284d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 2285d613b6a7SJames Smart ctxp->wqeq = lpfc_sli_get_iocbq(phba); 2286d613b6a7SJames Smart if (!ctxp->wqeq) { 2287d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 2288d613b6a7SJames Smart "6068 Abort failed: No wqeqs: " 2289d613b6a7SJames Smart "xri: x%x\n", xri); 2290d613b6a7SJames Smart /* No failure to an ABTS request. */ 2291d613b6a7SJames Smart kfree(ctxp); 2292d613b6a7SJames Smart return 0; 2293d613b6a7SJames Smart } 2294d613b6a7SJames Smart } 2295d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 2296d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 2297d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 2298d613b6a7SJames Smart 2299d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2300d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp; 2301d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 2302d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS; 2303d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, abts_wqeq); 2304d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2305d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 2306547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_unsol); 2307d613b6a7SJames Smart return 0; 2308d613b6a7SJames Smart } 2309d613b6a7SJames Smart 2310d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2311d613b6a7SJames Smart abts_wqeq->context2 = NULL; 2312d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2313d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 2314d613b6a7SJames Smart kfree(ctxp); 2315d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 2316d613b6a7SJames Smart "6056 Failed to Issue ABTS. Status x%x\n", rc); 2317d613b6a7SJames Smart return 0; 2318d613b6a7SJames Smart } 2319