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 74d613b6a7SJames Smart /** 75d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response 76d613b6a7SJames Smart * @phba: Pointer to HBA context object. 77d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 78d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 79d613b6a7SJames Smart * 80d613b6a7SJames Smart * The function is called from SLI ring event handler with no 81d613b6a7SJames Smart * lock held. This function is the completion handler for NVME LS commands 82d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 83d613b6a7SJames Smart **/ 84d613b6a7SJames Smart static void 85d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 86d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 87d613b6a7SJames Smart { 88d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 89d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp; 90d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 91d613b6a7SJames Smart uint32_t status, result; 92d613b6a7SJames Smart 93d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 94d613b6a7SJames Smart result = wcqe->parameter; 95d613b6a7SJames Smart if (!phba->targetport) 96d613b6a7SJames Smart goto out; 97d613b6a7SJames Smart 98d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 99d613b6a7SJames Smart 100d613b6a7SJames Smart if (status) 101d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_error); 102d613b6a7SJames Smart else 103d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_rsp_cmpl); 104d613b6a7SJames Smart 105d613b6a7SJames Smart out: 106d613b6a7SJames Smart ctxp = cmdwqe->context2; 107d613b6a7SJames Smart rsp = &ctxp->ctx.ls_req; 108d613b6a7SJames Smart 1092b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS CMPL: xri x%x stat x%x result x%x\n", 1102b65e182SJames Smart ctxp->oxid, status, result); 1112b65e182SJames Smart 112d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 113d613b6a7SJames Smart "6038 %s: Entrypoint: ctx %p status %x/%x\n", __func__, 114d613b6a7SJames Smart ctxp, status, result); 115d613b6a7SJames Smart 116d613b6a7SJames Smart lpfc_nlp_put(cmdwqe->context1); 117d613b6a7SJames Smart cmdwqe->context2 = NULL; 118d613b6a7SJames Smart cmdwqe->context3 = NULL; 119d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 120d613b6a7SJames Smart rsp->done(rsp); 121d613b6a7SJames Smart kfree(ctxp); 122d613b6a7SJames Smart } 123d613b6a7SJames Smart 124d613b6a7SJames Smart /** 125d613b6a7SJames Smart * lpfc_nvmet_rq_post - Repost a NVMET RQ DMA buffer and clean up context 126d613b6a7SJames Smart * @phba: HBA buffer is associated with 127d613b6a7SJames Smart * @ctxp: context to clean up 128d613b6a7SJames Smart * @mp: Buffer to free 129d613b6a7SJames Smart * 130d613b6a7SJames Smart * Description: Frees the given DMA buffer in the appropriate way given by 131d613b6a7SJames Smart * reposting it to its associated RQ so it can be reused. 132d613b6a7SJames Smart * 133d613b6a7SJames Smart * Notes: Takes phba->hbalock. Can be called with or without other locks held. 134d613b6a7SJames Smart * 135d613b6a7SJames Smart * Returns: None 136d613b6a7SJames Smart **/ 137d613b6a7SJames Smart void 138d613b6a7SJames Smart lpfc_nvmet_rq_post(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp, 139d613b6a7SJames Smart struct lpfc_dmabuf *mp) 140d613b6a7SJames Smart { 141d613b6a7SJames Smart if (ctxp) { 142d613b6a7SJames Smart if (ctxp->txrdy) { 143d613b6a7SJames Smart pci_pool_free(phba->txrdy_payload_pool, ctxp->txrdy, 144d613b6a7SJames Smart ctxp->txrdy_phys); 145d613b6a7SJames Smart ctxp->txrdy = NULL; 146d613b6a7SJames Smart ctxp->txrdy_phys = 0; 147d613b6a7SJames Smart } 148d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_FREE; 149d613b6a7SJames Smart } 150d613b6a7SJames Smart lpfc_rq_buf_free(phba, mp); 151d613b6a7SJames Smart } 152d613b6a7SJames Smart 1532b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1542b65e182SJames Smart static void 1552b65e182SJames Smart lpfc_nvmet_ktime(struct lpfc_hba *phba, 1562b65e182SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 1572b65e182SJames Smart { 1582b65e182SJames Smart uint64_t seg1, seg2, seg3, seg4, seg5; 1592b65e182SJames Smart uint64_t seg6, seg7, seg8, seg9, seg10; 1602b65e182SJames Smart 1612b65e182SJames Smart if (!phba->ktime_on) 1622b65e182SJames Smart return; 1632b65e182SJames Smart 1642b65e182SJames Smart if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme || 1652b65e182SJames Smart !ctxp->ts_nvme_data || !ctxp->ts_data_wqput || 1662b65e182SJames Smart !ctxp->ts_isr_data || !ctxp->ts_data_nvme || 1672b65e182SJames Smart !ctxp->ts_nvme_status || !ctxp->ts_status_wqput || 1682b65e182SJames Smart !ctxp->ts_isr_status || !ctxp->ts_status_nvme) 1692b65e182SJames Smart return; 1702b65e182SJames Smart 1712b65e182SJames Smart if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme) 1722b65e182SJames Smart return; 1732b65e182SJames Smart if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data) 1742b65e182SJames Smart return; 1752b65e182SJames Smart if (ctxp->ts_nvme_data > ctxp->ts_data_wqput) 1762b65e182SJames Smart return; 1772b65e182SJames Smart if (ctxp->ts_data_wqput > ctxp->ts_isr_data) 1782b65e182SJames Smart return; 1792b65e182SJames Smart if (ctxp->ts_isr_data > ctxp->ts_data_nvme) 1802b65e182SJames Smart return; 1812b65e182SJames Smart if (ctxp->ts_data_nvme > ctxp->ts_nvme_status) 1822b65e182SJames Smart return; 1832b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_status_wqput) 1842b65e182SJames Smart return; 1852b65e182SJames Smart if (ctxp->ts_status_wqput > ctxp->ts_isr_status) 1862b65e182SJames Smart return; 1872b65e182SJames Smart if (ctxp->ts_isr_status > ctxp->ts_status_nvme) 1882b65e182SJames Smart return; 1892b65e182SJames Smart /* 1902b65e182SJames Smart * Segment 1 - Time from FCP command received by MSI-X ISR 1912b65e182SJames Smart * to FCP command is passed to NVME Layer. 1922b65e182SJames Smart * Segment 2 - Time from FCP command payload handed 1932b65e182SJames Smart * off to NVME Layer to Driver receives a Command op 1942b65e182SJames Smart * from NVME Layer. 1952b65e182SJames Smart * Segment 3 - Time from Driver receives a Command op 1962b65e182SJames Smart * from NVME Layer to Command is put on WQ. 1972b65e182SJames Smart * Segment 4 - Time from Driver WQ put is done 1982b65e182SJames Smart * to MSI-X ISR for Command cmpl. 1992b65e182SJames Smart * Segment 5 - Time from MSI-X ISR for Command cmpl to 2002b65e182SJames Smart * Command cmpl is passed to NVME Layer. 2012b65e182SJames Smart * Segment 6 - Time from Command cmpl is passed to NVME 2022b65e182SJames Smart * Layer to Driver receives a RSP op from NVME Layer. 2032b65e182SJames Smart * Segment 7 - Time from Driver receives a RSP op from 2042b65e182SJames Smart * NVME Layer to WQ put is done on TRSP FCP Status. 2052b65e182SJames Smart * Segment 8 - Time from Driver WQ put is done on TRSP 2062b65e182SJames Smart * FCP Status to MSI-X ISR for TRSP cmpl. 2072b65e182SJames Smart * Segment 9 - Time from MSI-X ISR for TRSP cmpl to 2082b65e182SJames Smart * TRSP cmpl is passed to NVME Layer. 2092b65e182SJames Smart * Segment 10 - Time from FCP command received by 2102b65e182SJames Smart * MSI-X ISR to command is completed on wire. 2112b65e182SJames Smart * (Segments 1 thru 8) for READDATA / WRITEDATA 2122b65e182SJames Smart * (Segments 1 thru 4) for READDATA_RSP 2132b65e182SJames Smart */ 2142b65e182SJames Smart seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd; 2152b65e182SJames Smart seg2 = (ctxp->ts_nvme_data - ctxp->ts_isr_cmd) - seg1; 2162b65e182SJames Smart seg3 = (ctxp->ts_data_wqput - ctxp->ts_isr_cmd) - 2172b65e182SJames Smart seg1 - seg2; 2182b65e182SJames Smart seg4 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd) - 2192b65e182SJames Smart seg1 - seg2 - seg3; 2202b65e182SJames Smart seg5 = (ctxp->ts_data_nvme - ctxp->ts_isr_cmd) - 2212b65e182SJames Smart seg1 - seg2 - seg3 - seg4; 2222b65e182SJames Smart 2232b65e182SJames Smart /* For auto rsp commands seg6 thru seg10 will be 0 */ 2242b65e182SJames Smart if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) { 2252b65e182SJames Smart seg6 = (ctxp->ts_nvme_status - 2262b65e182SJames Smart ctxp->ts_isr_cmd) - 2272b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - seg5; 2282b65e182SJames Smart seg7 = (ctxp->ts_status_wqput - 2292b65e182SJames Smart ctxp->ts_isr_cmd) - 2302b65e182SJames Smart seg1 - seg2 - seg3 - 2312b65e182SJames Smart seg4 - seg5 - seg6; 2322b65e182SJames Smart seg8 = (ctxp->ts_isr_status - 2332b65e182SJames Smart ctxp->ts_isr_cmd) - 2342b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - 2352b65e182SJames Smart seg5 - seg6 - seg7; 2362b65e182SJames Smart seg9 = (ctxp->ts_status_nvme - 2372b65e182SJames Smart ctxp->ts_isr_cmd) - 2382b65e182SJames Smart seg1 - seg2 - seg3 - seg4 - 2392b65e182SJames Smart seg5 - seg6 - seg7 - seg8; 2402b65e182SJames Smart seg10 = (ctxp->ts_isr_status - 2412b65e182SJames Smart ctxp->ts_isr_cmd); 2422b65e182SJames Smart } else { 2432b65e182SJames Smart seg6 = 0; 2442b65e182SJames Smart seg7 = 0; 2452b65e182SJames Smart seg8 = 0; 2462b65e182SJames Smart seg9 = 0; 2472b65e182SJames Smart seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd); 2482b65e182SJames Smart } 2492b65e182SJames Smart 2502b65e182SJames Smart phba->ktime_seg1_total += seg1; 2512b65e182SJames Smart if (seg1 < phba->ktime_seg1_min) 2522b65e182SJames Smart phba->ktime_seg1_min = seg1; 2532b65e182SJames Smart else if (seg1 > phba->ktime_seg1_max) 2542b65e182SJames Smart phba->ktime_seg1_max = seg1; 2552b65e182SJames Smart 2562b65e182SJames Smart phba->ktime_seg2_total += seg2; 2572b65e182SJames Smart if (seg2 < phba->ktime_seg2_min) 2582b65e182SJames Smart phba->ktime_seg2_min = seg2; 2592b65e182SJames Smart else if (seg2 > phba->ktime_seg2_max) 2602b65e182SJames Smart phba->ktime_seg2_max = seg2; 2612b65e182SJames Smart 2622b65e182SJames Smart phba->ktime_seg3_total += seg3; 2632b65e182SJames Smart if (seg3 < phba->ktime_seg3_min) 2642b65e182SJames Smart phba->ktime_seg3_min = seg3; 2652b65e182SJames Smart else if (seg3 > phba->ktime_seg3_max) 2662b65e182SJames Smart phba->ktime_seg3_max = seg3; 2672b65e182SJames Smart 2682b65e182SJames Smart phba->ktime_seg4_total += seg4; 2692b65e182SJames Smart if (seg4 < phba->ktime_seg4_min) 2702b65e182SJames Smart phba->ktime_seg4_min = seg4; 2712b65e182SJames Smart else if (seg4 > phba->ktime_seg4_max) 2722b65e182SJames Smart phba->ktime_seg4_max = seg4; 2732b65e182SJames Smart 2742b65e182SJames Smart phba->ktime_seg5_total += seg5; 2752b65e182SJames Smart if (seg5 < phba->ktime_seg5_min) 2762b65e182SJames Smart phba->ktime_seg5_min = seg5; 2772b65e182SJames Smart else if (seg5 > phba->ktime_seg5_max) 2782b65e182SJames Smart phba->ktime_seg5_max = seg5; 2792b65e182SJames Smart 2802b65e182SJames Smart phba->ktime_data_samples++; 2812b65e182SJames Smart if (!seg6) 2822b65e182SJames Smart goto out; 2832b65e182SJames Smart 2842b65e182SJames Smart phba->ktime_seg6_total += seg6; 2852b65e182SJames Smart if (seg6 < phba->ktime_seg6_min) 2862b65e182SJames Smart phba->ktime_seg6_min = seg6; 2872b65e182SJames Smart else if (seg6 > phba->ktime_seg6_max) 2882b65e182SJames Smart phba->ktime_seg6_max = seg6; 2892b65e182SJames Smart 2902b65e182SJames Smart phba->ktime_seg7_total += seg7; 2912b65e182SJames Smart if (seg7 < phba->ktime_seg7_min) 2922b65e182SJames Smart phba->ktime_seg7_min = seg7; 2932b65e182SJames Smart else if (seg7 > phba->ktime_seg7_max) 2942b65e182SJames Smart phba->ktime_seg7_max = seg7; 2952b65e182SJames Smart 2962b65e182SJames Smart phba->ktime_seg8_total += seg8; 2972b65e182SJames Smart if (seg8 < phba->ktime_seg8_min) 2982b65e182SJames Smart phba->ktime_seg8_min = seg8; 2992b65e182SJames Smart else if (seg8 > phba->ktime_seg8_max) 3002b65e182SJames Smart phba->ktime_seg8_max = seg8; 3012b65e182SJames Smart 3022b65e182SJames Smart phba->ktime_seg9_total += seg9; 3032b65e182SJames Smart if (seg9 < phba->ktime_seg9_min) 3042b65e182SJames Smart phba->ktime_seg9_min = seg9; 3052b65e182SJames Smart else if (seg9 > phba->ktime_seg9_max) 3062b65e182SJames Smart phba->ktime_seg9_max = seg9; 3072b65e182SJames Smart out: 3082b65e182SJames Smart phba->ktime_seg10_total += seg10; 3092b65e182SJames Smart if (seg10 < phba->ktime_seg10_min) 3102b65e182SJames Smart phba->ktime_seg10_min = seg10; 3112b65e182SJames Smart else if (seg10 > phba->ktime_seg10_max) 3122b65e182SJames Smart phba->ktime_seg10_max = seg10; 3132b65e182SJames Smart phba->ktime_status_samples++; 3142b65e182SJames Smart } 3152b65e182SJames Smart #endif 3162b65e182SJames Smart 317d613b6a7SJames Smart /** 318d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response 319d613b6a7SJames Smart * @phba: Pointer to HBA context object. 320d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 321d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 322d613b6a7SJames Smart * 323d613b6a7SJames Smart * The function is called from SLI ring event handler with no 324d613b6a7SJames Smart * lock held. This function is the completion handler for NVME FCP commands 325d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 326d613b6a7SJames Smart **/ 327d613b6a7SJames Smart static void 328d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 329d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 330d613b6a7SJames Smart { 331d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 332d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp; 333d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 334d613b6a7SJames Smart uint32_t status, result, op, start_clean; 3352b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 3362b65e182SJames Smart uint32_t id; 3372b65e182SJames Smart #endif 338d613b6a7SJames Smart 339d613b6a7SJames Smart ctxp = cmdwqe->context2; 340d613b6a7SJames Smart rsp = &ctxp->ctx.fcp_req; 341d613b6a7SJames Smart op = rsp->op; 342d613b6a7SJames Smart ctxp->flag &= ~LPFC_NVMET_IO_INP; 343d613b6a7SJames Smart 344d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 345d613b6a7SJames Smart result = wcqe->parameter; 346d613b6a7SJames Smart 347d613b6a7SJames Smart if (!phba->targetport) 348d613b6a7SJames Smart goto out; 349d613b6a7SJames Smart 3502b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n", 3512b65e182SJames Smart ctxp->oxid, op, status); 3522b65e182SJames Smart 353d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 354d613b6a7SJames Smart if (status) { 355d613b6a7SJames Smart rsp->fcp_error = NVME_SC_DATA_XFER_ERROR; 356d613b6a7SJames Smart rsp->transferred_length = 0; 357d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_error); 358d613b6a7SJames Smart } else { 359d613b6a7SJames Smart rsp->fcp_error = NVME_SC_SUCCESS; 360d613b6a7SJames Smart if (op == NVMET_FCOP_RSP) 361d613b6a7SJames Smart rsp->transferred_length = rsp->rsplen; 362d613b6a7SJames Smart else 363d613b6a7SJames Smart rsp->transferred_length = rsp->transfer_length; 364d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp_cmpl); 365d613b6a7SJames Smart } 366d613b6a7SJames Smart 367d613b6a7SJames Smart out: 368d613b6a7SJames Smart if ((op == NVMET_FCOP_READDATA_RSP) || 369d613b6a7SJames Smart (op == NVMET_FCOP_RSP)) { 370d613b6a7SJames Smart /* Sanity check */ 371d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 372d613b6a7SJames Smart ctxp->entry_cnt++; 3732b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 3742b65e182SJames Smart if (phba->ktime_on) { 3752b65e182SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 3762b65e182SJames Smart ctxp->ts_isr_data = 3772b65e182SJames Smart cmdwqe->isr_timestamp; 3782b65e182SJames Smart ctxp->ts_data_nvme = 3792b65e182SJames Smart ktime_get_ns(); 3802b65e182SJames Smart ctxp->ts_nvme_status = 3812b65e182SJames Smart ctxp->ts_data_nvme; 3822b65e182SJames Smart ctxp->ts_status_wqput = 3832b65e182SJames Smart ctxp->ts_data_nvme; 3842b65e182SJames Smart ctxp->ts_isr_status = 3852b65e182SJames Smart ctxp->ts_data_nvme; 3862b65e182SJames Smart ctxp->ts_status_nvme = 3872b65e182SJames Smart ctxp->ts_data_nvme; 3882b65e182SJames Smart } else { 3892b65e182SJames Smart ctxp->ts_isr_status = 3902b65e182SJames Smart cmdwqe->isr_timestamp; 3912b65e182SJames Smart ctxp->ts_status_nvme = 3922b65e182SJames Smart ktime_get_ns(); 3932b65e182SJames Smart } 3942b65e182SJames Smart } 3952b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 3962b65e182SJames Smart id = smp_processor_id(); 3972b65e182SJames Smart if (ctxp->cpu != id) 3982b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 3992b65e182SJames Smart "6703 CPU Check cmpl: " 4002b65e182SJames Smart "cpu %d expect %d\n", 4012b65e182SJames Smart id, ctxp->cpu); 4022b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 4032b65e182SJames Smart phba->cpucheck_cmpl_io[id]++; 4042b65e182SJames Smart } 4052b65e182SJames Smart #endif 406d613b6a7SJames Smart rsp->done(rsp); 4072b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4082b65e182SJames Smart if (phba->ktime_on) 4092b65e182SJames Smart lpfc_nvmet_ktime(phba, ctxp); 4102b65e182SJames Smart #endif 411d613b6a7SJames Smart /* Let Abort cmpl repost the context */ 412d613b6a7SJames Smart if (!(ctxp->flag & LPFC_NVMET_ABORT_OP)) 413d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 414d613b6a7SJames Smart } else { 415d613b6a7SJames Smart ctxp->entry_cnt++; 416d613b6a7SJames Smart start_clean = offsetof(struct lpfc_iocbq, wqe); 417d613b6a7SJames Smart memset(((char *)cmdwqe) + start_clean, 0, 418d613b6a7SJames Smart (sizeof(struct lpfc_iocbq) - start_clean)); 4192b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 4202b65e182SJames Smart if (phba->ktime_on) { 4212b65e182SJames Smart ctxp->ts_isr_data = cmdwqe->isr_timestamp; 4222b65e182SJames Smart ctxp->ts_data_nvme = ktime_get_ns(); 4232b65e182SJames Smart } 4242b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 4252b65e182SJames Smart id = smp_processor_id(); 4262b65e182SJames Smart if (ctxp->cpu != id) 4272b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 4282b65e182SJames Smart "6704 CPU Check cmdcmpl: " 4292b65e182SJames Smart "cpu %d expect %d\n", 4302b65e182SJames Smart id, ctxp->cpu); 4312b65e182SJames Smart if (ctxp->cpu < LPFC_CHECK_CPU_CNT) 4322b65e182SJames Smart phba->cpucheck_ccmpl_io[id]++; 4332b65e182SJames Smart } 4342b65e182SJames Smart #endif 435d613b6a7SJames Smart rsp->done(rsp); 436d613b6a7SJames Smart } 437d613b6a7SJames Smart } 438d613b6a7SJames Smart 439d613b6a7SJames Smart static int 440d613b6a7SJames Smart lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport, 441d613b6a7SJames Smart struct nvmefc_tgt_ls_req *rsp) 442d613b6a7SJames Smart { 443d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 444d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.ls_req); 445d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 446d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf = 447d613b6a7SJames Smart (struct hbq_dmabuf *)ctxp->rqb_buffer; 448d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 449d613b6a7SJames Smart struct lpfc_nvmet_tgtport *nvmep = tgtport->private; 450d613b6a7SJames Smart struct lpfc_dmabuf dmabuf; 451d613b6a7SJames Smart struct ulp_bde64 bpl; 452d613b6a7SJames Smart int rc; 453d613b6a7SJames Smart 454d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 455d613b6a7SJames Smart "6023 %s: Entrypoint ctx %p %p\n", __func__, 456d613b6a7SJames Smart ctxp, tgtport); 457d613b6a7SJames Smart 458d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, ctxp, rsp->rspdma, 459d613b6a7SJames Smart rsp->rsplen); 460d613b6a7SJames Smart if (nvmewqeq == NULL) { 461d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 462d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 463d613b6a7SJames Smart "6150 LS Drop IO x%x: Prep\n", 464d613b6a7SJames Smart ctxp->oxid); 465d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 466d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, 467d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 468d613b6a7SJames Smart return -ENOMEM; 469d613b6a7SJames Smart } 470d613b6a7SJames Smart 471d613b6a7SJames Smart /* Save numBdes for bpl2sgl */ 472d613b6a7SJames Smart nvmewqeq->rsvd2 = 1; 473d613b6a7SJames Smart nvmewqeq->hba_wqidx = 0; 474d613b6a7SJames Smart nvmewqeq->context3 = &dmabuf; 475d613b6a7SJames Smart dmabuf.virt = &bpl; 476d613b6a7SJames Smart bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow; 477d613b6a7SJames Smart bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh; 478d613b6a7SJames Smart bpl.tus.f.bdeSize = rsp->rsplen; 479d613b6a7SJames Smart bpl.tus.f.bdeFlags = 0; 480d613b6a7SJames Smart bpl.tus.w = le32_to_cpu(bpl.tus.w); 481d613b6a7SJames Smart 482d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_rsp_cmp; 483d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 484d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 485d613b6a7SJames Smart 4862b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RESP: xri x%x wqidx x%x len x%x\n", 4872b65e182SJames Smart ctxp->oxid, nvmewqeq->hba_wqidx, rsp->rsplen); 4882b65e182SJames Smart 489d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, nvmewqeq); 490d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 491d613b6a7SJames Smart /* 492d613b6a7SJames Smart * Okay to repost buffer here, but wait till cmpl 493d613b6a7SJames Smart * before freeing ctxp and iocbq. 494d613b6a7SJames Smart */ 495d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 496d613b6a7SJames Smart ctxp->rqb_buffer = 0; 497d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_rsp); 498d613b6a7SJames Smart return 0; 499d613b6a7SJames Smart } 500d613b6a7SJames Smart /* Give back resources */ 501d613b6a7SJames Smart atomic_inc(&nvmep->xmt_ls_drop); 502d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 503d613b6a7SJames Smart "6151 LS Drop IO x%x: Issue %d\n", 504d613b6a7SJames Smart ctxp->oxid, rc); 505d613b6a7SJames Smart 506d613b6a7SJames Smart lpfc_nlp_put(nvmewqeq->context1); 507d613b6a7SJames Smart 508d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 509d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid); 510d613b6a7SJames Smart return -ENXIO; 511d613b6a7SJames Smart } 512d613b6a7SJames Smart 513d613b6a7SJames Smart static int 514d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport, 515d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp) 516d613b6a7SJames Smart { 517d613b6a7SJames Smart struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private; 518d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp = 519d613b6a7SJames Smart container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); 520d613b6a7SJames Smart struct lpfc_hba *phba = ctxp->phba; 521d613b6a7SJames Smart struct lpfc_iocbq *nvmewqeq; 522d613b6a7SJames Smart unsigned long iflags; 5232b65e182SJames Smart int rc, id; 5242b65e182SJames Smart 5252b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 5262b65e182SJames Smart if (phba->ktime_on) { 5272b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 5282b65e182SJames Smart ctxp->ts_nvme_status = ktime_get_ns(); 5292b65e182SJames Smart else 5302b65e182SJames Smart ctxp->ts_nvme_data = ktime_get_ns(); 5312b65e182SJames Smart } 5322b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) { 5332b65e182SJames Smart id = smp_processor_id(); 5342b65e182SJames Smart ctxp->cpu = id; 5352b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 5362b65e182SJames Smart phba->cpucheck_xmt_io[id]++; 5372b65e182SJames Smart if (rsp->hwqid != id) { 5382b65e182SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 5392b65e182SJames Smart "6705 CPU Check OP: " 5402b65e182SJames Smart "cpu %d expect %d\n", 5412b65e182SJames Smart id, rsp->hwqid); 5422b65e182SJames Smart ctxp->cpu = rsp->hwqid; 5432b65e182SJames Smart } 5442b65e182SJames Smart } 5452b65e182SJames Smart #endif 546d613b6a7SJames Smart 547d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_ABORT) { 548d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 549d613b6a7SJames Smart "6103 Abort op: oxri x%x %d cnt %d\n", 550d613b6a7SJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 5512b65e182SJames Smart 5522b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP ABRT: " 5532b65e182SJames Smart "xri x%x state x%x cnt x%x\n", 5542b65e182SJames Smart ctxp->oxid, ctxp->state, ctxp->entry_cnt); 5552b65e182SJames Smart 556d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_abort); 557d613b6a7SJames Smart ctxp->entry_cnt++; 558d613b6a7SJames Smart ctxp->flag |= LPFC_NVMET_ABORT_OP; 559d613b6a7SJames Smart if (ctxp->flag & LPFC_NVMET_IO_INP) 560d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid, 561d613b6a7SJames Smart ctxp->oxid); 562d613b6a7SJames Smart else 563d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid, 564d613b6a7SJames Smart ctxp->oxid); 565d613b6a7SJames Smart return 0; 566d613b6a7SJames Smart } 567d613b6a7SJames Smart 568d613b6a7SJames Smart /* Sanity check */ 569d613b6a7SJames Smart if (ctxp->state == LPFC_NVMET_STE_ABORT) { 570d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 571d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 572d613b6a7SJames Smart "6102 Bad state IO x%x aborted\n", 573d613b6a7SJames Smart ctxp->oxid); 574a5068b46SJames Smart rc = -ENXIO; 575d613b6a7SJames Smart goto aerr; 576d613b6a7SJames Smart } 577d613b6a7SJames Smart 578d613b6a7SJames Smart nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp); 579d613b6a7SJames Smart if (nvmewqeq == NULL) { 580d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 581d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 582d613b6a7SJames Smart "6152 FCP Drop IO x%x: Prep\n", 583d613b6a7SJames Smart ctxp->oxid); 584a5068b46SJames Smart rc = -ENXIO; 585d613b6a7SJames Smart goto aerr; 586d613b6a7SJames Smart } 587d613b6a7SJames Smart 588d613b6a7SJames Smart nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp; 589d613b6a7SJames Smart nvmewqeq->iocb_cmpl = NULL; 590d613b6a7SJames Smart nvmewqeq->context2 = ctxp; 591d613b6a7SJames Smart nvmewqeq->iocb_flag |= LPFC_IO_NVMET; 592d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = rsp->hwqid; 593d613b6a7SJames Smart 5942b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n", 5952b65e182SJames Smart ctxp->oxid, rsp->op, rsp->rsplen); 5962b65e182SJames Smart 597d613b6a7SJames Smart /* For now we take hbalock */ 598d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, iflags); 599d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq); 600d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, iflags); 601d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 602d613b6a7SJames Smart ctxp->flag |= LPFC_NVMET_IO_INP; 6032b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 6042b65e182SJames Smart if (!phba->ktime_on) 6052b65e182SJames Smart return 0; 6062b65e182SJames Smart if (rsp->op == NVMET_FCOP_RSP) 6072b65e182SJames Smart ctxp->ts_status_wqput = ktime_get_ns(); 6082b65e182SJames Smart else 6092b65e182SJames Smart ctxp->ts_data_wqput = ktime_get_ns(); 6102b65e182SJames Smart #endif 611d613b6a7SJames Smart return 0; 612d613b6a7SJames Smart } 613d613b6a7SJames Smart 614d613b6a7SJames Smart /* Give back resources */ 615d613b6a7SJames Smart atomic_inc(&lpfc_nvmep->xmt_fcp_drop); 616d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 617d613b6a7SJames Smart "6153 FCP Drop IO x%x: Issue: %d\n", 618d613b6a7SJames Smart ctxp->oxid, rc); 619d613b6a7SJames Smart 620d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 621d613b6a7SJames Smart nvmewqeq->context2 = NULL; 622d613b6a7SJames Smart nvmewqeq->context3 = NULL; 623a5068b46SJames Smart rc = -EBUSY; 624d613b6a7SJames Smart aerr: 625a5068b46SJames Smart return rc; 626d613b6a7SJames Smart } 627d613b6a7SJames Smart 628d613b6a7SJames Smart static void 629d613b6a7SJames Smart lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) 630d613b6a7SJames Smart { 631d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tport = targetport->private; 632d613b6a7SJames Smart 633d613b6a7SJames Smart /* release any threads waiting for the unreg to complete */ 634d613b6a7SJames Smart complete(&tport->tport_unreg_done); 635d613b6a7SJames Smart } 636d613b6a7SJames Smart 637d613b6a7SJames Smart static struct nvmet_fc_target_template lpfc_tgttemplate = { 638d613b6a7SJames Smart .targetport_delete = lpfc_nvmet_targetport_delete, 639d613b6a7SJames Smart .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp, 640d613b6a7SJames Smart .fcp_op = lpfc_nvmet_xmt_fcp_op, 641d613b6a7SJames Smart 642d613b6a7SJames Smart .max_hw_queues = 1, 643d613b6a7SJames Smart .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 644d613b6a7SJames Smart .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS, 645d613b6a7SJames Smart .dma_boundary = 0xFFFFFFFF, 646d613b6a7SJames Smart 647d613b6a7SJames Smart /* optional features */ 648d613b6a7SJames Smart .target_features = 0, 649d613b6a7SJames Smart /* sizes of additional private data for data structures */ 650d613b6a7SJames Smart .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport), 651d613b6a7SJames Smart }; 652d613b6a7SJames Smart 653d613b6a7SJames Smart int 654d613b6a7SJames Smart lpfc_nvmet_create_targetport(struct lpfc_hba *phba) 655d613b6a7SJames Smart { 656d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 657d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 658d613b6a7SJames Smart struct nvmet_fc_port_info pinfo; 659d613b6a7SJames Smart int error = 0; 660d613b6a7SJames Smart 661d613b6a7SJames Smart if (phba->targetport) 662d613b6a7SJames Smart return 0; 663d613b6a7SJames Smart 664d613b6a7SJames Smart memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info)); 665d613b6a7SJames Smart pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 666d613b6a7SJames Smart pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 667d613b6a7SJames Smart pinfo.port_id = vport->fc_myDID; 668d613b6a7SJames Smart 669d613b6a7SJames Smart lpfc_tgttemplate.max_hw_queues = phba->cfg_nvme_io_channel; 670d613b6a7SJames Smart lpfc_tgttemplate.max_sgl_segments = phba->cfg_sg_seg_cnt; 671d613b6a7SJames Smart lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP | 67239498faeSJames Smart NVMET_FCTGTFEAT_NEEDS_CMD_CPUSCHED | 67339498faeSJames Smart NVMET_FCTGTFEAT_CMD_IN_ISR | 67439498faeSJames Smart NVMET_FCTGTFEAT_OPDONE_IN_ISR; 675d613b6a7SJames Smart 6767d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 677d613b6a7SJames Smart error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 678d613b6a7SJames Smart &phba->pcidev->dev, 679d613b6a7SJames Smart &phba->targetport); 680166d7211SJames Smart #else 681166d7211SJames Smart error = -ENOMEM; 682166d7211SJames Smart #endif 683d613b6a7SJames Smart if (error) { 684d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 685d613b6a7SJames Smart "6025 Cannot register NVME targetport " 686d613b6a7SJames Smart "x%x\n", error); 687d613b6a7SJames Smart phba->targetport = NULL; 688d613b6a7SJames Smart } else { 689d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *) 690d613b6a7SJames Smart phba->targetport->private; 691d613b6a7SJames Smart tgtp->phba = phba; 692d613b6a7SJames Smart 693d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 694d613b6a7SJames Smart "6026 Registered NVME " 695d613b6a7SJames Smart "targetport: %p, private %p " 696d613b6a7SJames Smart "portnm %llx nodenm %llx\n", 697d613b6a7SJames Smart phba->targetport, tgtp, 698d613b6a7SJames Smart pinfo.port_name, pinfo.node_name); 699d613b6a7SJames Smart 700d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_in, 0); 701d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_out, 0); 702d613b6a7SJames Smart atomic_set(&tgtp->rcv_ls_req_drop, 0); 703d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_abort, 0); 704d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp, 0); 705d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_drop, 0); 706d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_error, 0); 707d613b6a7SJames Smart atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0); 708d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_in, 0); 709d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_out, 0); 710d613b6a7SJames Smart atomic_set(&tgtp->rcv_fcp_cmd_drop, 0); 711d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_abort, 0); 712d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_drop, 0); 713d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read_rsp, 0); 714d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_read, 0); 715d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_write, 0); 716d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp, 0); 717d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0); 718d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_error, 0); 719d613b6a7SJames Smart atomic_set(&tgtp->xmt_fcp_rsp_drop, 0); 720d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp, 0); 721d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_rsp_error, 0); 722d613b6a7SJames Smart atomic_set(&tgtp->xmt_abort_cmpl, 0); 723d613b6a7SJames Smart } 724d613b6a7SJames Smart return error; 725d613b6a7SJames Smart } 726d613b6a7SJames Smart 727d613b6a7SJames Smart int 728d613b6a7SJames Smart lpfc_nvmet_update_targetport(struct lpfc_hba *phba) 729d613b6a7SJames Smart { 730d613b6a7SJames Smart struct lpfc_vport *vport = phba->pport; 731d613b6a7SJames Smart 732d613b6a7SJames Smart if (!phba->targetport) 733d613b6a7SJames Smart return 0; 734d613b6a7SJames Smart 735d613b6a7SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 736d613b6a7SJames Smart "6007 Update NVMET port %p did x%x\n", 737d613b6a7SJames Smart phba->targetport, vport->fc_myDID); 738d613b6a7SJames Smart 739d613b6a7SJames Smart phba->targetport->port_id = vport->fc_myDID; 740d613b6a7SJames Smart return 0; 741d613b6a7SJames Smart } 742d613b6a7SJames Smart 743318083adSJames Smart /** 744318083adSJames Smart * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort 745318083adSJames Smart * @phba: pointer to lpfc hba data structure. 746318083adSJames Smart * @axri: pointer to the nvmet xri abort wcqe structure. 747318083adSJames Smart * 748318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 749318083adSJames Smart * NVMET aborted xri. 750318083adSJames Smart **/ 751318083adSJames Smart void 752318083adSJames Smart lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba, 753318083adSJames Smart struct sli4_wcqe_xri_aborted *axri) 754318083adSJames Smart { 755318083adSJames Smart /* TODO: work in progress */ 756318083adSJames Smart } 757318083adSJames Smart 758d613b6a7SJames Smart void 759d613b6a7SJames Smart lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 760d613b6a7SJames Smart { 7617d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 762d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 763d613b6a7SJames Smart 764d613b6a7SJames Smart if (phba->nvmet_support == 0) 765d613b6a7SJames Smart return; 766d613b6a7SJames Smart if (phba->targetport) { 767d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 768d613b6a7SJames Smart init_completion(&tgtp->tport_unreg_done); 769d613b6a7SJames Smart nvmet_fc_unregister_targetport(phba->targetport); 770d613b6a7SJames Smart wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); 771d613b6a7SJames Smart } 772d613b6a7SJames Smart phba->targetport = NULL; 773166d7211SJames Smart #endif 774d613b6a7SJames Smart } 775d613b6a7SJames Smart 776d613b6a7SJames Smart /** 777d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer - Process an unsolicited event data buffer 778d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 779d613b6a7SJames Smart * @pring: pointer to a SLI ring. 780d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 781d613b6a7SJames Smart * 782d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 783d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 784d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 785d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 786d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 787d613b6a7SJames Smart * of the discovery state machine. 788d613b6a7SJames Smart **/ 789d613b6a7SJames Smart static void 790d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 791d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf) 792d613b6a7SJames Smart { 7937d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 794d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 795d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 796d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 797d613b6a7SJames Smart uint32_t *payload; 798d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 799d613b6a7SJames Smart 800d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 801d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 802d613b6a7SJames Smart "6154 LS Drop IO\n"); 8032b65e182SJames Smart oxid = 0; 8042b65e182SJames Smart size = 0; 8052b65e182SJames Smart sid = 0; 806d613b6a7SJames Smart goto dropit; 807d613b6a7SJames Smart } 808d613b6a7SJames Smart 809d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 810d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 811d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 812d613b6a7SJames Smart size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); 813d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 814d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 815d613b6a7SJames Smart 816d613b6a7SJames Smart ctxp = kzalloc(sizeof(struct lpfc_nvmet_rcv_ctx), GFP_ATOMIC); 817d613b6a7SJames Smart if (ctxp == NULL) { 818d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 819d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 820d613b6a7SJames Smart "6155 LS Drop IO x%x: Alloc\n", 821d613b6a7SJames Smart oxid); 822d613b6a7SJames Smart dropit: 8232b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: " 8242b65e182SJames Smart "xri x%x sz %d from %06x\n", 8252b65e182SJames Smart oxid, size, sid); 826d613b6a7SJames Smart if (nvmebuf) 827d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 828d613b6a7SJames Smart return; 829d613b6a7SJames Smart } 830d613b6a7SJames Smart ctxp->phba = phba; 831d613b6a7SJames Smart ctxp->size = size; 832d613b6a7SJames Smart ctxp->oxid = oxid; 833d613b6a7SJames Smart ctxp->sid = sid; 834d613b6a7SJames Smart ctxp->wqeq = NULL; 835d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 836d613b6a7SJames Smart ctxp->rqb_buffer = (void *)nvmebuf; 8372b65e182SJames Smart 8382b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS RCV: xri x%x sz %d from %06x\n", 8392b65e182SJames Smart oxid, size, sid); 840d613b6a7SJames Smart /* 841d613b6a7SJames Smart * The calling sequence should be: 842d613b6a7SJames Smart * nvmet_fc_rcv_ls_req -> lpfc_nvmet_xmt_ls_rsp/cmp ->_req->done 843d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_rsp_cmp should free the allocated ctxp. 844d613b6a7SJames Smart */ 845d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_in); 846d613b6a7SJames Smart rc = nvmet_fc_rcv_ls_req(phba->targetport, &ctxp->ctx.ls_req, 847d613b6a7SJames Smart payload, size); 848d613b6a7SJames Smart 849d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 850d613b6a7SJames Smart "6037 %s: ctx %p sz %d rc %d: %08x %08x %08x " 851d613b6a7SJames Smart "%08x %08x %08x\n", __func__, ctxp, size, rc, 852d613b6a7SJames Smart *payload, *(payload+1), *(payload+2), 853d613b6a7SJames Smart *(payload+3), *(payload+4), *(payload+5)); 8542b65e182SJames Smart 855d613b6a7SJames Smart if (rc == 0) { 856d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_out); 857d613b6a7SJames Smart return; 858d613b6a7SJames Smart } 8592b65e182SJames Smart 8602b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET LS DROP: xri x%x sz %d from %06x\n", 8612b65e182SJames Smart oxid, size, sid); 8622b65e182SJames Smart 863d613b6a7SJames Smart atomic_inc(&tgtp->rcv_ls_req_drop); 864d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 865d613b6a7SJames Smart "6156 LS Drop IO x%x: nvmet_fc_rcv_ls_req %d\n", 866d613b6a7SJames Smart ctxp->oxid, rc); 867d613b6a7SJames Smart 868d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 869d613b6a7SJames Smart if (nvmebuf) 870d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 871d613b6a7SJames Smart 872d613b6a7SJames Smart atomic_inc(&tgtp->xmt_ls_abort); 873d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid); 874166d7211SJames Smart #endif 875d613b6a7SJames Smart } 876d613b6a7SJames Smart 877d613b6a7SJames Smart /** 878d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer 879d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 880d613b6a7SJames Smart * @pring: pointer to a SLI ring. 881d613b6a7SJames Smart * @nvmebuf: pointer to lpfc nvme command HBQ data structure. 882d613b6a7SJames Smart * 883d613b6a7SJames Smart * This routine is used for processing the WQE associated with a unsolicited 884d613b6a7SJames Smart * event. It first determines whether there is an existing ndlp that matches 885d613b6a7SJames Smart * the DID from the unsolicited WQE. If not, it will create a new one with 886d613b6a7SJames Smart * the DID from the unsolicited WQE. The ELS command from the unsolicited 887d613b6a7SJames Smart * WQE is then used to invoke the proper routine and to set up proper state 888d613b6a7SJames Smart * of the discovery state machine. 889d613b6a7SJames Smart **/ 890d613b6a7SJames Smart static void 891d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba, 892d613b6a7SJames Smart struct lpfc_sli_ring *pring, 893d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 894d613b6a7SJames Smart uint64_t isr_timestamp) 895d613b6a7SJames Smart { 8967d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) 897d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 898d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 899d613b6a7SJames Smart struct fc_frame_header *fc_hdr; 900d613b6a7SJames Smart uint32_t *payload; 901d613b6a7SJames Smart uint32_t size, oxid, sid, rc; 9022b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 9032b65e182SJames Smart uint32_t id; 9042b65e182SJames Smart #endif 905d613b6a7SJames Smart 906d613b6a7SJames Smart if (!nvmebuf || !phba->targetport) { 907d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 908d613b6a7SJames Smart "6157 FCP Drop IO\n"); 9092b65e182SJames Smart oxid = 0; 9102b65e182SJames Smart size = 0; 9112b65e182SJames Smart sid = 0; 912d613b6a7SJames Smart goto dropit; 913d613b6a7SJames Smart } 914d613b6a7SJames Smart 915d613b6a7SJames Smart 916d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 917d613b6a7SJames Smart payload = (uint32_t *)(nvmebuf->dbuf.virt); 918d613b6a7SJames Smart fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); 919d613b6a7SJames Smart size = nvmebuf->bytes_recv; 920d613b6a7SJames Smart oxid = be16_to_cpu(fc_hdr->fh_ox_id); 921d613b6a7SJames Smart sid = sli4_sid_from_fc_hdr(fc_hdr); 922d613b6a7SJames Smart 923d613b6a7SJames Smart ctxp = (struct lpfc_nvmet_rcv_ctx *)nvmebuf->context; 924d613b6a7SJames Smart if (ctxp == NULL) { 925d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 926d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 927d613b6a7SJames Smart "6158 FCP Drop IO x%x: Alloc\n", 928d613b6a7SJames Smart oxid); 929d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 930d613b6a7SJames Smart /* Cannot send ABTS without context */ 931d613b6a7SJames Smart return; 932d613b6a7SJames Smart } 933d613b6a7SJames Smart memset(ctxp, 0, sizeof(ctxp->ctx)); 934d613b6a7SJames Smart ctxp->wqeq = NULL; 935d613b6a7SJames Smart ctxp->txrdy = NULL; 936d613b6a7SJames Smart ctxp->offset = 0; 937d613b6a7SJames Smart ctxp->phba = phba; 938d613b6a7SJames Smart ctxp->size = size; 939d613b6a7SJames Smart ctxp->oxid = oxid; 940d613b6a7SJames Smart ctxp->sid = sid; 941d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RCV; 942d613b6a7SJames Smart ctxp->rqb_buffer = nvmebuf; 943d613b6a7SJames Smart ctxp->entry_cnt = 1; 944d613b6a7SJames Smart ctxp->flag = 0; 945d613b6a7SJames Smart 9462b65e182SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 9472b65e182SJames Smart if (phba->ktime_on) { 9482b65e182SJames Smart ctxp->ts_isr_cmd = isr_timestamp; 9492b65e182SJames Smart ctxp->ts_cmd_nvme = ktime_get_ns(); 9502b65e182SJames Smart ctxp->ts_nvme_data = 0; 9512b65e182SJames Smart ctxp->ts_data_wqput = 0; 9522b65e182SJames Smart ctxp->ts_isr_data = 0; 9532b65e182SJames Smart ctxp->ts_data_nvme = 0; 9542b65e182SJames Smart ctxp->ts_nvme_status = 0; 9552b65e182SJames Smart ctxp->ts_status_wqput = 0; 9562b65e182SJames Smart ctxp->ts_isr_status = 0; 9572b65e182SJames Smart ctxp->ts_status_nvme = 0; 9582b65e182SJames Smart } 9592b65e182SJames Smart 9602b65e182SJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV) { 9612b65e182SJames Smart id = smp_processor_id(); 9622b65e182SJames Smart if (id < LPFC_CHECK_CPU_CNT) 9632b65e182SJames Smart phba->cpucheck_rcv_io[id]++; 9642b65e182SJames Smart } 9652b65e182SJames Smart #endif 9662b65e182SJames Smart 9672b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d from %06x\n", 9682b65e182SJames Smart oxid, size, sid); 9692b65e182SJames Smart 970d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_in); 971d613b6a7SJames Smart /* 972d613b6a7SJames Smart * The calling sequence should be: 973d613b6a7SJames Smart * nvmet_fc_rcv_fcp_req -> lpfc_nvmet_xmt_fcp_op/cmp -> req->done 974d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp. 975d613b6a7SJames Smart */ 976d613b6a7SJames Smart rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req, 977d613b6a7SJames Smart payload, size); 978d613b6a7SJames Smart 979d613b6a7SJames Smart /* Process FCP command */ 980d613b6a7SJames Smart if (rc == 0) { 981d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_out); 982d613b6a7SJames Smart return; 983d613b6a7SJames Smart } 984d613b6a7SJames Smart 985d613b6a7SJames Smart atomic_inc(&tgtp->rcv_fcp_cmd_drop); 986d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 987318083adSJames Smart "6159 FCP Drop IO x%x: err x%x\n", 988d613b6a7SJames Smart ctxp->oxid, rc); 989d613b6a7SJames Smart dropit: 9902b65e182SJames Smart lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 9912b65e182SJames Smart oxid, size, sid); 992d613b6a7SJames Smart if (oxid) { 993d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid); 994d613b6a7SJames Smart return; 995d613b6a7SJames Smart } 996d613b6a7SJames Smart 997d613b6a7SJames Smart if (nvmebuf) { 998d613b6a7SJames Smart nvmebuf->iocbq->hba_wqidx = 0; 999d613b6a7SJames Smart /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 1000d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 1001d613b6a7SJames Smart } 1002166d7211SJames Smart #endif 1003d613b6a7SJames Smart } 1004d613b6a7SJames Smart 1005d613b6a7SJames Smart /** 1006d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_event - Process an unsolicited event from an nvme nport 1007d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1008d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1009d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1010d613b6a7SJames Smart * 1011d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1012d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1013d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1014d613b6a7SJames Smart * lpfc_nvmet_unsol_ls_buffer() after properly set up the buffer from the 1015d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1016d613b6a7SJames Smart **/ 1017d613b6a7SJames Smart void 1018d613b6a7SJames Smart lpfc_nvmet_unsol_ls_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1019d613b6a7SJames Smart struct lpfc_iocbq *piocb) 1020d613b6a7SJames Smart { 1021d613b6a7SJames Smart struct lpfc_dmabuf *d_buf; 1022d613b6a7SJames Smart struct hbq_dmabuf *nvmebuf; 1023d613b6a7SJames Smart 1024d613b6a7SJames Smart d_buf = piocb->context2; 1025d613b6a7SJames Smart nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); 1026d613b6a7SJames Smart 1027d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1028d613b6a7SJames Smart lpfc_in_buf_free(phba, &nvmebuf->dbuf); 1029d613b6a7SJames Smart return; 1030d613b6a7SJames Smart } 1031d613b6a7SJames Smart lpfc_nvmet_unsol_ls_buffer(phba, pring, nvmebuf); 1032d613b6a7SJames Smart } 1033d613b6a7SJames Smart 1034d613b6a7SJames Smart /** 1035d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport 1036d613b6a7SJames Smart * @phba: pointer to lpfc hba data structure. 1037d613b6a7SJames Smart * @pring: pointer to a SLI ring. 1038d613b6a7SJames Smart * @nvmebuf: pointer to received nvme data structure. 1039d613b6a7SJames Smart * 1040d613b6a7SJames Smart * This routine is used to process an unsolicited event received from a SLI 1041d613b6a7SJames Smart * (Service Level Interface) ring. The actual processing of the data buffer 1042d613b6a7SJames Smart * associated with the unsolicited event is done by invoking the routine 1043d613b6a7SJames Smart * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the 1044d613b6a7SJames Smart * SLI RQ on which the unsolicited event was received. 1045d613b6a7SJames Smart **/ 1046d613b6a7SJames Smart void 1047d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba, 1048d613b6a7SJames Smart struct lpfc_sli_ring *pring, 1049d613b6a7SJames Smart struct rqb_dmabuf *nvmebuf, 1050d613b6a7SJames Smart uint64_t isr_timestamp) 1051d613b6a7SJames Smart { 1052d613b6a7SJames Smart if (phba->nvmet_support == 0) { 1053d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 1054d613b6a7SJames Smart return; 1055d613b6a7SJames Smart } 1056d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_buffer(phba, pring, nvmebuf, 1057d613b6a7SJames Smart isr_timestamp); 1058d613b6a7SJames Smart } 1059d613b6a7SJames Smart 1060d613b6a7SJames Smart /** 1061d613b6a7SJames Smart * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure 1062d613b6a7SJames Smart * @phba: pointer to a host N_Port data structure. 1063d613b6a7SJames Smart * @ctxp: Context info for NVME LS Request 1064d613b6a7SJames Smart * @rspbuf: DMA buffer of NVME command. 1065d613b6a7SJames Smart * @rspsize: size of the NVME command. 1066d613b6a7SJames Smart * 1067d613b6a7SJames Smart * This routine is used for allocating a lpfc-WQE data structure from 1068d613b6a7SJames Smart * the driver lpfc-WQE free-list and prepare the WQE with the parameters 1069d613b6a7SJames Smart * passed into the routine for discovery state machine to issue an Extended 1070d613b6a7SJames Smart * Link Service (NVME) commands. It is a generic lpfc-WQE allocation 1071d613b6a7SJames Smart * and preparation routine that is used by all the discovery state machine 1072d613b6a7SJames Smart * routines and the NVME command-specific fields will be later set up by 1073d613b6a7SJames Smart * the individual discovery machine routines after calling this routine 1074d613b6a7SJames Smart * allocating and preparing a generic WQE data structure. It fills in the 1075d613b6a7SJames Smart * Buffer Descriptor Entries (BDEs), allocates buffers for both command 1076d613b6a7SJames Smart * payload and response payload (if expected). The reference count on the 1077d613b6a7SJames Smart * ndlp is incremented by 1 and the reference to the ndlp is put into 1078d613b6a7SJames Smart * context1 of the WQE data structure for this WQE to hold the ndlp 1079d613b6a7SJames Smart * reference for the command's callback function to access later. 1080d613b6a7SJames Smart * 1081d613b6a7SJames Smart * Return code 1082d613b6a7SJames Smart * Pointer to the newly allocated/prepared nvme wqe data structure 1083d613b6a7SJames Smart * NULL - when nvme wqe data structure allocation/preparation failed 1084d613b6a7SJames Smart **/ 1085d613b6a7SJames Smart static struct lpfc_iocbq * 1086d613b6a7SJames Smart lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba, 1087d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1088d613b6a7SJames Smart dma_addr_t rspbuf, uint16_t rspsize) 1089d613b6a7SJames Smart { 1090d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1091d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1092d613b6a7SJames Smart union lpfc_wqe *wqe; 1093d613b6a7SJames Smart 1094d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1095d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1096d613b6a7SJames Smart "6104 lpfc_nvmet_prep_ls_wqe: link err: " 1097d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1098d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1099d613b6a7SJames Smart return NULL; 1100d613b6a7SJames Smart } 1101d613b6a7SJames Smart 1102d613b6a7SJames Smart /* Allocate buffer for command wqe */ 1103d613b6a7SJames Smart nvmewqe = lpfc_sli_get_iocbq(phba); 1104d613b6a7SJames Smart if (nvmewqe == NULL) { 1105d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1106d613b6a7SJames Smart "6105 lpfc_nvmet_prep_ls_wqe: No WQE: " 1107d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1108d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1109d613b6a7SJames Smart return NULL; 1110d613b6a7SJames Smart } 1111d613b6a7SJames Smart 1112d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1113d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1114d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1115d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1116d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 1117d613b6a7SJames Smart "6106 lpfc_nvmet_prep_ls_wqe: No ndlp: " 1118d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1119d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1120d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1121d613b6a7SJames Smart } 1122d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1123d613b6a7SJames Smart 1124d613b6a7SJames Smart /* prevent preparing wqe with NULL ndlp reference */ 1125d613b6a7SJames Smart nvmewqe->context1 = lpfc_nlp_get(ndlp); 1126d613b6a7SJames Smart if (nvmewqe->context1 == NULL) 1127d613b6a7SJames Smart goto nvme_wqe_free_wqeq_exit; 1128d613b6a7SJames Smart nvmewqe->context2 = ctxp; 1129d613b6a7SJames Smart 1130d613b6a7SJames Smart wqe = &nvmewqe->wqe; 1131d613b6a7SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 1132d613b6a7SJames Smart 1133d613b6a7SJames Smart /* Words 0 - 2 */ 1134d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1135d613b6a7SJames Smart wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize; 1136d613b6a7SJames Smart wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf)); 1137d613b6a7SJames Smart wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf)); 1138d613b6a7SJames Smart 1139d613b6a7SJames Smart /* Word 3 */ 1140d613b6a7SJames Smart 1141d613b6a7SJames Smart /* Word 4 */ 1142d613b6a7SJames Smart 1143d613b6a7SJames Smart /* Word 5 */ 1144d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 1145d613b6a7SJames Smart bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 1146d613b6a7SJames Smart bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 11478b361639SJames Smart bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP); 1148d613b6a7SJames Smart bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 1149d613b6a7SJames Smart 1150d613b6a7SJames Smart /* Word 6 */ 1151d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, 1152d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1153d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag); 1154d613b6a7SJames Smart 1155d613b6a7SJames Smart /* Word 7 */ 1156d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com, 1157d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 1158d613b6a7SJames Smart bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI); 1159d613b6a7SJames Smart bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3); 1160d613b6a7SJames Smart bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); 1161d613b6a7SJames Smart 1162d613b6a7SJames Smart /* Word 8 */ 1163d613b6a7SJames Smart wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag; 1164d613b6a7SJames Smart 1165d613b6a7SJames Smart /* Word 9 */ 1166d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag); 1167d613b6a7SJames Smart /* Needs to be set by caller */ 1168d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid); 1169d613b6a7SJames Smart 1170d613b6a7SJames Smart /* Word 10 */ 1171d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); 1172d613b6a7SJames Smart bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 1173d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, 1174d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1175d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); 1176d613b6a7SJames Smart 1177d613b6a7SJames Smart /* Word 11 */ 1178d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com, 1179d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1180d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com, 1181d613b6a7SJames Smart OTHER_COMMAND); 1182d613b6a7SJames Smart 1183d613b6a7SJames Smart /* Word 12 */ 1184d613b6a7SJames Smart wqe->xmit_sequence.xmit_len = rspsize; 1185d613b6a7SJames Smart 1186d613b6a7SJames Smart nvmewqe->retry = 1; 1187d613b6a7SJames Smart nvmewqe->vport = phba->pport; 1188d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 1189d613b6a7SJames Smart nvmewqe->iocb_flag |= LPFC_IO_NVME_LS; 1190d613b6a7SJames Smart 1191d613b6a7SJames Smart /* Xmit NVME response to remote NPORT <did> */ 1192d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 1193d613b6a7SJames Smart "6039 Xmit NVME LS response to remote " 1194d613b6a7SJames Smart "NPORT x%x iotag:x%x oxid:x%x size:x%x\n", 1195d613b6a7SJames Smart ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid, 1196d613b6a7SJames Smart rspsize); 1197d613b6a7SJames Smart return nvmewqe; 1198d613b6a7SJames Smart 1199d613b6a7SJames Smart nvme_wqe_free_wqeq_exit: 1200d613b6a7SJames Smart nvmewqe->context2 = NULL; 1201d613b6a7SJames Smart nvmewqe->context3 = NULL; 1202d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, nvmewqe); 1203d613b6a7SJames Smart return NULL; 1204d613b6a7SJames Smart } 1205d613b6a7SJames Smart 1206d613b6a7SJames Smart 1207d613b6a7SJames Smart static struct lpfc_iocbq * 1208d613b6a7SJames Smart lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba, 1209d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp) 1210d613b6a7SJames Smart { 1211d613b6a7SJames Smart struct nvmefc_tgt_fcp_req *rsp = &ctxp->ctx.fcp_req; 1212d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1213d613b6a7SJames Smart struct sli4_sge *sgl; 1214d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1215d613b6a7SJames Smart struct lpfc_iocbq *nvmewqe; 1216d613b6a7SJames Smart struct scatterlist *sgel; 1217d613b6a7SJames Smart union lpfc_wqe128 *wqe; 1218d613b6a7SJames Smart uint32_t *txrdy; 1219d613b6a7SJames Smart dma_addr_t physaddr; 1220d613b6a7SJames Smart int i, cnt; 1221d613b6a7SJames Smart int xc = 1; 1222d613b6a7SJames Smart 1223d613b6a7SJames Smart if (!lpfc_is_link_up(phba)) { 1224d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1225d613b6a7SJames Smart "6107 lpfc_nvmet_prep_fcp_wqe: link err:" 1226d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", ctxp->sid, 1227d613b6a7SJames Smart ctxp->oxid); 1228d613b6a7SJames Smart return NULL; 1229d613b6a7SJames Smart } 1230d613b6a7SJames Smart 1231d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, ctxp->sid); 1232d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1233d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1234d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1235d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1236d613b6a7SJames Smart "6108 lpfc_nvmet_prep_fcp_wqe: no ndlp: " 1237d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1238d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1239d613b6a7SJames Smart return NULL; 1240d613b6a7SJames Smart } 1241d613b6a7SJames Smart 1242d613b6a7SJames Smart if (rsp->sg_cnt > phba->cfg_sg_seg_cnt) { 1243d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1244d613b6a7SJames Smart "6109 lpfc_nvmet_prep_fcp_wqe: seg cnt err: " 1245d613b6a7SJames Smart "NPORT x%x oxid:x%x\n", 1246d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1247d613b6a7SJames Smart return NULL; 1248d613b6a7SJames Smart } 1249d613b6a7SJames Smart 1250d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1251d613b6a7SJames Smart nvmewqe = ctxp->wqeq; 1252d613b6a7SJames Smart if (nvmewqe == NULL) { 1253d613b6a7SJames Smart /* Allocate buffer for command wqe */ 1254d613b6a7SJames Smart nvmewqe = ctxp->rqb_buffer->iocbq; 1255d613b6a7SJames Smart if (nvmewqe == NULL) { 1256d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1257d613b6a7SJames Smart "6110 lpfc_nvmet_prep_fcp_wqe: No " 1258d613b6a7SJames Smart "WQE: NPORT x%x oxid:x%x\n", 1259d613b6a7SJames Smart ctxp->sid, ctxp->oxid); 1260d613b6a7SJames Smart return NULL; 1261d613b6a7SJames Smart } 1262d613b6a7SJames Smart ctxp->wqeq = nvmewqe; 1263d613b6a7SJames Smart xc = 0; /* create new XRI */ 1264d613b6a7SJames Smart nvmewqe->sli4_lxritag = NO_XRI; 1265d613b6a7SJames Smart nvmewqe->sli4_xritag = NO_XRI; 1266d613b6a7SJames Smart } 1267d613b6a7SJames Smart 1268d613b6a7SJames Smart /* Sanity check */ 1269d613b6a7SJames Smart if (((ctxp->state == LPFC_NVMET_STE_RCV) && 1270d613b6a7SJames Smart (ctxp->entry_cnt == 1)) || 1271d613b6a7SJames Smart ((ctxp->state == LPFC_NVMET_STE_DATA) && 1272d613b6a7SJames Smart (ctxp->entry_cnt > 1))) { 1273d613b6a7SJames Smart wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 1274d613b6a7SJames Smart } else { 1275d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1276d613b6a7SJames Smart "6111 Wrong state %s: %d cnt %d\n", 1277d613b6a7SJames Smart __func__, ctxp->state, ctxp->entry_cnt); 1278d613b6a7SJames Smart return NULL; 1279d613b6a7SJames Smart } 1280d613b6a7SJames Smart 1281d613b6a7SJames Smart sgl = (struct sli4_sge *)ctxp->rqb_buffer->sglq->sgl; 1282d613b6a7SJames Smart switch (rsp->op) { 1283d613b6a7SJames Smart case NVMET_FCOP_READDATA: 1284d613b6a7SJames Smart case NVMET_FCOP_READDATA_RSP: 1285d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 1286d613b6a7SJames Smart sgel = &rsp->sg[0]; 1287d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 1288d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1289d613b6a7SJames Smart wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel); 1290d613b6a7SJames Smart wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr)); 1291d613b6a7SJames Smart wqe->fcp_tsend.bde.addrHigh = 1292d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1293d613b6a7SJames Smart 1294d613b6a7SJames Smart /* Word 3 */ 1295d613b6a7SJames Smart wqe->fcp_tsend.payload_offset_len = 0; 1296d613b6a7SJames Smart 1297d613b6a7SJames Smart /* Word 4 */ 1298d613b6a7SJames Smart wqe->fcp_tsend.relative_offset = ctxp->offset; 1299d613b6a7SJames Smart 1300d613b6a7SJames Smart /* Word 5 */ 1301d613b6a7SJames Smart 1302d613b6a7SJames Smart /* Word 6 */ 1303d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com, 1304d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1305d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com, 1306d613b6a7SJames Smart nvmewqe->sli4_xritag); 1307d613b6a7SJames Smart 1308d613b6a7SJames Smart /* Word 7 */ 1309d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE); 1310d613b6a7SJames Smart 1311d613b6a7SJames Smart /* Word 8 */ 1312d613b6a7SJames Smart wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag; 1313d613b6a7SJames Smart 1314d613b6a7SJames Smart /* Word 9 */ 1315d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag); 1316d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid); 1317d613b6a7SJames Smart 1318d613b6a7SJames Smart /* Word 10 */ 1319d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 1320d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1); 1321d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE); 1322d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com, 1323d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1324d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe->fcp_tsend.wqe_com, 0); 1325d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, xc); 1326d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1); 1327d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1328d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_tsend.wqe_com, 1); 1329d613b6a7SJames Smart 1330d613b6a7SJames Smart /* Word 11 */ 1331d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com, 1332d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1333d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com, 1334d613b6a7SJames Smart FCP_COMMAND_TSEND); 1335d613b6a7SJames Smart 1336d613b6a7SJames Smart /* Word 12 */ 1337d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 1338d613b6a7SJames Smart 1339d613b6a7SJames Smart /* Setup 2 SKIP SGEs */ 1340d613b6a7SJames Smart sgl->addr_hi = 0; 1341d613b6a7SJames Smart sgl->addr_lo = 0; 1342d613b6a7SJames Smart sgl->word2 = 0; 1343d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1344d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1345d613b6a7SJames Smart sgl->sge_len = 0; 1346d613b6a7SJames Smart sgl++; 1347d613b6a7SJames Smart sgl->addr_hi = 0; 1348d613b6a7SJames Smart sgl->addr_lo = 0; 1349d613b6a7SJames Smart sgl->word2 = 0; 1350d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1351d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1352d613b6a7SJames Smart sgl->sge_len = 0; 1353d613b6a7SJames Smart sgl++; 1354d613b6a7SJames Smart if (rsp->op == NVMET_FCOP_READDATA_RSP) { 1355d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read_rsp); 1356d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1); 1357d613b6a7SJames Smart if ((ndlp->nlp_flag & NLP_SUPPRESS_RSP) && 1358d613b6a7SJames Smart (rsp->rsplen == 12)) { 1359d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 1); 1360d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 1361d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 1362d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 1363d613b6a7SJames Smart } else { 1364d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1365d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1); 1366d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1); 1367d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 1368d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 1369d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, 1370d613b6a7SJames Smart rsp->rsplen); 1371d613b6a7SJames Smart } 1372d613b6a7SJames Smart } else { 1373d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_read); 1374d613b6a7SJames Smart 1375d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1376d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0); 1377d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0); 1378d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0); 1379d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0); 1380d613b6a7SJames Smart } 1381d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 1382d613b6a7SJames Smart break; 1383d613b6a7SJames Smart 1384d613b6a7SJames Smart case NVMET_FCOP_WRITEDATA: 1385d613b6a7SJames Smart /* Words 0 - 2 : The first sg segment */ 1386d613b6a7SJames Smart txrdy = pci_pool_alloc(phba->txrdy_payload_pool, 1387d613b6a7SJames Smart GFP_KERNEL, &physaddr); 1388d613b6a7SJames Smart if (!txrdy) { 1389d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 1390d613b6a7SJames Smart "6041 Bad txrdy buffer: oxid x%x\n", 1391d613b6a7SJames Smart ctxp->oxid); 1392d613b6a7SJames Smart return NULL; 1393d613b6a7SJames Smart } 1394d613b6a7SJames Smart ctxp->txrdy = txrdy; 1395d613b6a7SJames Smart ctxp->txrdy_phys = physaddr; 1396d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1397d613b6a7SJames Smart wqe->fcp_treceive.bde.tus.f.bdeSize = TXRDY_PAYLOAD_LEN; 1398d613b6a7SJames Smart wqe->fcp_treceive.bde.addrLow = 1399d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 1400d613b6a7SJames Smart wqe->fcp_treceive.bde.addrHigh = 1401d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1402d613b6a7SJames Smart 1403d613b6a7SJames Smart /* Word 3 */ 1404d613b6a7SJames Smart wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN; 1405d613b6a7SJames Smart 1406d613b6a7SJames Smart /* Word 4 */ 1407d613b6a7SJames Smart wqe->fcp_treceive.relative_offset = ctxp->offset; 1408d613b6a7SJames Smart 1409d613b6a7SJames Smart /* Word 5 */ 1410d613b6a7SJames Smart 1411d613b6a7SJames Smart /* Word 6 */ 1412d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com, 1413d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1414d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com, 1415d613b6a7SJames Smart nvmewqe->sli4_xritag); 1416d613b6a7SJames Smart 1417d613b6a7SJames Smart /* Word 7 */ 1418d613b6a7SJames Smart bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0); 1419d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com, 1420d613b6a7SJames Smart CMD_FCP_TRECEIVE64_WQE); 1421d613b6a7SJames Smart 1422d613b6a7SJames Smart /* Word 8 */ 1423d613b6a7SJames Smart wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag; 1424d613b6a7SJames Smart 1425d613b6a7SJames Smart /* Word 9 */ 1426d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag); 1427d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid); 1428d613b6a7SJames Smart 1429d613b6a7SJames Smart /* Word 10 */ 1430d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 1431d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1); 1432d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ); 1433d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com, 1434d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1435d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, xc); 1436d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0); 1437d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0); 1438d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0); 1439d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1); 1440d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1441d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_treceive.wqe_com, 1); 1442d613b6a7SJames Smart 1443d613b6a7SJames Smart /* Word 11 */ 1444d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com, 1445d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1446d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com, 1447d613b6a7SJames Smart FCP_COMMAND_TRECEIVE); 1448d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1449d613b6a7SJames Smart 1450d613b6a7SJames Smart /* Word 12 */ 1451d613b6a7SJames Smart wqe->fcp_tsend.fcp_data_len = rsp->transfer_length; 1452d613b6a7SJames Smart 1453d613b6a7SJames Smart /* Setup 1 TXRDY and 1 SKIP SGE */ 1454d613b6a7SJames Smart txrdy[0] = 0; 1455d613b6a7SJames Smart txrdy[1] = cpu_to_be32(rsp->transfer_length); 1456d613b6a7SJames Smart txrdy[2] = 0; 1457d613b6a7SJames Smart 1458d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 1459d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 1460d613b6a7SJames Smart sgl->word2 = 0; 1461d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 1462d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1463d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(TXRDY_PAYLOAD_LEN); 1464d613b6a7SJames Smart sgl++; 1465d613b6a7SJames Smart sgl->addr_hi = 0; 1466d613b6a7SJames Smart sgl->addr_lo = 0; 1467d613b6a7SJames Smart sgl->word2 = 0; 1468d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 1469d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1470d613b6a7SJames Smart sgl->sge_len = 0; 1471d613b6a7SJames Smart sgl++; 1472d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DATA; 1473d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_write); 1474d613b6a7SJames Smart break; 1475d613b6a7SJames Smart 1476d613b6a7SJames Smart case NVMET_FCOP_RSP: 1477d613b6a7SJames Smart /* Words 0 - 2 */ 1478d613b6a7SJames Smart physaddr = rsp->rspdma; 1479d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1480d613b6a7SJames Smart wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 1481d613b6a7SJames Smart wqe->fcp_trsp.bde.addrLow = 1482d613b6a7SJames Smart cpu_to_le32(putPaddrLow(physaddr)); 1483d613b6a7SJames Smart wqe->fcp_trsp.bde.addrHigh = 1484d613b6a7SJames Smart cpu_to_le32(putPaddrHigh(physaddr)); 1485d613b6a7SJames Smart 1486d613b6a7SJames Smart /* Word 3 */ 1487d613b6a7SJames Smart wqe->fcp_trsp.response_len = rsp->rsplen; 1488d613b6a7SJames Smart 1489d613b6a7SJames Smart /* Word 4 */ 1490d613b6a7SJames Smart wqe->fcp_trsp.rsvd_4_5[0] = 0; 1491d613b6a7SJames Smart 1492d613b6a7SJames Smart 1493d613b6a7SJames Smart /* Word 5 */ 1494d613b6a7SJames Smart 1495d613b6a7SJames Smart /* Word 6 */ 1496d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com, 1497d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1498d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com, 1499d613b6a7SJames Smart nvmewqe->sli4_xritag); 1500d613b6a7SJames Smart 1501d613b6a7SJames Smart /* Word 7 */ 1502d613b6a7SJames Smart bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1); 1503d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE); 1504d613b6a7SJames Smart 1505d613b6a7SJames Smart /* Word 8 */ 1506d613b6a7SJames Smart wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag; 1507d613b6a7SJames Smart 1508d613b6a7SJames Smart /* Word 9 */ 1509d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag); 1510d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid); 1511d613b6a7SJames Smart 1512d613b6a7SJames Smart /* Word 10 */ 1513d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 1514d613b6a7SJames Smart bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 0); 1515d613b6a7SJames Smart bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_WRITE); 1516d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com, 1517d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD3); 1518d613b6a7SJames Smart bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, xc); 1519d613b6a7SJames Smart bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1); 1520d613b6a7SJames Smart if (phba->cfg_nvme_oas) 1521d613b6a7SJames Smart bf_set(wqe_oas, &wqe->fcp_trsp.wqe_com, 1); 1522d613b6a7SJames Smart 1523d613b6a7SJames Smart /* Word 11 */ 1524d613b6a7SJames Smart bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com, 1525d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1526d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com, 1527d613b6a7SJames Smart FCP_COMMAND_TRSP); 1528d613b6a7SJames Smart bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0); 1529d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_RSP; 1530d613b6a7SJames Smart 1531d613b6a7SJames Smart if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) { 1532d613b6a7SJames Smart /* Good response - all zero's on wire */ 1533d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0); 1534d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0); 1535d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0); 1536d613b6a7SJames Smart } else { 1537d613b6a7SJames Smart bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1); 1538d613b6a7SJames Smart bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1); 1539d613b6a7SJames Smart bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 1540d613b6a7SJames Smart ((rsp->rsplen >> 2) - 1)); 1541d613b6a7SJames Smart memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen); 1542d613b6a7SJames Smart } 1543d613b6a7SJames Smart 1544d613b6a7SJames Smart /* Use rspbuf, NOT sg list */ 1545d613b6a7SJames Smart rsp->sg_cnt = 0; 1546d613b6a7SJames Smart sgl->word2 = 0; 1547d613b6a7SJames Smart atomic_inc(&tgtp->xmt_fcp_rsp); 1548d613b6a7SJames Smart break; 1549d613b6a7SJames Smart 1550d613b6a7SJames Smart default: 1551d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 1552d613b6a7SJames Smart "6064 Unknown Rsp Op %d\n", 1553d613b6a7SJames Smart rsp->op); 1554d613b6a7SJames Smart return NULL; 1555d613b6a7SJames Smart } 1556d613b6a7SJames Smart 1557d613b6a7SJames Smart nvmewqe->retry = 1; 1558d613b6a7SJames Smart nvmewqe->vport = phba->pport; 1559d613b6a7SJames Smart nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT; 1560d613b6a7SJames Smart nvmewqe->context1 = ndlp; 1561d613b6a7SJames Smart 1562d613b6a7SJames Smart for (i = 0; i < rsp->sg_cnt; i++) { 1563d613b6a7SJames Smart sgel = &rsp->sg[i]; 1564d613b6a7SJames Smart physaddr = sg_dma_address(sgel); 1565d613b6a7SJames Smart cnt = sg_dma_len(sgel); 1566d613b6a7SJames Smart sgl->addr_hi = putPaddrHigh(physaddr); 1567d613b6a7SJames Smart sgl->addr_lo = putPaddrLow(physaddr); 1568d613b6a7SJames Smart sgl->word2 = 0; 1569d613b6a7SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); 1570d613b6a7SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset); 1571d613b6a7SJames Smart if ((i+1) == rsp->sg_cnt) 1572d613b6a7SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1573d613b6a7SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1574d613b6a7SJames Smart sgl->sge_len = cpu_to_le32(cnt); 1575d613b6a7SJames Smart sgl++; 1576d613b6a7SJames Smart ctxp->offset += cnt; 1577d613b6a7SJames Smart } 1578d613b6a7SJames Smart return nvmewqe; 1579d613b6a7SJames Smart } 1580d613b6a7SJames Smart 1581d613b6a7SJames Smart /** 1582d613b6a7SJames Smart * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS 1583d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1584d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1585d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1586d613b6a7SJames Smart * 1587d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1588d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 1589d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1590d613b6a7SJames Smart **/ 1591d613b6a7SJames Smart static void 1592d613b6a7SJames Smart lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1593d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1594d613b6a7SJames Smart { 1595d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1596d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1597d613b6a7SJames Smart uint32_t status, result; 1598d613b6a7SJames Smart 1599d613b6a7SJames Smart ctxp = cmdwqe->context2; 1600d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1601d613b6a7SJames Smart result = wcqe->parameter; 1602d613b6a7SJames Smart 1603d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1604d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_cmpl); 1605d613b6a7SJames Smart 1606d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 1607d613b6a7SJames Smart "6165 Abort cmpl: xri x%x WCQE: %08x %08x %08x %08x\n", 1608d613b6a7SJames Smart ctxp->oxid, wcqe->word0, wcqe->total_data_placed, 1609d613b6a7SJames Smart result, wcqe->word3); 1610d613b6a7SJames Smart 1611d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 1612d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 1613d613b6a7SJames Smart 1614d613b6a7SJames Smart cmdwqe->context2 = NULL; 1615d613b6a7SJames Smart cmdwqe->context3 = NULL; 1616d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 1617d613b6a7SJames Smart } 1618d613b6a7SJames Smart 1619d613b6a7SJames Smart /** 1620d613b6a7SJames Smart * lpfc_nvmet_xmt_fcp_abort_cmp - Completion handler for ABTS 1621d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1622d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1623d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1624d613b6a7SJames Smart * 1625d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1626d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for FCP cmds 1627d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1628d613b6a7SJames Smart **/ 1629d613b6a7SJames Smart static void 1630d613b6a7SJames Smart lpfc_nvmet_xmt_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1631d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1632d613b6a7SJames Smart { 1633d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1634d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1635d613b6a7SJames Smart uint32_t status, result; 1636d613b6a7SJames Smart 1637d613b6a7SJames Smart ctxp = cmdwqe->context2; 1638d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1639d613b6a7SJames Smart result = wcqe->parameter; 1640d613b6a7SJames Smart 1641d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1642d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_cmpl); 1643d613b6a7SJames Smart 1644d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1645d613b6a7SJames Smart "6070 Abort cmpl: ctx %p WCQE: %08x %08x %08x %08x\n", 1646d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 1647d613b6a7SJames Smart result, wcqe->word3); 1648d613b6a7SJames Smart 1649d613b6a7SJames Smart if (ctxp) { 1650d613b6a7SJames Smart /* Sanity check */ 1651d613b6a7SJames Smart if (ctxp->state != LPFC_NVMET_STE_ABORT) { 1652d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 1653d613b6a7SJames Smart "6112 ABORT Wrong state:%d oxid x%x\n", 1654d613b6a7SJames Smart ctxp->state, ctxp->oxid); 1655d613b6a7SJames Smart } 1656d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_DONE; 1657d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 1658d613b6a7SJames Smart cmdwqe->context2 = NULL; 1659d613b6a7SJames Smart cmdwqe->context3 = NULL; 1660d613b6a7SJames Smart } 1661d613b6a7SJames Smart } 1662d613b6a7SJames Smart 1663d613b6a7SJames Smart /** 1664d613b6a7SJames Smart * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS 1665d613b6a7SJames Smart * @phba: Pointer to HBA context object. 1666d613b6a7SJames Smart * @cmdwqe: Pointer to driver command WQE object. 1667d613b6a7SJames Smart * @wcqe: Pointer to driver response CQE object. 1668d613b6a7SJames Smart * 1669d613b6a7SJames Smart * The function is called from SLI ring event handler with no 1670d613b6a7SJames Smart * lock held. This function is the completion handler for NVME ABTS for LS cmds 1671d613b6a7SJames Smart * The function frees memory resources used for the NVME commands. 1672d613b6a7SJames Smart **/ 1673d613b6a7SJames Smart static void 1674d613b6a7SJames Smart lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 1675d613b6a7SJames Smart struct lpfc_wcqe_complete *wcqe) 1676d613b6a7SJames Smart { 1677d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp; 1678d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1679d613b6a7SJames Smart uint32_t status, result; 1680d613b6a7SJames Smart 1681d613b6a7SJames Smart ctxp = cmdwqe->context2; 1682d613b6a7SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 1683d613b6a7SJames Smart result = wcqe->parameter; 1684d613b6a7SJames Smart 1685d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1686d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_cmpl); 1687d613b6a7SJames Smart 1688d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1689d613b6a7SJames Smart "6083 Abort cmpl: ctx %p WCQE: %08x %08x %08x %08x\n", 1690d613b6a7SJames Smart ctxp, wcqe->word0, wcqe->total_data_placed, 1691d613b6a7SJames Smart result, wcqe->word3); 1692d613b6a7SJames Smart 1693d613b6a7SJames Smart if (ctxp) { 1694d613b6a7SJames Smart cmdwqe->context2 = NULL; 1695d613b6a7SJames Smart cmdwqe->context3 = NULL; 1696d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 1697d613b6a7SJames Smart kfree(ctxp); 1698d613b6a7SJames Smart } else 1699d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 1700d613b6a7SJames Smart } 1701d613b6a7SJames Smart 1702d613b6a7SJames Smart static int 1703d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba, 1704d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1705d613b6a7SJames Smart uint32_t sid, uint16_t xri) 1706d613b6a7SJames Smart { 1707d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1708d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 1709d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 1710d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1711d613b6a7SJames Smart 1712d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1713318083adSJames Smart "6067 Abort: sid %x xri x%x/x%x\n", 1714318083adSJames Smart sid, xri, ctxp->wqeq->sli4_xritag); 1715d613b6a7SJames Smart 1716d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1717d613b6a7SJames Smart 1718d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 1719d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1720d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1721d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1722d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 1723d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1724d613b6a7SJames Smart "6134 Drop ABTS - wrong NDLP state x%x.\n", 1725b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 1726d613b6a7SJames Smart 1727d613b6a7SJames Smart /* No failure to an ABTS request. */ 1728d613b6a7SJames Smart return 0; 1729d613b6a7SJames Smart } 1730d613b6a7SJames Smart 1731d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 1732d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 1733d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 1734d613b6a7SJames Smart 1735d613b6a7SJames Smart /* 1736d613b6a7SJames Smart * Since we zero the whole WQE, we need to ensure we set the WQE fields 1737d613b6a7SJames Smart * that were initialized in lpfc_sli4_nvmet_alloc. 1738d613b6a7SJames Smart */ 1739d613b6a7SJames Smart memset(wqe_abts, 0, sizeof(union lpfc_wqe)); 1740d613b6a7SJames Smart 1741d613b6a7SJames Smart /* Word 5 */ 1742d613b6a7SJames Smart bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0); 1743d613b6a7SJames Smart bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1); 1744d613b6a7SJames Smart bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0); 1745d613b6a7SJames Smart bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS); 1746d613b6a7SJames Smart bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS); 1747d613b6a7SJames Smart 1748d613b6a7SJames Smart /* Word 6 */ 1749d613b6a7SJames Smart bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com, 1750d613b6a7SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 1751d613b6a7SJames Smart bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com, 1752d613b6a7SJames Smart abts_wqeq->sli4_xritag); 1753d613b6a7SJames Smart 1754d613b6a7SJames Smart /* Word 7 */ 1755d613b6a7SJames Smart bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com, 1756d613b6a7SJames Smart CMD_XMIT_SEQUENCE64_WQE); 1757d613b6a7SJames Smart bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI); 1758d613b6a7SJames Smart bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3); 1759d613b6a7SJames Smart bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0); 1760d613b6a7SJames Smart 1761d613b6a7SJames Smart /* Word 8 */ 1762d613b6a7SJames Smart wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag; 1763d613b6a7SJames Smart 1764d613b6a7SJames Smart /* Word 9 */ 1765d613b6a7SJames Smart bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag); 1766d613b6a7SJames Smart /* Needs to be set by caller */ 1767d613b6a7SJames Smart bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri); 1768d613b6a7SJames Smart 1769d613b6a7SJames Smart /* Word 10 */ 1770d613b6a7SJames Smart bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1); 1771d613b6a7SJames Smart bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE); 1772d613b6a7SJames Smart bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com, 1773d613b6a7SJames Smart LPFC_WQE_LENLOC_WORD12); 1774d613b6a7SJames Smart bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0); 1775d613b6a7SJames Smart bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0); 1776d613b6a7SJames Smart 1777d613b6a7SJames Smart /* Word 11 */ 1778d613b6a7SJames Smart bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com, 1779d613b6a7SJames Smart LPFC_WQE_CQ_ID_DEFAULT); 1780d613b6a7SJames Smart bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com, 1781d613b6a7SJames Smart OTHER_COMMAND); 1782d613b6a7SJames Smart 1783d613b6a7SJames Smart abts_wqeq->vport = phba->pport; 1784d613b6a7SJames Smart abts_wqeq->context1 = ndlp; 1785d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 1786d613b6a7SJames Smart abts_wqeq->context3 = NULL; 1787d613b6a7SJames Smart abts_wqeq->rsvd2 = 0; 1788d613b6a7SJames Smart /* hba_wqidx should already be setup from command we are aborting */ 1789d613b6a7SJames Smart abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR; 1790d613b6a7SJames Smart abts_wqeq->iocb.ulpLe = 1; 1791d613b6a7SJames Smart 1792d613b6a7SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1793d613b6a7SJames Smart "6069 Issue ABTS to xri x%x reqtag x%x\n", 1794d613b6a7SJames Smart xri, abts_wqeq->iotag); 1795d613b6a7SJames Smart return 1; 1796d613b6a7SJames Smart } 1797d613b6a7SJames Smart 1798d613b6a7SJames Smart static int 1799d613b6a7SJames Smart lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba, 1800d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1801d613b6a7SJames Smart uint32_t sid, uint16_t xri) 1802d613b6a7SJames Smart { 1803d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1804d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 1805d613b6a7SJames Smart union lpfc_wqe *abts_wqe; 1806d613b6a7SJames Smart struct lpfc_nodelist *ndlp; 1807d613b6a7SJames Smart unsigned long flags; 1808d613b6a7SJames Smart int rc; 1809d613b6a7SJames Smart 1810d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1811d613b6a7SJames Smart if (!ctxp->wqeq) { 1812d613b6a7SJames Smart ctxp->wqeq = ctxp->rqb_buffer->iocbq; 1813d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 1814d613b6a7SJames Smart } 1815d613b6a7SJames Smart 1816d613b6a7SJames Smart ndlp = lpfc_findnode_did(phba->pport, sid); 1817d613b6a7SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || 1818d613b6a7SJames Smart ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 1819d613b6a7SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { 1820d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 1821d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1822d613b6a7SJames Smart "6160 Drop ABTS - wrong NDLP state x%x.\n", 1823b5ccc7d6SJames Smart (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE); 1824d613b6a7SJames Smart 1825d613b6a7SJames Smart /* No failure to an ABTS request. */ 1826d613b6a7SJames Smart return 0; 1827d613b6a7SJames Smart } 1828d613b6a7SJames Smart 1829d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 1830d613b6a7SJames Smart ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba); 1831d613b6a7SJames Smart if (!ctxp->abort_wqeq) { 1832d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1833d613b6a7SJames Smart "6161 Abort failed: No wqeqs: " 1834d613b6a7SJames Smart "xri: x%x\n", ctxp->oxid); 1835d613b6a7SJames Smart /* No failure to an ABTS request. */ 1836d613b6a7SJames Smart return 0; 1837d613b6a7SJames Smart } 1838d613b6a7SJames Smart abts_wqeq = ctxp->abort_wqeq; 1839d613b6a7SJames Smart abts_wqe = &abts_wqeq->wqe; 1840d613b6a7SJames Smart ctxp->state = LPFC_NVMET_STE_ABORT; 1841d613b6a7SJames Smart 1842d613b6a7SJames Smart /* Announce entry to new IO submit field. */ 1843d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS, 1844d613b6a7SJames Smart "6162 Abort Request to rport DID x%06x " 1845d613b6a7SJames Smart "for xri x%x x%x\n", 1846d613b6a7SJames Smart ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag); 1847d613b6a7SJames Smart 1848d613b6a7SJames Smart /* If the hba is getting reset, this flag is set. It is 1849d613b6a7SJames Smart * cleared when the reset is complete and rings reestablished. 1850d613b6a7SJames Smart */ 1851d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 1852d613b6a7SJames Smart /* driver queued commands are in process of being flushed */ 1853d613b6a7SJames Smart if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) { 1854d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1855d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 1856d613b6a7SJames Smart "6163 Driver in reset cleanup - flushing " 1857d613b6a7SJames Smart "NVME Req now. hba_flag x%x oxid x%x\n", 1858d613b6a7SJames Smart phba->hba_flag, ctxp->oxid); 1859d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 1860d613b6a7SJames Smart return 0; 1861d613b6a7SJames Smart } 1862d613b6a7SJames Smart 1863d613b6a7SJames Smart /* Outstanding abort is in progress */ 1864d613b6a7SJames Smart if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) { 1865d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1866d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 1867d613b6a7SJames Smart "6164 Outstanding NVME I/O Abort Request " 1868d613b6a7SJames Smart "still pending on oxid x%x\n", 1869d613b6a7SJames Smart ctxp->oxid); 1870d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 1871d613b6a7SJames Smart return 0; 1872d613b6a7SJames Smart } 1873d613b6a7SJames Smart 1874d613b6a7SJames Smart /* Ready - mark outstanding as aborted by driver. */ 1875d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED; 1876d613b6a7SJames Smart 1877d613b6a7SJames Smart /* WQEs are reused. Clear stale data and set key fields to 1878d613b6a7SJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 1879d613b6a7SJames Smart */ 1880d613b6a7SJames Smart memset(abts_wqe, 0, sizeof(union lpfc_wqe)); 1881d613b6a7SJames Smart 1882d613b6a7SJames Smart /* word 3 */ 1883d613b6a7SJames Smart bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); 1884d613b6a7SJames Smart 1885d613b6a7SJames Smart /* word 7 */ 1886d613b6a7SJames Smart bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); 1887d613b6a7SJames Smart bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 1888d613b6a7SJames Smart 1889d613b6a7SJames Smart /* word 8 - tell the FW to abort the IO associated with this 1890d613b6a7SJames Smart * outstanding exchange ID. 1891d613b6a7SJames Smart */ 1892d613b6a7SJames Smart abts_wqe->abort_cmd.wqe_com.abort_tag = ctxp->wqeq->sli4_xritag; 1893d613b6a7SJames Smart 1894d613b6a7SJames Smart /* word 9 - this is the iotag for the abts_wqe completion. */ 1895d613b6a7SJames Smart bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, 1896d613b6a7SJames Smart abts_wqeq->iotag); 1897d613b6a7SJames Smart 1898d613b6a7SJames Smart /* word 10 */ 1899d613b6a7SJames Smart bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); 1900d613b6a7SJames Smart bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 1901d613b6a7SJames Smart 1902d613b6a7SJames Smart /* word 11 */ 1903d613b6a7SJames Smart bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); 1904d613b6a7SJames Smart bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); 1905d613b6a7SJames Smart bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1906d613b6a7SJames Smart 1907d613b6a7SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 1908d613b6a7SJames Smart abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx; 1909d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp; 1910d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 1911d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME; 1912d613b6a7SJames Smart abts_wqeq->context2 = ctxp; 1913d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 1914d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1915d613b6a7SJames Smart if (rc == WQE_SUCCESS) 1916d613b6a7SJames Smart return 0; 1917d613b6a7SJames Smart 1918d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 1919d613b6a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME, 1920d613b6a7SJames Smart "6166 Failed abts issue_wqe with status x%x " 1921d613b6a7SJames Smart "for oxid x%x.\n", 1922d613b6a7SJames Smart rc, ctxp->oxid); 1923d613b6a7SJames Smart return 1; 1924d613b6a7SJames Smart } 1925d613b6a7SJames Smart 1926d613b6a7SJames Smart 1927d613b6a7SJames Smart static int 1928d613b6a7SJames Smart lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba, 1929d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1930d613b6a7SJames Smart uint32_t sid, uint16_t xri) 1931d613b6a7SJames Smart { 1932d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1933d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 1934d613b6a7SJames Smart unsigned long flags; 1935d613b6a7SJames Smart int rc; 1936d613b6a7SJames Smart 1937d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1938d613b6a7SJames Smart if (!ctxp->wqeq) { 1939d613b6a7SJames Smart ctxp->wqeq = ctxp->rqb_buffer->iocbq; 1940d613b6a7SJames Smart ctxp->wqeq->hba_wqidx = 0; 1941d613b6a7SJames Smart } 1942d613b6a7SJames Smart 1943d613b6a7SJames Smart rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 1944d613b6a7SJames Smart if (rc == 0) 1945d613b6a7SJames Smart goto aerr; 1946d613b6a7SJames Smart 1947d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 1948d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 1949d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_abort_cmp; 1950d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 1951d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVMET; 1952d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq); 1953d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1954d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 1955d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 1956d613b6a7SJames Smart return 0; 1957d613b6a7SJames Smart } 1958d613b6a7SJames Smart 1959d613b6a7SJames Smart aerr: 1960d613b6a7SJames Smart lpfc_nvmet_rq_post(phba, ctxp, &ctxp->rqb_buffer->hbuf); 1961d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 1962d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1963d613b6a7SJames Smart "6135 Failed to Issue ABTS for oxid x%x. Status x%x\n", 1964d613b6a7SJames Smart ctxp->oxid, rc); 1965d613b6a7SJames Smart return 1; 1966d613b6a7SJames Smart } 1967d613b6a7SJames Smart 1968d613b6a7SJames Smart static int 1969d613b6a7SJames Smart lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *phba, 1970d613b6a7SJames Smart struct lpfc_nvmet_rcv_ctx *ctxp, 1971d613b6a7SJames Smart uint32_t sid, uint16_t xri) 1972d613b6a7SJames Smart { 1973d613b6a7SJames Smart struct lpfc_nvmet_tgtport *tgtp; 1974d613b6a7SJames Smart struct lpfc_iocbq *abts_wqeq; 1975d613b6a7SJames Smart union lpfc_wqe *wqe_abts; 1976d613b6a7SJames Smart unsigned long flags; 1977d613b6a7SJames Smart int rc; 1978d613b6a7SJames Smart 1979d613b6a7SJames Smart tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1980d613b6a7SJames Smart if (!ctxp->wqeq) { 1981d613b6a7SJames Smart /* Issue ABTS for this WQE based on iotag */ 1982d613b6a7SJames Smart ctxp->wqeq = lpfc_sli_get_iocbq(phba); 1983d613b6a7SJames Smart if (!ctxp->wqeq) { 1984d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1985d613b6a7SJames Smart "6068 Abort failed: No wqeqs: " 1986d613b6a7SJames Smart "xri: x%x\n", xri); 1987d613b6a7SJames Smart /* No failure to an ABTS request. */ 1988d613b6a7SJames Smart kfree(ctxp); 1989d613b6a7SJames Smart return 0; 1990d613b6a7SJames Smart } 1991d613b6a7SJames Smart } 1992d613b6a7SJames Smart abts_wqeq = ctxp->wqeq; 1993d613b6a7SJames Smart wqe_abts = &abts_wqeq->wqe; 1994d613b6a7SJames Smart lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri); 1995d613b6a7SJames Smart 1996d613b6a7SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 1997d613b6a7SJames Smart abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp; 1998d613b6a7SJames Smart abts_wqeq->iocb_cmpl = 0; 1999d613b6a7SJames Smart abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS; 2000d613b6a7SJames Smart rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, abts_wqeq); 2001d613b6a7SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 2002d613b6a7SJames Smart if (rc == WQE_SUCCESS) { 2003d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp); 2004d613b6a7SJames Smart return 0; 2005d613b6a7SJames Smart } 2006d613b6a7SJames Smart 2007d613b6a7SJames Smart atomic_inc(&tgtp->xmt_abort_rsp_error); 2008d613b6a7SJames Smart abts_wqeq->context2 = NULL; 2009d613b6a7SJames Smart abts_wqeq->context3 = NULL; 2010d613b6a7SJames Smart lpfc_sli_release_iocbq(phba, abts_wqeq); 2011d613b6a7SJames Smart kfree(ctxp); 2012d613b6a7SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 2013d613b6a7SJames Smart "6056 Failed to Issue ABTS. Status x%x\n", rc); 2014d613b6a7SJames Smart return 0; 2015d613b6a7SJames Smart } 2016