1d613b6a7SJames Smart /******************************************************************* 2d613b6a7SJames Smart * This file is part of the Emulex Linux Device Driver for * 3d613b6a7SJames Smart * Fibre Channsel Host Bus Adapters. * 4d080abe0SJames Smart * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * 5d080abe0SJames Smart * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * 6d613b6a7SJames Smart * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7d613b6a7SJames Smart * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 9d613b6a7SJames Smart * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10d613b6a7SJames Smart * * 11d613b6a7SJames Smart * This program is free software; you can redistribute it and/or * 12d613b6a7SJames Smart * modify it under the terms of version 2 of the GNU General * 13d613b6a7SJames Smart * Public License as published by the Free Software Foundation. * 14d613b6a7SJames Smart * This program is distributed in the hope that it will be useful. * 15d613b6a7SJames Smart * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16d613b6a7SJames Smart * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17d613b6a7SJames Smart * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18d613b6a7SJames Smart * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19d613b6a7SJames Smart * TO BE LEGALLY INVALID. See the GNU General Public License for * 20d613b6a7SJames Smart * more details, a copy of which can be found in the file COPYING * 21d613b6a7SJames Smart * included with this package. * 22d613b6a7SJames Smart ********************************************************************/ 23d613b6a7SJames Smart #include <linux/pci.h> 24d613b6a7SJames Smart #include <linux/slab.h> 25d613b6a7SJames Smart #include <linux/interrupt.h> 26d613b6a7SJames Smart #include <linux/delay.h> 27d613b6a7SJames Smart #include <asm/unaligned.h> 28d613b6a7SJames Smart #include <linux/crc-t10dif.h> 29d613b6a7SJames Smart #include <net/checksum.h> 30d613b6a7SJames Smart 31d613b6a7SJames Smart #include <scsi/scsi.h> 32d613b6a7SJames Smart #include <scsi/scsi_device.h> 33d613b6a7SJames Smart #include <scsi/scsi_eh.h> 34d613b6a7SJames Smart #include <scsi/scsi_host.h> 35d613b6a7SJames Smart #include <scsi/scsi_tcq.h> 36d613b6a7SJames Smart #include <scsi/scsi_transport_fc.h> 37d613b6a7SJames Smart #include <scsi/fc/fc_fs.h> 38d613b6a7SJames Smart 39d613b6a7SJames Smart #include <../drivers/nvme/host/nvme.h> 40d613b6a7SJames Smart #include <linux/nvme-fc-driver.h> 41d613b6a7SJames Smart 42d613b6a7SJames Smart #include "lpfc_version.h" 43d613b6a7SJames Smart #include "lpfc_hw4.h" 44d613b6a7SJames Smart #include "lpfc_hw.h" 45d613b6a7SJames Smart #include "lpfc_sli.h" 46d613b6a7SJames Smart #include "lpfc_sli4.h" 47d613b6a7SJames Smart #include "lpfc_nl.h" 48d613b6a7SJames Smart #include "lpfc_disc.h" 49d613b6a7SJames Smart #include "lpfc.h" 50d613b6a7SJames Smart #include "lpfc_scsi.h" 51d613b6a7SJames Smart #include "lpfc_nvme.h" 52d613b6a7SJames Smart #include "lpfc_nvmet.h" 53d613b6a7SJames Smart #include "lpfc_logmsg.h" 54d613b6a7SJames Smart #include "lpfc_crtn.h" 55d613b6a7SJames Smart #include "lpfc_vport.h" 562b65e182SJames Smart #include "lpfc_debugfs.h" 57d613b6a7SJames Smart 58d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *, 59d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 60d613b6a7SJames Smart dma_addr_t rspbuf, 61d613b6a7SJames Smart uint16_t rspsize); 62d613b6a7SJames Smart static struct lpfc_iocbq *lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *, 63d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *); 64d613b6a7SJames Smart static int lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *, 65d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 66d613b6a7SJames Smart uint32_t, uint16_t); 67d613b6a7SJames Smart static int lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *, 68d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 69d613b6a7SJames Smart uint32_t, uint16_t); 70d613b6a7SJames Smart static int lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *, 71d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *, 72d613b6a7SJames Smart uint32_t, uint16_t); 73d613b6a7SJames Smart 7486c67379SJames Smart void 7586c67379SJames Smart lpfc_nvmet_defer_release(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp) 7686c67379SJames Smart { 7786c67379SJames Smart unsigned long iflag; 7886c67379SJames Smart 79e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 8086c67379SJames Smart "6313 NVMET Defer ctx release xri x%x flg x%x\n", 8186c67379SJames Smart ctxp->oxid, ctxp->flag); 8286c67379SJames Smart 8386c67379SJames Smart spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 8486c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS) { 8586c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, 8686c67379SJames Smart iflag); 8786c67379SJames Smart return; 8886c67379SJames Smart } 8986c67379SJames Smart ctxp->flag |= LPFC_NVMET_CTX_RLS; 9086c67379SJames Smart list_add_tail(&ctxp->list, &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); 9186c67379SJames Smart spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag); 9286c67379SJames Smart } 9386c67379SJames Smart 94d613b6a7SJames Smart /** 95d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response 96d613b6a7SJames Smart * @phba: Pointer to HBA context object. 97d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 98d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 99d613b6a7SJames Smart * 100d613b6a7SJames Smart * The function is called from SLI ring event handler with no 101d613b6a7SJames Smart * lock held. This function is the completion handler for NVME LS commands 102d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 103d613b6a7SJames Smart **/ 104d613b6a7SJames Smart static void 105d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 106d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 107d613b6a7SJames Smart { 108d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 109d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp; 110d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 111d613b6a7SJames Smart uint32_t status, result; 112d613b6a7SJames Smart 113d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 114d613b6a7SJames Smart result = wcqe->parameter; 115ce1b591cSJames Smart ctxp = cmdwqe->context2; 116ce1b591cSJames Smart 117ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_LS_RSP || ctxp->entry_cnt != 2) { 118ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 119ce1b591cSJames Smart "6410 NVMET LS cmpl state mismatch IO x%x: " 120ce1b591cSJames Smart "%d %d\n", 121ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 122ce1b591cSJames Smart } 123ce1b591cSJames Smart 124d613b6a7SJames Smart if (!phba->targetport) 125d613b6a7SJames Smart goto out; 126d613b6a7SJames Smart 127d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 128d613b6a7SJames Smart 129d613b6a7SJames Smart if (status) 130d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_error); 131d613b6a7SJames Smart else 132d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_cmpl); 133d613b6a7SJames Smart 134d613b6a7SJames Smart out: 135d613b6a7SJames Smart rsp = &ctxp->ctx.ls_req; 136d613b6a7SJames Smart 1372b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS CMPL: xri x%x stat x%x result x%x\n", 1382b65e182SJames Smart ctxp->oxid, status, result); 1392b65e182SJames Smart 140d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 141ce1b591cSJames Smart "6038 NVMET LS rsp cmpl: %d %d oxid x%x\n", 142ce1b591cSJames Smart status, result, ctxp->oxid); 143d613b6a7SJames Smart 144d613b6a7SJames Smart lpfc_nlp_put(cmdwqe->context1); 145d613b6a7SJames Smart cmdwqe->context2 = NULL; 146d613b6a7SJames Smart cmdwqe->context3 = NULL; 147d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 148d613b6a7SJames Smart rsp->done(rsp); 149d613b6a7SJames Smart kfree(ctxp); 150d613b6a7SJames Smart } 151d613b6a7SJames Smart 152d613b6a7SJames Smart /** 1536c621a22SJames Smart * lpfc_nvmet_ctxbuf_post - Repost a NVMET RQ DMA buffer and clean up context 154d613b6a7SJames Smart * @phba: HBA buffer is associated with 155d613b6a7SJames Smart * @ctxp: context to clean up 156d613b6a7SJames Smart * @mp: Buffer to free 157d613b6a7SJames Smart * 158d613b6a7SJames Smart * Description: Frees the given DMA buffer in the appropriate way given by 159d613b6a7SJames Smart * reposting it to its associated RQ so it can be reused. 160d613b6a7SJames Smart * 161d613b6a7SJames Smart * Notes: Takes phba->hbalock. Can be called with or without other locks held. 162d613b6a7SJames Smart * 163d613b6a7SJames Smart * Returns: None 164d613b6a7SJames Smart **/ 165d613b6a7SJames Smart void 1666c621a22SJames Smart lpfc_nvmet_ctxbuf_post(struct lpfc_hba *phba, struct lpfc_nvmet_ctxbuf *ctx_buf) 167d613b6a7SJames Smart { 168eeeb51d8SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1696c621a22SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = ctx_buf->context; 170a8cf5dfeSJames Smart struct lpfc_nvmet_tgtport *tgtp; 171a8cf5dfeSJames Smart struct fc_frame_header *fc_hdr; 172a8cf5dfeSJames Smart struct rqb_dmabuf *nvmebuf; 17366d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 174a8cf5dfeSJames Smart uint32_t *payload; 175a8cf5dfeSJames Smart uint32_t size, oxid, sid, rc; 17666d7ce93SDick Kennedy int cpu; 1776c621a22SJames Smart unsigned long iflag; 17886c67379SJames Smart 179d613b6a7SJames Smart if (ctxp->txrdy) { 180771db5c0SRomain Perier dma_pool_free(phba->txrdy_payload_pool, ctxp->txrdy, 181d613b6a7SJames Smart ctxp->txrdy_phys); 182d613b6a7SJames Smart ctxp->txrdy = NULL; 183d613b6a7SJames Smart ctxp->txrdy_phys = 0; 184d613b6a7SJames Smart } 185ce1b591cSJames Smart 186ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_FREE) { 187ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 188ce1b591cSJames Smart "6411 NVMET free, already free IO x%x: %d %d\n", 189ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 190ce1b591cSJames Smart } 191d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_FREE; 1926c621a22SJames Smart 193a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 194a8cf5dfeSJames Smart if (phba->sli4_hba.nvmet_io_wait_cnt) { 195a8cf5dfeSJames Smart list_remove_head(&phba->sli4_hba.lpfc_nvmet_io_wait_list, 196a8cf5dfeSJames Smart nvmebuf, struct rqb_dmabuf, 197a8cf5dfeSJames Smart hbuf.list); 198a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt--; 199a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 200a8cf5dfeSJames Smart iflag); 201a8cf5dfeSJames Smart 202a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 203a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 204a8cf5dfeSJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 205a8cf5dfeSJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 206a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 207a8cf5dfeSJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 208a8cf5dfeSJames Smart 209a8cf5dfeSJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context; 210a8cf5dfeSJames Smart ctxp->wqeq = NULL; 211a8cf5dfeSJames Smart ctxp->txrdy = NULL; 212a8cf5dfeSJames Smart ctxp->offset = 0; 213a8cf5dfeSJames Smart ctxp->phba = phba; 214a8cf5dfeSJames Smart ctxp->size = size; 215a8cf5dfeSJames Smart ctxp->oxid = oxid; 216a8cf5dfeSJames Smart ctxp->sid = sid; 217a8cf5dfeSJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 218a8cf5dfeSJames Smart ctxp->entry_cnt = 1; 219a8cf5dfeSJames Smart ctxp->flag = 0; 220a8cf5dfeSJames Smart ctxp->ctxbuf = ctx_buf; 221a8cf5dfeSJames Smart spin_lock_init(&ctxp->ctxlock); 222a8cf5dfeSJames Smart 223a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 224c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 225a8cf5dfeSJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 226a8cf5dfeSJames Smart ctxp->ts_nvme_data = 0; 227a8cf5dfeSJames Smart ctxp->ts_data_wqput = 0; 228a8cf5dfeSJames Smart ctxp->ts_isr_data = 0; 229a8cf5dfeSJames Smart ctxp->ts_data_nvme = 0; 230a8cf5dfeSJames Smart ctxp->ts_nvme_status = 0; 231a8cf5dfeSJames Smart ctxp->ts_status_wqput = 0; 232a8cf5dfeSJames Smart ctxp->ts_isr_status = 0; 233a8cf5dfeSJames Smart ctxp->ts_status_nvme = 0; 234d613b6a7SJames Smart } 235a8cf5dfeSJames Smart #endif 236a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 237a8cf5dfeSJames Smart /* 238a8cf5dfeSJames Smart * The calling sequence should be: 239a8cf5dfeSJames Smart * nvmet_fc_rcv_fcp_req->lpfc_nvmet_xmt_fcp_op/cmp- req->done 240a8cf5dfeSJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 241a8cf5dfeSJames Smart * When we return from nvmet_fc_rcv_fcp_req, all relevant info 242a8cf5dfeSJames Smart * the NVME command / FC header is stored. 243a8cf5dfeSJames Smart * A buffer has already been reposted for this IO, so just free 244a8cf5dfeSJames Smart * the nvmebuf. 245a8cf5dfeSJames Smart */ 246a8cf5dfeSJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 247a8cf5dfeSJames Smart payload, size); 248a8cf5dfeSJames Smart 249a8cf5dfeSJames Smart /* Process FCP command */ 250a8cf5dfeSJames Smart if (rc == 0) { 251a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 252a8cf5dfeSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 253a8cf5dfeSJames Smart return; 254a8cf5dfeSJames Smart } 255a8cf5dfeSJames Smart 256a8cf5dfeSJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 257a8cf5dfeSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 258a8cf5dfeSJames Smart "2582 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 259a8cf5dfeSJames Smart ctxp->oxid, rc, 260a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 261a8cf5dfeSJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 262a8cf5dfeSJames Smart atomic_read(&tgtp->xmt_fcp_release)); 263a8cf5dfeSJames Smart 264a8cf5dfeSJames Smart lpfc_nvmet_defer_release(phba, ctxp); 265a8cf5dfeSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 266a8cf5dfeSJames Smart nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf); 267a8cf5dfeSJames Smart return; 268a8cf5dfeSJames Smart } 269a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 270a8cf5dfeSJames Smart 27166d7ce93SDick Kennedy /* 27266d7ce93SDick Kennedy * Use the CPU context list, from the MRQ the IO was received on 27366d7ce93SDick Kennedy * (ctxp->idx), to save context structure. 27466d7ce93SDick Kennedy */ 27566d7ce93SDick Kennedy cpu = smp_processor_id(); 27666d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, cpu, ctxp->idx); 27766d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, iflag); 27866d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 27966d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 28066d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, iflag); 281eeeb51d8SJames Smart #endif 282d613b6a7SJames Smart } 283d613b6a7SJames Smart 2842b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2852b65e182SJames Smart static void 2862b65e182SJames Smart lpfc_nvmet_ktime(struct lpfc_hba *phba, 2872b65e182SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 2882b65e182SJames Smart { 2892b65e182SJames Smart uint64_t seg1, seg2, seg3, seg4, seg5; 2902b65e182SJames Smart uint64_t seg6, seg7, seg8, seg9, seg10; 291c8a4ce0bSDick Kennedy uint64_t segsum; 2922b65e182SJames Smart 2932b65e182SJames Smart if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme || 2942b65e182SJames Smart !ctxp->ts_nvme_data || !ctxp->ts_data_wqput || 2952b65e182SJames Smart !ctxp->ts_isr_data || !ctxp->ts_data_nvme || 2962b65e182SJames Smart !ctxp->ts_nvme_status || !ctxp->ts_status_wqput || 2972b65e182SJames Smart !ctxp->ts_isr_status || !ctxp->ts_status_nvme) 2982b65e182SJames Smart return; 2992b65e182SJames Smart 300c8a4ce0bSDick Kennedy if (ctxp->ts_status_nvme < ctxp->ts_isr_cmd) 301c8a4ce0bSDick Kennedy return; 3022b65e182SJames Smart if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme) 3032b65e182SJames Smart return; 3042b65e182SJames Smart if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data) 3052b65e182SJames Smart return; 3062b65e182SJames Smart if (ctxp->ts_nvme_data > ctxp->ts_data_wqput) 3072b65e182SJames Smart return; 3082b65e182SJames Smart if (ctxp->ts_data_wqput > ctxp->ts_isr_data) 3092b65e182SJames Smart return; 3102b65e182SJames Smart if (ctxp->ts_isr_data > ctxp->ts_data_nvme) 3112b65e182SJames Smart return; 3122b65e182SJames Smart if (ctxp->ts_data_nvme > ctxp->ts_nvme_status) 3132b65e182SJames Smart return; 3142b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_status_wqput) 3152b65e182SJames Smart return; 3162b65e182SJames Smart if (ctxp->ts_status_wqput > ctxp->ts_isr_status) 3172b65e182SJames Smart return; 3182b65e182SJames Smart if (ctxp->ts_isr_status > ctxp->ts_status_nvme) 3192b65e182SJames Smart return; 3202b65e182SJames Smart /* 3212b65e182SJames Smart * Segment 1 - Time from FCP command received by MSI-X ISR 3222b65e182SJames Smart * to FCP command is passed to NVME Layer. 3232b65e182SJames Smart * Segment 2 - Time from FCP command payload handed 3242b65e182SJames Smart * off to NVME Layer to Driver receives a Command op 3252b65e182SJames Smart * from NVME Layer. 3262b65e182SJames Smart * Segment 3 - Time from Driver receives a Command op 3272b65e182SJames Smart * from NVME Layer to Command is put on WQ. 3282b65e182SJames Smart * Segment 4 - Time from Driver WQ put is done 3292b65e182SJames Smart * to MSI-X ISR for Command cmpl. 3302b65e182SJames Smart * Segment 5 - Time from MSI-X ISR for Command cmpl to 3312b65e182SJames Smart * Command cmpl is passed to NVME Layer. 3322b65e182SJames Smart * Segment 6 - Time from Command cmpl is passed to NVME 3332b65e182SJames Smart * Layer to Driver receives a RSP op from NVME Layer. 3342b65e182SJames Smart * Segment 7 - Time from Driver receives a RSP op from 3352b65e182SJames Smart * NVME Layer to WQ put is done on TRSP FCP Status. 3362b65e182SJames Smart * Segment 8 - Time from Driver WQ put is done on TRSP 3372b65e182SJames Smart * FCP Status to MSI-X ISR for TRSP cmpl. 3382b65e182SJames Smart * Segment 9 - Time from MSI-X ISR for TRSP cmpl to 3392b65e182SJames Smart * TRSP cmpl is passed to NVME Layer. 3402b65e182SJames Smart * Segment 10 - Time from FCP command received by 3412b65e182SJames Smart * MSI-X ISR to command is completed on wire. 3422b65e182SJames Smart * (Segments 1 thru 8) for READDATA / WRITEDATA 3432b65e182SJames Smart * (Segments 1 thru 4) for READDATA_RSP 3442b65e182SJames Smart */ 3452b65e182SJames Smart seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd; 346c8a4ce0bSDick Kennedy segsum = seg1; 347c8a4ce0bSDick Kennedy 348c8a4ce0bSDick Kennedy seg2 = ctxp->ts_nvme_data - ctxp->ts_isr_cmd; 349c8a4ce0bSDick Kennedy if (segsum > seg2) 350c8a4ce0bSDick Kennedy return; 351c8a4ce0bSDick Kennedy seg2 -= segsum; 352c8a4ce0bSDick Kennedy segsum += seg2; 353c8a4ce0bSDick Kennedy 354c8a4ce0bSDick Kennedy seg3 = ctxp->ts_data_wqput - ctxp->ts_isr_cmd; 355c8a4ce0bSDick Kennedy if (segsum > seg3) 356c8a4ce0bSDick Kennedy return; 357c8a4ce0bSDick Kennedy seg3 -= segsum; 358c8a4ce0bSDick Kennedy segsum += seg3; 359c8a4ce0bSDick Kennedy 360c8a4ce0bSDick Kennedy seg4 = ctxp->ts_isr_data - ctxp->ts_isr_cmd; 361c8a4ce0bSDick Kennedy if (segsum > seg4) 362c8a4ce0bSDick Kennedy return; 363c8a4ce0bSDick Kennedy seg4 -= segsum; 364c8a4ce0bSDick Kennedy segsum += seg4; 365c8a4ce0bSDick Kennedy 366c8a4ce0bSDick Kennedy seg5 = ctxp->ts_data_nvme - ctxp->ts_isr_cmd; 367c8a4ce0bSDick Kennedy if (segsum > seg5) 368c8a4ce0bSDick Kennedy return; 369c8a4ce0bSDick Kennedy seg5 -= segsum; 370c8a4ce0bSDick Kennedy segsum += seg5; 371c8a4ce0bSDick Kennedy 3722b65e182SJames Smart 3732b65e182SJames Smart /* For auto rsp commands seg6 thru seg10 will be 0 */ 3742b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) { 375c8a4ce0bSDick Kennedy seg6 = ctxp->ts_nvme_status - ctxp->ts_isr_cmd; 376c8a4ce0bSDick Kennedy if (segsum > seg6) 377c8a4ce0bSDick Kennedy return; 378c8a4ce0bSDick Kennedy seg6 -= segsum; 379c8a4ce0bSDick Kennedy segsum += seg6; 380c8a4ce0bSDick Kennedy 381c8a4ce0bSDick Kennedy seg7 = ctxp->ts_status_wqput - ctxp->ts_isr_cmd; 382c8a4ce0bSDick Kennedy if (segsum > seg7) 383c8a4ce0bSDick Kennedy return; 384c8a4ce0bSDick Kennedy seg7 -= segsum; 385c8a4ce0bSDick Kennedy segsum += seg7; 386c8a4ce0bSDick Kennedy 387c8a4ce0bSDick Kennedy seg8 = ctxp->ts_isr_status - ctxp->ts_isr_cmd; 388c8a4ce0bSDick Kennedy if (segsum > seg8) 389c8a4ce0bSDick Kennedy return; 390c8a4ce0bSDick Kennedy seg8 -= segsum; 391c8a4ce0bSDick Kennedy segsum += seg8; 392c8a4ce0bSDick Kennedy 393c8a4ce0bSDick Kennedy seg9 = ctxp->ts_status_nvme - ctxp->ts_isr_cmd; 394c8a4ce0bSDick Kennedy if (segsum > seg9) 395c8a4ce0bSDick Kennedy return; 396c8a4ce0bSDick Kennedy seg9 -= segsum; 397c8a4ce0bSDick Kennedy segsum += seg9; 398c8a4ce0bSDick Kennedy 399c8a4ce0bSDick Kennedy if (ctxp->ts_isr_status < ctxp->ts_isr_cmd) 400c8a4ce0bSDick Kennedy return; 4012b65e182SJames Smart seg10 = (ctxp->ts_isr_status - 4022b65e182SJames Smart ctxp->ts_isr_cmd); 4032b65e182SJames Smart } else { 404c8a4ce0bSDick Kennedy if (ctxp->ts_isr_data < ctxp->ts_isr_cmd) 405c8a4ce0bSDick Kennedy return; 4062b65e182SJames Smart seg6 = 0; 4072b65e182SJames Smart seg7 = 0; 4082b65e182SJames Smart seg8 = 0; 4092b65e182SJames Smart seg9 = 0; 4102b65e182SJames Smart seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd); 4112b65e182SJames Smart } 4122b65e182SJames Smart 4132b65e182SJames Smart phba->ktime_seg1_total += seg1; 4142b65e182SJames Smart if (seg1 < phba->ktime_seg1_min) 4152b65e182SJames Smart phba->ktime_seg1_min = seg1; 4162b65e182SJames Smart else if (seg1 > phba->ktime_seg1_max) 4172b65e182SJames Smart phba->ktime_seg1_max = seg1; 4182b65e182SJames Smart 4192b65e182SJames Smart phba->ktime_seg2_total += seg2; 4202b65e182SJames Smart if (seg2 < phba->ktime_seg2_min) 4212b65e182SJames Smart phba->ktime_seg2_min = seg2; 4222b65e182SJames Smart else if (seg2 > phba->ktime_seg2_max) 4232b65e182SJames Smart phba->ktime_seg2_max = seg2; 4242b65e182SJames Smart 4252b65e182SJames Smart phba->ktime_seg3_total += seg3; 4262b65e182SJames Smart if (seg3 < phba->ktime_seg3_min) 4272b65e182SJames Smart phba->ktime_seg3_min = seg3; 4282b65e182SJames Smart else if (seg3 > phba->ktime_seg3_max) 4292b65e182SJames Smart phba->ktime_seg3_max = seg3; 4302b65e182SJames Smart 4312b65e182SJames Smart phba->ktime_seg4_total += seg4; 4322b65e182SJames Smart if (seg4 < phba->ktime_seg4_min) 4332b65e182SJames Smart phba->ktime_seg4_min = seg4; 4342b65e182SJames Smart else if (seg4 > phba->ktime_seg4_max) 4352b65e182SJames Smart phba->ktime_seg4_max = seg4; 4362b65e182SJames Smart 4372b65e182SJames Smart phba->ktime_seg5_total += seg5; 4382b65e182SJames Smart if (seg5 < phba->ktime_seg5_min) 4392b65e182SJames Smart phba->ktime_seg5_min = seg5; 4402b65e182SJames Smart else if (seg5 > phba->ktime_seg5_max) 4412b65e182SJames Smart phba->ktime_seg5_max = seg5; 4422b65e182SJames Smart 4432b65e182SJames Smart phba->ktime_data_samples++; 4442b65e182SJames Smart if (!seg6) 4452b65e182SJames Smart goto out; 4462b65e182SJames Smart 4472b65e182SJames Smart phba->ktime_seg6_total += seg6; 4482b65e182SJames Smart if (seg6 < phba->ktime_seg6_min) 4492b65e182SJames Smart phba->ktime_seg6_min = seg6; 4502b65e182SJames Smart else if (seg6 > phba->ktime_seg6_max) 4512b65e182SJames Smart phba->ktime_seg6_max = seg6; 4522b65e182SJames Smart 4532b65e182SJames Smart phba->ktime_seg7_total += seg7; 4542b65e182SJames Smart if (seg7 < phba->ktime_seg7_min) 4552b65e182SJames Smart phba->ktime_seg7_min = seg7; 4562b65e182SJames Smart else if (seg7 > phba->ktime_seg7_max) 4572b65e182SJames Smart phba->ktime_seg7_max = seg7; 4582b65e182SJames Smart 4592b65e182SJames Smart phba->ktime_seg8_total += seg8; 4602b65e182SJames Smart if (seg8 < phba->ktime_seg8_min) 4612b65e182SJames Smart phba->ktime_seg8_min = seg8; 4622b65e182SJames Smart else if (seg8 > phba->ktime_seg8_max) 4632b65e182SJames Smart phba->ktime_seg8_max = seg8; 4642b65e182SJames Smart 4652b65e182SJames Smart phba->ktime_seg9_total += seg9; 4662b65e182SJames Smart if (seg9 < phba->ktime_seg9_min) 4672b65e182SJames Smart phba->ktime_seg9_min = seg9; 4682b65e182SJames Smart else if (seg9 > phba->ktime_seg9_max) 4692b65e182SJames Smart phba->ktime_seg9_max = seg9; 4702b65e182SJames Smart out: 4712b65e182SJames Smart phba->ktime_seg10_total += seg10; 4722b65e182SJames Smart if (seg10 < phba->ktime_seg10_min) 4732b65e182SJames Smart phba->ktime_seg10_min = seg10; 4742b65e182SJames Smart else if (seg10 > phba->ktime_seg10_max) 4752b65e182SJames Smart phba->ktime_seg10_max = seg10; 4762b65e182SJames Smart phba->ktime_status_samples++; 4772b65e182SJames Smart } 4782b65e182SJames Smart #endif 4792b65e182SJames Smart 480d613b6a7SJames Smart /** 481d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response 482d613b6a7SJames Smart * @phba: Pointer to HBA context object. 483d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 484d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 485d613b6a7SJames Smart * 486d613b6a7SJames Smart * The function is called from SLI ring event handler with no 487d613b6a7SJames Smart * lock held. This function is the completion handler for NVME FCP commands 488d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 489d613b6a7SJames Smart **/ 490d613b6a7SJames Smart static void 491d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 492d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 493d613b6a7SJames Smart { 494d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 495d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp; 496d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 497e3246a12SJames Smart uint32_t status, result, op, start_clean, logerr; 4982b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4992b65e182SJames Smart uint32_t id; 5002b65e182SJames Smart #endif 501d613b6a7SJames Smart 502d613b6a7SJames Smart ctxp = cmdwqe->context2; 50386c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_IO_INP; 50486c67379SJames Smart 505d613b6a7SJames Smart rsp = &ctxp->ctx.fcp_req; 506d613b6a7SJames Smart op = rsp->op; 507d613b6a7SJames Smart 508d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 509d613b6a7SJames Smart result = wcqe->parameter; 510d613b6a7SJames Smart 51186c67379SJames Smart if (phba->targetport) 51286c67379SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 51386c67379SJames Smart else 51486c67379SJames Smart tgtp = NULL; 515d613b6a7SJames Smart 5162b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n", 5172b65e182SJames Smart ctxp->oxid, op, status); 5182b65e182SJames Smart 519d613b6a7SJames Smart if (status) { 520d613b6a7SJames Smart rsp->fcp_error = NVME_SC_DATA_XFER_ERROR; 521d613b6a7SJames Smart rsp->transferred_length = 0; 52286c67379SJames Smart if (tgtp) 523d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_error); 52486c67379SJames Smart 525e3246a12SJames Smart logerr = LOG_NVME_IOERR; 526e3246a12SJames Smart 52786c67379SJames Smart /* pick up SLI4 exhange busy condition */ 52886c67379SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) { 52986c67379SJames Smart ctxp->flag |= LPFC_NVMET_XBUSY; 530e3246a12SJames Smart logerr |= LOG_NVME_ABTS; 53186c67379SJames Smart 53286c67379SJames Smart } else { 53386c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 53486c67379SJames Smart } 53586c67379SJames Smart 536e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, logerr, 537e3246a12SJames Smart "6315 IO Error Cmpl xri x%x: %x/%x XBUSY:x%x\n", 538e3246a12SJames Smart ctxp->oxid, status, result, ctxp->flag); 539e3246a12SJames Smart 540d613b6a7SJames Smart } else { 541d613b6a7SJames Smart rsp->fcp_error = NVME_SC_SUCCESS; 542d613b6a7SJames Smart if (op == NVMET_FCOP_RSP) 543d613b6a7SJames Smart rsp->transferred_length = rsp->rsplen; 544d613b6a7SJames Smart else 545d613b6a7SJames Smart rsp->transferred_length = rsp->transfer_length; 54686c67379SJames Smart if (tgtp) 547d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_cmpl); 548d613b6a7SJames Smart } 549d613b6a7SJames Smart 550d613b6a7SJames Smart if ((op == NVMET_FCOP_READDATA_RSP) || 551d613b6a7SJames Smart (op == NVMET_FCOP_RSP)) { 552d613b6a7SJames Smart /* Sanity check */ 553d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 554d613b6a7SJames Smart ctxp->entry_cnt++; 55586c67379SJames Smart 5562b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 557c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 5582b65e182SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 5592b65e182SJames Smart ctxp->ts_isr_data = 5602b65e182SJames Smart cmdwqe->isr_timestamp; 5612b65e182SJames Smart ctxp->ts_data_nvme = 5622b65e182SJames Smart ktime_get_ns(); 5632b65e182SJames Smart ctxp->ts_nvme_status = 5642b65e182SJames Smart ctxp->ts_data_nvme; 5652b65e182SJames Smart ctxp->ts_status_wqput = 5662b65e182SJames Smart ctxp->ts_data_nvme; 5672b65e182SJames Smart ctxp->ts_isr_status = 5682b65e182SJames Smart ctxp->ts_data_nvme; 5692b65e182SJames Smart ctxp->ts_status_nvme = 5702b65e182SJames Smart ctxp->ts_data_nvme; 5712b65e182SJames Smart } else { 5722b65e182SJames Smart ctxp->ts_isr_status = 5732b65e182SJames Smart cmdwqe->isr_timestamp; 5742b65e182SJames Smart ctxp->ts_status_nvme = 5752b65e182SJames Smart ktime_get_ns(); 5762b65e182SJames Smart } 5772b65e182SJames Smart } 5782b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 5792b65e182SJames Smart id = smp_processor_id(); 5802b65e182SJames Smart if (ctxp->cpu != id) 5812b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 5822b65e182SJames Smart "6703 CPU Check cmpl: " 5832b65e182SJames Smart "cpu %d expect %d\n", 5842b65e182SJames Smart id, ctxp->cpu); 5852b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 5862b65e182SJames Smart phba->cpucheck_cmpl_io[id]++; 5872b65e182SJames Smart } 5882b65e182SJames Smart #endif 589d613b6a7SJames Smart rsp->done(rsp); 5902b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 591c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) 5922b65e182SJames Smart lpfc_nvmet_ktime(phba, ctxp); 5932b65e182SJames Smart #endif 59419b58d94SJames Smart /* lpfc_nvmet_xmt_fcp_release() will recycle the context */ 595d613b6a7SJames Smart } else { 596d613b6a7SJames Smart ctxp->entry_cnt++; 597c6e0c925SDick Kennedy start_clean = offsetof(struct lpfc_iocbq, iocb_flag); 598d613b6a7SJames Smart memset(((char *)cmdwqe) + start_clean, 0, 599d613b6a7SJames Smart (sizeof(struct lpfc_iocbq) - start_clean)); 6002b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 601c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 6022b65e182SJames Smart ctxp->ts_isr_data = cmdwqe->isr_timestamp; 6032b65e182SJames Smart ctxp->ts_data_nvme = ktime_get_ns(); 6042b65e182SJames Smart } 6052b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 6062b65e182SJames Smart id = smp_processor_id(); 6072b65e182SJames Smart if (ctxp->cpu != id) 6082b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 6092b65e182SJames Smart "6704 CPU Check cmdcmpl: " 6102b65e182SJames Smart "cpu %d expect %d\n", 6112b65e182SJames Smart id, ctxp->cpu); 6122b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 6132b65e182SJames Smart phba->cpucheck_ccmpl_io[id]++; 6142b65e182SJames Smart } 6152b65e182SJames Smart #endif 616d613b6a7SJames Smart rsp->done(rsp); 617d613b6a7SJames Smart } 618d613b6a7SJames Smart } 619d613b6a7SJames Smart 620d613b6a7SJames Smart static int 621d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport, 622d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp) 623d613b6a7SJames Smart { 624d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 625d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.ls_req); 626d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 627d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf = 628d613b6a7SJames Smart (struct hbq_dmabuf *)ctxp->rqb_buffer; 629d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 630d613b6a7SJames Smart struct lpfc_nvmet_tgtport *nvmep = tgtport->private; 631d613b6a7SJames Smart struct lpfc_dmabuf dmabuf; 632d613b6a7SJames Smart struct ulp_bde64 bpl; 633d613b6a7SJames Smart int rc; 634d613b6a7SJames Smart 635d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 636ce1b591cSJames Smart "6023 NVMET LS rsp oxid x%x\n", ctxp->oxid); 637ce1b591cSJames Smart 638ce1b591cSJames Smart if ((ctxp->state != LPFC_NVMET_STE_LS_RCV) || 639ce1b591cSJames Smart (ctxp->entry_cnt != 1)) { 640ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 641ce1b591cSJames Smart "6412 NVMET LS rsp state mismatch " 642ce1b591cSJames Smart "oxid x%x: %d %d\n", 643ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 644ce1b591cSJames Smart } 645ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_RSP; 646ce1b591cSJames Smart ctxp->entry_cnt++; 647d613b6a7SJames Smart 648d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, ctxp, rsp->rspdma, 649d613b6a7SJames Smart rsp->rsplen); 650d613b6a7SJames Smart if (nvmewqeq == NULL) { 651d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 652d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 653d613b6a7SJames Smart "6150 LS Drop IO x%x: Prep\n", 654d613b6a7SJames Smart ctxp->oxid); 655d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 656547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 657d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, 658d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 659d613b6a7SJames Smart return -ENOMEM; 660d613b6a7SJames Smart } 661d613b6a7SJames Smart 662d613b6a7SJames Smart /* Save numBdes for bpl2sgl */ 663d613b6a7SJames Smart nvmewqeq->rsvd2 = 1; 664d613b6a7SJames Smart nvmewqeq->hba_wqidx = 0; 665d613b6a7SJames Smart nvmewqeq->context3 = &dmabuf; 666d613b6a7SJames Smart dmabuf.virt = &bpl; 667d613b6a7SJames Smart bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow; 668d613b6a7SJames Smart bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh; 669d613b6a7SJames Smart bpl.tus.f.bdeSize = rsp->rsplen; 670d613b6a7SJames Smart bpl.tus.f.bdeFlags = 0; 671d613b6a7SJames Smart bpl.tus.w = le32_to_cpu(bpl.tus.w); 672d613b6a7SJames Smart 673d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_rsp_cmp; 674d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 675d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 676d613b6a7SJames Smart 6772b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RESP: xri x%x wqidx x%x len x%x\n", 6782b65e182SJames Smart ctxp->oxid, nvmewqeq->hba_wqidx, rsp->rsplen); 6792b65e182SJames Smart 680d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, nvmewqeq); 681d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 682d613b6a7SJames Smart /* 683d613b6a7SJames Smart * Okay to repost buffer here, but wait till cmpl 684d613b6a7SJames Smart * before freeing ctxp and iocbq. 685d613b6a7SJames Smart */ 686d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 687d613b6a7SJames Smart ctxp->rqb_buffer = 0; 688d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_rsp); 689d613b6a7SJames Smart return 0; 690d613b6a7SJames Smart } 691d613b6a7SJames Smart /* Give back resources */ 692d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 693d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 694d613b6a7SJames Smart "6151 LS Drop IO x%x: Issue %d\n", 695d613b6a7SJames Smart ctxp->oxid, rc); 696d613b6a7SJames Smart 697d613b6a7SJames Smart lpfc_nlp_put(nvmewqeq->context1); 698d613b6a7SJames Smart 699d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 700547077a4SJames Smart atomic_inc(&nvmep->xmt_ls_abort); 701d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid); 702d613b6a7SJames Smart return -ENXIO; 703d613b6a7SJames Smart } 704d613b6a7SJames Smart 705d613b6a7SJames Smart static int 706d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport, 707d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp) 708d613b6a7SJames Smart { 709d613b6a7SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 710d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 711d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 712d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 713d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 714223b78eaSArnd Bergmann int rc; 7152b65e182SJames Smart 7162b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 717c8a4ce0bSDick Kennedy if (ctxp->ts_cmd_nvme) { 7182b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 7192b65e182SJames Smart ctxp->ts_nvme_status = ktime_get_ns(); 7202b65e182SJames Smart else 7212b65e182SJames Smart ctxp->ts_nvme_data = ktime_get_ns(); 7222b65e182SJames Smart } 7232b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 724223b78eaSArnd Bergmann int id = smp_processor_id(); 7252b65e182SJames Smart ctxp->cpu = id; 7262b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 7272b65e182SJames Smart phba->cpucheck_xmt_io[id]++; 7282b65e182SJames Smart if (rsp->hwqid != id) { 7292b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 7302b65e182SJames Smart "6705 CPU Check OP: " 7312b65e182SJames Smart "cpu %d expect %d\n", 7322b65e182SJames Smart id, rsp->hwqid); 7332b65e182SJames Smart ctxp->cpu = rsp->hwqid; 7342b65e182SJames Smart } 7352b65e182SJames Smart } 7362b65e182SJames Smart #endif 737d613b6a7SJames Smart 738d613b6a7SJames Smart /* Sanity check */ 73986c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABTS_RCV) || 74086c67379SJames Smart (ctxp->state == LPFC_NVMET_STE_ABORT)) { 741d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 742d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 74386c67379SJames Smart "6102 IO xri x%x aborted\n", 744d613b6a7SJames Smart ctxp->oxid); 745a5068b46SJames Smart rc = -ENXIO; 746d613b6a7SJames Smart goto aerr; 747d613b6a7SJames Smart } 748d613b6a7SJames Smart 749d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp); 750d613b6a7SJames Smart if (nvmewqeq == NULL) { 751d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 752d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 753d613b6a7SJames Smart "6152 FCP Drop IO x%x: Prep\n", 754d613b6a7SJames Smart ctxp->oxid); 755a5068b46SJames Smart rc = -ENXIO; 756d613b6a7SJames Smart goto aerr; 757d613b6a7SJames Smart } 758d613b6a7SJames Smart 759d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp; 760d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 761d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 762d613b6a7SJames Smart nvmewqeq->iocb_flag |= LPFC_IO_NVMET; 763d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = rsp->hwqid; 764d613b6a7SJames Smart 7652b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n", 7662b65e182SJames Smart ctxp->oxid, rsp->op, rsp->rsplen); 7672b65e182SJames Smart 76861f3d4bfSJames Smart ctxp->flag |= LPFC_NVMET_IO_INP; 769d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq); 770d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 7712b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 772c8a4ce0bSDick Kennedy if (!ctxp->ts_cmd_nvme) 7732b65e182SJames Smart return 0; 7742b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 7752b65e182SJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 7762b65e182SJames Smart else 7772b65e182SJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 7782b65e182SJames Smart #endif 779d613b6a7SJames Smart return 0; 780d613b6a7SJames Smart } 781d613b6a7SJames Smart 782d613b6a7SJames Smart /* Give back resources */ 783d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 784d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 785d613b6a7SJames Smart "6153 FCP Drop IO x%x: Issue: %d\n", 786d613b6a7SJames Smart ctxp->oxid, rc); 787d613b6a7SJames Smart 788d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 789d613b6a7SJames Smart nvmewqeq->context2 = NULL; 790d613b6a7SJames Smart nvmewqeq->context3 = NULL; 791a5068b46SJames Smart rc = -EBUSY; 792d613b6a7SJames Smart aerr: 793a5068b46SJames Smart return rc; 794d613b6a7SJames Smart } 795d613b6a7SJames Smart 796d613b6a7SJames Smart static void 797d613b6a7SJames Smart lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) 798d613b6a7SJames Smart { 799d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tport = targetport->private; 800d613b6a7SJames Smart 801d613b6a7SJames Smart /* release any threads waiting for the unreg to complete */ 802d613b6a7SJames Smart complete(&tport->tport_unreg_done); 803d613b6a7SJames Smart } 804d613b6a7SJames Smart 80519b58d94SJames Smart static void 806a97ec51bSJames Smart lpfc_nvmet_xmt_fcp_abort(struct nvmet_fc_target_port *tgtport, 807a97ec51bSJames Smart struct nvmefc_tgt_fcp_req *req) 808a97ec51bSJames Smart { 809a97ec51bSJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 810a97ec51bSJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 811a97ec51bSJames Smart container_of(req, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 812a97ec51bSJames Smart struct lpfc_hba *phba = ctxp->phba; 81386c67379SJames Smart unsigned long flags; 814a97ec51bSJames Smart 815a97ec51bSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 816ce1b591cSJames Smart "6103 NVMET Abort op: oxri x%x flg x%x ste %d\n", 817ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 818a97ec51bSJames Smart 819ce1b591cSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP ABRT: xri x%x flg x%x ste x%x\n", 820ce1b591cSJames Smart ctxp->oxid, ctxp->flag, ctxp->state); 821a97ec51bSJames Smart 822a97ec51bSJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_abort); 823ce1b591cSJames Smart 82486c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 825c578f6f4SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 82686c67379SJames Smart 82786c67379SJames Smart /* Since iaab/iaar are NOT set, we need to check 82886c67379SJames Smart * if the firmware is in process of aborting IO 82986c67379SJames Smart */ 83086c67379SJames Smart if (ctxp->flag & LPFC_NVMET_XBUSY) { 83186c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 83286c67379SJames Smart return; 83386c67379SJames Smart } 834a97ec51bSJames Smart ctxp->flag |= LPFC_NVMET_ABORT_OP; 835ce1b591cSJames Smart 836ce1b591cSJames Smart /* An state of LPFC_NVMET_STE_RCV means we have just received 837ce1b591cSJames Smart * the NVME command and have not started processing it. 838ce1b591cSJames Smart * (by issuing any IO WQEs on this exchange yet) 839ce1b591cSJames Smart */ 840ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_RCV) 841ce1b591cSJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 842a97ec51bSJames Smart ctxp->oxid); 843a97ec51bSJames Smart else 844ce1b591cSJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 845a97ec51bSJames Smart ctxp->oxid); 84686c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 847a97ec51bSJames Smart } 848a97ec51bSJames Smart 849a97ec51bSJames Smart static void 85019b58d94SJames Smart lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, 85119b58d94SJames Smart struct nvmefc_tgt_fcp_req *rsp) 85219b58d94SJames Smart { 853547077a4SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 85419b58d94SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 85519b58d94SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 85619b58d94SJames Smart struct lpfc_hba *phba = ctxp->phba; 85719b58d94SJames Smart unsigned long flags; 85819b58d94SJames Smart bool aborting = false; 85919b58d94SJames Smart 860ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_DONE && 861ce1b591cSJames Smart ctxp->state != LPFC_NVMET_STE_ABORT) { 862ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 863ce1b591cSJames Smart "6413 NVMET release bad state %d %d oxid x%x\n", 864ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 865ce1b591cSJames Smart } 866ce1b591cSJames Smart 86719b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 86886c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_ABORT_OP) || 86986c67379SJames Smart (ctxp->flag & LPFC_NVMET_XBUSY)) { 87019b58d94SJames Smart aborting = true; 87186c67379SJames Smart /* let the abort path do the real release */ 87286c67379SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 87319b58d94SJames Smart } 87419b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 87519b58d94SJames Smart 8769094367aSArnd Bergmann lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", ctxp->oxid, 8779094367aSArnd Bergmann ctxp->state, aborting); 87819b58d94SJames Smart 879547077a4SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_release); 880547077a4SJames Smart 88186c67379SJames Smart if (aborting) 88286c67379SJames Smart return; 88386c67379SJames Smart 8846c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 88519b58d94SJames Smart } 88619b58d94SJames Smart 88750738420SJames Smart static void 88850738420SJames Smart lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport, 88950738420SJames Smart struct nvmefc_tgt_fcp_req *rsp) 89050738420SJames Smart { 89150738420SJames Smart struct lpfc_nvmet_tgtport *tgtp; 89250738420SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 89350738420SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 89450738420SJames Smart struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; 89550738420SJames Smart struct lpfc_hba *phba = ctxp->phba; 89650738420SJames Smart 89750738420SJames Smart lpfc_nvmeio_data(phba, "NVMET DEFERRCV: xri x%x sz %d CPU %02x\n", 89850738420SJames Smart ctxp->oxid, ctxp->size, smp_processor_id()); 89950738420SJames Smart 90050738420SJames Smart tgtp = phba->targetport->private; 90150738420SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_defer); 90250738420SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 90350738420SJames Smart } 90450738420SJames Smart 905d613b6a7SJames Smart static struct nvmet_fc_target_template lpfc_tgttemplate = { 906d613b6a7SJames Smart .targetport_delete = lpfc_nvmet_targetport_delete, 907d613b6a7SJames Smart .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp, 908d613b6a7SJames Smart .fcp_op = lpfc_nvmet_xmt_fcp_op, 909a97ec51bSJames Smart .fcp_abort = lpfc_nvmet_xmt_fcp_abort, 91019b58d94SJames Smart .fcp_req_release = lpfc_nvmet_xmt_fcp_release, 91150738420SJames Smart .defer_rcv = lpfc_nvmet_defer_rcv, 912d613b6a7SJames Smart 913d613b6a7SJames Smart .max_hw_queues = 1, 914d613b6a7SJames Smart .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 915d613b6a7SJames Smart .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 916d613b6a7SJames Smart .dma_boundary = 0xFFFFFFFF, 917d613b6a7SJames Smart 918d613b6a7SJames Smart /* optional features */ 919d613b6a7SJames Smart .target_features = 0, 920d613b6a7SJames Smart /* sizes of additional private data for data structures */ 921d613b6a7SJames Smart .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport), 922d613b6a7SJames Smart }; 923d613b6a7SJames Smart 92439aa23f9SColin Ian King static void 92566d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(struct lpfc_hba *phba, 92666d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop) 9276c621a22SJames Smart { 9286c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf, *next_ctx_buf; 9296c621a22SJames Smart unsigned long flags; 9306c621a22SJames Smart 93166d7ce93SDick Kennedy spin_lock_irqsave(&infop->nvmet_ctx_list_lock, flags); 932966bb5b7SJames Smart list_for_each_entry_safe(ctx_buf, next_ctx_buf, 93366d7ce93SDick Kennedy &infop->nvmet_ctx_list, list) { 934c4031db7SDan Carpenter spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 9356c621a22SJames Smart list_del_init(&ctx_buf->list); 936c4031db7SDan Carpenter spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 93766d7ce93SDick Kennedy 93866d7ce93SDick Kennedy __lpfc_clear_active_sglq(phba, ctx_buf->sglq->sli4_lxritag); 9396c621a22SJames Smart ctx_buf->sglq->state = SGL_FREED; 9406c621a22SJames Smart ctx_buf->sglq->ndlp = NULL; 9416c621a22SJames Smart 942c4031db7SDan Carpenter spin_lock(&phba->sli4_hba.sgl_list_lock); 9436c621a22SJames Smart list_add_tail(&ctx_buf->sglq->list, 9446c621a22SJames Smart &phba->sli4_hba.lpfc_nvmet_sgl_list); 945c4031db7SDan Carpenter spin_unlock(&phba->sli4_hba.sgl_list_lock); 9466c621a22SJames Smart 9476c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 9486c621a22SJames Smart kfree(ctx_buf->context); 9496c621a22SJames Smart } 95066d7ce93SDick Kennedy spin_unlock_irqrestore(&infop->nvmet_ctx_list_lock, flags); 951966bb5b7SJames Smart } 95266d7ce93SDick Kennedy 95366d7ce93SDick Kennedy static void 95466d7ce93SDick Kennedy lpfc_nvmet_cleanup_io_context(struct lpfc_hba *phba) 95566d7ce93SDick Kennedy { 95666d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 95766d7ce93SDick Kennedy int i, j; 95866d7ce93SDick Kennedy 95966d7ce93SDick Kennedy /* The first context list, MRQ 0 CPU 0 */ 96066d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 96166d7ce93SDick Kennedy if (!infop) 96266d7ce93SDick Kennedy return; 96366d7ce93SDick Kennedy 96466d7ce93SDick Kennedy /* Cycle the the entire CPU context list for every MRQ */ 96566d7ce93SDick Kennedy for (i = 0; i < phba->cfg_nvmet_mrq; i++) { 96666d7ce93SDick Kennedy for (j = 0; j < phba->sli4_hba.num_present_cpu; j++) { 96766d7ce93SDick Kennedy __lpfc_nvmet_clean_io_for_cpu(phba, infop); 96866d7ce93SDick Kennedy infop++; /* next */ 96966d7ce93SDick Kennedy } 97066d7ce93SDick Kennedy } 97166d7ce93SDick Kennedy kfree(phba->sli4_hba.nvmet_ctx_info); 97266d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = NULL; 9736c621a22SJames Smart } 9746c621a22SJames Smart 97539aa23f9SColin Ian King static int 9766c621a22SJames Smart lpfc_nvmet_setup_io_context(struct lpfc_hba *phba) 9776c621a22SJames Smart { 9786c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 9796c621a22SJames Smart struct lpfc_iocbq *nvmewqe; 9806c621a22SJames Smart union lpfc_wqe128 *wqe; 98166d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *last_infop; 98266d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *infop; 98366d7ce93SDick Kennedy int i, j, idx; 9846c621a22SJames Smart 9856c621a22SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME, 9866c621a22SJames Smart "6403 Allocate NVMET resources for %d XRIs\n", 9876c621a22SJames Smart phba->sli4_hba.nvmet_xri_cnt); 9886c621a22SJames Smart 98966d7ce93SDick Kennedy phba->sli4_hba.nvmet_ctx_info = kcalloc( 99066d7ce93SDick Kennedy phba->sli4_hba.num_present_cpu * phba->cfg_nvmet_mrq, 99166d7ce93SDick Kennedy sizeof(struct lpfc_nvmet_ctx_info), GFP_KERNEL); 99266d7ce93SDick Kennedy if (!phba->sli4_hba.nvmet_ctx_info) { 99366d7ce93SDick Kennedy lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 99466d7ce93SDick Kennedy "6419 Failed allocate memory for " 99566d7ce93SDick Kennedy "nvmet context lists\n"); 99666d7ce93SDick Kennedy return -ENOMEM; 99766d7ce93SDick Kennedy } 99866d7ce93SDick Kennedy 99966d7ce93SDick Kennedy /* 100066d7ce93SDick Kennedy * Assuming X CPUs in the system, and Y MRQs, allocate some 100166d7ce93SDick Kennedy * lpfc_nvmet_ctx_info structures as follows: 100266d7ce93SDick Kennedy * 100366d7ce93SDick Kennedy * cpu0/mrq0 cpu1/mrq0 ... cpuX/mrq0 100466d7ce93SDick Kennedy * cpu0/mrq1 cpu1/mrq1 ... cpuX/mrq1 100566d7ce93SDick Kennedy * ... 100666d7ce93SDick Kennedy * cpuX/mrqY cpuX/mrqY ... cpuX/mrqY 100766d7ce93SDick Kennedy * 100866d7ce93SDick Kennedy * Each line represents a MRQ "silo" containing an entry for 100966d7ce93SDick Kennedy * every CPU. 101066d7ce93SDick Kennedy * 101166d7ce93SDick Kennedy * MRQ X is initially assumed to be associated with CPU X, thus 101266d7ce93SDick Kennedy * contexts are initially distributed across all MRQs using 101366d7ce93SDick Kennedy * the MRQ index (N) as follows cpuN/mrqN. When contexts are 101466d7ce93SDick Kennedy * freed, the are freed to the MRQ silo based on the CPU number 101566d7ce93SDick Kennedy * of the IO completion. Thus a context that was allocated for MRQ A 101666d7ce93SDick Kennedy * whose IO completed on CPU B will be freed to cpuB/mrqA. 101766d7ce93SDick Kennedy */ 101866d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 101966d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 102066d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 102166d7ce93SDick Kennedy INIT_LIST_HEAD(&infop->nvmet_ctx_list); 102266d7ce93SDick Kennedy spin_lock_init(&infop->nvmet_ctx_list_lock); 102366d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt = 0; 102466d7ce93SDick Kennedy infop++; 102566d7ce93SDick Kennedy } 102666d7ce93SDick Kennedy } 102766d7ce93SDick Kennedy 102866d7ce93SDick Kennedy /* 102966d7ce93SDick Kennedy * Setup the next CPU context info ptr for each MRQ. 103066d7ce93SDick Kennedy * MRQ 0 will cycle thru CPUs 0 - X separately from 103166d7ce93SDick Kennedy * MRQ 1 cycling thru CPUs 0 - X, and so on. 103266d7ce93SDick Kennedy */ 103366d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 103466d7ce93SDick Kennedy last_infop = lpfc_get_ctx_list(phba, 0, j); 103566d7ce93SDick Kennedy for (i = phba->sli4_hba.num_present_cpu - 1; i >= 0; i--) { 103666d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, i, j); 103766d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu = last_infop; 103866d7ce93SDick Kennedy last_infop = infop; 103966d7ce93SDick Kennedy } 104066d7ce93SDick Kennedy } 104166d7ce93SDick Kennedy 10426c621a22SJames Smart /* For all nvmet xris, allocate resources needed to process a 10436c621a22SJames Smart * received command on a per xri basis. 10446c621a22SJames Smart */ 104566d7ce93SDick Kennedy idx = 0; 10466c621a22SJames Smart for (i = 0; i < phba->sli4_hba.nvmet_xri_cnt; i++) { 10476c621a22SJames Smart ctx_buf = kzalloc(sizeof(*ctx_buf), GFP_KERNEL); 10486c621a22SJames Smart if (!ctx_buf) { 10496c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 10506c621a22SJames Smart "6404 Ran out of memory for NVMET\n"); 10516c621a22SJames Smart return -ENOMEM; 10526c621a22SJames Smart } 10536c621a22SJames Smart 10546c621a22SJames Smart ctx_buf->context = kzalloc(sizeof(*ctx_buf->context), 10556c621a22SJames Smart GFP_KERNEL); 10566c621a22SJames Smart if (!ctx_buf->context) { 10576c621a22SJames Smart kfree(ctx_buf); 10586c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 10596c621a22SJames Smart "6405 Ran out of NVMET " 10606c621a22SJames Smart "context memory\n"); 10616c621a22SJames Smart return -ENOMEM; 10626c621a22SJames Smart } 10636c621a22SJames Smart ctx_buf->context->ctxbuf = ctx_buf; 1064ce1b591cSJames Smart ctx_buf->context->state = LPFC_NVMET_STE_FREE; 10656c621a22SJames Smart 10666c621a22SJames Smart ctx_buf->iocbq = lpfc_sli_get_iocbq(phba); 10676c621a22SJames Smart if (!ctx_buf->iocbq) { 10686c621a22SJames Smart kfree(ctx_buf->context); 10696c621a22SJames Smart kfree(ctx_buf); 10706c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 10716c621a22SJames Smart "6406 Ran out of NVMET iocb/WQEs\n"); 10726c621a22SJames Smart return -ENOMEM; 10736c621a22SJames Smart } 10746c621a22SJames Smart ctx_buf->iocbq->iocb_flag = LPFC_IO_NVMET; 10756c621a22SJames Smart nvmewqe = ctx_buf->iocbq; 10766c621a22SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 10776c621a22SJames Smart /* Initialize WQE */ 10786c621a22SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 10796c621a22SJames Smart /* Word 7 */ 10806c621a22SJames Smart bf_set(wqe_ct, &wqe->generic.wqe_com, SLI4_CT_RPI); 10816c621a22SJames Smart bf_set(wqe_class, &wqe->generic.wqe_com, CLASS3); 10826c621a22SJames Smart /* Word 10 */ 10836c621a22SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 10846c621a22SJames Smart bf_set(wqe_ebde_cnt, &wqe->generic.wqe_com, 0); 10856c621a22SJames Smart bf_set(wqe_qosd, &wqe->generic.wqe_com, 0); 10866c621a22SJames Smart 10876c621a22SJames Smart ctx_buf->iocbq->context1 = NULL; 10886c621a22SJames Smart spin_lock(&phba->sli4_hba.sgl_list_lock); 10896c621a22SJames Smart ctx_buf->sglq = __lpfc_sli_get_nvmet_sglq(phba, ctx_buf->iocbq); 10906c621a22SJames Smart spin_unlock(&phba->sli4_hba.sgl_list_lock); 10916c621a22SJames Smart if (!ctx_buf->sglq) { 10926c621a22SJames Smart lpfc_sli_release_iocbq(phba, ctx_buf->iocbq); 10936c621a22SJames Smart kfree(ctx_buf->context); 10946c621a22SJames Smart kfree(ctx_buf); 10956c621a22SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 10966c621a22SJames Smart "6407 Ran out of NVMET XRIs\n"); 10976c621a22SJames Smart return -ENOMEM; 10986c621a22SJames Smart } 109966d7ce93SDick Kennedy 110066d7ce93SDick Kennedy /* 110166d7ce93SDick Kennedy * Add ctx to MRQidx context list. Our initial assumption 110266d7ce93SDick Kennedy * is MRQidx will be associated with CPUidx. This association 110366d7ce93SDick Kennedy * can change on the fly. 110466d7ce93SDick Kennedy */ 110566d7ce93SDick Kennedy infop = lpfc_get_ctx_list(phba, idx, idx); 110666d7ce93SDick Kennedy spin_lock(&infop->nvmet_ctx_list_lock); 110766d7ce93SDick Kennedy list_add_tail(&ctx_buf->list, &infop->nvmet_ctx_list); 110866d7ce93SDick Kennedy infop->nvmet_ctx_list_cnt++; 110966d7ce93SDick Kennedy spin_unlock(&infop->nvmet_ctx_list_lock); 111066d7ce93SDick Kennedy 111166d7ce93SDick Kennedy /* Spread ctx structures evenly across all MRQs */ 111266d7ce93SDick Kennedy idx++; 111366d7ce93SDick Kennedy if (idx >= phba->cfg_nvmet_mrq) 111466d7ce93SDick Kennedy idx = 0; 11156c621a22SJames Smart } 111666d7ce93SDick Kennedy 111766d7ce93SDick Kennedy infop = phba->sli4_hba.nvmet_ctx_info; 111866d7ce93SDick Kennedy for (j = 0; j < phba->cfg_nvmet_mrq; j++) { 111966d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 112066d7ce93SDick Kennedy lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 112166d7ce93SDick Kennedy "6408 TOTAL NVMET ctx for CPU %d " 112266d7ce93SDick Kennedy "MRQ %d: cnt %d nextcpu %p\n", 112366d7ce93SDick Kennedy i, j, infop->nvmet_ctx_list_cnt, 112466d7ce93SDick Kennedy infop->nvmet_ctx_next_cpu); 112566d7ce93SDick Kennedy infop++; 112666d7ce93SDick Kennedy } 112766d7ce93SDick Kennedy } 11286c621a22SJames Smart return 0; 11296c621a22SJames Smart } 11306c621a22SJames Smart 1131d613b6a7SJames Smart int 1132d613b6a7SJames Smart lpfc_nvmet_create_targetport(struct lpfc_hba *phba) 1133d613b6a7SJames Smart { 1134d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1135d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1136d613b6a7SJames Smart struct nvmet_fc_port_info pinfo; 11376c621a22SJames Smart int error; 1138d613b6a7SJames Smart 1139d613b6a7SJames Smart if (phba->targetport) 1140d613b6a7SJames Smart return 0; 1141d613b6a7SJames Smart 11426c621a22SJames Smart error = lpfc_nvmet_setup_io_context(phba); 11436c621a22SJames Smart if (error) 11446c621a22SJames Smart return error; 11456c621a22SJames Smart 1146d613b6a7SJames Smart memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info)); 1147d613b6a7SJames Smart pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 1148d613b6a7SJames Smart pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 1149d613b6a7SJames Smart pinfo.port_id = vport->fc_myDID; 1150d613b6a7SJames Smart 11514d4c4a4aSJames Smart /* Limit to LPFC_MAX_NVME_SEG_CNT. 11524d4c4a4aSJames Smart * For now need + 1 to get around NVME transport logic. 11534d4c4a4aSJames Smart */ 11544d4c4a4aSJames Smart if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { 11554d4c4a4aSJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, 11564d4c4a4aSJames Smart "6400 Reducing sg segment cnt to %d\n", 11574d4c4a4aSJames Smart LPFC_MAX_NVME_SEG_CNT); 11584d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; 11594d4c4a4aSJames Smart } else { 11604d4c4a4aSJames Smart phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; 11614d4c4a4aSJames Smart } 11624d4c4a4aSJames Smart lpfc_tgttemplate.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 1163d613b6a7SJames Smart lpfc_tgttemplate.max_hw_queues = phba->cfg_nvme_io_channel; 1164f485c18dSDick Kennedy lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP; 1165d613b6a7SJames Smart 11667d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1167d613b6a7SJames Smart error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 1168d613b6a7SJames Smart &phba->pcidev->dev, 1169d613b6a7SJames Smart &phba->targetport); 1170166d7211SJames Smart #else 11716c621a22SJames Smart error = -ENOENT; 1172166d7211SJames Smart #endif 1173d613b6a7SJames Smart if (error) { 1174d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1175d613b6a7SJames Smart "6025 Cannot register NVME targetport " 1176d613b6a7SJames Smart "x%x\n", error); 1177d613b6a7SJames Smart phba->targetport = NULL; 11786c621a22SJames Smart 11796c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 11806c621a22SJames Smart 1181d613b6a7SJames Smart } else { 1182d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *) 1183d613b6a7SJames Smart phba->targetport->private; 1184d613b6a7SJames Smart tgtp->phba = phba; 1185d613b6a7SJames Smart 1186d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1187d613b6a7SJames Smart "6026 Registered NVME " 1188d613b6a7SJames Smart "targetport: %p, private %p " 1189d613b6a7SJames Smart "portnm %llx nodenm %llx\n", 1190d613b6a7SJames Smart phba->targetport, tgtp, 1191d613b6a7SJames Smart pinfo.port_name, pinfo.node_name); 1192d613b6a7SJames Smart 1193d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_in, 0); 1194d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_out, 0); 1195d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_drop, 0); 1196d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_abort, 0); 1197547077a4SJames Smart atomic_set(&tgtp->xmt_ls_abort_cmpl, 0); 1198d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp, 0); 1199d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_drop, 0); 1200d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_error, 0); 1201d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0); 1202d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_in, 0); 1203d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_out, 0); 1204d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_drop, 0); 1205d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_drop, 0); 1206d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read_rsp, 0); 1207d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read, 0); 1208d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_write, 0); 1209d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp, 0); 1210547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_release, 0); 1211d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0); 1212d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_error, 0); 1213d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_drop, 0); 1214547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort, 0); 1215547077a4SJames Smart atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0); 1216547077a4SJames Smart atomic_set(&tgtp->xmt_abort_unsol, 0); 1217547077a4SJames Smart atomic_set(&tgtp->xmt_abort_sol, 0); 1218d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp, 0); 1219d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp_error, 0); 1220d613b6a7SJames Smart } 1221d613b6a7SJames Smart return error; 1222d613b6a7SJames Smart } 1223d613b6a7SJames Smart 1224d613b6a7SJames Smart int 1225d613b6a7SJames Smart lpfc_nvmet_update_targetport(struct lpfc_hba *phba) 1226d613b6a7SJames Smart { 1227d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 1228d613b6a7SJames Smart 1229d613b6a7SJames Smart if (!phba->targetport) 1230d613b6a7SJames Smart return 0; 1231d613b6a7SJames Smart 1232d613b6a7SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 1233d613b6a7SJames Smart "6007 Update NVMET port %p did x%x\n", 1234d613b6a7SJames Smart phba->targetport, vport->fc_myDID); 1235d613b6a7SJames Smart 1236d613b6a7SJames Smart phba->targetport->port_id = vport->fc_myDID; 1237d613b6a7SJames Smart return 0; 1238d613b6a7SJames Smart } 1239d613b6a7SJames Smart 1240318083adSJames Smart /** 1241318083adSJames Smart * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort 1242318083adSJames Smart * @phba: pointer to lpfc hba data structure. 1243318083adSJames Smart * @axri: pointer to the nvmet xri abort wcqe structure. 1244318083adSJames Smart * 1245318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 1246318083adSJames Smart * NVMET aborted xri. 1247318083adSJames Smart **/ 1248318083adSJames Smart void 1249318083adSJames Smart lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba, 1250318083adSJames Smart struct sli4_wcqe_xri_aborted *axri) 1251318083adSJames Smart { 125286c67379SJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 125386c67379SJames Smart uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 125486c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 125586c67379SJames Smart struct lpfc_nodelist *ndlp; 125686c67379SJames Smart unsigned long iflag = 0; 125786c67379SJames Smart int rrq_empty = 0; 125886c67379SJames Smart bool released = false; 125986c67379SJames Smart 126086c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 126186c67379SJames Smart "6317 XB aborted xri x%x rxid x%x\n", xri, rxid); 126286c67379SJames Smart 126386c67379SJames Smart if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) 126486c67379SJames Smart return; 126586c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 126686c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 126786c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 126886c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 126986c67379SJames Smart list) { 12706c621a22SJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 127186c67379SJames Smart continue; 127286c67379SJames Smart 127386c67379SJames Smart /* Check if we already received a free context call 127486c67379SJames Smart * and we have completed processing an abort situation. 127586c67379SJames Smart */ 127686c67379SJames Smart if (ctxp->flag & LPFC_NVMET_CTX_RLS && 127786c67379SJames Smart !(ctxp->flag & LPFC_NVMET_ABORT_OP)) { 127886c67379SJames Smart list_del(&ctxp->list); 127986c67379SJames Smart released = true; 128086c67379SJames Smart } 128186c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_XBUSY; 128286c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 128386c67379SJames Smart 128486c67379SJames Smart rrq_empty = list_empty(&phba->active_rrq_list); 128586c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 128686c67379SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 128786c67379SJames Smart if (ndlp && NLP_CHK_NODE_ACT(ndlp) && 128886c67379SJames Smart (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || 128986c67379SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 129086c67379SJames Smart lpfc_set_rrq_active(phba, ndlp, 12916c621a22SJames Smart ctxp->ctxbuf->sglq->sli4_lxritag, 129286c67379SJames Smart rxid, 1); 129386c67379SJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 129486c67379SJames Smart } 129586c67379SJames Smart 129686c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1297ce1b591cSJames Smart "6318 XB aborted oxid %x flg x%x (%x)\n", 129886c67379SJames Smart ctxp->oxid, ctxp->flag, released); 129986c67379SJames Smart if (released) 13006c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 13016c621a22SJames Smart 130286c67379SJames Smart if (rrq_empty) 130386c67379SJames Smart lpfc_worker_wake_up(phba); 130486c67379SJames Smart return; 130586c67379SJames Smart } 130686c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 130786c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 130886c67379SJames Smart } 130986c67379SJames Smart 131086c67379SJames Smart int 131186c67379SJames Smart lpfc_nvmet_rcv_unsol_abort(struct lpfc_vport *vport, 131286c67379SJames Smart struct fc_frame_header *fc_hdr) 131386c67379SJames Smart 131486c67379SJames Smart { 131586c67379SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 131686c67379SJames Smart struct lpfc_hba *phba = vport->phba; 131786c67379SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp; 131886c67379SJames Smart struct nvmefc_tgt_fcp_req *rsp; 131986c67379SJames Smart uint16_t xri; 132086c67379SJames Smart unsigned long iflag = 0; 132186c67379SJames Smart 132286c67379SJames Smart xri = be16_to_cpu(fc_hdr->fh_ox_id); 132386c67379SJames Smart 132486c67379SJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 132586c67379SJames Smart spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); 132686c67379SJames Smart list_for_each_entry_safe(ctxp, next_ctxp, 132786c67379SJames Smart &phba->sli4_hba.lpfc_abts_nvmet_ctx_list, 132886c67379SJames Smart list) { 13296c621a22SJames Smart if (ctxp->ctxbuf->sglq->sli4_xritag != xri) 133086c67379SJames Smart continue; 133186c67379SJames Smart 133286c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 133386c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 133486c67379SJames Smart 133586c67379SJames Smart spin_lock_irqsave(&ctxp->ctxlock, iflag); 133686c67379SJames Smart ctxp->flag |= LPFC_NVMET_ABTS_RCV; 133786c67379SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, iflag); 133886c67379SJames Smart 133986c67379SJames Smart lpfc_nvmeio_data(phba, 134086c67379SJames Smart "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 134186c67379SJames Smart xri, smp_processor_id(), 0); 134286c67379SJames Smart 134386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 134486c67379SJames Smart "6319 NVMET Rcv ABTS:acc xri x%x\n", xri); 134586c67379SJames Smart 134686c67379SJames Smart rsp = &ctxp->ctx.fcp_req; 134786c67379SJames Smart nvmet_fc_rcv_fcp_abort(phba->targetport, rsp); 134886c67379SJames Smart 134986c67379SJames Smart /* Respond with BA_ACC accordingly */ 135086c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1); 135186c67379SJames Smart return 0; 135286c67379SJames Smart } 135386c67379SJames Smart spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); 135486c67379SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 135586c67379SJames Smart 135686c67379SJames Smart lpfc_nvmeio_data(phba, "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n", 135786c67379SJames Smart xri, smp_processor_id(), 1); 135886c67379SJames Smart 135986c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 136086c67379SJames Smart "6320 NVMET Rcv ABTS:rjt xri x%x\n", xri); 136186c67379SJames Smart 136286c67379SJames Smart /* Respond with BA_RJT accordingly */ 136386c67379SJames Smart lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 0); 136486c67379SJames Smart #endif 1365b06e13c3SJens Axboe return 0; 1366318083adSJames Smart } 1367318083adSJames Smart 1368d613b6a7SJames Smart void 1369d613b6a7SJames Smart lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 1370d613b6a7SJames Smart { 13717d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1372d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1373d613b6a7SJames Smart 1374d613b6a7SJames Smart if (phba->nvmet_support == 0) 1375d613b6a7SJames Smart return; 1376d613b6a7SJames Smart if (phba->targetport) { 1377d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1378d613b6a7SJames Smart init_completion(&tgtp->tport_unreg_done); 1379d613b6a7SJames Smart nvmet_fc_unregister_targetport(phba->targetport); 1380d613b6a7SJames Smart wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); 13816c621a22SJames Smart lpfc_nvmet_cleanup_io_context(phba); 1382d613b6a7SJames Smart } 1383d613b6a7SJames Smart phba->targetport = NULL; 1384166d7211SJames Smart #endif 1385d613b6a7SJames Smart } 1386d613b6a7SJames Smart 1387d613b6a7SJames Smart /** 1388d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer - Process an unsolicited event data buffer 1389d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1390d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1391d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 1392d613b6a7SJames Smart * 1393d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1394d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1395d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1396d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1397d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1398d613b6a7SJames Smart * of the discovery state machine. 1399d613b6a7SJames Smart **/ 1400d613b6a7SJames Smart static void 1401d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1402d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf) 1403d613b6a7SJames Smart { 14047d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 1405d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1406d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 1407d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1408d613b6a7SJames Smart uint32_t *payload; 1409d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 1410d613b6a7SJames Smart 1411d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1412d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1413d613b6a7SJames Smart "6154 LS Drop IO\n"); 14142b65e182SJames Smart oxid = 0; 14152b65e182SJames Smart size = 0; 14162b65e182SJames Smart sid = 0; 1417547077a4SJames Smart ctxp = NULL; 1418d613b6a7SJames Smart goto dropit; 1419d613b6a7SJames Smart } 1420d613b6a7SJames Smart 1421d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1422d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1423d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1424d613b6a7SJames Smart size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); 1425d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1426d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1427d613b6a7SJames Smart 1428d613b6a7SJames Smart ctxp = kzalloc(sizeof(struct lpfc_nvmet_rcv_ctx), GFP_ATOMIC); 1429d613b6a7SJames Smart if (ctxp == NULL) { 1430d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1431d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1432d613b6a7SJames Smart "6155 LS Drop IO x%x: Alloc\n", 1433d613b6a7SJames Smart oxid); 1434d613b6a7SJames Smart dropit: 14352b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: " 14362b65e182SJames Smart "xri x%x sz %d from %06x\n", 14372b65e182SJames Smart oxid, size, sid); 1438d613b6a7SJames Smart if (nvmebuf) 1439d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1440d613b6a7SJames Smart return; 1441d613b6a7SJames Smart } 1442d613b6a7SJames Smart ctxp->phba = phba; 1443d613b6a7SJames Smart ctxp->size = size; 1444d613b6a7SJames Smart ctxp->oxid = oxid; 1445d613b6a7SJames Smart ctxp->sid = sid; 1446d613b6a7SJames Smart ctxp->wqeq = NULL; 1447ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_RCV; 1448ce1b591cSJames Smart ctxp->entry_cnt = 1; 1449d613b6a7SJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 14502b65e182SJames Smart 14512b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RCV: xri x%x sz %d from %06x\n", 14522b65e182SJames Smart oxid, size, sid); 1453d613b6a7SJames Smart /* 1454d613b6a7SJames Smart * The calling sequence should be: 1455d613b6a7SJames Smart * nvmet_fc_rcv_ls_req -> lpfc_nvmet_xmt_ls_rsp/cmp ->_req->done 1456d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp should free the allocated ctxp. 1457d613b6a7SJames Smart */ 1458d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_in); 1459d613b6a7SJames Smart rc = nvmet_fc_rcv_ls_req(phba->targetport, &ctxp->ctx.ls_req, 1460d613b6a7SJames Smart payload, size); 1461d613b6a7SJames Smart 1462d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1463ce1b591cSJames Smart "6037 NVMET Unsol rcv: sz %d rc %d: %08x %08x %08x " 1464ce1b591cSJames Smart "%08x %08x %08x\n", size, rc, 1465d613b6a7SJames Smart *payload, *(payload+1), *(payload+2), 1466d613b6a7SJames Smart *(payload+3), *(payload+4), *(payload+5)); 14672b65e182SJames Smart 1468d613b6a7SJames Smart if (rc == 0) { 1469d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_out); 1470d613b6a7SJames Smart return; 1471d613b6a7SJames Smart } 14722b65e182SJames Smart 14732b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: xri x%x sz %d from %06x\n", 14742b65e182SJames Smart oxid, size, sid); 14752b65e182SJames Smart 1476d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 1477d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1478d613b6a7SJames Smart "6156 LS Drop IO x%x: nvmet_fc_rcv_ls_req %d\n", 1479d613b6a7SJames Smart ctxp->oxid, rc); 1480d613b6a7SJames Smart 1481d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 1482d613b6a7SJames Smart if (nvmebuf) 1483d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1484d613b6a7SJames Smart 1485d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_abort); 1486d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid); 1487166d7211SJames Smart #endif 1488d613b6a7SJames Smart } 1489d613b6a7SJames Smart 149066d7ce93SDick Kennedy static struct lpfc_nvmet_ctxbuf * 149166d7ce93SDick Kennedy lpfc_nvmet_replenish_context(struct lpfc_hba *phba, 149266d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop) 149366d7ce93SDick Kennedy { 14942299e432SDick Kennedy #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 149566d7ce93SDick Kennedy struct lpfc_nvmet_ctxbuf *ctx_buf = NULL; 149666d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *get_infop; 149766d7ce93SDick Kennedy int i; 149866d7ce93SDick Kennedy 149966d7ce93SDick Kennedy /* 150066d7ce93SDick Kennedy * The current_infop for the MRQ a NVME command IU was received 150166d7ce93SDick Kennedy * on is empty. Our goal is to replenish this MRQs context 150266d7ce93SDick Kennedy * list from a another CPUs. 150366d7ce93SDick Kennedy * 150466d7ce93SDick Kennedy * First we need to pick a context list to start looking on. 150566d7ce93SDick Kennedy * nvmet_ctx_start_cpu has available context the last time 150666d7ce93SDick Kennedy * we needed to replenish this CPU where nvmet_ctx_next_cpu 150766d7ce93SDick Kennedy * is just the next sequential CPU for this MRQ. 150866d7ce93SDick Kennedy */ 150966d7ce93SDick Kennedy if (current_infop->nvmet_ctx_start_cpu) 151066d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_start_cpu; 151166d7ce93SDick Kennedy else 151266d7ce93SDick Kennedy get_infop = current_infop->nvmet_ctx_next_cpu; 151366d7ce93SDick Kennedy 151466d7ce93SDick Kennedy for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { 151566d7ce93SDick Kennedy if (get_infop == current_infop) { 151666d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 151766d7ce93SDick Kennedy continue; 151866d7ce93SDick Kennedy } 151966d7ce93SDick Kennedy spin_lock(&get_infop->nvmet_ctx_list_lock); 152066d7ce93SDick Kennedy 152166d7ce93SDick Kennedy /* Just take the entire context list, if there are any */ 152266d7ce93SDick Kennedy if (get_infop->nvmet_ctx_list_cnt) { 152366d7ce93SDick Kennedy list_splice_init(&get_infop->nvmet_ctx_list, 152466d7ce93SDick Kennedy ¤t_infop->nvmet_ctx_list); 152566d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt = 152666d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt - 1; 152766d7ce93SDick Kennedy get_infop->nvmet_ctx_list_cnt = 0; 152866d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 152966d7ce93SDick Kennedy 153066d7ce93SDick Kennedy current_infop->nvmet_ctx_start_cpu = get_infop; 153166d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 153266d7ce93SDick Kennedy ctx_buf, struct lpfc_nvmet_ctxbuf, 153366d7ce93SDick Kennedy list); 153466d7ce93SDick Kennedy return ctx_buf; 153566d7ce93SDick Kennedy } 153666d7ce93SDick Kennedy 153766d7ce93SDick Kennedy /* Otherwise, move on to the next CPU for this MRQ */ 153866d7ce93SDick Kennedy spin_unlock(&get_infop->nvmet_ctx_list_lock); 153966d7ce93SDick Kennedy get_infop = get_infop->nvmet_ctx_next_cpu; 154066d7ce93SDick Kennedy } 154166d7ce93SDick Kennedy 15422299e432SDick Kennedy #endif 154366d7ce93SDick Kennedy /* Nothing found, all contexts for the MRQ are in-flight */ 154466d7ce93SDick Kennedy return NULL; 154566d7ce93SDick Kennedy } 154666d7ce93SDick Kennedy 1547d613b6a7SJames Smart /** 1548d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer 1549d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 155066d7ce93SDick Kennedy * @idx: relative index of MRQ vector 1551d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 1552d613b6a7SJames Smart * 1553d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 1554d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 1555d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 1556d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 1557d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 1558d613b6a7SJames Smart * of the discovery state machine. 1559d613b6a7SJames Smart **/ 1560d613b6a7SJames Smart static void 1561d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba, 156266d7ce93SDick Kennedy uint32_t idx, 1563d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1564d613b6a7SJames Smart uint64_t isr_timestamp) 1565d613b6a7SJames Smart { 1566d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1567d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1568d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 15696c621a22SJames Smart struct lpfc_nvmet_ctxbuf *ctx_buf; 157066d7ce93SDick Kennedy struct lpfc_nvmet_ctx_info *current_infop; 1571d613b6a7SJames Smart uint32_t *payload; 1572a8cf5dfeSJames Smart uint32_t size, oxid, sid, rc, qno; 15736c621a22SJames Smart unsigned long iflag; 157466d7ce93SDick Kennedy int current_cpu; 15752b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 15762b65e182SJames Smart uint32_t id; 15772b65e182SJames Smart #endif 1578d613b6a7SJames Smart 157973626173SArnd Bergmann if (!IS_ENABLED(CONFIG_NVME_TARGET_FC)) 158073626173SArnd Bergmann return; 158173626173SArnd Bergmann 15826c621a22SJames Smart ctx_buf = NULL; 1583d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 1584d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 15856c621a22SJames Smart "6157 NVMET FCP Drop IO\n"); 15862b65e182SJames Smart oxid = 0; 15872b65e182SJames Smart size = 0; 15882b65e182SJames Smart sid = 0; 1589547077a4SJames Smart ctxp = NULL; 1590d613b6a7SJames Smart goto dropit; 1591d613b6a7SJames Smart } 1592d613b6a7SJames Smart 159366d7ce93SDick Kennedy /* 159466d7ce93SDick Kennedy * Get a pointer to the context list for this MRQ based on 159566d7ce93SDick Kennedy * the CPU this MRQ IRQ is associated with. If the CPU association 159666d7ce93SDick Kennedy * changes from our initial assumption, the context list could 159766d7ce93SDick Kennedy * be empty, thus it would need to be replenished with the 159866d7ce93SDick Kennedy * context list from another CPU for this MRQ. 159966d7ce93SDick Kennedy */ 160066d7ce93SDick Kennedy current_cpu = smp_processor_id(); 160166d7ce93SDick Kennedy current_infop = lpfc_get_ctx_list(phba, current_cpu, idx); 160266d7ce93SDick Kennedy spin_lock_irqsave(¤t_infop->nvmet_ctx_list_lock, iflag); 160366d7ce93SDick Kennedy if (current_infop->nvmet_ctx_list_cnt) { 160466d7ce93SDick Kennedy list_remove_head(¤t_infop->nvmet_ctx_list, 16056c621a22SJames Smart ctx_buf, struct lpfc_nvmet_ctxbuf, list); 160666d7ce93SDick Kennedy current_infop->nvmet_ctx_list_cnt--; 1607966bb5b7SJames Smart } else { 160866d7ce93SDick Kennedy ctx_buf = lpfc_nvmet_replenish_context(phba, current_infop); 16096c621a22SJames Smart } 161066d7ce93SDick Kennedy spin_unlock_irqrestore(¤t_infop->nvmet_ctx_list_lock, iflag); 16116c621a22SJames Smart 1612a8cf5dfeSJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 1613a8cf5dfeSJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 1614a8cf5dfeSJames Smart size = nvmebuf->bytes_recv; 1615a8cf5dfeSJames Smart 1616a8cf5dfeSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1617a8cf5dfeSJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV) { 1618a8cf5dfeSJames Smart id = smp_processor_id(); 1619a8cf5dfeSJames Smart if (id < LPFC_CHECK_CPU_CNT) 1620a8cf5dfeSJames Smart phba->cpucheck_rcv_io[id]++; 1621a8cf5dfeSJames Smart } 1622a8cf5dfeSJames Smart #endif 1623a8cf5dfeSJames Smart 1624a8cf5dfeSJames Smart lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d CPU %02x\n", 1625a8cf5dfeSJames Smart oxid, size, smp_processor_id()); 1626a8cf5dfeSJames Smart 16276c621a22SJames Smart if (!ctx_buf) { 1628a8cf5dfeSJames Smart /* Queue this NVME IO to process later */ 1629a8cf5dfeSJames Smart spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag); 1630a8cf5dfeSJames Smart list_add_tail(&nvmebuf->hbuf.list, 1631a8cf5dfeSJames Smart &phba->sli4_hba.lpfc_nvmet_io_wait_list); 1632a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_cnt++; 1633a8cf5dfeSJames Smart phba->sli4_hba.nvmet_io_wait_total++; 1634a8cf5dfeSJames Smart spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, 1635a8cf5dfeSJames Smart iflag); 1636a8cf5dfeSJames Smart 1637a8cf5dfeSJames Smart /* Post a brand new DMA buffer to RQ */ 1638a8cf5dfeSJames Smart qno = nvmebuf->idx; 1639a8cf5dfeSJames Smart lpfc_post_rq_buffer( 1640a8cf5dfeSJames Smart phba, phba->sli4_hba.nvmet_mrq_hdr[qno], 1641a8cf5dfeSJames Smart phba->sli4_hba.nvmet_mrq_data[qno], 1, qno); 1642a8cf5dfeSJames Smart return; 16436c621a22SJames Smart } 1644d613b6a7SJames Smart 1645d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1646d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 1647d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 1648d613b6a7SJames Smart 16496c621a22SJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context; 1650ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_FREE) { 1651ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1652ce1b591cSJames Smart "6414 NVMET Context corrupt %d %d oxid x%x\n", 1653ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 1654ce1b591cSJames Smart } 1655d613b6a7SJames Smart ctxp->wqeq = NULL; 1656d613b6a7SJames Smart ctxp->txrdy = NULL; 1657d613b6a7SJames Smart ctxp->offset = 0; 1658d613b6a7SJames Smart ctxp->phba = phba; 1659d613b6a7SJames Smart ctxp->size = size; 1660d613b6a7SJames Smart ctxp->oxid = oxid; 1661d613b6a7SJames Smart ctxp->sid = sid; 166266d7ce93SDick Kennedy ctxp->idx = idx; 1663d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 1664d613b6a7SJames Smart ctxp->entry_cnt = 1; 1665d613b6a7SJames Smart ctxp->flag = 0; 16666c621a22SJames Smart ctxp->ctxbuf = ctx_buf; 16672b7824d0SJames Smart spin_lock_init(&ctxp->ctxlock); 1668d613b6a7SJames Smart 16692b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1670c8a4ce0bSDick Kennedy if (isr_timestamp) { 16712b65e182SJames Smart ctxp->ts_isr_cmd = isr_timestamp; 16722b65e182SJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 16732b65e182SJames Smart ctxp->ts_nvme_data = 0; 16742b65e182SJames Smart ctxp->ts_data_wqput = 0; 16752b65e182SJames Smart ctxp->ts_isr_data = 0; 16762b65e182SJames Smart ctxp->ts_data_nvme = 0; 16772b65e182SJames Smart ctxp->ts_nvme_status = 0; 16782b65e182SJames Smart ctxp->ts_status_wqput = 0; 16792b65e182SJames Smart ctxp->ts_isr_status = 0; 16802b65e182SJames Smart ctxp->ts_status_nvme = 0; 1681c8a4ce0bSDick Kennedy } else { 1682c8a4ce0bSDick Kennedy ctxp->ts_cmd_nvme = 0; 16832b65e182SJames Smart } 16842b65e182SJames Smart #endif 16852b65e182SJames Smart 1686d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 1687d613b6a7SJames Smart /* 1688d613b6a7SJames Smart * The calling sequence should be: 1689d613b6a7SJames Smart * nvmet_fc_rcv_fcp_req -> lpfc_nvmet_xmt_fcp_op/cmp -> req->done 1690d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 16916c621a22SJames Smart * When we return from nvmet_fc_rcv_fcp_req, all relevant info in 16926c621a22SJames Smart * the NVME command / FC header is stored, so we are free to repost 16936c621a22SJames Smart * the buffer. 1694d613b6a7SJames Smart */ 1695d613b6a7SJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 1696d613b6a7SJames Smart payload, size); 1697d613b6a7SJames Smart 1698d613b6a7SJames Smart /* Process FCP command */ 1699d613b6a7SJames Smart if (rc == 0) { 1700d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 17016c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1702d613b6a7SJames Smart return; 1703d613b6a7SJames Smart } 1704d613b6a7SJames Smart 170550738420SJames Smart /* Processing of FCP command is deferred */ 170650738420SJames Smart if (rc == -EOVERFLOW) { 170750738420SJames Smart lpfc_nvmeio_data(phba, 170850738420SJames Smart "NVMET RCV BUSY: xri x%x sz %d from %06x\n", 170950738420SJames Smart oxid, size, sid); 171050738420SJames Smart /* defer reposting rcv buffer till .defer_rcv callback */ 171150738420SJames Smart ctxp->rqb_buffer = nvmebuf; 171250738420SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 171350738420SJames Smart return; 171450738420SJames Smart } 171550738420SJames Smart 1716d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 1717d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1718547077a4SJames Smart "6159 FCP Drop IO x%x: err x%x: x%x x%x x%x\n", 1719547077a4SJames Smart ctxp->oxid, rc, 1720547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_in), 1721547077a4SJames Smart atomic_read(&tgtp->rcv_fcp_cmd_out), 1722547077a4SJames Smart atomic_read(&tgtp->xmt_fcp_release)); 1723d613b6a7SJames Smart dropit: 17242b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 17252b65e182SJames Smart oxid, size, sid); 1726d613b6a7SJames Smart if (oxid) { 17276c621a22SJames Smart lpfc_nvmet_defer_release(phba, ctxp); 1728d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 17296c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1730d613b6a7SJames Smart return; 1731d613b6a7SJames Smart } 1732d613b6a7SJames Smart 17336c621a22SJames Smart if (ctx_buf) 17346c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctx_buf); 17356c621a22SJames Smart 17366c621a22SJames Smart if (nvmebuf) 17376c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */ 1738d613b6a7SJames Smart } 1739d613b6a7SJames Smart 1740d613b6a7SJames Smart /** 1741d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_event - Process an unsolicited event from an nvme nport 1742d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1743d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1744d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1745d613b6a7SJames Smart * 1746d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1747d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1748d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1749d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer() after properly set up the buffer from the 1750d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1751d613b6a7SJames Smart **/ 1752d613b6a7SJames Smart void 1753d613b6a7SJames Smart lpfc_nvmet_unsol_ls_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1754d613b6a7SJames Smart struct lpfc_iocbq *piocb) 1755d613b6a7SJames Smart { 1756d613b6a7SJames Smart struct lpfc_dmabuf *d_buf; 1757d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf; 1758d613b6a7SJames Smart 1759d613b6a7SJames Smart d_buf = piocb->context2; 1760d613b6a7SJames Smart nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); 1761d613b6a7SJames Smart 1762d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1763d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1764d613b6a7SJames Smart return; 1765d613b6a7SJames Smart } 1766d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(phba, pring, nvmebuf); 1767d613b6a7SJames Smart } 1768d613b6a7SJames Smart 1769d613b6a7SJames Smart /** 1770d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport 1771d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 177266d7ce93SDick Kennedy * @idx: relative index of MRQ vector 1773d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1774d613b6a7SJames Smart * 1775d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1776d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1777d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1778d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the 1779d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1780d613b6a7SJames Smart **/ 1781d613b6a7SJames Smart void 1782d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba, 178366d7ce93SDick Kennedy uint32_t idx, 1784d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1785d613b6a7SJames Smart uint64_t isr_timestamp) 1786d613b6a7SJames Smart { 1787d613b6a7SJames Smart if (phba->nvmet_support == 0) { 17886c621a22SJames Smart lpfc_rq_buf_free(phba, &nvmebuf->hbuf); 1789d613b6a7SJames Smart return; 1790d613b6a7SJames Smart } 179166d7ce93SDick Kennedy lpfc_nvmet_unsol_fcp_buffer(phba, idx, nvmebuf, 1792d613b6a7SJames Smart isr_timestamp); 1793d613b6a7SJames Smart } 1794d613b6a7SJames Smart 1795d613b6a7SJames Smart /** 1796d613b6a7SJames Smart * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure 1797d613b6a7SJames Smart * @phba: pointer to a host N_Port data structure. 1798d613b6a7SJames Smart * @ctxp: Context info for NVME LS Request 1799d613b6a7SJames Smart * @rspbuf: DMA buffer of NVME command. 1800d613b6a7SJames Smart * @rspsize: size of the NVME command. 1801d613b6a7SJames Smart * 1802d613b6a7SJames Smart * This routine is used for allocating a lpfc-WQE data structure from 1803d613b6a7SJames Smart * the driver lpfc-WQE free-list and prepare the WQE with the parameters 1804d613b6a7SJames Smart * passed into the routine for discovery state machine to issue an Extended 1805d613b6a7SJames Smart * Link Service (NVME) commands. It is a generic lpfc-WQE allocation 1806d613b6a7SJames Smart * and preparation routine that is used by all the discovery state machine 1807d613b6a7SJames Smart * routines and the NVME command-specific fields will be later set up by 1808d613b6a7SJames Smart * the individual discovery machine routines after calling this routine 1809d613b6a7SJames Smart * allocating and preparing a generic WQE data structure. It fills in the 1810d613b6a7SJames Smart * Buffer Descriptor Entries (BDEs), allocates buffers for both command 1811d613b6a7SJames Smart * payload and response payload (if expected). The reference count on the 1812d613b6a7SJames Smart * ndlp is incremented by 1 and the reference to the ndlp is put into 1813d613b6a7SJames Smart * context1 of the WQE data structure for this WQE to hold the ndlp 1814d613b6a7SJames Smart * reference for the command's callback function to access later. 1815d613b6a7SJames Smart * 1816d613b6a7SJames Smart * Return code 1817d613b6a7SJames Smart * Pointer to the newly allocated/prepared nvme wqe data structure 1818d613b6a7SJames Smart * NULL - when nvme wqe data structure allocation/preparation failed 1819d613b6a7SJames Smart **/ 1820d613b6a7SJames Smart static struct lpfc_iocbq * 1821d613b6a7SJames Smart lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba, 1822d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1823d613b6a7SJames Smart dma_addr_t rspbuf, uint16_t rspsize) 1824d613b6a7SJames Smart { 1825d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1826d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1827d613b6a7SJames Smart union lpfc_wqe *wqe; 1828d613b6a7SJames Smart 1829d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1830d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1831ce1b591cSJames Smart "6104 NVMET prep LS wqe: link err: " 1832ce1b591cSJames Smart "NPORT x%x oxid:x%x ste %d\n", 1833ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1834d613b6a7SJames Smart return NULL; 1835d613b6a7SJames Smart } 1836d613b6a7SJames Smart 1837d613b6a7SJames Smart /* Allocate buffer for command wqe */ 1838d613b6a7SJames Smart nvmewqe = lpfc_sli_get_iocbq(phba); 1839d613b6a7SJames Smart if (nvmewqe == NULL) { 1840d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1841ce1b591cSJames Smart "6105 NVMET prep LS wqe: No WQE: " 1842ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 1843ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1844d613b6a7SJames Smart return NULL; 1845d613b6a7SJames Smart } 1846d613b6a7SJames Smart 1847d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1848d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1849d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1850d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1851d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1852ce1b591cSJames Smart "6106 NVMET prep LS wqe: No ndlp: " 1853ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 1854ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1855d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1856d613b6a7SJames Smart } 1857d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1858d613b6a7SJames Smart 1859d613b6a7SJames Smart /* prevent preparing wqe with NULL ndlp reference */ 1860d613b6a7SJames Smart nvmewqe->context1 = lpfc_nlp_get(ndlp); 1861d613b6a7SJames Smart if (nvmewqe->context1 == NULL) 1862d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1863d613b6a7SJames Smart nvmewqe->context2 = ctxp; 1864d613b6a7SJames Smart 1865d613b6a7SJames Smart wqe = &nvmewqe->wqe; 1866d613b6a7SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 1867d613b6a7SJames Smart 1868d613b6a7SJames Smart /* Words 0 - 2 */ 1869d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1870d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize; 1871d613b6a7SJames Smart wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf)); 1872d613b6a7SJames Smart wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf)); 1873d613b6a7SJames Smart 1874d613b6a7SJames Smart /* Word 3 */ 1875d613b6a7SJames Smart 1876d613b6a7SJames Smart /* Word 4 */ 1877d613b6a7SJames Smart 1878d613b6a7SJames Smart /* Word 5 */ 1879d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 1880d613b6a7SJames Smart bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 1881d613b6a7SJames Smart bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 18828b361639SJames Smart bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP); 1883d613b6a7SJames Smart bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 1884d613b6a7SJames Smart 1885d613b6a7SJames Smart /* Word 6 */ 1886d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, 1887d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1888d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag); 1889d613b6a7SJames Smart 1890d613b6a7SJames Smart /* Word 7 */ 1891d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com, 1892d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 1893d613b6a7SJames Smart bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI); 1894d613b6a7SJames Smart bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3); 1895d613b6a7SJames Smart bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); 1896d613b6a7SJames Smart 1897d613b6a7SJames Smart /* Word 8 */ 1898d613b6a7SJames Smart wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag; 1899d613b6a7SJames Smart 1900d613b6a7SJames Smart /* Word 9 */ 1901d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag); 1902d613b6a7SJames Smart /* Needs to be set by caller */ 1903d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid); 1904d613b6a7SJames Smart 1905d613b6a7SJames Smart /* Word 10 */ 1906d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); 1907d613b6a7SJames Smart bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 1908d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, 1909d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1910d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); 1911d613b6a7SJames Smart 1912d613b6a7SJames Smart /* Word 11 */ 1913d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com, 1914d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1915d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com, 1916d613b6a7SJames Smart OTHER_COMMAND); 1917d613b6a7SJames Smart 1918d613b6a7SJames Smart /* Word 12 */ 1919d613b6a7SJames Smart wqe->xmit_sequence.xmit_len = rspsize; 1920d613b6a7SJames Smart 1921d613b6a7SJames Smart nvmewqe->retry = 1; 1922d613b6a7SJames Smart nvmewqe->vport = phba->pport; 1923d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 1924d613b6a7SJames Smart nvmewqe->iocb_flag |= LPFC_IO_NVME_LS; 1925d613b6a7SJames Smart 1926ce1b591cSJames Smart /* Xmit NVMET response to remote NPORT <did> */ 1927d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1928ce1b591cSJames Smart "6039 Xmit NVMET LS response to remote " 1929d613b6a7SJames Smart "NPORT x%x iotag:x%x oxid:x%x size:x%x\n", 1930d613b6a7SJames Smart ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid, 1931d613b6a7SJames Smart rspsize); 1932d613b6a7SJames Smart return nvmewqe; 1933d613b6a7SJames Smart 1934d613b6a7SJames Smart nvme_wqe_free_wqeq_exit: 1935d613b6a7SJames Smart nvmewqe->context2 = NULL; 1936d613b6a7SJames Smart nvmewqe->context3 = NULL; 1937d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, nvmewqe); 1938d613b6a7SJames Smart return NULL; 1939d613b6a7SJames Smart } 1940d613b6a7SJames Smart 1941d613b6a7SJames Smart 1942d613b6a7SJames Smart static struct lpfc_iocbq * 1943d613b6a7SJames Smart lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba, 1944d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 1945d613b6a7SJames Smart { 1946d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp = &ctxp->ctx.fcp_req; 1947d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1948d613b6a7SJames Smart struct sli4_sge *sgl; 1949d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1950d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1951d613b6a7SJames Smart struct scatterlist *sgel; 1952d613b6a7SJames Smart union lpfc_wqe128 *wqe; 1953d613b6a7SJames Smart uint32_t *txrdy; 1954d613b6a7SJames Smart dma_addr_t physaddr; 1955d613b6a7SJames Smart int i, cnt; 1956d613b6a7SJames Smart int xc = 1; 1957d613b6a7SJames Smart 1958d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1959d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1960ce1b591cSJames Smart "6107 NVMET prep FCP wqe: link err:" 1961ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 1962ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1963d613b6a7SJames Smart return NULL; 1964d613b6a7SJames Smart } 1965d613b6a7SJames Smart 1966d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1967d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1968d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1969d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1970d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1971ce1b591cSJames Smart "6108 NVMET prep FCP wqe: no ndlp: " 1972ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d\n", 1973ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1974d613b6a7SJames Smart return NULL; 1975d613b6a7SJames Smart } 1976d613b6a7SJames Smart 19774d4c4a4aSJames Smart if (rsp->sg_cnt > phba->cfg_nvme_seg_cnt) { 1978d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1979ce1b591cSJames Smart "6109 NVMET prep FCP wqe: seg cnt err: " 1980ce1b591cSJames Smart "NPORT x%x oxid x%x ste %d cnt %d\n", 1981ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state, 1982ce1b591cSJames Smart phba->cfg_nvme_seg_cnt); 1983d613b6a7SJames Smart return NULL; 1984d613b6a7SJames Smart } 1985d613b6a7SJames Smart 1986d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1987d613b6a7SJames Smart nvmewqe = ctxp->wqeq; 1988d613b6a7SJames Smart if (nvmewqe == NULL) { 1989d613b6a7SJames Smart /* Allocate buffer for command wqe */ 19906c621a22SJames Smart nvmewqe = ctxp->ctxbuf->iocbq; 1991d613b6a7SJames Smart if (nvmewqe == NULL) { 1992d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1993ce1b591cSJames Smart "6110 NVMET prep FCP wqe: No " 1994ce1b591cSJames Smart "WQE: NPORT x%x oxid x%x ste %d\n", 1995ce1b591cSJames Smart ctxp->sid, ctxp->oxid, ctxp->state); 1996d613b6a7SJames Smart return NULL; 1997d613b6a7SJames Smart } 1998d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1999d613b6a7SJames Smart xc = 0; /* create new XRI */ 2000d613b6a7SJames Smart nvmewqe->sli4_lxritag = NO_XRI; 2001d613b6a7SJames Smart nvmewqe->sli4_xritag = NO_XRI; 2002d613b6a7SJames Smart } 2003d613b6a7SJames Smart 2004d613b6a7SJames Smart /* Sanity check */ 2005d613b6a7SJames Smart if (((ctxp->state == LPFC_NVMET_STE_RCV) && 2006d613b6a7SJames Smart (ctxp->entry_cnt == 1)) || 2007ce1b591cSJames Smart (ctxp->state == LPFC_NVMET_STE_DATA)) { 2008d613b6a7SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 2009d613b6a7SJames Smart } else { 2010d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2011ce1b591cSJames Smart "6111 Wrong state NVMET FCP: %d cnt %d\n", 2012ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt); 2013d613b6a7SJames Smart return NULL; 2014d613b6a7SJames Smart } 2015d613b6a7SJames Smart 20166c621a22SJames Smart sgl = (struct sli4_sge *)ctxp->ctxbuf->sglq->sgl; 2017d613b6a7SJames Smart switch (rsp->op) { 2018d613b6a7SJames Smart case NVMET_FCOP_READDATA: 2019d613b6a7SJames Smart case NVMET_FCOP_READDATA_RSP: 2020d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 2021d613b6a7SJames Smart sgel = &rsp->sg[0]; 2022d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 2023d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2024d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel); 2025d613b6a7SJames Smart wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr)); 2026d613b6a7SJames Smart wqe->fcp_tsend.bde.addrHigh = 2027d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2028d613b6a7SJames Smart 2029d613b6a7SJames Smart /* Word 3 */ 2030d613b6a7SJames Smart wqe->fcp_tsend.payload_offset_len = 0; 2031d613b6a7SJames Smart 2032d613b6a7SJames Smart /* Word 4 */ 2033d613b6a7SJames Smart wqe->fcp_tsend.relative_offset = ctxp->offset; 2034d613b6a7SJames Smart 2035d613b6a7SJames Smart /* Word 5 */ 2036d613b6a7SJames Smart 2037d613b6a7SJames Smart /* Word 6 */ 2038d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com, 2039d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2040d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com, 2041d613b6a7SJames Smart nvmewqe->sli4_xritag); 2042d613b6a7SJames Smart 2043d613b6a7SJames Smart /* Word 7 */ 2044c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_tsend.wqe_com, 1); 2045d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE); 2046d613b6a7SJames Smart 2047d613b6a7SJames Smart /* Word 8 */ 2048d613b6a7SJames Smart wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag; 2049d613b6a7SJames Smart 2050d613b6a7SJames Smart /* Word 9 */ 2051d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag); 2052d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid); 2053d613b6a7SJames Smart 2054d613b6a7SJames Smart /* Word 10 */ 2055d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 2056d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1); 2057d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE); 2058d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com, 2059d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2060d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->fcp_tsend.wqe_com, 0); 2061d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, xc); 2062d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 2063d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2064d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_tsend.wqe_com, 1); 2065d613b6a7SJames Smart 2066d613b6a7SJames Smart /* Word 11 */ 2067d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com, 2068d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2069d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com, 2070d613b6a7SJames Smart FCP_COMMAND_TSEND); 2071d613b6a7SJames Smart 2072d613b6a7SJames Smart /* Word 12 */ 2073d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2074d613b6a7SJames Smart 2075d613b6a7SJames Smart /* Setup 2 SKIP SGEs */ 2076d613b6a7SJames Smart sgl->addr_hi = 0; 2077d613b6a7SJames Smart sgl->addr_lo = 0; 2078d613b6a7SJames Smart sgl->word2 = 0; 2079d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2080d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2081d613b6a7SJames Smart sgl->sge_len = 0; 2082d613b6a7SJames Smart sgl++; 2083d613b6a7SJames Smart sgl->addr_hi = 0; 2084d613b6a7SJames Smart sgl->addr_lo = 0; 2085d613b6a7SJames Smart sgl->word2 = 0; 2086d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2087d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2088d613b6a7SJames Smart sgl->sge_len = 0; 2089d613b6a7SJames Smart sgl++; 2090d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 2091d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read_rsp); 2092d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1); 2093d613b6a7SJames Smart if ((ndlp->nlp_flag & NLP_SUPPRESS_RSP) && 2094d613b6a7SJames Smart (rsp->rsplen == 12)) { 2095d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 1); 2096d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 2097d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 2098d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 2099d613b6a7SJames Smart } else { 2100d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2101d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1); 2102d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1); 2103d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 2104d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2105d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, 2106d613b6a7SJames Smart rsp->rsplen); 2107d613b6a7SJames Smart } 2108d613b6a7SJames Smart } else { 2109d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read); 2110d613b6a7SJames Smart 2111d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2112d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 2113d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 2114d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0); 2115d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 2116d613b6a7SJames Smart } 2117d613b6a7SJames Smart break; 2118d613b6a7SJames Smart 2119d613b6a7SJames Smart case NVMET_FCOP_WRITEDATA: 2120d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 2121771db5c0SRomain Perier txrdy = dma_pool_alloc(phba->txrdy_payload_pool, 2122d613b6a7SJames Smart GFP_KERNEL, &physaddr); 2123d613b6a7SJames Smart if (!txrdy) { 2124d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2125d613b6a7SJames Smart "6041 Bad txrdy buffer: oxid x%x\n", 2126d613b6a7SJames Smart ctxp->oxid); 2127d613b6a7SJames Smart return NULL; 2128d613b6a7SJames Smart } 2129d613b6a7SJames Smart ctxp->txrdy = txrdy; 2130d613b6a7SJames Smart ctxp->txrdy_phys = physaddr; 2131d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2132d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeSize = TXRDY_PAYLOAD_LEN; 2133d613b6a7SJames Smart wqe->fcp_treceive.bde.addrLow = 2134d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 2135d613b6a7SJames Smart wqe->fcp_treceive.bde.addrHigh = 2136d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2137d613b6a7SJames Smart 2138d613b6a7SJames Smart /* Word 3 */ 2139d613b6a7SJames Smart wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN; 2140d613b6a7SJames Smart 2141d613b6a7SJames Smart /* Word 4 */ 2142d613b6a7SJames Smart wqe->fcp_treceive.relative_offset = ctxp->offset; 2143d613b6a7SJames Smart 2144d613b6a7SJames Smart /* Word 5 */ 2145d613b6a7SJames Smart 2146d613b6a7SJames Smart /* Word 6 */ 2147d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com, 2148d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2149d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com, 2150d613b6a7SJames Smart nvmewqe->sli4_xritag); 2151d613b6a7SJames Smart 2152d613b6a7SJames Smart /* Word 7 */ 2153c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_treceive.wqe_com, 1); 2154d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0); 2155d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com, 2156d613b6a7SJames Smart CMD_FCP_TRECEIVE64_WQE); 2157d613b6a7SJames Smart 2158d613b6a7SJames Smart /* Word 8 */ 2159d613b6a7SJames Smart wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag; 2160d613b6a7SJames Smart 2161d613b6a7SJames Smart /* Word 9 */ 2162d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag); 2163d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid); 2164d613b6a7SJames Smart 2165d613b6a7SJames Smart /* Word 10 */ 2166d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 2167d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1); 2168d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ); 2169d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com, 2170d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2171d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, xc); 2172d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0); 2173d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0); 2174d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0); 2175d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 2176d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2177d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_treceive.wqe_com, 1); 2178d613b6a7SJames Smart 2179d613b6a7SJames Smart /* Word 11 */ 2180d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com, 2181d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2182d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com, 2183d613b6a7SJames Smart FCP_COMMAND_TRECEIVE); 2184d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2185d613b6a7SJames Smart 2186d613b6a7SJames Smart /* Word 12 */ 2187d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 2188d613b6a7SJames Smart 2189d613b6a7SJames Smart /* Setup 1 TXRDY and 1 SKIP SGE */ 2190d613b6a7SJames Smart txrdy[0] = 0; 2191d613b6a7SJames Smart txrdy[1] = cpu_to_be32(rsp->transfer_length); 2192d613b6a7SJames Smart txrdy[2] = 0; 2193d613b6a7SJames Smart 2194d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 2195d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 2196d613b6a7SJames Smart sgl->word2 = 0; 2197d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 2198d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2199d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(TXRDY_PAYLOAD_LEN); 2200d613b6a7SJames Smart sgl++; 2201d613b6a7SJames Smart sgl->addr_hi = 0; 2202d613b6a7SJames Smart sgl->addr_lo = 0; 2203d613b6a7SJames Smart sgl->word2 = 0; 2204d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 2205d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2206d613b6a7SJames Smart sgl->sge_len = 0; 2207d613b6a7SJames Smart sgl++; 2208d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_write); 2209d613b6a7SJames Smart break; 2210d613b6a7SJames Smart 2211d613b6a7SJames Smart case NVMET_FCOP_RSP: 2212d613b6a7SJames Smart /* Words 0 - 2 */ 2213d613b6a7SJames Smart physaddr = rsp->rspdma; 2214d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2215d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 2216d613b6a7SJames Smart wqe->fcp_trsp.bde.addrLow = 2217d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 2218d613b6a7SJames Smart wqe->fcp_trsp.bde.addrHigh = 2219d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 2220d613b6a7SJames Smart 2221d613b6a7SJames Smart /* Word 3 */ 2222d613b6a7SJames Smart wqe->fcp_trsp.response_len = rsp->rsplen; 2223d613b6a7SJames Smart 2224d613b6a7SJames Smart /* Word 4 */ 2225d613b6a7SJames Smart wqe->fcp_trsp.rsvd_4_5[0] = 0; 2226d613b6a7SJames Smart 2227d613b6a7SJames Smart 2228d613b6a7SJames Smart /* Word 5 */ 2229d613b6a7SJames Smart 2230d613b6a7SJames Smart /* Word 6 */ 2231d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com, 2232d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2233d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com, 2234d613b6a7SJames Smart nvmewqe->sli4_xritag); 2235d613b6a7SJames Smart 2236d613b6a7SJames Smart /* Word 7 */ 2237c6e0c925SDick Kennedy bf_set(wqe_pu, &wqe->fcp_trsp.wqe_com, 0); 2238d613b6a7SJames Smart bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1); 2239d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE); 2240d613b6a7SJames Smart 2241d613b6a7SJames Smart /* Word 8 */ 2242d613b6a7SJames Smart wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag; 2243d613b6a7SJames Smart 2244d613b6a7SJames Smart /* Word 9 */ 2245d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag); 2246d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid); 2247d613b6a7SJames Smart 2248d613b6a7SJames Smart /* Word 10 */ 2249d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 2250d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 0); 2251d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_WRITE); 2252d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com, 2253d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD3); 2254d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, xc); 2255d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 2256d613b6a7SJames Smart if (phba->cfg_nvme_oas) 2257d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_trsp.wqe_com, 1); 2258d613b6a7SJames Smart 2259d613b6a7SJames Smart /* Word 11 */ 2260d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com, 2261d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2262d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com, 2263d613b6a7SJames Smart FCP_COMMAND_TRSP); 2264d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 2265d613b6a7SJames Smart 2266d613b6a7SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 2267d613b6a7SJames Smart /* Good response - all zero's on wire */ 2268d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0); 2269d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0); 2270d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0); 2271d613b6a7SJames Smart } else { 2272d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1); 2273d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1); 2274d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 2275d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 2276d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen); 2277d613b6a7SJames Smart } 2278d613b6a7SJames Smart 2279d613b6a7SJames Smart /* Use rspbuf, NOT sg list */ 2280d613b6a7SJames Smart rsp->sg_cnt = 0; 2281d613b6a7SJames Smart sgl->word2 = 0; 2282d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp); 2283d613b6a7SJames Smart break; 2284d613b6a7SJames Smart 2285d613b6a7SJames Smart default: 2286d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 2287d613b6a7SJames Smart "6064 Unknown Rsp Op %d\n", 2288d613b6a7SJames Smart rsp->op); 2289d613b6a7SJames Smart return NULL; 2290d613b6a7SJames Smart } 2291d613b6a7SJames Smart 2292d613b6a7SJames Smart nvmewqe->retry = 1; 2293d613b6a7SJames Smart nvmewqe->vport = phba->pport; 2294d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 2295d613b6a7SJames Smart nvmewqe->context1 = ndlp; 2296d613b6a7SJames Smart 2297d613b6a7SJames Smart for (i = 0; i < rsp->sg_cnt; i++) { 2298d613b6a7SJames Smart sgel = &rsp->sg[i]; 2299d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 2300d613b6a7SJames Smart cnt = sg_dma_len(sgel); 2301d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 2302d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 2303d613b6a7SJames Smart sgl->word2 = 0; 2304d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 2305d613b6a7SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset); 2306d613b6a7SJames Smart if ((i+1) == rsp->sg_cnt) 2307d613b6a7SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 2308d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 2309d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(cnt); 2310d613b6a7SJames Smart sgl++; 2311d613b6a7SJames Smart ctxp->offset += cnt; 2312d613b6a7SJames Smart } 2313ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 2314ce1b591cSJames Smart ctxp->entry_cnt++; 2315d613b6a7SJames Smart return nvmewqe; 2316d613b6a7SJames Smart } 2317d613b6a7SJames Smart 2318d613b6a7SJames Smart /** 2319d613b6a7SJames Smart * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS 2320d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2321d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2322d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2323d613b6a7SJames Smart * 2324d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2325d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 2326d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2327d613b6a7SJames Smart **/ 2328d613b6a7SJames Smart static void 2329d613b6a7SJames Smart lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2330d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2331d613b6a7SJames Smart { 2332d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2333d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2334d613b6a7SJames Smart uint32_t status, result; 233519b58d94SJames Smart unsigned long flags; 233619b58d94SJames Smart bool released = false; 2337d613b6a7SJames Smart 2338d613b6a7SJames Smart ctxp = cmdwqe->context2; 2339d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2340d613b6a7SJames Smart result = wcqe->parameter; 2341d613b6a7SJames Smart 2342d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2343547077a4SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 2344547077a4SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 2345d613b6a7SJames Smart 2346d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 234786c67379SJames Smart 234886c67379SJames Smart /* Check if we already received a free context call 234986c67379SJames Smart * and we have completed processing an abort situation. 235086c67379SJames Smart */ 235119b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 235286c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 235386c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 235486c67379SJames Smart list_del(&ctxp->list); 235519b58d94SJames Smart released = true; 235686c67379SJames Smart } 235719b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 235819b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 2359547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 236019b58d94SJames Smart 2361e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 236286c67379SJames Smart "6165 ABORT cmpl: xri x%x flg x%x (%d) " 236386c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 236486c67379SJames Smart ctxp->oxid, ctxp->flag, released, 236586c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 236686c67379SJames Smart result, wcqe->word3); 236786c67379SJames Smart 23686c621a22SJames Smart cmdwqe->context2 = NULL; 23696c621a22SJames Smart cmdwqe->context3 = NULL; 237019b58d94SJames Smart /* 237119b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 237219b58d94SJames Smart * will be recycled by transport release call. 237319b58d94SJames Smart */ 237419b58d94SJames Smart if (released) 23756c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 2376d613b6a7SJames Smart 23776c621a22SJames Smart /* This is the iocbq for the abort, not the command */ 2378d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 237986c67379SJames Smart 238086c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 238186c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 238286c67379SJames Smart * should have been called already. 238386c67379SJames Smart */ 2384d613b6a7SJames Smart } 2385d613b6a7SJames Smart 2386d613b6a7SJames Smart /** 238786c67379SJames Smart * lpfc_nvmet_unsol_fcp_abort_cmp - Completion handler for ABTS 2388d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2389d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2390d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2391d613b6a7SJames Smart * 2392d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2393d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 2394d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2395d613b6a7SJames Smart **/ 2396d613b6a7SJames Smart static void 239786c67379SJames Smart lpfc_nvmet_unsol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2398d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2399d613b6a7SJames Smart { 2400d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2401d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 240219b58d94SJames Smart unsigned long flags; 2403d613b6a7SJames Smart uint32_t status, result; 240419b58d94SJames Smart bool released = false; 2405d613b6a7SJames Smart 2406d613b6a7SJames Smart ctxp = cmdwqe->context2; 2407d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2408d613b6a7SJames Smart result = wcqe->parameter; 2409d613b6a7SJames Smart 241086c67379SJames Smart if (!ctxp) { 241186c67379SJames Smart /* if context is clear, related io alrady complete */ 2412d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 241386c67379SJames Smart "6070 ABTS cmpl: WCQE: %08x %08x %08x %08x\n", 241486c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 2415d613b6a7SJames Smart result, wcqe->word3); 241686c67379SJames Smart return; 241786c67379SJames Smart } 2418d613b6a7SJames Smart 241978e1d200SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 242078e1d200SJames Smart if (ctxp->flag & LPFC_NVMET_ABORT_OP) 242178e1d200SJames Smart atomic_inc(&tgtp->xmt_fcp_abort_cmpl); 242278e1d200SJames Smart 2423d613b6a7SJames Smart /* Sanity check */ 2424d613b6a7SJames Smart if (ctxp->state != LPFC_NVMET_STE_ABORT) { 2425d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 242686c67379SJames Smart "6112 ABTS Wrong state:%d oxid x%x\n", 2427d613b6a7SJames Smart ctxp->state, ctxp->oxid); 2428d613b6a7SJames Smart } 242986c67379SJames Smart 243086c67379SJames Smart /* Check if we already received a free context call 243186c67379SJames Smart * and we have completed processing an abort situation. 243286c67379SJames Smart */ 2433d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 243419b58d94SJames Smart spin_lock_irqsave(&ctxp->ctxlock, flags); 243586c67379SJames Smart if ((ctxp->flag & LPFC_NVMET_CTX_RLS) && 243686c67379SJames Smart !(ctxp->flag & LPFC_NVMET_XBUSY)) { 243786c67379SJames Smart list_del(&ctxp->list); 243819b58d94SJames Smart released = true; 243986c67379SJames Smart } 244019b58d94SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 244119b58d94SJames Smart spin_unlock_irqrestore(&ctxp->ctxlock, flags); 2442547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 244319b58d94SJames Smart 244486c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 244586c67379SJames Smart "6316 ABTS cmpl xri x%x flg x%x (%x) " 244686c67379SJames Smart "WCQE: %08x %08x %08x %08x\n", 244786c67379SJames Smart ctxp->oxid, ctxp->flag, released, 244886c67379SJames Smart wcqe->word0, wcqe->total_data_placed, 244986c67379SJames Smart result, wcqe->word3); 24506c621a22SJames Smart 24516c621a22SJames Smart cmdwqe->context2 = NULL; 24526c621a22SJames Smart cmdwqe->context3 = NULL; 245319b58d94SJames Smart /* 245419b58d94SJames Smart * if transport has released ctx, then can reuse it. Otherwise, 245519b58d94SJames Smart * will be recycled by transport release call. 245619b58d94SJames Smart */ 245719b58d94SJames Smart if (released) 24586c621a22SJames Smart lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); 245986c67379SJames Smart 246086c67379SJames Smart /* Since iaab/iaar are NOT set, there is no work left. 246186c67379SJames Smart * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted 246286c67379SJames Smart * should have been called already. 246386c67379SJames Smart */ 2464d613b6a7SJames Smart } 2465d613b6a7SJames Smart 2466d613b6a7SJames Smart /** 2467d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS 2468d613b6a7SJames Smart * @phba: Pointer to HBA context object. 2469d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 2470d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 2471d613b6a7SJames Smart * 2472d613b6a7SJames Smart * The function is called from SLI ring event handler with no 2473d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for LS cmds 2474d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 2475d613b6a7SJames Smart **/ 2476d613b6a7SJames Smart static void 2477d613b6a7SJames Smart lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 2478d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 2479d613b6a7SJames Smart { 2480d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 2481d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2482d613b6a7SJames Smart uint32_t status, result; 2483d613b6a7SJames Smart 2484d613b6a7SJames Smart ctxp = cmdwqe->context2; 2485d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 2486d613b6a7SJames Smart result = wcqe->parameter; 2487d613b6a7SJames Smart 2488d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2489547077a4SJames Smart atomic_inc(&tgtp->xmt_ls_abort_cmpl); 2490d613b6a7SJames Smart 2491d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2492d613b6a7SJames Smart "6083 Abort cmpl: ctx %p WCQE:%08x %08x %08x %08x\n", 2493d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 2494d613b6a7SJames Smart result, wcqe->word3); 2495d613b6a7SJames Smart 2496ce1b591cSJames Smart if (!ctxp) { 2497ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2498ce1b591cSJames Smart "6415 NVMET LS Abort No ctx: WCQE: " 2499ce1b591cSJames Smart "%08x %08x %08x %08x\n", 2500ce1b591cSJames Smart wcqe->word0, wcqe->total_data_placed, 2501ce1b591cSJames Smart result, wcqe->word3); 2502ce1b591cSJames Smart 2503ce1b591cSJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 2504ce1b591cSJames Smart return; 2505ce1b591cSJames Smart } 2506ce1b591cSJames Smart 2507ce1b591cSJames Smart if (ctxp->state != LPFC_NVMET_STE_LS_ABORT) { 2508ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2509ce1b591cSJames Smart "6416 NVMET LS abort cmpl state mismatch: " 2510ce1b591cSJames Smart "oxid x%x: %d %d\n", 2511ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 2512ce1b591cSJames Smart } 2513ce1b591cSJames Smart 2514d613b6a7SJames Smart cmdwqe->context2 = NULL; 2515d613b6a7SJames Smart cmdwqe->context3 = NULL; 2516d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 2517d613b6a7SJames Smart kfree(ctxp); 2518d613b6a7SJames Smart } 2519d613b6a7SJames Smart 2520d613b6a7SJames Smart static int 2521d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba, 2522d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2523d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2524d613b6a7SJames Smart { 2525d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2526d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2527d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 2528d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2529d613b6a7SJames Smart 2530d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 253186c67379SJames Smart "6067 ABTS: sid %x xri x%x/x%x\n", 2532318083adSJames Smart sid, xri, ctxp->wqeq->sli4_xritag); 2533d613b6a7SJames Smart 2534d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2535d613b6a7SJames Smart 2536d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2537d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2538d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2539d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2540d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2541ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2542d613b6a7SJames Smart "6134 Drop ABTS - wrong NDLP state x%x.\n", 2543b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2544d613b6a7SJames Smart 2545d613b6a7SJames Smart /* No failure to an ABTS request. */ 2546d613b6a7SJames Smart return 0; 2547d613b6a7SJames Smart } 2548d613b6a7SJames Smart 2549d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 2550d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 2551d613b6a7SJames Smart 2552d613b6a7SJames Smart /* 2553d613b6a7SJames Smart * Since we zero the whole WQE, we need to ensure we set the WQE fields 2554d613b6a7SJames Smart * that were initialized in lpfc_sli4_nvmet_alloc. 2555d613b6a7SJames Smart */ 2556d613b6a7SJames Smart memset(wqe_abts, 0, sizeof(union lpfc_wqe)); 2557d613b6a7SJames Smart 2558d613b6a7SJames Smart /* Word 5 */ 2559d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0); 2560d613b6a7SJames Smart bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1); 2561d613b6a7SJames Smart bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0); 2562d613b6a7SJames Smart bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS); 2563d613b6a7SJames Smart bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS); 2564d613b6a7SJames Smart 2565d613b6a7SJames Smart /* Word 6 */ 2566d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com, 2567d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 2568d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com, 2569d613b6a7SJames Smart abts_wqeq->sli4_xritag); 2570d613b6a7SJames Smart 2571d613b6a7SJames Smart /* Word 7 */ 2572d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com, 2573d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 2574d613b6a7SJames Smart bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI); 2575d613b6a7SJames Smart bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3); 2576d613b6a7SJames Smart bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0); 2577d613b6a7SJames Smart 2578d613b6a7SJames Smart /* Word 8 */ 2579d613b6a7SJames Smart wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag; 2580d613b6a7SJames Smart 2581d613b6a7SJames Smart /* Word 9 */ 2582d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag); 2583d613b6a7SJames Smart /* Needs to be set by caller */ 2584d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri); 2585d613b6a7SJames Smart 2586d613b6a7SJames Smart /* Word 10 */ 2587d613b6a7SJames Smart bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1); 2588d613b6a7SJames Smart bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 2589d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com, 2590d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 2591d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0); 2592d613b6a7SJames Smart bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0); 2593d613b6a7SJames Smart 2594d613b6a7SJames Smart /* Word 11 */ 2595d613b6a7SJames Smart bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com, 2596d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 2597d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com, 2598d613b6a7SJames Smart OTHER_COMMAND); 2599d613b6a7SJames Smart 2600d613b6a7SJames Smart abts_wqeq->vport = phba->pport; 2601d613b6a7SJames Smart abts_wqeq->context1 = ndlp; 2602d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 2603d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2604d613b6a7SJames Smart abts_wqeq->rsvd2 = 0; 2605d613b6a7SJames Smart /* hba_wqidx should already be setup from command we are aborting */ 2606d613b6a7SJames Smart abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR; 2607d613b6a7SJames Smart abts_wqeq->iocb.ulpLe = 1; 2608d613b6a7SJames Smart 2609d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2610d613b6a7SJames Smart "6069 Issue ABTS to xri x%x reqtag x%x\n", 2611d613b6a7SJames Smart xri, abts_wqeq->iotag); 2612d613b6a7SJames Smart return 1; 2613d613b6a7SJames Smart } 2614d613b6a7SJames Smart 2615d613b6a7SJames Smart static int 2616d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba, 2617d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2618d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2619d613b6a7SJames Smart { 2620d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2621d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2622d613b6a7SJames Smart union lpfc_wqe *abts_wqe; 2623d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 2624d613b6a7SJames Smart unsigned long flags; 2625d613b6a7SJames Smart int rc; 2626d613b6a7SJames Smart 2627d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2628d613b6a7SJames Smart if (!ctxp->wqeq) { 26296c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 2630d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2631d613b6a7SJames Smart } 2632d613b6a7SJames Smart 2633d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 2634d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 2635d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 2636d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 2637d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2638ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 263986c67379SJames Smart "6160 Drop ABORT - wrong NDLP state x%x.\n", 2640b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 2641d613b6a7SJames Smart 2642d613b6a7SJames Smart /* No failure to an ABTS request. */ 264386c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2644d613b6a7SJames Smart return 0; 2645d613b6a7SJames Smart } 2646d613b6a7SJames Smart 2647d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 2648d613b6a7SJames Smart ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba); 2649d613b6a7SJames Smart if (!ctxp->abort_wqeq) { 2650547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2651ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 265286c67379SJames Smart "6161 ABORT failed: No wqeqs: " 2653d613b6a7SJames Smart "xri: x%x\n", ctxp->oxid); 2654d613b6a7SJames Smart /* No failure to an ABTS request. */ 265586c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2656d613b6a7SJames Smart return 0; 2657d613b6a7SJames Smart } 2658d613b6a7SJames Smart abts_wqeq = ctxp->abort_wqeq; 2659d613b6a7SJames Smart abts_wqe = &abts_wqeq->wqe; 2660d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 2661d613b6a7SJames Smart 2662d613b6a7SJames Smart /* Announce entry to new IO submit field. */ 266386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 266486c67379SJames Smart "6162 ABORT Request to rport DID x%06x " 2665d613b6a7SJames Smart "for xri x%x x%x\n", 2666d613b6a7SJames Smart ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag); 2667d613b6a7SJames Smart 2668d613b6a7SJames Smart /* If the hba is getting reset, this flag is set. It is 2669d613b6a7SJames Smart * cleared when the reset is complete and rings reestablished. 2670d613b6a7SJames Smart */ 2671d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2672d613b6a7SJames Smart /* driver queued commands are in process of being flushed */ 2673d613b6a7SJames Smart if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) { 2674d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2675547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2676d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2677d613b6a7SJames Smart "6163 Driver in reset cleanup - flushing " 2678d613b6a7SJames Smart "NVME Req now. hba_flag x%x oxid x%x\n", 2679d613b6a7SJames Smart phba->hba_flag, ctxp->oxid); 2680d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 268186c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2682d613b6a7SJames Smart return 0; 2683d613b6a7SJames Smart } 2684d613b6a7SJames Smart 2685d613b6a7SJames Smart /* Outstanding abort is in progress */ 2686d613b6a7SJames Smart if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) { 2687d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2688547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2689d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 2690d613b6a7SJames Smart "6164 Outstanding NVME I/O Abort Request " 2691d613b6a7SJames Smart "still pending on oxid x%x\n", 2692d613b6a7SJames Smart ctxp->oxid); 2693d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 269486c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2695d613b6a7SJames Smart return 0; 2696d613b6a7SJames Smart } 2697d613b6a7SJames Smart 2698d613b6a7SJames Smart /* Ready - mark outstanding as aborted by driver. */ 2699d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED; 2700d613b6a7SJames Smart 2701d613b6a7SJames Smart /* WQEs are reused. Clear stale data and set key fields to 2702d613b6a7SJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 2703d613b6a7SJames Smart */ 2704d613b6a7SJames Smart memset(abts_wqe, 0, sizeof(union lpfc_wqe)); 2705d613b6a7SJames Smart 2706d613b6a7SJames Smart /* word 3 */ 2707d613b6a7SJames Smart bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); 2708d613b6a7SJames Smart 2709d613b6a7SJames Smart /* word 7 */ 2710d613b6a7SJames Smart bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); 2711d613b6a7SJames Smart bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 2712d613b6a7SJames Smart 2713d613b6a7SJames Smart /* word 8 - tell the FW to abort the IO associated with this 2714d613b6a7SJames Smart * outstanding exchange ID. 2715d613b6a7SJames Smart */ 2716d613b6a7SJames Smart abts_wqe->abort_cmd.wqe_com.abort_tag = ctxp->wqeq->sli4_xritag; 2717d613b6a7SJames Smart 2718d613b6a7SJames Smart /* word 9 - this is the iotag for the abts_wqe completion. */ 2719d613b6a7SJames Smart bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, 2720d613b6a7SJames Smart abts_wqeq->iotag); 2721d613b6a7SJames Smart 2722d613b6a7SJames Smart /* word 10 */ 2723d613b6a7SJames Smart bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); 2724d613b6a7SJames Smart bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 2725d613b6a7SJames Smart 2726d613b6a7SJames Smart /* word 11 */ 2727d613b6a7SJames Smart bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); 2728d613b6a7SJames Smart bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); 2729d613b6a7SJames Smart bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 2730d613b6a7SJames Smart 2731d613b6a7SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 2732d613b6a7SJames Smart abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx; 2733d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp; 2734d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 2735d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME; 2736d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 27374550f9c7SJames Smart abts_wqeq->vport = phba->pport; 2738d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 2739d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2740547077a4SJames Smart if (rc == WQE_SUCCESS) { 2741547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_sol); 2742d613b6a7SJames Smart return 0; 2743547077a4SJames Smart } 2744d613b6a7SJames Smart 2745547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 274686c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2747d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 274886c67379SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 274986c67379SJames Smart "6166 Failed ABORT issue_wqe with status x%x " 2750d613b6a7SJames Smart "for oxid x%x.\n", 2751d613b6a7SJames Smart rc, ctxp->oxid); 2752d613b6a7SJames Smart return 1; 2753d613b6a7SJames Smart } 2754d613b6a7SJames Smart 2755d613b6a7SJames Smart 2756d613b6a7SJames Smart static int 2757d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba, 2758d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2759d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2760d613b6a7SJames Smart { 2761d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2762d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2763d613b6a7SJames Smart unsigned long flags; 2764d613b6a7SJames Smart int rc; 2765d613b6a7SJames Smart 2766d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2767d613b6a7SJames Smart if (!ctxp->wqeq) { 27686c621a22SJames Smart ctxp->wqeq = ctxp->ctxbuf->iocbq; 2769d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 2770d613b6a7SJames Smart } 2771d613b6a7SJames Smart 2772ce1b591cSJames Smart if (ctxp->state == LPFC_NVMET_STE_FREE) { 2773ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2774ce1b591cSJames Smart "6417 NVMET ABORT ctx freed %d %d oxid x%x\n", 2775ce1b591cSJames Smart ctxp->state, ctxp->entry_cnt, ctxp->oxid); 2776ce1b591cSJames Smart rc = WQE_BUSY; 2777ce1b591cSJames Smart goto aerr; 2778ce1b591cSJames Smart } 2779ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 2780ce1b591cSJames Smart ctxp->entry_cnt++; 2781d613b6a7SJames Smart rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 2782d613b6a7SJames Smart if (rc == 0) 2783d613b6a7SJames Smart goto aerr; 2784d613b6a7SJames Smart 2785d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2786d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 278786c67379SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_unsol_fcp_abort_cmp; 278886c67379SJames Smart abts_wqeq->iocb_cmpl = NULL; 2789d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVMET; 2790d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 2791d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2792d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 2793d613b6a7SJames Smart return 0; 2794d613b6a7SJames Smart } 2795d613b6a7SJames Smart 2796d613b6a7SJames Smart aerr: 279786c67379SJames Smart ctxp->flag &= ~LPFC_NVMET_ABORT_OP; 2798d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2799ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2800d613b6a7SJames Smart "6135 Failed to Issue ABTS for oxid x%x. Status x%x\n", 2801d613b6a7SJames Smart ctxp->oxid, rc); 2802d613b6a7SJames Smart return 1; 2803d613b6a7SJames Smart } 2804d613b6a7SJames Smart 2805d613b6a7SJames Smart static int 2806d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *phba, 2807d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 2808d613b6a7SJames Smart uint32_t sid, uint16_t xri) 2809d613b6a7SJames Smart { 2810d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 2811d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 2812d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 2813d613b6a7SJames Smart unsigned long flags; 2814d613b6a7SJames Smart int rc; 2815d613b6a7SJames Smart 2816ce1b591cSJames Smart if ((ctxp->state == LPFC_NVMET_STE_LS_RCV && ctxp->entry_cnt == 1) || 2817ce1b591cSJames Smart (ctxp->state == LPFC_NVMET_STE_LS_RSP && ctxp->entry_cnt == 2)) { 2818ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_ABORT; 2819ce1b591cSJames Smart ctxp->entry_cnt++; 2820ce1b591cSJames Smart } else { 2821ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2822ce1b591cSJames Smart "6418 NVMET LS abort state mismatch " 2823ce1b591cSJames Smart "IO x%x: %d %d\n", 2824ce1b591cSJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 2825ce1b591cSJames Smart ctxp->state = LPFC_NVMET_STE_LS_ABORT; 2826ce1b591cSJames Smart } 2827ce1b591cSJames Smart 2828d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 2829d613b6a7SJames Smart if (!ctxp->wqeq) { 2830d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 2831d613b6a7SJames Smart ctxp->wqeq = lpfc_sli_get_iocbq(phba); 2832d613b6a7SJames Smart if (!ctxp->wqeq) { 2833ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2834d613b6a7SJames Smart "6068 Abort failed: No wqeqs: " 2835d613b6a7SJames Smart "xri: x%x\n", xri); 2836d613b6a7SJames Smart /* No failure to an ABTS request. */ 2837d613b6a7SJames Smart kfree(ctxp); 2838d613b6a7SJames Smart return 0; 2839d613b6a7SJames Smart } 2840d613b6a7SJames Smart } 2841d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 2842d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 28436c621a22SJames Smart 2844ce1b591cSJames Smart if (lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri) == 0) { 2845ce1b591cSJames Smart rc = WQE_BUSY; 2846ce1b591cSJames Smart goto out; 2847ce1b591cSJames Smart } 2848d613b6a7SJames Smart 2849d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 2850d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp; 2851d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 2852d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS; 2853d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, abts_wqeq); 2854d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2855d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 2856547077a4SJames Smart atomic_inc(&tgtp->xmt_abort_unsol); 2857d613b6a7SJames Smart return 0; 2858d613b6a7SJames Smart } 2859ce1b591cSJames Smart out: 2860d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2861d613b6a7SJames Smart abts_wqeq->context2 = NULL; 2862d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2863d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 2864d613b6a7SJames Smart kfree(ctxp); 2865ce1b591cSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 2866d613b6a7SJames Smart "6056 Failed to Issue ABTS. Status x%x\n", rc); 2867d613b6a7SJames Smart return 0; 2868d613b6a7SJames Smart } 2869