1d613b6a7SJames Smart /******************************************************************* 2d613b6a7SJames Smart * This file is part of the Emulex Linux Device Driver for * 3d613b6a7SJames Smart * Fibre Channsel Host Bus Adapters. * 4983f761cSJames Smart * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term * 54ae2ebdeSJames Smart * “Broadcom” refers to Broadcom Inc. 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 "lpfc_version.h" 40d613b6a7SJames Smart #include "lpfc_hw4.h" 41d613b6a7SJames Smart #include "lpfc_hw.h" 42d613b6a7SJames Smart #include "lpfc_sli.h" 43d613b6a7SJames Smart #include "lpfc_sli4.h" 44d613b6a7SJames Smart #include "lpfc_nl.h" 45d613b6a7SJames Smart #include "lpfc_disc.h" 46d613b6a7SJames Smart #include "lpfc.h" 47d613b6a7SJames Smart #include "lpfc_scsi.h" 48d613b6a7SJames Smart #include "lpfc_nvme.h" 49d613b6a7SJames Smart #include "lpfc_logmsg.h" 50d613b6a7SJames Smart #include "lpfc_crtn.h" 51d613b6a7SJames Smart #include "lpfc_vport.h" 522b65e182SJames Smart #include "lpfc_debugfs.h" 53d613b6a7SJames Smart 54d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *, 557cacae2aSJames Smart struct lpfc_async_xchg_ctx *, 56d613b6a7SJames Smart dma_addr_t rspbuf, 57d613b6a7SJames Smart uint16_t rspsize); 58d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *, 597cacae2aSJames Smart struct lpfc_async_xchg_ctx *); 60d613b6a7SJames Smart static int lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *, 617cacae2aSJames Smart struct lpfc_async_xchg_ctx *, 62d613b6a7SJames Smart uint32_t, uint16_t); 63d613b6a7SJames Smart static int lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *, 647cacae2aSJames Smart struct lpfc_async_xchg_ctx *, 65d613b6a7SJames Smart uint32_t, uint16_t); 666e8e1c14SJames Smart static void lpfc_nvmet_wqfull_flush(struct lpfc_hba *, struct lpfc_queue *, 677cacae2aSJames Smart struct lpfc_async_xchg_ctx *); 68472e146dSJames Smart static void lpfc_nvmet_fcp_rqst_defer_work(struct work_struct *); 69472e146dSJames Smart 70472e146dSJames Smart static void lpfc_nvmet_process_rcv_fcp_req(struct lpfc_nvmet_ctxbuf *ctx_buf); 71d613b6a7SJames Smart 72fab2e466SColin Ian King static union lpfc_wqe128 lpfc_tsend_cmd_template; 73fab2e466SColin Ian King static union lpfc_wqe128 lpfc_treceive_cmd_template; 74fab2e466SColin Ian King static union lpfc_wqe128 lpfc_trsp_cmd_template; 75bd3061baSJames Smart 76bd3061baSJames Smart /* Setup WQE templates for NVME IOs */ 77bd3061baSJames Smart void 78fab2e466SColin Ian King lpfc_nvmet_cmd_template(void) 79bd3061baSJames Smart { 80bd3061baSJames Smart union lpfc_wqe128 *wqe; 81bd3061baSJames Smart 82bd3061baSJames Smart /* TSEND template */ 83bd3061baSJames Smart wqe = &lpfc_tsend_cmd_template; 84bd3061baSJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 85bd3061baSJames Smart 86bd3061baSJames Smart /* Word 0, 1, 2 - BDE is variable */ 87bd3061baSJames Smart 88bd3061baSJames Smart /* Word 3 - payload_offset_len is zero */ 89bd3061baSJames Smart 90bd3061baSJames Smart /* Word 4 - relative_offset is variable */ 91bd3061baSJames Smart 92bd3061baSJames Smart /* Word 5 - is zero */ 93bd3061baSJames Smart 94bd3061baSJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 95bd3061baSJames Smart 96bd3061baSJames Smart /* Word 7 - wqe_ar is variable */ 97bd3061baSJames Smart bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE); 98bd3061baSJames Smart bf_set(wqe_pu, &wqe->fcp_tsend.wqe_com, PARM_REL_OFF); 99bd3061baSJames Smart bf_set(wqe_class, &wqe->fcp_tsend.wqe_com, CLASS3); 100bd3061baSJames Smart bf_set(wqe_ct, &wqe->fcp_tsend.wqe_com, SLI4_CT_RPI); 101bd3061baSJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1); 102bd3061baSJames Smart 103bd3061baSJames Smart /* Word 8 - abort_tag is variable */ 104bd3061baSJames Smart 105bd3061baSJames Smart /* Word 9 - reqtag, rcvoxid is variable */ 106bd3061baSJames Smart 107bd3061baSJames Smart /* Word 10 - wqes, xc is variable */ 108b101eb27SJames Smart bf_set(wqe_xchg, &wqe->fcp_tsend.wqe_com, LPFC_NVME_XCHG); 109bd3061baSJames Smart bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1); 110bd3061baSJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 111bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, 1); 112bd3061baSJames Smart bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE); 113bd3061baSJames Smart bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com, LPFC_WQE_LENLOC_WORD12); 114bd3061baSJames Smart 115bd3061baSJames Smart /* Word 11 - sup, irsp, irsplen is variable */ 116bd3061baSJames Smart bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com, FCP_COMMAND_TSEND); 117bd3061baSJames Smart bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 118bd3061baSJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 119bd3061baSJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 120bd3061baSJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 121bd3061baSJames Smart bf_set(wqe_pbde, &wqe->fcp_tsend.wqe_com, 0); 122bd3061baSJames Smart 123bd3061baSJames Smart /* Word 12 - fcp_data_len is variable */ 124bd3061baSJames Smart 125bd3061baSJames Smart /* Word 13, 14, 15 - PBDE is zero */ 126bd3061baSJames Smart 127bd3061baSJames Smart /* TRECEIVE template */ 128bd3061baSJames Smart wqe = &lpfc_treceive_cmd_template; 129bd3061baSJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 130bd3061baSJames Smart 131bd3061baSJames Smart /* Word 0, 1, 2 - BDE is variable */ 132bd3061baSJames Smart 133bd3061baSJames Smart /* Word 3 */ 134bd3061baSJames Smart wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN; 135bd3061baSJames Smart 136bd3061baSJames Smart /* Word 4 - relative_offset is variable */ 137bd3061baSJames Smart 138bd3061baSJames Smart /* Word 5 - is zero */ 139bd3061baSJames Smart 140bd3061baSJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 141bd3061baSJames Smart 142bd3061baSJames Smart /* Word 7 */ 143bd3061baSJames Smart bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com, CMD_FCP_TRECEIVE64_WQE); 144bd3061baSJames Smart bf_set(wqe_pu, &wqe->fcp_treceive.wqe_com, PARM_REL_OFF); 145bd3061baSJames Smart bf_set(wqe_class, &wqe->fcp_treceive.wqe_com, CLASS3); 146bd3061baSJames Smart bf_set(wqe_ct, &wqe->fcp_treceive.wqe_com, SLI4_CT_RPI); 147bd3061baSJames Smart bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0); 148bd3061baSJames Smart 149bd3061baSJames Smart /* Word 8 - abort_tag is variable */ 150bd3061baSJames Smart 151bd3061baSJames Smart /* Word 9 - reqtag, rcvoxid is variable */ 152bd3061baSJames Smart 153bd3061baSJames Smart /* Word 10 - xc is variable */ 154bd3061baSJames Smart bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1); 155bd3061baSJames Smart bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0); 156b101eb27SJames Smart bf_set(wqe_xchg, &wqe->fcp_treceive.wqe_com, LPFC_NVME_XCHG); 157bd3061baSJames Smart bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ); 158bd3061baSJames Smart bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com, LPFC_WQE_LENLOC_WORD12); 159bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, 1); 160bd3061baSJames Smart 161bd3061baSJames Smart /* Word 11 - pbde is variable */ 162bd3061baSJames Smart bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com, FCP_COMMAND_TRECEIVE); 163bd3061baSJames Smart bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 164bd3061baSJames Smart bf_set(wqe_sup, &wqe->fcp_treceive.wqe_com, 0); 165bd3061baSJames Smart bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0); 166bd3061baSJames Smart bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0); 167bd3061baSJames Smart bf_set(wqe_pbde, &wqe->fcp_treceive.wqe_com, 1); 168bd3061baSJames Smart 169bd3061baSJames Smart /* Word 12 - fcp_data_len is variable */ 170bd3061baSJames Smart 171bd3061baSJames Smart /* Word 13, 14, 15 - PBDE is variable */ 172bd3061baSJames Smart 173bd3061baSJames Smart /* TRSP template */ 174bd3061baSJames Smart wqe = &lpfc_trsp_cmd_template; 175bd3061baSJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 176bd3061baSJames Smart 177bd3061baSJames Smart /* Word 0, 1, 2 - BDE is variable */ 178bd3061baSJames Smart 179bd3061baSJames Smart /* Word 3 - response_len is variable */ 180bd3061baSJames Smart 181bd3061baSJames Smart /* Word 4, 5 - is zero */ 182bd3061baSJames Smart 183bd3061baSJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 184bd3061baSJames Smart 185bd3061baSJames Smart /* Word 7 */ 186bd3061baSJames Smart bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE); 187bd3061baSJames Smart bf_set(wqe_pu, &wqe->fcp_trsp.wqe_com, PARM_UNUSED); 188bd3061baSJames Smart bf_set(wqe_class, &wqe->fcp_trsp.wqe_com, CLASS3); 189bd3061baSJames Smart bf_set(wqe_ct, &wqe->fcp_trsp.wqe_com, SLI4_CT_RPI); 190bd3061baSJames Smart bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1); /* wqe_ar */ 191bd3061baSJames Smart 192bd3061baSJames Smart /* Word 8 - abort_tag is variable */ 193bd3061baSJames Smart 194bd3061baSJames Smart /* Word 9 - reqtag is variable */ 195bd3061baSJames Smart 196bd3061baSJames Smart /* Word 10 wqes, xc is variable */ 197bd3061baSJames Smart bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 1); 198b101eb27SJames Smart bf_set(wqe_xchg, &wqe->fcp_trsp.wqe_com, LPFC_NVME_XCHG); 199bd3061baSJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0); 200bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, 0); 201bd3061baSJames Smart bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_NONE); 202bd3061baSJames Smart bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com, LPFC_WQE_LENLOC_WORD3); 203bd3061baSJames Smart 204bd3061baSJames Smart /* Word 11 irsp, irsplen is variable */ 205bd3061baSJames Smart bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com, FCP_COMMAND_TRSP); 206bd3061baSJames Smart bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 207bd3061baSJames Smart bf_set(wqe_sup, &wqe->fcp_trsp.wqe_com, 0); 208bd3061baSJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0); 209bd3061baSJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0); 210bd3061baSJames Smart bf_set(wqe_pbde, &wqe->fcp_trsp.wqe_com, 0); 211bd3061baSJames Smart 212bd3061baSJames Smart /* Word 12, 13, 14, 15 - is zero */ 213bd3061baSJames Smart } 214bd3061baSJames Smart 215336df6ebSNathan Chancellor #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 2167cacae2aSJames Smart static struct lpfc_async_xchg_ctx * 21779d8c4ceSJames Smart lpfc_nvmet_get_ctx_for_xri(struct lpfc_hba *phba, u16 xri) 21879d8c4ceSJames Smart { 2197cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 22079d8c4ceSJames Smart unsigned long iflag; 22179d8c4ceSJames Smart bool found = false; 22279d8c4ceSJames Smart 22379d8c4ceSJames Smart spin_lock_irqsave(&phba->sli4_hba.t_active_list_lock, iflag); 22479d8c4ceSJames Smart list_for_each_entry(ctxp, &phba->sli4_hba.t_active_ctx_list, list) { 22579d8c4ceSJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 22679d8c4ceSJames Smart continue; 22779d8c4ceSJames Smart 22879d8c4ceSJames Smart found = true; 22979d8c4ceSJames Smart break; 23079d8c4ceSJames Smart } 23179d8c4ceSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.t_active_list_lock, iflag); 23279d8c4ceSJames Smart if (found) 23379d8c4ceSJames Smart return ctxp; 23479d8c4ceSJames Smart 23579d8c4ceSJames Smart return NULL; 23679d8c4ceSJames Smart } 23779d8c4ceSJames Smart 2387cacae2aSJames Smart static struct lpfc_async_xchg_ctx * 23979d8c4ceSJames Smart lpfc_nvmet_get_ctx_for_oxid(struct lpfc_hba *phba, u16 oxid, u32 sid) 24079d8c4ceSJames Smart { 2417cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 24279d8c4ceSJames Smart unsigned long iflag; 24379d8c4ceSJames Smart bool found = false; 24479d8c4ceSJames Smart 24579d8c4ceSJames Smart spin_lock_irqsave(&phba->sli4_hba.t_active_list_lock, iflag); 24679d8c4ceSJames Smart list_for_each_entry(ctxp, &phba->sli4_hba.t_active_ctx_list, list) { 24779d8c4ceSJames Smart if (ctxp->oxid != oxid || ctxp->sid != sid) 24879d8c4ceSJames Smart continue; 24979d8c4ceSJames Smart 25079d8c4ceSJames Smart found = true; 25179d8c4ceSJames Smart break; 25279d8c4ceSJames Smart } 25379d8c4ceSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.t_active_list_lock, iflag); 25479d8c4ceSJames Smart if (found) 25579d8c4ceSJames Smart return ctxp; 25679d8c4ceSJames Smart 25779d8c4ceSJames Smart return NULL; 25879d8c4ceSJames Smart } 259336df6ebSNathan Chancellor #endif 26079d8c4ceSJames Smart 2613999df75SBart Van Assche static void 2627cacae2aSJames Smart lpfc_nvmet_defer_release(struct lpfc_hba *phba, 2637cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp) 26486c67379SJames Smart { 265472e146dSJames Smart lockdep_assert_held(&ctxp->ctxlock); 26686c67379SJames Smart 267e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 26879d8c4ceSJames Smart "6313 NVMET Defer ctx release oxid x%x flg x%x\n", 26986c67379SJames Smart ctxp->oxid, ctxp->flag); 27086c67379SJames Smart 2717b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_CTX_RLS) 27286c67379SJames Smart return; 273472e146dSJames Smart 2747b7f551bSJames Smart ctxp->flag |= LPFC_NVME_CTX_RLS; 27579d8c4ceSJames Smart spin_lock(&phba->sli4_hba.t_active_list_lock); 27679d8c4ceSJames Smart list_del(&ctxp->list); 27779d8c4ceSJames Smart spin_unlock(&phba->sli4_hba.t_active_list_lock); 278472e146dSJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 27986c67379SJames Smart list_add_tail(&ctxp->list, &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); 280472e146dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 28186c67379SJames Smart } 28286c67379SJames Smart 283d613b6a7SJames Smart /** 284fe1bedecSJames Smart * __lpfc_nvme_xmt_ls_rsp_cmp - Generic completion handler for the 285fe1bedecSJames Smart * transmission of an NVME LS response. 286fe1bedecSJames Smart * @phba: Pointer to HBA context object. 287fe1bedecSJames Smart * @cmdwqe: Pointer to driver command WQE object. 288fe1bedecSJames Smart * @wcqe: Pointer to driver response CQE object. 289fe1bedecSJames Smart * 290fe1bedecSJames Smart * The function is called from SLI ring event handler with no 291fe1bedecSJames Smart * lock held. The function frees memory resources used for the command 292fe1bedecSJames Smart * used to send the NVME LS RSP. 293fe1bedecSJames Smart **/ 294fe1bedecSJames Smart void 295fe1bedecSJames Smart __lpfc_nvme_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 296fe1bedecSJames Smart struct lpfc_wcqe_complete *wcqe) 297fe1bedecSJames Smart { 298fe1bedecSJames Smart struct lpfc_async_xchg_ctx *axchg = cmdwqe->context2; 299fe1bedecSJames Smart struct nvmefc_ls_rsp *ls_rsp = &axchg->ls_rsp; 300fe1bedecSJames Smart uint32_t status, result; 301fe1bedecSJames Smart 302fe1bedecSJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; 303fe1bedecSJames Smart result = wcqe->parameter; 304fe1bedecSJames Smart 305fe1bedecSJames Smart if (axchg->state != LPFC_NVME_STE_LS_RSP || axchg->entry_cnt != 2) { 306372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 307fe1bedecSJames Smart "6410 NVMEx LS cmpl state mismatch IO x%x: " 308fe1bedecSJames Smart "%d %d\n", 309fe1bedecSJames Smart axchg->oxid, axchg->state, axchg->entry_cnt); 310fe1bedecSJames Smart } 311fe1bedecSJames Smart 312fe1bedecSJames Smart lpfc_nvmeio_data(phba, "NVMEx LS CMPL: xri x%x stat x%x result x%x\n", 313fe1bedecSJames Smart axchg->oxid, status, result); 314fe1bedecSJames Smart 315fe1bedecSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 316fe1bedecSJames Smart "6038 NVMEx LS rsp cmpl: %d %d oxid x%x\n", 317fe1bedecSJames Smart status, result, axchg->oxid); 318fe1bedecSJames Smart 319fe1bedecSJames Smart lpfc_nlp_put(cmdwqe->context1); 320fe1bedecSJames Smart cmdwqe->context2 = NULL; 321fe1bedecSJames Smart cmdwqe->context3 = NULL; 322fe1bedecSJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 323fe1bedecSJames Smart ls_rsp->done(ls_rsp); 324fe1bedecSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 325fe1bedecSJames Smart "6200 NVMEx LS rsp cmpl done status %d oxid x%x\n", 326fe1bedecSJames Smart status, axchg->oxid); 327fe1bedecSJames Smart kfree(axchg); 328fe1bedecSJames Smart } 329fe1bedecSJames Smart 330fe1bedecSJames Smart /** 331d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response 332d613b6a7SJames Smart * @phba: Pointer to HBA context object. 333d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 334d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 335d613b6a7SJames Smart * 336d613b6a7SJames Smart * The function is called from SLI ring event handler with no 337d613b6a7SJames Smart * lock held. This function is the completion handler for NVME LS commands 338fe1bedecSJames Smart * The function updates any states and statistics, then calls the 339fe1bedecSJames Smart * generic completion handler to free resources. 340d613b6a7SJames Smart **/ 341d613b6a7SJames Smart static void 342d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 343d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 344d613b6a7SJames Smart { 345d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 346d613b6a7SJames Smart uint32_t status, result; 347d613b6a7SJames Smart 348d613b6a7SJames Smart if (!phba->targetport) 349fe1bedecSJames Smart goto finish; 350fe1bedecSJames Smart 351fe1bedecSJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; 352fe1bedecSJames Smart result = wcqe->parameter; 353d613b6a7SJames Smart 354d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3554b056682SJames Smart if (tgtp) { 3564b056682SJames Smart if (status) { 357d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_error); 3588ae33701SJames Smart if (result == IOERR_ABORT_REQUESTED) 3594b056682SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_aborted); 3604b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 3614b056682SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_xb_set); 3624b056682SJames Smart } else { 363d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_cmpl); 3644b056682SJames Smart } 3654b056682SJames Smart } 366d613b6a7SJames Smart 367fe1bedecSJames Smart finish: 368fe1bedecSJames Smart __lpfc_nvme_xmt_ls_rsp_cmp(phba, cmdwqe, wcqe); 369d613b6a7SJames Smart } 370d613b6a7SJames Smart 371d613b6a7SJames Smart /** 3726c621a22SJames Smart * lpfc_nvmet_ctxbuf_post - Repost a NVMET RQ DMA buffer and clean up context 373d613b6a7SJames Smart * @phba: HBA buffer is associated with 374d3cb79fcSLee Jones * @ctx_buf: ctx buffer context 375d613b6a7SJames Smart * 376d613b6a7SJames Smart * Description: Frees the given DMA buffer in the appropriate way given by 377d613b6a7SJames Smart * reposting it to its associated RQ so it can be reused. 378d613b6a7SJames Smart * 379d613b6a7SJames Smart * Notes: Takes phba->hbalock. Can be called with or without other locks held. 380d613b6a7SJames Smart * 381d613b6a7SJames Smart * Returns: None 382d613b6a7SJames Smart **/ 383d613b6a7SJames Smart void 3846c621a22SJames Smart lpfc_nvmet_ctxbuf_post(struct lpfc_hba *phba, struct lpfc_nvmet_ctxbuf *ctx_buf) 385d613b6a7SJames Smart { 386eeeb51d8SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 3877cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = ctx_buf->context; 388a8cf5dfeSJames Smart struct lpfc_nvmet_tgtport *tgtp; 389a8cf5dfeSJames Smart struct fc_frame_header *fc_hdr; 390a8cf5dfeSJames Smart struct rqb_dmabuf *nvmebuf; 39166d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 392472e146dSJames Smart uint32_t size, oxid, sid; 39366d7ce93SDick Kennedy int cpu; 3946c621a22SJames Smart unsigned long iflag; 39586c67379SJames Smart 3967b7f551bSJames Smart if (ctxp->state == LPFC_NVME_STE_FREE) { 397372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 398ce1b591cSJames Smart "6411 NVMET free, already free IO x%x: %d %d\n", 399ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 400ce1b591cSJames Smart } 401472e146dSJames Smart 402472e146dSJames Smart if (ctxp->rqb_buffer) { 403472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 4044767c58aSJames Smart nvmebuf = ctxp->rqb_buffer; 4054767c58aSJames Smart /* check if freed in another path whilst acquiring lock */ 4064767c58aSJames Smart if (nvmebuf) { 407472e146dSJames Smart ctxp->rqb_buffer = NULL; 4087b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_CTX_REUSE_WQ) { 4097b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_CTX_REUSE_WQ; 410472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 4114767c58aSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, 4124767c58aSJames Smart nvmebuf); 413472e146dSJames Smart } else { 414472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 4154767c58aSJames Smart /* repost */ 4164767c58aSJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); 4174767c58aSJames Smart } 4184767c58aSJames Smart } else { 4194767c58aSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 420472e146dSJames Smart } 421472e146dSJames Smart } 4227b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_FREE; 4236c621a22SJames Smart 424a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 425a8cf5dfeSJames Smart if (phba->sli4_hba.nvmet_io_wait_cnt) { 426a8cf5dfeSJames Smart list_remove_head(&phba->sli4_hba.lpfc_nvmet_io_wait_list, 427a8cf5dfeSJames Smart nvmebuf, struct rqb_dmabuf, 428a8cf5dfeSJames Smart hbuf.list); 429a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt--; 430a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 431a8cf5dfeSJames Smart iflag); 432a8cf5dfeSJames Smart 433a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 434a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 435a8cf5dfeSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 436a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 437a8cf5dfeSJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 438a8cf5dfeSJames Smart 4397cacae2aSJames Smart ctxp = (struct lpfc_async_xchg_ctx *)ctx_buf->context; 440a8cf5dfeSJames Smart ctxp->wqeq = NULL; 441a8cf5dfeSJames Smart ctxp->offset = 0; 442a8cf5dfeSJames Smart ctxp->phba = phba; 443a8cf5dfeSJames Smart ctxp->size = size; 444a8cf5dfeSJames Smart ctxp->oxid = oxid; 445a8cf5dfeSJames Smart ctxp->sid = sid; 4467b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_RCV; 447a8cf5dfeSJames Smart ctxp->entry_cnt = 1; 448a8cf5dfeSJames Smart ctxp->flag = 0; 449a8cf5dfeSJames Smart ctxp->ctxbuf = ctx_buf; 450cbc5de1bSJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 451a8cf5dfeSJames Smart spin_lock_init(&ctxp->ctxlock); 452a8cf5dfeSJames Smart 453a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 454d74a89aaSJames Smart /* NOTE: isr time stamp is stale when context is re-assigned*/ 455d74a89aaSJames Smart if (ctxp->ts_isr_cmd) { 456d74a89aaSJames Smart ctxp->ts_cmd_nvme = 0; 457a8cf5dfeSJames Smart ctxp->ts_nvme_data = 0; 458a8cf5dfeSJames Smart ctxp->ts_data_wqput = 0; 459a8cf5dfeSJames Smart ctxp->ts_isr_data = 0; 460a8cf5dfeSJames Smart ctxp->ts_data_nvme = 0; 461a8cf5dfeSJames Smart ctxp->ts_nvme_status = 0; 462a8cf5dfeSJames Smart ctxp->ts_status_wqput = 0; 463a8cf5dfeSJames Smart ctxp->ts_isr_status = 0; 464a8cf5dfeSJames Smart ctxp->ts_status_nvme = 0; 465d613b6a7SJames Smart } 466a8cf5dfeSJames Smart #endif 467a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 468472e146dSJames Smart 46979d8c4ceSJames Smart /* Indicate that a replacement buffer has been posted */ 470472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 4717b7f551bSJames Smart ctxp->flag |= LPFC_NVME_CTX_REUSE_WQ; 472472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 473a8cf5dfeSJames Smart 474472e146dSJames Smart if (!queue_work(phba->wq, &ctx_buf->defer_work)) { 475a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 476372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 477472e146dSJames Smart "6181 Unable to queue deferred work " 478472e146dSJames Smart "for oxid x%x. " 479472e146dSJames Smart "FCP Drop IO [x%x x%x x%x]\n", 480472e146dSJames Smart ctxp->oxid, 481a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 482a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 483a8cf5dfeSJames Smart atomic_read(&tgtp->xmt_fcp_release)); 484a8cf5dfeSJames Smart 485472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 486a8cf5dfeSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 487472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 488a8cf5dfeSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 489472e146dSJames Smart } 490a8cf5dfeSJames Smart return; 491a8cf5dfeSJames Smart } 492a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 493a8cf5dfeSJames Smart 49466d7ce93SDick Kennedy /* 49566d7ce93SDick Kennedy * Use the CPU context list, from the MRQ the IO was received on 49666d7ce93SDick Kennedy * (ctxp->idx), to save context structure. 49766d7ce93SDick Kennedy */ 49879d8c4ceSJames Smart spin_lock_irqsave(&phba->sli4_hba.t_active_list_lock, iflag); 49979d8c4ceSJames Smart list_del_init(&ctxp->list); 50079d8c4ceSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.t_active_list_lock, iflag); 501d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 50266d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, cpu, ctxp->idx); 50366d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, iflag); 50466d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 50566d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 50666d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, iflag); 507eeeb51d8SJames Smart #endif 508d613b6a7SJames Smart } 509d613b6a7SJames Smart 5102b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 5112b65e182SJames Smart static void 5122b65e182SJames Smart lpfc_nvmet_ktime(struct lpfc_hba *phba, 5137cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp) 5142b65e182SJames Smart { 5152b65e182SJames Smart uint64_t seg1, seg2, seg3, seg4, seg5; 5162b65e182SJames Smart uint64_t seg6, seg7, seg8, seg9, seg10; 517c8a4ce0bSDick Kennedy uint64_t segsum; 5182b65e182SJames Smart 5192b65e182SJames Smart if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme || 5202b65e182SJames Smart !ctxp->ts_nvme_data || !ctxp->ts_data_wqput || 5212b65e182SJames Smart !ctxp->ts_isr_data || !ctxp->ts_data_nvme || 5222b65e182SJames Smart !ctxp->ts_nvme_status || !ctxp->ts_status_wqput || 5232b65e182SJames Smart !ctxp->ts_isr_status || !ctxp->ts_status_nvme) 5242b65e182SJames Smart return; 5252b65e182SJames Smart 526c8a4ce0bSDick Kennedy if (ctxp->ts_status_nvme < ctxp->ts_isr_cmd) 527c8a4ce0bSDick Kennedy return; 5282b65e182SJames Smart if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme) 5292b65e182SJames Smart return; 5302b65e182SJames Smart if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data) 5312b65e182SJames Smart return; 5322b65e182SJames Smart if (ctxp->ts_nvme_data > ctxp->ts_data_wqput) 5332b65e182SJames Smart return; 5342b65e182SJames Smart if (ctxp->ts_data_wqput > ctxp->ts_isr_data) 5352b65e182SJames Smart return; 5362b65e182SJames Smart if (ctxp->ts_isr_data > ctxp->ts_data_nvme) 5372b65e182SJames Smart return; 5382b65e182SJames Smart if (ctxp->ts_data_nvme > ctxp->ts_nvme_status) 5392b65e182SJames Smart return; 5402b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_status_wqput) 5412b65e182SJames Smart return; 5422b65e182SJames Smart if (ctxp->ts_status_wqput > ctxp->ts_isr_status) 5432b65e182SJames Smart return; 5442b65e182SJames Smart if (ctxp->ts_isr_status > ctxp->ts_status_nvme) 5452b65e182SJames Smart return; 5462b65e182SJames Smart /* 5472b65e182SJames Smart * Segment 1 - Time from FCP command received by MSI-X ISR 5482b65e182SJames Smart * to FCP command is passed to NVME Layer. 5492b65e182SJames Smart * Segment 2 - Time from FCP command payload handed 5502b65e182SJames Smart * off to NVME Layer to Driver receives a Command op 5512b65e182SJames Smart * from NVME Layer. 5522b65e182SJames Smart * Segment 3 - Time from Driver receives a Command op 5532b65e182SJames Smart * from NVME Layer to Command is put on WQ. 5542b65e182SJames Smart * Segment 4 - Time from Driver WQ put is done 5552b65e182SJames Smart * to MSI-X ISR for Command cmpl. 5562b65e182SJames Smart * Segment 5 - Time from MSI-X ISR for Command cmpl to 5572b65e182SJames Smart * Command cmpl is passed to NVME Layer. 5582b65e182SJames Smart * Segment 6 - Time from Command cmpl is passed to NVME 5592b65e182SJames Smart * Layer to Driver receives a RSP op from NVME Layer. 5602b65e182SJames Smart * Segment 7 - Time from Driver receives a RSP op from 5612b65e182SJames Smart * NVME Layer to WQ put is done on TRSP FCP Status. 5622b65e182SJames Smart * Segment 8 - Time from Driver WQ put is done on TRSP 5632b65e182SJames Smart * FCP Status to MSI-X ISR for TRSP cmpl. 5642b65e182SJames Smart * Segment 9 - Time from MSI-X ISR for TRSP cmpl to 5652b65e182SJames Smart * TRSP cmpl is passed to NVME Layer. 5662b65e182SJames Smart * Segment 10 - Time from FCP command received by 5672b65e182SJames Smart * MSI-X ISR to command is completed on wire. 5682b65e182SJames Smart * (Segments 1 thru 8) for READDATA / WRITEDATA 5692b65e182SJames Smart * (Segments 1 thru 4) for READDATA_RSP 5702b65e182SJames Smart */ 5712b65e182SJames Smart seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd; 572c8a4ce0bSDick Kennedy segsum = seg1; 573c8a4ce0bSDick Kennedy 574c8a4ce0bSDick Kennedy seg2 = ctxp->ts_nvme_data - ctxp->ts_isr_cmd; 575c8a4ce0bSDick Kennedy if (segsum > seg2) 576c8a4ce0bSDick Kennedy return; 577c8a4ce0bSDick Kennedy seg2 -= segsum; 578c8a4ce0bSDick Kennedy segsum += seg2; 579c8a4ce0bSDick Kennedy 580c8a4ce0bSDick Kennedy seg3 = ctxp->ts_data_wqput - ctxp->ts_isr_cmd; 581c8a4ce0bSDick Kennedy if (segsum > seg3) 582c8a4ce0bSDick Kennedy return; 583c8a4ce0bSDick Kennedy seg3 -= segsum; 584c8a4ce0bSDick Kennedy segsum += seg3; 585c8a4ce0bSDick Kennedy 586c8a4ce0bSDick Kennedy seg4 = ctxp->ts_isr_data - ctxp->ts_isr_cmd; 587c8a4ce0bSDick Kennedy if (segsum > seg4) 588c8a4ce0bSDick Kennedy return; 589c8a4ce0bSDick Kennedy seg4 -= segsum; 590c8a4ce0bSDick Kennedy segsum += seg4; 591c8a4ce0bSDick Kennedy 592c8a4ce0bSDick Kennedy seg5 = ctxp->ts_data_nvme - ctxp->ts_isr_cmd; 593c8a4ce0bSDick Kennedy if (segsum > seg5) 594c8a4ce0bSDick Kennedy return; 595c8a4ce0bSDick Kennedy seg5 -= segsum; 596c8a4ce0bSDick Kennedy segsum += seg5; 597c8a4ce0bSDick Kennedy 5982b65e182SJames Smart 5992b65e182SJames Smart /* For auto rsp commands seg6 thru seg10 will be 0 */ 6002b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) { 601c8a4ce0bSDick Kennedy seg6 = ctxp->ts_nvme_status - ctxp->ts_isr_cmd; 602c8a4ce0bSDick Kennedy if (segsum > seg6) 603c8a4ce0bSDick Kennedy return; 604c8a4ce0bSDick Kennedy seg6 -= segsum; 605c8a4ce0bSDick Kennedy segsum += seg6; 606c8a4ce0bSDick Kennedy 607c8a4ce0bSDick Kennedy seg7 = ctxp->ts_status_wqput - ctxp->ts_isr_cmd; 608c8a4ce0bSDick Kennedy if (segsum > seg7) 609c8a4ce0bSDick Kennedy return; 610c8a4ce0bSDick Kennedy seg7 -= segsum; 611c8a4ce0bSDick Kennedy segsum += seg7; 612c8a4ce0bSDick Kennedy 613c8a4ce0bSDick Kennedy seg8 = ctxp->ts_isr_status - ctxp->ts_isr_cmd; 614c8a4ce0bSDick Kennedy if (segsum > seg8) 615c8a4ce0bSDick Kennedy return; 616c8a4ce0bSDick Kennedy seg8 -= segsum; 617c8a4ce0bSDick Kennedy segsum += seg8; 618c8a4ce0bSDick Kennedy 619c8a4ce0bSDick Kennedy seg9 = ctxp->ts_status_nvme - ctxp->ts_isr_cmd; 620c8a4ce0bSDick Kennedy if (segsum > seg9) 621c8a4ce0bSDick Kennedy return; 622c8a4ce0bSDick Kennedy seg9 -= segsum; 623c8a4ce0bSDick Kennedy segsum += seg9; 624c8a4ce0bSDick Kennedy 625c8a4ce0bSDick Kennedy if (ctxp->ts_isr_status < ctxp->ts_isr_cmd) 626c8a4ce0bSDick Kennedy return; 6272b65e182SJames Smart seg10 = (ctxp->ts_isr_status - 6282b65e182SJames Smart ctxp->ts_isr_cmd); 6292b65e182SJames Smart } else { 630c8a4ce0bSDick Kennedy if (ctxp->ts_isr_data < ctxp->ts_isr_cmd) 631c8a4ce0bSDick Kennedy return; 6322b65e182SJames Smart seg6 = 0; 6332b65e182SJames Smart seg7 = 0; 6342b65e182SJames Smart seg8 = 0; 6352b65e182SJames Smart seg9 = 0; 6362b65e182SJames Smart seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd); 6372b65e182SJames Smart } 6382b65e182SJames Smart 6392b65e182SJames Smart phba->ktime_seg1_total += seg1; 6402b65e182SJames Smart if (seg1 < phba->ktime_seg1_min) 6412b65e182SJames Smart phba->ktime_seg1_min = seg1; 6422b65e182SJames Smart else if (seg1 > phba->ktime_seg1_max) 6432b65e182SJames Smart phba->ktime_seg1_max = seg1; 6442b65e182SJames Smart 6452b65e182SJames Smart phba->ktime_seg2_total += seg2; 6462b65e182SJames Smart if (seg2 < phba->ktime_seg2_min) 6472b65e182SJames Smart phba->ktime_seg2_min = seg2; 6482b65e182SJames Smart else if (seg2 > phba->ktime_seg2_max) 6492b65e182SJames Smart phba->ktime_seg2_max = seg2; 6502b65e182SJames Smart 6512b65e182SJames Smart phba->ktime_seg3_total += seg3; 6522b65e182SJames Smart if (seg3 < phba->ktime_seg3_min) 6532b65e182SJames Smart phba->ktime_seg3_min = seg3; 6542b65e182SJames Smart else if (seg3 > phba->ktime_seg3_max) 6552b65e182SJames Smart phba->ktime_seg3_max = seg3; 6562b65e182SJames Smart 6572b65e182SJames Smart phba->ktime_seg4_total += seg4; 6582b65e182SJames Smart if (seg4 < phba->ktime_seg4_min) 6592b65e182SJames Smart phba->ktime_seg4_min = seg4; 6602b65e182SJames Smart else if (seg4 > phba->ktime_seg4_max) 6612b65e182SJames Smart phba->ktime_seg4_max = seg4; 6622b65e182SJames Smart 6632b65e182SJames Smart phba->ktime_seg5_total += seg5; 6642b65e182SJames Smart if (seg5 < phba->ktime_seg5_min) 6652b65e182SJames Smart phba->ktime_seg5_min = seg5; 6662b65e182SJames Smart else if (seg5 > phba->ktime_seg5_max) 6672b65e182SJames Smart phba->ktime_seg5_max = seg5; 6682b65e182SJames Smart 6692b65e182SJames Smart phba->ktime_data_samples++; 6702b65e182SJames Smart if (!seg6) 6712b65e182SJames Smart goto out; 6722b65e182SJames Smart 6732b65e182SJames Smart phba->ktime_seg6_total += seg6; 6742b65e182SJames Smart if (seg6 < phba->ktime_seg6_min) 6752b65e182SJames Smart phba->ktime_seg6_min = seg6; 6762b65e182SJames Smart else if (seg6 > phba->ktime_seg6_max) 6772b65e182SJames Smart phba->ktime_seg6_max = seg6; 6782b65e182SJames Smart 6792b65e182SJames Smart phba->ktime_seg7_total += seg7; 6802b65e182SJames Smart if (seg7 < phba->ktime_seg7_min) 6812b65e182SJames Smart phba->ktime_seg7_min = seg7; 6822b65e182SJames Smart else if (seg7 > phba->ktime_seg7_max) 6832b65e182SJames Smart phba->ktime_seg7_max = seg7; 6842b65e182SJames Smart 6852b65e182SJames Smart phba->ktime_seg8_total += seg8; 6862b65e182SJames Smart if (seg8 < phba->ktime_seg8_min) 6872b65e182SJames Smart phba->ktime_seg8_min = seg8; 6882b65e182SJames Smart else if (seg8 > phba->ktime_seg8_max) 6892b65e182SJames Smart phba->ktime_seg8_max = seg8; 6902b65e182SJames Smart 6912b65e182SJames Smart phba->ktime_seg9_total += seg9; 6922b65e182SJames Smart if (seg9 < phba->ktime_seg9_min) 6932b65e182SJames Smart phba->ktime_seg9_min = seg9; 6942b65e182SJames Smart else if (seg9 > phba->ktime_seg9_max) 6952b65e182SJames Smart phba->ktime_seg9_max = seg9; 6962b65e182SJames Smart out: 6972b65e182SJames Smart phba->ktime_seg10_total += seg10; 6982b65e182SJames Smart if (seg10 < phba->ktime_seg10_min) 6992b65e182SJames Smart phba->ktime_seg10_min = seg10; 7002b65e182SJames Smart else if (seg10 > phba->ktime_seg10_max) 7012b65e182SJames Smart phba->ktime_seg10_max = seg10; 7022b65e182SJames Smart phba->ktime_status_samples++; 7032b65e182SJames Smart } 7042b65e182SJames Smart #endif 7052b65e182SJames Smart 706d613b6a7SJames Smart /** 707d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response 708d613b6a7SJames Smart * @phba: Pointer to HBA context object. 709d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 710d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 711d613b6a7SJames Smart * 712d613b6a7SJames Smart * The function is called from SLI ring event handler with no 713d613b6a7SJames Smart * lock held. This function is the completion handler for NVME FCP commands 714d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 715d613b6a7SJames Smart **/ 716d613b6a7SJames Smart static void 717d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 718d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 719d613b6a7SJames Smart { 720d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 721d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp; 7227cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 723e3246a12SJames Smart uint32_t status, result, op, start_clean, logerr; 7242b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 725840eda96SJames Smart int id; 7262b65e182SJames Smart #endif 727d613b6a7SJames Smart 728d613b6a7SJames Smart ctxp = cmdwqe->context2; 7297b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_IO_INP; 73086c67379SJames Smart 7317cacae2aSJames Smart rsp = &ctxp->hdlrctx.fcp_req; 732d613b6a7SJames Smart op = rsp->op; 733d613b6a7SJames Smart 734d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 735d613b6a7SJames Smart result = wcqe->parameter; 736d613b6a7SJames Smart 73786c67379SJames Smart if (phba->targetport) 73886c67379SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 73986c67379SJames Smart else 74086c67379SJames Smart tgtp = NULL; 741d613b6a7SJames Smart 7422b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n", 7432b65e182SJames Smart ctxp->oxid, op, status); 7442b65e182SJames Smart 745d613b6a7SJames Smart if (status) { 746d613b6a7SJames Smart rsp->fcp_error = NVME_SC_DATA_XFER_ERROR; 747d613b6a7SJames Smart rsp->transferred_length = 0; 7484b056682SJames Smart if (tgtp) { 749d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_error); 7508ae33701SJames Smart if (result == IOERR_ABORT_REQUESTED) 7514b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_aborted); 7524b056682SJames Smart } 75386c67379SJames Smart 754e3246a12SJames Smart logerr = LOG_NVME_IOERR; 755e3246a12SJames Smart 75686c67379SJames Smart /* pick up SLI4 exhange busy condition */ 75786c67379SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) { 7587b7f551bSJames Smart ctxp->flag |= LPFC_NVME_XBUSY; 759e3246a12SJames Smart logerr |= LOG_NVME_ABTS; 7604b056682SJames Smart if (tgtp) 7614b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_xb_set); 76286c67379SJames Smart 76386c67379SJames Smart } else { 7647b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_XBUSY; 76586c67379SJames Smart } 76686c67379SJames Smart 767e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, logerr, 76879d8c4ceSJames Smart "6315 IO Error Cmpl oxid: x%x xri: x%x %x/%x " 76979d8c4ceSJames Smart "XBUSY:x%x\n", 77079d8c4ceSJames Smart ctxp->oxid, ctxp->ctxbuf->sglq->sli4_xritag, 77179d8c4ceSJames Smart status, result, ctxp->flag); 772e3246a12SJames Smart 773d613b6a7SJames Smart } else { 774d613b6a7SJames Smart rsp->fcp_error = NVME_SC_SUCCESS; 775d613b6a7SJames Smart if (op == NVMET_FCOP_RSP) 776d613b6a7SJames Smart rsp->transferred_length = rsp->rsplen; 777d613b6a7SJames Smart else 778d613b6a7SJames Smart rsp->transferred_length = rsp->transfer_length; 77986c67379SJames Smart if (tgtp) 780d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_cmpl); 781d613b6a7SJames Smart } 782d613b6a7SJames Smart 783d613b6a7SJames Smart if ((op == NVMET_FCOP_READDATA_RSP) || 784d613b6a7SJames Smart (op == NVMET_FCOP_RSP)) { 785d613b6a7SJames Smart /* Sanity check */ 7867b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_DONE; 787d613b6a7SJames Smart ctxp->entry_cnt++; 78886c67379SJames Smart 7892b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 790c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 7912b65e182SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 7922b65e182SJames Smart ctxp->ts_isr_data = 7932b65e182SJames Smart cmdwqe->isr_timestamp; 7942b65e182SJames Smart ctxp->ts_data_nvme = 7952b65e182SJames Smart ktime_get_ns(); 7962b65e182SJames Smart ctxp->ts_nvme_status = 7972b65e182SJames Smart ctxp->ts_data_nvme; 7982b65e182SJames Smart ctxp->ts_status_wqput = 7992b65e182SJames Smart ctxp->ts_data_nvme; 8002b65e182SJames Smart ctxp->ts_isr_status = 8012b65e182SJames Smart ctxp->ts_data_nvme; 8022b65e182SJames Smart ctxp->ts_status_nvme = 8032b65e182SJames Smart ctxp->ts_data_nvme; 8042b65e182SJames Smart } else { 8052b65e182SJames Smart ctxp->ts_isr_status = 8062b65e182SJames Smart cmdwqe->isr_timestamp; 8072b65e182SJames Smart ctxp->ts_status_nvme = 8082b65e182SJames Smart ktime_get_ns(); 8092b65e182SJames Smart } 8102b65e182SJames Smart } 8112b65e182SJames Smart #endif 812d613b6a7SJames Smart rsp->done(rsp); 8132b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 814c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) 8152b65e182SJames Smart lpfc_nvmet_ktime(phba, ctxp); 8162b65e182SJames Smart #endif 81719b58d94SJames Smart /* lpfc_nvmet_xmt_fcp_release() will recycle the context */ 818d613b6a7SJames Smart } else { 819d613b6a7SJames Smart ctxp->entry_cnt++; 820c6e0c925SDick Kennedy start_clean = offsetof(struct lpfc_iocbq, iocb_flag); 821d613b6a7SJames Smart memset(((char *)cmdwqe) + start_clean, 0, 822d613b6a7SJames Smart (sizeof(struct lpfc_iocbq) - start_clean)); 8232b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 824c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 8252b65e182SJames Smart ctxp->ts_isr_data = cmdwqe->isr_timestamp; 8262b65e182SJames Smart ctxp->ts_data_nvme = ktime_get_ns(); 8272b65e182SJames Smart } 8282b65e182SJames Smart #endif 829d613b6a7SJames Smart rsp->done(rsp); 830d613b6a7SJames Smart } 83163df6d63SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 832840eda96SJames Smart if (phba->hdwqstat_on & LPFC_CHECK_NVMET_IO) { 833d6d189ceSBart Van Assche id = raw_smp_processor_id(); 834840eda96SJames Smart this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); 83563df6d63SJames Smart if (ctxp->cpu != id) 83663df6d63SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 83763df6d63SJames Smart "6704 CPU Check cmdcmpl: " 83863df6d63SJames Smart "cpu %d expect %d\n", 83963df6d63SJames Smart id, ctxp->cpu); 84063df6d63SJames Smart } 84163df6d63SJames Smart #endif 842d613b6a7SJames Smart } 843d613b6a7SJames Smart 844fe1bedecSJames Smart /** 845fe1bedecSJames Smart * __lpfc_nvme_xmt_ls_rsp - Generic service routine to issue transmit 846fe1bedecSJames Smart * an NVME LS rsp for a prior NVME LS request that was received. 847fe1bedecSJames Smart * @axchg: pointer to exchange context for the NVME LS request the response 848fe1bedecSJames Smart * is for. 849fe1bedecSJames Smart * @ls_rsp: pointer to the transport LS RSP that is to be sent 850fe1bedecSJames Smart * @xmt_ls_rsp_cmp: completion routine to call upon RSP transmit done 851fe1bedecSJames Smart * 852fe1bedecSJames Smart * This routine is used to format and send a WQE to transmit a NVME LS 853fe1bedecSJames Smart * Response. The response is for a prior NVME LS request that was 854fe1bedecSJames Smart * received and posted to the transport. 855fe1bedecSJames Smart * 856fe1bedecSJames Smart * Returns: 857fe1bedecSJames Smart * 0 : if response successfully transmit 858fe1bedecSJames Smart * non-zero : if response failed to transmit, of the form -Exxx. 859fe1bedecSJames Smart **/ 860fe1bedecSJames Smart int 861fe1bedecSJames Smart __lpfc_nvme_xmt_ls_rsp(struct lpfc_async_xchg_ctx *axchg, 862fe1bedecSJames Smart struct nvmefc_ls_rsp *ls_rsp, 863fe1bedecSJames Smart void (*xmt_ls_rsp_cmp)(struct lpfc_hba *phba, 864fe1bedecSJames Smart struct lpfc_iocbq *cmdwqe, 865fe1bedecSJames Smart struct lpfc_wcqe_complete *wcqe)) 866d613b6a7SJames Smart { 867fe1bedecSJames Smart struct lpfc_hba *phba = axchg->phba; 868fe1bedecSJames Smart struct hbq_dmabuf *nvmebuf = (struct hbq_dmabuf *)axchg->rqb_buffer; 869d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 870d613b6a7SJames Smart struct lpfc_dmabuf dmabuf; 871d613b6a7SJames Smart struct ulp_bde64 bpl; 872d613b6a7SJames Smart int rc; 873d613b6a7SJames Smart 8741abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) 8751abcb371SDick Kennedy return -ENODEV; 8761abcb371SDick Kennedy 877d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 878fe1bedecSJames Smart "6023 NVMEx LS rsp oxid x%x\n", axchg->oxid); 879ce1b591cSJames Smart 880fe1bedecSJames Smart if (axchg->state != LPFC_NVME_STE_LS_RCV || axchg->entry_cnt != 1) { 881372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 882fe1bedecSJames Smart "6412 NVMEx LS rsp state mismatch " 883ce1b591cSJames Smart "oxid x%x: %d %d\n", 884fe1bedecSJames Smart axchg->oxid, axchg->state, axchg->entry_cnt); 885fe1bedecSJames Smart return -EALREADY; 886ce1b591cSJames Smart } 887fe1bedecSJames Smart axchg->state = LPFC_NVME_STE_LS_RSP; 888fe1bedecSJames Smart axchg->entry_cnt++; 889d613b6a7SJames Smart 890fe1bedecSJames Smart nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, axchg, ls_rsp->rspdma, 891fe1bedecSJames Smart ls_rsp->rsplen); 892d613b6a7SJames Smart if (nvmewqeq == NULL) { 893372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 894fe1bedecSJames Smart "6150 NVMEx LS Drop Rsp x%x: Prep\n", 895fe1bedecSJames Smart axchg->oxid); 896fe1bedecSJames Smart rc = -ENOMEM; 897fe1bedecSJames Smart goto out_free_buf; 898d613b6a7SJames Smart } 899d613b6a7SJames Smart 900d613b6a7SJames Smart /* Save numBdes for bpl2sgl */ 901d613b6a7SJames Smart nvmewqeq->rsvd2 = 1; 902d613b6a7SJames Smart nvmewqeq->hba_wqidx = 0; 903d613b6a7SJames Smart nvmewqeq->context3 = &dmabuf; 904d613b6a7SJames Smart dmabuf.virt = &bpl; 905d613b6a7SJames Smart bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow; 906d613b6a7SJames Smart bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh; 907fe1bedecSJames Smart bpl.tus.f.bdeSize = ls_rsp->rsplen; 908d613b6a7SJames Smart bpl.tus.f.bdeFlags = 0; 909d613b6a7SJames Smart bpl.tus.w = le32_to_cpu(bpl.tus.w); 910fe1bedecSJames Smart /* 911fe1bedecSJames Smart * Note: although we're using stack space for the dmabuf, the 912fe1bedecSJames Smart * call to lpfc_sli4_issue_wqe is synchronous, so it will not 913fe1bedecSJames Smart * be referenced after it returns back to this routine. 914fe1bedecSJames Smart */ 915d613b6a7SJames Smart 916fe1bedecSJames Smart nvmewqeq->wqe_cmpl = xmt_ls_rsp_cmp; 917d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 918fe1bedecSJames Smart nvmewqeq->context2 = axchg; 919d613b6a7SJames Smart 920fe1bedecSJames Smart lpfc_nvmeio_data(phba, "NVMEx LS RSP: xri x%x wqidx x%x len x%x\n", 921fe1bedecSJames Smart axchg->oxid, nvmewqeq->hba_wqidx, ls_rsp->rsplen); 9222b65e182SJames Smart 923fe1bedecSJames Smart rc = lpfc_sli4_issue_wqe(phba, axchg->hdwq, nvmewqeq); 924fe1bedecSJames Smart 925fe1bedecSJames Smart /* clear to be sure there's no reference */ 926fe1bedecSJames Smart nvmewqeq->context3 = NULL; 927fe1bedecSJames Smart 928d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 929d613b6a7SJames Smart /* 930d613b6a7SJames Smart * Okay to repost buffer here, but wait till cmpl 931d613b6a7SJames Smart * before freeing ctxp and iocbq. 932d613b6a7SJames Smart */ 933d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 934d613b6a7SJames Smart return 0; 935d613b6a7SJames Smart } 936fe1bedecSJames Smart 937372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 938fe1bedecSJames Smart "6151 NVMEx LS RSP x%x: failed to transmit %d\n", 939fe1bedecSJames Smart axchg->oxid, rc); 940fe1bedecSJames Smart 941fe1bedecSJames Smart rc = -ENXIO; 942d613b6a7SJames Smart 943d613b6a7SJames Smart lpfc_nlp_put(nvmewqeq->context1); 944d613b6a7SJames Smart 945fe1bedecSJames Smart out_free_buf: 946fe1bedecSJames Smart /* Give back resources */ 947d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 948fe1bedecSJames Smart 949fe1bedecSJames Smart /* 950fe1bedecSJames Smart * As transport doesn't track completions of responses, if the rsp 951fe1bedecSJames Smart * fails to send, the transport will effectively ignore the rsp 952fe1bedecSJames Smart * and consider the LS done. However, the driver has an active 953fe1bedecSJames Smart * exchange open for the LS - so be sure to abort the exchange 954fe1bedecSJames Smart * if the response isn't sent. 955fe1bedecSJames Smart */ 956fe1bedecSJames Smart lpfc_nvme_unsol_ls_issue_abort(phba, axchg, axchg->sid, axchg->oxid); 957fe1bedecSJames Smart return rc; 958fe1bedecSJames Smart } 959fe1bedecSJames Smart 960fe1bedecSJames Smart /** 961fe1bedecSJames Smart * lpfc_nvmet_xmt_ls_rsp - Transmit NVME LS response 962fe1bedecSJames Smart * @tgtport: pointer to target port that NVME LS is to be transmit from. 963fe1bedecSJames Smart * @ls_rsp: pointer to the transport LS RSP that is to be sent 964fe1bedecSJames Smart * 965fe1bedecSJames Smart * Driver registers this routine to transmit responses for received NVME 966fe1bedecSJames Smart * LS requests. 967fe1bedecSJames Smart * 968fe1bedecSJames Smart * This routine is used to format and send a WQE to transmit a NVME LS 969fe1bedecSJames Smart * Response. The ls_rsp is used to reverse-map the LS to the original 970fe1bedecSJames Smart * NVME LS request sequence, which provides addressing information for 971fe1bedecSJames Smart * the remote port the LS to be sent to, as well as the exchange id 972fe1bedecSJames Smart * that is the LS is bound to. 973fe1bedecSJames Smart * 974fe1bedecSJames Smart * Returns: 975fe1bedecSJames Smart * 0 : if response successfully transmit 976fe1bedecSJames Smart * non-zero : if response failed to transmit, of the form -Exxx. 977fe1bedecSJames Smart **/ 978fe1bedecSJames Smart static int 979fe1bedecSJames Smart lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport, 980fe1bedecSJames Smart struct nvmefc_ls_rsp *ls_rsp) 981fe1bedecSJames Smart { 982fe1bedecSJames Smart struct lpfc_async_xchg_ctx *axchg = 983fe1bedecSJames Smart container_of(ls_rsp, struct lpfc_async_xchg_ctx, ls_rsp); 984fe1bedecSJames Smart struct lpfc_nvmet_tgtport *nvmep = tgtport->private; 985fe1bedecSJames Smart int rc; 986fe1bedecSJames Smart 987fe1bedecSJames Smart if (axchg->phba->pport->load_flag & FC_UNLOADING) 988fe1bedecSJames Smart return -ENODEV; 989fe1bedecSJames Smart 990fe1bedecSJames Smart rc = __lpfc_nvme_xmt_ls_rsp(axchg, ls_rsp, lpfc_nvmet_xmt_ls_rsp_cmp); 991fe1bedecSJames Smart 992fe1bedecSJames Smart if (rc) { 993fe1bedecSJames Smart atomic_inc(&nvmep->xmt_ls_drop); 994fe1bedecSJames Smart /* 995fe1bedecSJames Smart * unless the failure is due to having already sent 996fe1bedecSJames Smart * the response, an abort will be generated for the 997fe1bedecSJames Smart * exchange if the rsp can't be sent. 998fe1bedecSJames Smart */ 999fe1bedecSJames Smart if (rc != -EALREADY) 1000547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 1001fe1bedecSJames Smart return rc; 1002fe1bedecSJames Smart } 1003fe1bedecSJames Smart 1004fe1bedecSJames Smart atomic_inc(&nvmep->xmt_ls_rsp); 1005fe1bedecSJames Smart return 0; 1006d613b6a7SJames Smart } 1007d613b6a7SJames Smart 1008d613b6a7SJames Smart static int 1009d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport, 1010d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp) 1011d613b6a7SJames Smart { 1012d613b6a7SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 10137cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = 10147cacae2aSJames Smart container_of(rsp, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); 1015d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 10166e8e1c14SJames Smart struct lpfc_queue *wq; 1017d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 10186e8e1c14SJames Smart struct lpfc_sli_ring *pring; 10196e8e1c14SJames Smart unsigned long iflags; 1020223b78eaSArnd Bergmann int rc; 1021840eda96SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1022840eda96SJames Smart int id; 1023840eda96SJames Smart #endif 10242b65e182SJames Smart 10251abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) { 10261abcb371SDick Kennedy rc = -ENODEV; 10271abcb371SDick Kennedy goto aerr; 10281abcb371SDick Kennedy } 10291abcb371SDick Kennedy 10302b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1031c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 10322b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 10332b65e182SJames Smart ctxp->ts_nvme_status = ktime_get_ns(); 10342b65e182SJames Smart else 10352b65e182SJames Smart ctxp->ts_nvme_data = ktime_get_ns(); 10362b65e182SJames Smart } 10371fbf9742SJames Smart 10381fbf9742SJames Smart /* Setup the hdw queue if not already set */ 10391fbf9742SJames Smart if (!ctxp->hdwq) 10401fbf9742SJames Smart ctxp->hdwq = &phba->sli4_hba.hdwq[rsp->hwqid]; 10411fbf9742SJames Smart 1042840eda96SJames Smart if (phba->hdwqstat_on & LPFC_CHECK_NVMET_IO) { 1043840eda96SJames Smart id = raw_smp_processor_id(); 1044840eda96SJames Smart this_cpu_inc(phba->sli4_hba.c_stat->xmt_io); 104563df6d63SJames Smart if (rsp->hwqid != id) 104663df6d63SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 10472b65e182SJames Smart "6705 CPU Check OP: " 10482b65e182SJames Smart "cpu %d expect %d\n", 10492b65e182SJames Smart id, rsp->hwqid); 105063df6d63SJames Smart ctxp->cpu = id; /* Setup cpu for cmpl check */ 10512b65e182SJames Smart } 10522b65e182SJames Smart #endif 1053d613b6a7SJames Smart 1054d613b6a7SJames Smart /* Sanity check */ 10557b7f551bSJames Smart if ((ctxp->flag & LPFC_NVME_ABTS_RCV) || 10567b7f551bSJames Smart (ctxp->state == LPFC_NVME_STE_ABORT)) { 1057d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 1058372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 105979d8c4ceSJames Smart "6102 IO oxid x%x aborted\n", 1060d613b6a7SJames Smart ctxp->oxid); 1061a5068b46SJames Smart rc = -ENXIO; 1062d613b6a7SJames Smart goto aerr; 1063d613b6a7SJames Smart } 1064d613b6a7SJames Smart 1065d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp); 1066d613b6a7SJames Smart if (nvmewqeq == NULL) { 1067d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 1068372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 1069d613b6a7SJames Smart "6152 FCP Drop IO x%x: Prep\n", 1070d613b6a7SJames Smart ctxp->oxid); 1071a5068b46SJames Smart rc = -ENXIO; 1072d613b6a7SJames Smart goto aerr; 1073d613b6a7SJames Smart } 1074d613b6a7SJames Smart 1075d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp; 1076d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 1077d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 1078d613b6a7SJames Smart nvmewqeq->iocb_flag |= LPFC_IO_NVMET; 1079d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = rsp->hwqid; 1080d613b6a7SJames Smart 10812b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n", 10822b65e182SJames Smart ctxp->oxid, rsp->op, rsp->rsplen); 10832b65e182SJames Smart 10847b7f551bSJames Smart ctxp->flag |= LPFC_NVME_IO_INP; 10851fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, ctxp->hdwq, nvmewqeq); 1086d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 10872b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1088c8a4ce0bSDick Kennedy if (!ctxp->ts_cmd_nvme) 10892b65e182SJames Smart return 0; 10902b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 10912b65e182SJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 10922b65e182SJames Smart else 10932b65e182SJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 10942b65e182SJames Smart #endif 1095d613b6a7SJames Smart return 0; 1096d613b6a7SJames Smart } 1097d613b6a7SJames Smart 10986e8e1c14SJames Smart if (rc == -EBUSY) { 10996e8e1c14SJames Smart /* 11006e8e1c14SJames Smart * WQ was full, so queue nvmewqeq to be sent after 11016e8e1c14SJames Smart * WQE release CQE 11026e8e1c14SJames Smart */ 11037b7f551bSJames Smart ctxp->flag |= LPFC_NVME_DEFER_WQFULL; 1104c00f62e6SJames Smart wq = ctxp->hdwq->io_wq; 11056e8e1c14SJames Smart pring = wq->pring; 11066e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 11076e8e1c14SJames Smart list_add_tail(&nvmewqeq->list, &wq->wqfull_list); 11086e8e1c14SJames Smart wq->q_flag |= HBA_NVMET_WQFULL; 11096e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 1110411de511SJames Smart atomic_inc(&lpfc_nvmep->defer_wqfull); 11116e8e1c14SJames Smart return 0; 11126e8e1c14SJames Smart } 11136e8e1c14SJames Smart 1114d613b6a7SJames Smart /* Give back resources */ 1115d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 1116372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 1117d613b6a7SJames Smart "6153 FCP Drop IO x%x: Issue: %d\n", 1118d613b6a7SJames Smart ctxp->oxid, rc); 1119d613b6a7SJames Smart 1120d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 1121d613b6a7SJames Smart nvmewqeq->context2 = NULL; 1122d613b6a7SJames Smart nvmewqeq->context3 = NULL; 1123a5068b46SJames Smart rc = -EBUSY; 1124d613b6a7SJames Smart aerr: 1125a5068b46SJames Smart return rc; 1126d613b6a7SJames Smart } 1127d613b6a7SJames Smart 1128d613b6a7SJames Smart static void 1129d613b6a7SJames Smart lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) 1130d613b6a7SJames Smart { 1131d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tport = targetport->private; 1132d613b6a7SJames Smart 1133d613b6a7SJames Smart /* release any threads waiting for the unreg to complete */ 1134c41f5988SEwan D. Milne if (tport->phba->targetport) 1135c41f5988SEwan D. Milne complete(tport->tport_unreg_cmp); 1136d613b6a7SJames Smart } 1137d613b6a7SJames Smart 113819b58d94SJames Smart static void 1139a97ec51bSJames Smart lpfc_nvmet_xmt_fcp_abort(struct nvmet_fc_target_port *tgtport, 1140a97ec51bSJames Smart struct nvmefc_tgt_fcp_req *req) 1141a97ec51bSJames Smart { 1142a97ec51bSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 11437cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = 11447cacae2aSJames Smart container_of(req, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); 1145a97ec51bSJames Smart struct lpfc_hba *phba = ctxp->phba; 11466e8e1c14SJames Smart struct lpfc_queue *wq; 114786c67379SJames Smart unsigned long flags; 1148a97ec51bSJames Smart 11491abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) 11501abcb371SDick Kennedy return; 11511abcb371SDick Kennedy 11521fbf9742SJames Smart if (!ctxp->hdwq) 11531fbf9742SJames Smart ctxp->hdwq = &phba->sli4_hba.hdwq[0]; 11541fbf9742SJames Smart 1155a97ec51bSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 115679d8c4ceSJames Smart "6103 NVMET Abort op: oxid x%x flg x%x ste %d\n", 1157ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 1158a97ec51bSJames Smart 1159ce1b591cSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP ABRT: xri x%x flg x%x ste x%x\n", 1160ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 1161a97ec51bSJames Smart 1162a97ec51bSJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_abort); 1163ce1b591cSJames Smart 116486c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 116586c67379SJames Smart 116686c67379SJames Smart /* Since iaab/iaar are NOT set, we need to check 116786c67379SJames Smart * if the firmware is in process of aborting IO 116886c67379SJames Smart */ 11697b7f551bSJames Smart if (ctxp->flag & (LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP)) { 117086c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 117186c67379SJames Smart return; 117286c67379SJames Smart } 11737b7f551bSJames Smart ctxp->flag |= LPFC_NVME_ABORT_OP; 1174ce1b591cSJames Smart 11757b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_DEFER_WQFULL) { 1176c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 11776e8e1c14SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 11786e8e1c14SJames Smart ctxp->oxid); 1179c00f62e6SJames Smart wq = ctxp->hdwq->io_wq; 11806e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(phba, wq, ctxp); 11816e8e1c14SJames Smart return; 11826e8e1c14SJames Smart } 1183c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 11846e8e1c14SJames Smart 11857b7f551bSJames Smart /* A state of LPFC_NVME_STE_RCV means we have just received 1186ce1b591cSJames Smart * the NVME command and have not started processing it. 1187ce1b591cSJames Smart * (by issuing any IO WQEs on this exchange yet) 1188ce1b591cSJames Smart */ 11897b7f551bSJames Smart if (ctxp->state == LPFC_NVME_STE_RCV) 1190ce1b591cSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 1191a97ec51bSJames Smart ctxp->oxid); 1192a97ec51bSJames Smart else 1193ce1b591cSJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 1194a97ec51bSJames Smart ctxp->oxid); 1195a97ec51bSJames Smart } 1196a97ec51bSJames Smart 1197a97ec51bSJames Smart static void 119819b58d94SJames Smart lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, 119919b58d94SJames Smart struct nvmefc_tgt_fcp_req *rsp) 120019b58d94SJames Smart { 1201547077a4SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 12027cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = 12037cacae2aSJames Smart container_of(rsp, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); 120419b58d94SJames Smart struct lpfc_hba *phba = ctxp->phba; 120519b58d94SJames Smart unsigned long flags; 120619b58d94SJames Smart bool aborting = false; 120719b58d94SJames Smart 1208c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 12097b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_XBUSY) 1210c160c0f8SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 1211c160c0f8SJames Smart "6027 NVMET release with XBUSY flag x%x" 1212c160c0f8SJames Smart " oxid x%x\n", 1213c160c0f8SJames Smart ctxp->flag, ctxp->oxid); 12147b7f551bSJames Smart else if (ctxp->state != LPFC_NVME_STE_DONE && 12157b7f551bSJames Smart ctxp->state != LPFC_NVME_STE_ABORT) 1216372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 1217ce1b591cSJames Smart "6413 NVMET release bad state %d %d oxid x%x\n", 1218ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 1219ce1b591cSJames Smart 12207b7f551bSJames Smart if ((ctxp->flag & LPFC_NVME_ABORT_OP) || 12217b7f551bSJames Smart (ctxp->flag & LPFC_NVME_XBUSY)) { 122219b58d94SJames Smart aborting = true; 122386c67379SJames Smart /* let the abort path do the real release */ 122486c67379SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 122519b58d94SJames Smart } 122619b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 122719b58d94SJames Smart 12289094367aSArnd Bergmann lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", ctxp->oxid, 12299094367aSArnd Bergmann ctxp->state, aborting); 123019b58d94SJames Smart 1231547077a4SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_release); 12327b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_TNOTIFY; 1233547077a4SJames Smart 123486c67379SJames Smart if (aborting) 123586c67379SJames Smart return; 123686c67379SJames Smart 12376c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 123819b58d94SJames Smart } 123919b58d94SJames Smart 124050738420SJames Smart static void 124150738420SJames Smart lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport, 124250738420SJames Smart struct nvmefc_tgt_fcp_req *rsp) 124350738420SJames Smart { 124450738420SJames Smart struct lpfc_nvmet_tgtport *tgtp; 12457cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = 12467cacae2aSJames Smart container_of(rsp, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); 124750738420SJames Smart struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; 124850738420SJames Smart struct lpfc_hba *phba = ctxp->phba; 1249472e146dSJames Smart unsigned long iflag; 1250472e146dSJames Smart 125150738420SJames Smart 125250738420SJames Smart lpfc_nvmeio_data(phba, "NVMET DEFERRCV: xri x%x sz %d CPU %02x\n", 1253d6d189ceSBart Van Assche ctxp->oxid, ctxp->size, raw_smp_processor_id()); 125450738420SJames Smart 12556871e814SJames Smart if (!nvmebuf) { 12566871e814SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 125779d8c4ceSJames Smart "6425 Defer rcv: no buffer oxid x%x: " 12586871e814SJames Smart "flg %x ste %x\n", 12596871e814SJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 12606871e814SJames Smart return; 12616871e814SJames Smart } 12626871e814SJames Smart 126350738420SJames Smart tgtp = phba->targetport->private; 12646871e814SJames Smart if (tgtp) 126550738420SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_defer); 1266411de511SJames Smart 1267411de511SJames Smart /* Free the nvmebuf since a new buffer already replaced it */ 1268cbc5de1bSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 1269472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 1270472e146dSJames Smart ctxp->rqb_buffer = NULL; 1271472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 127250738420SJames Smart } 127350738420SJames Smart 127454840bedSJames Smart /** 127554840bedSJames Smart * lpfc_nvmet_ls_req_cmp - completion handler for a nvme ls request 127654840bedSJames Smart * @phba: Pointer to HBA context object 127754840bedSJames Smart * @cmdwqe: Pointer to driver command WQE object. 127854840bedSJames Smart * @wcqe: Pointer to driver response CQE object. 127954840bedSJames Smart * 128054840bedSJames Smart * This function is the completion handler for NVME LS requests. 128154840bedSJames Smart * The function updates any states and statistics, then calls the 128254840bedSJames Smart * generic completion handler to finish completion of the request. 128354840bedSJames Smart **/ 128454840bedSJames Smart static void 128554840bedSJames Smart lpfc_nvmet_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 128654840bedSJames Smart struct lpfc_wcqe_complete *wcqe) 128754840bedSJames Smart { 128854840bedSJames Smart __lpfc_nvme_ls_req_cmp(phba, cmdwqe->vport, cmdwqe, wcqe); 128954840bedSJames Smart } 129054840bedSJames Smart 129154840bedSJames Smart /** 129254840bedSJames Smart * lpfc_nvmet_ls_req - Issue an Link Service request 1293d3cb79fcSLee Jones * @targetport: pointer to target instance registered with nvmet transport. 1294d3cb79fcSLee Jones * @hosthandle: hosthandle set by the driver in a prior ls_rqst_rcv. 129554840bedSJames Smart * Driver sets this value to the ndlp pointer. 1296d3cb79fcSLee Jones * @pnvme_lsreq: the transport nvme_ls_req structure for the LS 129754840bedSJames Smart * 129854840bedSJames Smart * Driver registers this routine to handle any link service request 129954840bedSJames Smart * from the nvme_fc transport to a remote nvme-aware port. 130054840bedSJames Smart * 130154840bedSJames Smart * Return value : 130254840bedSJames Smart * 0 - Success 130354840bedSJames Smart * non-zero: various error codes, in form of -Exxx 130454840bedSJames Smart **/ 130554840bedSJames Smart static int 130654840bedSJames Smart lpfc_nvmet_ls_req(struct nvmet_fc_target_port *targetport, 130754840bedSJames Smart void *hosthandle, 130854840bedSJames Smart struct nvmefc_ls_req *pnvme_lsreq) 130954840bedSJames Smart { 131054840bedSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmet = targetport->private; 131154840bedSJames Smart struct lpfc_hba *phba; 131254840bedSJames Smart struct lpfc_nodelist *ndlp; 131354840bedSJames Smart int ret; 131454840bedSJames Smart u32 hstate; 131554840bedSJames Smart 131654840bedSJames Smart if (!lpfc_nvmet) 131754840bedSJames Smart return -EINVAL; 131854840bedSJames Smart 131954840bedSJames Smart phba = lpfc_nvmet->phba; 132054840bedSJames Smart if (phba->pport->load_flag & FC_UNLOADING) 132154840bedSJames Smart return -EINVAL; 132254840bedSJames Smart 132354840bedSJames Smart hstate = atomic_read(&lpfc_nvmet->state); 132454840bedSJames Smart if (hstate == LPFC_NVMET_INV_HOST_ACTIVE) 132554840bedSJames Smart return -EACCES; 132654840bedSJames Smart 132754840bedSJames Smart ndlp = (struct lpfc_nodelist *)hosthandle; 132854840bedSJames Smart 132954840bedSJames Smart ret = __lpfc_nvme_ls_req(phba->pport, ndlp, pnvme_lsreq, 133054840bedSJames Smart lpfc_nvmet_ls_req_cmp); 133154840bedSJames Smart 133254840bedSJames Smart return ret; 133354840bedSJames Smart } 133454840bedSJames Smart 133554840bedSJames Smart /** 133654840bedSJames Smart * lpfc_nvmet_ls_abort - Abort a prior NVME LS request 133754840bedSJames Smart * @targetport: Transport targetport, that LS was issued from. 1338d3cb79fcSLee Jones * @hosthandle: hosthandle set by the driver in a prior ls_rqst_rcv. 133954840bedSJames Smart * Driver sets this value to the ndlp pointer. 1340d3cb79fcSLee Jones * @pnvme_lsreq: the transport nvme_ls_req structure for LS to be aborted 134154840bedSJames Smart * 134254840bedSJames Smart * Driver registers this routine to abort an NVME LS request that is 134354840bedSJames Smart * in progress (from the transports perspective). 134454840bedSJames Smart **/ 134554840bedSJames Smart static void 134654840bedSJames Smart lpfc_nvmet_ls_abort(struct nvmet_fc_target_port *targetport, 134754840bedSJames Smart void *hosthandle, 134854840bedSJames Smart struct nvmefc_ls_req *pnvme_lsreq) 134954840bedSJames Smart { 135054840bedSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmet = targetport->private; 135154840bedSJames Smart struct lpfc_hba *phba; 135254840bedSJames Smart struct lpfc_nodelist *ndlp; 135354840bedSJames Smart int ret; 135454840bedSJames Smart 135554840bedSJames Smart phba = lpfc_nvmet->phba; 135654840bedSJames Smart if (phba->pport->load_flag & FC_UNLOADING) 135754840bedSJames Smart return; 135854840bedSJames Smart 135954840bedSJames Smart ndlp = (struct lpfc_nodelist *)hosthandle; 136054840bedSJames Smart 136154840bedSJames Smart ret = __lpfc_nvme_ls_abort(phba->pport, ndlp, pnvme_lsreq); 136254840bedSJames Smart if (!ret) 136354840bedSJames Smart atomic_inc(&lpfc_nvmet->xmt_ls_abort); 136454840bedSJames Smart } 136554840bedSJames Smart 1366ab723121SJames Smart static void 13674c2805aaSJames Smart lpfc_nvmet_host_release(void *hosthandle) 13684c2805aaSJames Smart { 13694c2805aaSJames Smart struct lpfc_nodelist *ndlp = hosthandle; 1370*243156c0SJames Smart struct lpfc_hba *phba = ndlp->phba; 13714c2805aaSJames Smart struct lpfc_nvmet_tgtport *tgtp; 13724c2805aaSJames Smart 13734c2805aaSJames Smart if (!phba->targetport || !phba->targetport->private) 13744c2805aaSJames Smart return; 13754c2805aaSJames Smart 13764c2805aaSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 1377*243156c0SJames Smart "6202 NVMET XPT releasing hosthandle x%px " 1378*243156c0SJames Smart "DID x%x xflags x%x refcnt %d\n", 1379*243156c0SJames Smart hosthandle, ndlp->nlp_DID, ndlp->fc4_xpt_flags, 1380*243156c0SJames Smart kref_read(&ndlp->kref)); 13814c2805aaSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1382*243156c0SJames Smart spin_lock_irq(&ndlp->lock); 1383*243156c0SJames Smart ndlp->fc4_xpt_flags &= ~NLP_XPT_HAS_HH; 1384*243156c0SJames Smart spin_unlock_irq(&ndlp->lock); 1385*243156c0SJames Smart lpfc_nlp_put(ndlp); 13864c2805aaSJames Smart atomic_set(&tgtp->state, 0); 13874c2805aaSJames Smart } 13884c2805aaSJames Smart 13894c2805aaSJames Smart static void 1390ab723121SJames Smart lpfc_nvmet_discovery_event(struct nvmet_fc_target_port *tgtport) 1391ab723121SJames Smart { 1392ab723121SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1393ab723121SJames Smart struct lpfc_hba *phba; 1394ab723121SJames Smart uint32_t rc; 1395ab723121SJames Smart 1396ab723121SJames Smart tgtp = tgtport->private; 1397ab723121SJames Smart phba = tgtp->phba; 1398ab723121SJames Smart 1399ab723121SJames Smart rc = lpfc_issue_els_rscn(phba->pport, 0); 1400372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 1401ab723121SJames Smart "6420 NVMET subsystem change: Notification %s\n", 1402ab723121SJames Smart (rc) ? "Failed" : "Sent"); 1403ab723121SJames Smart } 1404ab723121SJames Smart 1405d613b6a7SJames Smart static struct nvmet_fc_target_template lpfc_tgttemplate = { 1406d613b6a7SJames Smart .targetport_delete = lpfc_nvmet_targetport_delete, 1407d613b6a7SJames Smart .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp, 1408d613b6a7SJames Smart .fcp_op = lpfc_nvmet_xmt_fcp_op, 1409a97ec51bSJames Smart .fcp_abort = lpfc_nvmet_xmt_fcp_abort, 141019b58d94SJames Smart .fcp_req_release = lpfc_nvmet_xmt_fcp_release, 141150738420SJames Smart .defer_rcv = lpfc_nvmet_defer_rcv, 1412ab723121SJames Smart .discovery_event = lpfc_nvmet_discovery_event, 141354840bedSJames Smart .ls_req = lpfc_nvmet_ls_req, 141454840bedSJames Smart .ls_abort = lpfc_nvmet_ls_abort, 14154c2805aaSJames Smart .host_release = lpfc_nvmet_host_release, 1416d613b6a7SJames Smart 1417d613b6a7SJames Smart .max_hw_queues = 1, 1418d613b6a7SJames Smart .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 1419d613b6a7SJames Smart .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 1420d613b6a7SJames Smart .dma_boundary = 0xFFFFFFFF, 1421d613b6a7SJames Smart 1422d613b6a7SJames Smart /* optional features */ 1423d613b6a7SJames Smart .target_features = 0, 1424d613b6a7SJames Smart /* sizes of additional private data for data structures */ 1425d613b6a7SJames Smart .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport), 142654840bedSJames Smart .lsrqst_priv_sz = 0, 1427d613b6a7SJames Smart }; 1428d613b6a7SJames Smart 142939aa23f9SColin Ian King static void 143066d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(struct lpfc_hba *phba, 143166d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop) 14326c621a22SJames Smart { 14336c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf, *next_ctx_buf; 14346c621a22SJames Smart unsigned long flags; 14356c621a22SJames Smart 143666d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, flags); 1437966bb5b7SJames Smart list_for_each_entry_safe(ctx_buf, next_ctx_buf, 143866d7ce93SDick Kennedy &infop->nvmet_ctx_list, list) { 14395e5b511dSJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 14406c621a22SJames Smart list_del_init(&ctx_buf->list); 14415e5b511dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 144266d7ce93SDick Kennedy 144366d7ce93SDick Kennedy __lpfc_clear_active_sglq(phba, ctx_buf->sglq->sli4_lxritag); 14446c621a22SJames Smart ctx_buf->sglq->state = SGL_FREED; 14456c621a22SJames Smart ctx_buf->sglq->ndlp = NULL; 14466c621a22SJames Smart 1447c4031db7SDan Carpenter spin_lock(&phba->sli4_hba.sgl_list_lock); 14486c621a22SJames Smart list_add_tail(&ctx_buf->sglq->list, 14496c621a22SJames Smart &phba->sli4_hba.lpfc_nvmet_sgl_list); 1450c4031db7SDan Carpenter spin_unlock(&phba->sli4_hba.sgl_list_lock); 14516c621a22SJames Smart 14526c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 14536c621a22SJames Smart kfree(ctx_buf->context); 14546c621a22SJames Smart } 145566d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, flags); 1456966bb5b7SJames Smart } 145766d7ce93SDick Kennedy 145866d7ce93SDick Kennedy static void 145966d7ce93SDick Kennedy lpfc_nvmet_cleanup_io_context(struct lpfc_hba *phba) 146066d7ce93SDick Kennedy { 146166d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 146266d7ce93SDick Kennedy int i, j; 146366d7ce93SDick Kennedy 146466d7ce93SDick Kennedy /* The first context list, MRQ 0 CPU 0 */ 146566d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 146666d7ce93SDick Kennedy if (!infop) 146766d7ce93SDick Kennedy return; 146866d7ce93SDick Kennedy 146966d7ce93SDick Kennedy /* Cycle the the entire CPU context list for every MRQ */ 147066d7ce93SDick Kennedy for (i = 0; i < phba->cfg_nvmet_mrq; i++) { 1471222e9239SJames Smart for_each_present_cpu(j) { 1472222e9239SJames Smart infop = lpfc_get_ctx_list(phba, j, i); 147366d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(phba, infop); 147466d7ce93SDick Kennedy } 147566d7ce93SDick Kennedy } 147666d7ce93SDick Kennedy kfree(phba->sli4_hba.nvmet_ctx_info); 147766d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = NULL; 14786c621a22SJames Smart } 14796c621a22SJames Smart 148039aa23f9SColin Ian King static int 14816c621a22SJames Smart lpfc_nvmet_setup_io_context(struct lpfc_hba *phba) 14826c621a22SJames Smart { 14836c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 14846c621a22SJames Smart struct lpfc_iocbq *nvmewqe; 14856c621a22SJames Smart union lpfc_wqe128 *wqe; 148666d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *last_infop; 148766d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 1488222e9239SJames Smart int i, j, idx, cpu; 14896c621a22SJames Smart 14906c621a22SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME, 14916c621a22SJames Smart "6403 Allocate NVMET resources for %d XRIs\n", 14926c621a22SJames Smart phba->sli4_hba.nvmet_xri_cnt); 14936c621a22SJames Smart 149466d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = kcalloc( 1495222e9239SJames Smart phba->sli4_hba.num_possible_cpu * phba->cfg_nvmet_mrq, 149666d7ce93SDick Kennedy sizeof(struct lpfc_nvmet_ctx_info), GFP_KERNEL); 149766d7ce93SDick Kennedy if (!phba->sli4_hba.nvmet_ctx_info) { 1498372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 149966d7ce93SDick Kennedy "6419 Failed allocate memory for " 150066d7ce93SDick Kennedy "nvmet context lists\n"); 150166d7ce93SDick Kennedy return -ENOMEM; 150266d7ce93SDick Kennedy } 150366d7ce93SDick Kennedy 150466d7ce93SDick Kennedy /* 150566d7ce93SDick Kennedy * Assuming X CPUs in the system, and Y MRQs, allocate some 150666d7ce93SDick Kennedy * lpfc_nvmet_ctx_info structures as follows: 150766d7ce93SDick Kennedy * 150866d7ce93SDick Kennedy * cpu0/mrq0 cpu1/mrq0 ... cpuX/mrq0 150966d7ce93SDick Kennedy * cpu0/mrq1 cpu1/mrq1 ... cpuX/mrq1 151066d7ce93SDick Kennedy * ... 151166d7ce93SDick Kennedy * cpuX/mrqY cpuX/mrqY ... cpuX/mrqY 151266d7ce93SDick Kennedy * 151366d7ce93SDick Kennedy * Each line represents a MRQ "silo" containing an entry for 151466d7ce93SDick Kennedy * every CPU. 151566d7ce93SDick Kennedy * 151666d7ce93SDick Kennedy * MRQ X is initially assumed to be associated with CPU X, thus 151766d7ce93SDick Kennedy * contexts are initially distributed across all MRQs using 151866d7ce93SDick Kennedy * the MRQ index (N) as follows cpuN/mrqN. When contexts are 151966d7ce93SDick Kennedy * freed, the are freed to the MRQ silo based on the CPU number 152066d7ce93SDick Kennedy * of the IO completion. Thus a context that was allocated for MRQ A 152166d7ce93SDick Kennedy * whose IO completed on CPU B will be freed to cpuB/mrqA. 152266d7ce93SDick Kennedy */ 1523222e9239SJames Smart for_each_possible_cpu(i) { 152466d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 1525222e9239SJames Smart infop = lpfc_get_ctx_list(phba, i, j); 152666d7ce93SDick Kennedy INIT_LIST_HEAD(&infop->nvmet_ctx_list); 152766d7ce93SDick Kennedy spin_lock_init(&infop->nvmet_ctx_list_lock); 152866d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt = 0; 152966d7ce93SDick Kennedy } 153066d7ce93SDick Kennedy } 153166d7ce93SDick Kennedy 153266d7ce93SDick Kennedy /* 153366d7ce93SDick Kennedy * Setup the next CPU context info ptr for each MRQ. 153466d7ce93SDick Kennedy * MRQ 0 will cycle thru CPUs 0 - X separately from 153566d7ce93SDick Kennedy * MRQ 1 cycling thru CPUs 0 - X, and so on. 153666d7ce93SDick Kennedy */ 153766d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 1538222e9239SJames Smart last_infop = lpfc_get_ctx_list(phba, 1539222e9239SJames Smart cpumask_first(cpu_present_mask), 1540222e9239SJames Smart j); 1541222e9239SJames Smart for (i = phba->sli4_hba.num_possible_cpu - 1; i >= 0; i--) { 154266d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, i, j); 154366d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu = last_infop; 154466d7ce93SDick Kennedy last_infop = infop; 154566d7ce93SDick Kennedy } 154666d7ce93SDick Kennedy } 154766d7ce93SDick Kennedy 15486c621a22SJames Smart /* For all nvmet xris, allocate resources needed to process a 15496c621a22SJames Smart * received command on a per xri basis. 15506c621a22SJames Smart */ 155166d7ce93SDick Kennedy idx = 0; 1552222e9239SJames Smart cpu = cpumask_first(cpu_present_mask); 15536c621a22SJames Smart for (i = 0; i < phba->sli4_hba.nvmet_xri_cnt; i++) { 15546c621a22SJames Smart ctx_buf = kzalloc(sizeof(*ctx_buf), GFP_KERNEL); 15556c621a22SJames Smart if (!ctx_buf) { 1556372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 15576c621a22SJames Smart "6404 Ran out of memory for NVMET\n"); 15586c621a22SJames Smart return -ENOMEM; 15596c621a22SJames Smart } 15606c621a22SJames Smart 15616c621a22SJames Smart ctx_buf->context = kzalloc(sizeof(*ctx_buf->context), 15626c621a22SJames Smart GFP_KERNEL); 15636c621a22SJames Smart if (!ctx_buf->context) { 15646c621a22SJames Smart kfree(ctx_buf); 1565372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 15666c621a22SJames Smart "6405 Ran out of NVMET " 15676c621a22SJames Smart "context memory\n"); 15686c621a22SJames Smart return -ENOMEM; 15696c621a22SJames Smart } 15706c621a22SJames Smart ctx_buf->context->ctxbuf = ctx_buf; 15717b7f551bSJames Smart ctx_buf->context->state = LPFC_NVME_STE_FREE; 15726c621a22SJames Smart 15736c621a22SJames Smart ctx_buf->iocbq = lpfc_sli_get_iocbq(phba); 15746c621a22SJames Smart if (!ctx_buf->iocbq) { 15756c621a22SJames Smart kfree(ctx_buf->context); 15766c621a22SJames Smart kfree(ctx_buf); 1577372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 15786c621a22SJames Smart "6406 Ran out of NVMET iocb/WQEs\n"); 15796c621a22SJames Smart return -ENOMEM; 15806c621a22SJames Smart } 15816c621a22SJames Smart ctx_buf->iocbq->iocb_flag = LPFC_IO_NVMET; 15826c621a22SJames Smart nvmewqe = ctx_buf->iocbq; 1583205e8240SJames Smart wqe = &nvmewqe->wqe; 1584bd3061baSJames Smart 15856c621a22SJames Smart /* Initialize WQE */ 15866c621a22SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 15876c621a22SJames Smart 15886c621a22SJames Smart ctx_buf->iocbq->context1 = NULL; 15896c621a22SJames Smart spin_lock(&phba->sli4_hba.sgl_list_lock); 15906c621a22SJames Smart ctx_buf->sglq = __lpfc_sli_get_nvmet_sglq(phba, ctx_buf->iocbq); 15916c621a22SJames Smart spin_unlock(&phba->sli4_hba.sgl_list_lock); 15926c621a22SJames Smart if (!ctx_buf->sglq) { 15936c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 15946c621a22SJames Smart kfree(ctx_buf->context); 15956c621a22SJames Smart kfree(ctx_buf); 1596372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 15976c621a22SJames Smart "6407 Ran out of NVMET XRIs\n"); 15986c621a22SJames Smart return -ENOMEM; 15996c621a22SJames Smart } 1600472e146dSJames Smart INIT_WORK(&ctx_buf->defer_work, lpfc_nvmet_fcp_rqst_defer_work); 160166d7ce93SDick Kennedy 160266d7ce93SDick Kennedy /* 160366d7ce93SDick Kennedy * Add ctx to MRQidx context list. Our initial assumption 160466d7ce93SDick Kennedy * is MRQidx will be associated with CPUidx. This association 160566d7ce93SDick Kennedy * can change on the fly. 160666d7ce93SDick Kennedy */ 1607222e9239SJames Smart infop = lpfc_get_ctx_list(phba, cpu, idx); 160866d7ce93SDick Kennedy spin_lock(&infop->nvmet_ctx_list_lock); 160966d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 161066d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 161166d7ce93SDick Kennedy spin_unlock(&infop->nvmet_ctx_list_lock); 161266d7ce93SDick Kennedy 161366d7ce93SDick Kennedy /* Spread ctx structures evenly across all MRQs */ 161466d7ce93SDick Kennedy idx++; 1615222e9239SJames Smart if (idx >= phba->cfg_nvmet_mrq) { 161666d7ce93SDick Kennedy idx = 0; 1617222e9239SJames Smart cpu = cpumask_first(cpu_present_mask); 1618222e9239SJames Smart continue; 1619222e9239SJames Smart } 1620222e9239SJames Smart cpu = cpumask_next(cpu, cpu_present_mask); 1621222e9239SJames Smart if (cpu == nr_cpu_ids) 1622222e9239SJames Smart cpu = cpumask_first(cpu_present_mask); 1623222e9239SJames Smart 16246c621a22SJames Smart } 162566d7ce93SDick Kennedy 1626222e9239SJames Smart for_each_present_cpu(i) { 16272879265fSJames Smart for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 16282879265fSJames Smart infop = lpfc_get_ctx_list(phba, i, j); 162966d7ce93SDick Kennedy lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 163066d7ce93SDick Kennedy "6408 TOTAL NVMET ctx for CPU %d " 163132350664SJames Smart "MRQ %d: cnt %d nextcpu x%px\n", 163266d7ce93SDick Kennedy i, j, infop->nvmet_ctx_list_cnt, 163366d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu); 163466d7ce93SDick Kennedy } 163566d7ce93SDick Kennedy } 16366c621a22SJames Smart return 0; 16376c621a22SJames Smart } 16386c621a22SJames Smart 1639d613b6a7SJames Smart int 1640d613b6a7SJames Smart lpfc_nvmet_create_targetport(struct lpfc_hba *phba) 1641d613b6a7SJames Smart { 1642d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1643d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1644d613b6a7SJames Smart struct nvmet_fc_port_info pinfo; 16456c621a22SJames Smart int error; 1646d613b6a7SJames Smart 1647d613b6a7SJames Smart if (phba->targetport) 1648d613b6a7SJames Smart return 0; 1649d613b6a7SJames Smart 16506c621a22SJames Smart error = lpfc_nvmet_setup_io_context(phba); 16516c621a22SJames Smart if (error) 16526c621a22SJames Smart return error; 16536c621a22SJames Smart 1654d613b6a7SJames Smart memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info)); 1655d613b6a7SJames Smart pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 1656d613b6a7SJames Smart pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 1657d613b6a7SJames Smart pinfo.port_id = vport->fc_myDID; 1658d613b6a7SJames Smart 16595b9e70b2SJames Smart /* We need to tell the transport layer + 1 because it takes page 16605b9e70b2SJames Smart * alignment into account. When space for the SGL is allocated we 16615b9e70b2SJames Smart * allocate + 3, one for cmd, one for rsp and one for this alignment 16624d4c4a4aSJames Smart */ 16634d4c4a4aSJames Smart lpfc_tgttemplate.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 1664cdb42becSJames Smart lpfc_tgttemplate.max_hw_queues = phba->cfg_hdw_queue; 1665f485c18dSDick Kennedy lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP; 1666d613b6a7SJames Smart 16677d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1668d613b6a7SJames Smart error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 1669d613b6a7SJames Smart &phba->pcidev->dev, 1670d613b6a7SJames Smart &phba->targetport); 1671166d7211SJames Smart #else 16726c621a22SJames Smart error = -ENOENT; 1673166d7211SJames Smart #endif 1674d613b6a7SJames Smart if (error) { 1675372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 1676e7981a2cSDick Kennedy "6025 Cannot register NVME targetport x%x: " 1677e7981a2cSDick Kennedy "portnm %llx nodenm %llx segs %d qs %d\n", 1678e7981a2cSDick Kennedy error, 1679e7981a2cSDick Kennedy pinfo.port_name, pinfo.node_name, 1680e7981a2cSDick Kennedy lpfc_tgttemplate.max_sgl_segments, 1681e7981a2cSDick Kennedy lpfc_tgttemplate.max_hw_queues); 1682d613b6a7SJames Smart phba->targetport = NULL; 1683e7981a2cSDick Kennedy phba->nvmet_support = 0; 16846c621a22SJames Smart 16856c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 16866c621a22SJames Smart 1687d613b6a7SJames Smart } else { 1688d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *) 1689d613b6a7SJames Smart phba->targetport->private; 1690d613b6a7SJames Smart tgtp->phba = phba; 1691d613b6a7SJames Smart 1692d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1693d613b6a7SJames Smart "6026 Registered NVME " 169432350664SJames Smart "targetport: x%px, private x%px " 1695e7981a2cSDick Kennedy "portnm %llx nodenm %llx segs %d qs %d\n", 1696d613b6a7SJames Smart phba->targetport, tgtp, 1697e7981a2cSDick Kennedy pinfo.port_name, pinfo.node_name, 1698e7981a2cSDick Kennedy lpfc_tgttemplate.max_sgl_segments, 1699e7981a2cSDick Kennedy lpfc_tgttemplate.max_hw_queues); 1700d613b6a7SJames Smart 1701d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_in, 0); 1702d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_out, 0); 1703d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_drop, 0); 1704d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_abort, 0); 1705547077a4SJames Smart atomic_set(&tgtp->xmt_ls_abort_cmpl, 0); 1706d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp, 0); 1707d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_drop, 0); 1708d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_error, 0); 17094b056682SJames Smart atomic_set(&tgtp->xmt_ls_rsp_xb_set, 0); 17104b056682SJames Smart atomic_set(&tgtp->xmt_ls_rsp_aborted, 0); 1711d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0); 1712d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_in, 0); 1713d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_out, 0); 1714d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_drop, 0); 1715d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_drop, 0); 1716d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read_rsp, 0); 1717d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read, 0); 1718d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_write, 0); 1719d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp, 0); 1720547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_release, 0); 1721d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0); 1722d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_error, 0); 17234b056682SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_xb_set, 0); 17244b056682SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_aborted, 0); 1725d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_drop, 0); 17264b056682SJames Smart atomic_set(&tgtp->xmt_fcp_xri_abort_cqe, 0); 1727547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort, 0); 1728547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0); 1729547077a4SJames Smart atomic_set(&tgtp->xmt_abort_unsol, 0); 1730547077a4SJames Smart atomic_set(&tgtp->xmt_abort_sol, 0); 1731d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp, 0); 1732d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp_error, 0); 1733411de511SJames Smart atomic_set(&tgtp->defer_ctx, 0); 1734411de511SJames Smart atomic_set(&tgtp->defer_fod, 0); 1735411de511SJames Smart atomic_set(&tgtp->defer_wqfull, 0); 1736d613b6a7SJames Smart } 1737d613b6a7SJames Smart return error; 1738d613b6a7SJames Smart } 1739d613b6a7SJames Smart 1740d613b6a7SJames Smart int 1741d613b6a7SJames Smart lpfc_nvmet_update_targetport(struct lpfc_hba *phba) 1742d613b6a7SJames Smart { 1743d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1744d613b6a7SJames Smart 1745d613b6a7SJames Smart if (!phba->targetport) 1746d613b6a7SJames Smart return 0; 1747d613b6a7SJames Smart 1748d613b6a7SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 174932350664SJames Smart "6007 Update NVMET port x%px did x%x\n", 1750d613b6a7SJames Smart phba->targetport, vport->fc_myDID); 1751d613b6a7SJames Smart 1752d613b6a7SJames Smart phba->targetport->port_id = vport->fc_myDID; 1753d613b6a7SJames Smart return 0; 1754d613b6a7SJames Smart } 1755d613b6a7SJames Smart 1756318083adSJames Smart /** 1757318083adSJames Smart * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort 1758318083adSJames Smart * @phba: pointer to lpfc hba data structure. 1759318083adSJames Smart * @axri: pointer to the nvmet xri abort wcqe structure. 1760318083adSJames Smart * 1761318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 1762318083adSJames Smart * NVMET aborted xri. 1763318083adSJames Smart **/ 1764318083adSJames Smart void 1765318083adSJames Smart lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba, 1766318083adSJames Smart struct sli4_wcqe_xri_aborted *axri) 1767318083adSJames Smart { 176832b93865SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 176986c67379SJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 177086c67379SJames Smart uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 17717cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, *next_ctxp; 17724b056682SJames Smart struct lpfc_nvmet_tgtport *tgtp; 177379d8c4ceSJames Smart struct nvmefc_tgt_fcp_req *req = NULL; 177486c67379SJames Smart struct lpfc_nodelist *ndlp; 177586c67379SJames Smart unsigned long iflag = 0; 177686c67379SJames Smart int rrq_empty = 0; 177786c67379SJames Smart bool released = false; 177886c67379SJames Smart 177986c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 178086c67379SJames Smart "6317 XB aborted xri x%x rxid x%x\n", xri, rxid); 178186c67379SJames Smart 178286c67379SJames Smart if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) 178386c67379SJames Smart return; 17844b056682SJames Smart 17854b056682SJames Smart if (phba->targetport) { 17864b056682SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 17874b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_xri_abort_cqe); 17884b056682SJames Smart } 17894b056682SJames Smart 179086c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 17915e5b511dSJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 179286c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 179386c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 179486c67379SJames Smart list) { 17956c621a22SJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 179686c67379SJames Smart continue; 179786c67379SJames Smart 1798c160c0f8SJames Smart spin_lock(&ctxp->ctxlock); 179986c67379SJames Smart /* Check if we already received a free context call 180086c67379SJames Smart * and we have completed processing an abort situation. 180186c67379SJames Smart */ 18027b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_CTX_RLS && 18037b7f551bSJames Smart !(ctxp->flag & LPFC_NVME_ABORT_OP)) { 180479d8c4ceSJames Smart list_del_init(&ctxp->list); 180586c67379SJames Smart released = true; 180686c67379SJames Smart } 18077b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_XBUSY; 1808c160c0f8SJames Smart spin_unlock(&ctxp->ctxlock); 18095e5b511dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 181086c67379SJames Smart 181186c67379SJames Smart rrq_empty = list_empty(&phba->active_rrq_list); 181286c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 181386c67379SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1814307e3380SJames Smart if (ndlp && 181586c67379SJames Smart (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || 181686c67379SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 181786c67379SJames Smart lpfc_set_rrq_active(phba, ndlp, 18186c621a22SJames Smart ctxp->ctxbuf->sglq->sli4_lxritag, 181986c67379SJames Smart rxid, 1); 182086c67379SJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 182186c67379SJames Smart } 182286c67379SJames Smart 182386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 182479d8c4ceSJames Smart "6318 XB aborted oxid x%x flg x%x (%x)\n", 182586c67379SJames Smart ctxp->oxid, ctxp->flag, released); 182686c67379SJames Smart if (released) 18276c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 18286c621a22SJames Smart 182986c67379SJames Smart if (rrq_empty) 183086c67379SJames Smart lpfc_worker_wake_up(phba); 183186c67379SJames Smart return; 183286c67379SJames Smart } 18335e5b511dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 183486c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 183579d8c4ceSJames Smart 183679d8c4ceSJames Smart ctxp = lpfc_nvmet_get_ctx_for_xri(phba, xri); 183779d8c4ceSJames Smart if (ctxp) { 183879d8c4ceSJames Smart /* 183979d8c4ceSJames Smart * Abort already done by FW, so BA_ACC sent. 184079d8c4ceSJames Smart * However, the transport may be unaware. 184179d8c4ceSJames Smart */ 184279d8c4ceSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 184379d8c4ceSJames Smart "6323 NVMET Rcv ABTS xri x%x ctxp state x%x " 184479d8c4ceSJames Smart "flag x%x oxid x%x rxid x%x\n", 184579d8c4ceSJames Smart xri, ctxp->state, ctxp->flag, ctxp->oxid, 184679d8c4ceSJames Smart rxid); 184779d8c4ceSJames Smart 184879d8c4ceSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 18497b7f551bSJames Smart ctxp->flag |= LPFC_NVME_ABTS_RCV; 18507b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_ABORT; 185179d8c4ceSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 185279d8c4ceSJames Smart 185379d8c4ceSJames Smart lpfc_nvmeio_data(phba, 185479d8c4ceSJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 185501d53c04SJames Smart xri, raw_smp_processor_id(), 0); 185679d8c4ceSJames Smart 18577cacae2aSJames Smart req = &ctxp->hdlrctx.fcp_req; 185879d8c4ceSJames Smart if (req) 185979d8c4ceSJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, req); 186079d8c4ceSJames Smart } 186132b93865SJames Smart #endif 186286c67379SJames Smart } 186386c67379SJames Smart 186486c67379SJames Smart int 186586c67379SJames Smart lpfc_nvmet_rcv_unsol_abort(struct lpfc_vport *vport, 186686c67379SJames Smart struct fc_frame_header *fc_hdr) 186786c67379SJames Smart { 186886c67379SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 186986c67379SJames Smart struct lpfc_hba *phba = vport->phba; 18707cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, *next_ctxp; 187186c67379SJames Smart struct nvmefc_tgt_fcp_req *rsp; 187232b93865SJames Smart uint32_t sid; 187379d8c4ceSJames Smart uint16_t oxid, xri; 187486c67379SJames Smart unsigned long iflag = 0; 187586c67379SJames Smart 187632b93865SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 187779d8c4ceSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 187886c67379SJames Smart 187986c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 18805e5b511dSJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 188186c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 188286c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 188386c67379SJames Smart list) { 188479d8c4ceSJames Smart if (ctxp->oxid != oxid || ctxp->sid != sid) 188586c67379SJames Smart continue; 188686c67379SJames Smart 188732b93865SJames Smart xri = ctxp->ctxbuf->sglq->sli4_xritag; 188832b93865SJames Smart 18895e5b511dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 189086c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 189186c67379SJames Smart 189286c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 18937b7f551bSJames Smart ctxp->flag |= LPFC_NVME_ABTS_RCV; 189486c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 189586c67379SJames Smart 189686c67379SJames Smart lpfc_nvmeio_data(phba, 189786c67379SJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 1898d6d189ceSBart Van Assche xri, raw_smp_processor_id(), 0); 189986c67379SJames Smart 190086c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 190186c67379SJames Smart "6319 NVMET Rcv ABTS:acc xri x%x\n", xri); 190286c67379SJames Smart 19037cacae2aSJames Smart rsp = &ctxp->hdlrctx.fcp_req; 190486c67379SJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, rsp); 190586c67379SJames Smart 190686c67379SJames Smart /* Respond with BA_ACC accordingly */ 190786c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 190886c67379SJames Smart return 0; 190986c67379SJames Smart } 19105e5b511dSJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 191186c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 191286c67379SJames Smart 191379d8c4ceSJames Smart /* check the wait list */ 191479d8c4ceSJames Smart if (phba->sli4_hba.nvmet_io_wait_cnt) { 191579d8c4ceSJames Smart struct rqb_dmabuf *nvmebuf; 191679d8c4ceSJames Smart struct fc_frame_header *fc_hdr_tmp; 191779d8c4ceSJames Smart u32 sid_tmp; 191879d8c4ceSJames Smart u16 oxid_tmp; 191979d8c4ceSJames Smart bool found = false; 192079d8c4ceSJames Smart 192179d8c4ceSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 192279d8c4ceSJames Smart 192379d8c4ceSJames Smart /* match by oxid and s_id */ 192479d8c4ceSJames Smart list_for_each_entry(nvmebuf, 192579d8c4ceSJames Smart &phba->sli4_hba.lpfc_nvmet_io_wait_list, 192679d8c4ceSJames Smart hbuf.list) { 192779d8c4ceSJames Smart fc_hdr_tmp = (struct fc_frame_header *) 192879d8c4ceSJames Smart (nvmebuf->hbuf.virt); 192979d8c4ceSJames Smart oxid_tmp = be16_to_cpu(fc_hdr_tmp->fh_ox_id); 193079d8c4ceSJames Smart sid_tmp = sli4_sid_from_fc_hdr(fc_hdr_tmp); 193179d8c4ceSJames Smart if (oxid_tmp != oxid || sid_tmp != sid) 193279d8c4ceSJames Smart continue; 193386c67379SJames Smart 193486c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 193579d8c4ceSJames Smart "6321 NVMET Rcv ABTS oxid x%x from x%x " 193679d8c4ceSJames Smart "is waiting for a ctxp\n", 193779d8c4ceSJames Smart oxid, sid); 193879d8c4ceSJames Smart 193979d8c4ceSJames Smart list_del_init(&nvmebuf->hbuf.list); 194079d8c4ceSJames Smart phba->sli4_hba.nvmet_io_wait_cnt--; 194179d8c4ceSJames Smart found = true; 194279d8c4ceSJames Smart break; 194379d8c4ceSJames Smart } 194479d8c4ceSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 194579d8c4ceSJames Smart iflag); 194679d8c4ceSJames Smart 194779d8c4ceSJames Smart /* free buffer since already posted a new DMA buffer to RQ */ 194879d8c4ceSJames Smart if (found) { 194979d8c4ceSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 195079d8c4ceSJames Smart /* Respond with BA_ACC accordingly */ 195179d8c4ceSJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 195279d8c4ceSJames Smart return 0; 195379d8c4ceSJames Smart } 195479d8c4ceSJames Smart } 195579d8c4ceSJames Smart 195679d8c4ceSJames Smart /* check active list */ 195779d8c4ceSJames Smart ctxp = lpfc_nvmet_get_ctx_for_oxid(phba, oxid, sid); 195879d8c4ceSJames Smart if (ctxp) { 195979d8c4ceSJames Smart xri = ctxp->ctxbuf->sglq->sli4_xritag; 196079d8c4ceSJames Smart 196179d8c4ceSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 19627b7f551bSJames Smart ctxp->flag |= (LPFC_NVME_ABTS_RCV | LPFC_NVME_ABORT_OP); 196379d8c4ceSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 196479d8c4ceSJames Smart 196579d8c4ceSJames Smart lpfc_nvmeio_data(phba, 196679d8c4ceSJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 196779d8c4ceSJames Smart xri, raw_smp_processor_id(), 0); 196879d8c4ceSJames Smart 196979d8c4ceSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 197079d8c4ceSJames Smart "6322 NVMET Rcv ABTS:acc oxid x%x xri x%x " 197179d8c4ceSJames Smart "flag x%x state x%x\n", 197279d8c4ceSJames Smart ctxp->oxid, xri, ctxp->flag, ctxp->state); 197379d8c4ceSJames Smart 19747b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_TNOTIFY) { 197579d8c4ceSJames Smart /* Notify the transport */ 197679d8c4ceSJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, 19777cacae2aSJames Smart &ctxp->hdlrctx.fcp_req); 197879d8c4ceSJames Smart } else { 19796594d31bSJames Smart cancel_work_sync(&ctxp->ctxbuf->defer_work); 198079d8c4ceSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 198179d8c4ceSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 198279d8c4ceSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 198379d8c4ceSJames Smart } 198479d8c4ceSJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 198579d8c4ceSJames Smart ctxp->oxid); 198679d8c4ceSJames Smart 19876594d31bSJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 198879d8c4ceSJames Smart return 0; 198979d8c4ceSJames Smart } 199079d8c4ceSJames Smart 199179d8c4ceSJames Smart lpfc_nvmeio_data(phba, "NVMET ABTS RCV: oxid x%x CPU %02x rjt %d\n", 199279d8c4ceSJames Smart oxid, raw_smp_processor_id(), 1); 199379d8c4ceSJames Smart 199479d8c4ceSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 199579d8c4ceSJames Smart "6320 NVMET Rcv ABTS:rjt oxid x%x\n", oxid); 199686c67379SJames Smart 199786c67379SJames Smart /* Respond with BA_RJT accordingly */ 199886c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 0); 199986c67379SJames Smart #endif 2000b06e13c3SJens Axboe return 0; 2001318083adSJames Smart } 2002318083adSJames Smart 20036e8e1c14SJames Smart static void 20046e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(struct lpfc_hba *phba, struct lpfc_queue *wq, 20057cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp) 20066e8e1c14SJames Smart { 20076e8e1c14SJames Smart struct lpfc_sli_ring *pring; 20086e8e1c14SJames Smart struct lpfc_iocbq *nvmewqeq; 20096e8e1c14SJames Smart struct lpfc_iocbq *next_nvmewqeq; 20106e8e1c14SJames Smart unsigned long iflags; 20116e8e1c14SJames Smart struct lpfc_wcqe_complete wcqe; 20126e8e1c14SJames Smart struct lpfc_wcqe_complete *wcqep; 20136e8e1c14SJames Smart 20146e8e1c14SJames Smart pring = wq->pring; 20156e8e1c14SJames Smart wcqep = &wcqe; 20166e8e1c14SJames Smart 20176e8e1c14SJames Smart /* Fake an ABORT error code back to cmpl routine */ 20186e8e1c14SJames Smart memset(wcqep, 0, sizeof(struct lpfc_wcqe_complete)); 20196e8e1c14SJames Smart bf_set(lpfc_wcqe_c_status, wcqep, IOSTAT_LOCAL_REJECT); 20206e8e1c14SJames Smart wcqep->parameter = IOERR_ABORT_REQUESTED; 20216e8e1c14SJames Smart 20226e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 20236e8e1c14SJames Smart list_for_each_entry_safe(nvmewqeq, next_nvmewqeq, 20246e8e1c14SJames Smart &wq->wqfull_list, list) { 20256e8e1c14SJames Smart if (ctxp) { 20266e8e1c14SJames Smart /* Checking for a specific IO to flush */ 20276e8e1c14SJames Smart if (nvmewqeq->context2 == ctxp) { 20286e8e1c14SJames Smart list_del(&nvmewqeq->list); 20296e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, 20306e8e1c14SJames Smart iflags); 20316e8e1c14SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(phba, nvmewqeq, 20326e8e1c14SJames Smart wcqep); 20336e8e1c14SJames Smart return; 20346e8e1c14SJames Smart } 20356e8e1c14SJames Smart continue; 20366e8e1c14SJames Smart } else { 20376e8e1c14SJames Smart /* Flush all IOs */ 20386e8e1c14SJames Smart list_del(&nvmewqeq->list); 20396e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 20406e8e1c14SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(phba, nvmewqeq, wcqep); 20416e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 20426e8e1c14SJames Smart } 20436e8e1c14SJames Smart } 20446e8e1c14SJames Smart if (!ctxp) 20456e8e1c14SJames Smart wq->q_flag &= ~HBA_NVMET_WQFULL; 20466e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 20476e8e1c14SJames Smart } 20486e8e1c14SJames Smart 20496e8e1c14SJames Smart void 20506e8e1c14SJames Smart lpfc_nvmet_wqfull_process(struct lpfc_hba *phba, 20516e8e1c14SJames Smart struct lpfc_queue *wq) 20526e8e1c14SJames Smart { 20536e8e1c14SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 20546e8e1c14SJames Smart struct lpfc_sli_ring *pring; 20556e8e1c14SJames Smart struct lpfc_iocbq *nvmewqeq; 20567cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 20576e8e1c14SJames Smart unsigned long iflags; 20586e8e1c14SJames Smart int rc; 20596e8e1c14SJames Smart 20606e8e1c14SJames Smart /* 20616e8e1c14SJames Smart * Some WQE slots are available, so try to re-issue anything 20626e8e1c14SJames Smart * on the WQ wqfull_list. 20636e8e1c14SJames Smart */ 20646e8e1c14SJames Smart pring = wq->pring; 20656e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 20666e8e1c14SJames Smart while (!list_empty(&wq->wqfull_list)) { 20676e8e1c14SJames Smart list_remove_head(&wq->wqfull_list, nvmewqeq, struct lpfc_iocbq, 20686e8e1c14SJames Smart list); 20696e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 20707cacae2aSJames Smart ctxp = (struct lpfc_async_xchg_ctx *)nvmewqeq->context2; 20711fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, ctxp->hdwq, nvmewqeq); 20726e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 20736e8e1c14SJames Smart if (rc == -EBUSY) { 20746e8e1c14SJames Smart /* WQ was full again, so put it back on the list */ 20756e8e1c14SJames Smart list_add(&nvmewqeq->list, &wq->wqfull_list); 20766e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 20776e8e1c14SJames Smart return; 20786e8e1c14SJames Smart } 207979d8c4ceSJames Smart if (rc == WQE_SUCCESS) { 208079d8c4ceSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 208179d8c4ceSJames Smart if (ctxp->ts_cmd_nvme) { 20827cacae2aSJames Smart if (ctxp->hdlrctx.fcp_req.op == NVMET_FCOP_RSP) 208379d8c4ceSJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 208479d8c4ceSJames Smart else 208579d8c4ceSJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 208679d8c4ceSJames Smart } 208779d8c4ceSJames Smart #endif 208879d8c4ceSJames Smart } else { 208979d8c4ceSJames Smart WARN_ON(rc); 209079d8c4ceSJames Smart } 20916e8e1c14SJames Smart } 20926e8e1c14SJames Smart wq->q_flag &= ~HBA_NVMET_WQFULL; 20936e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 20946e8e1c14SJames Smart 20956e8e1c14SJames Smart #endif 20966e8e1c14SJames Smart } 20976e8e1c14SJames Smart 2098d613b6a7SJames Smart void 2099d613b6a7SJames Smart lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 2100d613b6a7SJames Smart { 21017d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 2102d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 21036e8e1c14SJames Smart struct lpfc_queue *wq; 21046e8e1c14SJames Smart uint32_t qidx; 2105c41f5988SEwan D. Milne DECLARE_COMPLETION_ONSTACK(tport_unreg_cmp); 2106d613b6a7SJames Smart 2107d613b6a7SJames Smart if (phba->nvmet_support == 0) 2108d613b6a7SJames Smart return; 2109d613b6a7SJames Smart if (phba->targetport) { 2110d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2111cdb42becSJames Smart for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { 2112c00f62e6SJames Smart wq = phba->sli4_hba.hdwq[qidx].io_wq; 21136e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(phba, wq, NULL); 21146e8e1c14SJames Smart } 2115c41f5988SEwan D. Milne tgtp->tport_unreg_cmp = &tport_unreg_cmp; 2116d613b6a7SJames Smart nvmet_fc_unregister_targetport(phba->targetport); 2117af6de8c6SEwan D. Milne if (!wait_for_completion_timeout(&tport_unreg_cmp, 21182a0fb340SJames Smart msecs_to_jiffies(LPFC_NVMET_WAIT_TMO))) 2119372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 212032350664SJames Smart "6179 Unreg targetport x%px timeout " 21212a0fb340SJames Smart "reached.\n", phba->targetport); 21226c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 2123d613b6a7SJames Smart } 2124d613b6a7SJames Smart phba->targetport = NULL; 2125166d7211SJames Smart #endif 2126d613b6a7SJames Smart } 2127d613b6a7SJames Smart 2128d613b6a7SJames Smart /** 21293a8070c5SJames Smart * lpfc_nvmet_handle_lsreq - Process an NVME LS request 2130d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 21313a8070c5SJames Smart * @axchg: pointer to exchange context for the NVME LS request 2132d613b6a7SJames Smart * 21333a8070c5SJames Smart * This routine is used for processing an asychronously received NVME LS 21343a8070c5SJames Smart * request. Any remaining validation is done and the LS is then forwarded 21353a8070c5SJames Smart * to the nvmet-fc transport via nvmet_fc_rcv_ls_req(). 21363a8070c5SJames Smart * 21373a8070c5SJames Smart * The calling sequence should be: nvmet_fc_rcv_ls_req() -> (processing) 21383a8070c5SJames Smart * -> lpfc_nvmet_xmt_ls_rsp/cmp -> req->done. 21393a8070c5SJames Smart * lpfc_nvme_xmt_ls_rsp_cmp should free the allocated axchg. 21403a8070c5SJames Smart * 21413a8070c5SJames Smart * Returns 0 if LS was handled and delivered to the transport 21423a8070c5SJames Smart * Returns 1 if LS failed to be handled and should be dropped 21433a8070c5SJames Smart */ 21443a8070c5SJames Smart int 21453a8070c5SJames Smart lpfc_nvmet_handle_lsreq(struct lpfc_hba *phba, 21463a8070c5SJames Smart struct lpfc_async_xchg_ctx *axchg) 2147d613b6a7SJames Smart { 21487d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 21493a8070c5SJames Smart struct lpfc_nvmet_tgtport *tgtp = phba->targetport->private; 21503a8070c5SJames Smart uint32_t *payload = axchg->payload; 21513a8070c5SJames Smart int rc; 2152d613b6a7SJames Smart 2153d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_in); 21543a8070c5SJames Smart 21554c2805aaSJames Smart /* 21564c2805aaSJames Smart * Driver passes the ndlp as the hosthandle argument allowing 21574c2805aaSJames Smart * the transport to generate LS requests for any associateions 21584c2805aaSJames Smart * that are created. 21594c2805aaSJames Smart */ 21604c2805aaSJames Smart rc = nvmet_fc_rcv_ls_req(phba->targetport, axchg->ndlp, &axchg->ls_rsp, 21613a8070c5SJames Smart axchg->payload, axchg->size); 2162d613b6a7SJames Smart 2163d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 2164ce1b591cSJames Smart "6037 NVMET Unsol rcv: sz %d rc %d: %08x %08x %08x " 21653a8070c5SJames Smart "%08x %08x %08x\n", axchg->size, rc, 2166d613b6a7SJames Smart *payload, *(payload+1), *(payload+2), 2167d613b6a7SJames Smart *(payload+3), *(payload+4), *(payload+5)); 21682b65e182SJames Smart 21693a8070c5SJames Smart if (!rc) { 2170d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_out); 21713a8070c5SJames Smart return 0; 2172d613b6a7SJames Smart } 21732b65e182SJames Smart 2174d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 2175166d7211SJames Smart #endif 21763a8070c5SJames Smart return 1; 2177d613b6a7SJames Smart } 2178d613b6a7SJames Smart 2179472e146dSJames Smart static void 2180472e146dSJames Smart lpfc_nvmet_process_rcv_fcp_req(struct lpfc_nvmet_ctxbuf *ctx_buf) 2181472e146dSJames Smart { 2182472e146dSJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 21837cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp = ctx_buf->context; 2184472e146dSJames Smart struct lpfc_hba *phba = ctxp->phba; 2185472e146dSJames Smart struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; 2186472e146dSJames Smart struct lpfc_nvmet_tgtport *tgtp; 21874552e0f6SJames Smart uint32_t *payload, qno; 2188472e146dSJames Smart uint32_t rc; 2189472e146dSJames Smart unsigned long iflags; 2190472e146dSJames Smart 2191472e146dSJames Smart if (!nvmebuf) { 2192372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2193472e146dSJames Smart "6159 process_rcv_fcp_req, nvmebuf is NULL, " 2194472e146dSJames Smart "oxid: x%x flg: x%x state: x%x\n", 2195472e146dSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 2196472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflags); 2197472e146dSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 2198472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 2199472e146dSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 2200472e146dSJames Smart ctxp->oxid); 2201472e146dSJames Smart return; 2202472e146dSJames Smart } 2203472e146dSJames Smart 22047b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_ABTS_RCV) { 2205372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 220679d8c4ceSJames Smart "6324 IO oxid x%x aborted\n", 220779d8c4ceSJames Smart ctxp->oxid); 220879d8c4ceSJames Smart return; 220979d8c4ceSJames Smart } 221079d8c4ceSJames Smart 2211472e146dSJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 2212472e146dSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 22137b7f551bSJames Smart ctxp->flag |= LPFC_NVME_TNOTIFY; 2214d74a89aaSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2215d74a89aaSJames Smart if (ctxp->ts_isr_cmd) 2216d74a89aaSJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 2217d74a89aaSJames Smart #endif 2218472e146dSJames Smart /* 2219472e146dSJames Smart * The calling sequence should be: 2220472e146dSJames Smart * nvmet_fc_rcv_fcp_req->lpfc_nvmet_xmt_fcp_op/cmp- req->done 2221472e146dSJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 2222472e146dSJames Smart * When we return from nvmet_fc_rcv_fcp_req, all relevant info 2223472e146dSJames Smart * the NVME command / FC header is stored. 2224472e146dSJames Smart * A buffer has already been reposted for this IO, so just free 2225472e146dSJames Smart * the nvmebuf. 2226472e146dSJames Smart */ 22277cacae2aSJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->hdlrctx.fcp_req, 2228472e146dSJames Smart payload, ctxp->size); 2229472e146dSJames Smart /* Process FCP command */ 2230472e146dSJames Smart if (rc == 0) { 2231472e146dSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 22324552e0f6SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflags); 22337b7f551bSJames Smart if ((ctxp->flag & LPFC_NVME_CTX_REUSE_WQ) || 22344552e0f6SJames Smart (nvmebuf != ctxp->rqb_buffer)) { 22354552e0f6SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 22364552e0f6SJames Smart return; 22374552e0f6SJames Smart } 22384552e0f6SJames Smart ctxp->rqb_buffer = NULL; 22394552e0f6SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 22404552e0f6SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 2241472e146dSJames Smart return; 2242472e146dSJames Smart } 2243472e146dSJames Smart 2244472e146dSJames Smart /* Processing of FCP command is deferred */ 2245472e146dSJames Smart if (rc == -EOVERFLOW) { 2246472e146dSJames Smart lpfc_nvmeio_data(phba, "NVMET RCV BUSY: xri x%x sz %d " 2247472e146dSJames Smart "from %06x\n", 2248472e146dSJames Smart ctxp->oxid, ctxp->size, ctxp->sid); 2249472e146dSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 2250472e146dSJames Smart atomic_inc(&tgtp->defer_fod); 22514552e0f6SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflags); 22527b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_CTX_REUSE_WQ) { 22534552e0f6SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 22544552e0f6SJames Smart return; 22554552e0f6SJames Smart } 22564552e0f6SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 22574552e0f6SJames Smart /* 22584552e0f6SJames Smart * Post a replacement DMA buffer to RQ and defer 22594552e0f6SJames Smart * freeing rcv buffer till .defer_rcv callback 22604552e0f6SJames Smart */ 22614552e0f6SJames Smart qno = nvmebuf->idx; 22624552e0f6SJames Smart lpfc_post_rq_buffer( 22634552e0f6SJames Smart phba, phba->sli4_hba.nvmet_mrq_hdr[qno], 22644552e0f6SJames Smart phba->sli4_hba.nvmet_mrq_data[qno], 1, qno); 2265472e146dSJames Smart return; 2266472e146dSJames Smart } 22677b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_TNOTIFY; 2268472e146dSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 2269372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2270472e146dSJames Smart "2582 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 2271472e146dSJames Smart ctxp->oxid, rc, 2272472e146dSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 2273472e146dSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 2274472e146dSJames Smart atomic_read(&tgtp->xmt_fcp_release)); 2275472e146dSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 2276472e146dSJames Smart ctxp->oxid, ctxp->size, ctxp->sid); 2277472e146dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflags); 2278472e146dSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 2279472e146dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflags); 2280472e146dSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid); 2281472e146dSJames Smart #endif 2282472e146dSJames Smart } 2283472e146dSJames Smart 2284472e146dSJames Smart static void 2285472e146dSJames Smart lpfc_nvmet_fcp_rqst_defer_work(struct work_struct *work) 2286472e146dSJames Smart { 2287472e146dSJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 2288472e146dSJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf = 2289472e146dSJames Smart container_of(work, struct lpfc_nvmet_ctxbuf, defer_work); 2290472e146dSJames Smart 2291472e146dSJames Smart lpfc_nvmet_process_rcv_fcp_req(ctx_buf); 2292472e146dSJames Smart #endif 2293472e146dSJames Smart } 2294472e146dSJames Smart 229566d7ce93SDick Kennedy static struct lpfc_nvmet_ctxbuf * 229666d7ce93SDick Kennedy lpfc_nvmet_replenish_context(struct lpfc_hba *phba, 229766d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop) 229866d7ce93SDick Kennedy { 22992299e432SDick Kennedy #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 230066d7ce93SDick Kennedy struct lpfc_nvmet_ctxbuf *ctx_buf = NULL; 230166d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *get_infop; 230266d7ce93SDick Kennedy int i; 230366d7ce93SDick Kennedy 230466d7ce93SDick Kennedy /* 230566d7ce93SDick Kennedy * The current_infop for the MRQ a NVME command IU was received 230666d7ce93SDick Kennedy * on is empty. Our goal is to replenish this MRQs context 230766d7ce93SDick Kennedy * list from a another CPUs. 230866d7ce93SDick Kennedy * 230966d7ce93SDick Kennedy * First we need to pick a context list to start looking on. 231066d7ce93SDick Kennedy * nvmet_ctx_start_cpu has available context the last time 231166d7ce93SDick Kennedy * we needed to replenish this CPU where nvmet_ctx_next_cpu 231266d7ce93SDick Kennedy * is just the next sequential CPU for this MRQ. 231366d7ce93SDick Kennedy */ 231466d7ce93SDick Kennedy if (current_infop->nvmet_ctx_start_cpu) 231566d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_start_cpu; 231666d7ce93SDick Kennedy else 231766d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_next_cpu; 231866d7ce93SDick Kennedy 2319222e9239SJames Smart for (i = 0; i < phba->sli4_hba.num_possible_cpu; i++) { 232066d7ce93SDick Kennedy if (get_infop == current_infop) { 232166d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 232266d7ce93SDick Kennedy continue; 232366d7ce93SDick Kennedy } 232466d7ce93SDick Kennedy spin_lock(&get_infop->nvmet_ctx_list_lock); 232566d7ce93SDick Kennedy 232666d7ce93SDick Kennedy /* Just take the entire context list, if there are any */ 232766d7ce93SDick Kennedy if (get_infop->nvmet_ctx_list_cnt) { 232866d7ce93SDick Kennedy list_splice_init(&get_infop->nvmet_ctx_list, 232966d7ce93SDick Kennedy ¤t_infop->nvmet_ctx_list); 233066d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt = 233166d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt - 1; 233266d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt = 0; 233366d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 233466d7ce93SDick Kennedy 233566d7ce93SDick Kennedy current_infop->nvmet_ctx_start_cpu = get_infop; 233666d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 233766d7ce93SDick Kennedy ctx_buf, struct lpfc_nvmet_ctxbuf, 233866d7ce93SDick Kennedy list); 233966d7ce93SDick Kennedy return ctx_buf; 234066d7ce93SDick Kennedy } 234166d7ce93SDick Kennedy 234266d7ce93SDick Kennedy /* Otherwise, move on to the next CPU for this MRQ */ 234366d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 234466d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 234566d7ce93SDick Kennedy } 234666d7ce93SDick Kennedy 23472299e432SDick Kennedy #endif 234866d7ce93SDick Kennedy /* Nothing found, all contexts for the MRQ are in-flight */ 234966d7ce93SDick Kennedy return NULL; 235066d7ce93SDick Kennedy } 235166d7ce93SDick Kennedy 2352d613b6a7SJames Smart /** 2353d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer 2354d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 235566d7ce93SDick Kennedy * @idx: relative index of MRQ vector 2356d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 2357d74a89aaSJames Smart * @isr_timestamp: in jiffies. 2358d74a89aaSJames Smart * @cqflag: cq processing information regarding workload. 2359d613b6a7SJames Smart * 2360d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 2361d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 2362d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 2363d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 2364d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 2365d613b6a7SJames Smart * of the discovery state machine. 2366d613b6a7SJames Smart **/ 2367d613b6a7SJames Smart static void 2368d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba, 236966d7ce93SDick Kennedy uint32_t idx, 2370d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 2371d74a89aaSJames Smart uint64_t isr_timestamp, 2372d74a89aaSJames Smart uint8_t cqflag) 2373d613b6a7SJames Smart { 23747cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 2375d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2376d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 23776c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 237866d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop; 2379472e146dSJames Smart uint32_t size, oxid, sid, qno; 23806c621a22SJames Smart unsigned long iflag; 238166d7ce93SDick Kennedy int current_cpu; 2382d613b6a7SJames Smart 238373626173SArnd Bergmann if (!IS_ENABLED(CONFIG_NVME_TARGET_FC)) 238473626173SArnd Bergmann return; 238573626173SArnd Bergmann 23866c621a22SJames Smart ctx_buf = NULL; 2387d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 2388372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 23896c621a22SJames Smart "6157 NVMET FCP Drop IO\n"); 2390472e146dSJames Smart if (nvmebuf) 2391472e146dSJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); 2392472e146dSJames Smart return; 2393d613b6a7SJames Smart } 2394d613b6a7SJames Smart 239566d7ce93SDick Kennedy /* 239666d7ce93SDick Kennedy * Get a pointer to the context list for this MRQ based on 239766d7ce93SDick Kennedy * the CPU this MRQ IRQ is associated with. If the CPU association 239866d7ce93SDick Kennedy * changes from our initial assumption, the context list could 239966d7ce93SDick Kennedy * be empty, thus it would need to be replenished with the 240066d7ce93SDick Kennedy * context list from another CPU for this MRQ. 240166d7ce93SDick Kennedy */ 2402d6d189ceSBart Van Assche current_cpu = raw_smp_processor_id(); 240366d7ce93SDick Kennedy current_infop = lpfc_get_ctx_list(phba, current_cpu, idx); 240466d7ce93SDick Kennedy spin_lock_irqsave(¤t_infop->nvmet_ctx_list_lock, iflag); 240566d7ce93SDick Kennedy if (current_infop->nvmet_ctx_list_cnt) { 240666d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 24076c621a22SJames Smart ctx_buf, struct lpfc_nvmet_ctxbuf, list); 240866d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt--; 2409966bb5b7SJames Smart } else { 241066d7ce93SDick Kennedy ctx_buf = lpfc_nvmet_replenish_context(phba, current_infop); 24116c621a22SJames Smart } 241266d7ce93SDick Kennedy spin_unlock_irqrestore(¤t_infop->nvmet_ctx_list_lock, iflag); 24136c621a22SJames Smart 2414a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 2415a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 2416a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 2417a8cf5dfeSJames Smart 2418a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2419840eda96SJames Smart if (phba->hdwqstat_on & LPFC_CHECK_NVMET_IO) { 2420840eda96SJames Smart this_cpu_inc(phba->sli4_hba.c_stat->rcv_io); 242163df6d63SJames Smart if (idx != current_cpu) 242263df6d63SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 242363df6d63SJames Smart "6703 CPU Check rcv: " 242463df6d63SJames Smart "cpu %d expect %d\n", 242563df6d63SJames Smart current_cpu, idx); 2426a8cf5dfeSJames Smart } 2427a8cf5dfeSJames Smart #endif 2428a8cf5dfeSJames Smart 2429a8cf5dfeSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d CPU %02x\n", 2430d6d189ceSBart Van Assche oxid, size, raw_smp_processor_id()); 2431a8cf5dfeSJames Smart 2432411de511SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2433411de511SJames Smart 24346c621a22SJames Smart if (!ctx_buf) { 2435a8cf5dfeSJames Smart /* Queue this NVME IO to process later */ 2436a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 2437a8cf5dfeSJames Smart list_add_tail(&nvmebuf->hbuf.list, 2438a8cf5dfeSJames Smart &phba->sli4_hba.lpfc_nvmet_io_wait_list); 2439a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt++; 2440a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_total++; 2441a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 2442a8cf5dfeSJames Smart iflag); 2443a8cf5dfeSJames Smart 2444a8cf5dfeSJames Smart /* Post a brand new DMA buffer to RQ */ 2445a8cf5dfeSJames Smart qno = nvmebuf->idx; 2446a8cf5dfeSJames Smart lpfc_post_rq_buffer( 2447a8cf5dfeSJames Smart phba, phba->sli4_hba.nvmet_mrq_hdr[qno], 2448a8cf5dfeSJames Smart phba->sli4_hba.nvmet_mrq_data[qno], 1, qno); 2449411de511SJames Smart 2450411de511SJames Smart atomic_inc(&tgtp->defer_ctx); 2451a8cf5dfeSJames Smart return; 24526c621a22SJames Smart } 2453d613b6a7SJames Smart 2454d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 2455d613b6a7SJames Smart 24567cacae2aSJames Smart ctxp = (struct lpfc_async_xchg_ctx *)ctx_buf->context; 245779d8c4ceSJames Smart spin_lock_irqsave(&phba->sli4_hba.t_active_list_lock, iflag); 245879d8c4ceSJames Smart list_add_tail(&ctxp->list, &phba->sli4_hba.t_active_ctx_list); 245979d8c4ceSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.t_active_list_lock, iflag); 24607b7f551bSJames Smart if (ctxp->state != LPFC_NVME_STE_FREE) { 2461372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2462ce1b591cSJames Smart "6414 NVMET Context corrupt %d %d oxid x%x\n", 2463ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 2464ce1b591cSJames Smart } 2465d613b6a7SJames Smart ctxp->wqeq = NULL; 2466d613b6a7SJames Smart ctxp->offset = 0; 2467d613b6a7SJames Smart ctxp->phba = phba; 2468d613b6a7SJames Smart ctxp->size = size; 2469d613b6a7SJames Smart ctxp->oxid = oxid; 2470d613b6a7SJames Smart ctxp->sid = sid; 247166d7ce93SDick Kennedy ctxp->idx = idx; 24727b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_RCV; 2473d613b6a7SJames Smart ctxp->entry_cnt = 1; 2474d613b6a7SJames Smart ctxp->flag = 0; 24756c621a22SJames Smart ctxp->ctxbuf = ctx_buf; 2476cbc5de1bSJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 24771fbf9742SJames Smart ctxp->hdwq = NULL; 24782b7824d0SJames Smart spin_lock_init(&ctxp->ctxlock); 2479d613b6a7SJames Smart 24802b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2481d74a89aaSJames Smart if (isr_timestamp) 24822b65e182SJames Smart ctxp->ts_isr_cmd = isr_timestamp; 2483d74a89aaSJames Smart ctxp->ts_cmd_nvme = 0; 24842b65e182SJames Smart ctxp->ts_nvme_data = 0; 24852b65e182SJames Smart ctxp->ts_data_wqput = 0; 24862b65e182SJames Smart ctxp->ts_isr_data = 0; 24872b65e182SJames Smart ctxp->ts_data_nvme = 0; 24882b65e182SJames Smart ctxp->ts_nvme_status = 0; 24892b65e182SJames Smart ctxp->ts_status_wqput = 0; 24902b65e182SJames Smart ctxp->ts_isr_status = 0; 24912b65e182SJames Smart ctxp->ts_status_nvme = 0; 24922b65e182SJames Smart #endif 24932b65e182SJames Smart 2494d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 2495d74a89aaSJames Smart /* check for cq processing load */ 2496d74a89aaSJames Smart if (!cqflag) { 2497472e146dSJames Smart lpfc_nvmet_process_rcv_fcp_req(ctx_buf); 2498d74a89aaSJames Smart return; 2499d74a89aaSJames Smart } 2500d74a89aaSJames Smart 2501d74a89aaSJames Smart if (!queue_work(phba->wq, &ctx_buf->defer_work)) { 2502d74a89aaSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 2503372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2504d74a89aaSJames Smart "6325 Unable to queue work for oxid x%x. " 2505d74a89aaSJames Smart "FCP Drop IO [x%x x%x x%x]\n", 2506d74a89aaSJames Smart ctxp->oxid, 2507d74a89aaSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 2508d74a89aaSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 2509d74a89aaSJames Smart atomic_read(&tgtp->xmt_fcp_release)); 2510d74a89aaSJames Smart 2511d74a89aaSJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 2512d74a89aaSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 2513d74a89aaSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 2514d74a89aaSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 2515d74a89aaSJames Smart } 2516d613b6a7SJames Smart } 2517d613b6a7SJames Smart 2518d613b6a7SJames Smart /** 2519d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport 2520d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 252166d7ce93SDick Kennedy * @idx: relative index of MRQ vector 2522d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 2523d74a89aaSJames Smart * @isr_timestamp: in jiffies. 2524d74a89aaSJames Smart * @cqflag: cq processing information regarding workload. 2525d613b6a7SJames Smart * 2526d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 2527d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 2528d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 2529d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the 2530d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 2531d613b6a7SJames Smart **/ 2532d613b6a7SJames Smart void 2533d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba, 253466d7ce93SDick Kennedy uint32_t idx, 2535d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 2536d74a89aaSJames Smart uint64_t isr_timestamp, 2537d74a89aaSJames Smart uint8_t cqflag) 2538d613b6a7SJames Smart { 253943bfea1bSJames Smart if (!nvmebuf) { 2540372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 254143bfea1bSJames Smart "3167 NVMET FCP Drop IO\n"); 254243bfea1bSJames Smart return; 254343bfea1bSJames Smart } 2544d613b6a7SJames Smart if (phba->nvmet_support == 0) { 25456c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); 2546d613b6a7SJames Smart return; 2547d613b6a7SJames Smart } 2548d74a89aaSJames Smart lpfc_nvmet_unsol_fcp_buffer(phba, idx, nvmebuf, isr_timestamp, cqflag); 2549d613b6a7SJames Smart } 2550d613b6a7SJames Smart 2551d613b6a7SJames Smart /** 2552d613b6a7SJames Smart * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure 2553d613b6a7SJames Smart * @phba: pointer to a host N_Port data structure. 2554d613b6a7SJames Smart * @ctxp: Context info for NVME LS Request 2555d613b6a7SJames Smart * @rspbuf: DMA buffer of NVME command. 2556d613b6a7SJames Smart * @rspsize: size of the NVME command. 2557d613b6a7SJames Smart * 2558d613b6a7SJames Smart * This routine is used for allocating a lpfc-WQE data structure from 2559d613b6a7SJames Smart * the driver lpfc-WQE free-list and prepare the WQE with the parameters 2560d613b6a7SJames Smart * passed into the routine for discovery state machine to issue an Extended 2561d613b6a7SJames Smart * Link Service (NVME) commands. It is a generic lpfc-WQE allocation 2562d613b6a7SJames Smart * and preparation routine that is used by all the discovery state machine 2563d613b6a7SJames Smart * routines and the NVME command-specific fields will be later set up by 2564d613b6a7SJames Smart * the individual discovery machine routines after calling this routine 2565d613b6a7SJames Smart * allocating and preparing a generic WQE data structure. It fills in the 2566d613b6a7SJames Smart * Buffer Descriptor Entries (BDEs), allocates buffers for both command 2567d613b6a7SJames Smart * payload and response payload (if expected). The reference count on the 2568d613b6a7SJames Smart * ndlp is incremented by 1 and the reference to the ndlp is put into 2569d613b6a7SJames Smart * context1 of the WQE data structure for this WQE to hold the ndlp 2570d613b6a7SJames Smart * reference for the command's callback function to access later. 2571d613b6a7SJames Smart * 2572d613b6a7SJames Smart * Return code 2573d613b6a7SJames Smart * Pointer to the newly allocated/prepared nvme wqe data structure 2574d613b6a7SJames Smart * NULL - when nvme wqe data structure allocation/preparation failed 2575d613b6a7SJames Smart **/ 2576d613b6a7SJames Smart static struct lpfc_iocbq * 2577d613b6a7SJames Smart lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba, 25787cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, 2579d613b6a7SJames Smart dma_addr_t rspbuf, uint16_t rspsize) 2580d613b6a7SJames Smart { 2581d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2582d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 2583205e8240SJames Smart union lpfc_wqe128 *wqe; 2584d613b6a7SJames Smart 2585d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 2586372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2587ce1b591cSJames Smart "6104 NVMET prep LS wqe: link err: " 2588ce1b591cSJames Smart "NPORT x%x oxid:x%x ste %d\n", 2589ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2590d613b6a7SJames Smart return NULL; 2591d613b6a7SJames Smart } 2592d613b6a7SJames Smart 2593d613b6a7SJames Smart /* Allocate buffer for command wqe */ 2594d613b6a7SJames Smart nvmewqe = lpfc_sli_get_iocbq(phba); 2595d613b6a7SJames Smart if (nvmewqe == NULL) { 2596372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2597ce1b591cSJames Smart "6105 NVMET prep LS wqe: No WQE: " 2598ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2599ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2600d613b6a7SJames Smart return NULL; 2601d613b6a7SJames Smart } 2602d613b6a7SJames Smart 2603d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 2604307e3380SJames Smart if (!ndlp || 2605d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2606d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2607372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2608ce1b591cSJames Smart "6106 NVMET prep LS wqe: No ndlp: " 2609ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2610ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2611d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 2612d613b6a7SJames Smart } 2613d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 2614d613b6a7SJames Smart 2615d613b6a7SJames Smart /* prevent preparing wqe with NULL ndlp reference */ 2616d613b6a7SJames Smart nvmewqe->context1 = lpfc_nlp_get(ndlp); 2617d613b6a7SJames Smart if (nvmewqe->context1 == NULL) 2618d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 2619d613b6a7SJames Smart nvmewqe->context2 = ctxp; 2620d613b6a7SJames Smart 2621d613b6a7SJames Smart wqe = &nvmewqe->wqe; 2622d613b6a7SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 2623d613b6a7SJames Smart 2624d613b6a7SJames Smart /* Words 0 - 2 */ 2625d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2626d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize; 2627d613b6a7SJames Smart wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf)); 2628d613b6a7SJames Smart wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf)); 2629d613b6a7SJames Smart 2630d613b6a7SJames Smart /* Word 3 */ 2631d613b6a7SJames Smart 2632d613b6a7SJames Smart /* Word 4 */ 2633d613b6a7SJames Smart 2634d613b6a7SJames Smart /* Word 5 */ 2635d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 2636d613b6a7SJames Smart bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 2637d613b6a7SJames Smart bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 26388b361639SJames Smart bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP); 2639d613b6a7SJames Smart bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 2640d613b6a7SJames Smart 2641d613b6a7SJames Smart /* Word 6 */ 2642d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, 2643d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2644d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag); 2645d613b6a7SJames Smart 2646d613b6a7SJames Smart /* Word 7 */ 2647d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com, 2648d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 2649d613b6a7SJames Smart bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI); 2650d613b6a7SJames Smart bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3); 2651d613b6a7SJames Smart bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); 2652d613b6a7SJames Smart 2653d613b6a7SJames Smart /* Word 8 */ 2654d613b6a7SJames Smart wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag; 2655d613b6a7SJames Smart 2656d613b6a7SJames Smart /* Word 9 */ 2657d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag); 2658d613b6a7SJames Smart /* Needs to be set by caller */ 2659d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid); 2660d613b6a7SJames Smart 2661d613b6a7SJames Smart /* Word 10 */ 2662d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); 2663d613b6a7SJames Smart bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 2664d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, 2665d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2666d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); 2667d613b6a7SJames Smart 2668d613b6a7SJames Smart /* Word 11 */ 2669d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com, 2670d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2671d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com, 2672d613b6a7SJames Smart OTHER_COMMAND); 2673d613b6a7SJames Smart 2674d613b6a7SJames Smart /* Word 12 */ 2675d613b6a7SJames Smart wqe->xmit_sequence.xmit_len = rspsize; 2676d613b6a7SJames Smart 2677d613b6a7SJames Smart nvmewqe->retry = 1; 2678d613b6a7SJames Smart nvmewqe->vport = phba->pport; 2679d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 2680d613b6a7SJames Smart nvmewqe->iocb_flag |= LPFC_IO_NVME_LS; 2681d613b6a7SJames Smart 2682ce1b591cSJames Smart /* Xmit NVMET response to remote NPORT <did> */ 2683d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 2684ce1b591cSJames Smart "6039 Xmit NVMET LS response to remote " 2685d613b6a7SJames Smart "NPORT x%x iotag:x%x oxid:x%x size:x%x\n", 2686d613b6a7SJames Smart ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid, 2687d613b6a7SJames Smart rspsize); 2688d613b6a7SJames Smart return nvmewqe; 2689d613b6a7SJames Smart 2690d613b6a7SJames Smart nvme_wqe_free_wqeq_exit: 2691d613b6a7SJames Smart nvmewqe->context2 = NULL; 2692d613b6a7SJames Smart nvmewqe->context3 = NULL; 2693d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, nvmewqe); 2694d613b6a7SJames Smart return NULL; 2695d613b6a7SJames Smart } 2696d613b6a7SJames Smart 2697d613b6a7SJames Smart 2698d613b6a7SJames Smart static struct lpfc_iocbq * 2699d613b6a7SJames Smart lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba, 27007cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp) 2701d613b6a7SJames Smart { 27027cacae2aSJames Smart struct nvmefc_tgt_fcp_req *rsp = &ctxp->hdlrctx.fcp_req; 2703d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2704d613b6a7SJames Smart struct sli4_sge *sgl; 2705d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2706d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 2707d613b6a7SJames Smart struct scatterlist *sgel; 2708d613b6a7SJames Smart union lpfc_wqe128 *wqe; 27090bc2b7c5SJames Smart struct ulp_bde64 *bde; 2710d613b6a7SJames Smart dma_addr_t physaddr; 2711e7f40349SJames Smart int i, cnt, nsegs; 27120bc2b7c5SJames Smart int do_pbde; 2713d613b6a7SJames Smart int xc = 1; 2714d613b6a7SJames Smart 2715d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 2716372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2717ce1b591cSJames Smart "6107 NVMET prep FCP wqe: link err:" 2718ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2719ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2720d613b6a7SJames Smart return NULL; 2721d613b6a7SJames Smart } 2722d613b6a7SJames Smart 2723d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 2724307e3380SJames Smart if (!ndlp || 2725d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2726d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2727372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2728ce1b591cSJames Smart "6108 NVMET prep FCP wqe: no ndlp: " 2729ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2730ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2731d613b6a7SJames Smart return NULL; 2732d613b6a7SJames Smart } 2733d613b6a7SJames Smart 273481e6a637SJames Smart if (rsp->sg_cnt > lpfc_tgttemplate.max_sgl_segments) { 2735372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2736ce1b591cSJames Smart "6109 NVMET prep FCP wqe: seg cnt err: " 2737ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d cnt %d\n", 2738ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state, 2739ce1b591cSJames Smart phba->cfg_nvme_seg_cnt); 2740d613b6a7SJames Smart return NULL; 2741d613b6a7SJames Smart } 2742e7f40349SJames Smart nsegs = rsp->sg_cnt; 2743d613b6a7SJames Smart 2744d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2745d613b6a7SJames Smart nvmewqe = ctxp->wqeq; 2746d613b6a7SJames Smart if (nvmewqe == NULL) { 2747d613b6a7SJames Smart /* Allocate buffer for command wqe */ 27486c621a22SJames Smart nvmewqe = ctxp->ctxbuf->iocbq; 2749d613b6a7SJames Smart if (nvmewqe == NULL) { 2750372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2751ce1b591cSJames Smart "6110 NVMET prep FCP wqe: No " 2752ce1b591cSJames Smart "WQE: NPORT x%x oxid x%x ste %d\n", 2753ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2754d613b6a7SJames Smart return NULL; 2755d613b6a7SJames Smart } 2756d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 2757d613b6a7SJames Smart xc = 0; /* create new XRI */ 2758d613b6a7SJames Smart nvmewqe->sli4_lxritag = NO_XRI; 2759d613b6a7SJames Smart nvmewqe->sli4_xritag = NO_XRI; 2760d613b6a7SJames Smart } 2761d613b6a7SJames Smart 2762d613b6a7SJames Smart /* Sanity check */ 27637b7f551bSJames Smart if (((ctxp->state == LPFC_NVME_STE_RCV) && 2764d613b6a7SJames Smart (ctxp->entry_cnt == 1)) || 27657b7f551bSJames Smart (ctxp->state == LPFC_NVME_STE_DATA)) { 2766205e8240SJames Smart wqe = &nvmewqe->wqe; 2767d613b6a7SJames Smart } else { 2768372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2769ce1b591cSJames Smart "6111 Wrong state NVMET FCP: %d cnt %d\n", 2770ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt); 2771d613b6a7SJames Smart return NULL; 2772d613b6a7SJames Smart } 2773d613b6a7SJames Smart 27746c621a22SJames Smart sgl = (struct sli4_sge *)ctxp->ctxbuf->sglq->sgl; 2775d613b6a7SJames Smart switch (rsp->op) { 2776d613b6a7SJames Smart case NVMET_FCOP_READDATA: 2777d613b6a7SJames Smart case NVMET_FCOP_READDATA_RSP: 2778bd3061baSJames Smart /* From the tsend template, initialize words 7 - 11 */ 2779bd3061baSJames Smart memcpy(&wqe->words[7], 2780bd3061baSJames Smart &lpfc_tsend_cmd_template.words[7], 2781bd3061baSJames Smart sizeof(uint32_t) * 5); 2782bd3061baSJames Smart 2783d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 2784d613b6a7SJames Smart sgel = &rsp->sg[0]; 2785d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 2786d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2787d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel); 2788d613b6a7SJames Smart wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr)); 2789d613b6a7SJames Smart wqe->fcp_tsend.bde.addrHigh = 2790d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2791d613b6a7SJames Smart 2792d613b6a7SJames Smart /* Word 3 */ 2793d613b6a7SJames Smart wqe->fcp_tsend.payload_offset_len = 0; 2794d613b6a7SJames Smart 2795d613b6a7SJames Smart /* Word 4 */ 2796d613b6a7SJames Smart wqe->fcp_tsend.relative_offset = ctxp->offset; 2797d613b6a7SJames Smart 2798d613b6a7SJames Smart /* Word 5 */ 2799bd3061baSJames Smart wqe->fcp_tsend.reserved = 0; 2800d613b6a7SJames Smart 2801d613b6a7SJames Smart /* Word 6 */ 2802d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com, 2803d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2804d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com, 2805d613b6a7SJames Smart nvmewqe->sli4_xritag); 2806d613b6a7SJames Smart 2807bd3061baSJames Smart /* Word 7 - set ar later */ 2808d613b6a7SJames Smart 2809d613b6a7SJames Smart /* Word 8 */ 2810d613b6a7SJames Smart wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag; 2811d613b6a7SJames Smart 2812d613b6a7SJames Smart /* Word 9 */ 2813d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag); 2814d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid); 2815d613b6a7SJames Smart 2816bd3061baSJames Smart /* Word 10 - set wqes later, in template xc=1 */ 2817bd3061baSJames Smart if (!xc) 2818bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, 0); 2819d613b6a7SJames Smart 2820bd3061baSJames Smart /* Word 11 - set sup, irsp, irsplen later */ 2821bd3061baSJames Smart do_pbde = 0; 2822d613b6a7SJames Smart 2823d613b6a7SJames Smart /* Word 12 */ 2824d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2825d613b6a7SJames Smart 2826d613b6a7SJames Smart /* Setup 2 SKIP SGEs */ 2827d613b6a7SJames Smart sgl->addr_hi = 0; 2828d613b6a7SJames Smart sgl->addr_lo = 0; 2829d613b6a7SJames Smart sgl->word2 = 0; 2830d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2831d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2832d613b6a7SJames Smart sgl->sge_len = 0; 2833d613b6a7SJames Smart sgl++; 2834d613b6a7SJames Smart sgl->addr_hi = 0; 2835d613b6a7SJames Smart sgl->addr_lo = 0; 2836d613b6a7SJames Smart sgl->word2 = 0; 2837d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2838d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2839d613b6a7SJames Smart sgl->sge_len = 0; 2840d613b6a7SJames Smart sgl++; 2841d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 2842d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read_rsp); 2843bd3061baSJames Smart 2844bd3061baSJames Smart /* In template ar=1 wqes=0 sup=0 irsp=0 irsplen=0 */ 2845bd3061baSJames Smart 284620aefac3SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 284720aefac3SJames Smart if (ndlp->nlp_flag & NLP_SUPPRESS_RSP) 284820aefac3SJames Smart bf_set(wqe_sup, 284920aefac3SJames Smart &wqe->fcp_tsend.wqe_com, 1); 2850d613b6a7SJames Smart } else { 2851d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1); 2852d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1); 2853d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 2854d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2855d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, 2856d613b6a7SJames Smart rsp->rsplen); 2857d613b6a7SJames Smart } 2858d613b6a7SJames Smart } else { 2859d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read); 2860d613b6a7SJames Smart 2861bd3061baSJames Smart /* In template ar=1 wqes=0 sup=0 irsp=0 irsplen=0 */ 2862d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0); 2863d613b6a7SJames Smart } 2864d613b6a7SJames Smart break; 2865d613b6a7SJames Smart 2866d613b6a7SJames Smart case NVMET_FCOP_WRITEDATA: 2867bd3061baSJames Smart /* From the treceive template, initialize words 3 - 11 */ 2868bd3061baSJames Smart memcpy(&wqe->words[3], 2869bd3061baSJames Smart &lpfc_treceive_cmd_template.words[3], 2870bd3061baSJames Smart sizeof(uint32_t) * 9); 2871bd3061baSJames Smart 2872ea85a20cSJames Smart /* Words 0 - 2 : First SGE is skipped, set invalid BDE type */ 2873ea85a20cSJames Smart wqe->fcp_treceive.bde.tus.f.bdeFlags = LPFC_SGE_TYPE_SKIP; 2874ea85a20cSJames Smart wqe->fcp_treceive.bde.tus.f.bdeSize = 0; 2875ea85a20cSJames Smart wqe->fcp_treceive.bde.addrLow = 0; 2876ea85a20cSJames Smart wqe->fcp_treceive.bde.addrHigh = 0; 2877d613b6a7SJames Smart 2878d613b6a7SJames Smart /* Word 4 */ 2879d613b6a7SJames Smart wqe->fcp_treceive.relative_offset = ctxp->offset; 2880d613b6a7SJames Smart 2881d613b6a7SJames Smart /* Word 6 */ 2882d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com, 2883d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2884d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com, 2885d613b6a7SJames Smart nvmewqe->sli4_xritag); 2886d613b6a7SJames Smart 2887d613b6a7SJames Smart /* Word 7 */ 2888d613b6a7SJames Smart 2889d613b6a7SJames Smart /* Word 8 */ 2890d613b6a7SJames Smart wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag; 2891d613b6a7SJames Smart 2892d613b6a7SJames Smart /* Word 9 */ 2893d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag); 2894d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid); 2895d613b6a7SJames Smart 2896bd3061baSJames Smart /* Word 10 - in template xc=1 */ 2897bd3061baSJames Smart if (!xc) 2898bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, 0); 2899d613b6a7SJames Smart 2900bd3061baSJames Smart /* Word 11 - set pbde later */ 2901414abe0aSJames Smart if (phba->cfg_enable_pbde) { 2902bd3061baSJames Smart do_pbde = 1; 2903bd3061baSJames Smart } else { 2904bd3061baSJames Smart bf_set(wqe_pbde, &wqe->fcp_treceive.wqe_com, 0); 2905bd3061baSJames Smart do_pbde = 0; 2906bd3061baSJames Smart } 2907d613b6a7SJames Smart 2908d613b6a7SJames Smart /* Word 12 */ 2909d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2910d613b6a7SJames Smart 2911ea85a20cSJames Smart /* Setup 2 SKIP SGEs */ 2912ea85a20cSJames Smart sgl->addr_hi = 0; 2913ea85a20cSJames Smart sgl->addr_lo = 0; 2914d613b6a7SJames Smart sgl->word2 = 0; 2915ea85a20cSJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2916d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2917ea85a20cSJames Smart sgl->sge_len = 0; 2918d613b6a7SJames Smart sgl++; 2919d613b6a7SJames Smart sgl->addr_hi = 0; 2920d613b6a7SJames Smart sgl->addr_lo = 0; 2921d613b6a7SJames Smart sgl->word2 = 0; 2922d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2923d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2924d613b6a7SJames Smart sgl->sge_len = 0; 2925d613b6a7SJames Smart sgl++; 2926d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_write); 2927d613b6a7SJames Smart break; 2928d613b6a7SJames Smart 2929d613b6a7SJames Smart case NVMET_FCOP_RSP: 2930bd3061baSJames Smart /* From the treceive template, initialize words 4 - 11 */ 2931bd3061baSJames Smart memcpy(&wqe->words[4], 2932bd3061baSJames Smart &lpfc_trsp_cmd_template.words[4], 2933bd3061baSJames Smart sizeof(uint32_t) * 8); 2934bd3061baSJames Smart 2935d613b6a7SJames Smart /* Words 0 - 2 */ 2936d613b6a7SJames Smart physaddr = rsp->rspdma; 2937d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2938d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 2939d613b6a7SJames Smart wqe->fcp_trsp.bde.addrLow = 2940d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 2941d613b6a7SJames Smart wqe->fcp_trsp.bde.addrHigh = 2942d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2943d613b6a7SJames Smart 2944d613b6a7SJames Smart /* Word 3 */ 2945d613b6a7SJames Smart wqe->fcp_trsp.response_len = rsp->rsplen; 2946d613b6a7SJames Smart 2947d613b6a7SJames Smart /* Word 6 */ 2948d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com, 2949d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2950d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com, 2951d613b6a7SJames Smart nvmewqe->sli4_xritag); 2952d613b6a7SJames Smart 2953d613b6a7SJames Smart /* Word 7 */ 2954d613b6a7SJames Smart 2955d613b6a7SJames Smart /* Word 8 */ 2956d613b6a7SJames Smart wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag; 2957d613b6a7SJames Smart 2958d613b6a7SJames Smart /* Word 9 */ 2959d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag); 2960d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid); 2961d613b6a7SJames Smart 2962d613b6a7SJames Smart /* Word 10 */ 2963bd3061baSJames Smart if (xc) 2964bd3061baSJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, 1); 2965d613b6a7SJames Smart 2966d613b6a7SJames Smart /* Word 11 */ 2967bd3061baSJames Smart /* In template wqes=0 irsp=0 irsplen=0 - good response */ 2968bd3061baSJames Smart if (rsp->rsplen != LPFC_NVMET_SUCCESS_LEN) { 2969bd3061baSJames Smart /* Bad response - embed it */ 2970d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1); 2971d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1); 2972d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 2973d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2974d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen); 2975d613b6a7SJames Smart } 2976bd3061baSJames Smart do_pbde = 0; 2977bd3061baSJames Smart 2978bd3061baSJames Smart /* Word 12 */ 2979bd3061baSJames Smart wqe->fcp_trsp.rsvd_12_15[0] = 0; 2980d613b6a7SJames Smart 2981d613b6a7SJames Smart /* Use rspbuf, NOT sg list */ 2982e7f40349SJames Smart nsegs = 0; 2983d613b6a7SJames Smart sgl->word2 = 0; 2984d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp); 2985d613b6a7SJames Smart break; 2986d613b6a7SJames Smart 2987d613b6a7SJames Smart default: 2988d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 2989d613b6a7SJames Smart "6064 Unknown Rsp Op %d\n", 2990d613b6a7SJames Smart rsp->op); 2991d613b6a7SJames Smart return NULL; 2992d613b6a7SJames Smart } 2993d613b6a7SJames Smart 2994d613b6a7SJames Smart nvmewqe->retry = 1; 2995d613b6a7SJames Smart nvmewqe->vport = phba->pport; 2996d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 2997d613b6a7SJames Smart nvmewqe->context1 = ndlp; 2998d613b6a7SJames Smart 2999e7f40349SJames Smart for_each_sg(rsp->sg, sgel, nsegs, i) { 3000d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 3001d613b6a7SJames Smart cnt = sg_dma_len(sgel); 3002d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 3003d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 3004d613b6a7SJames Smart sgl->word2 = 0; 3005d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 3006d613b6a7SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset); 3007d613b6a7SJames Smart if ((i+1) == rsp->sg_cnt) 3008d613b6a7SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 3009d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 3010d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(cnt); 3011414abe0aSJames Smart if (i == 0) { 30120bc2b7c5SJames Smart bde = (struct ulp_bde64 *)&wqe->words[13]; 3013414abe0aSJames Smart if (do_pbde) { 30140bc2b7c5SJames Smart /* Words 13-15 (PBDE) */ 30150bc2b7c5SJames Smart bde->addrLow = sgl->addr_lo; 30160bc2b7c5SJames Smart bde->addrHigh = sgl->addr_hi; 30170bc2b7c5SJames Smart bde->tus.f.bdeSize = 30180bc2b7c5SJames Smart le32_to_cpu(sgl->sge_len); 30190bc2b7c5SJames Smart bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; 30200bc2b7c5SJames Smart bde->tus.w = cpu_to_le32(bde->tus.w); 3021414abe0aSJames Smart } else { 3022414abe0aSJames Smart memset(bde, 0, sizeof(struct ulp_bde64)); 3023414abe0aSJames Smart } 30240bc2b7c5SJames Smart } 3025d613b6a7SJames Smart sgl++; 3026d613b6a7SJames Smart ctxp->offset += cnt; 3027d613b6a7SJames Smart } 30287b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_DATA; 3029ce1b591cSJames Smart ctxp->entry_cnt++; 3030d613b6a7SJames Smart return nvmewqe; 3031d613b6a7SJames Smart } 3032d613b6a7SJames Smart 3033d613b6a7SJames Smart /** 3034d613b6a7SJames Smart * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS 3035d613b6a7SJames Smart * @phba: Pointer to HBA context object. 3036d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 3037d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 3038d613b6a7SJames Smart * 3039d613b6a7SJames Smart * The function is called from SLI ring event handler with no 3040d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 3041d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 3042d613b6a7SJames Smart **/ 3043d613b6a7SJames Smart static void 3044d613b6a7SJames Smart lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 3045d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 3046d613b6a7SJames Smart { 30477cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 3048d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 3049b27cbd55SBart Van Assche uint32_t result; 305019b58d94SJames Smart unsigned long flags; 305119b58d94SJames Smart bool released = false; 3052d613b6a7SJames Smart 3053d613b6a7SJames Smart ctxp = cmdwqe->context2; 3054d613b6a7SJames Smart result = wcqe->parameter; 3055d613b6a7SJames Smart 3056d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 30577b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_ABORT_OP) 3058547077a4SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 3059d613b6a7SJames Smart 3060c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 30617b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_DONE; 306286c67379SJames Smart 306386c67379SJames Smart /* Check if we already received a free context call 306486c67379SJames Smart * and we have completed processing an abort situation. 306586c67379SJames Smart */ 30667b7f551bSJames Smart if ((ctxp->flag & LPFC_NVME_CTX_RLS) && 30677b7f551bSJames Smart !(ctxp->flag & LPFC_NVME_XBUSY)) { 3068c160c0f8SJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 306979d8c4ceSJames Smart list_del_init(&ctxp->list); 3070c160c0f8SJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 307119b58d94SJames Smart released = true; 307286c67379SJames Smart } 30737b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 307419b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3075547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 307619b58d94SJames Smart 3077e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 307879d8c4ceSJames Smart "6165 ABORT cmpl: oxid x%x flg x%x (%d) " 307986c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 308086c67379SJames Smart ctxp->oxid, ctxp->flag, released, 308186c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 308286c67379SJames Smart result, wcqe->word3); 308386c67379SJames Smart 30846c621a22SJames Smart cmdwqe->context2 = NULL; 30856c621a22SJames Smart cmdwqe->context3 = NULL; 308619b58d94SJames Smart /* 308719b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 308819b58d94SJames Smart * will be recycled by transport release call. 308919b58d94SJames Smart */ 309019b58d94SJames Smart if (released) 30916c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 3092d613b6a7SJames Smart 30936c621a22SJames Smart /* This is the iocbq for the abort, not the command */ 3094d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 309586c67379SJames Smart 309686c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 30977b7f551bSJames Smart * For LPFC_NVME_XBUSY, lpfc_sli4_nvmet_xri_aborted 309886c67379SJames Smart * should have been called already. 309986c67379SJames Smart */ 3100d613b6a7SJames Smart } 3101d613b6a7SJames Smart 3102d613b6a7SJames Smart /** 310386c67379SJames Smart * lpfc_nvmet_unsol_fcp_abort_cmp - Completion handler for ABTS 3104d613b6a7SJames Smart * @phba: Pointer to HBA context object. 3105d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 3106d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 3107d613b6a7SJames Smart * 3108d613b6a7SJames Smart * The function is called from SLI ring event handler with no 3109d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 3110d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 3111d613b6a7SJames Smart **/ 3112d613b6a7SJames Smart static void 311386c67379SJames Smart lpfc_nvmet_unsol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 3114d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 3115d613b6a7SJames Smart { 31167cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 3117d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 311819b58d94SJames Smart unsigned long flags; 3119b27cbd55SBart Van Assche uint32_t result; 312019b58d94SJames Smart bool released = false; 3121d613b6a7SJames Smart 3122d613b6a7SJames Smart ctxp = cmdwqe->context2; 3123d613b6a7SJames Smart result = wcqe->parameter; 3124d613b6a7SJames Smart 312586c67379SJames Smart if (!ctxp) { 312686c67379SJames Smart /* if context is clear, related io alrady complete */ 3127d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 312886c67379SJames Smart "6070 ABTS cmpl: WCQE: %08x %08x %08x %08x\n", 312986c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 3130d613b6a7SJames Smart result, wcqe->word3); 313186c67379SJames Smart return; 313286c67379SJames Smart } 3133d613b6a7SJames Smart 313478e1d200SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3135c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 31367b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_ABORT_OP) 313778e1d200SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 313878e1d200SJames Smart 3139d613b6a7SJames Smart /* Sanity check */ 31407b7f551bSJames Smart if (ctxp->state != LPFC_NVME_STE_ABORT) { 3141372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 314286c67379SJames Smart "6112 ABTS Wrong state:%d oxid x%x\n", 3143d613b6a7SJames Smart ctxp->state, ctxp->oxid); 3144d613b6a7SJames Smart } 314586c67379SJames Smart 314686c67379SJames Smart /* Check if we already received a free context call 314786c67379SJames Smart * and we have completed processing an abort situation. 314886c67379SJames Smart */ 31497b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_DONE; 31507b7f551bSJames Smart if ((ctxp->flag & LPFC_NVME_CTX_RLS) && 31517b7f551bSJames Smart !(ctxp->flag & LPFC_NVME_XBUSY)) { 3152c160c0f8SJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 315379d8c4ceSJames Smart list_del_init(&ctxp->list); 3154c160c0f8SJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 315519b58d94SJames Smart released = true; 315686c67379SJames Smart } 31577b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 315819b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3159547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 316019b58d94SJames Smart 316186c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 316279d8c4ceSJames Smart "6316 ABTS cmpl oxid x%x flg x%x (%x) " 316386c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 316486c67379SJames Smart ctxp->oxid, ctxp->flag, released, 316586c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 316686c67379SJames Smart result, wcqe->word3); 31676c621a22SJames Smart 31686c621a22SJames Smart cmdwqe->context2 = NULL; 31696c621a22SJames Smart cmdwqe->context3 = NULL; 317019b58d94SJames Smart /* 317119b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 317219b58d94SJames Smart * will be recycled by transport release call. 317319b58d94SJames Smart */ 317419b58d94SJames Smart if (released) 31756c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 317686c67379SJames Smart 317786c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 31787b7f551bSJames Smart * For LPFC_NVME_XBUSY, lpfc_sli4_nvmet_xri_aborted 317986c67379SJames Smart * should have been called already. 318086c67379SJames Smart */ 3181d613b6a7SJames Smart } 3182d613b6a7SJames Smart 3183d613b6a7SJames Smart /** 3184d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS 3185d613b6a7SJames Smart * @phba: Pointer to HBA context object. 3186d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 3187d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 3188d613b6a7SJames Smart * 3189d613b6a7SJames Smart * The function is called from SLI ring event handler with no 3190d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for LS cmds 3191d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 3192d613b6a7SJames Smart **/ 3193d613b6a7SJames Smart static void 3194d613b6a7SJames Smart lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 3195d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 3196d613b6a7SJames Smart { 31977cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp; 3198d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 3199b27cbd55SBart Van Assche uint32_t result; 3200d613b6a7SJames Smart 3201d613b6a7SJames Smart ctxp = cmdwqe->context2; 3202d613b6a7SJames Smart result = wcqe->parameter; 3203d613b6a7SJames Smart 3204fcdd14b8SJames Smart if (phba->nvmet_support) { 3205d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3206547077a4SJames Smart atomic_inc(&tgtp->xmt_ls_abort_cmpl); 3207fcdd14b8SJames Smart } 3208d613b6a7SJames Smart 3209d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 321032350664SJames Smart "6083 Abort cmpl: ctx x%px WCQE:%08x %08x %08x %08x\n", 3211d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 3212d613b6a7SJames Smart result, wcqe->word3); 3213d613b6a7SJames Smart 3214ce1b591cSJames Smart if (!ctxp) { 3215372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3216ce1b591cSJames Smart "6415 NVMET LS Abort No ctx: WCQE: " 3217ce1b591cSJames Smart "%08x %08x %08x %08x\n", 3218ce1b591cSJames Smart wcqe->word0, wcqe->total_data_placed, 3219ce1b591cSJames Smart result, wcqe->word3); 3220ce1b591cSJames Smart 3221ce1b591cSJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 3222ce1b591cSJames Smart return; 3223ce1b591cSJames Smart } 3224ce1b591cSJames Smart 32257b7f551bSJames Smart if (ctxp->state != LPFC_NVME_STE_LS_ABORT) { 3226372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3227ce1b591cSJames Smart "6416 NVMET LS abort cmpl state mismatch: " 3228ce1b591cSJames Smart "oxid x%x: %d %d\n", 3229ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 3230ce1b591cSJames Smart } 3231ce1b591cSJames Smart 3232d613b6a7SJames Smart cmdwqe->context2 = NULL; 3233d613b6a7SJames Smart cmdwqe->context3 = NULL; 3234d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 3235d613b6a7SJames Smart kfree(ctxp); 3236d613b6a7SJames Smart } 3237d613b6a7SJames Smart 3238d613b6a7SJames Smart static int 3239d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba, 32407cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, 3241d613b6a7SJames Smart uint32_t sid, uint16_t xri) 3242d613b6a7SJames Smart { 3243fcdd14b8SJames Smart struct lpfc_nvmet_tgtport *tgtp = NULL; 3244d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 3245205e8240SJames Smart union lpfc_wqe128 *wqe_abts; 3246d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 3247d613b6a7SJames Smart 3248d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 324986c67379SJames Smart "6067 ABTS: sid %x xri x%x/x%x\n", 3250318083adSJames Smart sid, xri, ctxp->wqeq->sli4_xritag); 3251d613b6a7SJames Smart 3252fcdd14b8SJames Smart if (phba->nvmet_support && phba->targetport) 3253d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3254d613b6a7SJames Smart 3255d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 3256307e3380SJames Smart if (!ndlp || 3257d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 3258d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 3259fcdd14b8SJames Smart if (tgtp) 3260d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3261372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3262d613b6a7SJames Smart "6134 Drop ABTS - wrong NDLP state x%x.\n", 3263b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 3264d613b6a7SJames Smart 3265d613b6a7SJames Smart /* No failure to an ABTS request. */ 3266d613b6a7SJames Smart return 0; 3267d613b6a7SJames Smart } 3268d613b6a7SJames Smart 3269d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 3270d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 3271d613b6a7SJames Smart 3272d613b6a7SJames Smart /* 3273d613b6a7SJames Smart * Since we zero the whole WQE, we need to ensure we set the WQE fields 3274d613b6a7SJames Smart * that were initialized in lpfc_sli4_nvmet_alloc. 3275d613b6a7SJames Smart */ 3276d613b6a7SJames Smart memset(wqe_abts, 0, sizeof(union lpfc_wqe)); 3277d613b6a7SJames Smart 3278d613b6a7SJames Smart /* Word 5 */ 3279d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0); 3280d613b6a7SJames Smart bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1); 3281d613b6a7SJames Smart bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0); 3282d613b6a7SJames Smart bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS); 3283d613b6a7SJames Smart bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS); 3284d613b6a7SJames Smart 3285d613b6a7SJames Smart /* Word 6 */ 3286d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com, 3287d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 3288d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com, 3289d613b6a7SJames Smart abts_wqeq->sli4_xritag); 3290d613b6a7SJames Smart 3291d613b6a7SJames Smart /* Word 7 */ 3292d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com, 3293d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 3294d613b6a7SJames Smart bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI); 3295d613b6a7SJames Smart bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3); 3296d613b6a7SJames Smart bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0); 3297d613b6a7SJames Smart 3298d613b6a7SJames Smart /* Word 8 */ 3299d613b6a7SJames Smart wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag; 3300d613b6a7SJames Smart 3301d613b6a7SJames Smart /* Word 9 */ 3302d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag); 3303d613b6a7SJames Smart /* Needs to be set by caller */ 3304d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri); 3305d613b6a7SJames Smart 3306d613b6a7SJames Smart /* Word 10 */ 3307d613b6a7SJames Smart bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1); 3308d613b6a7SJames Smart bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 3309d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com, 3310d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 3311d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0); 3312d613b6a7SJames Smart bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0); 3313d613b6a7SJames Smart 3314d613b6a7SJames Smart /* Word 11 */ 3315d613b6a7SJames Smart bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com, 3316d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 3317d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com, 3318d613b6a7SJames Smart OTHER_COMMAND); 3319d613b6a7SJames Smart 3320d613b6a7SJames Smart abts_wqeq->vport = phba->pport; 3321d613b6a7SJames Smart abts_wqeq->context1 = ndlp; 3322d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 3323d613b6a7SJames Smart abts_wqeq->context3 = NULL; 3324d613b6a7SJames Smart abts_wqeq->rsvd2 = 0; 3325d613b6a7SJames Smart /* hba_wqidx should already be setup from command we are aborting */ 3326d613b6a7SJames Smart abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR; 3327d613b6a7SJames Smart abts_wqeq->iocb.ulpLe = 1; 3328d613b6a7SJames Smart 3329d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 3330d613b6a7SJames Smart "6069 Issue ABTS to xri x%x reqtag x%x\n", 3331d613b6a7SJames Smart xri, abts_wqeq->iotag); 3332d613b6a7SJames Smart return 1; 3333d613b6a7SJames Smart } 3334d613b6a7SJames Smart 3335db7531d2SJames Smart /** 3336db7531d2SJames Smart * lpfc_nvmet_prep_abort_wqe - set up 'abort' work queue entry. 3337db7531d2SJames Smart * @pwqeq: Pointer to command iocb. 3338db7531d2SJames Smart * @xritag: Tag that uniqely identifies the local exchange resource. 3339db7531d2SJames Smart * @opt: Option bits - 3340db7531d2SJames Smart * bit 0 = inhibit sending abts on the link 3341db7531d2SJames Smart * 3342db7531d2SJames Smart * This function is called with hbalock held. 3343db7531d2SJames Smart **/ 3344185d17e1SJames Smart static void 3345db7531d2SJames Smart lpfc_nvmet_prep_abort_wqe(struct lpfc_iocbq *pwqeq, u16 xritag, u8 opt) 3346db7531d2SJames Smart { 3347db7531d2SJames Smart union lpfc_wqe128 *wqe = &pwqeq->wqe; 3348db7531d2SJames Smart 3349db7531d2SJames Smart /* WQEs are reused. Clear stale data and set key fields to 3350db7531d2SJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 3351db7531d2SJames Smart */ 3352db7531d2SJames Smart memset(wqe, 0, sizeof(*wqe)); 3353db7531d2SJames Smart 3354db7531d2SJames Smart if (opt & INHIBIT_ABORT) 3355db7531d2SJames Smart bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); 3356db7531d2SJames Smart /* Abort specified xri tag, with the mask deliberately zeroed */ 3357db7531d2SJames Smart bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); 3358db7531d2SJames Smart 3359db7531d2SJames Smart bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 3360db7531d2SJames Smart 3361db7531d2SJames Smart /* Abort the I/O associated with this outstanding exchange ID. */ 3362db7531d2SJames Smart wqe->abort_cmd.wqe_com.abort_tag = xritag; 3363db7531d2SJames Smart 3364db7531d2SJames Smart /* iotag for the wqe completion. */ 3365db7531d2SJames Smart bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, pwqeq->iotag); 3366db7531d2SJames Smart 3367db7531d2SJames Smart bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); 3368db7531d2SJames Smart bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 3369db7531d2SJames Smart 3370db7531d2SJames Smart bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND); 3371db7531d2SJames Smart bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1); 3372db7531d2SJames Smart bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 3373db7531d2SJames Smart } 3374db7531d2SJames Smart 3375d613b6a7SJames Smart static int 3376d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba, 33777cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, 3378d613b6a7SJames Smart uint32_t sid, uint16_t xri) 3379d613b6a7SJames Smart { 3380d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 3381d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 3382d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 3383d613b6a7SJames Smart unsigned long flags; 338451f8e43eSJames Smart u8 opt; 3385d613b6a7SJames Smart int rc; 3386d613b6a7SJames Smart 3387d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3388d613b6a7SJames Smart if (!ctxp->wqeq) { 33896c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 3390d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 3391d613b6a7SJames Smart } 3392d613b6a7SJames Smart 3393d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 3394307e3380SJames Smart if (!ndlp || 3395d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 3396d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 3397d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3398372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 339986c67379SJames Smart "6160 Drop ABORT - wrong NDLP state x%x.\n", 3400b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 3401d613b6a7SJames Smart 3402d613b6a7SJames Smart /* No failure to an ABTS request. */ 3403c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 34047b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 3405c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3406d613b6a7SJames Smart return 0; 3407d613b6a7SJames Smart } 3408d613b6a7SJames Smart 3409d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 3410d613b6a7SJames Smart ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba); 3411c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 3412d613b6a7SJames Smart if (!ctxp->abort_wqeq) { 3413547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3414372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 341586c67379SJames Smart "6161 ABORT failed: No wqeqs: " 3416d613b6a7SJames Smart "xri: x%x\n", ctxp->oxid); 3417d613b6a7SJames Smart /* No failure to an ABTS request. */ 34187b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 3419c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3420d613b6a7SJames Smart return 0; 3421d613b6a7SJames Smart } 3422d613b6a7SJames Smart abts_wqeq = ctxp->abort_wqeq; 34237b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_ABORT; 34247b7f551bSJames Smart opt = (ctxp->flag & LPFC_NVME_ABTS_RCV) ? INHIBIT_ABORT : 0; 3425c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3426d613b6a7SJames Smart 3427d613b6a7SJames Smart /* Announce entry to new IO submit field. */ 342886c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 342986c67379SJames Smart "6162 ABORT Request to rport DID x%06x " 3430d613b6a7SJames Smart "for xri x%x x%x\n", 3431d613b6a7SJames Smart ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag); 3432d613b6a7SJames Smart 3433d613b6a7SJames Smart /* If the hba is getting reset, this flag is set. It is 3434d613b6a7SJames Smart * cleared when the reset is complete and rings reestablished. 3435d613b6a7SJames Smart */ 3436d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 3437d613b6a7SJames Smart /* driver queued commands are in process of being flushed */ 3438c00f62e6SJames Smart if (phba->hba_flag & HBA_IOQ_FLUSH) { 3439d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3440547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3441372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3442d613b6a7SJames Smart "6163 Driver in reset cleanup - flushing " 3443d613b6a7SJames Smart "NVME Req now. hba_flag x%x oxid x%x\n", 3444d613b6a7SJames Smart phba->hba_flag, ctxp->oxid); 3445d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 3446c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 34477b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 3448c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3449d613b6a7SJames Smart return 0; 3450d613b6a7SJames Smart } 3451d613b6a7SJames Smart 3452d613b6a7SJames Smart /* Outstanding abort is in progress */ 3453d613b6a7SJames Smart if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) { 3454d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3455547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3456372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3457d613b6a7SJames Smart "6164 Outstanding NVME I/O Abort Request " 3458d613b6a7SJames Smart "still pending on oxid x%x\n", 3459d613b6a7SJames Smart ctxp->oxid); 3460d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 3461c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 34627b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 3463c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3464d613b6a7SJames Smart return 0; 3465d613b6a7SJames Smart } 3466d613b6a7SJames Smart 3467d613b6a7SJames Smart /* Ready - mark outstanding as aborted by driver. */ 3468d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED; 3469d613b6a7SJames Smart 3470db7531d2SJames Smart lpfc_nvmet_prep_abort_wqe(abts_wqeq, ctxp->wqeq->sli4_xritag, opt); 3471d613b6a7SJames Smart 3472d613b6a7SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 3473d613b6a7SJames Smart abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx; 3474d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp; 34755314995eSSaurav Girepunje abts_wqeq->iocb_cmpl = NULL; 3476d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME; 3477d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 34784550f9c7SJames Smart abts_wqeq->vport = phba->pport; 34791fbf9742SJames Smart if (!ctxp->hdwq) 34801fbf9742SJames Smart ctxp->hdwq = &phba->sli4_hba.hdwq[abts_wqeq->hba_wqidx]; 34811fbf9742SJames Smart 34821fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, ctxp->hdwq, abts_wqeq); 3483d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3484547077a4SJames Smart if (rc == WQE_SUCCESS) { 3485547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_sol); 3486d613b6a7SJames Smart return 0; 3487547077a4SJames Smart } 3488d613b6a7SJames Smart 3489547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3490c160c0f8SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 34917b7f551bSJames Smart ctxp->flag &= ~LPFC_NVME_ABORT_OP; 3492c160c0f8SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 3493d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 3494372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 349586c67379SJames Smart "6166 Failed ABORT issue_wqe with status x%x " 3496d613b6a7SJames Smart "for oxid x%x.\n", 3497d613b6a7SJames Smart rc, ctxp->oxid); 3498d613b6a7SJames Smart return 1; 3499d613b6a7SJames Smart } 3500d613b6a7SJames Smart 3501d613b6a7SJames Smart static int 3502d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba, 35037cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, 3504d613b6a7SJames Smart uint32_t sid, uint16_t xri) 3505d613b6a7SJames Smart { 3506d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 3507d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 3508d613b6a7SJames Smart unsigned long flags; 3509c160c0f8SJames Smart bool released = false; 3510d613b6a7SJames Smart int rc; 3511d613b6a7SJames Smart 3512d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3513d613b6a7SJames Smart if (!ctxp->wqeq) { 35146c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 3515d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 3516d613b6a7SJames Smart } 3517d613b6a7SJames Smart 35187b7f551bSJames Smart if (ctxp->state == LPFC_NVME_STE_FREE) { 3519372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3520ce1b591cSJames Smart "6417 NVMET ABORT ctx freed %d %d oxid x%x\n", 3521ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 3522ce1b591cSJames Smart rc = WQE_BUSY; 3523ce1b591cSJames Smart goto aerr; 3524ce1b591cSJames Smart } 35257b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_ABORT; 3526ce1b591cSJames Smart ctxp->entry_cnt++; 3527d613b6a7SJames Smart rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 3528d613b6a7SJames Smart if (rc == 0) 3529d613b6a7SJames Smart goto aerr; 3530d613b6a7SJames Smart 3531d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 3532d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 353386c67379SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_unsol_fcp_abort_cmp; 353486c67379SJames Smart abts_wqeq->iocb_cmpl = NULL; 3535d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVMET; 35361fbf9742SJames Smart if (!ctxp->hdwq) 35371fbf9742SJames Smart ctxp->hdwq = &phba->sli4_hba.hdwq[abts_wqeq->hba_wqidx]; 35381fbf9742SJames Smart 35391fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, ctxp->hdwq, abts_wqeq); 3540d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3541d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 3542d613b6a7SJames Smart return 0; 3543d613b6a7SJames Smart } 3544d613b6a7SJames Smart 3545d613b6a7SJames Smart aerr: 354668c9b55dSJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 35477b7f551bSJames Smart if (ctxp->flag & LPFC_NVME_CTX_RLS) { 3548c160c0f8SJames Smart spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 354979d8c4ceSJames Smart list_del_init(&ctxp->list); 3550c160c0f8SJames Smart spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock); 3551c160c0f8SJames Smart released = true; 3552c160c0f8SJames Smart } 35537b7f551bSJames Smart ctxp->flag &= ~(LPFC_NVME_ABORT_OP | LPFC_NVME_CTX_RLS); 355468c9b55dSJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 355568c9b55dSJames Smart 3556d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3557372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 355879d8c4ceSJames Smart "6135 Failed to Issue ABTS for oxid x%x. Status x%x " 355979d8c4ceSJames Smart "(%x)\n", 356079d8c4ceSJames Smart ctxp->oxid, rc, released); 3561c160c0f8SJames Smart if (released) 356268c9b55dSJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 3563d613b6a7SJames Smart return 1; 3564d613b6a7SJames Smart } 3565d613b6a7SJames Smart 35663a8070c5SJames Smart /** 35673a8070c5SJames Smart * lpfc_nvme_unsol_ls_issue_abort - issue ABTS on an exchange received 35683a8070c5SJames Smart * via async frame receive where the frame is not handled. 35693a8070c5SJames Smart * @phba: pointer to adapter structure 35703a8070c5SJames Smart * @ctxp: pointer to the asynchronously received received sequence 35713a8070c5SJames Smart * @sid: address of the remote port to send the ABTS to 35723a8070c5SJames Smart * @xri: oxid value to for the ABTS (other side's exchange id). 35733a8070c5SJames Smart **/ 35743a8070c5SJames Smart int 35753a8070c5SJames Smart lpfc_nvme_unsol_ls_issue_abort(struct lpfc_hba *phba, 35767cacae2aSJames Smart struct lpfc_async_xchg_ctx *ctxp, 3577d613b6a7SJames Smart uint32_t sid, uint16_t xri) 3578d613b6a7SJames Smart { 3579fcdd14b8SJames Smart struct lpfc_nvmet_tgtport *tgtp = NULL; 3580d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 3581d613b6a7SJames Smart unsigned long flags; 3582d613b6a7SJames Smart int rc; 3583d613b6a7SJames Smart 35847b7f551bSJames Smart if ((ctxp->state == LPFC_NVME_STE_LS_RCV && ctxp->entry_cnt == 1) || 35857b7f551bSJames Smart (ctxp->state == LPFC_NVME_STE_LS_RSP && ctxp->entry_cnt == 2)) { 35867b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_LS_ABORT; 3587ce1b591cSJames Smart ctxp->entry_cnt++; 3588ce1b591cSJames Smart } else { 3589372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3590ce1b591cSJames Smart "6418 NVMET LS abort state mismatch " 3591ce1b591cSJames Smart "IO x%x: %d %d\n", 3592ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 35937b7f551bSJames Smart ctxp->state = LPFC_NVME_STE_LS_ABORT; 3594ce1b591cSJames Smart } 3595ce1b591cSJames Smart 3596fcdd14b8SJames Smart if (phba->nvmet_support && phba->targetport) 3597d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3598fcdd14b8SJames Smart 3599d613b6a7SJames Smart if (!ctxp->wqeq) { 3600d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 3601d613b6a7SJames Smart ctxp->wqeq = lpfc_sli_get_iocbq(phba); 3602d613b6a7SJames Smart if (!ctxp->wqeq) { 3603372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3604d613b6a7SJames Smart "6068 Abort failed: No wqeqs: " 3605d613b6a7SJames Smart "xri: x%x\n", xri); 3606d613b6a7SJames Smart /* No failure to an ABTS request. */ 3607d613b6a7SJames Smart kfree(ctxp); 3608d613b6a7SJames Smart return 0; 3609d613b6a7SJames Smart } 3610d613b6a7SJames Smart } 3611d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 36126c621a22SJames Smart 3613ce1b591cSJames Smart if (lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri) == 0) { 3614ce1b591cSJames Smart rc = WQE_BUSY; 3615ce1b591cSJames Smart goto out; 3616ce1b591cSJames Smart } 3617d613b6a7SJames Smart 3618d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 3619d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp; 36205314995eSSaurav Girepunje abts_wqeq->iocb_cmpl = NULL; 3621d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS; 36221fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, ctxp->hdwq, abts_wqeq); 3623d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3624d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 3625fcdd14b8SJames Smart if (tgtp) 3626547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_unsol); 3627d613b6a7SJames Smart return 0; 3628d613b6a7SJames Smart } 3629ce1b591cSJames Smart out: 3630fcdd14b8SJames Smart if (tgtp) 3631d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3632d613b6a7SJames Smart abts_wqeq->context2 = NULL; 3633d613b6a7SJames Smart abts_wqeq->context3 = NULL; 3634d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 3635372c187bSDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 3636d613b6a7SJames Smart "6056 Failed to Issue ABTS. Status x%x\n", rc); 36374e57e0b9SJames Smart return 1; 3638d613b6a7SJames Smart } 36394c2805aaSJames Smart 36404c2805aaSJames Smart /** 36414c2805aaSJames Smart * lpfc_nvmet_invalidate_host 36424c2805aaSJames Smart * 3643d3cb79fcSLee Jones * @phba: pointer to the driver instance bound to an adapter port. 3644d3cb79fcSLee Jones * @ndlp: pointer to an lpfc_nodelist type 36454c2805aaSJames Smart * 36464c2805aaSJames Smart * This routine upcalls the nvmet transport to invalidate an NVME 36474c2805aaSJames Smart * host to which this target instance had active connections. 36484c2805aaSJames Smart */ 36494c2805aaSJames Smart void 36504c2805aaSJames Smart lpfc_nvmet_invalidate_host(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) 36514c2805aaSJames Smart { 3652*243156c0SJames Smart u32 ndlp_has_hh; 36534c2805aaSJames Smart struct lpfc_nvmet_tgtport *tgtp; 36544c2805aaSJames Smart 3655*243156c0SJames Smart lpfc_printf_log(phba, KERN_INFO, 3656*243156c0SJames Smart LOG_NVME | LOG_NVME_ABTS | LOG_NVME_DISC, 36574c2805aaSJames Smart "6203 Invalidating hosthandle x%px\n", 36584c2805aaSJames Smart ndlp); 36594c2805aaSJames Smart 36604c2805aaSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 36614c2805aaSJames Smart atomic_set(&tgtp->state, LPFC_NVMET_INV_HOST_ACTIVE); 36624c2805aaSJames Smart 3663*243156c0SJames Smart spin_lock_irq(&ndlp->lock); 3664*243156c0SJames Smart ndlp_has_hh = ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH; 3665*243156c0SJames Smart spin_unlock_irq(&ndlp->lock); 3666*243156c0SJames Smart 3667*243156c0SJames Smart /* Do not invalidate any nodes that do not have a hosthandle. 3668*243156c0SJames Smart * The host_release callbk will cause a node reference 3669*243156c0SJames Smart * count imbalance and a crash. 3670*243156c0SJames Smart */ 3671*243156c0SJames Smart if (!ndlp_has_hh) { 3672*243156c0SJames Smart lpfc_printf_log(phba, KERN_INFO, 3673*243156c0SJames Smart LOG_NVME | LOG_NVME_ABTS | LOG_NVME_DISC, 3674*243156c0SJames Smart "6204 Skip invalidate on node x%px DID x%x\n", 3675*243156c0SJames Smart ndlp, ndlp->nlp_DID); 3676*243156c0SJames Smart return; 3677*243156c0SJames Smart } 3678*243156c0SJames Smart 36794c2805aaSJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 36804c2805aaSJames Smart /* Need to get the nvmet_fc_target_port pointer here.*/ 36814c2805aaSJames Smart nvmet_fc_invalidate_host(phba->targetport, ndlp); 36824c2805aaSJames Smart #endif 36834c2805aaSJames Smart } 3684