1d613b6a7SJames Smart /******************************************************************* 2d613b6a7SJames Smart * This file is part of the Emulex Linux Device Driver for * 3d613b6a7SJames Smart * Fibre Channsel Host Bus Adapters. * 4128bddacSJames Smart * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * 5d080abe0SJames Smart * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * 6d613b6a7SJames Smart * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7d613b6a7SJames Smart * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 9d613b6a7SJames Smart * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10d613b6a7SJames Smart * * 11d613b6a7SJames Smart * This program is free software; you can redistribute it and/or * 12d613b6a7SJames Smart * modify it under the terms of version 2 of the GNU General * 13d613b6a7SJames Smart * Public License as published by the Free Software Foundation. * 14d613b6a7SJames Smart * This program is distributed in the hope that it will be useful. * 15d613b6a7SJames Smart * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16d613b6a7SJames Smart * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17d613b6a7SJames Smart * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18d613b6a7SJames Smart * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19d613b6a7SJames Smart * TO BE LEGALLY INVALID. See the GNU General Public License for * 20d613b6a7SJames Smart * more details, a copy of which can be found in the file COPYING * 21d613b6a7SJames Smart * included with this package. * 22d613b6a7SJames Smart ********************************************************************/ 23d613b6a7SJames Smart #include <linux/pci.h> 24d613b6a7SJames Smart #include <linux/slab.h> 25d613b6a7SJames Smart #include <linux/interrupt.h> 26d613b6a7SJames Smart #include <linux/delay.h> 27d613b6a7SJames Smart #include <asm/unaligned.h> 28d613b6a7SJames Smart #include <linux/crc-t10dif.h> 29d613b6a7SJames Smart #include <net/checksum.h> 30d613b6a7SJames Smart 31d613b6a7SJames Smart #include <scsi/scsi.h> 32d613b6a7SJames Smart #include <scsi/scsi_device.h> 33d613b6a7SJames Smart #include <scsi/scsi_eh.h> 34d613b6a7SJames Smart #include <scsi/scsi_host.h> 35d613b6a7SJames Smart #include <scsi/scsi_tcq.h> 36d613b6a7SJames Smart #include <scsi/scsi_transport_fc.h> 37d613b6a7SJames Smart #include <scsi/fc/fc_fs.h> 38d613b6a7SJames Smart 398d731d1aSJames Smart #include <linux/nvme.h> 40d613b6a7SJames Smart #include <linux/nvme-fc-driver.h> 41cbc5de1bSJames Smart #include <linux/nvme-fc.h> 42d613b6a7SJames Smart 43d613b6a7SJames Smart #include "lpfc_version.h" 44d613b6a7SJames Smart #include "lpfc_hw4.h" 45d613b6a7SJames Smart #include "lpfc_hw.h" 46d613b6a7SJames Smart #include "lpfc_sli.h" 47d613b6a7SJames Smart #include "lpfc_sli4.h" 48d613b6a7SJames Smart #include "lpfc_nl.h" 49d613b6a7SJames Smart #include "lpfc_disc.h" 50d613b6a7SJames Smart #include "lpfc.h" 51d613b6a7SJames Smart #include "lpfc_scsi.h" 52d613b6a7SJames Smart #include "lpfc_nvme.h" 53d613b6a7SJames Smart #include "lpfc_nvmet.h" 54d613b6a7SJames Smart #include "lpfc_logmsg.h" 55d613b6a7SJames Smart #include "lpfc_crtn.h" 56d613b6a7SJames Smart #include "lpfc_vport.h" 572b65e182SJames Smart #include "lpfc_debugfs.h" 58d613b6a7SJames Smart 59d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *, 60d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 61d613b6a7SJames Smart dma_addr_t rspbuf, 62d613b6a7SJames Smart uint16_t rspsize); 63d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *, 64d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *); 65d613b6a7SJames Smart static int lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *, 66d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 67d613b6a7SJames Smart uint32_t, uint16_t); 68d613b6a7SJames Smart static int lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *, 69d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 70d613b6a7SJames Smart uint32_t, uint16_t); 71d613b6a7SJames Smart static int lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *, 72d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 73d613b6a7SJames Smart uint32_t, uint16_t); 746e8e1c14SJames Smart static void lpfc_nvmet_wqfull_flush(struct lpfc_hba *, struct lpfc_queue *, 756e8e1c14SJames Smart struct lpfc_nvmet_rcv_ctx *); 76d613b6a7SJames Smart 7786c67379SJames Smart void 7886c67379SJames Smart lpfc_nvmet_defer_release(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp) 7986c67379SJames Smart { 8086c67379SJames Smart unsigned long iflag; 8186c67379SJames Smart 82e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 8386c67379SJames Smart "6313 NVMET Defer ctx release xri x%x flg x%x\n", 8486c67379SJames Smart ctxp->oxid, ctxp->flag); 8586c67379SJames Smart 8686c67379SJames Smart spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 8786c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS) { 8886c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, 8986c67379SJames Smart iflag); 9086c67379SJames Smart return; 9186c67379SJames Smart } 9286c67379SJames Smart ctxp->flag |= LPFC_NVMET_CTX_RLS; 9386c67379SJames Smart list_add_tail(&ctxp->list, &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); 9486c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 9586c67379SJames Smart } 9686c67379SJames Smart 97d613b6a7SJames Smart /** 98d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response 99d613b6a7SJames Smart * @phba: Pointer to HBA context object. 100d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 101d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 102d613b6a7SJames Smart * 103d613b6a7SJames Smart * The function is called from SLI ring event handler with no 104d613b6a7SJames Smart * lock held. This function is the completion handler for NVME LS commands 105d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 106d613b6a7SJames Smart **/ 107d613b6a7SJames Smart static void 108d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 109d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 110d613b6a7SJames Smart { 111d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 112d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp; 113d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 114d613b6a7SJames Smart uint32_t status, result; 115d613b6a7SJames Smart 116d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 117d613b6a7SJames Smart result = wcqe->parameter; 118ce1b591cSJames Smart ctxp = cmdwqe->context2; 119ce1b591cSJames Smart 120ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_LS_RSP || ctxp->entry_cnt != 2) { 121ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 122ce1b591cSJames Smart "6410 NVMET LS cmpl state mismatch IO x%x: " 123ce1b591cSJames Smart "%d %d\n", 124ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 125ce1b591cSJames Smart } 126ce1b591cSJames Smart 127d613b6a7SJames Smart if (!phba->targetport) 128d613b6a7SJames Smart goto out; 129d613b6a7SJames Smart 130d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 131d613b6a7SJames Smart 1324b056682SJames Smart if (tgtp) { 1334b056682SJames Smart if (status) { 134d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_error); 1358ae33701SJames Smart if (result == IOERR_ABORT_REQUESTED) 1364b056682SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_aborted); 1374b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 1384b056682SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_xb_set); 1394b056682SJames Smart } else { 140d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_cmpl); 1414b056682SJames Smart } 1424b056682SJames Smart } 143d613b6a7SJames Smart 144d613b6a7SJames Smart out: 145d613b6a7SJames Smart rsp = &ctxp->ctx.ls_req; 146d613b6a7SJames Smart 1472b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS CMPL: xri x%x stat x%x result x%x\n", 1482b65e182SJames Smart ctxp->oxid, status, result); 1492b65e182SJames Smart 150d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 151ce1b591cSJames Smart "6038 NVMET LS rsp cmpl: %d %d oxid x%x\n", 152ce1b591cSJames Smart status, result, ctxp->oxid); 153d613b6a7SJames Smart 154d613b6a7SJames Smart lpfc_nlp_put(cmdwqe->context1); 155d613b6a7SJames Smart cmdwqe->context2 = NULL; 156d613b6a7SJames Smart cmdwqe->context3 = NULL; 157d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 158d613b6a7SJames Smart rsp->done(rsp); 159d613b6a7SJames Smart kfree(ctxp); 160d613b6a7SJames Smart } 161d613b6a7SJames Smart 162d613b6a7SJames Smart /** 1636c621a22SJames Smart * lpfc_nvmet_ctxbuf_post - Repost a NVMET RQ DMA buffer and clean up context 164d613b6a7SJames Smart * @phba: HBA buffer is associated with 165d613b6a7SJames Smart * @ctxp: context to clean up 166d613b6a7SJames Smart * @mp: Buffer to free 167d613b6a7SJames Smart * 168d613b6a7SJames Smart * Description: Frees the given DMA buffer in the appropriate way given by 169d613b6a7SJames Smart * reposting it to its associated RQ so it can be reused. 170d613b6a7SJames Smart * 171d613b6a7SJames Smart * Notes: Takes phba->hbalock. Can be called with or without other locks held. 172d613b6a7SJames Smart * 173d613b6a7SJames Smart * Returns: None 174d613b6a7SJames Smart **/ 175d613b6a7SJames Smart void 1766c621a22SJames Smart lpfc_nvmet_ctxbuf_post(struct lpfc_hba *phba, struct lpfc_nvmet_ctxbuf *ctx_buf) 177d613b6a7SJames Smart { 178eeeb51d8SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1796c621a22SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = ctx_buf->context; 180a8cf5dfeSJames Smart struct lpfc_nvmet_tgtport *tgtp; 181a8cf5dfeSJames Smart struct fc_frame_header *fc_hdr; 182a8cf5dfeSJames Smart struct rqb_dmabuf *nvmebuf; 18366d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 184a8cf5dfeSJames Smart uint32_t *payload; 185a8cf5dfeSJames Smart uint32_t size, oxid, sid, rc; 18666d7ce93SDick Kennedy int cpu; 1876c621a22SJames Smart unsigned long iflag; 18886c67379SJames Smart 189d613b6a7SJames Smart if (ctxp->txrdy) { 190771db5c0SRomain Perier dma_pool_free(phba->txrdy_payload_pool, ctxp->txrdy, 191d613b6a7SJames Smart ctxp->txrdy_phys); 192d613b6a7SJames Smart ctxp->txrdy = NULL; 193d613b6a7SJames Smart ctxp->txrdy_phys = 0; 194d613b6a7SJames Smart } 195ce1b591cSJames Smart 196ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_FREE) { 197ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 198ce1b591cSJames Smart "6411 NVMET free, already free IO x%x: %d %d\n", 199ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 200ce1b591cSJames Smart } 201d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_FREE; 2026c621a22SJames Smart 203a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 204a8cf5dfeSJames Smart if (phba->sli4_hba.nvmet_io_wait_cnt) { 205a8cf5dfeSJames Smart list_remove_head(&phba->sli4_hba.lpfc_nvmet_io_wait_list, 206a8cf5dfeSJames Smart nvmebuf, struct rqb_dmabuf, 207a8cf5dfeSJames Smart hbuf.list); 208a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt--; 209a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 210a8cf5dfeSJames Smart iflag); 211a8cf5dfeSJames Smart 212a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 213a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 214a8cf5dfeSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 215a8cf5dfeSJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 216a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 217a8cf5dfeSJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 218a8cf5dfeSJames Smart 219a8cf5dfeSJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context; 220a8cf5dfeSJames Smart ctxp->wqeq = NULL; 221a8cf5dfeSJames Smart ctxp->txrdy = NULL; 222a8cf5dfeSJames Smart ctxp->offset = 0; 223a8cf5dfeSJames Smart ctxp->phba = phba; 224a8cf5dfeSJames Smart ctxp->size = size; 225a8cf5dfeSJames Smart ctxp->oxid = oxid; 226a8cf5dfeSJames Smart ctxp->sid = sid; 227a8cf5dfeSJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 228a8cf5dfeSJames Smart ctxp->entry_cnt = 1; 229a8cf5dfeSJames Smart ctxp->flag = 0; 230a8cf5dfeSJames Smart ctxp->ctxbuf = ctx_buf; 231cbc5de1bSJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 232a8cf5dfeSJames Smart spin_lock_init(&ctxp->ctxlock); 233a8cf5dfeSJames Smart 234a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 235c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 236a8cf5dfeSJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 237a8cf5dfeSJames Smart ctxp->ts_nvme_data = 0; 238a8cf5dfeSJames Smart ctxp->ts_data_wqput = 0; 239a8cf5dfeSJames Smart ctxp->ts_isr_data = 0; 240a8cf5dfeSJames Smart ctxp->ts_data_nvme = 0; 241a8cf5dfeSJames Smart ctxp->ts_nvme_status = 0; 242a8cf5dfeSJames Smart ctxp->ts_status_wqput = 0; 243a8cf5dfeSJames Smart ctxp->ts_isr_status = 0; 244a8cf5dfeSJames Smart ctxp->ts_status_nvme = 0; 245d613b6a7SJames Smart } 246a8cf5dfeSJames Smart #endif 247a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 248a8cf5dfeSJames Smart /* 249a8cf5dfeSJames Smart * The calling sequence should be: 250a8cf5dfeSJames Smart * nvmet_fc_rcv_fcp_req->lpfc_nvmet_xmt_fcp_op/cmp- req->done 251a8cf5dfeSJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 252a8cf5dfeSJames Smart * When we return from nvmet_fc_rcv_fcp_req, all relevant info 253a8cf5dfeSJames Smart * the NVME command / FC header is stored. 254a8cf5dfeSJames Smart * A buffer has already been reposted for this IO, so just free 255a8cf5dfeSJames Smart * the nvmebuf. 256a8cf5dfeSJames Smart */ 257a8cf5dfeSJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 258a8cf5dfeSJames Smart payload, size); 259a8cf5dfeSJames Smart 260a8cf5dfeSJames Smart /* Process FCP command */ 261a8cf5dfeSJames Smart if (rc == 0) { 262a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 263a8cf5dfeSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 264a8cf5dfeSJames Smart return; 265a8cf5dfeSJames Smart } 266a8cf5dfeSJames Smart 267cbc5de1bSJames Smart /* Processing of FCP command is deferred */ 268cbc5de1bSJames Smart if (rc == -EOVERFLOW) { 269cbc5de1bSJames Smart lpfc_nvmeio_data(phba, 270cbc5de1bSJames Smart "NVMET RCV BUSY: xri x%x sz %d " 271cbc5de1bSJames Smart "from %06x\n", 272cbc5de1bSJames Smart oxid, size, sid); 273cbc5de1bSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 274cbc5de1bSJames Smart return; 275cbc5de1bSJames Smart } 276a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 277a8cf5dfeSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 278a8cf5dfeSJames Smart "2582 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 279a8cf5dfeSJames Smart ctxp->oxid, rc, 280a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 281a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 282a8cf5dfeSJames Smart atomic_read(&tgtp->xmt_fcp_release)); 283a8cf5dfeSJames Smart 284a8cf5dfeSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 285a8cf5dfeSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 286a8cf5dfeSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 287a8cf5dfeSJames Smart return; 288a8cf5dfeSJames Smart } 289a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 290a8cf5dfeSJames Smart 29166d7ce93SDick Kennedy /* 29266d7ce93SDick Kennedy * Use the CPU context list, from the MRQ the IO was received on 29366d7ce93SDick Kennedy * (ctxp->idx), to save context structure. 29466d7ce93SDick Kennedy */ 29566d7ce93SDick Kennedy cpu = smp_processor_id(); 29666d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, cpu, ctxp->idx); 29766d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, iflag); 29866d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 29966d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 30066d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, iflag); 301eeeb51d8SJames Smart #endif 302d613b6a7SJames Smart } 303d613b6a7SJames Smart 3042b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 3052b65e182SJames Smart static void 3062b65e182SJames Smart lpfc_nvmet_ktime(struct lpfc_hba *phba, 3072b65e182SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 3082b65e182SJames Smart { 3092b65e182SJames Smart uint64_t seg1, seg2, seg3, seg4, seg5; 3102b65e182SJames Smart uint64_t seg6, seg7, seg8, seg9, seg10; 311c8a4ce0bSDick Kennedy uint64_t segsum; 3122b65e182SJames Smart 3132b65e182SJames Smart if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme || 3142b65e182SJames Smart !ctxp->ts_nvme_data || !ctxp->ts_data_wqput || 3152b65e182SJames Smart !ctxp->ts_isr_data || !ctxp->ts_data_nvme || 3162b65e182SJames Smart !ctxp->ts_nvme_status || !ctxp->ts_status_wqput || 3172b65e182SJames Smart !ctxp->ts_isr_status || !ctxp->ts_status_nvme) 3182b65e182SJames Smart return; 3192b65e182SJames Smart 320c8a4ce0bSDick Kennedy if (ctxp->ts_status_nvme < ctxp->ts_isr_cmd) 321c8a4ce0bSDick Kennedy return; 3222b65e182SJames Smart if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme) 3232b65e182SJames Smart return; 3242b65e182SJames Smart if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data) 3252b65e182SJames Smart return; 3262b65e182SJames Smart if (ctxp->ts_nvme_data > ctxp->ts_data_wqput) 3272b65e182SJames Smart return; 3282b65e182SJames Smart if (ctxp->ts_data_wqput > ctxp->ts_isr_data) 3292b65e182SJames Smart return; 3302b65e182SJames Smart if (ctxp->ts_isr_data > ctxp->ts_data_nvme) 3312b65e182SJames Smart return; 3322b65e182SJames Smart if (ctxp->ts_data_nvme > ctxp->ts_nvme_status) 3332b65e182SJames Smart return; 3342b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_status_wqput) 3352b65e182SJames Smart return; 3362b65e182SJames Smart if (ctxp->ts_status_wqput > ctxp->ts_isr_status) 3372b65e182SJames Smart return; 3382b65e182SJames Smart if (ctxp->ts_isr_status > ctxp->ts_status_nvme) 3392b65e182SJames Smart return; 3402b65e182SJames Smart /* 3412b65e182SJames Smart * Segment 1 - Time from FCP command received by MSI-X ISR 3422b65e182SJames Smart * to FCP command is passed to NVME Layer. 3432b65e182SJames Smart * Segment 2 - Time from FCP command payload handed 3442b65e182SJames Smart * off to NVME Layer to Driver receives a Command op 3452b65e182SJames Smart * from NVME Layer. 3462b65e182SJames Smart * Segment 3 - Time from Driver receives a Command op 3472b65e182SJames Smart * from NVME Layer to Command is put on WQ. 3482b65e182SJames Smart * Segment 4 - Time from Driver WQ put is done 3492b65e182SJames Smart * to MSI-X ISR for Command cmpl. 3502b65e182SJames Smart * Segment 5 - Time from MSI-X ISR for Command cmpl to 3512b65e182SJames Smart * Command cmpl is passed to NVME Layer. 3522b65e182SJames Smart * Segment 6 - Time from Command cmpl is passed to NVME 3532b65e182SJames Smart * Layer to Driver receives a RSP op from NVME Layer. 3542b65e182SJames Smart * Segment 7 - Time from Driver receives a RSP op from 3552b65e182SJames Smart * NVME Layer to WQ put is done on TRSP FCP Status. 3562b65e182SJames Smart * Segment 8 - Time from Driver WQ put is done on TRSP 3572b65e182SJames Smart * FCP Status to MSI-X ISR for TRSP cmpl. 3582b65e182SJames Smart * Segment 9 - Time from MSI-X ISR for TRSP cmpl to 3592b65e182SJames Smart * TRSP cmpl is passed to NVME Layer. 3602b65e182SJames Smart * Segment 10 - Time from FCP command received by 3612b65e182SJames Smart * MSI-X ISR to command is completed on wire. 3622b65e182SJames Smart * (Segments 1 thru 8) for READDATA / WRITEDATA 3632b65e182SJames Smart * (Segments 1 thru 4) for READDATA_RSP 3642b65e182SJames Smart */ 3652b65e182SJames Smart seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd; 366c8a4ce0bSDick Kennedy segsum = seg1; 367c8a4ce0bSDick Kennedy 368c8a4ce0bSDick Kennedy seg2 = ctxp->ts_nvme_data - ctxp->ts_isr_cmd; 369c8a4ce0bSDick Kennedy if (segsum > seg2) 370c8a4ce0bSDick Kennedy return; 371c8a4ce0bSDick Kennedy seg2 -= segsum; 372c8a4ce0bSDick Kennedy segsum += seg2; 373c8a4ce0bSDick Kennedy 374c8a4ce0bSDick Kennedy seg3 = ctxp->ts_data_wqput - ctxp->ts_isr_cmd; 375c8a4ce0bSDick Kennedy if (segsum > seg3) 376c8a4ce0bSDick Kennedy return; 377c8a4ce0bSDick Kennedy seg3 -= segsum; 378c8a4ce0bSDick Kennedy segsum += seg3; 379c8a4ce0bSDick Kennedy 380c8a4ce0bSDick Kennedy seg4 = ctxp->ts_isr_data - ctxp->ts_isr_cmd; 381c8a4ce0bSDick Kennedy if (segsum > seg4) 382c8a4ce0bSDick Kennedy return; 383c8a4ce0bSDick Kennedy seg4 -= segsum; 384c8a4ce0bSDick Kennedy segsum += seg4; 385c8a4ce0bSDick Kennedy 386c8a4ce0bSDick Kennedy seg5 = ctxp->ts_data_nvme - ctxp->ts_isr_cmd; 387c8a4ce0bSDick Kennedy if (segsum > seg5) 388c8a4ce0bSDick Kennedy return; 389c8a4ce0bSDick Kennedy seg5 -= segsum; 390c8a4ce0bSDick Kennedy segsum += seg5; 391c8a4ce0bSDick Kennedy 3922b65e182SJames Smart 3932b65e182SJames Smart /* For auto rsp commands seg6 thru seg10 will be 0 */ 3942b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) { 395c8a4ce0bSDick Kennedy seg6 = ctxp->ts_nvme_status - ctxp->ts_isr_cmd; 396c8a4ce0bSDick Kennedy if (segsum > seg6) 397c8a4ce0bSDick Kennedy return; 398c8a4ce0bSDick Kennedy seg6 -= segsum; 399c8a4ce0bSDick Kennedy segsum += seg6; 400c8a4ce0bSDick Kennedy 401c8a4ce0bSDick Kennedy seg7 = ctxp->ts_status_wqput - ctxp->ts_isr_cmd; 402c8a4ce0bSDick Kennedy if (segsum > seg7) 403c8a4ce0bSDick Kennedy return; 404c8a4ce0bSDick Kennedy seg7 -= segsum; 405c8a4ce0bSDick Kennedy segsum += seg7; 406c8a4ce0bSDick Kennedy 407c8a4ce0bSDick Kennedy seg8 = ctxp->ts_isr_status - ctxp->ts_isr_cmd; 408c8a4ce0bSDick Kennedy if (segsum > seg8) 409c8a4ce0bSDick Kennedy return; 410c8a4ce0bSDick Kennedy seg8 -= segsum; 411c8a4ce0bSDick Kennedy segsum += seg8; 412c8a4ce0bSDick Kennedy 413c8a4ce0bSDick Kennedy seg9 = ctxp->ts_status_nvme - ctxp->ts_isr_cmd; 414c8a4ce0bSDick Kennedy if (segsum > seg9) 415c8a4ce0bSDick Kennedy return; 416c8a4ce0bSDick Kennedy seg9 -= segsum; 417c8a4ce0bSDick Kennedy segsum += seg9; 418c8a4ce0bSDick Kennedy 419c8a4ce0bSDick Kennedy if (ctxp->ts_isr_status < ctxp->ts_isr_cmd) 420c8a4ce0bSDick Kennedy return; 4212b65e182SJames Smart seg10 = (ctxp->ts_isr_status - 4222b65e182SJames Smart ctxp->ts_isr_cmd); 4232b65e182SJames Smart } else { 424c8a4ce0bSDick Kennedy if (ctxp->ts_isr_data < ctxp->ts_isr_cmd) 425c8a4ce0bSDick Kennedy return; 4262b65e182SJames Smart seg6 = 0; 4272b65e182SJames Smart seg7 = 0; 4282b65e182SJames Smart seg8 = 0; 4292b65e182SJames Smart seg9 = 0; 4302b65e182SJames Smart seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd); 4312b65e182SJames Smart } 4322b65e182SJames Smart 4332b65e182SJames Smart phba->ktime_seg1_total += seg1; 4342b65e182SJames Smart if (seg1 < phba->ktime_seg1_min) 4352b65e182SJames Smart phba->ktime_seg1_min = seg1; 4362b65e182SJames Smart else if (seg1 > phba->ktime_seg1_max) 4372b65e182SJames Smart phba->ktime_seg1_max = seg1; 4382b65e182SJames Smart 4392b65e182SJames Smart phba->ktime_seg2_total += seg2; 4402b65e182SJames Smart if (seg2 < phba->ktime_seg2_min) 4412b65e182SJames Smart phba->ktime_seg2_min = seg2; 4422b65e182SJames Smart else if (seg2 > phba->ktime_seg2_max) 4432b65e182SJames Smart phba->ktime_seg2_max = seg2; 4442b65e182SJames Smart 4452b65e182SJames Smart phba->ktime_seg3_total += seg3; 4462b65e182SJames Smart if (seg3 < phba->ktime_seg3_min) 4472b65e182SJames Smart phba->ktime_seg3_min = seg3; 4482b65e182SJames Smart else if (seg3 > phba->ktime_seg3_max) 4492b65e182SJames Smart phba->ktime_seg3_max = seg3; 4502b65e182SJames Smart 4512b65e182SJames Smart phba->ktime_seg4_total += seg4; 4522b65e182SJames Smart if (seg4 < phba->ktime_seg4_min) 4532b65e182SJames Smart phba->ktime_seg4_min = seg4; 4542b65e182SJames Smart else if (seg4 > phba->ktime_seg4_max) 4552b65e182SJames Smart phba->ktime_seg4_max = seg4; 4562b65e182SJames Smart 4572b65e182SJames Smart phba->ktime_seg5_total += seg5; 4582b65e182SJames Smart if (seg5 < phba->ktime_seg5_min) 4592b65e182SJames Smart phba->ktime_seg5_min = seg5; 4602b65e182SJames Smart else if (seg5 > phba->ktime_seg5_max) 4612b65e182SJames Smart phba->ktime_seg5_max = seg5; 4622b65e182SJames Smart 4632b65e182SJames Smart phba->ktime_data_samples++; 4642b65e182SJames Smart if (!seg6) 4652b65e182SJames Smart goto out; 4662b65e182SJames Smart 4672b65e182SJames Smart phba->ktime_seg6_total += seg6; 4682b65e182SJames Smart if (seg6 < phba->ktime_seg6_min) 4692b65e182SJames Smart phba->ktime_seg6_min = seg6; 4702b65e182SJames Smart else if (seg6 > phba->ktime_seg6_max) 4712b65e182SJames Smart phba->ktime_seg6_max = seg6; 4722b65e182SJames Smart 4732b65e182SJames Smart phba->ktime_seg7_total += seg7; 4742b65e182SJames Smart if (seg7 < phba->ktime_seg7_min) 4752b65e182SJames Smart phba->ktime_seg7_min = seg7; 4762b65e182SJames Smart else if (seg7 > phba->ktime_seg7_max) 4772b65e182SJames Smart phba->ktime_seg7_max = seg7; 4782b65e182SJames Smart 4792b65e182SJames Smart phba->ktime_seg8_total += seg8; 4802b65e182SJames Smart if (seg8 < phba->ktime_seg8_min) 4812b65e182SJames Smart phba->ktime_seg8_min = seg8; 4822b65e182SJames Smart else if (seg8 > phba->ktime_seg8_max) 4832b65e182SJames Smart phba->ktime_seg8_max = seg8; 4842b65e182SJames Smart 4852b65e182SJames Smart phba->ktime_seg9_total += seg9; 4862b65e182SJames Smart if (seg9 < phba->ktime_seg9_min) 4872b65e182SJames Smart phba->ktime_seg9_min = seg9; 4882b65e182SJames Smart else if (seg9 > phba->ktime_seg9_max) 4892b65e182SJames Smart phba->ktime_seg9_max = seg9; 4902b65e182SJames Smart out: 4912b65e182SJames Smart phba->ktime_seg10_total += seg10; 4922b65e182SJames Smart if (seg10 < phba->ktime_seg10_min) 4932b65e182SJames Smart phba->ktime_seg10_min = seg10; 4942b65e182SJames Smart else if (seg10 > phba->ktime_seg10_max) 4952b65e182SJames Smart phba->ktime_seg10_max = seg10; 4962b65e182SJames Smart phba->ktime_status_samples++; 4972b65e182SJames Smart } 4982b65e182SJames Smart #endif 4992b65e182SJames Smart 500d613b6a7SJames Smart /** 501d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response 502d613b6a7SJames Smart * @phba: Pointer to HBA context object. 503d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 504d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 505d613b6a7SJames Smart * 506d613b6a7SJames Smart * The function is called from SLI ring event handler with no 507d613b6a7SJames Smart * lock held. This function is the completion handler for NVME FCP commands 508d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 509d613b6a7SJames Smart **/ 510d613b6a7SJames Smart static void 511d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 512d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 513d613b6a7SJames Smart { 514d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 515d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp; 516d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 517e3246a12SJames Smart uint32_t status, result, op, start_clean, logerr; 5182b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 5192b65e182SJames Smart uint32_t id; 5202b65e182SJames Smart #endif 521d613b6a7SJames Smart 522d613b6a7SJames Smart ctxp = cmdwqe->context2; 52386c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_IO_INP; 52486c67379SJames Smart 525d613b6a7SJames Smart rsp = &ctxp->ctx.fcp_req; 526d613b6a7SJames Smart op = rsp->op; 527d613b6a7SJames Smart 528d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 529d613b6a7SJames Smart result = wcqe->parameter; 530d613b6a7SJames Smart 53186c67379SJames Smart if (phba->targetport) 53286c67379SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 53386c67379SJames Smart else 53486c67379SJames Smart tgtp = NULL; 535d613b6a7SJames Smart 5362b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n", 5372b65e182SJames Smart ctxp->oxid, op, status); 5382b65e182SJames Smart 539d613b6a7SJames Smart if (status) { 540d613b6a7SJames Smart rsp->fcp_error = NVME_SC_DATA_XFER_ERROR; 541d613b6a7SJames Smart rsp->transferred_length = 0; 5424b056682SJames Smart if (tgtp) { 543d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_error); 5448ae33701SJames Smart if (result == IOERR_ABORT_REQUESTED) 5454b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_aborted); 5464b056682SJames Smart } 54786c67379SJames Smart 548e3246a12SJames Smart logerr = LOG_NVME_IOERR; 549e3246a12SJames Smart 55086c67379SJames Smart /* pick up SLI4 exhange busy condition */ 55186c67379SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) { 55286c67379SJames Smart ctxp->flag |= LPFC_NVMET_XBUSY; 553e3246a12SJames Smart logerr |= LOG_NVME_ABTS; 5544b056682SJames Smart if (tgtp) 5554b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_xb_set); 55686c67379SJames Smart 55786c67379SJames Smart } else { 55886c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 55986c67379SJames Smart } 56086c67379SJames Smart 561e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, logerr, 562e3246a12SJames Smart "6315 IO Error Cmpl xri x%x: %x/%x XBUSY:x%x\n", 563e3246a12SJames Smart ctxp->oxid, status, result, ctxp->flag); 564e3246a12SJames Smart 565d613b6a7SJames Smart } else { 566d613b6a7SJames Smart rsp->fcp_error = NVME_SC_SUCCESS; 567d613b6a7SJames Smart if (op == NVMET_FCOP_RSP) 568d613b6a7SJames Smart rsp->transferred_length = rsp->rsplen; 569d613b6a7SJames Smart else 570d613b6a7SJames Smart rsp->transferred_length = rsp->transfer_length; 57186c67379SJames Smart if (tgtp) 572d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_cmpl); 573d613b6a7SJames Smart } 574d613b6a7SJames Smart 575d613b6a7SJames Smart if ((op == NVMET_FCOP_READDATA_RSP) || 576d613b6a7SJames Smart (op == NVMET_FCOP_RSP)) { 577d613b6a7SJames Smart /* Sanity check */ 578d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 579d613b6a7SJames Smart ctxp->entry_cnt++; 58086c67379SJames Smart 5812b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 582c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 5832b65e182SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 5842b65e182SJames Smart ctxp->ts_isr_data = 5852b65e182SJames Smart cmdwqe->isr_timestamp; 5862b65e182SJames Smart ctxp->ts_data_nvme = 5872b65e182SJames Smart ktime_get_ns(); 5882b65e182SJames Smart ctxp->ts_nvme_status = 5892b65e182SJames Smart ctxp->ts_data_nvme; 5902b65e182SJames Smart ctxp->ts_status_wqput = 5912b65e182SJames Smart ctxp->ts_data_nvme; 5922b65e182SJames Smart ctxp->ts_isr_status = 5932b65e182SJames Smart ctxp->ts_data_nvme; 5942b65e182SJames Smart ctxp->ts_status_nvme = 5952b65e182SJames Smart ctxp->ts_data_nvme; 5962b65e182SJames Smart } else { 5972b65e182SJames Smart ctxp->ts_isr_status = 5982b65e182SJames Smart cmdwqe->isr_timestamp; 5992b65e182SJames Smart ctxp->ts_status_nvme = 6002b65e182SJames Smart ktime_get_ns(); 6012b65e182SJames Smart } 6022b65e182SJames Smart } 6032b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 6042b65e182SJames Smart id = smp_processor_id(); 6052b65e182SJames Smart if (ctxp->cpu != id) 6062b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 6072b65e182SJames Smart "6703 CPU Check cmpl: " 6082b65e182SJames Smart "cpu %d expect %d\n", 6092b65e182SJames Smart id, ctxp->cpu); 6102b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 6112b65e182SJames Smart phba->cpucheck_cmpl_io[id]++; 6122b65e182SJames Smart } 6132b65e182SJames Smart #endif 614d613b6a7SJames Smart rsp->done(rsp); 6152b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 616c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) 6172b65e182SJames Smart lpfc_nvmet_ktime(phba, ctxp); 6182b65e182SJames Smart #endif 61919b58d94SJames Smart /* lpfc_nvmet_xmt_fcp_release() will recycle the context */ 620d613b6a7SJames Smart } else { 621d613b6a7SJames Smart ctxp->entry_cnt++; 622c6e0c925SDick Kennedy start_clean = offsetof(struct lpfc_iocbq, iocb_flag); 623d613b6a7SJames Smart memset(((char *)cmdwqe) + start_clean, 0, 624d613b6a7SJames Smart (sizeof(struct lpfc_iocbq) - start_clean)); 6252b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 626c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 6272b65e182SJames Smart ctxp->ts_isr_data = cmdwqe->isr_timestamp; 6282b65e182SJames Smart ctxp->ts_data_nvme = ktime_get_ns(); 6292b65e182SJames Smart } 6302b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 6312b65e182SJames Smart id = smp_processor_id(); 6322b65e182SJames Smart if (ctxp->cpu != id) 6332b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 6342b65e182SJames Smart "6704 CPU Check cmdcmpl: " 6352b65e182SJames Smart "cpu %d expect %d\n", 6362b65e182SJames Smart id, ctxp->cpu); 6372b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 6382b65e182SJames Smart phba->cpucheck_ccmpl_io[id]++; 6392b65e182SJames Smart } 6402b65e182SJames Smart #endif 641d613b6a7SJames Smart rsp->done(rsp); 642d613b6a7SJames Smart } 643d613b6a7SJames Smart } 644d613b6a7SJames Smart 645d613b6a7SJames Smart static int 646d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport, 647d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp) 648d613b6a7SJames Smart { 649d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 650d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.ls_req); 651d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 652d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf = 653d613b6a7SJames Smart (struct hbq_dmabuf *)ctxp->rqb_buffer; 654d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 655d613b6a7SJames Smart struct lpfc_nvmet_tgtport *nvmep = tgtport->private; 656d613b6a7SJames Smart struct lpfc_dmabuf dmabuf; 657d613b6a7SJames Smart struct ulp_bde64 bpl; 658d613b6a7SJames Smart int rc; 659d613b6a7SJames Smart 6601abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) 6611abcb371SDick Kennedy return -ENODEV; 6621abcb371SDick Kennedy 6633386f4bdSJames Smart if (phba->pport->load_flag & FC_UNLOADING) 6643386f4bdSJames Smart return -ENODEV; 6653386f4bdSJames Smart 666d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 667ce1b591cSJames Smart "6023 NVMET LS rsp oxid x%x\n", ctxp->oxid); 668ce1b591cSJames Smart 669ce1b591cSJames Smart if ((ctxp->state != LPFC_NVMET_STE_LS_RCV) || 670ce1b591cSJames Smart (ctxp->entry_cnt != 1)) { 671ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 672ce1b591cSJames Smart "6412 NVMET LS rsp state mismatch " 673ce1b591cSJames Smart "oxid x%x: %d %d\n", 674ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 675ce1b591cSJames Smart } 676ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_RSP; 677ce1b591cSJames Smart ctxp->entry_cnt++; 678d613b6a7SJames Smart 679d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, ctxp, rsp->rspdma, 680d613b6a7SJames Smart rsp->rsplen); 681d613b6a7SJames Smart if (nvmewqeq == NULL) { 682d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 683d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 684d613b6a7SJames Smart "6150 LS Drop IO x%x: Prep\n", 685d613b6a7SJames Smart ctxp->oxid); 686d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 687547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 688d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, 689d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 690d613b6a7SJames Smart return -ENOMEM; 691d613b6a7SJames Smart } 692d613b6a7SJames Smart 693d613b6a7SJames Smart /* Save numBdes for bpl2sgl */ 694d613b6a7SJames Smart nvmewqeq->rsvd2 = 1; 695d613b6a7SJames Smart nvmewqeq->hba_wqidx = 0; 696d613b6a7SJames Smart nvmewqeq->context3 = &dmabuf; 697d613b6a7SJames Smart dmabuf.virt = &bpl; 698d613b6a7SJames Smart bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow; 699d613b6a7SJames Smart bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh; 700d613b6a7SJames Smart bpl.tus.f.bdeSize = rsp->rsplen; 701d613b6a7SJames Smart bpl.tus.f.bdeFlags = 0; 702d613b6a7SJames Smart bpl.tus.w = le32_to_cpu(bpl.tus.w); 703d613b6a7SJames Smart 704d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_rsp_cmp; 705d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 706d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 707d613b6a7SJames Smart 7082b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RESP: xri x%x wqidx x%x len x%x\n", 7092b65e182SJames Smart ctxp->oxid, nvmewqeq->hba_wqidx, rsp->rsplen); 7102b65e182SJames Smart 711d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, nvmewqeq); 712d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 713d613b6a7SJames Smart /* 714d613b6a7SJames Smart * Okay to repost buffer here, but wait till cmpl 715d613b6a7SJames Smart * before freeing ctxp and iocbq. 716d613b6a7SJames Smart */ 717d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 718d613b6a7SJames Smart ctxp->rqb_buffer = 0; 719d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_rsp); 720d613b6a7SJames Smart return 0; 721d613b6a7SJames Smart } 722d613b6a7SJames Smart /* Give back resources */ 723d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 724d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 725d613b6a7SJames Smart "6151 LS Drop IO x%x: Issue %d\n", 726d613b6a7SJames Smart ctxp->oxid, rc); 727d613b6a7SJames Smart 728d613b6a7SJames Smart lpfc_nlp_put(nvmewqeq->context1); 729d613b6a7SJames Smart 730d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 731547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 732d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid); 733d613b6a7SJames Smart return -ENXIO; 734d613b6a7SJames Smart } 735d613b6a7SJames Smart 736d613b6a7SJames Smart static int 737d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport, 738d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp) 739d613b6a7SJames Smart { 740d613b6a7SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 741d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 742d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 743d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 7446e8e1c14SJames Smart struct lpfc_queue *wq; 745d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 7466e8e1c14SJames Smart struct lpfc_sli_ring *pring; 7476e8e1c14SJames Smart unsigned long iflags; 748223b78eaSArnd Bergmann int rc; 7492b65e182SJames Smart 7501abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) { 7511abcb371SDick Kennedy rc = -ENODEV; 7521abcb371SDick Kennedy goto aerr; 7531abcb371SDick Kennedy } 7541abcb371SDick Kennedy 7553386f4bdSJames Smart if (phba->pport->load_flag & FC_UNLOADING) { 7563386f4bdSJames Smart rc = -ENODEV; 7573386f4bdSJames Smart goto aerr; 7583386f4bdSJames Smart } 7593386f4bdSJames Smart 7602b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 761c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 7622b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 7632b65e182SJames Smart ctxp->ts_nvme_status = ktime_get_ns(); 7642b65e182SJames Smart else 7652b65e182SJames Smart ctxp->ts_nvme_data = ktime_get_ns(); 7662b65e182SJames Smart } 7672b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 768223b78eaSArnd Bergmann int id = smp_processor_id(); 7692b65e182SJames Smart ctxp->cpu = id; 7702b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 7712b65e182SJames Smart phba->cpucheck_xmt_io[id]++; 7722b65e182SJames Smart if (rsp->hwqid != id) { 7732b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 7742b65e182SJames Smart "6705 CPU Check OP: " 7752b65e182SJames Smart "cpu %d expect %d\n", 7762b65e182SJames Smart id, rsp->hwqid); 7772b65e182SJames Smart ctxp->cpu = rsp->hwqid; 7782b65e182SJames Smart } 7792b65e182SJames Smart } 7802b65e182SJames Smart #endif 781d613b6a7SJames Smart 782d613b6a7SJames Smart /* Sanity check */ 78386c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABTS_RCV) || 78486c67379SJames Smart (ctxp->state == LPFC_NVMET_STE_ABORT)) { 785d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 786d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 78786c67379SJames Smart "6102 IO xri x%x aborted\n", 788d613b6a7SJames Smart ctxp->oxid); 789a5068b46SJames Smart rc = -ENXIO; 790d613b6a7SJames Smart goto aerr; 791d613b6a7SJames Smart } 792d613b6a7SJames Smart 793d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp); 794d613b6a7SJames Smart if (nvmewqeq == NULL) { 795d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 796d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 797d613b6a7SJames Smart "6152 FCP Drop IO x%x: Prep\n", 798d613b6a7SJames Smart ctxp->oxid); 799a5068b46SJames Smart rc = -ENXIO; 800d613b6a7SJames Smart goto aerr; 801d613b6a7SJames Smart } 802d613b6a7SJames Smart 803d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp; 804d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 805d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 806d613b6a7SJames Smart nvmewqeq->iocb_flag |= LPFC_IO_NVMET; 807d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = rsp->hwqid; 808d613b6a7SJames Smart 8092b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n", 8102b65e182SJames Smart ctxp->oxid, rsp->op, rsp->rsplen); 8112b65e182SJames Smart 81261f3d4bfSJames Smart ctxp->flag |= LPFC_NVMET_IO_INP; 813d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq); 814d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 8152b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 816c8a4ce0bSDick Kennedy if (!ctxp->ts_cmd_nvme) 8172b65e182SJames Smart return 0; 8182b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 8192b65e182SJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 8202b65e182SJames Smart else 8212b65e182SJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 8222b65e182SJames Smart #endif 823d613b6a7SJames Smart return 0; 824d613b6a7SJames Smart } 825d613b6a7SJames Smart 8266e8e1c14SJames Smart if (rc == -EBUSY) { 8276e8e1c14SJames Smart /* 8286e8e1c14SJames Smart * WQ was full, so queue nvmewqeq to be sent after 8296e8e1c14SJames Smart * WQE release CQE 8306e8e1c14SJames Smart */ 8316e8e1c14SJames Smart ctxp->flag |= LPFC_NVMET_DEFER_WQFULL; 8326e8e1c14SJames Smart wq = phba->sli4_hba.nvme_wq[rsp->hwqid]; 8336e8e1c14SJames Smart pring = wq->pring; 8346e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 8356e8e1c14SJames Smart list_add_tail(&nvmewqeq->list, &wq->wqfull_list); 8366e8e1c14SJames Smart wq->q_flag |= HBA_NVMET_WQFULL; 8376e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 838411de511SJames Smart atomic_inc(&lpfc_nvmep->defer_wqfull); 8396e8e1c14SJames Smart return 0; 8406e8e1c14SJames Smart } 8416e8e1c14SJames Smart 842d613b6a7SJames Smart /* Give back resources */ 843d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 844d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 845d613b6a7SJames Smart "6153 FCP Drop IO x%x: Issue: %d\n", 846d613b6a7SJames Smart ctxp->oxid, rc); 847d613b6a7SJames Smart 848d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 849d613b6a7SJames Smart nvmewqeq->context2 = NULL; 850d613b6a7SJames Smart nvmewqeq->context3 = NULL; 851a5068b46SJames Smart rc = -EBUSY; 852d613b6a7SJames Smart aerr: 853a5068b46SJames Smart return rc; 854d613b6a7SJames Smart } 855d613b6a7SJames Smart 856d613b6a7SJames Smart static void 857d613b6a7SJames Smart lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) 858d613b6a7SJames Smart { 859d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tport = targetport->private; 860d613b6a7SJames Smart 861d613b6a7SJames Smart /* release any threads waiting for the unreg to complete */ 862d613b6a7SJames Smart complete(&tport->tport_unreg_done); 863d613b6a7SJames Smart } 864d613b6a7SJames Smart 86519b58d94SJames Smart static void 866a97ec51bSJames Smart lpfc_nvmet_xmt_fcp_abort(struct nvmet_fc_target_port *tgtport, 867a97ec51bSJames Smart struct nvmefc_tgt_fcp_req *req) 868a97ec51bSJames Smart { 869a97ec51bSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 870a97ec51bSJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 871a97ec51bSJames Smart container_of(req, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 872a97ec51bSJames Smart struct lpfc_hba *phba = ctxp->phba; 8736e8e1c14SJames Smart struct lpfc_queue *wq; 87486c67379SJames Smart unsigned long flags; 875a97ec51bSJames Smart 8761abcb371SDick Kennedy if (phba->pport->load_flag & FC_UNLOADING) 8771abcb371SDick Kennedy return; 8781abcb371SDick Kennedy 8793386f4bdSJames Smart if (phba->pport->load_flag & FC_UNLOADING) 8803386f4bdSJames Smart return; 8813386f4bdSJames Smart 882a97ec51bSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 883ce1b591cSJames Smart "6103 NVMET Abort op: oxri x%x flg x%x ste %d\n", 884ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 885a97ec51bSJames Smart 886ce1b591cSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP ABRT: xri x%x flg x%x ste x%x\n", 887ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 888a97ec51bSJames Smart 889a97ec51bSJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_abort); 890ce1b591cSJames Smart 89186c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 892c578f6f4SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 89386c67379SJames Smart 89486c67379SJames Smart /* Since iaab/iaar are NOT set, we need to check 89586c67379SJames Smart * if the firmware is in process of aborting IO 89686c67379SJames Smart */ 89786c67379SJames Smart if (ctxp->flag & LPFC_NVMET_XBUSY) { 89886c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 89986c67379SJames Smart return; 90086c67379SJames Smart } 901a97ec51bSJames Smart ctxp->flag |= LPFC_NVMET_ABORT_OP; 902ce1b591cSJames Smart 9036e8e1c14SJames Smart if (ctxp->flag & LPFC_NVMET_DEFER_WQFULL) { 9046e8e1c14SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 9056e8e1c14SJames Smart ctxp->oxid); 9066e8e1c14SJames Smart wq = phba->sli4_hba.nvme_wq[ctxp->wqeq->hba_wqidx]; 9076e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(phba, wq, ctxp); 9086e8e1c14SJames Smart return; 9096e8e1c14SJames Smart } 9106e8e1c14SJames Smart 911ce1b591cSJames Smart /* An state of LPFC_NVMET_STE_RCV means we have just received 912ce1b591cSJames Smart * the NVME command and have not started processing it. 913ce1b591cSJames Smart * (by issuing any IO WQEs on this exchange yet) 914ce1b591cSJames Smart */ 915ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_RCV) 916ce1b591cSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 917a97ec51bSJames Smart ctxp->oxid); 918a97ec51bSJames Smart else 919ce1b591cSJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 920a97ec51bSJames Smart ctxp->oxid); 92186c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 922a97ec51bSJames Smart } 923a97ec51bSJames Smart 924a97ec51bSJames Smart static void 92519b58d94SJames Smart lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, 92619b58d94SJames Smart struct nvmefc_tgt_fcp_req *rsp) 92719b58d94SJames Smart { 928547077a4SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 92919b58d94SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 93019b58d94SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 93119b58d94SJames Smart struct lpfc_hba *phba = ctxp->phba; 93219b58d94SJames Smart unsigned long flags; 93319b58d94SJames Smart bool aborting = false; 93419b58d94SJames Smart 935ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_DONE && 936ce1b591cSJames Smart ctxp->state != LPFC_NVMET_STE_ABORT) { 937ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 938ce1b591cSJames Smart "6413 NVMET release bad state %d %d oxid x%x\n", 939ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 940ce1b591cSJames Smart } 941ce1b591cSJames Smart 94219b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 94386c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABORT_OP) || 94486c67379SJames Smart (ctxp->flag & LPFC_NVMET_XBUSY)) { 94519b58d94SJames Smart aborting = true; 94686c67379SJames Smart /* let the abort path do the real release */ 94786c67379SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 94819b58d94SJames Smart } 94919b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 95019b58d94SJames Smart 9519094367aSArnd Bergmann lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", ctxp->oxid, 9529094367aSArnd Bergmann ctxp->state, aborting); 95319b58d94SJames Smart 954547077a4SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_release); 955547077a4SJames Smart 95686c67379SJames Smart if (aborting) 95786c67379SJames Smart return; 95886c67379SJames Smart 9596c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 96019b58d94SJames Smart } 96119b58d94SJames Smart 96250738420SJames Smart static void 96350738420SJames Smart lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport, 96450738420SJames Smart struct nvmefc_tgt_fcp_req *rsp) 96550738420SJames Smart { 96650738420SJames Smart struct lpfc_nvmet_tgtport *tgtp; 96750738420SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 96850738420SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 96950738420SJames Smart struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; 97050738420SJames Smart struct lpfc_hba *phba = ctxp->phba; 97150738420SJames Smart 97250738420SJames Smart lpfc_nvmeio_data(phba, "NVMET DEFERRCV: xri x%x sz %d CPU %02x\n", 97350738420SJames Smart ctxp->oxid, ctxp->size, smp_processor_id()); 97450738420SJames Smart 97550738420SJames Smart tgtp = phba->targetport->private; 97650738420SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_defer); 977411de511SJames Smart 978411de511SJames Smart /* Free the nvmebuf since a new buffer already replaced it */ 979cbc5de1bSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 98050738420SJames Smart } 98150738420SJames Smart 982d613b6a7SJames Smart static struct nvmet_fc_target_template lpfc_tgttemplate = { 983d613b6a7SJames Smart .targetport_delete = lpfc_nvmet_targetport_delete, 984d613b6a7SJames Smart .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp, 985d613b6a7SJames Smart .fcp_op = lpfc_nvmet_xmt_fcp_op, 986a97ec51bSJames Smart .fcp_abort = lpfc_nvmet_xmt_fcp_abort, 98719b58d94SJames Smart .fcp_req_release = lpfc_nvmet_xmt_fcp_release, 98850738420SJames Smart .defer_rcv = lpfc_nvmet_defer_rcv, 989d613b6a7SJames Smart 990d613b6a7SJames Smart .max_hw_queues = 1, 991d613b6a7SJames Smart .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 992d613b6a7SJames Smart .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 993d613b6a7SJames Smart .dma_boundary = 0xFFFFFFFF, 994d613b6a7SJames Smart 995d613b6a7SJames Smart /* optional features */ 996d613b6a7SJames Smart .target_features = 0, 997d613b6a7SJames Smart /* sizes of additional private data for data structures */ 998d613b6a7SJames Smart .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport), 999d613b6a7SJames Smart }; 1000d613b6a7SJames Smart 100139aa23f9SColin Ian King static void 100266d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(struct lpfc_hba *phba, 100366d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop) 10046c621a22SJames Smart { 10056c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf, *next_ctx_buf; 10066c621a22SJames Smart unsigned long flags; 10076c621a22SJames Smart 100866d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, flags); 1009966bb5b7SJames Smart list_for_each_entry_safe(ctx_buf, next_ctx_buf, 101066d7ce93SDick Kennedy &infop->nvmet_ctx_list, list) { 1011c4031db7SDan Carpenter spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 10126c621a22SJames Smart list_del_init(&ctx_buf->list); 1013c4031db7SDan Carpenter spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 101466d7ce93SDick Kennedy 101566d7ce93SDick Kennedy __lpfc_clear_active_sglq(phba, ctx_buf->sglq->sli4_lxritag); 10166c621a22SJames Smart ctx_buf->sglq->state = SGL_FREED; 10176c621a22SJames Smart ctx_buf->sglq->ndlp = NULL; 10186c621a22SJames Smart 1019c4031db7SDan Carpenter spin_lock(&phba->sli4_hba.sgl_list_lock); 10206c621a22SJames Smart list_add_tail(&ctx_buf->sglq->list, 10216c621a22SJames Smart &phba->sli4_hba.lpfc_nvmet_sgl_list); 1022c4031db7SDan Carpenter spin_unlock(&phba->sli4_hba.sgl_list_lock); 10236c621a22SJames Smart 10246c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 10256c621a22SJames Smart kfree(ctx_buf->context); 10266c621a22SJames Smart } 102766d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, flags); 1028966bb5b7SJames Smart } 102966d7ce93SDick Kennedy 103066d7ce93SDick Kennedy static void 103166d7ce93SDick Kennedy lpfc_nvmet_cleanup_io_context(struct lpfc_hba *phba) 103266d7ce93SDick Kennedy { 103366d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 103466d7ce93SDick Kennedy int i, j; 103566d7ce93SDick Kennedy 103666d7ce93SDick Kennedy /* The first context list, MRQ 0 CPU 0 */ 103766d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 103866d7ce93SDick Kennedy if (!infop) 103966d7ce93SDick Kennedy return; 104066d7ce93SDick Kennedy 104166d7ce93SDick Kennedy /* Cycle the the entire CPU context list for every MRQ */ 104266d7ce93SDick Kennedy for (i = 0; i < phba->cfg_nvmet_mrq; i++) { 104366d7ce93SDick Kennedy for (j = 0; j < phba->sli4_hba.num_present_cpu; j++) { 104466d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(phba, infop); 104566d7ce93SDick Kennedy infop++; /* next */ 104666d7ce93SDick Kennedy } 104766d7ce93SDick Kennedy } 104866d7ce93SDick Kennedy kfree(phba->sli4_hba.nvmet_ctx_info); 104966d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = NULL; 10506c621a22SJames Smart } 10516c621a22SJames Smart 105239aa23f9SColin Ian King static int 10536c621a22SJames Smart lpfc_nvmet_setup_io_context(struct lpfc_hba *phba) 10546c621a22SJames Smart { 10556c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 10566c621a22SJames Smart struct lpfc_iocbq *nvmewqe; 10576c621a22SJames Smart union lpfc_wqe128 *wqe; 105866d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *last_infop; 105966d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 106066d7ce93SDick Kennedy int i, j, idx; 10616c621a22SJames Smart 10626c621a22SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME, 10636c621a22SJames Smart "6403 Allocate NVMET resources for %d XRIs\n", 10646c621a22SJames Smart phba->sli4_hba.nvmet_xri_cnt); 10656c621a22SJames Smart 106666d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = kcalloc( 106766d7ce93SDick Kennedy phba->sli4_hba.num_present_cpu * phba->cfg_nvmet_mrq, 106866d7ce93SDick Kennedy sizeof(struct lpfc_nvmet_ctx_info), GFP_KERNEL); 106966d7ce93SDick Kennedy if (!phba->sli4_hba.nvmet_ctx_info) { 107066d7ce93SDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 107166d7ce93SDick Kennedy "6419 Failed allocate memory for " 107266d7ce93SDick Kennedy "nvmet context lists\n"); 107366d7ce93SDick Kennedy return -ENOMEM; 107466d7ce93SDick Kennedy } 107566d7ce93SDick Kennedy 107666d7ce93SDick Kennedy /* 107766d7ce93SDick Kennedy * Assuming X CPUs in the system, and Y MRQs, allocate some 107866d7ce93SDick Kennedy * lpfc_nvmet_ctx_info structures as follows: 107966d7ce93SDick Kennedy * 108066d7ce93SDick Kennedy * cpu0/mrq0 cpu1/mrq0 ... cpuX/mrq0 108166d7ce93SDick Kennedy * cpu0/mrq1 cpu1/mrq1 ... cpuX/mrq1 108266d7ce93SDick Kennedy * ... 108366d7ce93SDick Kennedy * cpuX/mrqY cpuX/mrqY ... cpuX/mrqY 108466d7ce93SDick Kennedy * 108566d7ce93SDick Kennedy * Each line represents a MRQ "silo" containing an entry for 108666d7ce93SDick Kennedy * every CPU. 108766d7ce93SDick Kennedy * 108866d7ce93SDick Kennedy * MRQ X is initially assumed to be associated with CPU X, thus 108966d7ce93SDick Kennedy * contexts are initially distributed across all MRQs using 109066d7ce93SDick Kennedy * the MRQ index (N) as follows cpuN/mrqN. When contexts are 109166d7ce93SDick Kennedy * freed, the are freed to the MRQ silo based on the CPU number 109266d7ce93SDick Kennedy * of the IO completion. Thus a context that was allocated for MRQ A 109366d7ce93SDick Kennedy * whose IO completed on CPU B will be freed to cpuB/mrqA. 109466d7ce93SDick Kennedy */ 109566d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 109666d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 109766d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 109866d7ce93SDick Kennedy INIT_LIST_HEAD(&infop->nvmet_ctx_list); 109966d7ce93SDick Kennedy spin_lock_init(&infop->nvmet_ctx_list_lock); 110066d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt = 0; 110166d7ce93SDick Kennedy infop++; 110266d7ce93SDick Kennedy } 110366d7ce93SDick Kennedy } 110466d7ce93SDick Kennedy 110566d7ce93SDick Kennedy /* 110666d7ce93SDick Kennedy * Setup the next CPU context info ptr for each MRQ. 110766d7ce93SDick Kennedy * MRQ 0 will cycle thru CPUs 0 - X separately from 110866d7ce93SDick Kennedy * MRQ 1 cycling thru CPUs 0 - X, and so on. 110966d7ce93SDick Kennedy */ 111066d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 111166d7ce93SDick Kennedy last_infop = lpfc_get_ctx_list(phba, 0, j); 111266d7ce93SDick Kennedy for (i = phba->sli4_hba.num_present_cpu - 1; i >= 0; i--) { 111366d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, i, j); 111466d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu = last_infop; 111566d7ce93SDick Kennedy last_infop = infop; 111666d7ce93SDick Kennedy } 111766d7ce93SDick Kennedy } 111866d7ce93SDick Kennedy 11196c621a22SJames Smart /* For all nvmet xris, allocate resources needed to process a 11206c621a22SJames Smart * received command on a per xri basis. 11216c621a22SJames Smart */ 112266d7ce93SDick Kennedy idx = 0; 11236c621a22SJames Smart for (i = 0; i < phba->sli4_hba.nvmet_xri_cnt; i++) { 11246c621a22SJames Smart ctx_buf = kzalloc(sizeof(*ctx_buf), GFP_KERNEL); 11256c621a22SJames Smart if (!ctx_buf) { 11266c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 11276c621a22SJames Smart "6404 Ran out of memory for NVMET\n"); 11286c621a22SJames Smart return -ENOMEM; 11296c621a22SJames Smart } 11306c621a22SJames Smart 11316c621a22SJames Smart ctx_buf->context = kzalloc(sizeof(*ctx_buf->context), 11326c621a22SJames Smart GFP_KERNEL); 11336c621a22SJames Smart if (!ctx_buf->context) { 11346c621a22SJames Smart kfree(ctx_buf); 11356c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 11366c621a22SJames Smart "6405 Ran out of NVMET " 11376c621a22SJames Smart "context memory\n"); 11386c621a22SJames Smart return -ENOMEM; 11396c621a22SJames Smart } 11406c621a22SJames Smart ctx_buf->context->ctxbuf = ctx_buf; 1141ce1b591cSJames Smart ctx_buf->context->state = LPFC_NVMET_STE_FREE; 11426c621a22SJames Smart 11436c621a22SJames Smart ctx_buf->iocbq = lpfc_sli_get_iocbq(phba); 11446c621a22SJames Smart if (!ctx_buf->iocbq) { 11456c621a22SJames Smart kfree(ctx_buf->context); 11466c621a22SJames Smart kfree(ctx_buf); 11476c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 11486c621a22SJames Smart "6406 Ran out of NVMET iocb/WQEs\n"); 11496c621a22SJames Smart return -ENOMEM; 11506c621a22SJames Smart } 11516c621a22SJames Smart ctx_buf->iocbq->iocb_flag = LPFC_IO_NVMET; 11526c621a22SJames Smart nvmewqe = ctx_buf->iocbq; 11536c621a22SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 11546c621a22SJames Smart /* Initialize WQE */ 11556c621a22SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 11566c621a22SJames Smart /* Word 7 */ 11576c621a22SJames Smart bf_set(wqe_ct, &wqe->generic.wqe_com, SLI4_CT_RPI); 11586c621a22SJames Smart bf_set(wqe_class, &wqe->generic.wqe_com, CLASS3); 11596c621a22SJames Smart /* Word 10 */ 11606c621a22SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 11616c621a22SJames Smart bf_set(wqe_ebde_cnt, &wqe->generic.wqe_com, 0); 11626c621a22SJames Smart bf_set(wqe_qosd, &wqe->generic.wqe_com, 0); 11636c621a22SJames Smart 11646c621a22SJames Smart ctx_buf->iocbq->context1 = NULL; 11656c621a22SJames Smart spin_lock(&phba->sli4_hba.sgl_list_lock); 11666c621a22SJames Smart ctx_buf->sglq = __lpfc_sli_get_nvmet_sglq(phba, ctx_buf->iocbq); 11676c621a22SJames Smart spin_unlock(&phba->sli4_hba.sgl_list_lock); 11686c621a22SJames Smart if (!ctx_buf->sglq) { 11696c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 11706c621a22SJames Smart kfree(ctx_buf->context); 11716c621a22SJames Smart kfree(ctx_buf); 11726c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 11736c621a22SJames Smart "6407 Ran out of NVMET XRIs\n"); 11746c621a22SJames Smart return -ENOMEM; 11756c621a22SJames Smart } 117666d7ce93SDick Kennedy 117766d7ce93SDick Kennedy /* 117866d7ce93SDick Kennedy * Add ctx to MRQidx context list. Our initial assumption 117966d7ce93SDick Kennedy * is MRQidx will be associated with CPUidx. This association 118066d7ce93SDick Kennedy * can change on the fly. 118166d7ce93SDick Kennedy */ 118266d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, idx, idx); 118366d7ce93SDick Kennedy spin_lock(&infop->nvmet_ctx_list_lock); 118466d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 118566d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 118666d7ce93SDick Kennedy spin_unlock(&infop->nvmet_ctx_list_lock); 118766d7ce93SDick Kennedy 118866d7ce93SDick Kennedy /* Spread ctx structures evenly across all MRQs */ 118966d7ce93SDick Kennedy idx++; 119066d7ce93SDick Kennedy if (idx >= phba->cfg_nvmet_mrq) 119166d7ce93SDick Kennedy idx = 0; 11926c621a22SJames Smart } 119366d7ce93SDick Kennedy 119466d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 119566d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 119666d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 119766d7ce93SDick Kennedy lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 119866d7ce93SDick Kennedy "6408 TOTAL NVMET ctx for CPU %d " 119966d7ce93SDick Kennedy "MRQ %d: cnt %d nextcpu %p\n", 120066d7ce93SDick Kennedy i, j, infop->nvmet_ctx_list_cnt, 120166d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu); 120266d7ce93SDick Kennedy infop++; 120366d7ce93SDick Kennedy } 120466d7ce93SDick Kennedy } 12056c621a22SJames Smart return 0; 12066c621a22SJames Smart } 12076c621a22SJames Smart 1208d613b6a7SJames Smart int 1209d613b6a7SJames Smart lpfc_nvmet_create_targetport(struct lpfc_hba *phba) 1210d613b6a7SJames Smart { 1211d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1212d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1213d613b6a7SJames Smart struct nvmet_fc_port_info pinfo; 12146c621a22SJames Smart int error; 1215d613b6a7SJames Smart 1216d613b6a7SJames Smart if (phba->targetport) 1217d613b6a7SJames Smart return 0; 1218d613b6a7SJames Smart 12196c621a22SJames Smart error = lpfc_nvmet_setup_io_context(phba); 12206c621a22SJames Smart if (error) 12216c621a22SJames Smart return error; 12226c621a22SJames Smart 1223d613b6a7SJames Smart memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info)); 1224d613b6a7SJames Smart pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 1225d613b6a7SJames Smart pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 1226d613b6a7SJames Smart pinfo.port_id = vport->fc_myDID; 1227d613b6a7SJames Smart 12284d4c4a4aSJames Smart /* Limit to LPFC_MAX_NVME_SEG_CNT. 12294d4c4a4aSJames Smart * For now need + 1 to get around NVME transport logic. 12304d4c4a4aSJames Smart */ 12314d4c4a4aSJames Smart if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { 12324d4c4a4aSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 12334d4c4a4aSJames Smart "6400 Reducing sg segment cnt to %d\n", 12344d4c4a4aSJames Smart LPFC_MAX_NVME_SEG_CNT); 12354d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; 12364d4c4a4aSJames Smart } else { 12374d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; 12384d4c4a4aSJames Smart } 12394d4c4a4aSJames Smart lpfc_tgttemplate.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 1240d613b6a7SJames Smart lpfc_tgttemplate.max_hw_queues = phba->cfg_nvme_io_channel; 1241f485c18dSDick Kennedy lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP; 1242d613b6a7SJames Smart 12437d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1244d613b6a7SJames Smart error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 1245d613b6a7SJames Smart &phba->pcidev->dev, 1246d613b6a7SJames Smart &phba->targetport); 1247166d7211SJames Smart #else 12486c621a22SJames Smart error = -ENOENT; 1249166d7211SJames Smart #endif 1250d613b6a7SJames Smart if (error) { 1251d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1252e7981a2cSDick Kennedy "6025 Cannot register NVME targetport x%x: " 1253e7981a2cSDick Kennedy "portnm %llx nodenm %llx segs %d qs %d\n", 1254e7981a2cSDick Kennedy error, 1255e7981a2cSDick Kennedy pinfo.port_name, pinfo.node_name, 1256e7981a2cSDick Kennedy lpfc_tgttemplate.max_sgl_segments, 1257e7981a2cSDick Kennedy lpfc_tgttemplate.max_hw_queues); 1258d613b6a7SJames Smart phba->targetport = NULL; 1259e7981a2cSDick Kennedy phba->nvmet_support = 0; 12606c621a22SJames Smart 12616c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 12626c621a22SJames Smart 1263d613b6a7SJames Smart } else { 1264d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *) 1265d613b6a7SJames Smart phba->targetport->private; 1266d613b6a7SJames Smart tgtp->phba = phba; 1267d613b6a7SJames Smart 1268d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1269d613b6a7SJames Smart "6026 Registered NVME " 1270d613b6a7SJames Smart "targetport: %p, private %p " 1271e7981a2cSDick Kennedy "portnm %llx nodenm %llx segs %d qs %d\n", 1272d613b6a7SJames Smart phba->targetport, tgtp, 1273e7981a2cSDick Kennedy pinfo.port_name, pinfo.node_name, 1274e7981a2cSDick Kennedy lpfc_tgttemplate.max_sgl_segments, 1275e7981a2cSDick Kennedy lpfc_tgttemplate.max_hw_queues); 1276d613b6a7SJames Smart 1277d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_in, 0); 1278d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_out, 0); 1279d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_drop, 0); 1280d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_abort, 0); 1281547077a4SJames Smart atomic_set(&tgtp->xmt_ls_abort_cmpl, 0); 1282d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp, 0); 1283d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_drop, 0); 1284d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_error, 0); 12854b056682SJames Smart atomic_set(&tgtp->xmt_ls_rsp_xb_set, 0); 12864b056682SJames Smart atomic_set(&tgtp->xmt_ls_rsp_aborted, 0); 1287d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0); 1288d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_in, 0); 1289d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_out, 0); 1290d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_drop, 0); 1291d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_drop, 0); 1292d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read_rsp, 0); 1293d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read, 0); 1294d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_write, 0); 1295d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp, 0); 1296547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_release, 0); 1297d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0); 1298d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_error, 0); 12994b056682SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_xb_set, 0); 13004b056682SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_aborted, 0); 1301d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_drop, 0); 13024b056682SJames Smart atomic_set(&tgtp->xmt_fcp_xri_abort_cqe, 0); 1303547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort, 0); 1304547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0); 1305547077a4SJames Smart atomic_set(&tgtp->xmt_abort_unsol, 0); 1306547077a4SJames Smart atomic_set(&tgtp->xmt_abort_sol, 0); 1307d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp, 0); 1308d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp_error, 0); 1309411de511SJames Smart atomic_set(&tgtp->defer_ctx, 0); 1310411de511SJames Smart atomic_set(&tgtp->defer_fod, 0); 1311411de511SJames Smart atomic_set(&tgtp->defer_wqfull, 0); 1312d613b6a7SJames Smart } 1313d613b6a7SJames Smart return error; 1314d613b6a7SJames Smart } 1315d613b6a7SJames Smart 1316d613b6a7SJames Smart int 1317d613b6a7SJames Smart lpfc_nvmet_update_targetport(struct lpfc_hba *phba) 1318d613b6a7SJames Smart { 1319d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1320d613b6a7SJames Smart 1321d613b6a7SJames Smart if (!phba->targetport) 1322d613b6a7SJames Smart return 0; 1323d613b6a7SJames Smart 1324d613b6a7SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 1325d613b6a7SJames Smart "6007 Update NVMET port %p did x%x\n", 1326d613b6a7SJames Smart phba->targetport, vport->fc_myDID); 1327d613b6a7SJames Smart 1328d613b6a7SJames Smart phba->targetport->port_id = vport->fc_myDID; 1329d613b6a7SJames Smart return 0; 1330d613b6a7SJames Smart } 1331d613b6a7SJames Smart 1332318083adSJames Smart /** 1333318083adSJames Smart * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort 1334318083adSJames Smart * @phba: pointer to lpfc hba data structure. 1335318083adSJames Smart * @axri: pointer to the nvmet xri abort wcqe structure. 1336318083adSJames Smart * 1337318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 1338318083adSJames Smart * NVMET aborted xri. 1339318083adSJames Smart **/ 1340318083adSJames Smart void 1341318083adSJames Smart lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba, 1342318083adSJames Smart struct sli4_wcqe_xri_aborted *axri) 1343318083adSJames Smart { 134486c67379SJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 134586c67379SJames Smart uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 134686c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 13474b056682SJames Smart struct lpfc_nvmet_tgtport *tgtp; 134886c67379SJames Smart struct lpfc_nodelist *ndlp; 134986c67379SJames Smart unsigned long iflag = 0; 135086c67379SJames Smart int rrq_empty = 0; 135186c67379SJames Smart bool released = false; 135286c67379SJames Smart 135386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 135486c67379SJames Smart "6317 XB aborted xri x%x rxid x%x\n", xri, rxid); 135586c67379SJames Smart 135686c67379SJames Smart if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) 135786c67379SJames Smart return; 13584b056682SJames Smart 13594b056682SJames Smart if (phba->targetport) { 13604b056682SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 13614b056682SJames Smart atomic_inc(&tgtp->xmt_fcp_xri_abort_cqe); 13624b056682SJames Smart } 13634b056682SJames Smart 136486c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 136586c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 136686c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 136786c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 136886c67379SJames Smart list) { 13696c621a22SJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 137086c67379SJames Smart continue; 137186c67379SJames Smart 137286c67379SJames Smart /* Check if we already received a free context call 137386c67379SJames Smart * and we have completed processing an abort situation. 137486c67379SJames Smart */ 137586c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS && 137686c67379SJames Smart !(ctxp->flag & LPFC_NVMET_ABORT_OP)) { 137786c67379SJames Smart list_del(&ctxp->list); 137886c67379SJames Smart released = true; 137986c67379SJames Smart } 138086c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 138186c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 138286c67379SJames Smart 138386c67379SJames Smart rrq_empty = list_empty(&phba->active_rrq_list); 138486c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 138586c67379SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 138686c67379SJames Smart if (ndlp && NLP_CHK_NODE_ACT(ndlp) && 138786c67379SJames Smart (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || 138886c67379SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 138986c67379SJames Smart lpfc_set_rrq_active(phba, ndlp, 13906c621a22SJames Smart ctxp->ctxbuf->sglq->sli4_lxritag, 139186c67379SJames Smart rxid, 1); 139286c67379SJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 139386c67379SJames Smart } 139486c67379SJames Smart 139586c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1396ce1b591cSJames Smart "6318 XB aborted oxid %x flg x%x (%x)\n", 139786c67379SJames Smart ctxp->oxid, ctxp->flag, released); 139886c67379SJames Smart if (released) 13996c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 14006c621a22SJames Smart 140186c67379SJames Smart if (rrq_empty) 140286c67379SJames Smart lpfc_worker_wake_up(phba); 140386c67379SJames Smart return; 140486c67379SJames Smart } 140586c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 140686c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 140786c67379SJames Smart } 140886c67379SJames Smart 140986c67379SJames Smart int 141086c67379SJames Smart lpfc_nvmet_rcv_unsol_abort(struct lpfc_vport *vport, 141186c67379SJames Smart struct fc_frame_header *fc_hdr) 141286c67379SJames Smart 141386c67379SJames Smart { 141486c67379SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 141586c67379SJames Smart struct lpfc_hba *phba = vport->phba; 141686c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 141786c67379SJames Smart struct nvmefc_tgt_fcp_req *rsp; 141886c67379SJames Smart uint16_t xri; 141986c67379SJames Smart unsigned long iflag = 0; 142086c67379SJames Smart 142186c67379SJames Smart xri = be16_to_cpu(fc_hdr->fh_ox_id); 142286c67379SJames Smart 142386c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 142486c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 142586c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 142686c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 142786c67379SJames Smart list) { 14286c621a22SJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 142986c67379SJames Smart continue; 143086c67379SJames Smart 143186c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 143286c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 143386c67379SJames Smart 143486c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 143586c67379SJames Smart ctxp->flag |= LPFC_NVMET_ABTS_RCV; 143686c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 143786c67379SJames Smart 143886c67379SJames Smart lpfc_nvmeio_data(phba, 143986c67379SJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 144086c67379SJames Smart xri, smp_processor_id(), 0); 144186c67379SJames Smart 144286c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 144386c67379SJames Smart "6319 NVMET Rcv ABTS:acc xri x%x\n", xri); 144486c67379SJames Smart 144586c67379SJames Smart rsp = &ctxp->ctx.fcp_req; 144686c67379SJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, rsp); 144786c67379SJames Smart 144886c67379SJames Smart /* Respond with BA_ACC accordingly */ 144986c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 145086c67379SJames Smart return 0; 145186c67379SJames Smart } 145286c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 145386c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 145486c67379SJames Smart 145586c67379SJames Smart lpfc_nvmeio_data(phba, "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 145686c67379SJames Smart xri, smp_processor_id(), 1); 145786c67379SJames Smart 145886c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 145986c67379SJames Smart "6320 NVMET Rcv ABTS:rjt xri x%x\n", xri); 146086c67379SJames Smart 146186c67379SJames Smart /* Respond with BA_RJT accordingly */ 146286c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 0); 146386c67379SJames Smart #endif 1464b06e13c3SJens Axboe return 0; 1465318083adSJames Smart } 1466318083adSJames Smart 14676e8e1c14SJames Smart static void 14686e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(struct lpfc_hba *phba, struct lpfc_queue *wq, 14696e8e1c14SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 14706e8e1c14SJames Smart { 14716e8e1c14SJames Smart struct lpfc_sli_ring *pring; 14726e8e1c14SJames Smart struct lpfc_iocbq *nvmewqeq; 14736e8e1c14SJames Smart struct lpfc_iocbq *next_nvmewqeq; 14746e8e1c14SJames Smart unsigned long iflags; 14756e8e1c14SJames Smart struct lpfc_wcqe_complete wcqe; 14766e8e1c14SJames Smart struct lpfc_wcqe_complete *wcqep; 14776e8e1c14SJames Smart 14786e8e1c14SJames Smart pring = wq->pring; 14796e8e1c14SJames Smart wcqep = &wcqe; 14806e8e1c14SJames Smart 14816e8e1c14SJames Smart /* Fake an ABORT error code back to cmpl routine */ 14826e8e1c14SJames Smart memset(wcqep, 0, sizeof(struct lpfc_wcqe_complete)); 14836e8e1c14SJames Smart bf_set(lpfc_wcqe_c_status, wcqep, IOSTAT_LOCAL_REJECT); 14846e8e1c14SJames Smart wcqep->parameter = IOERR_ABORT_REQUESTED; 14856e8e1c14SJames Smart 14866e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 14876e8e1c14SJames Smart list_for_each_entry_safe(nvmewqeq, next_nvmewqeq, 14886e8e1c14SJames Smart &wq->wqfull_list, list) { 14896e8e1c14SJames Smart if (ctxp) { 14906e8e1c14SJames Smart /* Checking for a specific IO to flush */ 14916e8e1c14SJames Smart if (nvmewqeq->context2 == ctxp) { 14926e8e1c14SJames Smart list_del(&nvmewqeq->list); 14936e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, 14946e8e1c14SJames Smart iflags); 14956e8e1c14SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(phba, nvmewqeq, 14966e8e1c14SJames Smart wcqep); 14976e8e1c14SJames Smart return; 14986e8e1c14SJames Smart } 14996e8e1c14SJames Smart continue; 15006e8e1c14SJames Smart } else { 15016e8e1c14SJames Smart /* Flush all IOs */ 15026e8e1c14SJames Smart list_del(&nvmewqeq->list); 15036e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 15046e8e1c14SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(phba, nvmewqeq, wcqep); 15056e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 15066e8e1c14SJames Smart } 15076e8e1c14SJames Smart } 15086e8e1c14SJames Smart if (!ctxp) 15096e8e1c14SJames Smart wq->q_flag &= ~HBA_NVMET_WQFULL; 15106e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 15116e8e1c14SJames Smart } 15126e8e1c14SJames Smart 15136e8e1c14SJames Smart void 15146e8e1c14SJames Smart lpfc_nvmet_wqfull_process(struct lpfc_hba *phba, 15156e8e1c14SJames Smart struct lpfc_queue *wq) 15166e8e1c14SJames Smart { 15176e8e1c14SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 15186e8e1c14SJames Smart struct lpfc_sli_ring *pring; 15196e8e1c14SJames Smart struct lpfc_iocbq *nvmewqeq; 15206e8e1c14SJames Smart unsigned long iflags; 15216e8e1c14SJames Smart int rc; 15226e8e1c14SJames Smart 15236e8e1c14SJames Smart /* 15246e8e1c14SJames Smart * Some WQE slots are available, so try to re-issue anything 15256e8e1c14SJames Smart * on the WQ wqfull_list. 15266e8e1c14SJames Smart */ 15276e8e1c14SJames Smart pring = wq->pring; 15286e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 15296e8e1c14SJames Smart while (!list_empty(&wq->wqfull_list)) { 15306e8e1c14SJames Smart list_remove_head(&wq->wqfull_list, nvmewqeq, struct lpfc_iocbq, 15316e8e1c14SJames Smart list); 15326e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 15336e8e1c14SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq); 15346e8e1c14SJames Smart spin_lock_irqsave(&pring->ring_lock, iflags); 15356e8e1c14SJames Smart if (rc == -EBUSY) { 15366e8e1c14SJames Smart /* WQ was full again, so put it back on the list */ 15376e8e1c14SJames Smart list_add(&nvmewqeq->list, &wq->wqfull_list); 15386e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 15396e8e1c14SJames Smart return; 15406e8e1c14SJames Smart } 15416e8e1c14SJames Smart } 15426e8e1c14SJames Smart wq->q_flag &= ~HBA_NVMET_WQFULL; 15436e8e1c14SJames Smart spin_unlock_irqrestore(&pring->ring_lock, iflags); 15446e8e1c14SJames Smart 15456e8e1c14SJames Smart #endif 15466e8e1c14SJames Smart } 15476e8e1c14SJames Smart 1548d613b6a7SJames Smart void 1549d613b6a7SJames Smart lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 1550d613b6a7SJames Smart { 15517d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1552d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 15536e8e1c14SJames Smart struct lpfc_queue *wq; 15546e8e1c14SJames Smart uint32_t qidx; 1555d613b6a7SJames Smart 1556d613b6a7SJames Smart if (phba->nvmet_support == 0) 1557d613b6a7SJames Smart return; 1558d613b6a7SJames Smart if (phba->targetport) { 1559d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 15606e8e1c14SJames Smart for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) { 15616e8e1c14SJames Smart wq = phba->sli4_hba.nvme_wq[qidx]; 15626e8e1c14SJames Smart lpfc_nvmet_wqfull_flush(phba, wq, NULL); 15636e8e1c14SJames Smart } 1564d613b6a7SJames Smart init_completion(&tgtp->tport_unreg_done); 1565d613b6a7SJames Smart nvmet_fc_unregister_targetport(phba->targetport); 1566d613b6a7SJames Smart wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); 15676c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 1568d613b6a7SJames Smart } 1569d613b6a7SJames Smart phba->targetport = NULL; 1570166d7211SJames Smart #endif 1571d613b6a7SJames Smart } 1572d613b6a7SJames Smart 1573d613b6a7SJames Smart /** 1574d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer - Process an unsolicited event data buffer 1575d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1576d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1577d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 1578d613b6a7SJames Smart * 1579d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1580d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1581d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1582d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1583d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1584d613b6a7SJames Smart * of the discovery state machine. 1585d613b6a7SJames Smart **/ 1586d613b6a7SJames Smart static void 1587d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1588d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf) 1589d613b6a7SJames Smart { 15907d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1591d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1592d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 1593d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1594d613b6a7SJames Smart uint32_t *payload; 1595d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 1596d613b6a7SJames Smart 1597d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1598d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1599d613b6a7SJames Smart "6154 LS Drop IO\n"); 16002b65e182SJames Smart oxid = 0; 16012b65e182SJames Smart size = 0; 16022b65e182SJames Smart sid = 0; 1603547077a4SJames Smart ctxp = NULL; 1604d613b6a7SJames Smart goto dropit; 1605d613b6a7SJames Smart } 1606d613b6a7SJames Smart 1607d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1608d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1609d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1610d613b6a7SJames Smart size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); 1611d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1612d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1613d613b6a7SJames Smart 1614d613b6a7SJames Smart ctxp = kzalloc(sizeof(struct lpfc_nvmet_rcv_ctx), GFP_ATOMIC); 1615d613b6a7SJames Smart if (ctxp == NULL) { 1616d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1617d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1618d613b6a7SJames Smart "6155 LS Drop IO x%x: Alloc\n", 1619d613b6a7SJames Smart oxid); 1620d613b6a7SJames Smart dropit: 16212b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: " 16222b65e182SJames Smart "xri x%x sz %d from %06x\n", 16232b65e182SJames Smart oxid, size, sid); 1624d613b6a7SJames Smart if (nvmebuf) 1625d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1626d613b6a7SJames Smart return; 1627d613b6a7SJames Smart } 1628d613b6a7SJames Smart ctxp->phba = phba; 1629d613b6a7SJames Smart ctxp->size = size; 1630d613b6a7SJames Smart ctxp->oxid = oxid; 1631d613b6a7SJames Smart ctxp->sid = sid; 1632d613b6a7SJames Smart ctxp->wqeq = NULL; 1633ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_RCV; 1634ce1b591cSJames Smart ctxp->entry_cnt = 1; 1635d613b6a7SJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 16362b65e182SJames Smart 16372b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RCV: xri x%x sz %d from %06x\n", 16382b65e182SJames Smart oxid, size, sid); 1639d613b6a7SJames Smart /* 1640d613b6a7SJames Smart * The calling sequence should be: 1641d613b6a7SJames Smart * nvmet_fc_rcv_ls_req -> lpfc_nvmet_xmt_ls_rsp/cmp ->_req->done 1642d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp should free the allocated ctxp. 1643d613b6a7SJames Smart */ 1644d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_in); 1645d613b6a7SJames Smart rc = nvmet_fc_rcv_ls_req(phba->targetport, &ctxp->ctx.ls_req, 1646d613b6a7SJames Smart payload, size); 1647d613b6a7SJames Smart 1648d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1649ce1b591cSJames Smart "6037 NVMET Unsol rcv: sz %d rc %d: %08x %08x %08x " 1650ce1b591cSJames Smart "%08x %08x %08x\n", size, rc, 1651d613b6a7SJames Smart *payload, *(payload+1), *(payload+2), 1652d613b6a7SJames Smart *(payload+3), *(payload+4), *(payload+5)); 16532b65e182SJames Smart 1654d613b6a7SJames Smart if (rc == 0) { 1655d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_out); 1656d613b6a7SJames Smart return; 1657d613b6a7SJames Smart } 16582b65e182SJames Smart 16592b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: xri x%x sz %d from %06x\n", 16602b65e182SJames Smart oxid, size, sid); 16612b65e182SJames Smart 1662d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1663d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1664d613b6a7SJames Smart "6156 LS Drop IO x%x: nvmet_fc_rcv_ls_req %d\n", 1665d613b6a7SJames Smart ctxp->oxid, rc); 1666d613b6a7SJames Smart 1667d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 1668d613b6a7SJames Smart if (nvmebuf) 1669d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1670d613b6a7SJames Smart 1671d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_abort); 1672d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid); 1673166d7211SJames Smart #endif 1674d613b6a7SJames Smart } 1675d613b6a7SJames Smart 167666d7ce93SDick Kennedy static struct lpfc_nvmet_ctxbuf * 167766d7ce93SDick Kennedy lpfc_nvmet_replenish_context(struct lpfc_hba *phba, 167866d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop) 167966d7ce93SDick Kennedy { 16802299e432SDick Kennedy #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 168166d7ce93SDick Kennedy struct lpfc_nvmet_ctxbuf *ctx_buf = NULL; 168266d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *get_infop; 168366d7ce93SDick Kennedy int i; 168466d7ce93SDick Kennedy 168566d7ce93SDick Kennedy /* 168666d7ce93SDick Kennedy * The current_infop for the MRQ a NVME command IU was received 168766d7ce93SDick Kennedy * on is empty. Our goal is to replenish this MRQs context 168866d7ce93SDick Kennedy * list from a another CPUs. 168966d7ce93SDick Kennedy * 169066d7ce93SDick Kennedy * First we need to pick a context list to start looking on. 169166d7ce93SDick Kennedy * nvmet_ctx_start_cpu has available context the last time 169266d7ce93SDick Kennedy * we needed to replenish this CPU where nvmet_ctx_next_cpu 169366d7ce93SDick Kennedy * is just the next sequential CPU for this MRQ. 169466d7ce93SDick Kennedy */ 169566d7ce93SDick Kennedy if (current_infop->nvmet_ctx_start_cpu) 169666d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_start_cpu; 169766d7ce93SDick Kennedy else 169866d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_next_cpu; 169966d7ce93SDick Kennedy 170066d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 170166d7ce93SDick Kennedy if (get_infop == current_infop) { 170266d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 170366d7ce93SDick Kennedy continue; 170466d7ce93SDick Kennedy } 170566d7ce93SDick Kennedy spin_lock(&get_infop->nvmet_ctx_list_lock); 170666d7ce93SDick Kennedy 170766d7ce93SDick Kennedy /* Just take the entire context list, if there are any */ 170866d7ce93SDick Kennedy if (get_infop->nvmet_ctx_list_cnt) { 170966d7ce93SDick Kennedy list_splice_init(&get_infop->nvmet_ctx_list, 171066d7ce93SDick Kennedy ¤t_infop->nvmet_ctx_list); 171166d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt = 171266d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt - 1; 171366d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt = 0; 171466d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 171566d7ce93SDick Kennedy 171666d7ce93SDick Kennedy current_infop->nvmet_ctx_start_cpu = get_infop; 171766d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 171866d7ce93SDick Kennedy ctx_buf, struct lpfc_nvmet_ctxbuf, 171966d7ce93SDick Kennedy list); 172066d7ce93SDick Kennedy return ctx_buf; 172166d7ce93SDick Kennedy } 172266d7ce93SDick Kennedy 172366d7ce93SDick Kennedy /* Otherwise, move on to the next CPU for this MRQ */ 172466d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 172566d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 172666d7ce93SDick Kennedy } 172766d7ce93SDick Kennedy 17282299e432SDick Kennedy #endif 172966d7ce93SDick Kennedy /* Nothing found, all contexts for the MRQ are in-flight */ 173066d7ce93SDick Kennedy return NULL; 173166d7ce93SDick Kennedy } 173266d7ce93SDick Kennedy 1733d613b6a7SJames Smart /** 1734d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer 1735d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 173666d7ce93SDick Kennedy * @idx: relative index of MRQ vector 1737d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 1738d613b6a7SJames Smart * 1739d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1740d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1741d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1742d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1743d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1744d613b6a7SJames Smart * of the discovery state machine. 1745d613b6a7SJames Smart **/ 1746d613b6a7SJames Smart static void 1747d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba, 174866d7ce93SDick Kennedy uint32_t idx, 1749d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1750d613b6a7SJames Smart uint64_t isr_timestamp) 1751d613b6a7SJames Smart { 1752d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1753d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1754d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 17556c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 175666d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop; 1757d613b6a7SJames Smart uint32_t *payload; 1758a8cf5dfeSJames Smart uint32_t size, oxid, sid, rc, qno; 17596c621a22SJames Smart unsigned long iflag; 176066d7ce93SDick Kennedy int current_cpu; 17612b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 17622b65e182SJames Smart uint32_t id; 17632b65e182SJames Smart #endif 1764d613b6a7SJames Smart 176573626173SArnd Bergmann if (!IS_ENABLED(CONFIG_NVME_TARGET_FC)) 176673626173SArnd Bergmann return; 176773626173SArnd Bergmann 17686c621a22SJames Smart ctx_buf = NULL; 1769d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1770d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 17716c621a22SJames Smart "6157 NVMET FCP Drop IO\n"); 17722b65e182SJames Smart oxid = 0; 17732b65e182SJames Smart size = 0; 17742b65e182SJames Smart sid = 0; 1775547077a4SJames Smart ctxp = NULL; 1776d613b6a7SJames Smart goto dropit; 1777d613b6a7SJames Smart } 1778d613b6a7SJames Smart 177966d7ce93SDick Kennedy /* 178066d7ce93SDick Kennedy * Get a pointer to the context list for this MRQ based on 178166d7ce93SDick Kennedy * the CPU this MRQ IRQ is associated with. If the CPU association 178266d7ce93SDick Kennedy * changes from our initial assumption, the context list could 178366d7ce93SDick Kennedy * be empty, thus it would need to be replenished with the 178466d7ce93SDick Kennedy * context list from another CPU for this MRQ. 178566d7ce93SDick Kennedy */ 178666d7ce93SDick Kennedy current_cpu = smp_processor_id(); 178766d7ce93SDick Kennedy current_infop = lpfc_get_ctx_list(phba, current_cpu, idx); 178866d7ce93SDick Kennedy spin_lock_irqsave(¤t_infop->nvmet_ctx_list_lock, iflag); 178966d7ce93SDick Kennedy if (current_infop->nvmet_ctx_list_cnt) { 179066d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 17916c621a22SJames Smart ctx_buf, struct lpfc_nvmet_ctxbuf, list); 179266d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt--; 1793966bb5b7SJames Smart } else { 179466d7ce93SDick Kennedy ctx_buf = lpfc_nvmet_replenish_context(phba, current_infop); 17956c621a22SJames Smart } 179666d7ce93SDick Kennedy spin_unlock_irqrestore(¤t_infop->nvmet_ctx_list_lock, iflag); 17976c621a22SJames Smart 1798a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1799a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1800a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 1801a8cf5dfeSJames Smart 1802a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1803a8cf5dfeSJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV) { 1804a8cf5dfeSJames Smart id = smp_processor_id(); 1805a8cf5dfeSJames Smart if (id < LPFC_CHECK_CPU_CNT) 1806a8cf5dfeSJames Smart phba->cpucheck_rcv_io[id]++; 1807a8cf5dfeSJames Smart } 1808a8cf5dfeSJames Smart #endif 1809a8cf5dfeSJames Smart 1810a8cf5dfeSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d CPU %02x\n", 1811a8cf5dfeSJames Smart oxid, size, smp_processor_id()); 1812a8cf5dfeSJames Smart 1813411de511SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1814411de511SJames Smart 18156c621a22SJames Smart if (!ctx_buf) { 1816a8cf5dfeSJames Smart /* Queue this NVME IO to process later */ 1817a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 1818a8cf5dfeSJames Smart list_add_tail(&nvmebuf->hbuf.list, 1819a8cf5dfeSJames Smart &phba->sli4_hba.lpfc_nvmet_io_wait_list); 1820a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt++; 1821a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_total++; 1822a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 1823a8cf5dfeSJames Smart iflag); 1824a8cf5dfeSJames Smart 1825a8cf5dfeSJames Smart /* Post a brand new DMA buffer to RQ */ 1826a8cf5dfeSJames Smart qno = nvmebuf->idx; 1827a8cf5dfeSJames Smart lpfc_post_rq_buffer( 1828a8cf5dfeSJames Smart phba, phba->sli4_hba.nvmet_mrq_hdr[qno], 1829a8cf5dfeSJames Smart phba->sli4_hba.nvmet_mrq_data[qno], 1, qno); 1830411de511SJames Smart 1831411de511SJames Smart atomic_inc(&tgtp->defer_ctx); 1832a8cf5dfeSJames Smart return; 18336c621a22SJames Smart } 1834d613b6a7SJames Smart 1835d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1836d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1837d613b6a7SJames Smart 18386c621a22SJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context; 1839ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_FREE) { 1840ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1841ce1b591cSJames Smart "6414 NVMET Context corrupt %d %d oxid x%x\n", 1842ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 1843ce1b591cSJames Smart } 1844d613b6a7SJames Smart ctxp->wqeq = NULL; 1845d613b6a7SJames Smart ctxp->txrdy = NULL; 1846d613b6a7SJames Smart ctxp->offset = 0; 1847d613b6a7SJames Smart ctxp->phba = phba; 1848d613b6a7SJames Smart ctxp->size = size; 1849d613b6a7SJames Smart ctxp->oxid = oxid; 1850d613b6a7SJames Smart ctxp->sid = sid; 185166d7ce93SDick Kennedy ctxp->idx = idx; 1852d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 1853d613b6a7SJames Smart ctxp->entry_cnt = 1; 1854d613b6a7SJames Smart ctxp->flag = 0; 18556c621a22SJames Smart ctxp->ctxbuf = ctx_buf; 1856cbc5de1bSJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 18572b7824d0SJames Smart spin_lock_init(&ctxp->ctxlock); 1858d613b6a7SJames Smart 18592b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1860c8a4ce0bSDick Kennedy if (isr_timestamp) { 18612b65e182SJames Smart ctxp->ts_isr_cmd = isr_timestamp; 18622b65e182SJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 18632b65e182SJames Smart ctxp->ts_nvme_data = 0; 18642b65e182SJames Smart ctxp->ts_data_wqput = 0; 18652b65e182SJames Smart ctxp->ts_isr_data = 0; 18662b65e182SJames Smart ctxp->ts_data_nvme = 0; 18672b65e182SJames Smart ctxp->ts_nvme_status = 0; 18682b65e182SJames Smart ctxp->ts_status_wqput = 0; 18692b65e182SJames Smart ctxp->ts_isr_status = 0; 18702b65e182SJames Smart ctxp->ts_status_nvme = 0; 1871c8a4ce0bSDick Kennedy } else { 1872c8a4ce0bSDick Kennedy ctxp->ts_cmd_nvme = 0; 18732b65e182SJames Smart } 18742b65e182SJames Smart #endif 18752b65e182SJames Smart 1876d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 1877d613b6a7SJames Smart /* 1878d613b6a7SJames Smart * The calling sequence should be: 1879d613b6a7SJames Smart * nvmet_fc_rcv_fcp_req -> lpfc_nvmet_xmt_fcp_op/cmp -> req->done 1880d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 18816c621a22SJames Smart * When we return from nvmet_fc_rcv_fcp_req, all relevant info in 18826c621a22SJames Smart * the NVME command / FC header is stored, so we are free to repost 18836c621a22SJames Smart * the buffer. 1884d613b6a7SJames Smart */ 1885d613b6a7SJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 1886d613b6a7SJames Smart payload, size); 1887d613b6a7SJames Smart 1888d613b6a7SJames Smart /* Process FCP command */ 1889d613b6a7SJames Smart if (rc == 0) { 1890cbc5de1bSJames Smart ctxp->rqb_buffer = NULL; 1891d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 18926c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1893d613b6a7SJames Smart return; 1894d613b6a7SJames Smart } 1895d613b6a7SJames Smart 189650738420SJames Smart /* Processing of FCP command is deferred */ 189750738420SJames Smart if (rc == -EOVERFLOW) { 1898411de511SJames Smart /* 1899411de511SJames Smart * Post a brand new DMA buffer to RQ and defer 1900411de511SJames Smart * freeing rcv buffer till .defer_rcv callback 1901411de511SJames Smart */ 1902411de511SJames Smart qno = nvmebuf->idx; 1903411de511SJames Smart lpfc_post_rq_buffer( 1904411de511SJames Smart phba, phba->sli4_hba.nvmet_mrq_hdr[qno], 1905411de511SJames Smart phba->sli4_hba.nvmet_mrq_data[qno], 1, qno); 1906411de511SJames Smart 190750738420SJames Smart lpfc_nvmeio_data(phba, 190850738420SJames Smart "NVMET RCV BUSY: xri x%x sz %d from %06x\n", 190950738420SJames Smart oxid, size, sid); 191050738420SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 1911411de511SJames Smart atomic_inc(&tgtp->defer_fod); 191250738420SJames Smart return; 191350738420SJames Smart } 1914cbc5de1bSJames Smart ctxp->rqb_buffer = nvmebuf; 191550738420SJames Smart 1916d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 1917d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1918547077a4SJames Smart "6159 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 1919547077a4SJames Smart ctxp->oxid, rc, 1920547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 1921547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 1922547077a4SJames Smart atomic_read(&tgtp->xmt_fcp_release)); 1923d613b6a7SJames Smart dropit: 19242b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 19252b65e182SJames Smart oxid, size, sid); 1926d613b6a7SJames Smart if (oxid) { 19276c621a22SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 1928d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 19296c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1930d613b6a7SJames Smart return; 1931d613b6a7SJames Smart } 1932d613b6a7SJames Smart 19336c621a22SJames Smart if (ctx_buf) 19346c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctx_buf); 19356c621a22SJames Smart 19366c621a22SJames Smart if (nvmebuf) 19376c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1938d613b6a7SJames Smart } 1939d613b6a7SJames Smart 1940d613b6a7SJames Smart /** 1941d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_event - Process an unsolicited event from an nvme nport 1942d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1943d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1944d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1945d613b6a7SJames Smart * 1946d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1947d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1948d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1949d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer() after properly set up the buffer from the 1950d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1951d613b6a7SJames Smart **/ 1952d613b6a7SJames Smart void 1953d613b6a7SJames Smart lpfc_nvmet_unsol_ls_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1954d613b6a7SJames Smart struct lpfc_iocbq *piocb) 1955d613b6a7SJames Smart { 1956d613b6a7SJames Smart struct lpfc_dmabuf *d_buf; 1957d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf; 1958d613b6a7SJames Smart 1959d613b6a7SJames Smart d_buf = piocb->context2; 1960d613b6a7SJames Smart nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); 1961d613b6a7SJames Smart 1962d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1963d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1964d613b6a7SJames Smart return; 1965d613b6a7SJames Smart } 1966d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(phba, pring, nvmebuf); 1967d613b6a7SJames Smart } 1968d613b6a7SJames Smart 1969d613b6a7SJames Smart /** 1970d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport 1971d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 197266d7ce93SDick Kennedy * @idx: relative index of MRQ vector 1973d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1974d613b6a7SJames Smart * 1975d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1976d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1977d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1978d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the 1979d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1980d613b6a7SJames Smart **/ 1981d613b6a7SJames Smart void 1982d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba, 198366d7ce93SDick Kennedy uint32_t idx, 1984d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1985d613b6a7SJames Smart uint64_t isr_timestamp) 1986d613b6a7SJames Smart { 1987d613b6a7SJames Smart if (phba->nvmet_support == 0) { 19886c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); 1989d613b6a7SJames Smart return; 1990d613b6a7SJames Smart } 199166d7ce93SDick Kennedy lpfc_nvmet_unsol_fcp_buffer(phba, idx, nvmebuf, 1992d613b6a7SJames Smart isr_timestamp); 1993d613b6a7SJames Smart } 1994d613b6a7SJames Smart 1995d613b6a7SJames Smart /** 1996d613b6a7SJames Smart * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure 1997d613b6a7SJames Smart * @phba: pointer to a host N_Port data structure. 1998d613b6a7SJames Smart * @ctxp: Context info for NVME LS Request 1999d613b6a7SJames Smart * @rspbuf: DMA buffer of NVME command. 2000d613b6a7SJames Smart * @rspsize: size of the NVME command. 2001d613b6a7SJames Smart * 2002d613b6a7SJames Smart * This routine is used for allocating a lpfc-WQE data structure from 2003d613b6a7SJames Smart * the driver lpfc-WQE free-list and prepare the WQE with the parameters 2004d613b6a7SJames Smart * passed into the routine for discovery state machine to issue an Extended 2005d613b6a7SJames Smart * Link Service (NVME) commands. It is a generic lpfc-WQE allocation 2006d613b6a7SJames Smart * and preparation routine that is used by all the discovery state machine 2007d613b6a7SJames Smart * routines and the NVME command-specific fields will be later set up by 2008d613b6a7SJames Smart * the individual discovery machine routines after calling this routine 2009d613b6a7SJames Smart * allocating and preparing a generic WQE data structure. It fills in the 2010d613b6a7SJames Smart * Buffer Descriptor Entries (BDEs), allocates buffers for both command 2011d613b6a7SJames Smart * payload and response payload (if expected). The reference count on the 2012d613b6a7SJames Smart * ndlp is incremented by 1 and the reference to the ndlp is put into 2013d613b6a7SJames Smart * context1 of the WQE data structure for this WQE to hold the ndlp 2014d613b6a7SJames Smart * reference for the command's callback function to access later. 2015d613b6a7SJames Smart * 2016d613b6a7SJames Smart * Return code 2017d613b6a7SJames Smart * Pointer to the newly allocated/prepared nvme wqe data structure 2018d613b6a7SJames Smart * NULL - when nvme wqe data structure allocation/preparation failed 2019d613b6a7SJames Smart **/ 2020d613b6a7SJames Smart static struct lpfc_iocbq * 2021d613b6a7SJames Smart lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba, 2022d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2023d613b6a7SJames Smart dma_addr_t rspbuf, uint16_t rspsize) 2024d613b6a7SJames Smart { 2025d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2026d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 2027d613b6a7SJames Smart union lpfc_wqe *wqe; 2028d613b6a7SJames Smart 2029d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 2030d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 2031ce1b591cSJames Smart "6104 NVMET prep LS wqe: link err: " 2032ce1b591cSJames Smart "NPORT x%x oxid:x%x ste %d\n", 2033ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2034d613b6a7SJames Smart return NULL; 2035d613b6a7SJames Smart } 2036d613b6a7SJames Smart 2037d613b6a7SJames Smart /* Allocate buffer for command wqe */ 2038d613b6a7SJames Smart nvmewqe = lpfc_sli_get_iocbq(phba); 2039d613b6a7SJames Smart if (nvmewqe == NULL) { 2040d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 2041ce1b591cSJames Smart "6105 NVMET prep LS wqe: No WQE: " 2042ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2043ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2044d613b6a7SJames Smart return NULL; 2045d613b6a7SJames Smart } 2046d613b6a7SJames Smart 2047d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 2048d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2049d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2050d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2051d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 2052ce1b591cSJames Smart "6106 NVMET prep LS wqe: No ndlp: " 2053ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2054ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2055d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 2056d613b6a7SJames Smart } 2057d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 2058d613b6a7SJames Smart 2059d613b6a7SJames Smart /* prevent preparing wqe with NULL ndlp reference */ 2060d613b6a7SJames Smart nvmewqe->context1 = lpfc_nlp_get(ndlp); 2061d613b6a7SJames Smart if (nvmewqe->context1 == NULL) 2062d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 2063d613b6a7SJames Smart nvmewqe->context2 = ctxp; 2064d613b6a7SJames Smart 2065d613b6a7SJames Smart wqe = &nvmewqe->wqe; 2066d613b6a7SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 2067d613b6a7SJames Smart 2068d613b6a7SJames Smart /* Words 0 - 2 */ 2069d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2070d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize; 2071d613b6a7SJames Smart wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf)); 2072d613b6a7SJames Smart wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf)); 2073d613b6a7SJames Smart 2074d613b6a7SJames Smart /* Word 3 */ 2075d613b6a7SJames Smart 2076d613b6a7SJames Smart /* Word 4 */ 2077d613b6a7SJames Smart 2078d613b6a7SJames Smart /* Word 5 */ 2079d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 2080d613b6a7SJames Smart bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 2081d613b6a7SJames Smart bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 20828b361639SJames Smart bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP); 2083d613b6a7SJames Smart bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 2084d613b6a7SJames Smart 2085d613b6a7SJames Smart /* Word 6 */ 2086d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, 2087d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2088d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag); 2089d613b6a7SJames Smart 2090d613b6a7SJames Smart /* Word 7 */ 2091d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com, 2092d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 2093d613b6a7SJames Smart bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI); 2094d613b6a7SJames Smart bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3); 2095d613b6a7SJames Smart bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); 2096d613b6a7SJames Smart 2097d613b6a7SJames Smart /* Word 8 */ 2098d613b6a7SJames Smart wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag; 2099d613b6a7SJames Smart 2100d613b6a7SJames Smart /* Word 9 */ 2101d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag); 2102d613b6a7SJames Smart /* Needs to be set by caller */ 2103d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid); 2104d613b6a7SJames Smart 2105d613b6a7SJames Smart /* Word 10 */ 2106d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); 2107d613b6a7SJames Smart bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 2108d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, 2109d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2110d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); 2111d613b6a7SJames Smart 2112d613b6a7SJames Smart /* Word 11 */ 2113d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com, 2114d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2115d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com, 2116d613b6a7SJames Smart OTHER_COMMAND); 2117d613b6a7SJames Smart 2118d613b6a7SJames Smart /* Word 12 */ 2119d613b6a7SJames Smart wqe->xmit_sequence.xmit_len = rspsize; 2120d613b6a7SJames Smart 2121d613b6a7SJames Smart nvmewqe->retry = 1; 2122d613b6a7SJames Smart nvmewqe->vport = phba->pport; 2123d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 2124d613b6a7SJames Smart nvmewqe->iocb_flag |= LPFC_IO_NVME_LS; 2125d613b6a7SJames Smart 2126ce1b591cSJames Smart /* Xmit NVMET response to remote NPORT <did> */ 2127d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 2128ce1b591cSJames Smart "6039 Xmit NVMET LS response to remote " 2129d613b6a7SJames Smart "NPORT x%x iotag:x%x oxid:x%x size:x%x\n", 2130d613b6a7SJames Smart ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid, 2131d613b6a7SJames Smart rspsize); 2132d613b6a7SJames Smart return nvmewqe; 2133d613b6a7SJames Smart 2134d613b6a7SJames Smart nvme_wqe_free_wqeq_exit: 2135d613b6a7SJames Smart nvmewqe->context2 = NULL; 2136d613b6a7SJames Smart nvmewqe->context3 = NULL; 2137d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, nvmewqe); 2138d613b6a7SJames Smart return NULL; 2139d613b6a7SJames Smart } 2140d613b6a7SJames Smart 2141d613b6a7SJames Smart 2142d613b6a7SJames Smart static struct lpfc_iocbq * 2143d613b6a7SJames Smart lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba, 2144d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 2145d613b6a7SJames Smart { 2146d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp = &ctxp->ctx.fcp_req; 2147d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2148d613b6a7SJames Smart struct sli4_sge *sgl; 2149d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2150d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 2151d613b6a7SJames Smart struct scatterlist *sgel; 2152d613b6a7SJames Smart union lpfc_wqe128 *wqe; 21530bc2b7c5SJames Smart struct ulp_bde64 *bde; 2154d613b6a7SJames Smart uint32_t *txrdy; 2155d613b6a7SJames Smart dma_addr_t physaddr; 2156d613b6a7SJames Smart int i, cnt; 21570bc2b7c5SJames Smart int do_pbde; 2158d613b6a7SJames Smart int xc = 1; 2159d613b6a7SJames Smart 2160d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 2161d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2162ce1b591cSJames Smart "6107 NVMET prep FCP wqe: link err:" 2163ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2164ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2165d613b6a7SJames Smart return NULL; 2166d613b6a7SJames Smart } 2167d613b6a7SJames Smart 2168d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 2169d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2170d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2171d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2172d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2173ce1b591cSJames Smart "6108 NVMET prep FCP wqe: no ndlp: " 2174ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 2175ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2176d613b6a7SJames Smart return NULL; 2177d613b6a7SJames Smart } 2178d613b6a7SJames Smart 217981e6a637SJames Smart if (rsp->sg_cnt > lpfc_tgttemplate.max_sgl_segments) { 2180d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2181ce1b591cSJames Smart "6109 NVMET prep FCP wqe: seg cnt err: " 2182ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d cnt %d\n", 2183ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state, 2184ce1b591cSJames Smart phba->cfg_nvme_seg_cnt); 2185d613b6a7SJames Smart return NULL; 2186d613b6a7SJames Smart } 2187d613b6a7SJames Smart 2188d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2189d613b6a7SJames Smart nvmewqe = ctxp->wqeq; 2190d613b6a7SJames Smart if (nvmewqe == NULL) { 2191d613b6a7SJames Smart /* Allocate buffer for command wqe */ 21926c621a22SJames Smart nvmewqe = ctxp->ctxbuf->iocbq; 2193d613b6a7SJames Smart if (nvmewqe == NULL) { 2194d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2195ce1b591cSJames Smart "6110 NVMET prep FCP wqe: No " 2196ce1b591cSJames Smart "WQE: NPORT x%x oxid x%x ste %d\n", 2197ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 2198d613b6a7SJames Smart return NULL; 2199d613b6a7SJames Smart } 2200d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 2201d613b6a7SJames Smart xc = 0; /* create new XRI */ 2202d613b6a7SJames Smart nvmewqe->sli4_lxritag = NO_XRI; 2203d613b6a7SJames Smart nvmewqe->sli4_xritag = NO_XRI; 2204d613b6a7SJames Smart } 2205d613b6a7SJames Smart 2206d613b6a7SJames Smart /* Sanity check */ 2207d613b6a7SJames Smart if (((ctxp->state == LPFC_NVMET_STE_RCV) && 2208d613b6a7SJames Smart (ctxp->entry_cnt == 1)) || 2209ce1b591cSJames Smart (ctxp->state == LPFC_NVMET_STE_DATA)) { 2210d613b6a7SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 2211d613b6a7SJames Smart } else { 2212d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2213ce1b591cSJames Smart "6111 Wrong state NVMET FCP: %d cnt %d\n", 2214ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt); 2215d613b6a7SJames Smart return NULL; 2216d613b6a7SJames Smart } 2217d613b6a7SJames Smart 22186c621a22SJames Smart sgl = (struct sli4_sge *)ctxp->ctxbuf->sglq->sgl; 2219d613b6a7SJames Smart switch (rsp->op) { 2220d613b6a7SJames Smart case NVMET_FCOP_READDATA: 2221d613b6a7SJames Smart case NVMET_FCOP_READDATA_RSP: 2222d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 2223d613b6a7SJames Smart sgel = &rsp->sg[0]; 2224d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 2225d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2226d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel); 2227d613b6a7SJames Smart wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr)); 2228d613b6a7SJames Smart wqe->fcp_tsend.bde.addrHigh = 2229d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2230d613b6a7SJames Smart 2231d613b6a7SJames Smart /* Word 3 */ 2232d613b6a7SJames Smart wqe->fcp_tsend.payload_offset_len = 0; 2233d613b6a7SJames Smart 2234d613b6a7SJames Smart /* Word 4 */ 2235d613b6a7SJames Smart wqe->fcp_tsend.relative_offset = ctxp->offset; 2236d613b6a7SJames Smart 2237d613b6a7SJames Smart /* Word 5 */ 2238d613b6a7SJames Smart 2239d613b6a7SJames Smart /* Word 6 */ 2240d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com, 2241d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2242d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com, 2243d613b6a7SJames Smart nvmewqe->sli4_xritag); 2244d613b6a7SJames Smart 2245d613b6a7SJames Smart /* Word 7 */ 2246c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_tsend.wqe_com, 1); 2247d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE); 22480bc2b7c5SJames Smart do_pbde = 0; 2249d613b6a7SJames Smart 2250d613b6a7SJames Smart /* Word 8 */ 2251d613b6a7SJames Smart wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag; 2252d613b6a7SJames Smart 2253d613b6a7SJames Smart /* Word 9 */ 2254d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag); 2255d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid); 2256d613b6a7SJames Smart 2257d613b6a7SJames Smart /* Word 10 */ 2258d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 2259d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1); 2260d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE); 2261d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com, 2262d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2263d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->fcp_tsend.wqe_com, 0); 2264d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, xc); 2265d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 2266d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2267d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_tsend.wqe_com, 1); 2268d613b6a7SJames Smart 2269d613b6a7SJames Smart /* Word 11 */ 2270d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com, 2271d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2272d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com, 2273d613b6a7SJames Smart FCP_COMMAND_TSEND); 2274d613b6a7SJames Smart 2275d613b6a7SJames Smart /* Word 12 */ 2276d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2277d613b6a7SJames Smart 2278d613b6a7SJames Smart /* Setup 2 SKIP SGEs */ 2279d613b6a7SJames Smart sgl->addr_hi = 0; 2280d613b6a7SJames Smart sgl->addr_lo = 0; 2281d613b6a7SJames Smart sgl->word2 = 0; 2282d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2283d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2284d613b6a7SJames Smart sgl->sge_len = 0; 2285d613b6a7SJames Smart sgl++; 2286d613b6a7SJames Smart sgl->addr_hi = 0; 2287d613b6a7SJames Smart sgl->addr_lo = 0; 2288d613b6a7SJames Smart sgl->word2 = 0; 2289d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2290d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2291d613b6a7SJames Smart sgl->sge_len = 0; 2292d613b6a7SJames Smart sgl++; 2293d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 2294d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read_rsp); 2295d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1); 229620aefac3SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 229720aefac3SJames Smart if (ndlp->nlp_flag & NLP_SUPPRESS_RSP) 229820aefac3SJames Smart bf_set(wqe_sup, 229920aefac3SJames Smart &wqe->fcp_tsend.wqe_com, 1); 2300d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 2301d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 2302d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 2303d613b6a7SJames Smart } else { 2304d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2305d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1); 2306d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1); 2307d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 2308d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2309d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, 2310d613b6a7SJames Smart rsp->rsplen); 2311d613b6a7SJames Smart } 2312d613b6a7SJames Smart } else { 2313d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read); 2314d613b6a7SJames Smart 2315d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2316d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 2317d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 2318d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0); 2319d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 2320d613b6a7SJames Smart } 2321d613b6a7SJames Smart break; 2322d613b6a7SJames Smart 2323d613b6a7SJames Smart case NVMET_FCOP_WRITEDATA: 2324d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 2325771db5c0SRomain Perier txrdy = dma_pool_alloc(phba->txrdy_payload_pool, 2326d613b6a7SJames Smart GFP_KERNEL, &physaddr); 2327d613b6a7SJames Smart if (!txrdy) { 2328d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2329d613b6a7SJames Smart "6041 Bad txrdy buffer: oxid x%x\n", 2330d613b6a7SJames Smart ctxp->oxid); 2331d613b6a7SJames Smart return NULL; 2332d613b6a7SJames Smart } 2333d613b6a7SJames Smart ctxp->txrdy = txrdy; 2334d613b6a7SJames Smart ctxp->txrdy_phys = physaddr; 2335d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2336d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeSize = TXRDY_PAYLOAD_LEN; 2337d613b6a7SJames Smart wqe->fcp_treceive.bde.addrLow = 2338d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 2339d613b6a7SJames Smart wqe->fcp_treceive.bde.addrHigh = 2340d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2341d613b6a7SJames Smart 2342d613b6a7SJames Smart /* Word 3 */ 2343d613b6a7SJames Smart wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN; 2344d613b6a7SJames Smart 2345d613b6a7SJames Smart /* Word 4 */ 2346d613b6a7SJames Smart wqe->fcp_treceive.relative_offset = ctxp->offset; 2347d613b6a7SJames Smart 2348d613b6a7SJames Smart /* Word 5 */ 2349d613b6a7SJames Smart 2350d613b6a7SJames Smart /* Word 6 */ 2351d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com, 2352d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2353d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com, 2354d613b6a7SJames Smart nvmewqe->sli4_xritag); 2355d613b6a7SJames Smart 2356d613b6a7SJames Smart /* Word 7 */ 2357c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_treceive.wqe_com, 1); 2358d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0); 2359d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com, 2360d613b6a7SJames Smart CMD_FCP_TRECEIVE64_WQE); 23610bc2b7c5SJames Smart if (phba->nvme_embed_pbde) 23620bc2b7c5SJames Smart do_pbde = 1; 23630bc2b7c5SJames Smart else 23640bc2b7c5SJames Smart do_pbde = 0; 2365d613b6a7SJames Smart 2366d613b6a7SJames Smart /* Word 8 */ 2367d613b6a7SJames Smart wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag; 2368d613b6a7SJames Smart 2369d613b6a7SJames Smart /* Word 9 */ 2370d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag); 2371d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid); 2372d613b6a7SJames Smart 2373d613b6a7SJames Smart /* Word 10 */ 2374d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 2375d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1); 2376d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ); 2377d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com, 2378d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2379d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, xc); 2380d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0); 2381d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0); 2382d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0); 2383d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 2384d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2385d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_treceive.wqe_com, 1); 2386d613b6a7SJames Smart 2387d613b6a7SJames Smart /* Word 11 */ 2388d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com, 2389d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2390d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com, 2391d613b6a7SJames Smart FCP_COMMAND_TRECEIVE); 2392d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2393d613b6a7SJames Smart 2394d613b6a7SJames Smart /* Word 12 */ 2395d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2396d613b6a7SJames Smart 2397d613b6a7SJames Smart /* Setup 1 TXRDY and 1 SKIP SGE */ 2398d613b6a7SJames Smart txrdy[0] = 0; 2399d613b6a7SJames Smart txrdy[1] = cpu_to_be32(rsp->transfer_length); 2400d613b6a7SJames Smart txrdy[2] = 0; 2401d613b6a7SJames Smart 2402d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 2403d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 2404d613b6a7SJames Smart sgl->word2 = 0; 2405d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 2406d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2407d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(TXRDY_PAYLOAD_LEN); 2408d613b6a7SJames Smart sgl++; 2409d613b6a7SJames Smart sgl->addr_hi = 0; 2410d613b6a7SJames Smart sgl->addr_lo = 0; 2411d613b6a7SJames Smart sgl->word2 = 0; 2412d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2413d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2414d613b6a7SJames Smart sgl->sge_len = 0; 2415d613b6a7SJames Smart sgl++; 2416d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_write); 2417d613b6a7SJames Smart break; 2418d613b6a7SJames Smart 2419d613b6a7SJames Smart case NVMET_FCOP_RSP: 2420d613b6a7SJames Smart /* Words 0 - 2 */ 2421d613b6a7SJames Smart physaddr = rsp->rspdma; 2422d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2423d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 2424d613b6a7SJames Smart wqe->fcp_trsp.bde.addrLow = 2425d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 2426d613b6a7SJames Smart wqe->fcp_trsp.bde.addrHigh = 2427d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2428d613b6a7SJames Smart 2429d613b6a7SJames Smart /* Word 3 */ 2430d613b6a7SJames Smart wqe->fcp_trsp.response_len = rsp->rsplen; 2431d613b6a7SJames Smart 2432d613b6a7SJames Smart /* Word 4 */ 2433d613b6a7SJames Smart wqe->fcp_trsp.rsvd_4_5[0] = 0; 2434d613b6a7SJames Smart 2435d613b6a7SJames Smart 2436d613b6a7SJames Smart /* Word 5 */ 2437d613b6a7SJames Smart 2438d613b6a7SJames Smart /* Word 6 */ 2439d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com, 2440d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2441d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com, 2442d613b6a7SJames Smart nvmewqe->sli4_xritag); 2443d613b6a7SJames Smart 2444d613b6a7SJames Smart /* Word 7 */ 2445c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_trsp.wqe_com, 0); 2446d613b6a7SJames Smart bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1); 2447d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE); 24480bc2b7c5SJames Smart do_pbde = 0; 2449d613b6a7SJames Smart 2450d613b6a7SJames Smart /* Word 8 */ 2451d613b6a7SJames Smart wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag; 2452d613b6a7SJames Smart 2453d613b6a7SJames Smart /* Word 9 */ 2454d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag); 2455d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid); 2456d613b6a7SJames Smart 2457d613b6a7SJames Smart /* Word 10 */ 2458d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 2459d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 0); 2460d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_WRITE); 2461d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com, 2462d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD3); 2463d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, xc); 2464d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 2465d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2466d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_trsp.wqe_com, 1); 2467d613b6a7SJames Smart 2468d613b6a7SJames Smart /* Word 11 */ 2469d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com, 2470d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2471d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com, 2472d613b6a7SJames Smart FCP_COMMAND_TRSP); 2473d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2474d613b6a7SJames Smart 2475d613b6a7SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 2476d613b6a7SJames Smart /* Good response - all zero's on wire */ 2477d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0); 2478d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0); 2479d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0); 2480d613b6a7SJames Smart } else { 2481d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1); 2482d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1); 2483d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 2484d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2485d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen); 2486d613b6a7SJames Smart } 2487d613b6a7SJames Smart 2488d613b6a7SJames Smart /* Use rspbuf, NOT sg list */ 2489d613b6a7SJames Smart rsp->sg_cnt = 0; 2490d613b6a7SJames Smart sgl->word2 = 0; 2491d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp); 2492d613b6a7SJames Smart break; 2493d613b6a7SJames Smart 2494d613b6a7SJames Smart default: 2495d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 2496d613b6a7SJames Smart "6064 Unknown Rsp Op %d\n", 2497d613b6a7SJames Smart rsp->op); 2498d613b6a7SJames Smart return NULL; 2499d613b6a7SJames Smart } 2500d613b6a7SJames Smart 2501d613b6a7SJames Smart nvmewqe->retry = 1; 2502d613b6a7SJames Smart nvmewqe->vport = phba->pport; 2503d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 2504d613b6a7SJames Smart nvmewqe->context1 = ndlp; 2505d613b6a7SJames Smart 2506d613b6a7SJames Smart for (i = 0; i < rsp->sg_cnt; i++) { 2507d613b6a7SJames Smart sgel = &rsp->sg[i]; 2508d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 2509d613b6a7SJames Smart cnt = sg_dma_len(sgel); 2510d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 2511d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 2512d613b6a7SJames Smart sgl->word2 = 0; 2513d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 2514d613b6a7SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset); 2515d613b6a7SJames Smart if ((i+1) == rsp->sg_cnt) 2516d613b6a7SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 2517d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2518d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(cnt); 25190bc2b7c5SJames Smart if (do_pbde && i == 0) { 25200bc2b7c5SJames Smart bde = (struct ulp_bde64 *)&wqe->words[13]; 25210bc2b7c5SJames Smart memset(bde, 0, sizeof(struct ulp_bde64)); 25220bc2b7c5SJames Smart /* Words 13-15 (PBDE)*/ 25230bc2b7c5SJames Smart bde->addrLow = sgl->addr_lo; 25240bc2b7c5SJames Smart bde->addrHigh = sgl->addr_hi; 25250bc2b7c5SJames Smart bde->tus.f.bdeSize = 25260bc2b7c5SJames Smart le32_to_cpu(sgl->sge_len); 25270bc2b7c5SJames Smart bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; 25280bc2b7c5SJames Smart bde->tus.w = cpu_to_le32(bde->tus.w); 25290bc2b7c5SJames Smart } 2530d613b6a7SJames Smart sgl++; 2531d613b6a7SJames Smart ctxp->offset += cnt; 2532d613b6a7SJames Smart } 25330bc2b7c5SJames Smart 25340bc2b7c5SJames Smart if (do_pbde) 25350bc2b7c5SJames Smart bf_set(wqe_pbde, &wqe->generic.wqe_com, 1); 25360bc2b7c5SJames Smart else 25370bc2b7c5SJames Smart bf_set(wqe_pbde, &wqe->generic.wqe_com, 0); 2538ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 2539ce1b591cSJames Smart ctxp->entry_cnt++; 2540d613b6a7SJames Smart return nvmewqe; 2541d613b6a7SJames Smart } 2542d613b6a7SJames Smart 2543d613b6a7SJames Smart /** 2544d613b6a7SJames Smart * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS 2545d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2546d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2547d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2548d613b6a7SJames Smart * 2549d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2550d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 2551d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2552d613b6a7SJames Smart **/ 2553d613b6a7SJames Smart static void 2554d613b6a7SJames Smart lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2555d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2556d613b6a7SJames Smart { 2557d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2558d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2559d613b6a7SJames Smart uint32_t status, result; 256019b58d94SJames Smart unsigned long flags; 256119b58d94SJames Smart bool released = false; 2562d613b6a7SJames Smart 2563d613b6a7SJames Smart ctxp = cmdwqe->context2; 2564d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2565d613b6a7SJames Smart result = wcqe->parameter; 2566d613b6a7SJames Smart 2567d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2568547077a4SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 2569547077a4SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 2570d613b6a7SJames Smart 2571d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 257286c67379SJames Smart 257386c67379SJames Smart /* Check if we already received a free context call 257486c67379SJames Smart * and we have completed processing an abort situation. 257586c67379SJames Smart */ 257619b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 257786c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 257886c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 257986c67379SJames Smart list_del(&ctxp->list); 258019b58d94SJames Smart released = true; 258186c67379SJames Smart } 258219b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 258319b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 2584547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 258519b58d94SJames Smart 2586e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 258786c67379SJames Smart "6165 ABORT cmpl: xri x%x flg x%x (%d) " 258886c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 258986c67379SJames Smart ctxp->oxid, ctxp->flag, released, 259086c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 259186c67379SJames Smart result, wcqe->word3); 259286c67379SJames Smart 25936c621a22SJames Smart cmdwqe->context2 = NULL; 25946c621a22SJames Smart cmdwqe->context3 = NULL; 259519b58d94SJames Smart /* 259619b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 259719b58d94SJames Smart * will be recycled by transport release call. 259819b58d94SJames Smart */ 259919b58d94SJames Smart if (released) 26006c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 2601d613b6a7SJames Smart 26026c621a22SJames Smart /* This is the iocbq for the abort, not the command */ 2603d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 260486c67379SJames Smart 260586c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 260686c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 260786c67379SJames Smart * should have been called already. 260886c67379SJames Smart */ 2609d613b6a7SJames Smart } 2610d613b6a7SJames Smart 2611d613b6a7SJames Smart /** 261286c67379SJames Smart * lpfc_nvmet_unsol_fcp_abort_cmp - Completion handler for ABTS 2613d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2614d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2615d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2616d613b6a7SJames Smart * 2617d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2618d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 2619d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2620d613b6a7SJames Smart **/ 2621d613b6a7SJames Smart static void 262286c67379SJames Smart lpfc_nvmet_unsol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2623d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2624d613b6a7SJames Smart { 2625d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2626d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 262719b58d94SJames Smart unsigned long flags; 2628d613b6a7SJames Smart uint32_t status, result; 262919b58d94SJames Smart bool released = false; 2630d613b6a7SJames Smart 2631d613b6a7SJames Smart ctxp = cmdwqe->context2; 2632d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2633d613b6a7SJames Smart result = wcqe->parameter; 2634d613b6a7SJames Smart 263586c67379SJames Smart if (!ctxp) { 263686c67379SJames Smart /* if context is clear, related io alrady complete */ 2637d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 263886c67379SJames Smart "6070 ABTS cmpl: WCQE: %08x %08x %08x %08x\n", 263986c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 2640d613b6a7SJames Smart result, wcqe->word3); 264186c67379SJames Smart return; 264286c67379SJames Smart } 2643d613b6a7SJames Smart 264478e1d200SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 264578e1d200SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 264678e1d200SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 264778e1d200SJames Smart 2648d613b6a7SJames Smart /* Sanity check */ 2649d613b6a7SJames Smart if (ctxp->state != LPFC_NVMET_STE_ABORT) { 2650d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 265186c67379SJames Smart "6112 ABTS Wrong state:%d oxid x%x\n", 2652d613b6a7SJames Smart ctxp->state, ctxp->oxid); 2653d613b6a7SJames Smart } 265486c67379SJames Smart 265586c67379SJames Smart /* Check if we already received a free context call 265686c67379SJames Smart * and we have completed processing an abort situation. 265786c67379SJames Smart */ 2658d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 265919b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 266086c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 266186c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 266286c67379SJames Smart list_del(&ctxp->list); 266319b58d94SJames Smart released = true; 266486c67379SJames Smart } 266519b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 266619b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 2667547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 266819b58d94SJames Smart 266986c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 267086c67379SJames Smart "6316 ABTS cmpl xri x%x flg x%x (%x) " 267186c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 267286c67379SJames Smart ctxp->oxid, ctxp->flag, released, 267386c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 267486c67379SJames Smart result, wcqe->word3); 26756c621a22SJames Smart 26766c621a22SJames Smart cmdwqe->context2 = NULL; 26776c621a22SJames Smart cmdwqe->context3 = NULL; 267819b58d94SJames Smart /* 267919b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 268019b58d94SJames Smart * will be recycled by transport release call. 268119b58d94SJames Smart */ 268219b58d94SJames Smart if (released) 26836c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 268486c67379SJames Smart 268586c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 268686c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 268786c67379SJames Smart * should have been called already. 268886c67379SJames Smart */ 2689d613b6a7SJames Smart } 2690d613b6a7SJames Smart 2691d613b6a7SJames Smart /** 2692d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS 2693d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2694d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2695d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2696d613b6a7SJames Smart * 2697d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2698d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for LS cmds 2699d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2700d613b6a7SJames Smart **/ 2701d613b6a7SJames Smart static void 2702d613b6a7SJames Smart lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2703d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2704d613b6a7SJames Smart { 2705d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2706d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2707d613b6a7SJames Smart uint32_t status, result; 2708d613b6a7SJames Smart 2709d613b6a7SJames Smart ctxp = cmdwqe->context2; 2710d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2711d613b6a7SJames Smart result = wcqe->parameter; 2712d613b6a7SJames Smart 2713d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2714547077a4SJames Smart atomic_inc(&tgtp->xmt_ls_abort_cmpl); 2715d613b6a7SJames Smart 2716d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2717d613b6a7SJames Smart "6083 Abort cmpl: ctx %p WCQE:%08x %08x %08x %08x\n", 2718d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 2719d613b6a7SJames Smart result, wcqe->word3); 2720d613b6a7SJames Smart 2721ce1b591cSJames Smart if (!ctxp) { 2722ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2723ce1b591cSJames Smart "6415 NVMET LS Abort No ctx: WCQE: " 2724ce1b591cSJames Smart "%08x %08x %08x %08x\n", 2725ce1b591cSJames Smart wcqe->word0, wcqe->total_data_placed, 2726ce1b591cSJames Smart result, wcqe->word3); 2727ce1b591cSJames Smart 2728ce1b591cSJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 2729ce1b591cSJames Smart return; 2730ce1b591cSJames Smart } 2731ce1b591cSJames Smart 2732ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_LS_ABORT) { 2733ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2734ce1b591cSJames Smart "6416 NVMET LS abort cmpl state mismatch: " 2735ce1b591cSJames Smart "oxid x%x: %d %d\n", 2736ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 2737ce1b591cSJames Smart } 2738ce1b591cSJames Smart 2739d613b6a7SJames Smart cmdwqe->context2 = NULL; 2740d613b6a7SJames Smart cmdwqe->context3 = NULL; 2741d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 2742d613b6a7SJames Smart kfree(ctxp); 2743d613b6a7SJames Smart } 2744d613b6a7SJames Smart 2745d613b6a7SJames Smart static int 2746d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba, 2747d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2748d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2749d613b6a7SJames Smart { 2750d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2751d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2752d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 2753d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2754d613b6a7SJames Smart 2755d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 275686c67379SJames Smart "6067 ABTS: sid %x xri x%x/x%x\n", 2757318083adSJames Smart sid, xri, ctxp->wqeq->sli4_xritag); 2758d613b6a7SJames Smart 2759d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2760d613b6a7SJames Smart 2761d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2762d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2763d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2764d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2765d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2766ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2767d613b6a7SJames Smart "6134 Drop ABTS - wrong NDLP state x%x.\n", 2768b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2769d613b6a7SJames Smart 2770d613b6a7SJames Smart /* No failure to an ABTS request. */ 2771d613b6a7SJames Smart return 0; 2772d613b6a7SJames Smart } 2773d613b6a7SJames Smart 2774d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 2775d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 2776d613b6a7SJames Smart 2777d613b6a7SJames Smart /* 2778d613b6a7SJames Smart * Since we zero the whole WQE, we need to ensure we set the WQE fields 2779d613b6a7SJames Smart * that were initialized in lpfc_sli4_nvmet_alloc. 2780d613b6a7SJames Smart */ 2781d613b6a7SJames Smart memset(wqe_abts, 0, sizeof(union lpfc_wqe)); 2782d613b6a7SJames Smart 2783d613b6a7SJames Smart /* Word 5 */ 2784d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0); 2785d613b6a7SJames Smart bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1); 2786d613b6a7SJames Smart bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0); 2787d613b6a7SJames Smart bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS); 2788d613b6a7SJames Smart bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS); 2789d613b6a7SJames Smart 2790d613b6a7SJames Smart /* Word 6 */ 2791d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com, 2792d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2793d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com, 2794d613b6a7SJames Smart abts_wqeq->sli4_xritag); 2795d613b6a7SJames Smart 2796d613b6a7SJames Smart /* Word 7 */ 2797d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com, 2798d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 2799d613b6a7SJames Smart bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI); 2800d613b6a7SJames Smart bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3); 2801d613b6a7SJames Smart bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0); 2802d613b6a7SJames Smart 2803d613b6a7SJames Smart /* Word 8 */ 2804d613b6a7SJames Smart wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag; 2805d613b6a7SJames Smart 2806d613b6a7SJames Smart /* Word 9 */ 2807d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag); 2808d613b6a7SJames Smart /* Needs to be set by caller */ 2809d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri); 2810d613b6a7SJames Smart 2811d613b6a7SJames Smart /* Word 10 */ 2812d613b6a7SJames Smart bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1); 2813d613b6a7SJames Smart bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 2814d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com, 2815d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2816d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0); 2817d613b6a7SJames Smart bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0); 2818d613b6a7SJames Smart 2819d613b6a7SJames Smart /* Word 11 */ 2820d613b6a7SJames Smart bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com, 2821d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2822d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com, 2823d613b6a7SJames Smart OTHER_COMMAND); 2824d613b6a7SJames Smart 2825d613b6a7SJames Smart abts_wqeq->vport = phba->pport; 2826d613b6a7SJames Smart abts_wqeq->context1 = ndlp; 2827d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 2828d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2829d613b6a7SJames Smart abts_wqeq->rsvd2 = 0; 2830d613b6a7SJames Smart /* hba_wqidx should already be setup from command we are aborting */ 2831d613b6a7SJames Smart abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR; 2832d613b6a7SJames Smart abts_wqeq->iocb.ulpLe = 1; 2833d613b6a7SJames Smart 2834d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2835d613b6a7SJames Smart "6069 Issue ABTS to xri x%x reqtag x%x\n", 2836d613b6a7SJames Smart xri, abts_wqeq->iotag); 2837d613b6a7SJames Smart return 1; 2838d613b6a7SJames Smart } 2839d613b6a7SJames Smart 2840d613b6a7SJames Smart static int 2841d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba, 2842d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2843d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2844d613b6a7SJames Smart { 2845d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2846d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2847d613b6a7SJames Smart union lpfc_wqe *abts_wqe; 2848d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2849d613b6a7SJames Smart unsigned long flags; 2850d613b6a7SJames Smart int rc; 2851d613b6a7SJames Smart 2852d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2853d613b6a7SJames Smart if (!ctxp->wqeq) { 28546c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 2855d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2856d613b6a7SJames Smart } 2857d613b6a7SJames Smart 2858d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2859d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2860d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2861d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2862d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2863ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 286486c67379SJames Smart "6160 Drop ABORT - wrong NDLP state x%x.\n", 2865b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2866d613b6a7SJames Smart 2867d613b6a7SJames Smart /* No failure to an ABTS request. */ 286886c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2869d613b6a7SJames Smart return 0; 2870d613b6a7SJames Smart } 2871d613b6a7SJames Smart 2872d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 2873d613b6a7SJames Smart ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba); 2874d613b6a7SJames Smart if (!ctxp->abort_wqeq) { 2875547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2876ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 287786c67379SJames Smart "6161 ABORT failed: No wqeqs: " 2878d613b6a7SJames Smart "xri: x%x\n", ctxp->oxid); 2879d613b6a7SJames Smart /* No failure to an ABTS request. */ 288086c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2881d613b6a7SJames Smart return 0; 2882d613b6a7SJames Smart } 2883d613b6a7SJames Smart abts_wqeq = ctxp->abort_wqeq; 2884d613b6a7SJames Smart abts_wqe = &abts_wqeq->wqe; 2885d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 2886d613b6a7SJames Smart 2887d613b6a7SJames Smart /* Announce entry to new IO submit field. */ 288886c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 288986c67379SJames Smart "6162 ABORT Request to rport DID x%06x " 2890d613b6a7SJames Smart "for xri x%x x%x\n", 2891d613b6a7SJames Smart ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag); 2892d613b6a7SJames Smart 2893d613b6a7SJames Smart /* If the hba is getting reset, this flag is set. It is 2894d613b6a7SJames Smart * cleared when the reset is complete and rings reestablished. 2895d613b6a7SJames Smart */ 2896d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2897d613b6a7SJames Smart /* driver queued commands are in process of being flushed */ 2898d613b6a7SJames Smart if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) { 2899d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2900547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2901d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2902d613b6a7SJames Smart "6163 Driver in reset cleanup - flushing " 2903d613b6a7SJames Smart "NVME Req now. hba_flag x%x oxid x%x\n", 2904d613b6a7SJames Smart phba->hba_flag, ctxp->oxid); 2905d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 290686c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2907d613b6a7SJames Smart return 0; 2908d613b6a7SJames Smart } 2909d613b6a7SJames Smart 2910d613b6a7SJames Smart /* Outstanding abort is in progress */ 2911d613b6a7SJames Smart if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) { 2912d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2913547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2914d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2915d613b6a7SJames Smart "6164 Outstanding NVME I/O Abort Request " 2916d613b6a7SJames Smart "still pending on oxid x%x\n", 2917d613b6a7SJames Smart ctxp->oxid); 2918d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 291986c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2920d613b6a7SJames Smart return 0; 2921d613b6a7SJames Smart } 2922d613b6a7SJames Smart 2923d613b6a7SJames Smart /* Ready - mark outstanding as aborted by driver. */ 2924d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED; 2925d613b6a7SJames Smart 2926d613b6a7SJames Smart /* WQEs are reused. Clear stale data and set key fields to 2927d613b6a7SJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 2928d613b6a7SJames Smart */ 2929d613b6a7SJames Smart memset(abts_wqe, 0, sizeof(union lpfc_wqe)); 2930d613b6a7SJames Smart 2931d613b6a7SJames Smart /* word 3 */ 2932d613b6a7SJames Smart bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); 2933d613b6a7SJames Smart 2934d613b6a7SJames Smart /* word 7 */ 2935d613b6a7SJames Smart bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); 2936d613b6a7SJames Smart bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 2937d613b6a7SJames Smart 2938d613b6a7SJames Smart /* word 8 - tell the FW to abort the IO associated with this 2939d613b6a7SJames Smart * outstanding exchange ID. 2940d613b6a7SJames Smart */ 2941d613b6a7SJames Smart abts_wqe->abort_cmd.wqe_com.abort_tag = ctxp->wqeq->sli4_xritag; 2942d613b6a7SJames Smart 2943d613b6a7SJames Smart /* word 9 - this is the iotag for the abts_wqe completion. */ 2944d613b6a7SJames Smart bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, 2945d613b6a7SJames Smart abts_wqeq->iotag); 2946d613b6a7SJames Smart 2947d613b6a7SJames Smart /* word 10 */ 2948d613b6a7SJames Smart bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); 2949d613b6a7SJames Smart bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 2950d613b6a7SJames Smart 2951d613b6a7SJames Smart /* word 11 */ 2952d613b6a7SJames Smart bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); 2953d613b6a7SJames Smart bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); 2954d613b6a7SJames Smart bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 2955d613b6a7SJames Smart 2956d613b6a7SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 2957d613b6a7SJames Smart abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx; 2958d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp; 2959d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 2960d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME; 2961d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 29624550f9c7SJames Smart abts_wqeq->vport = phba->pport; 2963d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 2964d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2965547077a4SJames Smart if (rc == WQE_SUCCESS) { 2966547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_sol); 2967d613b6a7SJames Smart return 0; 2968547077a4SJames Smart } 2969d613b6a7SJames Smart 2970547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 297186c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2972d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 297386c67379SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 297486c67379SJames Smart "6166 Failed ABORT issue_wqe with status x%x " 2975d613b6a7SJames Smart "for oxid x%x.\n", 2976d613b6a7SJames Smart rc, ctxp->oxid); 2977d613b6a7SJames Smart return 1; 2978d613b6a7SJames Smart } 2979d613b6a7SJames Smart 2980d613b6a7SJames Smart 2981d613b6a7SJames Smart static int 2982d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba, 2983d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2984d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2985d613b6a7SJames Smart { 2986d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2987d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2988d613b6a7SJames Smart unsigned long flags; 2989d613b6a7SJames Smart int rc; 2990d613b6a7SJames Smart 2991d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2992d613b6a7SJames Smart if (!ctxp->wqeq) { 29936c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 2994d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2995d613b6a7SJames Smart } 2996d613b6a7SJames Smart 2997ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_FREE) { 2998ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2999ce1b591cSJames Smart "6417 NVMET ABORT ctx freed %d %d oxid x%x\n", 3000ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 3001ce1b591cSJames Smart rc = WQE_BUSY; 3002ce1b591cSJames Smart goto aerr; 3003ce1b591cSJames Smart } 3004ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 3005ce1b591cSJames Smart ctxp->entry_cnt++; 3006d613b6a7SJames Smart rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 3007d613b6a7SJames Smart if (rc == 0) 3008d613b6a7SJames Smart goto aerr; 3009d613b6a7SJames Smart 3010d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 3011d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 301286c67379SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_unsol_fcp_abort_cmp; 301386c67379SJames Smart abts_wqeq->iocb_cmpl = NULL; 3014d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVMET; 3015d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 3016d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3017d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 3018d613b6a7SJames Smart return 0; 3019d613b6a7SJames Smart } 3020d613b6a7SJames Smart 3021d613b6a7SJames Smart aerr: 302286c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 3023d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3024ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 3025d613b6a7SJames Smart "6135 Failed to Issue ABTS for oxid x%x. Status x%x\n", 3026d613b6a7SJames Smart ctxp->oxid, rc); 3027d613b6a7SJames Smart return 1; 3028d613b6a7SJames Smart } 3029d613b6a7SJames Smart 3030d613b6a7SJames Smart static int 3031d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *phba, 3032d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 3033d613b6a7SJames Smart uint32_t sid, uint16_t xri) 3034d613b6a7SJames Smart { 3035d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 3036d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 3037d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 3038d613b6a7SJames Smart unsigned long flags; 3039d613b6a7SJames Smart int rc; 3040d613b6a7SJames Smart 3041ce1b591cSJames Smart if ((ctxp->state == LPFC_NVMET_STE_LS_RCV && ctxp->entry_cnt == 1) || 3042ce1b591cSJames Smart (ctxp->state == LPFC_NVMET_STE_LS_RSP && ctxp->entry_cnt == 2)) { 3043ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_ABORT; 3044ce1b591cSJames Smart ctxp->entry_cnt++; 3045ce1b591cSJames Smart } else { 3046ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 3047ce1b591cSJames Smart "6418 NVMET LS abort state mismatch " 3048ce1b591cSJames Smart "IO x%x: %d %d\n", 3049ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 3050ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_ABORT; 3051ce1b591cSJames Smart } 3052ce1b591cSJames Smart 3053d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 3054d613b6a7SJames Smart if (!ctxp->wqeq) { 3055d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 3056d613b6a7SJames Smart ctxp->wqeq = lpfc_sli_get_iocbq(phba); 3057d613b6a7SJames Smart if (!ctxp->wqeq) { 3058ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 3059d613b6a7SJames Smart "6068 Abort failed: No wqeqs: " 3060d613b6a7SJames Smart "xri: x%x\n", xri); 3061d613b6a7SJames Smart /* No failure to an ABTS request. */ 3062d613b6a7SJames Smart kfree(ctxp); 3063d613b6a7SJames Smart return 0; 3064d613b6a7SJames Smart } 3065d613b6a7SJames Smart } 3066d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 3067d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 30686c621a22SJames Smart 3069ce1b591cSJames Smart if (lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri) == 0) { 3070ce1b591cSJames Smart rc = WQE_BUSY; 3071ce1b591cSJames Smart goto out; 3072ce1b591cSJames Smart } 3073d613b6a7SJames Smart 3074d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 3075d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp; 3076d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 3077d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS; 3078d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, abts_wqeq); 3079d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 3080d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 3081547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_unsol); 3082d613b6a7SJames Smart return 0; 3083d613b6a7SJames Smart } 3084ce1b591cSJames Smart out: 3085d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 3086d613b6a7SJames Smart abts_wqeq->context2 = NULL; 3087d613b6a7SJames Smart abts_wqeq->context3 = NULL; 3088d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 3089d613b6a7SJames Smart kfree(ctxp); 3090ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 3091d613b6a7SJames Smart "6056 Failed to Issue ABTS. Status x%x\n", rc); 3092d613b6a7SJames Smart return 0; 3093d613b6a7SJames Smart } 3094