101649561SJames Smart /******************************************************************* 201649561SJames Smart * This file is part of the Emulex Linux Device Driver for * 301649561SJames Smart * Fibre Channel Host Bus Adapters. * 40d041215SJames Smart * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term * 53e21d1cbSJames Smart * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 601649561SJames Smart * Copyright (C) 2004-2016 Emulex. All rights reserved. * 701649561SJames Smart * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 901649561SJames Smart * Portions Copyright (C) 2004-2005 Christoph Hellwig * 1001649561SJames Smart * * 1101649561SJames Smart * This program is free software; you can redistribute it and/or * 1201649561SJames Smart * modify it under the terms of version 2 of the GNU General * 1301649561SJames Smart * Public License as published by the Free Software Foundation. * 1401649561SJames Smart * This program is distributed in the hope that it will be useful. * 1501649561SJames Smart * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 1601649561SJames Smart * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 1701649561SJames Smart * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 1801649561SJames Smart * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 1901649561SJames Smart * TO BE LEGALLY INVALID. See the GNU General Public License for * 2001649561SJames Smart * more details, a copy of which can be found in the file COPYING * 2101649561SJames Smart * included with this package. * 2201649561SJames Smart ********************************************************************/ 2301649561SJames Smart #include <linux/pci.h> 2401649561SJames Smart #include <linux/slab.h> 2501649561SJames Smart #include <linux/interrupt.h> 2601649561SJames Smart #include <linux/delay.h> 2701649561SJames Smart #include <asm/unaligned.h> 2801649561SJames Smart #include <linux/crc-t10dif.h> 2901649561SJames Smart #include <net/checksum.h> 3001649561SJames Smart 3101649561SJames Smart #include <scsi/scsi.h> 3201649561SJames Smart #include <scsi/scsi_device.h> 3301649561SJames Smart #include <scsi/scsi_eh.h> 3401649561SJames Smart #include <scsi/scsi_host.h> 3501649561SJames Smart #include <scsi/scsi_tcq.h> 3601649561SJames Smart #include <scsi/scsi_transport_fc.h> 3701649561SJames Smart #include <scsi/fc/fc_fs.h> 3801649561SJames Smart 3901649561SJames Smart #include "lpfc_version.h" 4001649561SJames Smart #include "lpfc_hw4.h" 4101649561SJames Smart #include "lpfc_hw.h" 4201649561SJames Smart #include "lpfc_sli.h" 4301649561SJames Smart #include "lpfc_sli4.h" 4401649561SJames Smart #include "lpfc_nl.h" 4501649561SJames Smart #include "lpfc_disc.h" 4601649561SJames Smart #include "lpfc.h" 4701649561SJames Smart #include "lpfc_nvme.h" 4801649561SJames Smart #include "lpfc_scsi.h" 4901649561SJames Smart #include "lpfc_logmsg.h" 5001649561SJames Smart #include "lpfc_crtn.h" 5101649561SJames Smart #include "lpfc_vport.h" 52bd2cdd5eSJames Smart #include "lpfc_debugfs.h" 5301649561SJames Smart 5401649561SJames Smart /* NVME initiator-based functions */ 5501649561SJames Smart 56c490850aSJames Smart static struct lpfc_io_buf * 57cf1a1d3eSJames Smart lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 585e5b511dSJames Smart int idx, int expedite); 5901649561SJames Smart 6001649561SJames Smart static void 61c490850aSJames Smart lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_io_buf *); 6201649561SJames Smart 6381e6a637SJames Smart static struct nvme_fc_port_template lpfc_nvme_template; 6401649561SJames Smart 65fab2e466SColin Ian King static union lpfc_wqe128 lpfc_iread_cmd_template; 66fab2e466SColin Ian King static union lpfc_wqe128 lpfc_iwrite_cmd_template; 67fab2e466SColin Ian King static union lpfc_wqe128 lpfc_icmnd_cmd_template; 685fd11085SJames Smart 695fd11085SJames Smart /* Setup WQE templates for NVME IOs */ 705fd11085SJames Smart void 71fab2e466SColin Ian King lpfc_nvme_cmd_template(void) 725fd11085SJames Smart { 735fd11085SJames Smart union lpfc_wqe128 *wqe; 745fd11085SJames Smart 755fd11085SJames Smart /* IREAD template */ 765fd11085SJames Smart wqe = &lpfc_iread_cmd_template; 775fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 785fd11085SJames Smart 795fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 805fd11085SJames Smart 815fd11085SJames Smart /* Word 3 - cmd_buff_len, payload_offset_len is zero */ 825fd11085SJames Smart 835fd11085SJames Smart /* Word 4 - total_xfer_len is variable */ 845fd11085SJames Smart 855fd11085SJames Smart /* Word 5 - is zero */ 865fd11085SJames Smart 875fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 885fd11085SJames Smart 895fd11085SJames Smart /* Word 7 */ 905fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE); 915fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK); 925fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3); 935fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI); 945fd11085SJames Smart 955fd11085SJames Smart /* Word 8 - abort_tag is variable */ 965fd11085SJames Smart 975fd11085SJames Smart /* Word 9 - reqtag is variable */ 985fd11085SJames Smart 995fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1005fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0); 1015fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_iread.wqe_com, 1); 1025fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); 1035fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4); 1045fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); 1055fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); 1065fd11085SJames Smart 1075fd11085SJames Smart /* Word 11 - pbde is variable */ 1085fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, NVME_READ_CMD); 1095fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1105fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); 1115fd11085SJames Smart 1125fd11085SJames Smart /* Word 12 - is zero */ 1135fd11085SJames Smart 1145fd11085SJames Smart /* Word 13, 14, 15 - PBDE is variable */ 1155fd11085SJames Smart 1165fd11085SJames Smart /* IWRITE template */ 1175fd11085SJames Smart wqe = &lpfc_iwrite_cmd_template; 1185fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 1195fd11085SJames Smart 1205fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 1215fd11085SJames Smart 1225fd11085SJames Smart /* Word 3 - cmd_buff_len, payload_offset_len is zero */ 1235fd11085SJames Smart 1245fd11085SJames Smart /* Word 4 - total_xfer_len is variable */ 1255fd11085SJames Smart 1265fd11085SJames Smart /* Word 5 - initial_xfer_len is variable */ 1275fd11085SJames Smart 1285fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 1295fd11085SJames Smart 1305fd11085SJames Smart /* Word 7 */ 1315fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE); 1325fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK); 1335fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3); 1345fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI); 1355fd11085SJames Smart 1365fd11085SJames Smart /* Word 8 - abort_tag is variable */ 1375fd11085SJames Smart 1385fd11085SJames Smart /* Word 9 - reqtag is variable */ 1395fd11085SJames Smart 1405fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1415fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0); 1425fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_iwrite.wqe_com, 1); 1435fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); 1445fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4); 1455fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); 1465fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); 1475fd11085SJames Smart 1485fd11085SJames Smart /* Word 11 - pbde is variable */ 1495fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, NVME_WRITE_CMD); 1505fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1515fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); 1525fd11085SJames Smart 1535fd11085SJames Smart /* Word 12 - is zero */ 1545fd11085SJames Smart 1555fd11085SJames Smart /* Word 13, 14, 15 - PBDE is variable */ 1565fd11085SJames Smart 1575fd11085SJames Smart /* ICMND template */ 1585fd11085SJames Smart wqe = &lpfc_icmnd_cmd_template; 1595fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 1605fd11085SJames Smart 1615fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 1625fd11085SJames Smart 1635fd11085SJames Smart /* Word 3 - payload_offset_len is variable */ 1645fd11085SJames Smart 1655fd11085SJames Smart /* Word 4, 5 - is zero */ 1665fd11085SJames Smart 1675fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 1685fd11085SJames Smart 1695fd11085SJames Smart /* Word 7 */ 1705fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE); 1715fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); 1725fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3); 1735fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI); 1745fd11085SJames Smart 1755fd11085SJames Smart /* Word 8 - abort_tag is variable */ 1765fd11085SJames Smart 1775fd11085SJames Smart /* Word 9 - reqtag is variable */ 1785fd11085SJames Smart 1795fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1805fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); 1815fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_icmd.wqe_com, 1); 1825fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE); 1835fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE); 1845fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); 1855fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); 1865fd11085SJames Smart 1875fd11085SJames Smart /* Word 11 */ 1885fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, FCP_COMMAND); 1895fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1905fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0); 1915fd11085SJames Smart 1925fd11085SJames Smart /* Word 12, 13, 14, 15 - is zero */ 1935fd11085SJames Smart } 1945fd11085SJames Smart 19501649561SJames Smart /** 19651f8e43eSJames Smart * lpfc_nvme_prep_abort_wqe - set up 'abort' work queue entry. 19751f8e43eSJames Smart * @pwqeq: Pointer to command iocb. 19851f8e43eSJames Smart * @xritag: Tag that uniqely identifies the local exchange resource. 19951f8e43eSJames Smart * @opt: Option bits - 20051f8e43eSJames Smart * bit 0 = inhibit sending abts on the link 20151f8e43eSJames Smart * 20251f8e43eSJames Smart * This function is called with hbalock held. 20351f8e43eSJames Smart **/ 20451f8e43eSJames Smart void 20551f8e43eSJames Smart lpfc_nvme_prep_abort_wqe(struct lpfc_iocbq *pwqeq, u16 xritag, u8 opt) 20651f8e43eSJames Smart { 20751f8e43eSJames Smart union lpfc_wqe128 *wqe = &pwqeq->wqe; 20851f8e43eSJames Smart 20951f8e43eSJames Smart /* WQEs are reused. Clear stale data and set key fields to 21051f8e43eSJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 21151f8e43eSJames Smart */ 21251f8e43eSJames Smart memset(wqe, 0, sizeof(*wqe)); 21351f8e43eSJames Smart 21451f8e43eSJames Smart if (opt & INHIBIT_ABORT) 21551f8e43eSJames Smart bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); 21651f8e43eSJames Smart /* Abort specified xri tag, with the mask deliberately zeroed */ 21751f8e43eSJames Smart bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); 21851f8e43eSJames Smart 21951f8e43eSJames Smart bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 22051f8e43eSJames Smart 22151f8e43eSJames Smart /* Abort the IO associated with this outstanding exchange ID. */ 22251f8e43eSJames Smart wqe->abort_cmd.wqe_com.abort_tag = xritag; 22351f8e43eSJames Smart 22451f8e43eSJames Smart /* iotag for the wqe completion. */ 22551f8e43eSJames Smart bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, pwqeq->iotag); 22651f8e43eSJames Smart 22751f8e43eSJames Smart bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); 22851f8e43eSJames Smart bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 22951f8e43eSJames Smart 23051f8e43eSJames Smart bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND); 23151f8e43eSJames Smart bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1); 23251f8e43eSJames Smart bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 23351f8e43eSJames Smart } 23451f8e43eSJames Smart 23551f8e43eSJames Smart /** 23601649561SJames Smart * lpfc_nvme_create_queue - 23701649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 23801649561SJames Smart * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. 23901649561SJames Smart * @handle: An opaque driver handle used in follow-up calls. 24001649561SJames Smart * 24101649561SJames Smart * Driver registers this routine to preallocate and initialize any 24201649561SJames Smart * internal data structures to bind the @qidx to its internal IO queues. 24301649561SJames Smart * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ. 24401649561SJames Smart * 24501649561SJames Smart * Return value : 24601649561SJames Smart * 0 - Success 24701649561SJames Smart * -EINVAL - Unsupported input value. 24801649561SJames Smart * -ENOMEM - Could not alloc necessary memory 24901649561SJames Smart **/ 25001649561SJames Smart static int 25101649561SJames Smart lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport, 25201649561SJames Smart unsigned int qidx, u16 qsize, 25301649561SJames Smart void **handle) 25401649561SJames Smart { 25501649561SJames Smart struct lpfc_nvme_lport *lport; 25601649561SJames Smart struct lpfc_vport *vport; 25701649561SJames Smart struct lpfc_nvme_qhandle *qhandle; 25801649561SJames Smart char *str; 25901649561SJames Smart 260c3725bdcSJames Smart if (!pnvme_lport->private) 261c3725bdcSJames Smart return -ENOMEM; 262c3725bdcSJames Smart 26301649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 26401649561SJames Smart vport = lport->vport; 26501649561SJames Smart qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL); 26601649561SJames Smart if (qhandle == NULL) 26701649561SJames Smart return -ENOMEM; 26801649561SJames Smart 269d6d189ceSBart Van Assche qhandle->cpu_id = raw_smp_processor_id(); 27001649561SJames Smart qhandle->qidx = qidx; 27101649561SJames Smart /* 27201649561SJames Smart * NVME qidx == 0 is the admin queue, so both admin queue 27301649561SJames Smart * and first IO queue will use MSI-X vector and associated 27401649561SJames Smart * EQ/CQ/WQ at index 0. After that they are sequentially assigned. 27501649561SJames Smart */ 27601649561SJames Smart if (qidx) { 27701649561SJames Smart str = "IO "; /* IO queue */ 27801649561SJames Smart qhandle->index = ((qidx - 1) % 2796a828b0fSJames Smart lpfc_nvme_template.max_hw_queues); 28001649561SJames Smart } else { 28101649561SJames Smart str = "ADM"; /* Admin queue */ 28201649561SJames Smart qhandle->index = qidx; 28301649561SJames Smart } 28401649561SJames Smart 285d58734f0SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 28601649561SJames Smart "6073 Binding %s HdwQueue %d (cpu %d) to " 28732350664SJames Smart "hdw_queue %d qhandle x%px\n", str, 28801649561SJames Smart qidx, qhandle->cpu_id, qhandle->index, qhandle); 28901649561SJames Smart *handle = (void *)qhandle; 29001649561SJames Smart return 0; 29101649561SJames Smart } 29201649561SJames Smart 29301649561SJames Smart /** 29401649561SJames Smart * lpfc_nvme_delete_queue - 29501649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 29601649561SJames Smart * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. 29701649561SJames Smart * @handle: An opaque driver handle from lpfc_nvme_create_queue 29801649561SJames Smart * 29901649561SJames Smart * Driver registers this routine to free 30001649561SJames Smart * any internal data structures to bind the @qidx to its internal 30101649561SJames Smart * IO queues. 30201649561SJames Smart * 30301649561SJames Smart * Return value : 30401649561SJames Smart * 0 - Success 30501649561SJames Smart * TODO: What are the failure codes. 30601649561SJames Smart **/ 30701649561SJames Smart static void 30801649561SJames Smart lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport, 30901649561SJames Smart unsigned int qidx, 31001649561SJames Smart void *handle) 31101649561SJames Smart { 31201649561SJames Smart struct lpfc_nvme_lport *lport; 31301649561SJames Smart struct lpfc_vport *vport; 31401649561SJames Smart 315c3725bdcSJames Smart if (!pnvme_lport->private) 316c3725bdcSJames Smart return; 317c3725bdcSJames Smart 31801649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 31901649561SJames Smart vport = lport->vport; 32001649561SJames Smart 32101649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 32232350664SJames Smart "6001 ENTER. lpfc_pnvme x%px, qidx x%x qhandle x%px\n", 32301649561SJames Smart lport, qidx, handle); 32401649561SJames Smart kfree(handle); 32501649561SJames Smart } 32601649561SJames Smart 32701649561SJames Smart static void 32801649561SJames Smart lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport) 32901649561SJames Smart { 33001649561SJames Smart struct lpfc_nvme_lport *lport = localport->private; 33101649561SJames Smart 332add9d6beSJames Smart lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME, 33332350664SJames Smart "6173 localport x%px delete complete\n", 334add9d6beSJames Smart lport); 335add9d6beSJames Smart 33601649561SJames Smart /* release any threads waiting for the unreg to complete */ 3377961cba6SEwan D. Milne if (lport->vport->localport) 3387961cba6SEwan D. Milne complete(lport->lport_unreg_cmp); 33901649561SJames Smart } 34001649561SJames Smart 34101649561SJames Smart /* lpfc_nvme_remoteport_delete 34201649561SJames Smart * 34301649561SJames Smart * @remoteport: Pointer to an nvme transport remoteport instance. 34401649561SJames Smart * 34501649561SJames Smart * This is a template downcall. NVME transport calls this function 34601649561SJames Smart * when it has completed the unregistration of a previously 34701649561SJames Smart * registered remoteport. 34801649561SJames Smart * 34901649561SJames Smart * Return value : 35001649561SJames Smart * None 35101649561SJames Smart */ 3523999df75SBart Van Assche static void 35301649561SJames Smart lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport) 35401649561SJames Smart { 35501649561SJames Smart struct lpfc_nvme_rport *rport = remoteport->private; 35601649561SJames Smart struct lpfc_vport *vport; 35701649561SJames Smart struct lpfc_nodelist *ndlp; 35801649561SJames Smart 35901649561SJames Smart ndlp = rport->ndlp; 36001649561SJames Smart if (!ndlp) 36101649561SJames Smart goto rport_err; 36201649561SJames Smart 36301649561SJames Smart vport = ndlp->vport; 36401649561SJames Smart if (!vport) 36501649561SJames Smart goto rport_err; 36601649561SJames Smart 36701649561SJames Smart /* Remove this rport from the lport's list - memory is owned by the 36801649561SJames Smart * transport. Remove the ndlp reference for the NVME transport before 3697a06dcd3SJames Smart * calling state machine to remove the node. 37001649561SJames Smart */ 37101649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 37232350664SJames Smart "6146 remoteport delete of remoteport x%px\n", 37301649561SJames Smart remoteport); 3743fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 375b15bd3e6SJames Smart 376b15bd3e6SJames Smart /* The register rebind might have occurred before the delete 377b15bd3e6SJames Smart * downcall. Guard against this race. 378b15bd3e6SJames Smart */ 379b15bd3e6SJames Smart if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) { 3807a06dcd3SJames Smart ndlp->nrport = NULL; 38101466024SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 3823fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 3833fd78355SJames Smart 3843fd78355SJames Smart /* Remove original register reference. The host transport 3853fd78355SJames Smart * won't reference this rport/remoteport any further. 3863fd78355SJames Smart */ 38701649561SJames Smart lpfc_nlp_put(ndlp); 388807e7353SJames Smart } else { 389807e7353SJames Smart spin_unlock_irq(&vport->phba->hbalock); 390807e7353SJames Smart } 39101649561SJames Smart 39201649561SJames Smart rport_err: 3933fd78355SJames Smart return; 39401649561SJames Smart } 39501649561SJames Smart 3963a8070c5SJames Smart /** 3973a8070c5SJames Smart * lpfc_nvme_handle_lsreq - Process an unsolicited NVME LS request 3983a8070c5SJames Smart * @phba: pointer to lpfc hba data structure. 3993a8070c5SJames Smart * @axchg: pointer to exchange context for the NVME LS request 4003a8070c5SJames Smart * 4013a8070c5SJames Smart * This routine is used for processing an asychronously received NVME LS 4023a8070c5SJames Smart * request. Any remaining validation is done and the LS is then forwarded 4033a8070c5SJames Smart * to the nvme-fc transport via nvme_fc_rcv_ls_req(). 4043a8070c5SJames Smart * 4053a8070c5SJames Smart * Returns 0 if LS was handled and delivered to the transport 4063a8070c5SJames Smart * Returns 1 if LS failed to be handled and should be dropped 4073a8070c5SJames Smart */ 4083a8070c5SJames Smart int 4093a8070c5SJames Smart lpfc_nvme_handle_lsreq(struct lpfc_hba *phba, 4103a8070c5SJames Smart struct lpfc_async_xchg_ctx *axchg) 4113a8070c5SJames Smart { 4123a8070c5SJames Smart return 1; 4133a8070c5SJames Smart } 4143a8070c5SJames Smart 415*6514b25dSJames Smart /** 416*6514b25dSJames Smart * __lpfc_nvme_ls_req_cmp - Generic completion handler for a NVME 417*6514b25dSJames Smart * LS request. 418*6514b25dSJames Smart * @phba: Pointer to HBA context object 419*6514b25dSJames Smart * @vport: The local port that issued the LS 420*6514b25dSJames Smart * @cmdwqe: Pointer to driver command WQE object. 421*6514b25dSJames Smart * @wcqe: Pointer to driver response CQE object. 422*6514b25dSJames Smart * 423*6514b25dSJames Smart * This function is the generic completion handler for NVME LS requests. 424*6514b25dSJames Smart * The function updates any states and statistics, calls the transport 425*6514b25dSJames Smart * ls_req done() routine, then tears down the command and buffers used 426*6514b25dSJames Smart * for the LS request. 427*6514b25dSJames Smart **/ 428*6514b25dSJames Smart void 429*6514b25dSJames Smart __lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_vport *vport, 430*6514b25dSJames Smart struct lpfc_iocbq *cmdwqe, 431*6514b25dSJames Smart struct lpfc_wcqe_complete *wcqe) 432*6514b25dSJames Smart { 433*6514b25dSJames Smart struct nvmefc_ls_req *pnvme_lsreq; 434*6514b25dSJames Smart struct lpfc_dmabuf *buf_ptr; 435*6514b25dSJames Smart struct lpfc_nodelist *ndlp; 436*6514b25dSJames Smart uint32_t status; 437*6514b25dSJames Smart 438*6514b25dSJames Smart pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2; 439*6514b25dSJames Smart ndlp = (struct lpfc_nodelist *)cmdwqe->context1; 440*6514b25dSJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; 441*6514b25dSJames Smart 442*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 443*6514b25dSJames Smart "6047 NVMEx LS REQ %px cmpl DID %x Xri: %x " 444*6514b25dSJames Smart "status %x reason x%x cmd:x%px lsreg:x%px bmp:x%px " 445*6514b25dSJames Smart "ndlp:x%px\n", 446*6514b25dSJames Smart pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, 447*6514b25dSJames Smart cmdwqe->sli4_xritag, status, 448*6514b25dSJames Smart (wcqe->parameter & 0xffff), 449*6514b25dSJames Smart cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp); 450*6514b25dSJames Smart 451*6514b25dSJames Smart lpfc_nvmeio_data(phba, "NVMEx LS CMPL: xri x%x stat x%x parm x%x\n", 452*6514b25dSJames Smart cmdwqe->sli4_xritag, status, wcqe->parameter); 453*6514b25dSJames Smart 454*6514b25dSJames Smart if (cmdwqe->context3) { 455*6514b25dSJames Smart buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3; 456*6514b25dSJames Smart lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 457*6514b25dSJames Smart kfree(buf_ptr); 458*6514b25dSJames Smart cmdwqe->context3 = NULL; 459*6514b25dSJames Smart } 460*6514b25dSJames Smart if (pnvme_lsreq->done) 461*6514b25dSJames Smart pnvme_lsreq->done(pnvme_lsreq, status); 462*6514b25dSJames Smart else 463*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 464*6514b25dSJames Smart "6046 NVMEx cmpl without done call back? " 465*6514b25dSJames Smart "Data %px DID %x Xri: %x status %x\n", 466*6514b25dSJames Smart pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, 467*6514b25dSJames Smart cmdwqe->sli4_xritag, status); 468*6514b25dSJames Smart if (ndlp) { 469*6514b25dSJames Smart lpfc_nlp_put(ndlp); 470*6514b25dSJames Smart cmdwqe->context1 = NULL; 471*6514b25dSJames Smart } 472*6514b25dSJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 473*6514b25dSJames Smart } 474*6514b25dSJames Smart 47501649561SJames Smart static void 476*6514b25dSJames Smart lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 47701649561SJames Smart struct lpfc_wcqe_complete *wcqe) 47801649561SJames Smart { 47901649561SJames Smart struct lpfc_vport *vport = cmdwqe->vport; 4804b056682SJames Smart struct lpfc_nvme_lport *lport; 48101649561SJames Smart uint32_t status; 48201649561SJames Smart 48301649561SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; 48466a210ffSJames Smart 48566a85155SJames Smart if (vport->localport) { 48666a85155SJames Smart lport = (struct lpfc_nvme_lport *)vport->localport->private; 48766a210ffSJames Smart if (lport) { 48866a210ffSJames Smart atomic_inc(&lport->fc4NvmeLsCmpls); 4894b056682SJames Smart if (status) { 4904b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 4914b056682SJames Smart atomic_inc(&lport->cmpl_ls_xb); 4924b056682SJames Smart atomic_inc(&lport->cmpl_ls_err); 4934b056682SJames Smart } 49466a210ffSJames Smart } 49566a85155SJames Smart } 4964b056682SJames Smart 497*6514b25dSJames Smart __lpfc_nvme_ls_req_cmp(phba, vport, cmdwqe, wcqe); 49801649561SJames Smart } 49901649561SJames Smart 50001649561SJames Smart static int 50101649561SJames Smart lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, 50201649561SJames Smart struct lpfc_dmabuf *inp, 50301649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq, 50401649561SJames Smart void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, 50501649561SJames Smart struct lpfc_wcqe_complete *), 50601649561SJames Smart struct lpfc_nodelist *ndlp, uint32_t num_entry, 50701649561SJames Smart uint32_t tmo, uint8_t retry) 50801649561SJames Smart { 50901649561SJames Smart struct lpfc_hba *phba = vport->phba; 510205e8240SJames Smart union lpfc_wqe128 *wqe; 51101649561SJames Smart struct lpfc_iocbq *genwqe; 51201649561SJames Smart struct ulp_bde64 *bpl; 51301649561SJames Smart struct ulp_bde64 bde; 51401649561SJames Smart int i, rc, xmit_len, first_len; 51501649561SJames Smart 51601649561SJames Smart /* Allocate buffer for command WQE */ 51701649561SJames Smart genwqe = lpfc_sli_get_iocbq(phba); 51801649561SJames Smart if (genwqe == NULL) 51901649561SJames Smart return 1; 52001649561SJames Smart 52101649561SJames Smart wqe = &genwqe->wqe; 522d9f492a1SJames Smart /* Initialize only 64 bytes */ 52301649561SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 52401649561SJames Smart 52501649561SJames Smart genwqe->context3 = (uint8_t *)bmp; 52601649561SJames Smart genwqe->iocb_flag |= LPFC_IO_NVME_LS; 52701649561SJames Smart 52801649561SJames Smart /* Save for completion so we can release these resources */ 52901649561SJames Smart genwqe->context1 = lpfc_nlp_get(ndlp); 53001649561SJames Smart genwqe->context2 = (uint8_t *)pnvme_lsreq; 53101649561SJames Smart /* Fill in payload, bp points to frame payload */ 53201649561SJames Smart 53301649561SJames Smart if (!tmo) 53401649561SJames Smart /* FC spec states we need 3 * ratov for CT requests */ 53501649561SJames Smart tmo = (3 * phba->fc_ratov); 53601649561SJames Smart 53701649561SJames Smart /* For this command calculate the xmit length of the request bde. */ 53801649561SJames Smart xmit_len = 0; 53901649561SJames Smart first_len = 0; 54001649561SJames Smart bpl = (struct ulp_bde64 *)bmp->virt; 54101649561SJames Smart for (i = 0; i < num_entry; i++) { 54201649561SJames Smart bde.tus.w = bpl[i].tus.w; 54301649561SJames Smart if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) 54401649561SJames Smart break; 54501649561SJames Smart xmit_len += bde.tus.f.bdeSize; 54601649561SJames Smart if (i == 0) 54701649561SJames Smart first_len = xmit_len; 54801649561SJames Smart } 54901649561SJames Smart 55001649561SJames Smart genwqe->rsvd2 = num_entry; 55101649561SJames Smart genwqe->hba_wqidx = 0; 55201649561SJames Smart 55301649561SJames Smart /* Words 0 - 2 */ 55401649561SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 55501649561SJames Smart wqe->generic.bde.tus.f.bdeSize = first_len; 55601649561SJames Smart wqe->generic.bde.addrLow = bpl[0].addrLow; 55701649561SJames Smart wqe->generic.bde.addrHigh = bpl[0].addrHigh; 55801649561SJames Smart 55901649561SJames Smart /* Word 3 */ 56001649561SJames Smart wqe->gen_req.request_payload_len = first_len; 56101649561SJames Smart 56201649561SJames Smart /* Word 4 */ 56301649561SJames Smart 56401649561SJames Smart /* Word 5 */ 56501649561SJames Smart bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0); 56601649561SJames Smart bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1); 56701649561SJames Smart bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1); 5688b361639SJames Smart bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ); 56901649561SJames Smart bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME); 57001649561SJames Smart 57101649561SJames Smart /* Word 6 */ 57201649561SJames Smart bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com, 57301649561SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 57401649561SJames Smart bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag); 57501649561SJames Smart 57601649561SJames Smart /* Word 7 */ 57701649561SJames Smart bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1)); 57801649561SJames Smart bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3); 57901649561SJames Smart bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE); 58001649561SJames Smart bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI); 58101649561SJames Smart 58201649561SJames Smart /* Word 8 */ 58301649561SJames Smart wqe->gen_req.wqe_com.abort_tag = genwqe->iotag; 58401649561SJames Smart 58501649561SJames Smart /* Word 9 */ 58601649561SJames Smart bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag); 58701649561SJames Smart 58801649561SJames Smart /* Word 10 */ 58901649561SJames Smart bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); 59001649561SJames Smart bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); 59101649561SJames Smart bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); 59201649561SJames Smart bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); 59301649561SJames Smart bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); 59401649561SJames Smart 59501649561SJames Smart /* Word 11 */ 59601649561SJames Smart bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 59701649561SJames Smart bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND); 59801649561SJames Smart 59901649561SJames Smart 60001649561SJames Smart /* Issue GEN REQ WQE for NPORT <did> */ 60101649561SJames Smart genwqe->wqe_cmpl = cmpl; 60201649561SJames Smart genwqe->iocb_cmpl = NULL; 60301649561SJames Smart genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT; 60401649561SJames Smart genwqe->vport = vport; 60501649561SJames Smart genwqe->retry = retry; 60601649561SJames Smart 607bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n", 608bd2cdd5eSJames Smart genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID); 609bd2cdd5eSJames Smart 6101fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], genwqe); 611cd22d605SDick Kennedy if (rc) { 612*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC | LOG_ELS, 61301649561SJames Smart "6045 Issue GEN REQ WQE to NPORT x%x " 614*6514b25dSJames Smart "Data: x%x x%x rc x%x\n", 61501649561SJames Smart ndlp->nlp_DID, genwqe->iotag, 616*6514b25dSJames Smart vport->port_state, rc); 61701649561SJames Smart lpfc_sli_release_iocbq(phba, genwqe); 61801649561SJames Smart return 1; 61901649561SJames Smart } 620*6514b25dSJames Smart 621*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC | LOG_ELS, 622*6514b25dSJames Smart "6050 Issue GEN REQ WQE to NPORT x%x " 623*6514b25dSJames Smart "Data: oxid: x%x state: x%x wq:x%px lsreq:x%px " 624*6514b25dSJames Smart "bmp:x%px xmit:%d 1st:%d\n", 625*6514b25dSJames Smart ndlp->nlp_DID, genwqe->sli4_xritag, 626*6514b25dSJames Smart vport->port_state, 627*6514b25dSJames Smart genwqe, pnvme_lsreq, bmp, xmit_len, first_len); 62801649561SJames Smart return 0; 62901649561SJames Smart } 63001649561SJames Smart 631*6514b25dSJames Smart 63201649561SJames Smart /** 633*6514b25dSJames Smart * __lpfc_nvme_ls_req - Generic service routine to issue an NVME LS request 634*6514b25dSJames Smart * @vport: The local port issuing the LS 635*6514b25dSJames Smart * @ndlp: The remote port to send the LS to 636*6514b25dSJames Smart * @pnvme_lsreq: Pointer to LS request structure from the transport 63701649561SJames Smart * 638*6514b25dSJames Smart * Routine validates the ndlp, builds buffers and sends a GEN_REQUEST 639*6514b25dSJames Smart * WQE to perform the LS operation. 64001649561SJames Smart * 64101649561SJames Smart * Return value : 64201649561SJames Smart * 0 - Success 643*6514b25dSJames Smart * non-zero: various error codes, in form of -Exxx 64401649561SJames Smart **/ 645*6514b25dSJames Smart int 646*6514b25dSJames Smart __lpfc_nvme_ls_req(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 647*6514b25dSJames Smart struct nvmefc_ls_req *pnvme_lsreq, 648*6514b25dSJames Smart void (*gen_req_cmp)(struct lpfc_hba *phba, 649*6514b25dSJames Smart struct lpfc_iocbq *cmdwqe, 650*6514b25dSJames Smart struct lpfc_wcqe_complete *wcqe)) 65101649561SJames Smart { 65201649561SJames Smart struct lpfc_dmabuf *bmp; 653*6514b25dSJames Smart struct ulp_bde64 *bpl; 654*6514b25dSJames Smart int ret; 655ba43c4d0SJames Smart uint16_t ntype, nstate; 65601649561SJames Smart 657ba43c4d0SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 658*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 659*6514b25dSJames Smart LOG_NVME_DISC | LOG_NODE | LOG_NVME_IOERR, 660*6514b25dSJames Smart "6051 NVMEx LS REQ: Bad NDLP x%px, Failing " 661*6514b25dSJames Smart "LS Req\n", 662*6514b25dSJames Smart ndlp); 663ba43c4d0SJames Smart return -ENODEV; 664ba43c4d0SJames Smart } 665ba43c4d0SJames Smart 666ba43c4d0SJames Smart ntype = ndlp->nlp_type; 667ba43c4d0SJames Smart nstate = ndlp->nlp_state; 668ba43c4d0SJames Smart if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) || 669ba43c4d0SJames Smart (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) { 670*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 671*6514b25dSJames Smart LOG_NVME_DISC | LOG_NODE | LOG_NVME_IOERR, 672*6514b25dSJames Smart "6088 NVMEx LS REQ: Fail DID x%06x not " 673*6514b25dSJames Smart "ready for IO. Type x%x, State x%x\n", 674*6514b25dSJames Smart ndlp->nlp_DID, ntype, nstate); 675ba43c4d0SJames Smart return -ENODEV; 67601649561SJames Smart } 677*6514b25dSJames Smart 678*6514b25dSJames Smart /* 679*6514b25dSJames Smart * there are two dma buf in the request, actually there is one and 680*6514b25dSJames Smart * the second one is just the start address + cmd size. 681*6514b25dSJames Smart * Before calling lpfc_nvme_gen_req these buffers need to be wrapped 682*6514b25dSJames Smart * in a lpfc_dmabuf struct. When freeing we just free the wrapper 683*6514b25dSJames Smart * because the nvem layer owns the data bufs. 684*6514b25dSJames Smart * We do not have to break these packets open, we don't care what is 685*6514b25dSJames Smart * in them. And we do not have to look at the resonse data, we only 686*6514b25dSJames Smart * care that we got a response. All of the caring is going to happen 687*6514b25dSJames Smart * in the nvme-fc layer. 688*6514b25dSJames Smart */ 689*6514b25dSJames Smart 690*6514b25dSJames Smart bmp = kmalloc(sizeof(*bmp), GFP_KERNEL); 69101649561SJames Smart if (!bmp) { 69201649561SJames Smart 693*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 694*6514b25dSJames Smart LOG_NVME_DISC | LOG_NVME_IOERR, 695*6514b25dSJames Smart "6044 NVMEx LS REQ: Could not alloc LS buf " 696*6514b25dSJames Smart "for DID %x\n", 697*6514b25dSJames Smart ndlp->nlp_DID); 698*6514b25dSJames Smart return -ENOMEM; 69901649561SJames Smart } 700*6514b25dSJames Smart 70101649561SJames Smart bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys)); 70201649561SJames Smart if (!bmp->virt) { 703*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 704*6514b25dSJames Smart LOG_NVME_DISC | LOG_NVME_IOERR, 705*6514b25dSJames Smart "6042 NVMEx LS REQ: Could not alloc mbuf " 706*6514b25dSJames Smart "for DID %x\n", 707*6514b25dSJames Smart ndlp->nlp_DID); 70801649561SJames Smart kfree(bmp); 709*6514b25dSJames Smart return -ENOMEM; 71001649561SJames Smart } 711*6514b25dSJames Smart 712*6514b25dSJames Smart INIT_LIST_HEAD(&bmp->list); 713*6514b25dSJames Smart 71401649561SJames Smart bpl = (struct ulp_bde64 *)bmp->virt; 71501649561SJames Smart bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma)); 71601649561SJames Smart bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma)); 71701649561SJames Smart bpl->tus.f.bdeFlags = 0; 71801649561SJames Smart bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen; 71901649561SJames Smart bpl->tus.w = le32_to_cpu(bpl->tus.w); 72001649561SJames Smart bpl++; 72101649561SJames Smart 72201649561SJames Smart bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma)); 72301649561SJames Smart bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma)); 72401649561SJames Smart bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; 72501649561SJames Smart bpl->tus.f.bdeSize = pnvme_lsreq->rsplen; 72601649561SJames Smart bpl->tus.w = le32_to_cpu(bpl->tus.w); 72701649561SJames Smart 72801649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 729*6514b25dSJames Smart "6149 NVMEx LS REQ: Issue to DID 0x%06x lsreq x%px, " 730*6514b25dSJames Smart "rqstlen:%d rsplen:%d %pad %pad\n", 731*6514b25dSJames Smart ndlp->nlp_DID, pnvme_lsreq, pnvme_lsreq->rqstlen, 732825c6abbSArnd Bergmann pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma, 733825c6abbSArnd Bergmann &pnvme_lsreq->rspdma); 73401649561SJames Smart 73501649561SJames Smart ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr, 736*6514b25dSJames Smart pnvme_lsreq, gen_req_cmp, ndlp, 2, 737*6514b25dSJames Smart LPFC_NVME_LS_TIMEOUT, 0); 73801649561SJames Smart if (ret != WQE_SUCCESS) { 739*6514b25dSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 740*6514b25dSJames Smart LOG_NVME_DISC | LOG_NVME_IOERR, 741*6514b25dSJames Smart "6052 NVMEx REQ: EXIT. issue ls wqe failed " 742*6514b25dSJames Smart "lsreq x%px Status %x DID %x\n", 743*6514b25dSJames Smart pnvme_lsreq, ret, ndlp->nlp_DID); 74401649561SJames Smart lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys); 74501649561SJames Smart kfree(bmp); 746*6514b25dSJames Smart return -EIO; 74701649561SJames Smart } 74801649561SJames Smart 749*6514b25dSJames Smart return 0; 750*6514b25dSJames Smart } 751*6514b25dSJames Smart 752*6514b25dSJames Smart /** 753*6514b25dSJames Smart * lpfc_nvme_ls_req - Issue an NVME Link Service request 754*6514b25dSJames Smart * @lpfc_nvme_lport: Transport localport that LS is to be issued from. 755*6514b25dSJames Smart * @lpfc_nvme_rport: Transport remoteport that LS is to be sent to. 756*6514b25dSJames Smart * @pnvme_lsreq - the transport nvme_ls_req structure for the LS 757*6514b25dSJames Smart * 758*6514b25dSJames Smart * Driver registers this routine to handle any link service request 759*6514b25dSJames Smart * from the nvme_fc transport to a remote nvme-aware port. 760*6514b25dSJames Smart * 761*6514b25dSJames Smart * Return value : 762*6514b25dSJames Smart * 0 - Success 763*6514b25dSJames Smart * non-zero: various error codes, in form of -Exxx 764*6514b25dSJames Smart **/ 765*6514b25dSJames Smart static int 766*6514b25dSJames Smart lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport, 767*6514b25dSJames Smart struct nvme_fc_remote_port *pnvme_rport, 768*6514b25dSJames Smart struct nvmefc_ls_req *pnvme_lsreq) 769*6514b25dSJames Smart { 770*6514b25dSJames Smart struct lpfc_nvme_lport *lport; 771*6514b25dSJames Smart struct lpfc_nvme_rport *rport; 772*6514b25dSJames Smart struct lpfc_vport *vport; 773*6514b25dSJames Smart int ret; 774*6514b25dSJames Smart 775*6514b25dSJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 776*6514b25dSJames Smart rport = (struct lpfc_nvme_rport *)pnvme_rport->private; 777*6514b25dSJames Smart if (unlikely(!lport) || unlikely(!rport)) 778*6514b25dSJames Smart return -EINVAL; 779*6514b25dSJames Smart 780*6514b25dSJames Smart vport = lport->vport; 781*6514b25dSJames Smart if (vport->load_flag & FC_UNLOADING) 782*6514b25dSJames Smart return -ENODEV; 783*6514b25dSJames Smart 784*6514b25dSJames Smart atomic_inc(&lport->fc4NvmeLsRequests); 785*6514b25dSJames Smart 786*6514b25dSJames Smart ret = __lpfc_nvme_ls_req(vport, rport->ndlp, pnvme_lsreq, 787*6514b25dSJames Smart lpfc_nvme_ls_req_cmp); 788*6514b25dSJames Smart if (ret) 789*6514b25dSJames Smart atomic_inc(&lport->xmt_ls_err); 790*6514b25dSJames Smart 79101649561SJames Smart return ret; 79201649561SJames Smart } 79301649561SJames Smart 79401649561SJames Smart /** 79501649561SJames Smart * lpfc_nvme_ls_abort - Issue an Link Service request 79601649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 79701649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 79801649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 79901649561SJames Smart * 80001649561SJames Smart * Driver registers this routine to handle any link service request 80101649561SJames Smart * from the nvme_fc transport to a remote nvme-aware port. 80201649561SJames Smart * 80301649561SJames Smart * Return value : 80401649561SJames Smart * 0 - Success 80501649561SJames Smart * TODO: What are the failure codes. 80601649561SJames Smart **/ 80701649561SJames Smart static void 80801649561SJames Smart lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport, 80901649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 81001649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq) 81101649561SJames Smart { 81201649561SJames Smart struct lpfc_nvme_lport *lport; 81301649561SJames Smart struct lpfc_vport *vport; 81401649561SJames Smart struct lpfc_hba *phba; 81501649561SJames Smart struct lpfc_nodelist *ndlp; 81601649561SJames Smart LIST_HEAD(abort_list); 81701649561SJames Smart struct lpfc_sli_ring *pring; 81801649561SJames Smart struct lpfc_iocbq *wqe, *next_wqe; 81901649561SJames Smart 82001649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 82166a210ffSJames Smart if (unlikely(!lport)) 82266a210ffSJames Smart return; 82301649561SJames Smart vport = lport->vport; 82401649561SJames Smart phba = vport->phba; 82501649561SJames Smart 8263386f4bdSJames Smart if (vport->load_flag & FC_UNLOADING) 8273386f4bdSJames Smart return; 8283386f4bdSJames Smart 82901649561SJames Smart ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); 83001649561SJames Smart if (!ndlp) { 83101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 83201649561SJames Smart "6049 Could not find node for DID %x\n", 83301649561SJames Smart pnvme_rport->port_id); 83401649561SJames Smart return; 83501649561SJames Smart } 83601649561SJames Smart 83701649561SJames Smart /* Expand print to include key fields. */ 83801649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 83932350664SJames Smart "6040 ENTER. lport x%px, rport x%px lsreq x%px rqstlen:%d " 840825c6abbSArnd Bergmann "rsplen:%d %pad %pad\n", 84101649561SJames Smart pnvme_lport, pnvme_rport, 84201649561SJames Smart pnvme_lsreq, pnvme_lsreq->rqstlen, 843825c6abbSArnd Bergmann pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma, 844825c6abbSArnd Bergmann &pnvme_lsreq->rspdma); 84501649561SJames Smart 84601649561SJames Smart /* 84701649561SJames Smart * Lock the ELS ring txcmplq and build a local list of all ELS IOs 84801649561SJames Smart * that need an ABTS. The IOs need to stay on the txcmplq so that 84901649561SJames Smart * the abort operation completes them successfully. 85001649561SJames Smart */ 85101649561SJames Smart pring = phba->sli4_hba.nvmels_wq->pring; 85201649561SJames Smart spin_lock_irq(&phba->hbalock); 85301649561SJames Smart spin_lock(&pring->ring_lock); 85401649561SJames Smart list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) { 85501649561SJames Smart /* Add to abort_list on on NDLP match. */ 85601649561SJames Smart if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) { 85701649561SJames Smart wqe->iocb_flag |= LPFC_DRIVER_ABORTED; 85801649561SJames Smart list_add_tail(&wqe->dlist, &abort_list); 85901649561SJames Smart } 86001649561SJames Smart } 86101649561SJames Smart spin_unlock(&pring->ring_lock); 86201649561SJames Smart spin_unlock_irq(&phba->hbalock); 86301649561SJames Smart 86401649561SJames Smart /* Abort the targeted IOs and remove them from the abort list. */ 86501649561SJames Smart list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) { 8664b056682SJames Smart atomic_inc(&lport->xmt_ls_abort); 86701649561SJames Smart spin_lock_irq(&phba->hbalock); 86801649561SJames Smart list_del_init(&wqe->dlist); 86901649561SJames Smart lpfc_sli_issue_abort_iotag(phba, pring, wqe); 87001649561SJames Smart spin_unlock_irq(&phba->hbalock); 87101649561SJames Smart } 87201649561SJames Smart } 87301649561SJames Smart 87401649561SJames Smart /* Fix up the existing sgls for NVME IO. */ 8755fd11085SJames Smart static inline void 87601649561SJames Smart lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport, 877c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd, 87801649561SJames Smart struct nvmefc_fcp_req *nCmd) 87901649561SJames Smart { 8804e565cf0SJames Smart struct lpfc_hba *phba = vport->phba; 88101649561SJames Smart struct sli4_sge *sgl; 88201649561SJames Smart union lpfc_wqe128 *wqe; 88301649561SJames Smart uint32_t *wptr, *dptr; 88401649561SJames Smart 88501649561SJames Smart /* 8864e565cf0SJames Smart * Get a local pointer to the built-in wqe and correct 8874e565cf0SJames Smart * the cmd size to match NVME's 96 bytes and fix 8884e565cf0SJames Smart * the dma address. 8894e565cf0SJames Smart */ 8904e565cf0SJames Smart 891205e8240SJames Smart wqe = &lpfc_ncmd->cur_iocbq.wqe; 8924e565cf0SJames Smart 8934e565cf0SJames Smart /* 89401649561SJames Smart * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to 89501649561SJames Smart * match NVME. NVME sends 96 bytes. Also, use the 89601649561SJames Smart * nvme commands command and response dma addresses 89701649561SJames Smart * rather than the virtual memory to ease the restore 89801649561SJames Smart * operation. 89901649561SJames Smart */ 9000794d601SJames Smart sgl = lpfc_ncmd->dma_sgl; 90101649561SJames Smart sgl->sge_len = cpu_to_le32(nCmd->cmdlen); 9024e565cf0SJames Smart if (phba->cfg_nvme_embed_cmd) { 9034e565cf0SJames Smart sgl->addr_hi = 0; 9044e565cf0SJames Smart sgl->addr_lo = 0; 9054e565cf0SJames Smart 9064e565cf0SJames Smart /* Word 0-2 - NVME CMND IU (embedded payload) */ 9074e565cf0SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED; 9084e565cf0SJames Smart wqe->generic.bde.tus.f.bdeSize = 56; 9094e565cf0SJames Smart wqe->generic.bde.addrHigh = 0; 9104e565cf0SJames Smart wqe->generic.bde.addrLow = 64; /* Word 16 */ 9114e565cf0SJames Smart 9125fd11085SJames Smart /* Word 10 - dbde is 0, wqes is 1 in template */ 91301649561SJames Smart 91401649561SJames Smart /* 91501649561SJames Smart * Embed the payload in the last half of the WQE 91601649561SJames Smart * WQE words 16-30 get the NVME CMD IU payload 91701649561SJames Smart * 918b06a622fSJames Smart * WQE words 16-19 get payload Words 1-4 91901649561SJames Smart * WQE words 20-21 get payload Words 6-7 92001649561SJames Smart * WQE words 22-29 get payload Words 16-23 92101649561SJames Smart */ 922b06a622fSJames Smart wptr = &wqe->words[16]; /* WQE ptr */ 92301649561SJames Smart dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */ 924b06a622fSJames Smart dptr++; /* Skip Word 0 in payload */ 92501649561SJames Smart 926b06a622fSJames Smart *wptr++ = *dptr++; /* Word 1 */ 92701649561SJames Smart *wptr++ = *dptr++; /* Word 2 */ 92801649561SJames Smart *wptr++ = *dptr++; /* Word 3 */ 92901649561SJames Smart *wptr++ = *dptr++; /* Word 4 */ 93001649561SJames Smart dptr++; /* Skip Word 5 in payload */ 93101649561SJames Smart *wptr++ = *dptr++; /* Word 6 */ 93201649561SJames Smart *wptr++ = *dptr++; /* Word 7 */ 93301649561SJames Smart dptr += 8; /* Skip Words 8-15 in payload */ 93401649561SJames Smart *wptr++ = *dptr++; /* Word 16 */ 93501649561SJames Smart *wptr++ = *dptr++; /* Word 17 */ 93601649561SJames Smart *wptr++ = *dptr++; /* Word 18 */ 93701649561SJames Smart *wptr++ = *dptr++; /* Word 19 */ 93801649561SJames Smart *wptr++ = *dptr++; /* Word 20 */ 93901649561SJames Smart *wptr++ = *dptr++; /* Word 21 */ 94001649561SJames Smart *wptr++ = *dptr++; /* Word 22 */ 94101649561SJames Smart *wptr = *dptr; /* Word 23 */ 9425fd11085SJames Smart } else { 9435fd11085SJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma)); 9445fd11085SJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma)); 9455fd11085SJames Smart 9465fd11085SJames Smart /* Word 0-2 - NVME CMND IU Inline BDE */ 9475fd11085SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 9485fd11085SJames Smart wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen; 9495fd11085SJames Smart wqe->generic.bde.addrHigh = sgl->addr_hi; 9505fd11085SJames Smart wqe->generic.bde.addrLow = sgl->addr_lo; 9515fd11085SJames Smart 9525fd11085SJames Smart /* Word 10 */ 9535fd11085SJames Smart bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); 9545fd11085SJames Smart bf_set(wqe_wqes, &wqe->generic.wqe_com, 0); 9555fd11085SJames Smart } 9565fd11085SJames Smart 9575fd11085SJames Smart sgl++; 9585fd11085SJames Smart 9595fd11085SJames Smart /* Setup the physical region for the FCP RSP */ 9605fd11085SJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma)); 9615fd11085SJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma)); 9625fd11085SJames Smart sgl->word2 = le32_to_cpu(sgl->word2); 9635fd11085SJames Smart if (nCmd->sg_cnt) 9645fd11085SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 9655fd11085SJames Smart else 9665fd11085SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 9675fd11085SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 9685fd11085SJames Smart sgl->sge_len = cpu_to_le32(nCmd->rsplen); 96901649561SJames Smart } 97001649561SJames Smart 971bd2cdd5eSJames Smart 97201649561SJames Smart /** 97301649561SJames Smart * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO 97401649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 97501649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 97601649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 97701649561SJames Smart * 97801649561SJames Smart * Driver registers this routine as it io request handler. This 97901649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 98001649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 98101649561SJames Smart * 98201649561SJames Smart * Return value : 98301649561SJames Smart * 0 - Success 98401649561SJames Smart * TODO: What are the failure codes. 98501649561SJames Smart **/ 98601649561SJames Smart static void 98701649561SJames Smart lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn, 98801649561SJames Smart struct lpfc_wcqe_complete *wcqe) 98901649561SJames Smart { 990c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd = 991c490850aSJames Smart (struct lpfc_io_buf *)pwqeIn->context1; 99201649561SJames Smart struct lpfc_vport *vport = pwqeIn->vport; 99301649561SJames Smart struct nvmefc_fcp_req *nCmd; 99401649561SJames Smart struct nvme_fc_ersp_iu *ep; 99501649561SJames Smart struct nvme_fc_cmd_iu *cp; 99601649561SJames Smart struct lpfc_nodelist *ndlp; 997bbe3012bSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 9984b056682SJames Smart struct lpfc_nvme_lport *lport; 999352b205aSArnd Bergmann uint32_t code, status, idx; 100001649561SJames Smart uint16_t cid, sqhd, data; 100101649561SJames Smart uint32_t *ptr; 1002840eda96SJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1003840eda96SJames Smart int cpu; 1004840eda96SJames Smart #endif 100501649561SJames Smart 100601649561SJames Smart /* Sanity check on return of outstanding command */ 10074d5e789aSJames Smart if (!lpfc_ncmd) { 10084d5e789aSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 10094d5e789aSJames Smart LOG_NODE | LOG_NVME_IOERR, 10104d5e789aSJames Smart "6071 Null lpfc_ncmd pointer. No " 10114d5e789aSJames Smart "release, skip completion\n"); 10124d5e789aSJames Smart return; 10134d5e789aSJames Smart } 10144d5e789aSJames Smart 1015c2017260SJames Smart /* Guard against abort handler being called at same time */ 1016c2017260SJames Smart spin_lock(&lpfc_ncmd->buf_lock); 1017c2017260SJames Smart 1018c2017260SJames Smart if (!lpfc_ncmd->nvmeCmd) { 1019c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 102001649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, 102132350664SJames Smart "6066 Missing cmpl ptrs: lpfc_ncmd x%px, " 102232350664SJames Smart "nvmeCmd x%px\n", 10230b05e9feSJames Smart lpfc_ncmd, lpfc_ncmd->nvmeCmd); 10244d5e789aSJames Smart 10254d5e789aSJames Smart /* Release the lpfc_ncmd regardless of the missing elements. */ 10264d5e789aSJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 102701649561SJames Smart return; 102801649561SJames Smart } 102901649561SJames Smart nCmd = lpfc_ncmd->nvmeCmd; 10304b056682SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 103166a210ffSJames Smart 10324c47efc1SJames Smart idx = lpfc_ncmd->cur_iocbq.hba_wqidx; 10334c47efc1SJames Smart phba->sli4_hba.hdwq[idx].nvme_cstat.io_cmpls++; 10344c47efc1SJames Smart 10351df09449SJames Smart if (unlikely(status && vport->localport)) { 10364b056682SJames Smart lport = (struct lpfc_nvme_lport *)vport->localport->private; 10371df09449SJames Smart if (lport) { 10384b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 10394b056682SJames Smart atomic_inc(&lport->cmpl_fcp_xb); 10404b056682SJames Smart atomic_inc(&lport->cmpl_fcp_err); 10414b056682SJames Smart } 104266a210ffSJames Smart } 104301649561SJames Smart 1044bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n", 1045bd2cdd5eSJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 10464b056682SJames Smart status, wcqe->parameter); 104701649561SJames Smart /* 104801649561SJames Smart * Catch race where our node has transitioned, but the 104901649561SJames Smart * transport is still transitioning. 105001649561SJames Smart */ 10510b05e9feSJames Smart ndlp = lpfc_ncmd->ndlp; 105201649561SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 105301649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 105401649561SJames Smart "6062 Ignoring NVME cmpl. No ndlp\n"); 105501649561SJames Smart goto out_err; 105601649561SJames Smart } 105701649561SJames Smart 105801649561SJames Smart code = bf_get(lpfc_wcqe_c_code, wcqe); 105901649561SJames Smart if (code == CQE_CODE_NVME_ERSP) { 106001649561SJames Smart /* For this type of CQE, we need to rebuild the rsp */ 106101649561SJames Smart ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr; 106201649561SJames Smart 106301649561SJames Smart /* 106401649561SJames Smart * Get Command Id from cmd to plug into response. This 106501649561SJames Smart * code is not needed in the next NVME Transport drop. 106601649561SJames Smart */ 106701649561SJames Smart cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr; 106801649561SJames Smart cid = cp->sqe.common.command_id; 106901649561SJames Smart 107001649561SJames Smart /* 107101649561SJames Smart * RSN is in CQE word 2 107201649561SJames Smart * SQHD is in CQE Word 3 bits 15:0 107301649561SJames Smart * Cmd Specific info is in CQE Word 1 107401649561SJames Smart * and in CQE Word 0 bits 15:0 107501649561SJames Smart */ 107601649561SJames Smart sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe); 107701649561SJames Smart 107801649561SJames Smart /* Now lets build the NVME ERSP IU */ 107901649561SJames Smart ep->iu_len = cpu_to_be16(8); 108001649561SJames Smart ep->rsn = wcqe->parameter; 108101649561SJames Smart ep->xfrd_len = cpu_to_be32(nCmd->payload_length); 108201649561SJames Smart ep->rsvd12 = 0; 108301649561SJames Smart ptr = (uint32_t *)&ep->cqe.result.u64; 108401649561SJames Smart *ptr++ = wcqe->total_data_placed; 108501649561SJames Smart data = bf_get(lpfc_wcqe_c_ersp0, wcqe); 108601649561SJames Smart *ptr = (uint32_t)data; 108701649561SJames Smart ep->cqe.sq_head = sqhd; 108801649561SJames Smart ep->cqe.sq_id = nCmd->sqid; 108901649561SJames Smart ep->cqe.command_id = cid; 109001649561SJames Smart ep->cqe.status = 0; 109101649561SJames Smart 109201649561SJames Smart lpfc_ncmd->status = IOSTAT_SUCCESS; 109301649561SJames Smart lpfc_ncmd->result = 0; 109401649561SJames Smart nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN; 109501649561SJames Smart nCmd->transferred_length = nCmd->payload_length; 109601649561SJames Smart } else { 10974b056682SJames Smart lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK); 1098952c303bSDick Kennedy lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK); 109901649561SJames Smart 110001649561SJames Smart /* For NVME, the only failure path that results in an 110101649561SJames Smart * IO error is when the adapter rejects it. All other 110201649561SJames Smart * conditions are a success case and resolved by the 110301649561SJames Smart * transport. 110401649561SJames Smart * IOSTAT_FCP_RSP_ERROR means: 110501649561SJames Smart * 1. Length of data received doesn't match total 110601649561SJames Smart * transfer length in WQE 110701649561SJames Smart * 2. If the RSP payload does NOT match these cases: 110801649561SJames Smart * a. RSP length 12/24 bytes and all zeros 110901649561SJames Smart * b. NVME ERSP 111001649561SJames Smart */ 111101649561SJames Smart switch (lpfc_ncmd->status) { 111201649561SJames Smart case IOSTAT_SUCCESS: 111301649561SJames Smart nCmd->transferred_length = wcqe->total_data_placed; 111401649561SJames Smart nCmd->rcv_rsplen = 0; 111501649561SJames Smart nCmd->status = 0; 111601649561SJames Smart break; 111701649561SJames Smart case IOSTAT_FCP_RSP_ERROR: 111801649561SJames Smart nCmd->transferred_length = wcqe->total_data_placed; 111901649561SJames Smart nCmd->rcv_rsplen = wcqe->parameter; 112001649561SJames Smart nCmd->status = 0; 112101649561SJames Smart /* Sanity check */ 112201649561SJames Smart if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN) 112301649561SJames Smart break; 112401649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 112501649561SJames Smart "6081 NVME Completion Protocol Error: " 112686c67379SJames Smart "xri %x status x%x result x%x " 112786c67379SJames Smart "placed x%x\n", 112886c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 112901649561SJames Smart lpfc_ncmd->status, lpfc_ncmd->result, 113001649561SJames Smart wcqe->total_data_placed); 113101649561SJames Smart break; 1132952c303bSDick Kennedy case IOSTAT_LOCAL_REJECT: 1133952c303bSDick Kennedy /* Let fall through to set command final state. */ 1134952c303bSDick Kennedy if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED) 1135952c303bSDick Kennedy lpfc_printf_vlog(vport, KERN_INFO, 1136952c303bSDick Kennedy LOG_NVME_IOERR, 113732350664SJames Smart "6032 Delay Aborted cmd x%px " 113832350664SJames Smart "nvme cmd x%px, xri x%x, " 1139952c303bSDick Kennedy "xb %d\n", 1140952c303bSDick Kennedy lpfc_ncmd, nCmd, 1141952c303bSDick Kennedy lpfc_ncmd->cur_iocbq.sli4_xritag, 1142952c303bSDick Kennedy bf_get(lpfc_wcqe_c_xb, wcqe)); 1143cd05c155SBart Van Assche /* fall through */ 114401649561SJames Smart default: 114501649561SJames Smart out_err: 1146e3246a12SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 114786c67379SJames Smart "6072 NVME Completion Error: xri %x " 11482c013a3aSJames Smart "status x%x result x%x [x%x] " 11492c013a3aSJames Smart "placed x%x\n", 115086c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 115101649561SJames Smart lpfc_ncmd->status, lpfc_ncmd->result, 11522c013a3aSJames Smart wcqe->parameter, 115301649561SJames Smart wcqe->total_data_placed); 115401649561SJames Smart nCmd->transferred_length = 0; 115501649561SJames Smart nCmd->rcv_rsplen = 0; 11568e009ce8SJames Smart nCmd->status = NVME_SC_INTERNAL; 115701649561SJames Smart } 115801649561SJames Smart } 115901649561SJames Smart 116001649561SJames Smart /* pick up SLI4 exhange busy condition */ 116101649561SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 116201649561SJames Smart lpfc_ncmd->flags |= LPFC_SBUF_XBUSY; 116301649561SJames Smart else 116401649561SJames Smart lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY; 116501649561SJames Smart 116601649561SJames Smart /* Update stats and complete the IO. There is 116701649561SJames Smart * no need for dma unprep because the nvme_transport 116801649561SJames Smart * owns the dma address. 116901649561SJames Smart */ 1170bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1171c8a4ce0bSDick Kennedy if (lpfc_ncmd->ts_cmd_start) { 1172bd2cdd5eSJames Smart lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp; 11732fcbc569SJames Smart lpfc_ncmd->ts_data_io = ktime_get_ns(); 11742fcbc569SJames Smart phba->ktime_last_cmd = lpfc_ncmd->ts_data_io; 11752fcbc569SJames Smart lpfc_io_ktime(phba, lpfc_ncmd); 1176bd2cdd5eSJames Smart } 1177840eda96SJames Smart if (unlikely(phba->hdwqstat_on & LPFC_CHECK_NVME_IO)) { 1178d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 1179840eda96SJames Smart this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); 118063df6d63SJames Smart if (lpfc_ncmd->cpu != cpu) 118163df6d63SJames Smart lpfc_printf_vlog(vport, 118263df6d63SJames Smart KERN_INFO, LOG_NVME_IOERR, 1183bd2cdd5eSJames Smart "6701 CPU Check cmpl: " 1184bd2cdd5eSJames Smart "cpu %d expect %d\n", 118563df6d63SJames Smart cpu, lpfc_ncmd->cpu); 1186bd2cdd5eSJames Smart } 1187bd2cdd5eSJames Smart #endif 1188952c303bSDick Kennedy 1189952c303bSDick Kennedy /* NVME targets need completion held off until the abort exchange 1190add9d6beSJames Smart * completes unless the NVME Rport is getting unregistered. 1191952c303bSDick Kennedy */ 1192add9d6beSJames Smart 11933fd78355SJames Smart if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) { 119491455b85SJames Smart freqpriv = nCmd->private; 119591455b85SJames Smart freqpriv->nvme_buf = NULL; 11963fd78355SJames Smart lpfc_ncmd->nvmeCmd = NULL; 1197c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 1198c2017260SJames Smart nCmd->done(nCmd); 1199c2017260SJames Smart } else 1200c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 120101649561SJames Smart 1202952c303bSDick Kennedy /* Call release with XB=1 to queue the IO into the abort list. */ 120301649561SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 120401649561SJames Smart } 120501649561SJames Smart 120601649561SJames Smart 120701649561SJames Smart /** 120801649561SJames Smart * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO 120901649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 121001649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 121101649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 121201649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 121301649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 121401649561SJames Smart * 121501649561SJames Smart * Driver registers this routine as it io request handler. This 121601649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 121701649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 121801649561SJames Smart * 121901649561SJames Smart * Return value : 122001649561SJames Smart * 0 - Success 122101649561SJames Smart * TODO: What are the failure codes. 122201649561SJames Smart **/ 122301649561SJames Smart static int 122401649561SJames Smart lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport, 1225c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd, 122666a210ffSJames Smart struct lpfc_nodelist *pnode, 12274c47efc1SJames Smart struct lpfc_fc4_ctrl_stat *cstat) 122801649561SJames Smart { 122901649561SJames Smart struct lpfc_hba *phba = vport->phba; 123001649561SJames Smart struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; 123101649561SJames Smart struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq); 1232205e8240SJames Smart union lpfc_wqe128 *wqe = &pwqeq->wqe; 123301649561SJames Smart uint32_t req_len; 123401649561SJames Smart 1235e960f5abSJames Smart if (!NLP_CHK_NODE_ACT(pnode)) 123601649561SJames Smart return -EINVAL; 123701649561SJames Smart 123801649561SJames Smart /* 123901649561SJames Smart * There are three possibilities here - use scatter-gather segment, use 124001649561SJames Smart * the single mapping, or neither. 124101649561SJames Smart */ 124201649561SJames Smart if (nCmd->sg_cnt) { 124301649561SJames Smart if (nCmd->io_dir == NVMEFC_FCP_WRITE) { 12445fd11085SJames Smart /* From the iwrite template, initialize words 7 - 11 */ 12455fd11085SJames Smart memcpy(&wqe->words[7], 12465fd11085SJames Smart &lpfc_iwrite_cmd_template.words[7], 12475fd11085SJames Smart sizeof(uint32_t) * 5); 12485fd11085SJames Smart 12495fd11085SJames Smart /* Word 4 */ 12505fd11085SJames Smart wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length; 12515fd11085SJames Smart 125201649561SJames Smart /* Word 5 */ 125301649561SJames Smart if ((phba->cfg_nvme_enable_fb) && 125401649561SJames Smart (pnode->nlp_flag & NLP_FIRSTBURST)) { 125501649561SJames Smart req_len = lpfc_ncmd->nvmeCmd->payload_length; 125601649561SJames Smart if (req_len < pnode->nvme_fb_size) 125701649561SJames Smart wqe->fcp_iwrite.initial_xfer_len = 125801649561SJames Smart req_len; 125901649561SJames Smart else 126001649561SJames Smart wqe->fcp_iwrite.initial_xfer_len = 126101649561SJames Smart pnode->nvme_fb_size; 12625fd11085SJames Smart } else { 12635fd11085SJames Smart wqe->fcp_iwrite.initial_xfer_len = 0; 126401649561SJames Smart } 12654c47efc1SJames Smart cstat->output_requests++; 126601649561SJames Smart } else { 12675fd11085SJames Smart /* From the iread template, initialize words 7 - 11 */ 12685fd11085SJames Smart memcpy(&wqe->words[7], 12695fd11085SJames Smart &lpfc_iread_cmd_template.words[7], 12705fd11085SJames Smart sizeof(uint32_t) * 5); 127101649561SJames Smart 12725fd11085SJames Smart /* Word 4 */ 12735fd11085SJames Smart wqe->fcp_iread.total_xfer_len = nCmd->payload_length; 127401649561SJames Smart 12755fd11085SJames Smart /* Word 5 */ 12765fd11085SJames Smart wqe->fcp_iread.rsrvd5 = 0; 127701649561SJames Smart 12784c47efc1SJames Smart cstat->input_requests++; 127901649561SJames Smart } 128001649561SJames Smart } else { 12815fd11085SJames Smart /* From the icmnd template, initialize words 4 - 11 */ 12825fd11085SJames Smart memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4], 12835fd11085SJames Smart sizeof(uint32_t) * 8); 12844c47efc1SJames Smart cstat->control_requests++; 128501649561SJames Smart } 12860d8af096SJames Smart 12870d8af096SJames Smart if (pnode->nlp_nvme_info & NLP_NVME_NSLER) 12880d8af096SJames Smart bf_set(wqe_erp, &wqe->generic.wqe_com, 1); 128901649561SJames Smart /* 129001649561SJames Smart * Finish initializing those WQE fields that are independent 129101649561SJames Smart * of the nvme_cmnd request_buffer 129201649561SJames Smart */ 129301649561SJames Smart 12945fd11085SJames Smart /* Word 3 */ 12955fd11085SJames Smart bf_set(payload_offset_len, &wqe->fcp_icmd, 12965fd11085SJames Smart (nCmd->rsplen + nCmd->cmdlen)); 12975fd11085SJames Smart 129801649561SJames Smart /* Word 6 */ 129901649561SJames Smart bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 130001649561SJames Smart phba->sli4_hba.rpi_ids[pnode->nlp_rpi]); 130101649561SJames Smart bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); 130201649561SJames Smart 130301649561SJames Smart /* Word 8 */ 130401649561SJames Smart wqe->generic.wqe_com.abort_tag = pwqeq->iotag; 130501649561SJames Smart 130601649561SJames Smart /* Word 9 */ 130701649561SJames Smart bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); 130801649561SJames Smart 1309414abe0aSJames Smart /* Words 13 14 15 are for PBDE support */ 1310414abe0aSJames Smart 131101649561SJames Smart pwqeq->vport = vport; 131201649561SJames Smart return 0; 131301649561SJames Smart } 131401649561SJames Smart 131501649561SJames Smart 131601649561SJames Smart /** 131701649561SJames Smart * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO 131801649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 131901649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 132001649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 132101649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 132201649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 132301649561SJames Smart * 132401649561SJames Smart * Driver registers this routine as it io request handler. This 132501649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 132601649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 132701649561SJames Smart * 132801649561SJames Smart * Return value : 132901649561SJames Smart * 0 - Success 133001649561SJames Smart * TODO: What are the failure codes. 133101649561SJames Smart **/ 133201649561SJames Smart static int 133301649561SJames Smart lpfc_nvme_prep_io_dma(struct lpfc_vport *vport, 1334c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd) 133501649561SJames Smart { 133601649561SJames Smart struct lpfc_hba *phba = vport->phba; 133701649561SJames Smart struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; 1338205e8240SJames Smart union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe; 13390794d601SJames Smart struct sli4_sge *sgl = lpfc_ncmd->dma_sgl; 1340d79c9e9dSJames Smart struct sli4_hybrid_sgl *sgl_xtra = NULL; 134101649561SJames Smart struct scatterlist *data_sg; 134201649561SJames Smart struct sli4_sge *first_data_sgl; 13430bc2b7c5SJames Smart struct ulp_bde64 *bde; 1344d79c9e9dSJames Smart dma_addr_t physaddr = 0; 134501649561SJames Smart uint32_t num_bde = 0; 1346d79c9e9dSJames Smart uint32_t dma_len = 0; 134701649561SJames Smart uint32_t dma_offset = 0; 1348d79c9e9dSJames Smart int nseg, i, j; 1349d79c9e9dSJames Smart bool lsp_just_set = false; 135001649561SJames Smart 135101649561SJames Smart /* Fix up the command and response DMA stuff. */ 135201649561SJames Smart lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd); 135301649561SJames Smart 135401649561SJames Smart /* 135501649561SJames Smart * There are three possibilities here - use scatter-gather segment, use 135601649561SJames Smart * the single mapping, or neither. 135701649561SJames Smart */ 135801649561SJames Smart if (nCmd->sg_cnt) { 135901649561SJames Smart /* 136001649561SJames Smart * Jump over the cmd and rsp SGEs. The fix routine 136101649561SJames Smart * has already adjusted for this. 136201649561SJames Smart */ 136301649561SJames Smart sgl += 2; 136401649561SJames Smart 136501649561SJames Smart first_data_sgl = sgl; 136601649561SJames Smart lpfc_ncmd->seg_cnt = nCmd->sg_cnt; 136781e6a637SJames Smart if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) { 136801649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 136901649561SJames Smart "6058 Too many sg segments from " 137001649561SJames Smart "NVME Transport. Max %d, " 137101649561SJames Smart "nvmeIO sg_cnt %d\n", 137229bfd55aSJames Smart phba->cfg_nvme_seg_cnt + 1, 137301649561SJames Smart lpfc_ncmd->seg_cnt); 137401649561SJames Smart lpfc_ncmd->seg_cnt = 0; 137501649561SJames Smart return 1; 137601649561SJames Smart } 137701649561SJames Smart 137801649561SJames Smart /* 137901649561SJames Smart * The driver established a maximum scatter-gather segment count 138001649561SJames Smart * during probe that limits the number of sg elements in any 138101649561SJames Smart * single nvme command. Just run through the seg_cnt and format 138201649561SJames Smart * the sge's. 138301649561SJames Smart */ 138401649561SJames Smart nseg = nCmd->sg_cnt; 138501649561SJames Smart data_sg = nCmd->first_sgl; 1386d79c9e9dSJames Smart 1387d79c9e9dSJames Smart /* for tracking the segment boundaries */ 1388d79c9e9dSJames Smart j = 2; 138901649561SJames Smart for (i = 0; i < nseg; i++) { 139001649561SJames Smart if (data_sg == NULL) { 139101649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 139201649561SJames Smart "6059 dptr err %d, nseg %d\n", 139301649561SJames Smart i, nseg); 139401649561SJames Smart lpfc_ncmd->seg_cnt = 0; 139501649561SJames Smart return 1; 139601649561SJames Smart } 1397d79c9e9dSJames Smart 1398d79c9e9dSJames Smart sgl->word2 = 0; 1399d79c9e9dSJames Smart if ((num_bde + 1) == nseg) { 1400d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1401d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1402d79c9e9dSJames Smart LPFC_SGE_TYPE_DATA); 1403d79c9e9dSJames Smart } else { 1404d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 1405d79c9e9dSJames Smart 1406d79c9e9dSJames Smart /* expand the segment */ 1407d79c9e9dSJames Smart if (!lsp_just_set && 1408d79c9e9dSJames Smart !((j + 1) % phba->border_sge_num) && 1409d79c9e9dSJames Smart ((nseg - 1) != i)) { 1410d79c9e9dSJames Smart /* set LSP type */ 1411d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1412d79c9e9dSJames Smart LPFC_SGE_TYPE_LSP); 1413d79c9e9dSJames Smart 1414d79c9e9dSJames Smart sgl_xtra = lpfc_get_sgl_per_hdwq( 1415d79c9e9dSJames Smart phba, lpfc_ncmd); 1416d79c9e9dSJames Smart 1417d79c9e9dSJames Smart if (unlikely(!sgl_xtra)) { 1418d79c9e9dSJames Smart lpfc_ncmd->seg_cnt = 0; 1419d79c9e9dSJames Smart return 1; 1420d79c9e9dSJames Smart } 1421d79c9e9dSJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow( 1422d79c9e9dSJames Smart sgl_xtra->dma_phys_sgl)); 1423d79c9e9dSJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh( 1424d79c9e9dSJames Smart sgl_xtra->dma_phys_sgl)); 1425d79c9e9dSJames Smart 1426d79c9e9dSJames Smart } else { 1427d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1428d79c9e9dSJames Smart LPFC_SGE_TYPE_DATA); 1429d79c9e9dSJames Smart } 1430d79c9e9dSJames Smart } 1431d79c9e9dSJames Smart 1432d79c9e9dSJames Smart if (!(bf_get(lpfc_sli4_sge_type, sgl) & 1433d79c9e9dSJames Smart LPFC_SGE_TYPE_LSP)) { 1434d79c9e9dSJames Smart if ((nseg - 1) == i) 1435d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1436d79c9e9dSJames Smart 143701649561SJames Smart physaddr = data_sg->dma_address; 143801649561SJames Smart dma_len = data_sg->length; 1439d79c9e9dSJames Smart sgl->addr_lo = cpu_to_le32( 1440d79c9e9dSJames Smart putPaddrLow(physaddr)); 1441d79c9e9dSJames Smart sgl->addr_hi = cpu_to_le32( 1442d79c9e9dSJames Smart putPaddrHigh(physaddr)); 1443d79c9e9dSJames Smart 144401649561SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); 144501649561SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 144601649561SJames Smart sgl->sge_len = cpu_to_le32(dma_len); 144701649561SJames Smart 144801649561SJames Smart dma_offset += dma_len; 144901649561SJames Smart data_sg = sg_next(data_sg); 1450d79c9e9dSJames Smart 145101649561SJames Smart sgl++; 1452d79c9e9dSJames Smart 1453d79c9e9dSJames Smart lsp_just_set = false; 1454d79c9e9dSJames Smart } else { 1455d79c9e9dSJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1456d79c9e9dSJames Smart 1457d79c9e9dSJames Smart sgl->sge_len = cpu_to_le32( 1458d79c9e9dSJames Smart phba->cfg_sg_dma_buf_size); 1459d79c9e9dSJames Smart 1460d79c9e9dSJames Smart sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; 1461d79c9e9dSJames Smart i = i - 1; 1462d79c9e9dSJames Smart 1463d79c9e9dSJames Smart lsp_just_set = true; 1464d79c9e9dSJames Smart } 1465d79c9e9dSJames Smart 1466d79c9e9dSJames Smart j++; 146701649561SJames Smart } 1468414abe0aSJames Smart if (phba->cfg_enable_pbde) { 14690bc2b7c5SJames Smart /* Use PBDE support for first SGL only, offset == 0 */ 14700bc2b7c5SJames Smart /* Words 13-15 */ 14710bc2b7c5SJames Smart bde = (struct ulp_bde64 *) 14720bc2b7c5SJames Smart &wqe->words[13]; 14730bc2b7c5SJames Smart bde->addrLow = first_data_sgl->addr_lo; 14740bc2b7c5SJames Smart bde->addrHigh = first_data_sgl->addr_hi; 14750bc2b7c5SJames Smart bde->tus.f.bdeSize = 14760bc2b7c5SJames Smart le32_to_cpu(first_data_sgl->sge_len); 14770bc2b7c5SJames Smart bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; 14780bc2b7c5SJames Smart bde->tus.w = cpu_to_le32(bde->tus.w); 14795fd11085SJames Smart /* wqe_pbde is 1 in template */ 14805fd11085SJames Smart } else { 14815fd11085SJames Smart memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3)); 14820bc2b7c5SJames Smart bf_set(wqe_pbde, &wqe->generic.wqe_com, 0); 14835fd11085SJames Smart } 14840bc2b7c5SJames Smart 1485414abe0aSJames Smart } else { 14860794d601SJames Smart lpfc_ncmd->seg_cnt = 0; 14870794d601SJames Smart 148801649561SJames Smart /* For this clause to be valid, the payload_length 148901649561SJames Smart * and sg_cnt must zero. 149001649561SJames Smart */ 149101649561SJames Smart if (nCmd->payload_length != 0) { 149201649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 149301649561SJames Smart "6063 NVME DMA Prep Err: sg_cnt %d " 149401649561SJames Smart "payload_length x%x\n", 149501649561SJames Smart nCmd->sg_cnt, nCmd->payload_length); 149601649561SJames Smart return 1; 149701649561SJames Smart } 149801649561SJames Smart } 149901649561SJames Smart return 0; 150001649561SJames Smart } 150101649561SJames Smart 150201649561SJames Smart /** 150301649561SJames Smart * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO 150401649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 150501649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 150601649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 150701649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 150801649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 150901649561SJames Smart * 151001649561SJames Smart * Driver registers this routine as it io request handler. This 151101649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 151201649561SJames Smart * data structure to the rport 151301649561SJames Smart indicated in @lpfc_nvme_rport. 151401649561SJames Smart * 151501649561SJames Smart * Return value : 151601649561SJames Smart * 0 - Success 151701649561SJames Smart * TODO: What are the failure codes. 151801649561SJames Smart **/ 151901649561SJames Smart static int 152001649561SJames Smart lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport, 152101649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 152201649561SJames Smart void *hw_queue_handle, 152301649561SJames Smart struct nvmefc_fcp_req *pnvme_fcreq) 152401649561SJames Smart { 152501649561SJames Smart int ret = 0; 1526cf1a1d3eSJames Smart int expedite = 0; 152763df6d63SJames Smart int idx, cpu; 152801649561SJames Smart struct lpfc_nvme_lport *lport; 15294c47efc1SJames Smart struct lpfc_fc4_ctrl_stat *cstat; 153001649561SJames Smart struct lpfc_vport *vport; 153101649561SJames Smart struct lpfc_hba *phba; 153201649561SJames Smart struct lpfc_nodelist *ndlp; 1533c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd; 153401649561SJames Smart struct lpfc_nvme_rport *rport; 153501649561SJames Smart struct lpfc_nvme_qhandle *lpfc_queue_info; 1536c3725bdcSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 1537cf1a1d3eSJames Smart struct nvme_common_command *sqe; 1538bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1539bd2cdd5eSJames Smart uint64_t start = 0; 1540bd2cdd5eSJames Smart #endif 154101649561SJames Smart 1542c3725bdcSJames Smart /* Validate pointers. LLDD fault handling with transport does 1543c3725bdcSJames Smart * have timing races. 1544c3725bdcSJames Smart */ 154501649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 1546c3725bdcSJames Smart if (unlikely(!lport)) { 1547c3725bdcSJames Smart ret = -EINVAL; 1548c3725bdcSJames Smart goto out_fail; 1549c3725bdcSJames Smart } 1550c3725bdcSJames Smart 155101649561SJames Smart vport = lport->vport; 1552c3725bdcSJames Smart 1553c3725bdcSJames Smart if (unlikely(!hw_queue_handle)) { 155444c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 155544c2757bSJames Smart "6117 Fail IO, NULL hw_queue_handle\n"); 155644c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1557cd240071SJames Smart ret = -EBUSY; 1558c3725bdcSJames Smart goto out_fail; 1559c3725bdcSJames Smart } 1560c3725bdcSJames Smart 156101649561SJames Smart phba = vport->phba; 156201649561SJames Smart 15631abcb371SDick Kennedy if (vport->load_flag & FC_UNLOADING) { 15641abcb371SDick Kennedy ret = -ENODEV; 15651abcb371SDick Kennedy goto out_fail; 15661abcb371SDick Kennedy } 15671abcb371SDick Kennedy 15681df09449SJames Smart if (unlikely(vport->load_flag & FC_UNLOADING)) { 156944c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 157044c2757bSJames Smart "6124 Fail IO, Driver unload\n"); 157144c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 15723386f4bdSJames Smart ret = -ENODEV; 15733386f4bdSJames Smart goto out_fail; 15743386f4bdSJames Smart } 15753386f4bdSJames Smart 1576c3725bdcSJames Smart freqpriv = pnvme_fcreq->private; 1577c3725bdcSJames Smart if (unlikely(!freqpriv)) { 157844c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 157944c2757bSJames Smart "6158 Fail IO, NULL request data\n"); 158044c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1581c3725bdcSJames Smart ret = -EINVAL; 1582b7672ae6SDick Kennedy goto out_fail; 1583b7672ae6SDick Kennedy } 1584b7672ae6SDick Kennedy 1585bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1586bd2cdd5eSJames Smart if (phba->ktime_on) 1587bd2cdd5eSJames Smart start = ktime_get_ns(); 1588bd2cdd5eSJames Smart #endif 158901649561SJames Smart rport = (struct lpfc_nvme_rport *)pnvme_rport->private; 159001649561SJames Smart lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle; 159101649561SJames Smart 159201649561SJames Smart /* 159301649561SJames Smart * Catch race where our node has transitioned, but the 159401649561SJames Smart * transport is still transitioning. 159501649561SJames Smart */ 159601649561SJames Smart ndlp = rport->ndlp; 159701649561SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 159844c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR, 159932350664SJames Smart "6053 Busy IO, ndlp not ready: rport x%px " 160032350664SJames Smart "ndlp x%px, DID x%06x\n", 160101649561SJames Smart rport, ndlp, pnvme_rport->port_id); 160244c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1603cd240071SJames Smart ret = -EBUSY; 160401649561SJames Smart goto out_fail; 160501649561SJames Smart } 160601649561SJames Smart 160701649561SJames Smart /* The remote node has to be a mapped target or it's an error. */ 160801649561SJames Smart if ((ndlp->nlp_type & NLP_NVME_TARGET) && 160901649561SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { 161044c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR, 161144c2757bSJames Smart "6036 Fail IO, DID x%06x not ready for " 1612cd240071SJames Smart "IO. State x%x, Type x%x Flg x%x\n", 161344c2757bSJames Smart pnvme_rport->port_id, 1614cd240071SJames Smart ndlp->nlp_state, ndlp->nlp_type, 1615cd240071SJames Smart ndlp->upcall_flags); 16164b056682SJames Smart atomic_inc(&lport->xmt_fcp_bad_ndlp); 1617cd240071SJames Smart ret = -EBUSY; 161801649561SJames Smart goto out_fail; 161901649561SJames Smart 162001649561SJames Smart } 162101649561SJames Smart 1622cf1a1d3eSJames Smart /* Currently only NVME Keep alive commands should be expedited 1623cf1a1d3eSJames Smart * if the driver runs out of a resource. These should only be 1624cf1a1d3eSJames Smart * issued on the admin queue, qidx 0 1625cf1a1d3eSJames Smart */ 1626cf1a1d3eSJames Smart if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) { 1627cf1a1d3eSJames Smart sqe = &((struct nvme_fc_cmd_iu *) 1628cf1a1d3eSJames Smart pnvme_fcreq->cmdaddr)->sqe.common; 1629cf1a1d3eSJames Smart if (sqe->opcode == nvme_admin_keep_alive) 1630cf1a1d3eSJames Smart expedite = 1; 1631cf1a1d3eSJames Smart } 1632cf1a1d3eSJames Smart 163301649561SJames Smart /* The node is shared with FCP IO, make sure the IO pending count does 163401649561SJames Smart * not exceed the programmed depth. 163501649561SJames Smart */ 16362a5b7d62SJames Smart if (lpfc_ndlp_check_qdepth(phba, ndlp)) { 1637cf1a1d3eSJames Smart if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) && 1638cf1a1d3eSJames Smart !expedite) { 163944c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 164044c2757bSJames Smart "6174 Fail IO, ndlp qdepth exceeded: " 16414d5e789aSJames Smart "idx %d DID %x pend %d qdepth %d\n", 16424d5e789aSJames Smart lpfc_queue_info->index, ndlp->nlp_DID, 16434d5e789aSJames Smart atomic_read(&ndlp->cmd_pending), 16444d5e789aSJames Smart ndlp->cmd_qdepth); 16454b056682SJames Smart atomic_inc(&lport->xmt_fcp_qdepth); 1646cd22d605SDick Kennedy ret = -EBUSY; 164701649561SJames Smart goto out_fail; 164801649561SJames Smart } 16492a5b7d62SJames Smart } 165001649561SJames Smart 16516a828b0fSJames Smart /* Lookup Hardware Queue index based on fcp_io_sched module parameter */ 165245aa312eSJames Smart if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) { 165345aa312eSJames Smart idx = lpfc_queue_info->index; 165445aa312eSJames Smart } else { 1655d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 16566a828b0fSJames Smart idx = phba->sli4_hba.cpu_map[cpu].hdwq; 165745aa312eSJames Smart } 165845aa312eSJames Smart 165945aa312eSJames Smart lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, idx, expedite); 166001649561SJames Smart if (lpfc_ncmd == NULL) { 16614b056682SJames Smart atomic_inc(&lport->xmt_fcp_noxri); 166201649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 166344c2757bSJames Smart "6065 Fail IO, driver buffer pool is empty: " 166444c2757bSJames Smart "idx %d DID %x\n", 166544c2757bSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 1666cd22d605SDick Kennedy ret = -EBUSY; 166701649561SJames Smart goto out_fail; 166801649561SJames Smart } 1669bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1670c8a4ce0bSDick Kennedy if (start) { 1671bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_start = start; 1672bd2cdd5eSJames Smart lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd; 1673c8a4ce0bSDick Kennedy } else { 1674c8a4ce0bSDick Kennedy lpfc_ncmd->ts_cmd_start = 0; 1675bd2cdd5eSJames Smart } 1676bd2cdd5eSJames Smart #endif 167701649561SJames Smart 167801649561SJames Smart /* 167901649561SJames Smart * Store the data needed by the driver to issue, abort, and complete 168001649561SJames Smart * an IO. 168101649561SJames Smart * Do not let the IO hang out forever. There is no midlayer issuing 168201649561SJames Smart * an abort so inform the FW of the maximum IO pending time. 168301649561SJames Smart */ 1684bbe3012bSJames Smart freqpriv->nvme_buf = lpfc_ncmd; 168501649561SJames Smart lpfc_ncmd->nvmeCmd = pnvme_fcreq; 1686318083adSJames Smart lpfc_ncmd->ndlp = ndlp; 16870794d601SJames Smart lpfc_ncmd->qidx = lpfc_queue_info->qidx; 168801649561SJames Smart 168901649561SJames Smart /* 169001649561SJames Smart * Issue the IO on the WQ indicated by index in the hw_queue_handle. 169101649561SJames Smart * This identfier was create in our hardware queue create callback 169201649561SJames Smart * routine. The driver now is dependent on the IO queue steering from 169301649561SJames Smart * the transport. We are trusting the upper NVME layers know which 169401649561SJames Smart * index to use and that they have affinitized a CPU to this hardware 169501649561SJames Smart * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ. 169601649561SJames Smart */ 169766a210ffSJames Smart lpfc_ncmd->cur_iocbq.hba_wqidx = idx; 16984c47efc1SJames Smart cstat = &phba->sli4_hba.hdwq[idx].nvme_cstat; 169966a210ffSJames Smart 170066a210ffSJames Smart lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat); 170166a210ffSJames Smart ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd); 170266a210ffSJames Smart if (ret) { 170344c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 170444c2757bSJames Smart "6175 Fail IO, Prep DMA: " 170544c2757bSJames Smart "idx %d DID %x\n", 170644c2757bSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 170744c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 170866a210ffSJames Smart ret = -ENOMEM; 170966a210ffSJames Smart goto out_free_nvme_buf; 171066a210ffSJames Smart } 171166a210ffSJames Smart 1712bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n", 1713bd2cdd5eSJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 1714bd2cdd5eSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 1715bd2cdd5eSJames Smart 17161fbf9742SJames Smart ret = lpfc_sli4_issue_wqe(phba, lpfc_ncmd->hdwq, &lpfc_ncmd->cur_iocbq); 171701649561SJames Smart if (ret) { 17184b056682SJames Smart atomic_inc(&lport->xmt_fcp_wqerr); 1719e3246a12SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 172044c2757bSJames Smart "6113 Fail IO, Could not issue WQE err %x " 172101649561SJames Smart "sid: x%x did: x%x oxid: x%x\n", 172201649561SJames Smart ret, vport->fc_myDID, ndlp->nlp_DID, 172301649561SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag); 172401649561SJames Smart goto out_free_nvme_buf; 172501649561SJames Smart } 172601649561SJames Smart 1727c490850aSJames Smart if (phba->cfg_xri_rebalancing) 1728c490850aSJames Smart lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_ncmd->hdwq_no); 1729c490850aSJames Smart 1730bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1731c8a4ce0bSDick Kennedy if (lpfc_ncmd->ts_cmd_start) 1732bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_wqput = ktime_get_ns(); 1733bd2cdd5eSJames Smart 1734840eda96SJames Smart if (phba->hdwqstat_on & LPFC_CHECK_NVME_IO) { 1735d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 1736840eda96SJames Smart this_cpu_inc(phba->sli4_hba.c_stat->xmt_io); 173763df6d63SJames Smart lpfc_ncmd->cpu = cpu; 173863df6d63SJames Smart if (idx != cpu) 1739bd2cdd5eSJames Smart lpfc_printf_vlog(vport, 174063df6d63SJames Smart KERN_INFO, LOG_NVME_IOERR, 1741bd2cdd5eSJames Smart "6702 CPU Check cmd: " 1742bd2cdd5eSJames Smart "cpu %d wq %d\n", 1743bd2cdd5eSJames Smart lpfc_ncmd->cpu, 1744bd2cdd5eSJames Smart lpfc_queue_info->index); 1745bd2cdd5eSJames Smart } 1746bd2cdd5eSJames Smart #endif 174701649561SJames Smart return 0; 174801649561SJames Smart 174901649561SJames Smart out_free_nvme_buf: 17502cee7808SJames Smart if (lpfc_ncmd->nvmeCmd->sg_cnt) { 17512cee7808SJames Smart if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE) 17524c47efc1SJames Smart cstat->output_requests--; 17532cee7808SJames Smart else 17544c47efc1SJames Smart cstat->input_requests--; 17552cee7808SJames Smart } else 17564c47efc1SJames Smart cstat->control_requests--; 175701649561SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 175801649561SJames Smart out_fail: 175901649561SJames Smart return ret; 176001649561SJames Smart } 176101649561SJames Smart 176201649561SJames Smart /** 176301649561SJames Smart * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request. 176401649561SJames Smart * @phba: Pointer to HBA context object 176501649561SJames Smart * @cmdiocb: Pointer to command iocb object. 176601649561SJames Smart * @rspiocb: Pointer to response iocb object. 176701649561SJames Smart * 176801649561SJames Smart * This is the callback function for any NVME FCP IO that was aborted. 176901649561SJames Smart * 177001649561SJames Smart * Return value: 177101649561SJames Smart * None 177201649561SJames Smart **/ 177301649561SJames Smart void 177401649561SJames Smart lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 177501649561SJames Smart struct lpfc_wcqe_complete *abts_cmpl) 177601649561SJames Smart { 1777e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME, 177801649561SJames Smart "6145 ABORT_XRI_CN completing on rpi x%x " 177901649561SJames Smart "original iotag x%x, abort cmd iotag x%x " 178001649561SJames Smart "req_tag x%x, status x%x, hwstatus x%x\n", 178101649561SJames Smart cmdiocb->iocb.un.acxri.abortContextTag, 178201649561SJames Smart cmdiocb->iocb.un.acxri.abortIoTag, 178301649561SJames Smart cmdiocb->iotag, 178401649561SJames Smart bf_get(lpfc_wcqe_c_request_tag, abts_cmpl), 178501649561SJames Smart bf_get(lpfc_wcqe_c_status, abts_cmpl), 178601649561SJames Smart bf_get(lpfc_wcqe_c_hw_status, abts_cmpl)); 178701649561SJames Smart lpfc_sli_release_iocbq(phba, cmdiocb); 178801649561SJames Smart } 178901649561SJames Smart 179001649561SJames Smart /** 179101649561SJames Smart * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS 179201649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 179301649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 179401649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 179501649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 179601649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 179701649561SJames Smart * 179801649561SJames Smart * Driver registers this routine as its nvme request io abort handler. This 179901649561SJames Smart * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq 180001649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. This routine 180101649561SJames Smart * is executed asynchronously - one the target is validated as "MAPPED" and 180201649561SJames Smart * ready for IO, the driver issues the abort request and returns. 180301649561SJames Smart * 180401649561SJames Smart * Return value: 180501649561SJames Smart * None 180601649561SJames Smart **/ 180701649561SJames Smart static void 180801649561SJames Smart lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport, 180901649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 181001649561SJames Smart void *hw_queue_handle, 181101649561SJames Smart struct nvmefc_fcp_req *pnvme_fcreq) 181201649561SJames Smart { 181301649561SJames Smart struct lpfc_nvme_lport *lport; 181401649561SJames Smart struct lpfc_vport *vport; 181501649561SJames Smart struct lpfc_hba *phba; 1816c490850aSJames Smart struct lpfc_io_buf *lpfc_nbuf; 181701649561SJames Smart struct lpfc_iocbq *abts_buf; 181801649561SJames Smart struct lpfc_iocbq *nvmereq_wqe; 1819c3725bdcSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 182001649561SJames Smart unsigned long flags; 182101649561SJames Smart int ret_val; 182201649561SJames Smart 1823c3725bdcSJames Smart /* Validate pointers. LLDD fault handling with transport does 1824c3725bdcSJames Smart * have timing races. 1825c3725bdcSJames Smart */ 182601649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 1827c3725bdcSJames Smart if (unlikely(!lport)) 1828c3725bdcSJames Smart return; 182901649561SJames Smart 1830c3725bdcSJames Smart vport = lport->vport; 1831c3725bdcSJames Smart 1832c3725bdcSJames Smart if (unlikely(!hw_queue_handle)) { 1833c3725bdcSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 1834c3725bdcSJames Smart "6129 Fail Abort, HW Queue Handle NULL.\n"); 1835c3725bdcSJames Smart return; 1836c3725bdcSJames Smart } 1837c3725bdcSJames Smart 1838c3725bdcSJames Smart phba = vport->phba; 1839c3725bdcSJames Smart freqpriv = pnvme_fcreq->private; 1840c3725bdcSJames Smart 1841c3725bdcSJames Smart if (unlikely(!freqpriv)) 1842c3725bdcSJames Smart return; 18433386f4bdSJames Smart if (vport->load_flag & FC_UNLOADING) 18443386f4bdSJames Smart return; 18453386f4bdSJames Smart 184601649561SJames Smart /* Announce entry to new IO submit field. */ 184786c67379SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 184801649561SJames Smart "6002 Abort Request to rport DID x%06x " 184932350664SJames Smart "for nvme_fc_req x%px\n", 185001649561SJames Smart pnvme_rport->port_id, 185101649561SJames Smart pnvme_fcreq); 185201649561SJames Smart 185301649561SJames Smart /* If the hba is getting reset, this flag is set. It is 185401649561SJames Smart * cleared when the reset is complete and rings reestablished. 185501649561SJames Smart */ 185601649561SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 185701649561SJames Smart /* driver queued commands are in process of being flushed */ 1858c00f62e6SJames Smart if (phba->hba_flag & HBA_IOQ_FLUSH) { 185901649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 186086c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 186101649561SJames Smart "6139 Driver in reset cleanup - flushing " 186201649561SJames Smart "NVME Req now. hba_flag x%x\n", 186301649561SJames Smart phba->hba_flag); 186401649561SJames Smart return; 186501649561SJames Smart } 186601649561SJames Smart 1867bbe3012bSJames Smart lpfc_nbuf = freqpriv->nvme_buf; 186801649561SJames Smart if (!lpfc_nbuf) { 186901649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 187086c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 187101649561SJames Smart "6140 NVME IO req has no matching lpfc nvme " 187201649561SJames Smart "io buffer. Skipping abort req.\n"); 187301649561SJames Smart return; 187401649561SJames Smart } else if (!lpfc_nbuf->nvmeCmd) { 187501649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 187686c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 187701649561SJames Smart "6141 lpfc NVME IO req has no nvme_fcreq " 187801649561SJames Smart "io buffer. Skipping abort req.\n"); 187901649561SJames Smart return; 188001649561SJames Smart } 18812b7824d0SJames Smart nvmereq_wqe = &lpfc_nbuf->cur_iocbq; 188201649561SJames Smart 1883c2017260SJames Smart /* Guard against IO completion being called at same time */ 1884c2017260SJames Smart spin_lock(&lpfc_nbuf->buf_lock); 1885c2017260SJames Smart 188601649561SJames Smart /* 188701649561SJames Smart * The lpfc_nbuf and the mapped nvme_fcreq in the driver's 188801649561SJames Smart * state must match the nvme_fcreq passed by the nvme 188901649561SJames Smart * transport. If they don't match, it is likely the driver 189001649561SJames Smart * has already completed the NVME IO and the nvme transport 189101649561SJames Smart * has not seen it yet. 189201649561SJames Smart */ 189301649561SJames Smart if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) { 189486c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 189501649561SJames Smart "6143 NVME req mismatch: " 189632350664SJames Smart "lpfc_nbuf x%px nvmeCmd x%px, " 189732350664SJames Smart "pnvme_fcreq x%px. Skipping Abort xri x%x\n", 189801649561SJames Smart lpfc_nbuf, lpfc_nbuf->nvmeCmd, 18992b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1900c2017260SJames Smart goto out_unlock; 190101649561SJames Smart } 190201649561SJames Smart 190301649561SJames Smart /* Don't abort IOs no longer on the pending queue. */ 190401649561SJames Smart if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { 190586c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 190632350664SJames Smart "6142 NVME IO req x%px not queued - skipping " 19072b7824d0SJames Smart "abort req xri x%x\n", 19082b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1909c2017260SJames Smart goto out_unlock; 191001649561SJames Smart } 191101649561SJames Smart 19124b056682SJames Smart atomic_inc(&lport->xmt_fcp_abort); 1913bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n", 1914bd2cdd5eSJames Smart nvmereq_wqe->sli4_xritag, 191500cefeb9SJames Smart nvmereq_wqe->hba_wqidx, pnvme_rport->port_id); 1916bd2cdd5eSJames Smart 191701649561SJames Smart /* Outstanding abort is in progress */ 191801649561SJames Smart if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) { 191986c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 192001649561SJames Smart "6144 Outstanding NVME I/O Abort Request " 192132350664SJames Smart "still pending on nvme_fcreq x%px, " 192232350664SJames Smart "lpfc_ncmd %px xri x%x\n", 19232b7824d0SJames Smart pnvme_fcreq, lpfc_nbuf, 19242b7824d0SJames Smart nvmereq_wqe->sli4_xritag); 1925c2017260SJames Smart goto out_unlock; 192601649561SJames Smart } 192701649561SJames Smart 192801649561SJames Smart abts_buf = __lpfc_sli_get_iocbq(phba); 192901649561SJames Smart if (!abts_buf) { 193086c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 193101649561SJames Smart "6136 No available abort wqes. Skipping " 193232350664SJames Smart "Abts req for nvme_fcreq x%px xri x%x\n", 19332b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1934c2017260SJames Smart goto out_unlock; 193501649561SJames Smart } 193601649561SJames Smart 193701649561SJames Smart /* Ready - mark outstanding as aborted by driver. */ 193801649561SJames Smart nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED; 193901649561SJames Smart 194051f8e43eSJames Smart lpfc_nvme_prep_abort_wqe(abts_buf, nvmereq_wqe->sli4_xritag, 0); 194101649561SJames Smart 194201649561SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 194301649561SJames Smart abts_buf->iocb_flag |= LPFC_IO_NVME; 194401649561SJames Smart abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx; 194501649561SJames Smart abts_buf->vport = vport; 194601649561SJames Smart abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; 19471fbf9742SJames Smart ret_val = lpfc_sli4_issue_wqe(phba, lpfc_nbuf->hdwq, abts_buf); 1948c2017260SJames Smart spin_unlock(&lpfc_nbuf->buf_lock); 194901649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1950cd22d605SDick Kennedy if (ret_val) { 195186c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 195201649561SJames Smart "6137 Failed abts issue_wqe with status x%x " 195332350664SJames Smart "for nvme_fcreq x%px.\n", 195401649561SJames Smart ret_val, pnvme_fcreq); 195501649561SJames Smart lpfc_sli_release_iocbq(phba, abts_buf); 195601649561SJames Smart return; 195701649561SJames Smart } 195801649561SJames Smart 195986c67379SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 19602b7824d0SJames Smart "6138 Transport Abort NVME Request Issued for " 196101649561SJames Smart "ox_id x%x on reqtag x%x\n", 196201649561SJames Smart nvmereq_wqe->sli4_xritag, 196301649561SJames Smart abts_buf->iotag); 1964c2017260SJames Smart return; 1965c2017260SJames Smart 1966c2017260SJames Smart out_unlock: 1967c2017260SJames Smart spin_unlock(&lpfc_nbuf->buf_lock); 1968c2017260SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1969c2017260SJames Smart return; 197001649561SJames Smart } 197101649561SJames Smart 197201649561SJames Smart /* Declare and initialization an instance of the FC NVME template. */ 197301649561SJames Smart static struct nvme_fc_port_template lpfc_nvme_template = { 197401649561SJames Smart /* initiator-based functions */ 197501649561SJames Smart .localport_delete = lpfc_nvme_localport_delete, 197601649561SJames Smart .remoteport_delete = lpfc_nvme_remoteport_delete, 197701649561SJames Smart .create_queue = lpfc_nvme_create_queue, 197801649561SJames Smart .delete_queue = lpfc_nvme_delete_queue, 197901649561SJames Smart .ls_req = lpfc_nvme_ls_req, 198001649561SJames Smart .fcp_io = lpfc_nvme_fcp_io_submit, 198101649561SJames Smart .ls_abort = lpfc_nvme_ls_abort, 198201649561SJames Smart .fcp_abort = lpfc_nvme_fcp_abort, 198301649561SJames Smart 198401649561SJames Smart .max_hw_queues = 1, 198501649561SJames Smart .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS, 198601649561SJames Smart .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS, 198701649561SJames Smart .dma_boundary = 0xFFFFFFFF, 198801649561SJames Smart 198901649561SJames Smart /* Sizes of additional private data for data structures. 199001649561SJames Smart * No use for the last two sizes at this time. 199101649561SJames Smart */ 199201649561SJames Smart .local_priv_sz = sizeof(struct lpfc_nvme_lport), 199301649561SJames Smart .remote_priv_sz = sizeof(struct lpfc_nvme_rport), 199401649561SJames Smart .lsrqst_priv_sz = 0, 1995bbe3012bSJames Smart .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv), 199601649561SJames Smart }; 199701649561SJames Smart 199801649561SJames Smart /** 19995e5b511dSJames Smart * lpfc_get_nvme_buf - Get a nvme buffer from io_buf_list of the HBA 200001649561SJames Smart * @phba: The HBA for which this call is being executed. 200101649561SJames Smart * 20025e5b511dSJames Smart * This routine removes a nvme buffer from head of @hdwq io_buf_list 200301649561SJames Smart * and returns to caller. 200401649561SJames Smart * 200501649561SJames Smart * Return codes: 200601649561SJames Smart * NULL - Error 200701649561SJames Smart * Pointer to lpfc_nvme_buf - Success 200801649561SJames Smart **/ 2009c490850aSJames Smart static struct lpfc_io_buf * 2010cf1a1d3eSJames Smart lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 20115e5b511dSJames Smart int idx, int expedite) 201201649561SJames Smart { 2013c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd; 20145e5b511dSJames Smart struct lpfc_sli4_hdw_queue *qp; 20150794d601SJames Smart struct sli4_sge *sgl; 20160794d601SJames Smart struct lpfc_iocbq *pwqeq; 20170794d601SJames Smart union lpfc_wqe128 *wqe; 201801649561SJames Smart 2019c490850aSJames Smart lpfc_ncmd = lpfc_get_io_buf(phba, NULL, idx, expedite); 20202a5b7d62SJames Smart 20210794d601SJames Smart if (lpfc_ncmd) { 20220794d601SJames Smart pwqeq = &(lpfc_ncmd->cur_iocbq); 20230794d601SJames Smart wqe = &pwqeq->wqe; 20240794d601SJames Smart 20250794d601SJames Smart /* Setup key fields in buffer that may have been changed 20260794d601SJames Smart * if other protocols used this buffer. 20270794d601SJames Smart */ 20280794d601SJames Smart pwqeq->iocb_flag = LPFC_IO_NVME; 20290794d601SJames Smart pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl; 20300794d601SJames Smart lpfc_ncmd->start_time = jiffies; 20310794d601SJames Smart lpfc_ncmd->flags = 0; 20320794d601SJames Smart 20330794d601SJames Smart /* Rsp SGE will be filled in when we rcv an IO 20340794d601SJames Smart * from the NVME Layer to be sent. 20350794d601SJames Smart * The cmd is going to be embedded so we need a SKIP SGE. 20360794d601SJames Smart */ 20370794d601SJames Smart sgl = lpfc_ncmd->dma_sgl; 20380794d601SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 20390794d601SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 20400794d601SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 20410794d601SJames Smart /* Fill in word 3 / sgl_len during cmd submission */ 20420794d601SJames Smart 2043d9f492a1SJames Smart /* Initialize 64 bytes only */ 20440794d601SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 20450794d601SJames Smart 20460794d601SJames Smart if (lpfc_ndlp_check_qdepth(phba, ndlp)) { 20472a5b7d62SJames Smart atomic_inc(&ndlp->cmd_pending); 2048c490850aSJames Smart lpfc_ncmd->flags |= LPFC_SBUF_BUMP_QDEPTH; 20492a5b7d62SJames Smart } 20505e5b511dSJames Smart 2051c490850aSJames Smart } else { 2052c490850aSJames Smart qp = &phba->sli4_hba.hdwq[idx]; 20535e5b511dSJames Smart qp->empty_io_bufs++; 2054c490850aSJames Smart } 20555e5b511dSJames Smart 205601649561SJames Smart return lpfc_ncmd; 205701649561SJames Smart } 205801649561SJames Smart 205901649561SJames Smart /** 206001649561SJames Smart * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list. 206101649561SJames Smart * @phba: The Hba for which this call is being executed. 206201649561SJames Smart * @lpfc_ncmd: The nvme buffer which is being released. 206301649561SJames Smart * 206401649561SJames Smart * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba 20655e5b511dSJames Smart * lpfc_io_buf_list list. For SLI4 XRI's are tied to the nvme buffer 206601649561SJames Smart * and cannot be reused for at least RA_TOV amount of time if it was 206701649561SJames Smart * aborted. 206801649561SJames Smart **/ 206901649561SJames Smart static void 2070c490850aSJames Smart lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd) 207101649561SJames Smart { 20725e5b511dSJames Smart struct lpfc_sli4_hdw_queue *qp; 207301649561SJames Smart unsigned long iflag = 0; 207401649561SJames Smart 2075c490850aSJames Smart if ((lpfc_ncmd->flags & LPFC_SBUF_BUMP_QDEPTH) && lpfc_ncmd->ndlp) 20762a5b7d62SJames Smart atomic_dec(&lpfc_ncmd->ndlp->cmd_pending); 20772a5b7d62SJames Smart 20782a5b7d62SJames Smart lpfc_ncmd->ndlp = NULL; 2079c490850aSJames Smart lpfc_ncmd->flags &= ~LPFC_SBUF_BUMP_QDEPTH; 20802a5b7d62SJames Smart 20811fbf9742SJames Smart qp = lpfc_ncmd->hdwq; 208222770cbaSJames Smart if (unlikely(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) { 208386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 208486c67379SJames Smart "6310 XB release deferred for " 208586c67379SJames Smart "ox_id x%x on reqtag x%x\n", 208686c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 208786c67379SJames Smart lpfc_ncmd->cur_iocbq.iotag); 208886c67379SJames Smart 2089c00f62e6SJames Smart spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag); 209001649561SJames Smart list_add_tail(&lpfc_ncmd->list, 2091c00f62e6SJames Smart &qp->lpfc_abts_io_buf_list); 20925e5b511dSJames Smart qp->abts_nvme_io_bufs++; 2093c00f62e6SJames Smart spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag); 2094c490850aSJames Smart } else 2095c490850aSJames Smart lpfc_release_io_buf(phba, (struct lpfc_io_buf *)lpfc_ncmd, qp); 209601649561SJames Smart } 209701649561SJames Smart 209801649561SJames Smart /** 209901649561SJames Smart * lpfc_nvme_create_localport - Create/Bind an nvme localport instance. 210001649561SJames Smart * @pvport - the lpfc_vport instance requesting a localport. 210101649561SJames Smart * 210201649561SJames Smart * This routine is invoked to create an nvme localport instance to bind 210301649561SJames Smart * to the nvme_fc_transport. It is called once during driver load 210401649561SJames Smart * like lpfc_create_shost after all other services are initialized. 210501649561SJames Smart * It requires a vport, vpi, and wwns at call time. Other localport 210601649561SJames Smart * parameters are modified as the driver's FCID and the Fabric WWN 210701649561SJames Smart * are established. 210801649561SJames Smart * 210901649561SJames Smart * Return codes 211001649561SJames Smart * 0 - successful 211101649561SJames Smart * -ENOMEM - no heap memory available 211201649561SJames Smart * other values - from nvme registration upcall 211301649561SJames Smart **/ 211401649561SJames Smart int 211501649561SJames Smart lpfc_nvme_create_localport(struct lpfc_vport *vport) 211601649561SJames Smart { 2117166d7211SJames Smart int ret = 0; 211801649561SJames Smart struct lpfc_hba *phba = vport->phba; 211901649561SJames Smart struct nvme_fc_port_info nfcp_info; 212001649561SJames Smart struct nvme_fc_local_port *localport; 212101649561SJames Smart struct lpfc_nvme_lport *lport; 212201649561SJames Smart 212301649561SJames Smart /* Initialize this localport instance. The vport wwn usage ensures 212401649561SJames Smart * that NPIV is accounted for. 212501649561SJames Smart */ 212601649561SJames Smart memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info)); 212701649561SJames Smart nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR; 212801649561SJames Smart nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 212901649561SJames Smart nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 213001649561SJames Smart 21315b9e70b2SJames Smart /* We need to tell the transport layer + 1 because it takes page 21325b9e70b2SJames Smart * alignment into account. When space for the SGL is allocated we 21335b9e70b2SJames Smart * allocate + 3, one for cmd, one for rsp and one for this alignment 21344d4c4a4aSJames Smart */ 21354d4c4a4aSJames Smart lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 213601649561SJames Smart 2137542ddc9bSJames Smart /* Advertise how many hw queues we support based on cfg_hdw_queue, 2138542ddc9bSJames Smart * which will not exceed cpu count. 2139542ddc9bSJames Smart */ 2140cdb42becSJames Smart lpfc_nvme_template.max_hw_queues = phba->cfg_hdw_queue; 214166a210ffSJames Smart 2142faf5a744SArnd Bergmann if (!IS_ENABLED(CONFIG_NVME_FC)) 2143faf5a744SArnd Bergmann return ret; 2144faf5a744SArnd Bergmann 214501649561SJames Smart /* localport is allocated from the stack, but the registration 214601649561SJames Smart * call allocates heap memory as well as the private area. 214701649561SJames Smart */ 2148faf5a744SArnd Bergmann 214901649561SJames Smart ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template, 215001649561SJames Smart &vport->phba->pcidev->dev, &localport); 215101649561SJames Smart if (!ret) { 215201649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC, 215301649561SJames Smart "6005 Successfully registered local " 215432350664SJames Smart "NVME port num %d, localP x%px, private " 215532350664SJames Smart "x%px, sg_seg %d\n", 215601649561SJames Smart localport->port_num, localport, 215701649561SJames Smart localport->private, 215801649561SJames Smart lpfc_nvme_template.max_sgl_segments); 215901649561SJames Smart 216001649561SJames Smart /* Private is our lport size declared in the template. */ 216101649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 216201649561SJames Smart vport->localport = localport; 216301649561SJames Smart lport->vport = vport; 216401649561SJames Smart vport->nvmei_support = 1; 21656b486ce9SDick Kennedy 21664b056682SJames Smart atomic_set(&lport->xmt_fcp_noxri, 0); 21674b056682SJames Smart atomic_set(&lport->xmt_fcp_bad_ndlp, 0); 21684b056682SJames Smart atomic_set(&lport->xmt_fcp_qdepth, 0); 216944c2757bSJames Smart atomic_set(&lport->xmt_fcp_err, 0); 21704b056682SJames Smart atomic_set(&lport->xmt_fcp_wqerr, 0); 21714b056682SJames Smart atomic_set(&lport->xmt_fcp_abort, 0); 21724b056682SJames Smart atomic_set(&lport->xmt_ls_abort, 0); 21734b056682SJames Smart atomic_set(&lport->xmt_ls_err, 0); 21744b056682SJames Smart atomic_set(&lport->cmpl_fcp_xb, 0); 21754b056682SJames Smart atomic_set(&lport->cmpl_fcp_err, 0); 21764b056682SJames Smart atomic_set(&lport->cmpl_ls_xb, 0); 21774b056682SJames Smart atomic_set(&lport->cmpl_ls_err, 0); 217866a210ffSJames Smart atomic_set(&lport->fc4NvmeLsRequests, 0); 217966a210ffSJames Smart atomic_set(&lport->fc4NvmeLsCmpls, 0); 21806b486ce9SDick Kennedy } 21813ebd9b47SJames Smart 218201649561SJames Smart return ret; 218301649561SJames Smart } 218401649561SJames Smart 2185d964b3e5SBart Van Assche #if (IS_ENABLED(CONFIG_NVME_FC)) 2186add9d6beSJames Smart /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg. 2187add9d6beSJames Smart * 2188add9d6beSJames Smart * The driver has to wait for the host nvme transport to callback 2189add9d6beSJames Smart * indicating the localport has successfully unregistered all 2190add9d6beSJames Smart * resources. Since this is an uninterruptible wait, loop every ten 2191add9d6beSJames Smart * seconds and print a message indicating no progress. 2192add9d6beSJames Smart * 2193add9d6beSJames Smart * An uninterruptible wait is used because of the risk of transport-to- 2194add9d6beSJames Smart * driver state mismatch. 2195add9d6beSJames Smart */ 21963999df75SBart Van Assche static void 2197add9d6beSJames Smart lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport, 21987961cba6SEwan D. Milne struct lpfc_nvme_lport *lport, 21997961cba6SEwan D. Milne struct completion *lport_unreg_cmp) 2200add9d6beSJames Smart { 2201add9d6beSJames Smart u32 wait_tmo; 22022ab70c21SJames Smart int ret, i, pending = 0; 22032ab70c21SJames Smart struct lpfc_sli_ring *pring; 22042ab70c21SJames Smart struct lpfc_hba *phba = vport->phba; 2205add9d6beSJames Smart 2206add9d6beSJames Smart /* Host transport has to clean up and confirm requiring an indefinite 2207add9d6beSJames Smart * wait. Print a message if a 10 second wait expires and renew the 2208add9d6beSJames Smart * wait. This is unexpected. 2209add9d6beSJames Smart */ 2210add9d6beSJames Smart wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000); 2211add9d6beSJames Smart while (true) { 22127961cba6SEwan D. Milne ret = wait_for_completion_timeout(lport_unreg_cmp, wait_tmo); 2213add9d6beSJames Smart if (unlikely(!ret)) { 22142ab70c21SJames Smart pending = 0; 22152ab70c21SJames Smart for (i = 0; i < phba->cfg_hdw_queue; i++) { 2216c00f62e6SJames Smart pring = phba->sli4_hba.hdwq[i].io_wq->pring; 22172ab70c21SJames Smart if (!pring) 22182ab70c21SJames Smart continue; 22192ab70c21SJames Smart if (pring->txcmplq_cnt) 22202ab70c21SJames Smart pending += pring->txcmplq_cnt; 22212ab70c21SJames Smart } 2222add9d6beSJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 222332350664SJames Smart "6176 Lport x%px Localport x%px wait " 22242ab70c21SJames Smart "timed out. Pending %d. Renewing.\n", 22252ab70c21SJames Smart lport, vport->localport, pending); 2226add9d6beSJames Smart continue; 2227add9d6beSJames Smart } 2228add9d6beSJames Smart break; 2229add9d6beSJames Smart } 2230add9d6beSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 223132350664SJames Smart "6177 Lport x%px Localport x%px Complete Success\n", 2232add9d6beSJames Smart lport, vport->localport); 2233add9d6beSJames Smart } 2234d964b3e5SBart Van Assche #endif 2235add9d6beSJames Smart 223601649561SJames Smart /** 223701649561SJames Smart * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport. 223801649561SJames Smart * @pnvme: pointer to lpfc nvme data structure. 223901649561SJames Smart * 224001649561SJames Smart * This routine is invoked to destroy all lports bound to the phba. 224101649561SJames Smart * The lport memory was allocated by the nvme fc transport and is 224201649561SJames Smart * released there. This routine ensures all rports bound to the 224301649561SJames Smart * lport have been disconnected. 224401649561SJames Smart * 224501649561SJames Smart **/ 224601649561SJames Smart void 224701649561SJames Smart lpfc_nvme_destroy_localport(struct lpfc_vport *vport) 224801649561SJames Smart { 22497d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 225001649561SJames Smart struct nvme_fc_local_port *localport; 225101649561SJames Smart struct lpfc_nvme_lport *lport; 225201649561SJames Smart int ret; 22537961cba6SEwan D. Milne DECLARE_COMPLETION_ONSTACK(lport_unreg_cmp); 225401649561SJames Smart 225501649561SJames Smart if (vport->nvmei_support == 0) 225601649561SJames Smart return; 225701649561SJames Smart 225801649561SJames Smart localport = vport->localport; 225901649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 226001649561SJames Smart 226101649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 226232350664SJames Smart "6011 Destroying NVME localport x%px\n", 226301649561SJames Smart localport); 2264166d7211SJames Smart 226501649561SJames Smart /* lport's rport list is clear. Unregister 226601649561SJames Smart * lport and release resources. 226701649561SJames Smart */ 22687961cba6SEwan D. Milne lport->lport_unreg_cmp = &lport_unreg_cmp; 226901649561SJames Smart ret = nvme_fc_unregister_localport(localport); 2270add9d6beSJames Smart 2271add9d6beSJames Smart /* Wait for completion. This either blocks 2272add9d6beSJames Smart * indefinitely or succeeds 2273add9d6beSJames Smart */ 22747961cba6SEwan D. Milne lpfc_nvme_lport_unreg_wait(vport, lport, &lport_unreg_cmp); 22757961cba6SEwan D. Milne vport->localport = NULL; 227601649561SJames Smart 227701649561SJames Smart /* Regardless of the unregister upcall response, clear 227801649561SJames Smart * nvmei_support. All rports are unregistered and the 227901649561SJames Smart * driver will clean up. 228001649561SJames Smart */ 228101649561SJames Smart vport->nvmei_support = 0; 228201649561SJames Smart if (ret == 0) { 228301649561SJames Smart lpfc_printf_vlog(vport, 228401649561SJames Smart KERN_INFO, LOG_NVME_DISC, 228501649561SJames Smart "6009 Unregistered lport Success\n"); 228601649561SJames Smart } else { 228701649561SJames Smart lpfc_printf_vlog(vport, 228801649561SJames Smart KERN_INFO, LOG_NVME_DISC, 228901649561SJames Smart "6010 Unregistered lport " 229001649561SJames Smart "Failed, status x%x\n", 229101649561SJames Smart ret); 229201649561SJames Smart } 2293166d7211SJames Smart #endif 229401649561SJames Smart } 229501649561SJames Smart 229601649561SJames Smart void 229701649561SJames Smart lpfc_nvme_update_localport(struct lpfc_vport *vport) 229801649561SJames Smart { 22994410a67aSJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 230001649561SJames Smart struct nvme_fc_local_port *localport; 230101649561SJames Smart struct lpfc_nvme_lport *lport; 230201649561SJames Smart 230301649561SJames Smart localport = vport->localport; 23044410a67aSJames Smart if (!localport) { 23054410a67aSJames Smart lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME, 23064410a67aSJames Smart "6710 Update NVME fail. No localport\n"); 23074410a67aSJames Smart return; 23084410a67aSJames Smart } 230901649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 23104410a67aSJames Smart if (!lport) { 23114410a67aSJames Smart lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME, 231232350664SJames Smart "6171 Update NVME fail. localP x%px, No lport\n", 23134410a67aSJames Smart localport); 23144410a67aSJames Smart return; 23154410a67aSJames Smart } 231601649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 231732350664SJames Smart "6012 Update NVME lport x%px did x%x\n", 231801649561SJames Smart localport, vport->fc_myDID); 231901649561SJames Smart 232001649561SJames Smart localport->port_id = vport->fc_myDID; 232101649561SJames Smart if (localport->port_id == 0) 232201649561SJames Smart localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY; 232301649561SJames Smart else 232401649561SJames Smart localport->port_role = FC_PORT_ROLE_NVME_INITIATOR; 232501649561SJames Smart 232601649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 232732350664SJames Smart "6030 bound lport x%px to DID x%06x\n", 232801649561SJames Smart lport, localport->port_id); 23294410a67aSJames Smart #endif 233001649561SJames Smart } 233101649561SJames Smart 233201649561SJames Smart int 233301649561SJames Smart lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 233401649561SJames Smart { 23357d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 233601649561SJames Smart int ret = 0; 233701649561SJames Smart struct nvme_fc_local_port *localport; 233801649561SJames Smart struct lpfc_nvme_lport *lport; 233901649561SJames Smart struct lpfc_nvme_rport *rport; 234001466024SJames Smart struct lpfc_nvme_rport *oldrport; 234101649561SJames Smart struct nvme_fc_remote_port *remote_port; 234201649561SJames Smart struct nvme_fc_port_info rpinfo; 234393a3922dSJames Smart struct lpfc_nodelist *prev_ndlp = NULL; 234401649561SJames Smart 234501649561SJames Smart lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC, 234601649561SJames Smart "6006 Register NVME PORT. DID x%06x nlptype x%x\n", 234701649561SJames Smart ndlp->nlp_DID, ndlp->nlp_type); 234801649561SJames Smart 234901649561SJames Smart localport = vport->localport; 2350bb6a8a2cSDick Kennedy if (!localport) 2351bb6a8a2cSDick Kennedy return 0; 2352bb6a8a2cSDick Kennedy 235301649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 235401649561SJames Smart 23557a06dcd3SJames Smart /* NVME rports are not preserved across devloss. 23567a06dcd3SJames Smart * Just register this instance. Note, rpinfo->dev_loss_tmo 23577a06dcd3SJames Smart * is left 0 to indicate accept transport defaults. The 23587a06dcd3SJames Smart * driver communicates port role capabilities consistent 23597a06dcd3SJames Smart * with the PRLI response data. 236001649561SJames Smart */ 23617a06dcd3SJames Smart memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info)); 23627a06dcd3SJames Smart rpinfo.port_id = ndlp->nlp_DID; 236301649561SJames Smart if (ndlp->nlp_type & NLP_NVME_TARGET) 23647a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET; 236501649561SJames Smart if (ndlp->nlp_type & NLP_NVME_INITIATOR) 23667a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR; 236701649561SJames Smart 23687a06dcd3SJames Smart if (ndlp->nlp_type & NLP_NVME_DISCOVERY) 23697a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY; 23707a06dcd3SJames Smart 23717a06dcd3SJames Smart rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); 23727a06dcd3SJames Smart rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); 237301466024SJames Smart 23749e210178SJames Smart spin_lock_irq(&vport->phba->hbalock); 237501466024SJames Smart oldrport = lpfc_ndlp_get_nrport(ndlp); 237661184f17SJames Smart if (oldrport) { 237761184f17SJames Smart prev_ndlp = oldrport->ndlp; 23789e210178SJames Smart spin_unlock_irq(&vport->phba->hbalock); 237961184f17SJames Smart } else { 238061184f17SJames Smart spin_unlock_irq(&vport->phba->hbalock); 23813fd78355SJames Smart lpfc_nlp_get(ndlp); 238261184f17SJames Smart } 23833fd78355SJames Smart 23847a06dcd3SJames Smart ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port); 23857a06dcd3SJames Smart if (!ret) { 23867a06dcd3SJames Smart /* If the ndlp already has an nrport, this is just 23877a06dcd3SJames Smart * a resume of the existing rport. Else this is a 23887a06dcd3SJames Smart * new rport. 23897a06dcd3SJames Smart */ 2390b15bd3e6SJames Smart /* Guard against an unregister/reregister 2391b15bd3e6SJames Smart * race that leaves the WAIT flag set. 2392b15bd3e6SJames Smart */ 2393b15bd3e6SJames Smart spin_lock_irq(&vport->phba->hbalock); 2394b15bd3e6SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 2395b15bd3e6SJames Smart spin_unlock_irq(&vport->phba->hbalock); 23967a06dcd3SJames Smart rport = remote_port->private; 239701466024SJames Smart if (oldrport) { 239893a3922dSJames Smart /* New remoteport record does not guarantee valid 239993a3922dSJames Smart * host private memory area. 240093a3922dSJames Smart */ 240101466024SJames Smart if (oldrport == remote_port->private) { 240293a3922dSJames Smart /* Same remoteport - ndlp should match. 240393a3922dSJames Smart * Just reuse. 240493a3922dSJames Smart */ 240501649561SJames Smart lpfc_printf_vlog(ndlp->vport, KERN_INFO, 240601649561SJames Smart LOG_NVME_DISC, 24076825b7bdSJames Smart "6014 Rebind lport to current " 240832350664SJames Smart "remoteport x%px wwpn 0x%llx, " 240932350664SJames Smart "Data: x%x x%x x%px x%px x%x " 241032350664SJames Smart " x%06x\n", 24113fd78355SJames Smart remote_port, 241201649561SJames Smart remote_port->port_name, 241301649561SJames Smart remote_port->port_id, 241401649561SJames Smart remote_port->port_role, 241561184f17SJames Smart oldrport->ndlp, 24163fd78355SJames Smart ndlp, 241701649561SJames Smart ndlp->nlp_type, 241801649561SJames Smart ndlp->nlp_DID); 24196825b7bdSJames Smart 24206825b7bdSJames Smart /* It's a complete rebind only if the driver 24216825b7bdSJames Smart * is registering with the same ndlp. Otherwise 24226825b7bdSJames Smart * the driver likely executed a node swap 24236825b7bdSJames Smart * prior to this registration and the ndlp to 24246825b7bdSJames Smart * remoteport binding needs to be redone. 24256825b7bdSJames Smart */ 24266825b7bdSJames Smart if (prev_ndlp == ndlp) 24273fd78355SJames Smart return 0; 24286825b7bdSJames Smart 24293fd78355SJames Smart } 24302b75d0f9SDick Kennedy 24313fd78355SJames Smart /* Sever the ndlp<->rport association 24323fd78355SJames Smart * before dropping the ndlp ref from 24333fd78355SJames Smart * register. 24342b75d0f9SDick Kennedy */ 24353fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 24362b75d0f9SDick Kennedy ndlp->nrport = NULL; 243701466024SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 24383fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 24392b75d0f9SDick Kennedy rport->ndlp = NULL; 24403fd78355SJames Smart rport->remoteport = NULL; 2441b04744ceSJames Smart 2442b04744ceSJames Smart /* Reference only removed if previous NDLP is no longer 2443b04744ceSJames Smart * active. It might be just a swap and removing the 2444b04744ceSJames Smart * reference would cause a premature cleanup. 2445b04744ceSJames Smart */ 2446b04744ceSJames Smart if (prev_ndlp && prev_ndlp != ndlp) { 2447b04744ceSJames Smart if ((!NLP_CHK_NODE_ACT(prev_ndlp)) || 2448b04744ceSJames Smart (!prev_ndlp->nrport)) 2449b04744ceSJames Smart lpfc_nlp_put(prev_ndlp); 2450b04744ceSJames Smart } 24512b75d0f9SDick Kennedy } 24522b75d0f9SDick Kennedy 24532b75d0f9SDick Kennedy /* Clean bind the rport to the ndlp. */ 245401649561SJames Smart rport->remoteport = remote_port; 245501649561SJames Smart rport->lport = lport; 24563fd78355SJames Smart rport->ndlp = ndlp; 24573fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 245801649561SJames Smart ndlp->nrport = rport; 24593fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 246001649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, 246101649561SJames Smart LOG_NVME_DISC | LOG_NODE, 24626825b7bdSJames Smart "6022 Bind lport x%px to remoteport x%px " 24636825b7bdSJames Smart "rport x%px WWNN 0x%llx, " 24647a06dcd3SJames Smart "Rport WWPN 0x%llx DID " 246532350664SJames Smart "x%06x Role x%x, ndlp %p prev_ndlp x%px\n", 246693a3922dSJames Smart lport, remote_port, rport, 246701649561SJames Smart rpinfo.node_name, rpinfo.port_name, 24683fd78355SJames Smart rpinfo.port_id, rpinfo.port_role, 246993a3922dSJames Smart ndlp, prev_ndlp); 247001649561SJames Smart } else { 247101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, 247201649561SJames Smart LOG_NVME_DISC | LOG_NODE, 247301649561SJames Smart "6031 RemotePort Registration failed " 247401649561SJames Smart "err: %d, DID x%06x\n", 247501649561SJames Smart ret, ndlp->nlp_DID); 247601649561SJames Smart } 24777a06dcd3SJames Smart 247801649561SJames Smart return ret; 2479166d7211SJames Smart #else 2480166d7211SJames Smart return 0; 2481166d7211SJames Smart #endif 248201649561SJames Smart } 248301649561SJames Smart 24846f2589f4SJames Smart /** 24856f2589f4SJames Smart * lpfc_nvme_rescan_port - Check to see if we should rescan this remoteport 24866f2589f4SJames Smart * 24876f2589f4SJames Smart * If the ndlp represents an NVME Target, that we are logged into, 24886f2589f4SJames Smart * ping the NVME FC Transport layer to initiate a device rescan 24896f2589f4SJames Smart * on this remote NPort. 24906f2589f4SJames Smart */ 24916f2589f4SJames Smart void 24926f2589f4SJames Smart lpfc_nvme_rescan_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 24936f2589f4SJames Smart { 24946f2589f4SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 2495a6d10f24SJames Smart struct lpfc_nvme_rport *nrport; 2496a6d10f24SJames Smart struct nvme_fc_remote_port *remoteport = NULL; 24976f2589f4SJames Smart 2498a6d10f24SJames Smart spin_lock_irq(&vport->phba->hbalock); 2499a6d10f24SJames Smart nrport = lpfc_ndlp_get_nrport(ndlp); 2500a6d10f24SJames Smart if (nrport) 2501a6d10f24SJames Smart remoteport = nrport->remoteport; 2502a6d10f24SJames Smart spin_unlock_irq(&vport->phba->hbalock); 25036f2589f4SJames Smart 25046f2589f4SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 25056f2589f4SJames Smart "6170 Rescan NPort DID x%06x type x%x " 2506a6d10f24SJames Smart "state x%x nrport x%px remoteport x%px\n", 2507a6d10f24SJames Smart ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_state, 2508a6d10f24SJames Smart nrport, remoteport); 2509a6d10f24SJames Smart 2510a6d10f24SJames Smart if (!nrport || !remoteport) 2511a6d10f24SJames Smart goto rescan_exit; 25126f2589f4SJames Smart 25136f2589f4SJames Smart /* Only rescan if we are an NVME target in the MAPPED state */ 25146f2589f4SJames Smart if (remoteport->port_role & FC_PORT_ROLE_NVME_DISCOVERY && 25156f2589f4SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE) { 25166f2589f4SJames Smart nvme_fc_rescan_remoteport(remoteport); 25176f2589f4SJames Smart 25186f2589f4SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 25196f2589f4SJames Smart "6172 NVME rescanned DID x%06x " 25206f2589f4SJames Smart "port_state x%x\n", 25216f2589f4SJames Smart ndlp->nlp_DID, remoteport->port_state); 25226f2589f4SJames Smart } 25236f2589f4SJames Smart return; 2524a6d10f24SJames Smart rescan_exit: 2525a6d10f24SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 2526a6d10f24SJames Smart "6169 Skip NVME Rport Rescan, NVME remoteport " 2527a6d10f24SJames Smart "unregistered\n"); 25286f2589f4SJames Smart #endif 25296f2589f4SJames Smart } 25306f2589f4SJames Smart 253101649561SJames Smart /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport. 253201649561SJames Smart * 253301649561SJames Smart * There is no notion of Devloss or rport recovery from the current 253401649561SJames Smart * nvme_transport perspective. Loss of an rport just means IO cannot 253501649561SJames Smart * be sent and recovery is completely up to the initator. 253601649561SJames Smart * For now, the driver just unbinds the DID and port_role so that 253701649561SJames Smart * no further IO can be issued. Changes are planned for later. 253801649561SJames Smart * 253901649561SJames Smart * Notes - the ndlp reference count is not decremented here since 254001649561SJames Smart * since there is no nvme_transport api for devloss. Node ref count 254101649561SJames Smart * is only adjusted in driver unload. 254201649561SJames Smart */ 254301649561SJames Smart void 254401649561SJames Smart lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 254501649561SJames Smart { 25467d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 254701649561SJames Smart int ret; 254801649561SJames Smart struct nvme_fc_local_port *localport; 254901649561SJames Smart struct lpfc_nvme_lport *lport; 255001649561SJames Smart struct lpfc_nvme_rport *rport; 25519e210178SJames Smart struct nvme_fc_remote_port *remoteport = NULL; 255201649561SJames Smart 255301649561SJames Smart localport = vport->localport; 255401649561SJames Smart 255501649561SJames Smart /* This is fundamental error. The localport is always 255601649561SJames Smart * available until driver unload. Just exit. 255701649561SJames Smart */ 255801649561SJames Smart if (!localport) 255901649561SJames Smart return; 256001649561SJames Smart 256101649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 256201649561SJames Smart if (!lport) 256301649561SJames Smart goto input_err; 256401649561SJames Smart 25659e210178SJames Smart spin_lock_irq(&vport->phba->hbalock); 256601466024SJames Smart rport = lpfc_ndlp_get_nrport(ndlp); 25679e210178SJames Smart if (rport) 25689e210178SJames Smart remoteport = rport->remoteport; 25699e210178SJames Smart spin_unlock_irq(&vport->phba->hbalock); 25709e210178SJames Smart if (!remoteport) 257101649561SJames Smart goto input_err; 257201649561SJames Smart 257301649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 257432350664SJames Smart "6033 Unreg nvme remoteport x%px, portname x%llx, " 257501649561SJames Smart "port_id x%06x, portstate x%x port type x%x\n", 257601649561SJames Smart remoteport, remoteport->port_name, 257701649561SJames Smart remoteport->port_id, remoteport->port_state, 257801649561SJames Smart ndlp->nlp_type); 257901649561SJames Smart 258001649561SJames Smart /* Sanity check ndlp type. Only call for NVME ports. Don't 258101649561SJames Smart * clear any rport state until the transport calls back. 258201649561SJames Smart */ 25833b5bde69SJames Smart 25843b5bde69SJames Smart if (ndlp->nlp_type & NLP_NVME_TARGET) { 25857a06dcd3SJames Smart /* No concern about the role change on the nvme remoteport. 25867a06dcd3SJames Smart * The transport will update it. 25877a06dcd3SJames Smart */ 2588add9d6beSJames Smart ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG; 25897438273fSJames Smart 25907438273fSJames Smart /* Don't let the host nvme transport keep sending keep-alives 25917438273fSJames Smart * on this remoteport. Vport is unloading, no recovery. The 25927438273fSJames Smart * return values is ignored. The upcall is a courtesy to the 25937438273fSJames Smart * transport. 25947438273fSJames Smart */ 25957438273fSJames Smart if (vport->load_flag & FC_UNLOADING) 25967438273fSJames Smart (void)nvme_fc_set_remoteport_devloss(remoteport, 0); 25977438273fSJames Smart 259801649561SJames Smart ret = nvme_fc_unregister_remoteport(remoteport); 25993fd78355SJames Smart if (ret != 0) { 26003fd78355SJames Smart lpfc_nlp_put(ndlp); 260101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 260201649561SJames Smart "6167 NVME unregister failed %d " 260301649561SJames Smart "port_state x%x\n", 260401649561SJames Smart ret, remoteport->port_state); 26053fd78355SJames Smart } 260601649561SJames Smart } 260701649561SJames Smart return; 260801649561SJames Smart 260901649561SJames Smart input_err: 2610166d7211SJames Smart #endif 261101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 261232350664SJames Smart "6168 State error: lport x%px, rport x%px FCID x%06x\n", 261301649561SJames Smart vport->localport, ndlp->rport, ndlp->nlp_DID); 261401649561SJames Smart } 2615318083adSJames Smart 2616318083adSJames Smart /** 2617318083adSJames Smart * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort 2618318083adSJames Smart * @phba: pointer to lpfc hba data structure. 2619318083adSJames Smart * @axri: pointer to the fcp xri abort wcqe structure. 2620c00f62e6SJames Smart * @lpfc_ncmd: The nvme job structure for the request being aborted. 2621318083adSJames Smart * 2622318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 2623952c303bSDick Kennedy * NVME aborted xri. Aborted NVME IO commands are completed to the transport 2624952c303bSDick Kennedy * here. 2625318083adSJames Smart **/ 2626318083adSJames Smart void 2627318083adSJames Smart lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba, 2628c00f62e6SJames Smart struct sli4_wcqe_xri_aborted *axri, 2629c00f62e6SJames Smart struct lpfc_io_buf *lpfc_ncmd) 2630318083adSJames Smart { 2631318083adSJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 2632952c303bSDick Kennedy struct nvmefc_fcp_req *nvme_cmd = NULL; 2633c00f62e6SJames Smart struct lpfc_nodelist *ndlp = lpfc_ncmd->ndlp; 2634318083adSJames Smart 2635318083adSJames Smart 2636952c303bSDick Kennedy if (ndlp) 2637318083adSJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 263886c67379SJames Smart 263986c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2640c00f62e6SJames Smart "6311 nvme_cmd %p xri x%x tag x%x abort complete and " 2641c00f62e6SJames Smart "xri released\n", 2642952c303bSDick Kennedy lpfc_ncmd->nvmeCmd, xri, 2643952c303bSDick Kennedy lpfc_ncmd->cur_iocbq.iotag); 264486c67379SJames Smart 2645952c303bSDick Kennedy /* Aborted NVME commands are required to not complete 2646952c303bSDick Kennedy * before the abort exchange command fully completes. 2647952c303bSDick Kennedy * Once completed, it is available via the put list. 2648952c303bSDick Kennedy */ 26493fd78355SJames Smart if (lpfc_ncmd->nvmeCmd) { 2650952c303bSDick Kennedy nvme_cmd = lpfc_ncmd->nvmeCmd; 2651952c303bSDick Kennedy nvme_cmd->done(nvme_cmd); 26523fd78355SJames Smart lpfc_ncmd->nvmeCmd = NULL; 26533fd78355SJames Smart } 2654318083adSJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 2655318083adSJames Smart } 2656c3725bdcSJames Smart 2657c3725bdcSJames Smart /** 2658c3725bdcSJames Smart * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete 2659c3725bdcSJames Smart * @phba: Pointer to HBA context object. 2660c3725bdcSJames Smart * 2661c3725bdcSJames Smart * This function flushes all wqes in the nvme rings and frees all resources 2662c3725bdcSJames Smart * in the txcmplq. This function does not issue abort wqes for the IO 2663c3725bdcSJames Smart * commands in txcmplq, they will just be returned with 2664c3725bdcSJames Smart * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI 2665c3725bdcSJames Smart * slot has been permanently disabled. 2666c3725bdcSJames Smart **/ 2667c3725bdcSJames Smart void 2668c3725bdcSJames Smart lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba) 2669c3725bdcSJames Smart { 2670c3725bdcSJames Smart struct lpfc_sli_ring *pring; 2671c3725bdcSJames Smart u32 i, wait_cnt = 0; 2672c3725bdcSJames Smart 2673cdb42becSJames Smart if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.hdwq) 2674c3725bdcSJames Smart return; 2675c3725bdcSJames Smart 2676c00f62e6SJames Smart /* Cycle through all IO rings and make sure all outstanding 2677c3725bdcSJames Smart * WQEs have been removed from the txcmplqs. 2678c3725bdcSJames Smart */ 2679cdb42becSJames Smart for (i = 0; i < phba->cfg_hdw_queue; i++) { 2680c00f62e6SJames Smart if (!phba->sli4_hba.hdwq[i].io_wq) 26816a828b0fSJames Smart continue; 2682c00f62e6SJames Smart pring = phba->sli4_hba.hdwq[i].io_wq->pring; 2683c3725bdcSJames Smart 2684d580c613SJames Smart if (!pring) 2685d580c613SJames Smart continue; 2686d580c613SJames Smart 2687c3725bdcSJames Smart /* Retrieve everything on the txcmplq */ 2688c3725bdcSJames Smart while (!list_empty(&pring->txcmplq)) { 2689c3725bdcSJames Smart msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); 2690c3725bdcSJames Smart wait_cnt++; 2691c3725bdcSJames Smart 2692c3725bdcSJames Smart /* The sleep is 10mS. Every ten seconds, 2693c3725bdcSJames Smart * dump a message. Something is wrong. 2694c3725bdcSJames Smart */ 2695c3725bdcSJames Smart if ((wait_cnt % 1000) == 0) { 2696c3725bdcSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2697c3725bdcSJames Smart "6178 NVME IO not empty, " 2698c3725bdcSJames Smart "cnt %d\n", wait_cnt); 2699c3725bdcSJames Smart } 2700c3725bdcSJames Smart } 2701c3725bdcSJames Smart } 2702c3725bdcSJames Smart } 270384f2ddf8SJames Smart 270484f2ddf8SJames Smart void 270584f2ddf8SJames Smart lpfc_nvme_cancel_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn) 270684f2ddf8SJames Smart { 270784f2ddf8SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 270884f2ddf8SJames Smart struct lpfc_io_buf *lpfc_ncmd; 270984f2ddf8SJames Smart struct nvmefc_fcp_req *nCmd; 271084f2ddf8SJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 271184f2ddf8SJames Smart 271284f2ddf8SJames Smart if (!pwqeIn->context1) { 271384f2ddf8SJames Smart lpfc_sli_release_iocbq(phba, pwqeIn); 271484f2ddf8SJames Smart return; 271584f2ddf8SJames Smart } 271684f2ddf8SJames Smart /* For abort iocb just return, IO iocb will do a done call */ 271784f2ddf8SJames Smart if (bf_get(wqe_cmnd, &pwqeIn->wqe.gen_req.wqe_com) == 271884f2ddf8SJames Smart CMD_ABORT_XRI_CX) { 271984f2ddf8SJames Smart lpfc_sli_release_iocbq(phba, pwqeIn); 272084f2ddf8SJames Smart return; 272184f2ddf8SJames Smart } 272284f2ddf8SJames Smart lpfc_ncmd = (struct lpfc_io_buf *)pwqeIn->context1; 272384f2ddf8SJames Smart 272484f2ddf8SJames Smart spin_lock(&lpfc_ncmd->buf_lock); 272584f2ddf8SJames Smart if (!lpfc_ncmd->nvmeCmd) { 272684f2ddf8SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 272784f2ddf8SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 272884f2ddf8SJames Smart return; 272984f2ddf8SJames Smart } 273084f2ddf8SJames Smart 273184f2ddf8SJames Smart nCmd = lpfc_ncmd->nvmeCmd; 273284f2ddf8SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 273384f2ddf8SJames Smart "6194 NVME Cancel xri %x\n", 273484f2ddf8SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag); 273584f2ddf8SJames Smart 273684f2ddf8SJames Smart nCmd->transferred_length = 0; 273784f2ddf8SJames Smart nCmd->rcv_rsplen = 0; 273884f2ddf8SJames Smart nCmd->status = NVME_SC_INTERNAL; 273984f2ddf8SJames Smart freqpriv = nCmd->private; 274084f2ddf8SJames Smart freqpriv->nvme_buf = NULL; 274184f2ddf8SJames Smart lpfc_ncmd->nvmeCmd = NULL; 274284f2ddf8SJames Smart 274384f2ddf8SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 274484f2ddf8SJames Smart nCmd->done(nCmd); 274584f2ddf8SJames Smart 274684f2ddf8SJames Smart /* Call release with XB=1 to queue the IO into the abort list. */ 274784f2ddf8SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 274884f2ddf8SJames Smart #endif 274984f2ddf8SJames Smart } 2750