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 <linux/nvme.h> 4001649561SJames Smart #include <linux/nvme-fc-driver.h> 4101649561SJames Smart #include <linux/nvme-fc.h> 4201649561SJames Smart #include "lpfc_version.h" 4301649561SJames Smart #include "lpfc_hw4.h" 4401649561SJames Smart #include "lpfc_hw.h" 4501649561SJames Smart #include "lpfc_sli.h" 4601649561SJames Smart #include "lpfc_sli4.h" 4701649561SJames Smart #include "lpfc_nl.h" 4801649561SJames Smart #include "lpfc_disc.h" 4901649561SJames Smart #include "lpfc.h" 5001649561SJames Smart #include "lpfc_nvme.h" 5101649561SJames Smart #include "lpfc_scsi.h" 5201649561SJames Smart #include "lpfc_logmsg.h" 5301649561SJames Smart #include "lpfc_crtn.h" 5401649561SJames Smart #include "lpfc_vport.h" 55bd2cdd5eSJames Smart #include "lpfc_debugfs.h" 5601649561SJames Smart 5701649561SJames Smart /* NVME initiator-based functions */ 5801649561SJames Smart 59c490850aSJames Smart static struct lpfc_io_buf * 60cf1a1d3eSJames Smart lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 615e5b511dSJames Smart int idx, int expedite); 6201649561SJames Smart 6301649561SJames Smart static void 64c490850aSJames Smart lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_io_buf *); 6501649561SJames Smart 6681e6a637SJames Smart static struct nvme_fc_port_template lpfc_nvme_template; 6701649561SJames Smart 68fab2e466SColin Ian King static union lpfc_wqe128 lpfc_iread_cmd_template; 69fab2e466SColin Ian King static union lpfc_wqe128 lpfc_iwrite_cmd_template; 70fab2e466SColin Ian King static union lpfc_wqe128 lpfc_icmnd_cmd_template; 715fd11085SJames Smart 725fd11085SJames Smart /* Setup WQE templates for NVME IOs */ 735fd11085SJames Smart void 74fab2e466SColin Ian King lpfc_nvme_cmd_template(void) 755fd11085SJames Smart { 765fd11085SJames Smart union lpfc_wqe128 *wqe; 775fd11085SJames Smart 785fd11085SJames Smart /* IREAD template */ 795fd11085SJames Smart wqe = &lpfc_iread_cmd_template; 805fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 815fd11085SJames Smart 825fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 835fd11085SJames Smart 845fd11085SJames Smart /* Word 3 - cmd_buff_len, payload_offset_len is zero */ 855fd11085SJames Smart 865fd11085SJames Smart /* Word 4 - total_xfer_len is variable */ 875fd11085SJames Smart 885fd11085SJames Smart /* Word 5 - is zero */ 895fd11085SJames Smart 905fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 915fd11085SJames Smart 925fd11085SJames Smart /* Word 7 */ 935fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE); 945fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK); 955fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3); 965fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI); 975fd11085SJames Smart 985fd11085SJames Smart /* Word 8 - abort_tag is variable */ 995fd11085SJames Smart 1005fd11085SJames Smart /* Word 9 - reqtag is variable */ 1015fd11085SJames Smart 1025fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1035fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0); 1045fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_iread.wqe_com, 1); 1055fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); 1065fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4); 1075fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); 1085fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); 1095fd11085SJames Smart 1105fd11085SJames Smart /* Word 11 - pbde is variable */ 1115fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, NVME_READ_CMD); 1125fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1135fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); 1145fd11085SJames Smart 1155fd11085SJames Smart /* Word 12 - is zero */ 1165fd11085SJames Smart 1175fd11085SJames Smart /* Word 13, 14, 15 - PBDE is variable */ 1185fd11085SJames Smart 1195fd11085SJames Smart /* IWRITE template */ 1205fd11085SJames Smart wqe = &lpfc_iwrite_cmd_template; 1215fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 1225fd11085SJames Smart 1235fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 1245fd11085SJames Smart 1255fd11085SJames Smart /* Word 3 - cmd_buff_len, payload_offset_len is zero */ 1265fd11085SJames Smart 1275fd11085SJames Smart /* Word 4 - total_xfer_len is variable */ 1285fd11085SJames Smart 1295fd11085SJames Smart /* Word 5 - initial_xfer_len is variable */ 1305fd11085SJames Smart 1315fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 1325fd11085SJames Smart 1335fd11085SJames Smart /* Word 7 */ 1345fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE); 1355fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK); 1365fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3); 1375fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI); 1385fd11085SJames Smart 1395fd11085SJames Smart /* Word 8 - abort_tag is variable */ 1405fd11085SJames Smart 1415fd11085SJames Smart /* Word 9 - reqtag is variable */ 1425fd11085SJames Smart 1435fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1445fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0); 1455fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_iwrite.wqe_com, 1); 1465fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); 1475fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4); 1485fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); 1495fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); 1505fd11085SJames Smart 1515fd11085SJames Smart /* Word 11 - pbde is variable */ 1525fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, NVME_WRITE_CMD); 1535fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1545fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); 1555fd11085SJames Smart 1565fd11085SJames Smart /* Word 12 - is zero */ 1575fd11085SJames Smart 1585fd11085SJames Smart /* Word 13, 14, 15 - PBDE is variable */ 1595fd11085SJames Smart 1605fd11085SJames Smart /* ICMND template */ 1615fd11085SJames Smart wqe = &lpfc_icmnd_cmd_template; 1625fd11085SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe128)); 1635fd11085SJames Smart 1645fd11085SJames Smart /* Word 0, 1, 2 - BDE is variable */ 1655fd11085SJames Smart 1665fd11085SJames Smart /* Word 3 - payload_offset_len is variable */ 1675fd11085SJames Smart 1685fd11085SJames Smart /* Word 4, 5 - is zero */ 1695fd11085SJames Smart 1705fd11085SJames Smart /* Word 6 - ctxt_tag, xri_tag is variable */ 1715fd11085SJames Smart 1725fd11085SJames Smart /* Word 7 */ 1735fd11085SJames Smart bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE); 1745fd11085SJames Smart bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); 1755fd11085SJames Smart bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3); 1765fd11085SJames Smart bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI); 1775fd11085SJames Smart 1785fd11085SJames Smart /* Word 8 - abort_tag is variable */ 1795fd11085SJames Smart 1805fd11085SJames Smart /* Word 9 - reqtag is variable */ 1815fd11085SJames Smart 1825fd11085SJames Smart /* Word 10 - dbde, wqes is variable */ 1835fd11085SJames Smart bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); 1845fd11085SJames Smart bf_set(wqe_nvme, &wqe->fcp_icmd.wqe_com, 1); 1855fd11085SJames Smart bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE); 1865fd11085SJames Smart bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE); 1875fd11085SJames Smart bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); 1885fd11085SJames Smart bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); 1895fd11085SJames Smart 1905fd11085SJames Smart /* Word 11 */ 1915fd11085SJames Smart bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, FCP_COMMAND); 1925fd11085SJames Smart bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 1935fd11085SJames Smart bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0); 1945fd11085SJames Smart 1955fd11085SJames Smart /* Word 12, 13, 14, 15 - is zero */ 1965fd11085SJames Smart } 1975fd11085SJames Smart 19801649561SJames Smart /** 19951f8e43eSJames Smart * lpfc_nvme_prep_abort_wqe - set up 'abort' work queue entry. 20051f8e43eSJames Smart * @pwqeq: Pointer to command iocb. 20151f8e43eSJames Smart * @xritag: Tag that uniqely identifies the local exchange resource. 20251f8e43eSJames Smart * @opt: Option bits - 20351f8e43eSJames Smart * bit 0 = inhibit sending abts on the link 20451f8e43eSJames Smart * 20551f8e43eSJames Smart * This function is called with hbalock held. 20651f8e43eSJames Smart **/ 20751f8e43eSJames Smart void 20851f8e43eSJames Smart lpfc_nvme_prep_abort_wqe(struct lpfc_iocbq *pwqeq, u16 xritag, u8 opt) 20951f8e43eSJames Smart { 21051f8e43eSJames Smart union lpfc_wqe128 *wqe = &pwqeq->wqe; 21151f8e43eSJames Smart 21251f8e43eSJames Smart /* WQEs are reused. Clear stale data and set key fields to 21351f8e43eSJames Smart * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. 21451f8e43eSJames Smart */ 21551f8e43eSJames Smart memset(wqe, 0, sizeof(*wqe)); 21651f8e43eSJames Smart 21751f8e43eSJames Smart if (opt & INHIBIT_ABORT) 21851f8e43eSJames Smart bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); 21951f8e43eSJames Smart /* Abort specified xri tag, with the mask deliberately zeroed */ 22051f8e43eSJames Smart bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); 22151f8e43eSJames Smart 22251f8e43eSJames Smart bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); 22351f8e43eSJames Smart 22451f8e43eSJames Smart /* Abort the IO associated with this outstanding exchange ID. */ 22551f8e43eSJames Smart wqe->abort_cmd.wqe_com.abort_tag = xritag; 22651f8e43eSJames Smart 22751f8e43eSJames Smart /* iotag for the wqe completion. */ 22851f8e43eSJames Smart bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, pwqeq->iotag); 22951f8e43eSJames Smart 23051f8e43eSJames Smart bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); 23151f8e43eSJames Smart bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); 23251f8e43eSJames Smart 23351f8e43eSJames Smart bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND); 23451f8e43eSJames Smart bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1); 23551f8e43eSJames Smart bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 23651f8e43eSJames Smart } 23751f8e43eSJames Smart 23851f8e43eSJames Smart /** 23901649561SJames Smart * lpfc_nvme_create_queue - 24001649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 24101649561SJames Smart * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. 24201649561SJames Smart * @handle: An opaque driver handle used in follow-up calls. 24301649561SJames Smart * 24401649561SJames Smart * Driver registers this routine to preallocate and initialize any 24501649561SJames Smart * internal data structures to bind the @qidx to its internal IO queues. 24601649561SJames Smart * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ. 24701649561SJames Smart * 24801649561SJames Smart * Return value : 24901649561SJames Smart * 0 - Success 25001649561SJames Smart * -EINVAL - Unsupported input value. 25101649561SJames Smart * -ENOMEM - Could not alloc necessary memory 25201649561SJames Smart **/ 25301649561SJames Smart static int 25401649561SJames Smart lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport, 25501649561SJames Smart unsigned int qidx, u16 qsize, 25601649561SJames Smart void **handle) 25701649561SJames Smart { 25801649561SJames Smart struct lpfc_nvme_lport *lport; 25901649561SJames Smart struct lpfc_vport *vport; 26001649561SJames Smart struct lpfc_nvme_qhandle *qhandle; 26101649561SJames Smart char *str; 26201649561SJames Smart 263c3725bdcSJames Smart if (!pnvme_lport->private) 264c3725bdcSJames Smart return -ENOMEM; 265c3725bdcSJames Smart 26601649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 26701649561SJames Smart vport = lport->vport; 26801649561SJames Smart qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL); 26901649561SJames Smart if (qhandle == NULL) 27001649561SJames Smart return -ENOMEM; 27101649561SJames Smart 272d6d189ceSBart Van Assche qhandle->cpu_id = raw_smp_processor_id(); 27301649561SJames Smart qhandle->qidx = qidx; 27401649561SJames Smart /* 27501649561SJames Smart * NVME qidx == 0 is the admin queue, so both admin queue 27601649561SJames Smart * and first IO queue will use MSI-X vector and associated 27701649561SJames Smart * EQ/CQ/WQ at index 0. After that they are sequentially assigned. 27801649561SJames Smart */ 27901649561SJames Smart if (qidx) { 28001649561SJames Smart str = "IO "; /* IO queue */ 28101649561SJames Smart qhandle->index = ((qidx - 1) % 2826a828b0fSJames Smart lpfc_nvme_template.max_hw_queues); 28301649561SJames Smart } else { 28401649561SJames Smart str = "ADM"; /* Admin queue */ 28501649561SJames Smart qhandle->index = qidx; 28601649561SJames Smart } 28701649561SJames Smart 288d58734f0SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 28901649561SJames Smart "6073 Binding %s HdwQueue %d (cpu %d) to " 29032350664SJames Smart "hdw_queue %d qhandle x%px\n", str, 29101649561SJames Smart qidx, qhandle->cpu_id, qhandle->index, qhandle); 29201649561SJames Smart *handle = (void *)qhandle; 29301649561SJames Smart return 0; 29401649561SJames Smart } 29501649561SJames Smart 29601649561SJames Smart /** 29701649561SJames Smart * lpfc_nvme_delete_queue - 29801649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 29901649561SJames Smart * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. 30001649561SJames Smart * @handle: An opaque driver handle from lpfc_nvme_create_queue 30101649561SJames Smart * 30201649561SJames Smart * Driver registers this routine to free 30301649561SJames Smart * any internal data structures to bind the @qidx to its internal 30401649561SJames Smart * IO queues. 30501649561SJames Smart * 30601649561SJames Smart * Return value : 30701649561SJames Smart * 0 - Success 30801649561SJames Smart * TODO: What are the failure codes. 30901649561SJames Smart **/ 31001649561SJames Smart static void 31101649561SJames Smart lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport, 31201649561SJames Smart unsigned int qidx, 31301649561SJames Smart void *handle) 31401649561SJames Smart { 31501649561SJames Smart struct lpfc_nvme_lport *lport; 31601649561SJames Smart struct lpfc_vport *vport; 31701649561SJames Smart 318c3725bdcSJames Smart if (!pnvme_lport->private) 319c3725bdcSJames Smart return; 320c3725bdcSJames Smart 32101649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 32201649561SJames Smart vport = lport->vport; 32301649561SJames Smart 32401649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 32532350664SJames Smart "6001 ENTER. lpfc_pnvme x%px, qidx x%x qhandle x%px\n", 32601649561SJames Smart lport, qidx, handle); 32701649561SJames Smart kfree(handle); 32801649561SJames Smart } 32901649561SJames Smart 33001649561SJames Smart static void 33101649561SJames Smart lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport) 33201649561SJames Smart { 33301649561SJames Smart struct lpfc_nvme_lport *lport = localport->private; 33401649561SJames Smart 335add9d6beSJames Smart lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME, 33632350664SJames Smart "6173 localport x%px delete complete\n", 337add9d6beSJames Smart lport); 338add9d6beSJames Smart 33901649561SJames Smart /* release any threads waiting for the unreg to complete */ 3407961cba6SEwan D. Milne if (lport->vport->localport) 3417961cba6SEwan D. Milne complete(lport->lport_unreg_cmp); 34201649561SJames Smart } 34301649561SJames Smart 34401649561SJames Smart /* lpfc_nvme_remoteport_delete 34501649561SJames Smart * 34601649561SJames Smart * @remoteport: Pointer to an nvme transport remoteport instance. 34701649561SJames Smart * 34801649561SJames Smart * This is a template downcall. NVME transport calls this function 34901649561SJames Smart * when it has completed the unregistration of a previously 35001649561SJames Smart * registered remoteport. 35101649561SJames Smart * 35201649561SJames Smart * Return value : 35301649561SJames Smart * None 35401649561SJames Smart */ 3553999df75SBart Van Assche static void 35601649561SJames Smart lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport) 35701649561SJames Smart { 35801649561SJames Smart struct lpfc_nvme_rport *rport = remoteport->private; 35901649561SJames Smart struct lpfc_vport *vport; 36001649561SJames Smart struct lpfc_nodelist *ndlp; 36101649561SJames Smart 36201649561SJames Smart ndlp = rport->ndlp; 36301649561SJames Smart if (!ndlp) 36401649561SJames Smart goto rport_err; 36501649561SJames Smart 36601649561SJames Smart vport = ndlp->vport; 36701649561SJames Smart if (!vport) 36801649561SJames Smart goto rport_err; 36901649561SJames Smart 37001649561SJames Smart /* Remove this rport from the lport's list - memory is owned by the 37101649561SJames Smart * transport. Remove the ndlp reference for the NVME transport before 3727a06dcd3SJames Smart * calling state machine to remove the node. 37301649561SJames Smart */ 37401649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 37532350664SJames Smart "6146 remoteport delete of remoteport x%px\n", 37601649561SJames Smart remoteport); 3773fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 378b15bd3e6SJames Smart 379b15bd3e6SJames Smart /* The register rebind might have occurred before the delete 380b15bd3e6SJames Smart * downcall. Guard against this race. 381b15bd3e6SJames Smart */ 382b15bd3e6SJames Smart if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) { 3837a06dcd3SJames Smart ndlp->nrport = NULL; 38401466024SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 385b15bd3e6SJames Smart } 3863fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 3873fd78355SJames Smart 3883fd78355SJames Smart /* Remove original register reference. The host transport 3893fd78355SJames Smart * won't reference this rport/remoteport any further. 3903fd78355SJames Smart */ 39101649561SJames Smart lpfc_nlp_put(ndlp); 39201649561SJames Smart 39301649561SJames Smart rport_err: 3943fd78355SJames Smart return; 39501649561SJames Smart } 39601649561SJames Smart 39701649561SJames Smart static void 39801649561SJames Smart lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, 39901649561SJames Smart struct lpfc_wcqe_complete *wcqe) 40001649561SJames Smart { 40101649561SJames Smart struct lpfc_vport *vport = cmdwqe->vport; 4024b056682SJames Smart struct lpfc_nvme_lport *lport; 40301649561SJames Smart uint32_t status; 40401649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq; 40501649561SJames Smart struct lpfc_dmabuf *buf_ptr; 40601649561SJames Smart struct lpfc_nodelist *ndlp; 40701649561SJames Smart 40801649561SJames Smart pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2; 40901649561SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; 41066a210ffSJames Smart 41166a85155SJames Smart if (vport->localport) { 41266a85155SJames Smart lport = (struct lpfc_nvme_lport *)vport->localport->private; 41366a210ffSJames Smart if (lport) { 41466a210ffSJames Smart atomic_inc(&lport->fc4NvmeLsCmpls); 4154b056682SJames Smart if (status) { 4164b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 4174b056682SJames Smart atomic_inc(&lport->cmpl_ls_xb); 4184b056682SJames Smart atomic_inc(&lport->cmpl_ls_err); 4194b056682SJames Smart } 42066a210ffSJames Smart } 42166a85155SJames Smart } 4224b056682SJames Smart 42301649561SJames Smart ndlp = (struct lpfc_nodelist *)cmdwqe->context1; 42401649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 42501649561SJames Smart "6047 nvme cmpl Enter " 42632350664SJames Smart "Data %px DID %x Xri: %x status %x reason x%x " 42732350664SJames Smart "cmd:x%px lsreg:x%px bmp:x%px ndlp:x%px\n", 42801649561SJames Smart pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, 42901649561SJames Smart cmdwqe->sli4_xritag, status, 430815a9c43SJames Smart (wcqe->parameter & 0xffff), 43101649561SJames Smart cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp); 43201649561SJames Smart 433bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n", 434bd2cdd5eSJames Smart cmdwqe->sli4_xritag, status, wcqe->parameter); 435bd2cdd5eSJames Smart 43601649561SJames Smart if (cmdwqe->context3) { 43701649561SJames Smart buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3; 43801649561SJames Smart lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 43901649561SJames Smart kfree(buf_ptr); 44001649561SJames Smart cmdwqe->context3 = NULL; 44101649561SJames Smart } 44201649561SJames Smart if (pnvme_lsreq->done) 44301649561SJames Smart pnvme_lsreq->done(pnvme_lsreq, status); 44401649561SJames Smart else 44501649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 44601649561SJames Smart "6046 nvme cmpl without done call back? " 44732350664SJames Smart "Data %px DID %x Xri: %x status %x\n", 44801649561SJames Smart pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, 44901649561SJames Smart cmdwqe->sli4_xritag, status); 45001649561SJames Smart if (ndlp) { 45101649561SJames Smart lpfc_nlp_put(ndlp); 45201649561SJames Smart cmdwqe->context1 = NULL; 45301649561SJames Smart } 45401649561SJames Smart lpfc_sli_release_iocbq(phba, cmdwqe); 45501649561SJames Smart } 45601649561SJames Smart 45701649561SJames Smart static int 45801649561SJames Smart lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, 45901649561SJames Smart struct lpfc_dmabuf *inp, 46001649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq, 46101649561SJames Smart void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, 46201649561SJames Smart struct lpfc_wcqe_complete *), 46301649561SJames Smart struct lpfc_nodelist *ndlp, uint32_t num_entry, 46401649561SJames Smart uint32_t tmo, uint8_t retry) 46501649561SJames Smart { 46601649561SJames Smart struct lpfc_hba *phba = vport->phba; 467205e8240SJames Smart union lpfc_wqe128 *wqe; 46801649561SJames Smart struct lpfc_iocbq *genwqe; 46901649561SJames Smart struct ulp_bde64 *bpl; 47001649561SJames Smart struct ulp_bde64 bde; 47101649561SJames Smart int i, rc, xmit_len, first_len; 47201649561SJames Smart 47301649561SJames Smart /* Allocate buffer for command WQE */ 47401649561SJames Smart genwqe = lpfc_sli_get_iocbq(phba); 47501649561SJames Smart if (genwqe == NULL) 47601649561SJames Smart return 1; 47701649561SJames Smart 47801649561SJames Smart wqe = &genwqe->wqe; 479d9f492a1SJames Smart /* Initialize only 64 bytes */ 48001649561SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 48101649561SJames Smart 48201649561SJames Smart genwqe->context3 = (uint8_t *)bmp; 48301649561SJames Smart genwqe->iocb_flag |= LPFC_IO_NVME_LS; 48401649561SJames Smart 48501649561SJames Smart /* Save for completion so we can release these resources */ 48601649561SJames Smart genwqe->context1 = lpfc_nlp_get(ndlp); 48701649561SJames Smart genwqe->context2 = (uint8_t *)pnvme_lsreq; 48801649561SJames Smart /* Fill in payload, bp points to frame payload */ 48901649561SJames Smart 49001649561SJames Smart if (!tmo) 49101649561SJames Smart /* FC spec states we need 3 * ratov for CT requests */ 49201649561SJames Smart tmo = (3 * phba->fc_ratov); 49301649561SJames Smart 49401649561SJames Smart /* For this command calculate the xmit length of the request bde. */ 49501649561SJames Smart xmit_len = 0; 49601649561SJames Smart first_len = 0; 49701649561SJames Smart bpl = (struct ulp_bde64 *)bmp->virt; 49801649561SJames Smart for (i = 0; i < num_entry; i++) { 49901649561SJames Smart bde.tus.w = bpl[i].tus.w; 50001649561SJames Smart if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) 50101649561SJames Smart break; 50201649561SJames Smart xmit_len += bde.tus.f.bdeSize; 50301649561SJames Smart if (i == 0) 50401649561SJames Smart first_len = xmit_len; 50501649561SJames Smart } 50601649561SJames Smart 50701649561SJames Smart genwqe->rsvd2 = num_entry; 50801649561SJames Smart genwqe->hba_wqidx = 0; 50901649561SJames Smart 51001649561SJames Smart /* Words 0 - 2 */ 51101649561SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 51201649561SJames Smart wqe->generic.bde.tus.f.bdeSize = first_len; 51301649561SJames Smart wqe->generic.bde.addrLow = bpl[0].addrLow; 51401649561SJames Smart wqe->generic.bde.addrHigh = bpl[0].addrHigh; 51501649561SJames Smart 51601649561SJames Smart /* Word 3 */ 51701649561SJames Smart wqe->gen_req.request_payload_len = first_len; 51801649561SJames Smart 51901649561SJames Smart /* Word 4 */ 52001649561SJames Smart 52101649561SJames Smart /* Word 5 */ 52201649561SJames Smart bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0); 52301649561SJames Smart bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1); 52401649561SJames Smart bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1); 5258b361639SJames Smart bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ); 52601649561SJames Smart bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME); 52701649561SJames Smart 52801649561SJames Smart /* Word 6 */ 52901649561SJames Smart bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com, 53001649561SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 53101649561SJames Smart bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag); 53201649561SJames Smart 53301649561SJames Smart /* Word 7 */ 53401649561SJames Smart bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1)); 53501649561SJames Smart bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3); 53601649561SJames Smart bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE); 53701649561SJames Smart bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI); 53801649561SJames Smart 53901649561SJames Smart /* Word 8 */ 54001649561SJames Smart wqe->gen_req.wqe_com.abort_tag = genwqe->iotag; 54101649561SJames Smart 54201649561SJames Smart /* Word 9 */ 54301649561SJames Smart bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag); 54401649561SJames Smart 54501649561SJames Smart /* Word 10 */ 54601649561SJames Smart bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); 54701649561SJames Smart bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); 54801649561SJames Smart bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); 54901649561SJames Smart bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); 55001649561SJames Smart bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); 55101649561SJames Smart 55201649561SJames Smart /* Word 11 */ 55301649561SJames Smart bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); 55401649561SJames Smart bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND); 55501649561SJames Smart 55601649561SJames Smart 55701649561SJames Smart /* Issue GEN REQ WQE for NPORT <did> */ 55801649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 55901649561SJames Smart "6050 Issue GEN REQ WQE to NPORT x%x " 56032350664SJames Smart "Data: x%x x%x wq:x%px lsreq:x%px bmp:x%px " 56132350664SJames Smart "xmit:%d 1st:%d\n", 56201649561SJames Smart ndlp->nlp_DID, genwqe->iotag, 56301649561SJames Smart vport->port_state, 56401649561SJames Smart genwqe, pnvme_lsreq, bmp, xmit_len, first_len); 56501649561SJames Smart genwqe->wqe_cmpl = cmpl; 56601649561SJames Smart genwqe->iocb_cmpl = NULL; 56701649561SJames Smart genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT; 56801649561SJames Smart genwqe->vport = vport; 56901649561SJames Smart genwqe->retry = retry; 57001649561SJames Smart 571bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n", 572bd2cdd5eSJames Smart genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID); 573bd2cdd5eSJames Smart 5741fbf9742SJames Smart rc = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], genwqe); 575cd22d605SDick Kennedy if (rc) { 57601649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 57701649561SJames Smart "6045 Issue GEN REQ WQE to NPORT x%x " 57801649561SJames Smart "Data: x%x x%x\n", 57901649561SJames Smart ndlp->nlp_DID, genwqe->iotag, 58001649561SJames Smart vport->port_state); 58101649561SJames Smart lpfc_sli_release_iocbq(phba, genwqe); 58201649561SJames Smart return 1; 58301649561SJames Smart } 58401649561SJames Smart return 0; 58501649561SJames Smart } 58601649561SJames Smart 58701649561SJames Smart /** 58801649561SJames Smart * lpfc_nvme_ls_req - Issue an Link Service request 58901649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 59001649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 59101649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 59201649561SJames Smart * 59301649561SJames Smart * Driver registers this routine to handle any link service request 59401649561SJames Smart * from the nvme_fc transport to a remote nvme-aware port. 59501649561SJames Smart * 59601649561SJames Smart * Return value : 59701649561SJames Smart * 0 - Success 59801649561SJames Smart * TODO: What are the failure codes. 59901649561SJames Smart **/ 60001649561SJames Smart static int 60101649561SJames Smart lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport, 60201649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 60301649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq) 60401649561SJames Smart { 60501649561SJames Smart int ret = 0; 60601649561SJames Smart struct lpfc_nvme_lport *lport; 607815a9c43SJames Smart struct lpfc_nvme_rport *rport; 60801649561SJames Smart struct lpfc_vport *vport; 60901649561SJames Smart struct lpfc_nodelist *ndlp; 61001649561SJames Smart struct ulp_bde64 *bpl; 61101649561SJames Smart struct lpfc_dmabuf *bmp; 612ba43c4d0SJames Smart uint16_t ntype, nstate; 61301649561SJames Smart 61401649561SJames Smart /* there are two dma buf in the request, actually there is one and 61501649561SJames Smart * the second one is just the start address + cmd size. 61601649561SJames Smart * Before calling lpfc_nvme_gen_req these buffers need to be wrapped 61701649561SJames Smart * in a lpfc_dmabuf struct. When freeing we just free the wrapper 61801649561SJames Smart * because the nvem layer owns the data bufs. 61901649561SJames Smart * We do not have to break these packets open, we don't care what is in 62001649561SJames Smart * them. And we do not have to look at the resonse data, we only care 62101649561SJames Smart * that we got a response. All of the caring is going to happen in the 62201649561SJames Smart * nvme-fc layer. 62301649561SJames Smart */ 62401649561SJames Smart 62501649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 626815a9c43SJames Smart rport = (struct lpfc_nvme_rport *)pnvme_rport->private; 62766a210ffSJames Smart if (unlikely(!lport) || unlikely(!rport)) 62866a210ffSJames Smart return -EINVAL; 62966a210ffSJames Smart 63001649561SJames Smart vport = lport->vport; 63101649561SJames Smart 6321abcb371SDick Kennedy if (vport->load_flag & FC_UNLOADING) 6331abcb371SDick Kennedy return -ENODEV; 6341abcb371SDick Kennedy 635815a9c43SJames Smart /* Need the ndlp. It is stored in the driver's rport. */ 636815a9c43SJames Smart ndlp = rport->ndlp; 637ba43c4d0SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 638ba43c4d0SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, 63932350664SJames Smart "6051 Remoteport x%px, rport has invalid ndlp. " 640815a9c43SJames Smart "Failing LS Req\n", pnvme_rport); 641ba43c4d0SJames Smart return -ENODEV; 642ba43c4d0SJames Smart } 643ba43c4d0SJames Smart 644ba43c4d0SJames Smart /* The remote node has to be a mapped nvme target or an 645ba43c4d0SJames Smart * unmapped nvme initiator or it's an error. 646ba43c4d0SJames Smart */ 647ba43c4d0SJames Smart ntype = ndlp->nlp_type; 648ba43c4d0SJames Smart nstate = ndlp->nlp_state; 649ba43c4d0SJames Smart if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) || 650ba43c4d0SJames Smart (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) { 651ba43c4d0SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, 652ba43c4d0SJames Smart "6088 DID x%06x not ready for " 653ba43c4d0SJames Smart "IO. State x%x, Type x%x\n", 654ba43c4d0SJames Smart pnvme_rport->port_id, 655ba43c4d0SJames Smart ndlp->nlp_state, ndlp->nlp_type); 656ba43c4d0SJames Smart return -ENODEV; 65701649561SJames Smart } 65801649561SJames Smart bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 65901649561SJames Smart if (!bmp) { 66001649561SJames Smart 66101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 66201649561SJames Smart "6044 Could not find node for DID %x\n", 66301649561SJames Smart pnvme_rport->port_id); 66401649561SJames Smart return 2; 66501649561SJames Smart } 66601649561SJames Smart INIT_LIST_HEAD(&bmp->list); 66701649561SJames Smart bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys)); 66801649561SJames Smart if (!bmp->virt) { 66901649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 67001649561SJames Smart "6042 Could not find node for DID %x\n", 67101649561SJames Smart pnvme_rport->port_id); 67201649561SJames Smart kfree(bmp); 67301649561SJames Smart return 3; 67401649561SJames Smart } 67501649561SJames Smart bpl = (struct ulp_bde64 *)bmp->virt; 67601649561SJames Smart bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma)); 67701649561SJames Smart bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma)); 67801649561SJames Smart bpl->tus.f.bdeFlags = 0; 67901649561SJames Smart bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen; 68001649561SJames Smart bpl->tus.w = le32_to_cpu(bpl->tus.w); 68101649561SJames Smart bpl++; 68201649561SJames Smart 68301649561SJames Smart bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma)); 68401649561SJames Smart bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma)); 68501649561SJames Smart bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; 68601649561SJames Smart bpl->tus.f.bdeSize = pnvme_lsreq->rsplen; 68701649561SJames Smart bpl->tus.w = le32_to_cpu(bpl->tus.w); 68801649561SJames Smart 68901649561SJames Smart /* Expand print to include key fields. */ 69001649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 69132350664SJames Smart "6149 Issue LS Req to DID 0x%06x lport x%px, " 69232350664SJames Smart "rport x%px lsreq x%px rqstlen:%d rsplen:%d " 69332350664SJames Smart "%pad %pad\n", 69432350664SJames Smart ndlp->nlp_DID, pnvme_lport, pnvme_rport, 69501649561SJames Smart pnvme_lsreq, pnvme_lsreq->rqstlen, 696825c6abbSArnd Bergmann pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma, 697825c6abbSArnd Bergmann &pnvme_lsreq->rspdma); 69801649561SJames Smart 69966a210ffSJames Smart atomic_inc(&lport->fc4NvmeLsRequests); 70001649561SJames Smart 70101649561SJames Smart /* Hardcode the wait to 30 seconds. Connections are failing otherwise. 70201649561SJames Smart * This code allows it all to work. 70301649561SJames Smart */ 70401649561SJames Smart ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr, 70501649561SJames Smart pnvme_lsreq, lpfc_nvme_cmpl_gen_req, 70601649561SJames Smart ndlp, 2, 30, 0); 70701649561SJames Smart if (ret != WQE_SUCCESS) { 7084b056682SJames Smart atomic_inc(&lport->xmt_ls_err); 709815a9c43SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 71032350664SJames Smart "6052 EXIT. issue ls wqe failed lport x%px, " 71132350664SJames Smart "rport x%px lsreq x%px Status %x DID %x\n", 71201649561SJames Smart pnvme_lport, pnvme_rport, pnvme_lsreq, 71301649561SJames Smart ret, ndlp->nlp_DID); 71401649561SJames Smart lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys); 71501649561SJames Smart kfree(bmp); 71601649561SJames Smart return ret; 71701649561SJames Smart } 71801649561SJames Smart 71901649561SJames Smart /* Stub in routine and return 0 for now. */ 72001649561SJames Smart return ret; 72101649561SJames Smart } 72201649561SJames Smart 72301649561SJames Smart /** 72401649561SJames Smart * lpfc_nvme_ls_abort - Issue an Link Service request 72501649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 72601649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 72701649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 72801649561SJames Smart * 72901649561SJames Smart * Driver registers this routine to handle any link service request 73001649561SJames Smart * from the nvme_fc transport to a remote nvme-aware port. 73101649561SJames Smart * 73201649561SJames Smart * Return value : 73301649561SJames Smart * 0 - Success 73401649561SJames Smart * TODO: What are the failure codes. 73501649561SJames Smart **/ 73601649561SJames Smart static void 73701649561SJames Smart lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport, 73801649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 73901649561SJames Smart struct nvmefc_ls_req *pnvme_lsreq) 74001649561SJames Smart { 74101649561SJames Smart struct lpfc_nvme_lport *lport; 74201649561SJames Smart struct lpfc_vport *vport; 74301649561SJames Smart struct lpfc_hba *phba; 74401649561SJames Smart struct lpfc_nodelist *ndlp; 74501649561SJames Smart LIST_HEAD(abort_list); 74601649561SJames Smart struct lpfc_sli_ring *pring; 74701649561SJames Smart struct lpfc_iocbq *wqe, *next_wqe; 74801649561SJames Smart 74901649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 75066a210ffSJames Smart if (unlikely(!lport)) 75166a210ffSJames Smart return; 75201649561SJames Smart vport = lport->vport; 75301649561SJames Smart phba = vport->phba; 75401649561SJames Smart 7553386f4bdSJames Smart if (vport->load_flag & FC_UNLOADING) 7563386f4bdSJames Smart return; 7573386f4bdSJames Smart 75801649561SJames Smart ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); 75901649561SJames Smart if (!ndlp) { 76001649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 76101649561SJames Smart "6049 Could not find node for DID %x\n", 76201649561SJames Smart pnvme_rport->port_id); 76301649561SJames Smart return; 76401649561SJames Smart } 76501649561SJames Smart 76601649561SJames Smart /* Expand print to include key fields. */ 76701649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 76832350664SJames Smart "6040 ENTER. lport x%px, rport x%px lsreq x%px rqstlen:%d " 769825c6abbSArnd Bergmann "rsplen:%d %pad %pad\n", 77001649561SJames Smart pnvme_lport, pnvme_rport, 77101649561SJames Smart pnvme_lsreq, pnvme_lsreq->rqstlen, 772825c6abbSArnd Bergmann pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma, 773825c6abbSArnd Bergmann &pnvme_lsreq->rspdma); 77401649561SJames Smart 77501649561SJames Smart /* 77601649561SJames Smart * Lock the ELS ring txcmplq and build a local list of all ELS IOs 77701649561SJames Smart * that need an ABTS. The IOs need to stay on the txcmplq so that 77801649561SJames Smart * the abort operation completes them successfully. 77901649561SJames Smart */ 78001649561SJames Smart pring = phba->sli4_hba.nvmels_wq->pring; 78101649561SJames Smart spin_lock_irq(&phba->hbalock); 78201649561SJames Smart spin_lock(&pring->ring_lock); 78301649561SJames Smart list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) { 78401649561SJames Smart /* Add to abort_list on on NDLP match. */ 78501649561SJames Smart if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) { 78601649561SJames Smart wqe->iocb_flag |= LPFC_DRIVER_ABORTED; 78701649561SJames Smart list_add_tail(&wqe->dlist, &abort_list); 78801649561SJames Smart } 78901649561SJames Smart } 79001649561SJames Smart spin_unlock(&pring->ring_lock); 79101649561SJames Smart spin_unlock_irq(&phba->hbalock); 79201649561SJames Smart 79301649561SJames Smart /* Abort the targeted IOs and remove them from the abort list. */ 79401649561SJames Smart list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) { 7954b056682SJames Smart atomic_inc(&lport->xmt_ls_abort); 79601649561SJames Smart spin_lock_irq(&phba->hbalock); 79701649561SJames Smart list_del_init(&wqe->dlist); 79801649561SJames Smart lpfc_sli_issue_abort_iotag(phba, pring, wqe); 79901649561SJames Smart spin_unlock_irq(&phba->hbalock); 80001649561SJames Smart } 80101649561SJames Smart } 80201649561SJames Smart 80301649561SJames Smart /* Fix up the existing sgls for NVME IO. */ 8045fd11085SJames Smart static inline void 80501649561SJames Smart lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport, 806c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd, 80701649561SJames Smart struct nvmefc_fcp_req *nCmd) 80801649561SJames Smart { 8094e565cf0SJames Smart struct lpfc_hba *phba = vport->phba; 81001649561SJames Smart struct sli4_sge *sgl; 81101649561SJames Smart union lpfc_wqe128 *wqe; 81201649561SJames Smart uint32_t *wptr, *dptr; 81301649561SJames Smart 81401649561SJames Smart /* 8154e565cf0SJames Smart * Get a local pointer to the built-in wqe and correct 8164e565cf0SJames Smart * the cmd size to match NVME's 96 bytes and fix 8174e565cf0SJames Smart * the dma address. 8184e565cf0SJames Smart */ 8194e565cf0SJames Smart 820205e8240SJames Smart wqe = &lpfc_ncmd->cur_iocbq.wqe; 8214e565cf0SJames Smart 8224e565cf0SJames Smart /* 82301649561SJames Smart * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to 82401649561SJames Smart * match NVME. NVME sends 96 bytes. Also, use the 82501649561SJames Smart * nvme commands command and response dma addresses 82601649561SJames Smart * rather than the virtual memory to ease the restore 82701649561SJames Smart * operation. 82801649561SJames Smart */ 8290794d601SJames Smart sgl = lpfc_ncmd->dma_sgl; 83001649561SJames Smart sgl->sge_len = cpu_to_le32(nCmd->cmdlen); 8314e565cf0SJames Smart if (phba->cfg_nvme_embed_cmd) { 8324e565cf0SJames Smart sgl->addr_hi = 0; 8334e565cf0SJames Smart sgl->addr_lo = 0; 8344e565cf0SJames Smart 8354e565cf0SJames Smart /* Word 0-2 - NVME CMND IU (embedded payload) */ 8364e565cf0SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED; 8374e565cf0SJames Smart wqe->generic.bde.tus.f.bdeSize = 56; 8384e565cf0SJames Smart wqe->generic.bde.addrHigh = 0; 8394e565cf0SJames Smart wqe->generic.bde.addrLow = 64; /* Word 16 */ 8404e565cf0SJames Smart 8415fd11085SJames Smart /* Word 10 - dbde is 0, wqes is 1 in template */ 84201649561SJames Smart 84301649561SJames Smart /* 84401649561SJames Smart * Embed the payload in the last half of the WQE 84501649561SJames Smart * WQE words 16-30 get the NVME CMD IU payload 84601649561SJames Smart * 847b06a622fSJames Smart * WQE words 16-19 get payload Words 1-4 84801649561SJames Smart * WQE words 20-21 get payload Words 6-7 84901649561SJames Smart * WQE words 22-29 get payload Words 16-23 85001649561SJames Smart */ 851b06a622fSJames Smart wptr = &wqe->words[16]; /* WQE ptr */ 85201649561SJames Smart dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */ 853b06a622fSJames Smart dptr++; /* Skip Word 0 in payload */ 85401649561SJames Smart 855b06a622fSJames Smart *wptr++ = *dptr++; /* Word 1 */ 85601649561SJames Smart *wptr++ = *dptr++; /* Word 2 */ 85701649561SJames Smart *wptr++ = *dptr++; /* Word 3 */ 85801649561SJames Smart *wptr++ = *dptr++; /* Word 4 */ 85901649561SJames Smart dptr++; /* Skip Word 5 in payload */ 86001649561SJames Smart *wptr++ = *dptr++; /* Word 6 */ 86101649561SJames Smart *wptr++ = *dptr++; /* Word 7 */ 86201649561SJames Smart dptr += 8; /* Skip Words 8-15 in payload */ 86301649561SJames Smart *wptr++ = *dptr++; /* Word 16 */ 86401649561SJames Smart *wptr++ = *dptr++; /* Word 17 */ 86501649561SJames Smart *wptr++ = *dptr++; /* Word 18 */ 86601649561SJames Smart *wptr++ = *dptr++; /* Word 19 */ 86701649561SJames Smart *wptr++ = *dptr++; /* Word 20 */ 86801649561SJames Smart *wptr++ = *dptr++; /* Word 21 */ 86901649561SJames Smart *wptr++ = *dptr++; /* Word 22 */ 87001649561SJames Smart *wptr = *dptr; /* Word 23 */ 8715fd11085SJames Smart } else { 8725fd11085SJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma)); 8735fd11085SJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma)); 8745fd11085SJames Smart 8755fd11085SJames Smart /* Word 0-2 - NVME CMND IU Inline BDE */ 8765fd11085SJames Smart wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 8775fd11085SJames Smart wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen; 8785fd11085SJames Smart wqe->generic.bde.addrHigh = sgl->addr_hi; 8795fd11085SJames Smart wqe->generic.bde.addrLow = sgl->addr_lo; 8805fd11085SJames Smart 8815fd11085SJames Smart /* Word 10 */ 8825fd11085SJames Smart bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); 8835fd11085SJames Smart bf_set(wqe_wqes, &wqe->generic.wqe_com, 0); 8845fd11085SJames Smart } 8855fd11085SJames Smart 8865fd11085SJames Smart sgl++; 8875fd11085SJames Smart 8885fd11085SJames Smart /* Setup the physical region for the FCP RSP */ 8895fd11085SJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma)); 8905fd11085SJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma)); 8915fd11085SJames Smart sgl->word2 = le32_to_cpu(sgl->word2); 8925fd11085SJames Smart if (nCmd->sg_cnt) 8935fd11085SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 8945fd11085SJames Smart else 8955fd11085SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 8965fd11085SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 8975fd11085SJames Smart sgl->sge_len = cpu_to_le32(nCmd->rsplen); 89801649561SJames Smart } 89901649561SJames Smart 900bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 901bd2cdd5eSJames Smart static void 902bd2cdd5eSJames Smart lpfc_nvme_ktime(struct lpfc_hba *phba, 903c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd) 904bd2cdd5eSJames Smart { 905bd2cdd5eSJames Smart uint64_t seg1, seg2, seg3, seg4; 906c8a4ce0bSDick Kennedy uint64_t segsum; 907bd2cdd5eSJames Smart 908bd2cdd5eSJames Smart if (!lpfc_ncmd->ts_last_cmd || 909bd2cdd5eSJames Smart !lpfc_ncmd->ts_cmd_start || 910bd2cdd5eSJames Smart !lpfc_ncmd->ts_cmd_wqput || 911bd2cdd5eSJames Smart !lpfc_ncmd->ts_isr_cmpl || 912bd2cdd5eSJames Smart !lpfc_ncmd->ts_data_nvme) 913bd2cdd5eSJames Smart return; 914c8a4ce0bSDick Kennedy 915c8a4ce0bSDick Kennedy if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_cmd_start) 916c8a4ce0bSDick Kennedy return; 917bd2cdd5eSJames Smart if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd) 918bd2cdd5eSJames Smart return; 919bd2cdd5eSJames Smart if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start) 920bd2cdd5eSJames Smart return; 921bd2cdd5eSJames Smart if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput) 922bd2cdd5eSJames Smart return; 923bd2cdd5eSJames Smart if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl) 924bd2cdd5eSJames Smart return; 925bd2cdd5eSJames Smart /* 926bd2cdd5eSJames Smart * Segment 1 - Time from Last FCP command cmpl is handed 927bd2cdd5eSJames Smart * off to NVME Layer to start of next command. 928bd2cdd5eSJames Smart * Segment 2 - Time from Driver receives a IO cmd start 929bd2cdd5eSJames Smart * from NVME Layer to WQ put is done on IO cmd. 930bd2cdd5eSJames Smart * Segment 3 - Time from Driver WQ put is done on IO cmd 931bd2cdd5eSJames Smart * to MSI-X ISR for IO cmpl. 932bd2cdd5eSJames Smart * Segment 4 - Time from MSI-X ISR for IO cmpl to when 933bd2cdd5eSJames Smart * cmpl is handled off to the NVME Layer. 934bd2cdd5eSJames Smart */ 935bd2cdd5eSJames Smart seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd; 936c8a4ce0bSDick Kennedy if (seg1 > 5000000) /* 5 ms - for sequential IOs only */ 937c8a4ce0bSDick Kennedy seg1 = 0; 938bd2cdd5eSJames Smart 939bd2cdd5eSJames Smart /* Calculate times relative to start of IO */ 940bd2cdd5eSJames Smart seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start); 941c8a4ce0bSDick Kennedy segsum = seg2; 942c8a4ce0bSDick Kennedy seg3 = lpfc_ncmd->ts_isr_cmpl - lpfc_ncmd->ts_cmd_start; 943c8a4ce0bSDick Kennedy if (segsum > seg3) 944c8a4ce0bSDick Kennedy return; 945c8a4ce0bSDick Kennedy seg3 -= segsum; 946c8a4ce0bSDick Kennedy segsum += seg3; 947c8a4ce0bSDick Kennedy 948c8a4ce0bSDick Kennedy seg4 = lpfc_ncmd->ts_data_nvme - lpfc_ncmd->ts_cmd_start; 949c8a4ce0bSDick Kennedy if (segsum > seg4) 950c8a4ce0bSDick Kennedy return; 951c8a4ce0bSDick Kennedy seg4 -= segsum; 952c8a4ce0bSDick Kennedy 953bd2cdd5eSJames Smart phba->ktime_data_samples++; 954bd2cdd5eSJames Smart phba->ktime_seg1_total += seg1; 955bd2cdd5eSJames Smart if (seg1 < phba->ktime_seg1_min) 956bd2cdd5eSJames Smart phba->ktime_seg1_min = seg1; 957bd2cdd5eSJames Smart else if (seg1 > phba->ktime_seg1_max) 958bd2cdd5eSJames Smart phba->ktime_seg1_max = seg1; 959bd2cdd5eSJames Smart phba->ktime_seg2_total += seg2; 960bd2cdd5eSJames Smart if (seg2 < phba->ktime_seg2_min) 961bd2cdd5eSJames Smart phba->ktime_seg2_min = seg2; 962bd2cdd5eSJames Smart else if (seg2 > phba->ktime_seg2_max) 963bd2cdd5eSJames Smart phba->ktime_seg2_max = seg2; 964bd2cdd5eSJames Smart phba->ktime_seg3_total += seg3; 965bd2cdd5eSJames Smart if (seg3 < phba->ktime_seg3_min) 966bd2cdd5eSJames Smart phba->ktime_seg3_min = seg3; 967bd2cdd5eSJames Smart else if (seg3 > phba->ktime_seg3_max) 968bd2cdd5eSJames Smart phba->ktime_seg3_max = seg3; 969bd2cdd5eSJames Smart phba->ktime_seg4_total += seg4; 970bd2cdd5eSJames Smart if (seg4 < phba->ktime_seg4_min) 971bd2cdd5eSJames Smart phba->ktime_seg4_min = seg4; 972bd2cdd5eSJames Smart else if (seg4 > phba->ktime_seg4_max) 973bd2cdd5eSJames Smart phba->ktime_seg4_max = seg4; 974bd2cdd5eSJames Smart 975bd2cdd5eSJames Smart lpfc_ncmd->ts_last_cmd = 0; 976bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_start = 0; 977bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_wqput = 0; 978bd2cdd5eSJames Smart lpfc_ncmd->ts_isr_cmpl = 0; 979bd2cdd5eSJames Smart lpfc_ncmd->ts_data_nvme = 0; 980bd2cdd5eSJames Smart } 981bd2cdd5eSJames Smart #endif 982bd2cdd5eSJames Smart 98301649561SJames Smart /** 98401649561SJames Smart * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO 98501649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 98601649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 98701649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 98801649561SJames Smart * 98901649561SJames Smart * Driver registers this routine as it io request handler. This 99001649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 99101649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 99201649561SJames Smart * 99301649561SJames Smart * Return value : 99401649561SJames Smart * 0 - Success 99501649561SJames Smart * TODO: What are the failure codes. 99601649561SJames Smart **/ 99701649561SJames Smart static void 99801649561SJames Smart lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn, 99901649561SJames Smart struct lpfc_wcqe_complete *wcqe) 100001649561SJames Smart { 1001c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd = 1002c490850aSJames Smart (struct lpfc_io_buf *)pwqeIn->context1; 100301649561SJames Smart struct lpfc_vport *vport = pwqeIn->vport; 100401649561SJames Smart struct nvmefc_fcp_req *nCmd; 100501649561SJames Smart struct nvme_fc_ersp_iu *ep; 100601649561SJames Smart struct nvme_fc_cmd_iu *cp; 100701649561SJames Smart struct lpfc_nodelist *ndlp; 1008bbe3012bSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 10094b056682SJames Smart struct lpfc_nvme_lport *lport; 1010352b205aSArnd Bergmann uint32_t code, status, idx; 101101649561SJames Smart uint16_t cid, sqhd, data; 101201649561SJames Smart uint32_t *ptr; 101301649561SJames Smart 101401649561SJames Smart /* Sanity check on return of outstanding command */ 10154d5e789aSJames Smart if (!lpfc_ncmd) { 10164d5e789aSJames Smart lpfc_printf_vlog(vport, KERN_ERR, 10174d5e789aSJames Smart LOG_NODE | LOG_NVME_IOERR, 10184d5e789aSJames Smart "6071 Null lpfc_ncmd pointer. No " 10194d5e789aSJames Smart "release, skip completion\n"); 10204d5e789aSJames Smart return; 10214d5e789aSJames Smart } 10224d5e789aSJames Smart 1023c2017260SJames Smart /* Guard against abort handler being called at same time */ 1024c2017260SJames Smart spin_lock(&lpfc_ncmd->buf_lock); 1025c2017260SJames Smart 1026c2017260SJames Smart if (!lpfc_ncmd->nvmeCmd) { 1027c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 102801649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, 102932350664SJames Smart "6066 Missing cmpl ptrs: lpfc_ncmd x%px, " 103032350664SJames Smart "nvmeCmd x%px\n", 10310b05e9feSJames Smart lpfc_ncmd, lpfc_ncmd->nvmeCmd); 10324d5e789aSJames Smart 10334d5e789aSJames Smart /* Release the lpfc_ncmd regardless of the missing elements. */ 10344d5e789aSJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 103501649561SJames Smart return; 103601649561SJames Smart } 103701649561SJames Smart nCmd = lpfc_ncmd->nvmeCmd; 10384b056682SJames Smart status = bf_get(lpfc_wcqe_c_status, wcqe); 103966a210ffSJames Smart 10404c47efc1SJames Smart idx = lpfc_ncmd->cur_iocbq.hba_wqidx; 10414c47efc1SJames Smart phba->sli4_hba.hdwq[idx].nvme_cstat.io_cmpls++; 10424c47efc1SJames Smart 10431df09449SJames Smart if (unlikely(status && vport->localport)) { 10444b056682SJames Smart lport = (struct lpfc_nvme_lport *)vport->localport->private; 10451df09449SJames Smart if (lport) { 10464b056682SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 10474b056682SJames Smart atomic_inc(&lport->cmpl_fcp_xb); 10484b056682SJames Smart atomic_inc(&lport->cmpl_fcp_err); 10494b056682SJames Smart } 105066a210ffSJames Smart } 105101649561SJames Smart 1052bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n", 1053bd2cdd5eSJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 10544b056682SJames Smart status, wcqe->parameter); 105501649561SJames Smart /* 105601649561SJames Smart * Catch race where our node has transitioned, but the 105701649561SJames Smart * transport is still transitioning. 105801649561SJames Smart */ 10590b05e9feSJames Smart ndlp = lpfc_ncmd->ndlp; 106001649561SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 106101649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 106201649561SJames Smart "6062 Ignoring NVME cmpl. No ndlp\n"); 106301649561SJames Smart goto out_err; 106401649561SJames Smart } 106501649561SJames Smart 106601649561SJames Smart code = bf_get(lpfc_wcqe_c_code, wcqe); 106701649561SJames Smart if (code == CQE_CODE_NVME_ERSP) { 106801649561SJames Smart /* For this type of CQE, we need to rebuild the rsp */ 106901649561SJames Smart ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr; 107001649561SJames Smart 107101649561SJames Smart /* 107201649561SJames Smart * Get Command Id from cmd to plug into response. This 107301649561SJames Smart * code is not needed in the next NVME Transport drop. 107401649561SJames Smart */ 107501649561SJames Smart cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr; 107601649561SJames Smart cid = cp->sqe.common.command_id; 107701649561SJames Smart 107801649561SJames Smart /* 107901649561SJames Smart * RSN is in CQE word 2 108001649561SJames Smart * SQHD is in CQE Word 3 bits 15:0 108101649561SJames Smart * Cmd Specific info is in CQE Word 1 108201649561SJames Smart * and in CQE Word 0 bits 15:0 108301649561SJames Smart */ 108401649561SJames Smart sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe); 108501649561SJames Smart 108601649561SJames Smart /* Now lets build the NVME ERSP IU */ 108701649561SJames Smart ep->iu_len = cpu_to_be16(8); 108801649561SJames Smart ep->rsn = wcqe->parameter; 108901649561SJames Smart ep->xfrd_len = cpu_to_be32(nCmd->payload_length); 109001649561SJames Smart ep->rsvd12 = 0; 109101649561SJames Smart ptr = (uint32_t *)&ep->cqe.result.u64; 109201649561SJames Smart *ptr++ = wcqe->total_data_placed; 109301649561SJames Smart data = bf_get(lpfc_wcqe_c_ersp0, wcqe); 109401649561SJames Smart *ptr = (uint32_t)data; 109501649561SJames Smart ep->cqe.sq_head = sqhd; 109601649561SJames Smart ep->cqe.sq_id = nCmd->sqid; 109701649561SJames Smart ep->cqe.command_id = cid; 109801649561SJames Smart ep->cqe.status = 0; 109901649561SJames Smart 110001649561SJames Smart lpfc_ncmd->status = IOSTAT_SUCCESS; 110101649561SJames Smart lpfc_ncmd->result = 0; 110201649561SJames Smart nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN; 110301649561SJames Smart nCmd->transferred_length = nCmd->payload_length; 110401649561SJames Smart } else { 11054b056682SJames Smart lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK); 1106952c303bSDick Kennedy lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK); 110701649561SJames Smart 110801649561SJames Smart /* For NVME, the only failure path that results in an 110901649561SJames Smart * IO error is when the adapter rejects it. All other 111001649561SJames Smart * conditions are a success case and resolved by the 111101649561SJames Smart * transport. 111201649561SJames Smart * IOSTAT_FCP_RSP_ERROR means: 111301649561SJames Smart * 1. Length of data received doesn't match total 111401649561SJames Smart * transfer length in WQE 111501649561SJames Smart * 2. If the RSP payload does NOT match these cases: 111601649561SJames Smart * a. RSP length 12/24 bytes and all zeros 111701649561SJames Smart * b. NVME ERSP 111801649561SJames Smart */ 111901649561SJames Smart switch (lpfc_ncmd->status) { 112001649561SJames Smart case IOSTAT_SUCCESS: 112101649561SJames Smart nCmd->transferred_length = wcqe->total_data_placed; 112201649561SJames Smart nCmd->rcv_rsplen = 0; 112301649561SJames Smart nCmd->status = 0; 112401649561SJames Smart break; 112501649561SJames Smart case IOSTAT_FCP_RSP_ERROR: 112601649561SJames Smart nCmd->transferred_length = wcqe->total_data_placed; 112701649561SJames Smart nCmd->rcv_rsplen = wcqe->parameter; 112801649561SJames Smart nCmd->status = 0; 112901649561SJames Smart /* Sanity check */ 113001649561SJames Smart if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN) 113101649561SJames Smart break; 113201649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 113301649561SJames Smart "6081 NVME Completion Protocol Error: " 113486c67379SJames Smart "xri %x status x%x result x%x " 113586c67379SJames Smart "placed x%x\n", 113686c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 113701649561SJames Smart lpfc_ncmd->status, lpfc_ncmd->result, 113801649561SJames Smart wcqe->total_data_placed); 113901649561SJames Smart break; 1140952c303bSDick Kennedy case IOSTAT_LOCAL_REJECT: 1141952c303bSDick Kennedy /* Let fall through to set command final state. */ 1142952c303bSDick Kennedy if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED) 1143952c303bSDick Kennedy lpfc_printf_vlog(vport, KERN_INFO, 1144952c303bSDick Kennedy LOG_NVME_IOERR, 114532350664SJames Smart "6032 Delay Aborted cmd x%px " 114632350664SJames Smart "nvme cmd x%px, xri x%x, " 1147952c303bSDick Kennedy "xb %d\n", 1148952c303bSDick Kennedy lpfc_ncmd, nCmd, 1149952c303bSDick Kennedy lpfc_ncmd->cur_iocbq.sli4_xritag, 1150952c303bSDick Kennedy bf_get(lpfc_wcqe_c_xb, wcqe)); 1151cd05c155SBart Van Assche /* fall through */ 115201649561SJames Smart default: 115301649561SJames Smart out_err: 1154e3246a12SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 115586c67379SJames Smart "6072 NVME Completion Error: xri %x " 11562c013a3aSJames Smart "status x%x result x%x [x%x] " 11572c013a3aSJames Smart "placed x%x\n", 115886c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 115901649561SJames Smart lpfc_ncmd->status, lpfc_ncmd->result, 11602c013a3aSJames Smart wcqe->parameter, 116101649561SJames Smart wcqe->total_data_placed); 116201649561SJames Smart nCmd->transferred_length = 0; 116301649561SJames Smart nCmd->rcv_rsplen = 0; 11648e009ce8SJames Smart nCmd->status = NVME_SC_INTERNAL; 116501649561SJames Smart } 116601649561SJames Smart } 116701649561SJames Smart 116801649561SJames Smart /* pick up SLI4 exhange busy condition */ 116901649561SJames Smart if (bf_get(lpfc_wcqe_c_xb, wcqe)) 117001649561SJames Smart lpfc_ncmd->flags |= LPFC_SBUF_XBUSY; 117101649561SJames Smart else 117201649561SJames Smart lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY; 117301649561SJames Smart 117401649561SJames Smart /* Update stats and complete the IO. There is 117501649561SJames Smart * no need for dma unprep because the nvme_transport 117601649561SJames Smart * owns the dma address. 117701649561SJames Smart */ 1178bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1179c8a4ce0bSDick Kennedy if (lpfc_ncmd->ts_cmd_start) { 1180bd2cdd5eSJames Smart lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp; 1181bd2cdd5eSJames Smart lpfc_ncmd->ts_data_nvme = ktime_get_ns(); 1182bd2cdd5eSJames Smart phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme; 1183bd2cdd5eSJames Smart lpfc_nvme_ktime(phba, lpfc_ncmd); 1184bd2cdd5eSJames Smart } 11851df09449SJames Smart if (unlikely(phba->cpucheck_on & LPFC_CHECK_NVME_IO)) { 1186352b205aSArnd Bergmann uint32_t cpu; 118763df6d63SJames Smart idx = lpfc_ncmd->cur_iocbq.hba_wqidx; 1188d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 118963df6d63SJames Smart if (cpu < LPFC_CHECK_CPU_CNT) { 119063df6d63SJames Smart if (lpfc_ncmd->cpu != cpu) 119163df6d63SJames Smart lpfc_printf_vlog(vport, 119263df6d63SJames Smart KERN_INFO, LOG_NVME_IOERR, 1193bd2cdd5eSJames Smart "6701 CPU Check cmpl: " 1194bd2cdd5eSJames Smart "cpu %d expect %d\n", 119563df6d63SJames Smart cpu, lpfc_ncmd->cpu); 119663df6d63SJames Smart phba->sli4_hba.hdwq[idx].cpucheck_cmpl_io[cpu]++; 119763df6d63SJames Smart } 1198bd2cdd5eSJames Smart } 1199bd2cdd5eSJames Smart #endif 1200952c303bSDick Kennedy 1201952c303bSDick Kennedy /* NVME targets need completion held off until the abort exchange 1202add9d6beSJames Smart * completes unless the NVME Rport is getting unregistered. 1203952c303bSDick Kennedy */ 1204add9d6beSJames Smart 12053fd78355SJames Smart if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) { 120691455b85SJames Smart freqpriv = nCmd->private; 120791455b85SJames Smart freqpriv->nvme_buf = NULL; 12083fd78355SJames Smart lpfc_ncmd->nvmeCmd = NULL; 1209c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 1210c2017260SJames Smart nCmd->done(nCmd); 1211c2017260SJames Smart } else 1212c2017260SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 121301649561SJames Smart 1214952c303bSDick Kennedy /* Call release with XB=1 to queue the IO into the abort list. */ 121501649561SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 121601649561SJames Smart } 121701649561SJames Smart 121801649561SJames Smart 121901649561SJames Smart /** 122001649561SJames Smart * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO 122101649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 122201649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 122301649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 122401649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 122501649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 122601649561SJames Smart * 122701649561SJames Smart * Driver registers this routine as it io request handler. This 122801649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 122901649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 123001649561SJames Smart * 123101649561SJames Smart * Return value : 123201649561SJames Smart * 0 - Success 123301649561SJames Smart * TODO: What are the failure codes. 123401649561SJames Smart **/ 123501649561SJames Smart static int 123601649561SJames Smart lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport, 1237c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd, 123866a210ffSJames Smart struct lpfc_nodelist *pnode, 12394c47efc1SJames Smart struct lpfc_fc4_ctrl_stat *cstat) 124001649561SJames Smart { 124101649561SJames Smart struct lpfc_hba *phba = vport->phba; 124201649561SJames Smart struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; 124301649561SJames Smart struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq); 1244205e8240SJames Smart union lpfc_wqe128 *wqe = &pwqeq->wqe; 124501649561SJames Smart uint32_t req_len; 124601649561SJames Smart 1247e960f5abSJames Smart if (!NLP_CHK_NODE_ACT(pnode)) 124801649561SJames Smart return -EINVAL; 124901649561SJames Smart 125001649561SJames Smart /* 125101649561SJames Smart * There are three possibilities here - use scatter-gather segment, use 125201649561SJames Smart * the single mapping, or neither. 125301649561SJames Smart */ 125401649561SJames Smart if (nCmd->sg_cnt) { 125501649561SJames Smart if (nCmd->io_dir == NVMEFC_FCP_WRITE) { 12565fd11085SJames Smart /* From the iwrite template, initialize words 7 - 11 */ 12575fd11085SJames Smart memcpy(&wqe->words[7], 12585fd11085SJames Smart &lpfc_iwrite_cmd_template.words[7], 12595fd11085SJames Smart sizeof(uint32_t) * 5); 12605fd11085SJames Smart 12615fd11085SJames Smart /* Word 4 */ 12625fd11085SJames Smart wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length; 12635fd11085SJames Smart 126401649561SJames Smart /* Word 5 */ 126501649561SJames Smart if ((phba->cfg_nvme_enable_fb) && 126601649561SJames Smart (pnode->nlp_flag & NLP_FIRSTBURST)) { 126701649561SJames Smart req_len = lpfc_ncmd->nvmeCmd->payload_length; 126801649561SJames Smart if (req_len < pnode->nvme_fb_size) 126901649561SJames Smart wqe->fcp_iwrite.initial_xfer_len = 127001649561SJames Smart req_len; 127101649561SJames Smart else 127201649561SJames Smart wqe->fcp_iwrite.initial_xfer_len = 127301649561SJames Smart pnode->nvme_fb_size; 12745fd11085SJames Smart } else { 12755fd11085SJames Smart wqe->fcp_iwrite.initial_xfer_len = 0; 127601649561SJames Smart } 12774c47efc1SJames Smart cstat->output_requests++; 127801649561SJames Smart } else { 12795fd11085SJames Smart /* From the iread template, initialize words 7 - 11 */ 12805fd11085SJames Smart memcpy(&wqe->words[7], 12815fd11085SJames Smart &lpfc_iread_cmd_template.words[7], 12825fd11085SJames Smart sizeof(uint32_t) * 5); 128301649561SJames Smart 12845fd11085SJames Smart /* Word 4 */ 12855fd11085SJames Smart wqe->fcp_iread.total_xfer_len = nCmd->payload_length; 128601649561SJames Smart 12875fd11085SJames Smart /* Word 5 */ 12885fd11085SJames Smart wqe->fcp_iread.rsrvd5 = 0; 128901649561SJames Smart 12904c47efc1SJames Smart cstat->input_requests++; 129101649561SJames Smart } 129201649561SJames Smart } else { 12935fd11085SJames Smart /* From the icmnd template, initialize words 4 - 11 */ 12945fd11085SJames Smart memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4], 12955fd11085SJames Smart sizeof(uint32_t) * 8); 12964c47efc1SJames Smart cstat->control_requests++; 129701649561SJames Smart } 12980d8af096SJames Smart 12990d8af096SJames Smart if (pnode->nlp_nvme_info & NLP_NVME_NSLER) 13000d8af096SJames Smart bf_set(wqe_erp, &wqe->generic.wqe_com, 1); 130101649561SJames Smart /* 130201649561SJames Smart * Finish initializing those WQE fields that are independent 130301649561SJames Smart * of the nvme_cmnd request_buffer 130401649561SJames Smart */ 130501649561SJames Smart 13065fd11085SJames Smart /* Word 3 */ 13075fd11085SJames Smart bf_set(payload_offset_len, &wqe->fcp_icmd, 13085fd11085SJames Smart (nCmd->rsplen + nCmd->cmdlen)); 13095fd11085SJames Smart 131001649561SJames Smart /* Word 6 */ 131101649561SJames Smart bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 131201649561SJames Smart phba->sli4_hba.rpi_ids[pnode->nlp_rpi]); 131301649561SJames Smart bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); 131401649561SJames Smart 131501649561SJames Smart /* Word 8 */ 131601649561SJames Smart wqe->generic.wqe_com.abort_tag = pwqeq->iotag; 131701649561SJames Smart 131801649561SJames Smart /* Word 9 */ 131901649561SJames Smart bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); 132001649561SJames Smart 1321414abe0aSJames Smart /* Words 13 14 15 are for PBDE support */ 1322414abe0aSJames Smart 132301649561SJames Smart pwqeq->vport = vport; 132401649561SJames Smart return 0; 132501649561SJames Smart } 132601649561SJames Smart 132701649561SJames Smart 132801649561SJames Smart /** 132901649561SJames Smart * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO 133001649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 133101649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 133201649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 133301649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 133401649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 133501649561SJames Smart * 133601649561SJames Smart * Driver registers this routine as it io request handler. This 133701649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 133801649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. 133901649561SJames Smart * 134001649561SJames Smart * Return value : 134101649561SJames Smart * 0 - Success 134201649561SJames Smart * TODO: What are the failure codes. 134301649561SJames Smart **/ 134401649561SJames Smart static int 134501649561SJames Smart lpfc_nvme_prep_io_dma(struct lpfc_vport *vport, 1346c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd) 134701649561SJames Smart { 134801649561SJames Smart struct lpfc_hba *phba = vport->phba; 134901649561SJames Smart struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; 1350205e8240SJames Smart union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe; 13510794d601SJames Smart struct sli4_sge *sgl = lpfc_ncmd->dma_sgl; 1352d79c9e9dSJames Smart struct sli4_hybrid_sgl *sgl_xtra = NULL; 135301649561SJames Smart struct scatterlist *data_sg; 135401649561SJames Smart struct sli4_sge *first_data_sgl; 13550bc2b7c5SJames Smart struct ulp_bde64 *bde; 1356d79c9e9dSJames Smart dma_addr_t physaddr = 0; 135701649561SJames Smart uint32_t num_bde = 0; 1358d79c9e9dSJames Smart uint32_t dma_len = 0; 135901649561SJames Smart uint32_t dma_offset = 0; 1360d79c9e9dSJames Smart int nseg, i, j; 1361d79c9e9dSJames Smart bool lsp_just_set = false; 136201649561SJames Smart 136301649561SJames Smart /* Fix up the command and response DMA stuff. */ 136401649561SJames Smart lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd); 136501649561SJames Smart 136601649561SJames Smart /* 136701649561SJames Smart * There are three possibilities here - use scatter-gather segment, use 136801649561SJames Smart * the single mapping, or neither. 136901649561SJames Smart */ 137001649561SJames Smart if (nCmd->sg_cnt) { 137101649561SJames Smart /* 137201649561SJames Smart * Jump over the cmd and rsp SGEs. The fix routine 137301649561SJames Smart * has already adjusted for this. 137401649561SJames Smart */ 137501649561SJames Smart sgl += 2; 137601649561SJames Smart 137701649561SJames Smart first_data_sgl = sgl; 137801649561SJames Smart lpfc_ncmd->seg_cnt = nCmd->sg_cnt; 137981e6a637SJames Smart if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) { 138001649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 138101649561SJames Smart "6058 Too many sg segments from " 138201649561SJames Smart "NVME Transport. Max %d, " 138301649561SJames Smart "nvmeIO sg_cnt %d\n", 138429bfd55aSJames Smart phba->cfg_nvme_seg_cnt + 1, 138501649561SJames Smart lpfc_ncmd->seg_cnt); 138601649561SJames Smart lpfc_ncmd->seg_cnt = 0; 138701649561SJames Smart return 1; 138801649561SJames Smart } 138901649561SJames Smart 139001649561SJames Smart /* 139101649561SJames Smart * The driver established a maximum scatter-gather segment count 139201649561SJames Smart * during probe that limits the number of sg elements in any 139301649561SJames Smart * single nvme command. Just run through the seg_cnt and format 139401649561SJames Smart * the sge's. 139501649561SJames Smart */ 139601649561SJames Smart nseg = nCmd->sg_cnt; 139701649561SJames Smart data_sg = nCmd->first_sgl; 1398d79c9e9dSJames Smart 1399d79c9e9dSJames Smart /* for tracking the segment boundaries */ 1400d79c9e9dSJames Smart j = 2; 140101649561SJames Smart for (i = 0; i < nseg; i++) { 140201649561SJames Smart if (data_sg == NULL) { 140301649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 140401649561SJames Smart "6059 dptr err %d, nseg %d\n", 140501649561SJames Smart i, nseg); 140601649561SJames Smart lpfc_ncmd->seg_cnt = 0; 140701649561SJames Smart return 1; 140801649561SJames Smart } 1409d79c9e9dSJames Smart 1410d79c9e9dSJames Smart sgl->word2 = 0; 1411d79c9e9dSJames Smart if ((num_bde + 1) == nseg) { 1412d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1413d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1414d79c9e9dSJames Smart LPFC_SGE_TYPE_DATA); 1415d79c9e9dSJames Smart } else { 1416d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 1417d79c9e9dSJames Smart 1418d79c9e9dSJames Smart /* expand the segment */ 1419d79c9e9dSJames Smart if (!lsp_just_set && 1420d79c9e9dSJames Smart !((j + 1) % phba->border_sge_num) && 1421d79c9e9dSJames Smart ((nseg - 1) != i)) { 1422d79c9e9dSJames Smart /* set LSP type */ 1423d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1424d79c9e9dSJames Smart LPFC_SGE_TYPE_LSP); 1425d79c9e9dSJames Smart 1426d79c9e9dSJames Smart sgl_xtra = lpfc_get_sgl_per_hdwq( 1427d79c9e9dSJames Smart phba, lpfc_ncmd); 1428d79c9e9dSJames Smart 1429d79c9e9dSJames Smart if (unlikely(!sgl_xtra)) { 1430d79c9e9dSJames Smart lpfc_ncmd->seg_cnt = 0; 1431d79c9e9dSJames Smart return 1; 1432d79c9e9dSJames Smart } 1433d79c9e9dSJames Smart sgl->addr_lo = cpu_to_le32(putPaddrLow( 1434d79c9e9dSJames Smart sgl_xtra->dma_phys_sgl)); 1435d79c9e9dSJames Smart sgl->addr_hi = cpu_to_le32(putPaddrHigh( 1436d79c9e9dSJames Smart sgl_xtra->dma_phys_sgl)); 1437d79c9e9dSJames Smart 1438d79c9e9dSJames Smart } else { 1439d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_type, sgl, 1440d79c9e9dSJames Smart LPFC_SGE_TYPE_DATA); 1441d79c9e9dSJames Smart } 1442d79c9e9dSJames Smart } 1443d79c9e9dSJames Smart 1444d79c9e9dSJames Smart if (!(bf_get(lpfc_sli4_sge_type, sgl) & 1445d79c9e9dSJames Smart LPFC_SGE_TYPE_LSP)) { 1446d79c9e9dSJames Smart if ((nseg - 1) == i) 1447d79c9e9dSJames Smart bf_set(lpfc_sli4_sge_last, sgl, 1); 1448d79c9e9dSJames Smart 144901649561SJames Smart physaddr = data_sg->dma_address; 145001649561SJames Smart dma_len = data_sg->length; 1451d79c9e9dSJames Smart sgl->addr_lo = cpu_to_le32( 1452d79c9e9dSJames Smart putPaddrLow(physaddr)); 1453d79c9e9dSJames Smart sgl->addr_hi = cpu_to_le32( 1454d79c9e9dSJames Smart putPaddrHigh(physaddr)); 1455d79c9e9dSJames Smart 145601649561SJames Smart bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); 145701649561SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 145801649561SJames Smart sgl->sge_len = cpu_to_le32(dma_len); 145901649561SJames Smart 146001649561SJames Smart dma_offset += dma_len; 146101649561SJames Smart data_sg = sg_next(data_sg); 1462d79c9e9dSJames Smart 146301649561SJames Smart sgl++; 1464d79c9e9dSJames Smart 1465d79c9e9dSJames Smart lsp_just_set = false; 1466d79c9e9dSJames Smart } else { 1467d79c9e9dSJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 1468d79c9e9dSJames Smart 1469d79c9e9dSJames Smart sgl->sge_len = cpu_to_le32( 1470d79c9e9dSJames Smart phba->cfg_sg_dma_buf_size); 1471d79c9e9dSJames Smart 1472d79c9e9dSJames Smart sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; 1473d79c9e9dSJames Smart i = i - 1; 1474d79c9e9dSJames Smart 1475d79c9e9dSJames Smart lsp_just_set = true; 1476d79c9e9dSJames Smart } 1477d79c9e9dSJames Smart 1478d79c9e9dSJames Smart j++; 147901649561SJames Smart } 1480414abe0aSJames Smart if (phba->cfg_enable_pbde) { 14810bc2b7c5SJames Smart /* Use PBDE support for first SGL only, offset == 0 */ 14820bc2b7c5SJames Smart /* Words 13-15 */ 14830bc2b7c5SJames Smart bde = (struct ulp_bde64 *) 14840bc2b7c5SJames Smart &wqe->words[13]; 14850bc2b7c5SJames Smart bde->addrLow = first_data_sgl->addr_lo; 14860bc2b7c5SJames Smart bde->addrHigh = first_data_sgl->addr_hi; 14870bc2b7c5SJames Smart bde->tus.f.bdeSize = 14880bc2b7c5SJames Smart le32_to_cpu(first_data_sgl->sge_len); 14890bc2b7c5SJames Smart bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; 14900bc2b7c5SJames Smart bde->tus.w = cpu_to_le32(bde->tus.w); 14915fd11085SJames Smart /* wqe_pbde is 1 in template */ 14925fd11085SJames Smart } else { 14935fd11085SJames Smart memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3)); 14940bc2b7c5SJames Smart bf_set(wqe_pbde, &wqe->generic.wqe_com, 0); 14955fd11085SJames Smart } 14960bc2b7c5SJames Smart 1497414abe0aSJames Smart } else { 14980794d601SJames Smart lpfc_ncmd->seg_cnt = 0; 14990794d601SJames Smart 150001649561SJames Smart /* For this clause to be valid, the payload_length 150101649561SJames Smart * and sg_cnt must zero. 150201649561SJames Smart */ 150301649561SJames Smart if (nCmd->payload_length != 0) { 150401649561SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 150501649561SJames Smart "6063 NVME DMA Prep Err: sg_cnt %d " 150601649561SJames Smart "payload_length x%x\n", 150701649561SJames Smart nCmd->sg_cnt, nCmd->payload_length); 150801649561SJames Smart return 1; 150901649561SJames Smart } 151001649561SJames Smart } 151101649561SJames Smart return 0; 151201649561SJames Smart } 151301649561SJames Smart 151401649561SJames Smart /** 151501649561SJames Smart * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO 151601649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 151701649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 151801649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 151901649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 152001649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 152101649561SJames Smart * 152201649561SJames Smart * Driver registers this routine as it io request handler. This 152301649561SJames Smart * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq 152401649561SJames Smart * data structure to the rport 152501649561SJames Smart indicated in @lpfc_nvme_rport. 152601649561SJames Smart * 152701649561SJames Smart * Return value : 152801649561SJames Smart * 0 - Success 152901649561SJames Smart * TODO: What are the failure codes. 153001649561SJames Smart **/ 153101649561SJames Smart static int 153201649561SJames Smart lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport, 153301649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 153401649561SJames Smart void *hw_queue_handle, 153501649561SJames Smart struct nvmefc_fcp_req *pnvme_fcreq) 153601649561SJames Smart { 153701649561SJames Smart int ret = 0; 1538cf1a1d3eSJames Smart int expedite = 0; 153963df6d63SJames Smart int idx, cpu; 154001649561SJames Smart struct lpfc_nvme_lport *lport; 15414c47efc1SJames Smart struct lpfc_fc4_ctrl_stat *cstat; 154201649561SJames Smart struct lpfc_vport *vport; 154301649561SJames Smart struct lpfc_hba *phba; 154401649561SJames Smart struct lpfc_nodelist *ndlp; 1545c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd; 154601649561SJames Smart struct lpfc_nvme_rport *rport; 154701649561SJames Smart struct lpfc_nvme_qhandle *lpfc_queue_info; 1548c3725bdcSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 1549cf1a1d3eSJames Smart struct nvme_common_command *sqe; 1550bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1551bd2cdd5eSJames Smart uint64_t start = 0; 1552bd2cdd5eSJames Smart #endif 155301649561SJames Smart 1554c3725bdcSJames Smart /* Validate pointers. LLDD fault handling with transport does 1555c3725bdcSJames Smart * have timing races. 1556c3725bdcSJames Smart */ 155701649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 1558c3725bdcSJames Smart if (unlikely(!lport)) { 1559c3725bdcSJames Smart ret = -EINVAL; 1560c3725bdcSJames Smart goto out_fail; 1561c3725bdcSJames Smart } 1562c3725bdcSJames Smart 156301649561SJames Smart vport = lport->vport; 1564c3725bdcSJames Smart 1565c3725bdcSJames Smart if (unlikely(!hw_queue_handle)) { 156644c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 156744c2757bSJames Smart "6117 Fail IO, NULL hw_queue_handle\n"); 156844c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1569cd240071SJames Smart ret = -EBUSY; 1570c3725bdcSJames Smart goto out_fail; 1571c3725bdcSJames Smart } 1572c3725bdcSJames Smart 157301649561SJames Smart phba = vport->phba; 157401649561SJames Smart 15751abcb371SDick Kennedy if (vport->load_flag & FC_UNLOADING) { 15761abcb371SDick Kennedy ret = -ENODEV; 15771abcb371SDick Kennedy goto out_fail; 15781abcb371SDick Kennedy } 15791abcb371SDick Kennedy 15801df09449SJames Smart if (unlikely(vport->load_flag & FC_UNLOADING)) { 158144c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 158244c2757bSJames Smart "6124 Fail IO, Driver unload\n"); 158344c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 15843386f4bdSJames Smart ret = -ENODEV; 15853386f4bdSJames Smart goto out_fail; 15863386f4bdSJames Smart } 15873386f4bdSJames Smart 1588c3725bdcSJames Smart freqpriv = pnvme_fcreq->private; 1589c3725bdcSJames Smart if (unlikely(!freqpriv)) { 159044c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 159144c2757bSJames Smart "6158 Fail IO, NULL request data\n"); 159244c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1593c3725bdcSJames Smart ret = -EINVAL; 1594b7672ae6SDick Kennedy goto out_fail; 1595b7672ae6SDick Kennedy } 1596b7672ae6SDick Kennedy 1597bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1598bd2cdd5eSJames Smart if (phba->ktime_on) 1599bd2cdd5eSJames Smart start = ktime_get_ns(); 1600bd2cdd5eSJames Smart #endif 160101649561SJames Smart rport = (struct lpfc_nvme_rport *)pnvme_rport->private; 160201649561SJames Smart lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle; 160301649561SJames Smart 160401649561SJames Smart /* 160501649561SJames Smart * Catch race where our node has transitioned, but the 160601649561SJames Smart * transport is still transitioning. 160701649561SJames Smart */ 160801649561SJames Smart ndlp = rport->ndlp; 160901649561SJames Smart if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 161044c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR, 161132350664SJames Smart "6053 Busy IO, ndlp not ready: rport x%px " 161232350664SJames Smart "ndlp x%px, DID x%06x\n", 161301649561SJames Smart rport, ndlp, pnvme_rport->port_id); 161444c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 1615cd240071SJames Smart ret = -EBUSY; 161601649561SJames Smart goto out_fail; 161701649561SJames Smart } 161801649561SJames Smart 161901649561SJames Smart /* The remote node has to be a mapped target or it's an error. */ 162001649561SJames Smart if ((ndlp->nlp_type & NLP_NVME_TARGET) && 162101649561SJames Smart (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { 162244c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR, 162344c2757bSJames Smart "6036 Fail IO, DID x%06x not ready for " 1624cd240071SJames Smart "IO. State x%x, Type x%x Flg x%x\n", 162544c2757bSJames Smart pnvme_rport->port_id, 1626cd240071SJames Smart ndlp->nlp_state, ndlp->nlp_type, 1627cd240071SJames Smart ndlp->upcall_flags); 16284b056682SJames Smart atomic_inc(&lport->xmt_fcp_bad_ndlp); 1629cd240071SJames Smart ret = -EBUSY; 163001649561SJames Smart goto out_fail; 163101649561SJames Smart 163201649561SJames Smart } 163301649561SJames Smart 1634cf1a1d3eSJames Smart /* Currently only NVME Keep alive commands should be expedited 1635cf1a1d3eSJames Smart * if the driver runs out of a resource. These should only be 1636cf1a1d3eSJames Smart * issued on the admin queue, qidx 0 1637cf1a1d3eSJames Smart */ 1638cf1a1d3eSJames Smart if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) { 1639cf1a1d3eSJames Smart sqe = &((struct nvme_fc_cmd_iu *) 1640cf1a1d3eSJames Smart pnvme_fcreq->cmdaddr)->sqe.common; 1641cf1a1d3eSJames Smart if (sqe->opcode == nvme_admin_keep_alive) 1642cf1a1d3eSJames Smart expedite = 1; 1643cf1a1d3eSJames Smart } 1644cf1a1d3eSJames Smart 164501649561SJames Smart /* The node is shared with FCP IO, make sure the IO pending count does 164601649561SJames Smart * not exceed the programmed depth. 164701649561SJames Smart */ 16482a5b7d62SJames Smart if (lpfc_ndlp_check_qdepth(phba, ndlp)) { 1649cf1a1d3eSJames Smart if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) && 1650cf1a1d3eSJames Smart !expedite) { 165144c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 165244c2757bSJames Smart "6174 Fail IO, ndlp qdepth exceeded: " 16534d5e789aSJames Smart "idx %d DID %x pend %d qdepth %d\n", 16544d5e789aSJames Smart lpfc_queue_info->index, ndlp->nlp_DID, 16554d5e789aSJames Smart atomic_read(&ndlp->cmd_pending), 16564d5e789aSJames Smart ndlp->cmd_qdepth); 16574b056682SJames Smart atomic_inc(&lport->xmt_fcp_qdepth); 1658cd22d605SDick Kennedy ret = -EBUSY; 165901649561SJames Smart goto out_fail; 166001649561SJames Smart } 16612a5b7d62SJames Smart } 166201649561SJames Smart 16636a828b0fSJames Smart /* Lookup Hardware Queue index based on fcp_io_sched module parameter */ 166445aa312eSJames Smart if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) { 166545aa312eSJames Smart idx = lpfc_queue_info->index; 166645aa312eSJames Smart } else { 1667d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 16686a828b0fSJames Smart idx = phba->sli4_hba.cpu_map[cpu].hdwq; 166945aa312eSJames Smart } 167045aa312eSJames Smart 167145aa312eSJames Smart lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, idx, expedite); 167201649561SJames Smart if (lpfc_ncmd == NULL) { 16734b056682SJames Smart atomic_inc(&lport->xmt_fcp_noxri); 167401649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 167544c2757bSJames Smart "6065 Fail IO, driver buffer pool is empty: " 167644c2757bSJames Smart "idx %d DID %x\n", 167744c2757bSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 1678cd22d605SDick Kennedy ret = -EBUSY; 167901649561SJames Smart goto out_fail; 168001649561SJames Smart } 1681bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1682c8a4ce0bSDick Kennedy if (start) { 1683bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_start = start; 1684bd2cdd5eSJames Smart lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd; 1685c8a4ce0bSDick Kennedy } else { 1686c8a4ce0bSDick Kennedy lpfc_ncmd->ts_cmd_start = 0; 1687bd2cdd5eSJames Smart } 1688bd2cdd5eSJames Smart #endif 168901649561SJames Smart 169001649561SJames Smart /* 169101649561SJames Smart * Store the data needed by the driver to issue, abort, and complete 169201649561SJames Smart * an IO. 169301649561SJames Smart * Do not let the IO hang out forever. There is no midlayer issuing 169401649561SJames Smart * an abort so inform the FW of the maximum IO pending time. 169501649561SJames Smart */ 1696bbe3012bSJames Smart freqpriv->nvme_buf = lpfc_ncmd; 169701649561SJames Smart lpfc_ncmd->nvmeCmd = pnvme_fcreq; 1698318083adSJames Smart lpfc_ncmd->ndlp = ndlp; 16990794d601SJames Smart lpfc_ncmd->qidx = lpfc_queue_info->qidx; 170001649561SJames Smart 170101649561SJames Smart /* 170201649561SJames Smart * Issue the IO on the WQ indicated by index in the hw_queue_handle. 170301649561SJames Smart * This identfier was create in our hardware queue create callback 170401649561SJames Smart * routine. The driver now is dependent on the IO queue steering from 170501649561SJames Smart * the transport. We are trusting the upper NVME layers know which 170601649561SJames Smart * index to use and that they have affinitized a CPU to this hardware 170701649561SJames Smart * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ. 170801649561SJames Smart */ 170966a210ffSJames Smart lpfc_ncmd->cur_iocbq.hba_wqidx = idx; 17104c47efc1SJames Smart cstat = &phba->sli4_hba.hdwq[idx].nvme_cstat; 171166a210ffSJames Smart 171266a210ffSJames Smart lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat); 171366a210ffSJames Smart ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd); 171466a210ffSJames Smart if (ret) { 171544c2757bSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 171644c2757bSJames Smart "6175 Fail IO, Prep DMA: " 171744c2757bSJames Smart "idx %d DID %x\n", 171844c2757bSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 171944c2757bSJames Smart atomic_inc(&lport->xmt_fcp_err); 172066a210ffSJames Smart ret = -ENOMEM; 172166a210ffSJames Smart goto out_free_nvme_buf; 172266a210ffSJames Smart } 172366a210ffSJames Smart 1724bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n", 1725bd2cdd5eSJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 1726bd2cdd5eSJames Smart lpfc_queue_info->index, ndlp->nlp_DID); 1727bd2cdd5eSJames Smart 17281fbf9742SJames Smart ret = lpfc_sli4_issue_wqe(phba, lpfc_ncmd->hdwq, &lpfc_ncmd->cur_iocbq); 172901649561SJames Smart if (ret) { 17304b056682SJames Smart atomic_inc(&lport->xmt_fcp_wqerr); 1731e3246a12SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 173244c2757bSJames Smart "6113 Fail IO, Could not issue WQE err %x " 173301649561SJames Smart "sid: x%x did: x%x oxid: x%x\n", 173401649561SJames Smart ret, vport->fc_myDID, ndlp->nlp_DID, 173501649561SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag); 173601649561SJames Smart goto out_free_nvme_buf; 173701649561SJames Smart } 173801649561SJames Smart 1739c490850aSJames Smart if (phba->cfg_xri_rebalancing) 1740c490850aSJames Smart lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_ncmd->hdwq_no); 1741c490850aSJames Smart 1742bd2cdd5eSJames Smart #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1743c8a4ce0bSDick Kennedy if (lpfc_ncmd->ts_cmd_start) 1744bd2cdd5eSJames Smart lpfc_ncmd->ts_cmd_wqput = ktime_get_ns(); 1745bd2cdd5eSJames Smart 1746bd2cdd5eSJames Smart if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) { 1747d6d189ceSBart Van Assche cpu = raw_smp_processor_id(); 174863df6d63SJames Smart if (cpu < LPFC_CHECK_CPU_CNT) { 174963df6d63SJames Smart lpfc_ncmd->cpu = cpu; 175063df6d63SJames Smart if (idx != cpu) 1751bd2cdd5eSJames Smart lpfc_printf_vlog(vport, 175263df6d63SJames Smart KERN_INFO, LOG_NVME_IOERR, 1753bd2cdd5eSJames Smart "6702 CPU Check cmd: " 1754bd2cdd5eSJames Smart "cpu %d wq %d\n", 1755bd2cdd5eSJames Smart lpfc_ncmd->cpu, 1756bd2cdd5eSJames Smart lpfc_queue_info->index); 175763df6d63SJames Smart phba->sli4_hba.hdwq[idx].cpucheck_xmt_io[cpu]++; 1758bd2cdd5eSJames Smart } 1759bd2cdd5eSJames Smart } 1760bd2cdd5eSJames Smart #endif 176101649561SJames Smart return 0; 176201649561SJames Smart 176301649561SJames Smart out_free_nvme_buf: 17642cee7808SJames Smart if (lpfc_ncmd->nvmeCmd->sg_cnt) { 17652cee7808SJames Smart if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE) 17664c47efc1SJames Smart cstat->output_requests--; 17672cee7808SJames Smart else 17684c47efc1SJames Smart cstat->input_requests--; 17692cee7808SJames Smart } else 17704c47efc1SJames Smart cstat->control_requests--; 177101649561SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 177201649561SJames Smart out_fail: 177301649561SJames Smart return ret; 177401649561SJames Smart } 177501649561SJames Smart 177601649561SJames Smart /** 177701649561SJames Smart * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request. 177801649561SJames Smart * @phba: Pointer to HBA context object 177901649561SJames Smart * @cmdiocb: Pointer to command iocb object. 178001649561SJames Smart * @rspiocb: Pointer to response iocb object. 178101649561SJames Smart * 178201649561SJames Smart * This is the callback function for any NVME FCP IO that was aborted. 178301649561SJames Smart * 178401649561SJames Smart * Return value: 178501649561SJames Smart * None 178601649561SJames Smart **/ 178701649561SJames Smart void 178801649561SJames Smart lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 178901649561SJames Smart struct lpfc_wcqe_complete *abts_cmpl) 179001649561SJames Smart { 1791e3246a12SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME, 179201649561SJames Smart "6145 ABORT_XRI_CN completing on rpi x%x " 179301649561SJames Smart "original iotag x%x, abort cmd iotag x%x " 179401649561SJames Smart "req_tag x%x, status x%x, hwstatus x%x\n", 179501649561SJames Smart cmdiocb->iocb.un.acxri.abortContextTag, 179601649561SJames Smart cmdiocb->iocb.un.acxri.abortIoTag, 179701649561SJames Smart cmdiocb->iotag, 179801649561SJames Smart bf_get(lpfc_wcqe_c_request_tag, abts_cmpl), 179901649561SJames Smart bf_get(lpfc_wcqe_c_status, abts_cmpl), 180001649561SJames Smart bf_get(lpfc_wcqe_c_hw_status, abts_cmpl)); 180101649561SJames Smart lpfc_sli_release_iocbq(phba, cmdiocb); 180201649561SJames Smart } 180301649561SJames Smart 180401649561SJames Smart /** 180501649561SJames Smart * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS 180601649561SJames Smart * @lpfc_pnvme: Pointer to the driver's nvme instance data 180701649561SJames Smart * @lpfc_nvme_lport: Pointer to the driver's local port data 180801649561SJames Smart * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq 180901649561SJames Smart * @lpfc_nvme_fcreq: IO request from nvme fc to driver. 181001649561SJames Smart * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue 181101649561SJames Smart * 181201649561SJames Smart * Driver registers this routine as its nvme request io abort handler. This 181301649561SJames Smart * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq 181401649561SJames Smart * data structure to the rport indicated in @lpfc_nvme_rport. This routine 181501649561SJames Smart * is executed asynchronously - one the target is validated as "MAPPED" and 181601649561SJames Smart * ready for IO, the driver issues the abort request and returns. 181701649561SJames Smart * 181801649561SJames Smart * Return value: 181901649561SJames Smart * None 182001649561SJames Smart **/ 182101649561SJames Smart static void 182201649561SJames Smart lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport, 182301649561SJames Smart struct nvme_fc_remote_port *pnvme_rport, 182401649561SJames Smart void *hw_queue_handle, 182501649561SJames Smart struct nvmefc_fcp_req *pnvme_fcreq) 182601649561SJames Smart { 182701649561SJames Smart struct lpfc_nvme_lport *lport; 182801649561SJames Smart struct lpfc_vport *vport; 182901649561SJames Smart struct lpfc_hba *phba; 1830c490850aSJames Smart struct lpfc_io_buf *lpfc_nbuf; 183101649561SJames Smart struct lpfc_iocbq *abts_buf; 183201649561SJames Smart struct lpfc_iocbq *nvmereq_wqe; 1833c3725bdcSJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 183401649561SJames Smart unsigned long flags; 183501649561SJames Smart int ret_val; 183601649561SJames Smart 1837c3725bdcSJames Smart /* Validate pointers. LLDD fault handling with transport does 1838c3725bdcSJames Smart * have timing races. 1839c3725bdcSJames Smart */ 184001649561SJames Smart lport = (struct lpfc_nvme_lport *)pnvme_lport->private; 1841c3725bdcSJames Smart if (unlikely(!lport)) 1842c3725bdcSJames Smart return; 184301649561SJames Smart 1844c3725bdcSJames Smart vport = lport->vport; 1845c3725bdcSJames Smart 1846c3725bdcSJames Smart if (unlikely(!hw_queue_handle)) { 1847c3725bdcSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 1848c3725bdcSJames Smart "6129 Fail Abort, HW Queue Handle NULL.\n"); 1849c3725bdcSJames Smart return; 1850c3725bdcSJames Smart } 1851c3725bdcSJames Smart 1852c3725bdcSJames Smart phba = vport->phba; 1853c3725bdcSJames Smart freqpriv = pnvme_fcreq->private; 1854c3725bdcSJames Smart 1855c3725bdcSJames Smart if (unlikely(!freqpriv)) 1856c3725bdcSJames Smart return; 18573386f4bdSJames Smart if (vport->load_flag & FC_UNLOADING) 18583386f4bdSJames Smart return; 18593386f4bdSJames Smart 186001649561SJames Smart /* Announce entry to new IO submit field. */ 186186c67379SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 186201649561SJames Smart "6002 Abort Request to rport DID x%06x " 186332350664SJames Smart "for nvme_fc_req x%px\n", 186401649561SJames Smart pnvme_rport->port_id, 186501649561SJames Smart pnvme_fcreq); 186601649561SJames Smart 186701649561SJames Smart /* If the hba is getting reset, this flag is set. It is 186801649561SJames Smart * cleared when the reset is complete and rings reestablished. 186901649561SJames Smart */ 187001649561SJames Smart spin_lock_irqsave(&phba->hbalock, flags); 187101649561SJames Smart /* driver queued commands are in process of being flushed */ 1872c00f62e6SJames Smart if (phba->hba_flag & HBA_IOQ_FLUSH) { 187301649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 187486c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 187501649561SJames Smart "6139 Driver in reset cleanup - flushing " 187601649561SJames Smart "NVME Req now. hba_flag x%x\n", 187701649561SJames Smart phba->hba_flag); 187801649561SJames Smart return; 187901649561SJames Smart } 188001649561SJames Smart 1881bbe3012bSJames Smart lpfc_nbuf = freqpriv->nvme_buf; 188201649561SJames Smart if (!lpfc_nbuf) { 188301649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 188486c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 188501649561SJames Smart "6140 NVME IO req has no matching lpfc nvme " 188601649561SJames Smart "io buffer. Skipping abort req.\n"); 188701649561SJames Smart return; 188801649561SJames Smart } else if (!lpfc_nbuf->nvmeCmd) { 188901649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 189086c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 189101649561SJames Smart "6141 lpfc NVME IO req has no nvme_fcreq " 189201649561SJames Smart "io buffer. Skipping abort req.\n"); 189301649561SJames Smart return; 189401649561SJames Smart } 18952b7824d0SJames Smart nvmereq_wqe = &lpfc_nbuf->cur_iocbq; 189601649561SJames Smart 1897c2017260SJames Smart /* Guard against IO completion being called at same time */ 1898c2017260SJames Smart spin_lock(&lpfc_nbuf->buf_lock); 1899c2017260SJames Smart 190001649561SJames Smart /* 190101649561SJames Smart * The lpfc_nbuf and the mapped nvme_fcreq in the driver's 190201649561SJames Smart * state must match the nvme_fcreq passed by the nvme 190301649561SJames Smart * transport. If they don't match, it is likely the driver 190401649561SJames Smart * has already completed the NVME IO and the nvme transport 190501649561SJames Smart * has not seen it yet. 190601649561SJames Smart */ 190701649561SJames Smart if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) { 190886c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 190901649561SJames Smart "6143 NVME req mismatch: " 191032350664SJames Smart "lpfc_nbuf x%px nvmeCmd x%px, " 191132350664SJames Smart "pnvme_fcreq x%px. Skipping Abort xri x%x\n", 191201649561SJames Smart lpfc_nbuf, lpfc_nbuf->nvmeCmd, 19132b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1914c2017260SJames Smart goto out_unlock; 191501649561SJames Smart } 191601649561SJames Smart 191701649561SJames Smart /* Don't abort IOs no longer on the pending queue. */ 191801649561SJames Smart if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { 191986c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 192032350664SJames Smart "6142 NVME IO req x%px not queued - skipping " 19212b7824d0SJames Smart "abort req xri x%x\n", 19222b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1923c2017260SJames Smart goto out_unlock; 192401649561SJames Smart } 192501649561SJames Smart 19264b056682SJames Smart atomic_inc(&lport->xmt_fcp_abort); 1927bd2cdd5eSJames Smart lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n", 1928bd2cdd5eSJames Smart nvmereq_wqe->sli4_xritag, 192900cefeb9SJames Smart nvmereq_wqe->hba_wqidx, pnvme_rport->port_id); 1930bd2cdd5eSJames Smart 193101649561SJames Smart /* Outstanding abort is in progress */ 193201649561SJames Smart if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) { 193386c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 193401649561SJames Smart "6144 Outstanding NVME I/O Abort Request " 193532350664SJames Smart "still pending on nvme_fcreq x%px, " 193632350664SJames Smart "lpfc_ncmd %px xri x%x\n", 19372b7824d0SJames Smart pnvme_fcreq, lpfc_nbuf, 19382b7824d0SJames Smart nvmereq_wqe->sli4_xritag); 1939c2017260SJames Smart goto out_unlock; 194001649561SJames Smart } 194101649561SJames Smart 194201649561SJames Smart abts_buf = __lpfc_sli_get_iocbq(phba); 194301649561SJames Smart if (!abts_buf) { 194486c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 194501649561SJames Smart "6136 No available abort wqes. Skipping " 194632350664SJames Smart "Abts req for nvme_fcreq x%px xri x%x\n", 19472b7824d0SJames Smart pnvme_fcreq, nvmereq_wqe->sli4_xritag); 1948c2017260SJames Smart goto out_unlock; 194901649561SJames Smart } 195001649561SJames Smart 195101649561SJames Smart /* Ready - mark outstanding as aborted by driver. */ 195201649561SJames Smart nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED; 195301649561SJames Smart 195451f8e43eSJames Smart lpfc_nvme_prep_abort_wqe(abts_buf, nvmereq_wqe->sli4_xritag, 0); 195501649561SJames Smart 195601649561SJames Smart /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 195701649561SJames Smart abts_buf->iocb_flag |= LPFC_IO_NVME; 195801649561SJames Smart abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx; 195901649561SJames Smart abts_buf->vport = vport; 196001649561SJames Smart abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; 19611fbf9742SJames Smart ret_val = lpfc_sli4_issue_wqe(phba, lpfc_nbuf->hdwq, abts_buf); 1962c2017260SJames Smart spin_unlock(&lpfc_nbuf->buf_lock); 196301649561SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1964cd22d605SDick Kennedy if (ret_val) { 196586c67379SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, 196601649561SJames Smart "6137 Failed abts issue_wqe with status x%x " 196732350664SJames Smart "for nvme_fcreq x%px.\n", 196801649561SJames Smart ret_val, pnvme_fcreq); 196901649561SJames Smart lpfc_sli_release_iocbq(phba, abts_buf); 197001649561SJames Smart return; 197101649561SJames Smart } 197201649561SJames Smart 197386c67379SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 19742b7824d0SJames Smart "6138 Transport Abort NVME Request Issued for " 197501649561SJames Smart "ox_id x%x on reqtag x%x\n", 197601649561SJames Smart nvmereq_wqe->sli4_xritag, 197701649561SJames Smart abts_buf->iotag); 1978c2017260SJames Smart return; 1979c2017260SJames Smart 1980c2017260SJames Smart out_unlock: 1981c2017260SJames Smart spin_unlock(&lpfc_nbuf->buf_lock); 1982c2017260SJames Smart spin_unlock_irqrestore(&phba->hbalock, flags); 1983c2017260SJames Smart return; 198401649561SJames Smart } 198501649561SJames Smart 198601649561SJames Smart /* Declare and initialization an instance of the FC NVME template. */ 198701649561SJames Smart static struct nvme_fc_port_template lpfc_nvme_template = { 198801649561SJames Smart /* initiator-based functions */ 198901649561SJames Smart .localport_delete = lpfc_nvme_localport_delete, 199001649561SJames Smart .remoteport_delete = lpfc_nvme_remoteport_delete, 199101649561SJames Smart .create_queue = lpfc_nvme_create_queue, 199201649561SJames Smart .delete_queue = lpfc_nvme_delete_queue, 199301649561SJames Smart .ls_req = lpfc_nvme_ls_req, 199401649561SJames Smart .fcp_io = lpfc_nvme_fcp_io_submit, 199501649561SJames Smart .ls_abort = lpfc_nvme_ls_abort, 199601649561SJames Smart .fcp_abort = lpfc_nvme_fcp_abort, 199701649561SJames Smart 199801649561SJames Smart .max_hw_queues = 1, 199901649561SJames Smart .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS, 200001649561SJames Smart .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS, 200101649561SJames Smart .dma_boundary = 0xFFFFFFFF, 200201649561SJames Smart 200301649561SJames Smart /* Sizes of additional private data for data structures. 200401649561SJames Smart * No use for the last two sizes at this time. 200501649561SJames Smart */ 200601649561SJames Smart .local_priv_sz = sizeof(struct lpfc_nvme_lport), 200701649561SJames Smart .remote_priv_sz = sizeof(struct lpfc_nvme_rport), 200801649561SJames Smart .lsrqst_priv_sz = 0, 2009bbe3012bSJames Smart .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv), 201001649561SJames Smart }; 201101649561SJames Smart 201201649561SJames Smart /** 20135e5b511dSJames Smart * lpfc_get_nvme_buf - Get a nvme buffer from io_buf_list of the HBA 201401649561SJames Smart * @phba: The HBA for which this call is being executed. 201501649561SJames Smart * 20165e5b511dSJames Smart * This routine removes a nvme buffer from head of @hdwq io_buf_list 201701649561SJames Smart * and returns to caller. 201801649561SJames Smart * 201901649561SJames Smart * Return codes: 202001649561SJames Smart * NULL - Error 202101649561SJames Smart * Pointer to lpfc_nvme_buf - Success 202201649561SJames Smart **/ 2023c490850aSJames Smart static struct lpfc_io_buf * 2024cf1a1d3eSJames Smart lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 20255e5b511dSJames Smart int idx, int expedite) 202601649561SJames Smart { 2027c490850aSJames Smart struct lpfc_io_buf *lpfc_ncmd; 20285e5b511dSJames Smart struct lpfc_sli4_hdw_queue *qp; 20290794d601SJames Smart struct sli4_sge *sgl; 20300794d601SJames Smart struct lpfc_iocbq *pwqeq; 20310794d601SJames Smart union lpfc_wqe128 *wqe; 203201649561SJames Smart 2033c490850aSJames Smart lpfc_ncmd = lpfc_get_io_buf(phba, NULL, idx, expedite); 20342a5b7d62SJames Smart 20350794d601SJames Smart if (lpfc_ncmd) { 20360794d601SJames Smart pwqeq = &(lpfc_ncmd->cur_iocbq); 20370794d601SJames Smart wqe = &pwqeq->wqe; 20380794d601SJames Smart 20390794d601SJames Smart /* Setup key fields in buffer that may have been changed 20400794d601SJames Smart * if other protocols used this buffer. 20410794d601SJames Smart */ 20420794d601SJames Smart pwqeq->iocb_flag = LPFC_IO_NVME; 20430794d601SJames Smart pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl; 20440794d601SJames Smart lpfc_ncmd->start_time = jiffies; 20450794d601SJames Smart lpfc_ncmd->flags = 0; 20460794d601SJames Smart 20470794d601SJames Smart /* Rsp SGE will be filled in when we rcv an IO 20480794d601SJames Smart * from the NVME Layer to be sent. 20490794d601SJames Smart * The cmd is going to be embedded so we need a SKIP SGE. 20500794d601SJames Smart */ 20510794d601SJames Smart sgl = lpfc_ncmd->dma_sgl; 20520794d601SJames Smart bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); 20530794d601SJames Smart bf_set(lpfc_sli4_sge_last, sgl, 0); 20540794d601SJames Smart sgl->word2 = cpu_to_le32(sgl->word2); 20550794d601SJames Smart /* Fill in word 3 / sgl_len during cmd submission */ 20560794d601SJames Smart 2057d9f492a1SJames Smart /* Initialize 64 bytes only */ 20580794d601SJames Smart memset(wqe, 0, sizeof(union lpfc_wqe)); 20590794d601SJames Smart 20600794d601SJames Smart if (lpfc_ndlp_check_qdepth(phba, ndlp)) { 20612a5b7d62SJames Smart atomic_inc(&ndlp->cmd_pending); 2062c490850aSJames Smart lpfc_ncmd->flags |= LPFC_SBUF_BUMP_QDEPTH; 20632a5b7d62SJames Smart } 20645e5b511dSJames Smart 2065c490850aSJames Smart } else { 2066c490850aSJames Smart qp = &phba->sli4_hba.hdwq[idx]; 20675e5b511dSJames Smart qp->empty_io_bufs++; 2068c490850aSJames Smart } 20695e5b511dSJames Smart 207001649561SJames Smart return lpfc_ncmd; 207101649561SJames Smart } 207201649561SJames Smart 207301649561SJames Smart /** 207401649561SJames Smart * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list. 207501649561SJames Smart * @phba: The Hba for which this call is being executed. 207601649561SJames Smart * @lpfc_ncmd: The nvme buffer which is being released. 207701649561SJames Smart * 207801649561SJames Smart * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba 20795e5b511dSJames Smart * lpfc_io_buf_list list. For SLI4 XRI's are tied to the nvme buffer 208001649561SJames Smart * and cannot be reused for at least RA_TOV amount of time if it was 208101649561SJames Smart * aborted. 208201649561SJames Smart **/ 208301649561SJames Smart static void 2084c490850aSJames Smart lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd) 208501649561SJames Smart { 20865e5b511dSJames Smart struct lpfc_sli4_hdw_queue *qp; 208701649561SJames Smart unsigned long iflag = 0; 208801649561SJames Smart 2089c490850aSJames Smart if ((lpfc_ncmd->flags & LPFC_SBUF_BUMP_QDEPTH) && lpfc_ncmd->ndlp) 20902a5b7d62SJames Smart atomic_dec(&lpfc_ncmd->ndlp->cmd_pending); 20912a5b7d62SJames Smart 20922a5b7d62SJames Smart lpfc_ncmd->ndlp = NULL; 2093c490850aSJames Smart lpfc_ncmd->flags &= ~LPFC_SBUF_BUMP_QDEPTH; 20942a5b7d62SJames Smart 20951fbf9742SJames Smart qp = lpfc_ncmd->hdwq; 209622770cbaSJames Smart if (unlikely(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) { 209786c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 209886c67379SJames Smart "6310 XB release deferred for " 209986c67379SJames Smart "ox_id x%x on reqtag x%x\n", 210086c67379SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag, 210186c67379SJames Smart lpfc_ncmd->cur_iocbq.iotag); 210286c67379SJames Smart 2103c00f62e6SJames Smart spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag); 210401649561SJames Smart list_add_tail(&lpfc_ncmd->list, 2105c00f62e6SJames Smart &qp->lpfc_abts_io_buf_list); 21065e5b511dSJames Smart qp->abts_nvme_io_bufs++; 2107c00f62e6SJames Smart spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag); 2108c490850aSJames Smart } else 2109c490850aSJames Smart lpfc_release_io_buf(phba, (struct lpfc_io_buf *)lpfc_ncmd, qp); 211001649561SJames Smart } 211101649561SJames Smart 211201649561SJames Smart /** 211301649561SJames Smart * lpfc_nvme_create_localport - Create/Bind an nvme localport instance. 211401649561SJames Smart * @pvport - the lpfc_vport instance requesting a localport. 211501649561SJames Smart * 211601649561SJames Smart * This routine is invoked to create an nvme localport instance to bind 211701649561SJames Smart * to the nvme_fc_transport. It is called once during driver load 211801649561SJames Smart * like lpfc_create_shost after all other services are initialized. 211901649561SJames Smart * It requires a vport, vpi, and wwns at call time. Other localport 212001649561SJames Smart * parameters are modified as the driver's FCID and the Fabric WWN 212101649561SJames Smart * are established. 212201649561SJames Smart * 212301649561SJames Smart * Return codes 212401649561SJames Smart * 0 - successful 212501649561SJames Smart * -ENOMEM - no heap memory available 212601649561SJames Smart * other values - from nvme registration upcall 212701649561SJames Smart **/ 212801649561SJames Smart int 212901649561SJames Smart lpfc_nvme_create_localport(struct lpfc_vport *vport) 213001649561SJames Smart { 2131166d7211SJames Smart int ret = 0; 213201649561SJames Smart struct lpfc_hba *phba = vport->phba; 213301649561SJames Smart struct nvme_fc_port_info nfcp_info; 213401649561SJames Smart struct nvme_fc_local_port *localport; 213501649561SJames Smart struct lpfc_nvme_lport *lport; 213601649561SJames Smart 213701649561SJames Smart /* Initialize this localport instance. The vport wwn usage ensures 213801649561SJames Smart * that NPIV is accounted for. 213901649561SJames Smart */ 214001649561SJames Smart memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info)); 214101649561SJames Smart nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR; 214201649561SJames Smart nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); 214301649561SJames Smart nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn); 214401649561SJames Smart 21455b9e70b2SJames Smart /* We need to tell the transport layer + 1 because it takes page 21465b9e70b2SJames Smart * alignment into account. When space for the SGL is allocated we 21475b9e70b2SJames Smart * allocate + 3, one for cmd, one for rsp and one for this alignment 21484d4c4a4aSJames Smart */ 21494d4c4a4aSJames Smart lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; 215001649561SJames Smart 2151*542ddc9bSJames Smart /* Advertise how many hw queues we support based on cfg_hdw_queue, 2152*542ddc9bSJames Smart * which will not exceed cpu count. 2153*542ddc9bSJames Smart */ 2154cdb42becSJames Smart lpfc_nvme_template.max_hw_queues = phba->cfg_hdw_queue; 215566a210ffSJames Smart 2156faf5a744SArnd Bergmann if (!IS_ENABLED(CONFIG_NVME_FC)) 2157faf5a744SArnd Bergmann return ret; 2158faf5a744SArnd Bergmann 215901649561SJames Smart /* localport is allocated from the stack, but the registration 216001649561SJames Smart * call allocates heap memory as well as the private area. 216101649561SJames Smart */ 2162faf5a744SArnd Bergmann 216301649561SJames Smart ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template, 216401649561SJames Smart &vport->phba->pcidev->dev, &localport); 216501649561SJames Smart if (!ret) { 216601649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC, 216701649561SJames Smart "6005 Successfully registered local " 216832350664SJames Smart "NVME port num %d, localP x%px, private " 216932350664SJames Smart "x%px, sg_seg %d\n", 217001649561SJames Smart localport->port_num, localport, 217101649561SJames Smart localport->private, 217201649561SJames Smart lpfc_nvme_template.max_sgl_segments); 217301649561SJames Smart 217401649561SJames Smart /* Private is our lport size declared in the template. */ 217501649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 217601649561SJames Smart vport->localport = localport; 217701649561SJames Smart lport->vport = vport; 217801649561SJames Smart vport->nvmei_support = 1; 21796b486ce9SDick Kennedy 21804b056682SJames Smart atomic_set(&lport->xmt_fcp_noxri, 0); 21814b056682SJames Smart atomic_set(&lport->xmt_fcp_bad_ndlp, 0); 21824b056682SJames Smart atomic_set(&lport->xmt_fcp_qdepth, 0); 218344c2757bSJames Smart atomic_set(&lport->xmt_fcp_err, 0); 21844b056682SJames Smart atomic_set(&lport->xmt_fcp_wqerr, 0); 21854b056682SJames Smart atomic_set(&lport->xmt_fcp_abort, 0); 21864b056682SJames Smart atomic_set(&lport->xmt_ls_abort, 0); 21874b056682SJames Smart atomic_set(&lport->xmt_ls_err, 0); 21884b056682SJames Smart atomic_set(&lport->cmpl_fcp_xb, 0); 21894b056682SJames Smart atomic_set(&lport->cmpl_fcp_err, 0); 21904b056682SJames Smart atomic_set(&lport->cmpl_ls_xb, 0); 21914b056682SJames Smart atomic_set(&lport->cmpl_ls_err, 0); 219266a210ffSJames Smart atomic_set(&lport->fc4NvmeLsRequests, 0); 219366a210ffSJames Smart atomic_set(&lport->fc4NvmeLsCmpls, 0); 21946b486ce9SDick Kennedy } 21953ebd9b47SJames Smart 219601649561SJames Smart return ret; 219701649561SJames Smart } 219801649561SJames Smart 2199d964b3e5SBart Van Assche #if (IS_ENABLED(CONFIG_NVME_FC)) 2200add9d6beSJames Smart /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg. 2201add9d6beSJames Smart * 2202add9d6beSJames Smart * The driver has to wait for the host nvme transport to callback 2203add9d6beSJames Smart * indicating the localport has successfully unregistered all 2204add9d6beSJames Smart * resources. Since this is an uninterruptible wait, loop every ten 2205add9d6beSJames Smart * seconds and print a message indicating no progress. 2206add9d6beSJames Smart * 2207add9d6beSJames Smart * An uninterruptible wait is used because of the risk of transport-to- 2208add9d6beSJames Smart * driver state mismatch. 2209add9d6beSJames Smart */ 22103999df75SBart Van Assche static void 2211add9d6beSJames Smart lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport, 22127961cba6SEwan D. Milne struct lpfc_nvme_lport *lport, 22137961cba6SEwan D. Milne struct completion *lport_unreg_cmp) 2214add9d6beSJames Smart { 2215add9d6beSJames Smart u32 wait_tmo; 22162ab70c21SJames Smart int ret, i, pending = 0; 22172ab70c21SJames Smart struct lpfc_sli_ring *pring; 22182ab70c21SJames Smart struct lpfc_hba *phba = vport->phba; 2219add9d6beSJames Smart 2220add9d6beSJames Smart /* Host transport has to clean up and confirm requiring an indefinite 2221add9d6beSJames Smart * wait. Print a message if a 10 second wait expires and renew the 2222add9d6beSJames Smart * wait. This is unexpected. 2223add9d6beSJames Smart */ 2224add9d6beSJames Smart wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000); 2225add9d6beSJames Smart while (true) { 22267961cba6SEwan D. Milne ret = wait_for_completion_timeout(lport_unreg_cmp, wait_tmo); 2227add9d6beSJames Smart if (unlikely(!ret)) { 22282ab70c21SJames Smart pending = 0; 22292ab70c21SJames Smart for (i = 0; i < phba->cfg_hdw_queue; i++) { 2230c00f62e6SJames Smart pring = phba->sli4_hba.hdwq[i].io_wq->pring; 22312ab70c21SJames Smart if (!pring) 22322ab70c21SJames Smart continue; 22332ab70c21SJames Smart if (pring->txcmplq_cnt) 22342ab70c21SJames Smart pending += pring->txcmplq_cnt; 22352ab70c21SJames Smart } 2236add9d6beSJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, 223732350664SJames Smart "6176 Lport x%px Localport x%px wait " 22382ab70c21SJames Smart "timed out. Pending %d. Renewing.\n", 22392ab70c21SJames Smart lport, vport->localport, pending); 2240add9d6beSJames Smart continue; 2241add9d6beSJames Smart } 2242add9d6beSJames Smart break; 2243add9d6beSJames Smart } 2244add9d6beSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, 224532350664SJames Smart "6177 Lport x%px Localport x%px Complete Success\n", 2246add9d6beSJames Smart lport, vport->localport); 2247add9d6beSJames Smart } 2248d964b3e5SBart Van Assche #endif 2249add9d6beSJames Smart 225001649561SJames Smart /** 225101649561SJames Smart * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport. 225201649561SJames Smart * @pnvme: pointer to lpfc nvme data structure. 225301649561SJames Smart * 225401649561SJames Smart * This routine is invoked to destroy all lports bound to the phba. 225501649561SJames Smart * The lport memory was allocated by the nvme fc transport and is 225601649561SJames Smart * released there. This routine ensures all rports bound to the 225701649561SJames Smart * lport have been disconnected. 225801649561SJames Smart * 225901649561SJames Smart **/ 226001649561SJames Smart void 226101649561SJames Smart lpfc_nvme_destroy_localport(struct lpfc_vport *vport) 226201649561SJames Smart { 22637d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 226401649561SJames Smart struct nvme_fc_local_port *localport; 226501649561SJames Smart struct lpfc_nvme_lport *lport; 226601649561SJames Smart int ret; 22677961cba6SEwan D. Milne DECLARE_COMPLETION_ONSTACK(lport_unreg_cmp); 226801649561SJames Smart 226901649561SJames Smart if (vport->nvmei_support == 0) 227001649561SJames Smart return; 227101649561SJames Smart 227201649561SJames Smart localport = vport->localport; 227301649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 227401649561SJames Smart 227501649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 227632350664SJames Smart "6011 Destroying NVME localport x%px\n", 227701649561SJames Smart localport); 2278166d7211SJames Smart 227901649561SJames Smart /* lport's rport list is clear. Unregister 228001649561SJames Smart * lport and release resources. 228101649561SJames Smart */ 22827961cba6SEwan D. Milne lport->lport_unreg_cmp = &lport_unreg_cmp; 228301649561SJames Smart ret = nvme_fc_unregister_localport(localport); 2284add9d6beSJames Smart 2285add9d6beSJames Smart /* Wait for completion. This either blocks 2286add9d6beSJames Smart * indefinitely or succeeds 2287add9d6beSJames Smart */ 22887961cba6SEwan D. Milne lpfc_nvme_lport_unreg_wait(vport, lport, &lport_unreg_cmp); 22897961cba6SEwan D. Milne vport->localport = NULL; 229001649561SJames Smart 229101649561SJames Smart /* Regardless of the unregister upcall response, clear 229201649561SJames Smart * nvmei_support. All rports are unregistered and the 229301649561SJames Smart * driver will clean up. 229401649561SJames Smart */ 229501649561SJames Smart vport->nvmei_support = 0; 229601649561SJames Smart if (ret == 0) { 229701649561SJames Smart lpfc_printf_vlog(vport, 229801649561SJames Smart KERN_INFO, LOG_NVME_DISC, 229901649561SJames Smart "6009 Unregistered lport Success\n"); 230001649561SJames Smart } else { 230101649561SJames Smart lpfc_printf_vlog(vport, 230201649561SJames Smart KERN_INFO, LOG_NVME_DISC, 230301649561SJames Smart "6010 Unregistered lport " 230401649561SJames Smart "Failed, status x%x\n", 230501649561SJames Smart ret); 230601649561SJames Smart } 2307166d7211SJames Smart #endif 230801649561SJames Smart } 230901649561SJames Smart 231001649561SJames Smart void 231101649561SJames Smart lpfc_nvme_update_localport(struct lpfc_vport *vport) 231201649561SJames Smart { 23134410a67aSJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 231401649561SJames Smart struct nvme_fc_local_port *localport; 231501649561SJames Smart struct lpfc_nvme_lport *lport; 231601649561SJames Smart 231701649561SJames Smart localport = vport->localport; 23184410a67aSJames Smart if (!localport) { 23194410a67aSJames Smart lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME, 23204410a67aSJames Smart "6710 Update NVME fail. No localport\n"); 23214410a67aSJames Smart return; 23224410a67aSJames Smart } 232301649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 23244410a67aSJames Smart if (!lport) { 23254410a67aSJames Smart lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME, 232632350664SJames Smart "6171 Update NVME fail. localP x%px, No lport\n", 23274410a67aSJames Smart localport); 23284410a67aSJames Smart return; 23294410a67aSJames Smart } 233001649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 233132350664SJames Smart "6012 Update NVME lport x%px did x%x\n", 233201649561SJames Smart localport, vport->fc_myDID); 233301649561SJames Smart 233401649561SJames Smart localport->port_id = vport->fc_myDID; 233501649561SJames Smart if (localport->port_id == 0) 233601649561SJames Smart localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY; 233701649561SJames Smart else 233801649561SJames Smart localport->port_role = FC_PORT_ROLE_NVME_INITIATOR; 233901649561SJames Smart 234001649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 234132350664SJames Smart "6030 bound lport x%px to DID x%06x\n", 234201649561SJames Smart lport, localport->port_id); 23434410a67aSJames Smart #endif 234401649561SJames Smart } 234501649561SJames Smart 234601649561SJames Smart int 234701649561SJames Smart lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 234801649561SJames Smart { 23497d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 235001649561SJames Smart int ret = 0; 235101649561SJames Smart struct nvme_fc_local_port *localport; 235201649561SJames Smart struct lpfc_nvme_lport *lport; 235301649561SJames Smart struct lpfc_nvme_rport *rport; 235401466024SJames Smart struct lpfc_nvme_rport *oldrport; 235501649561SJames Smart struct nvme_fc_remote_port *remote_port; 235601649561SJames Smart struct nvme_fc_port_info rpinfo; 235793a3922dSJames Smart struct lpfc_nodelist *prev_ndlp = NULL; 235801649561SJames Smart 235901649561SJames Smart lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC, 236001649561SJames Smart "6006 Register NVME PORT. DID x%06x nlptype x%x\n", 236101649561SJames Smart ndlp->nlp_DID, ndlp->nlp_type); 236201649561SJames Smart 236301649561SJames Smart localport = vport->localport; 2364bb6a8a2cSDick Kennedy if (!localport) 2365bb6a8a2cSDick Kennedy return 0; 2366bb6a8a2cSDick Kennedy 236701649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 236801649561SJames Smart 23697a06dcd3SJames Smart /* NVME rports are not preserved across devloss. 23707a06dcd3SJames Smart * Just register this instance. Note, rpinfo->dev_loss_tmo 23717a06dcd3SJames Smart * is left 0 to indicate accept transport defaults. The 23727a06dcd3SJames Smart * driver communicates port role capabilities consistent 23737a06dcd3SJames Smart * with the PRLI response data. 237401649561SJames Smart */ 23757a06dcd3SJames Smart memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info)); 23767a06dcd3SJames Smart rpinfo.port_id = ndlp->nlp_DID; 237701649561SJames Smart if (ndlp->nlp_type & NLP_NVME_TARGET) 23787a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET; 237901649561SJames Smart if (ndlp->nlp_type & NLP_NVME_INITIATOR) 23807a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR; 238101649561SJames Smart 23827a06dcd3SJames Smart if (ndlp->nlp_type & NLP_NVME_DISCOVERY) 23837a06dcd3SJames Smart rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY; 23847a06dcd3SJames Smart 23857a06dcd3SJames Smart rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); 23867a06dcd3SJames Smart rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); 238701466024SJames Smart 23889e210178SJames Smart spin_lock_irq(&vport->phba->hbalock); 238901466024SJames Smart oldrport = lpfc_ndlp_get_nrport(ndlp); 239061184f17SJames Smart if (oldrport) { 239161184f17SJames Smart prev_ndlp = oldrport->ndlp; 23929e210178SJames Smart spin_unlock_irq(&vport->phba->hbalock); 239361184f17SJames Smart } else { 239461184f17SJames Smart spin_unlock_irq(&vport->phba->hbalock); 23953fd78355SJames Smart lpfc_nlp_get(ndlp); 239661184f17SJames Smart } 23973fd78355SJames Smart 23987a06dcd3SJames Smart ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port); 23997a06dcd3SJames Smart if (!ret) { 24007a06dcd3SJames Smart /* If the ndlp already has an nrport, this is just 24017a06dcd3SJames Smart * a resume of the existing rport. Else this is a 24027a06dcd3SJames Smart * new rport. 24037a06dcd3SJames Smart */ 2404b15bd3e6SJames Smart /* Guard against an unregister/reregister 2405b15bd3e6SJames Smart * race that leaves the WAIT flag set. 2406b15bd3e6SJames Smart */ 2407b15bd3e6SJames Smart spin_lock_irq(&vport->phba->hbalock); 2408b15bd3e6SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 2409b15bd3e6SJames Smart spin_unlock_irq(&vport->phba->hbalock); 24107a06dcd3SJames Smart rport = remote_port->private; 241101466024SJames Smart if (oldrport) { 241293a3922dSJames Smart /* New remoteport record does not guarantee valid 241393a3922dSJames Smart * host private memory area. 241493a3922dSJames Smart */ 241501466024SJames Smart if (oldrport == remote_port->private) { 241693a3922dSJames Smart /* Same remoteport - ndlp should match. 241793a3922dSJames Smart * Just reuse. 241893a3922dSJames Smart */ 241901649561SJames Smart lpfc_printf_vlog(ndlp->vport, KERN_INFO, 242001649561SJames Smart LOG_NVME_DISC, 24216825b7bdSJames Smart "6014 Rebind lport to current " 242232350664SJames Smart "remoteport x%px wwpn 0x%llx, " 242332350664SJames Smart "Data: x%x x%x x%px x%px x%x " 242432350664SJames Smart " x%06x\n", 24253fd78355SJames Smart remote_port, 242601649561SJames Smart remote_port->port_name, 242701649561SJames Smart remote_port->port_id, 242801649561SJames Smart remote_port->port_role, 242961184f17SJames Smart oldrport->ndlp, 24303fd78355SJames Smart ndlp, 243101649561SJames Smart ndlp->nlp_type, 243201649561SJames Smart ndlp->nlp_DID); 24336825b7bdSJames Smart 24346825b7bdSJames Smart /* It's a complete rebind only if the driver 24356825b7bdSJames Smart * is registering with the same ndlp. Otherwise 24366825b7bdSJames Smart * the driver likely executed a node swap 24376825b7bdSJames Smart * prior to this registration and the ndlp to 24386825b7bdSJames Smart * remoteport binding needs to be redone. 24396825b7bdSJames Smart */ 24406825b7bdSJames Smart if (prev_ndlp == ndlp) 24413fd78355SJames Smart return 0; 24426825b7bdSJames Smart 24433fd78355SJames Smart } 24442b75d0f9SDick Kennedy 24453fd78355SJames Smart /* Sever the ndlp<->rport association 24463fd78355SJames Smart * before dropping the ndlp ref from 24473fd78355SJames Smart * register. 24482b75d0f9SDick Kennedy */ 24493fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 24502b75d0f9SDick Kennedy ndlp->nrport = NULL; 245101466024SJames Smart ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG; 24523fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 24532b75d0f9SDick Kennedy rport->ndlp = NULL; 24543fd78355SJames Smart rport->remoteport = NULL; 2455b04744ceSJames Smart 2456b04744ceSJames Smart /* Reference only removed if previous NDLP is no longer 2457b04744ceSJames Smart * active. It might be just a swap and removing the 2458b04744ceSJames Smart * reference would cause a premature cleanup. 2459b04744ceSJames Smart */ 2460b04744ceSJames Smart if (prev_ndlp && prev_ndlp != ndlp) { 2461b04744ceSJames Smart if ((!NLP_CHK_NODE_ACT(prev_ndlp)) || 2462b04744ceSJames Smart (!prev_ndlp->nrport)) 2463b04744ceSJames Smart lpfc_nlp_put(prev_ndlp); 2464b04744ceSJames Smart } 24652b75d0f9SDick Kennedy } 24662b75d0f9SDick Kennedy 24672b75d0f9SDick Kennedy /* Clean bind the rport to the ndlp. */ 246801649561SJames Smart rport->remoteport = remote_port; 246901649561SJames Smart rport->lport = lport; 24703fd78355SJames Smart rport->ndlp = ndlp; 24713fd78355SJames Smart spin_lock_irq(&vport->phba->hbalock); 247201649561SJames Smart ndlp->nrport = rport; 24733fd78355SJames Smart spin_unlock_irq(&vport->phba->hbalock); 247401649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, 247501649561SJames Smart LOG_NVME_DISC | LOG_NODE, 24766825b7bdSJames Smart "6022 Bind lport x%px to remoteport x%px " 24776825b7bdSJames Smart "rport x%px WWNN 0x%llx, " 24787a06dcd3SJames Smart "Rport WWPN 0x%llx DID " 247932350664SJames Smart "x%06x Role x%x, ndlp %p prev_ndlp x%px\n", 248093a3922dSJames Smart lport, remote_port, rport, 248101649561SJames Smart rpinfo.node_name, rpinfo.port_name, 24823fd78355SJames Smart rpinfo.port_id, rpinfo.port_role, 248393a3922dSJames Smart ndlp, prev_ndlp); 248401649561SJames Smart } else { 248501649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, 248601649561SJames Smart LOG_NVME_DISC | LOG_NODE, 248701649561SJames Smart "6031 RemotePort Registration failed " 248801649561SJames Smart "err: %d, DID x%06x\n", 248901649561SJames Smart ret, ndlp->nlp_DID); 249001649561SJames Smart } 24917a06dcd3SJames Smart 249201649561SJames Smart return ret; 2493166d7211SJames Smart #else 2494166d7211SJames Smart return 0; 2495166d7211SJames Smart #endif 249601649561SJames Smart } 249701649561SJames Smart 24986f2589f4SJames Smart /** 24996f2589f4SJames Smart * lpfc_nvme_rescan_port - Check to see if we should rescan this remoteport 25006f2589f4SJames Smart * 25016f2589f4SJames Smart * If the ndlp represents an NVME Target, that we are logged into, 25026f2589f4SJames Smart * ping the NVME FC Transport layer to initiate a device rescan 25036f2589f4SJames Smart * on this remote NPort. 25046f2589f4SJames Smart */ 25056f2589f4SJames Smart void 25066f2589f4SJames Smart lpfc_nvme_rescan_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 25076f2589f4SJames Smart { 25086f2589f4SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 2509a6d10f24SJames Smart struct lpfc_nvme_rport *nrport; 2510a6d10f24SJames Smart struct nvme_fc_remote_port *remoteport = NULL; 25116f2589f4SJames Smart 2512a6d10f24SJames Smart spin_lock_irq(&vport->phba->hbalock); 2513a6d10f24SJames Smart nrport = lpfc_ndlp_get_nrport(ndlp); 2514a6d10f24SJames Smart if (nrport) 2515a6d10f24SJames Smart remoteport = nrport->remoteport; 2516a6d10f24SJames Smart spin_unlock_irq(&vport->phba->hbalock); 25176f2589f4SJames Smart 25186f2589f4SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 25196f2589f4SJames Smart "6170 Rescan NPort DID x%06x type x%x " 2520a6d10f24SJames Smart "state x%x nrport x%px remoteport x%px\n", 2521a6d10f24SJames Smart ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_state, 2522a6d10f24SJames Smart nrport, remoteport); 2523a6d10f24SJames Smart 2524a6d10f24SJames Smart if (!nrport || !remoteport) 2525a6d10f24SJames Smart goto rescan_exit; 25266f2589f4SJames Smart 25276f2589f4SJames Smart /* Only rescan if we are an NVME target in the MAPPED state */ 25286f2589f4SJames Smart if (remoteport->port_role & FC_PORT_ROLE_NVME_DISCOVERY && 25296f2589f4SJames Smart ndlp->nlp_state == NLP_STE_MAPPED_NODE) { 25306f2589f4SJames Smart nvme_fc_rescan_remoteport(remoteport); 25316f2589f4SJames Smart 25326f2589f4SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 25336f2589f4SJames Smart "6172 NVME rescanned DID x%06x " 25346f2589f4SJames Smart "port_state x%x\n", 25356f2589f4SJames Smart ndlp->nlp_DID, remoteport->port_state); 25366f2589f4SJames Smart } 25376f2589f4SJames Smart return; 2538a6d10f24SJames Smart rescan_exit: 2539a6d10f24SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 2540a6d10f24SJames Smart "6169 Skip NVME Rport Rescan, NVME remoteport " 2541a6d10f24SJames Smart "unregistered\n"); 25426f2589f4SJames Smart #endif 25436f2589f4SJames Smart } 25446f2589f4SJames Smart 254501649561SJames Smart /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport. 254601649561SJames Smart * 254701649561SJames Smart * There is no notion of Devloss or rport recovery from the current 254801649561SJames Smart * nvme_transport perspective. Loss of an rport just means IO cannot 254901649561SJames Smart * be sent and recovery is completely up to the initator. 255001649561SJames Smart * For now, the driver just unbinds the DID and port_role so that 255101649561SJames Smart * no further IO can be issued. Changes are planned for later. 255201649561SJames Smart * 255301649561SJames Smart * Notes - the ndlp reference count is not decremented here since 255401649561SJames Smart * since there is no nvme_transport api for devloss. Node ref count 255501649561SJames Smart * is only adjusted in driver unload. 255601649561SJames Smart */ 255701649561SJames Smart void 255801649561SJames Smart lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 255901649561SJames Smart { 25607d708033SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 256101649561SJames Smart int ret; 256201649561SJames Smart struct nvme_fc_local_port *localport; 256301649561SJames Smart struct lpfc_nvme_lport *lport; 256401649561SJames Smart struct lpfc_nvme_rport *rport; 25659e210178SJames Smart struct nvme_fc_remote_port *remoteport = NULL; 256601649561SJames Smart 256701649561SJames Smart localport = vport->localport; 256801649561SJames Smart 256901649561SJames Smart /* This is fundamental error. The localport is always 257001649561SJames Smart * available until driver unload. Just exit. 257101649561SJames Smart */ 257201649561SJames Smart if (!localport) 257301649561SJames Smart return; 257401649561SJames Smart 257501649561SJames Smart lport = (struct lpfc_nvme_lport *)localport->private; 257601649561SJames Smart if (!lport) 257701649561SJames Smart goto input_err; 257801649561SJames Smart 25799e210178SJames Smart spin_lock_irq(&vport->phba->hbalock); 258001466024SJames Smart rport = lpfc_ndlp_get_nrport(ndlp); 25819e210178SJames Smart if (rport) 25829e210178SJames Smart remoteport = rport->remoteport; 25839e210178SJames Smart spin_unlock_irq(&vport->phba->hbalock); 25849e210178SJames Smart if (!remoteport) 258501649561SJames Smart goto input_err; 258601649561SJames Smart 258701649561SJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 258832350664SJames Smart "6033 Unreg nvme remoteport x%px, portname x%llx, " 258901649561SJames Smart "port_id x%06x, portstate x%x port type x%x\n", 259001649561SJames Smart remoteport, remoteport->port_name, 259101649561SJames Smart remoteport->port_id, remoteport->port_state, 259201649561SJames Smart ndlp->nlp_type); 259301649561SJames Smart 259401649561SJames Smart /* Sanity check ndlp type. Only call for NVME ports. Don't 259501649561SJames Smart * clear any rport state until the transport calls back. 259601649561SJames Smart */ 25973b5bde69SJames Smart 25983b5bde69SJames Smart if (ndlp->nlp_type & NLP_NVME_TARGET) { 25997a06dcd3SJames Smart /* No concern about the role change on the nvme remoteport. 26007a06dcd3SJames Smart * The transport will update it. 26017a06dcd3SJames Smart */ 2602add9d6beSJames Smart ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG; 26037438273fSJames Smart 26047438273fSJames Smart /* Don't let the host nvme transport keep sending keep-alives 26057438273fSJames Smart * on this remoteport. Vport is unloading, no recovery. The 26067438273fSJames Smart * return values is ignored. The upcall is a courtesy to the 26077438273fSJames Smart * transport. 26087438273fSJames Smart */ 26097438273fSJames Smart if (vport->load_flag & FC_UNLOADING) 26107438273fSJames Smart (void)nvme_fc_set_remoteport_devloss(remoteport, 0); 26117438273fSJames Smart 261201649561SJames Smart ret = nvme_fc_unregister_remoteport(remoteport); 26133fd78355SJames Smart if (ret != 0) { 26143fd78355SJames Smart lpfc_nlp_put(ndlp); 261501649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 261601649561SJames Smart "6167 NVME unregister failed %d " 261701649561SJames Smart "port_state x%x\n", 261801649561SJames Smart ret, remoteport->port_state); 26193fd78355SJames Smart } 262001649561SJames Smart } 262101649561SJames Smart return; 262201649561SJames Smart 262301649561SJames Smart input_err: 2624166d7211SJames Smart #endif 262501649561SJames Smart lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 262632350664SJames Smart "6168 State error: lport x%px, rport x%px FCID x%06x\n", 262701649561SJames Smart vport->localport, ndlp->rport, ndlp->nlp_DID); 262801649561SJames Smart } 2629318083adSJames Smart 2630318083adSJames Smart /** 2631318083adSJames Smart * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort 2632318083adSJames Smart * @phba: pointer to lpfc hba data structure. 2633318083adSJames Smart * @axri: pointer to the fcp xri abort wcqe structure. 2634c00f62e6SJames Smart * @lpfc_ncmd: The nvme job structure for the request being aborted. 2635318083adSJames Smart * 2636318083adSJames Smart * This routine is invoked by the worker thread to process a SLI4 fast-path 2637952c303bSDick Kennedy * NVME aborted xri. Aborted NVME IO commands are completed to the transport 2638952c303bSDick Kennedy * here. 2639318083adSJames Smart **/ 2640318083adSJames Smart void 2641318083adSJames Smart lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba, 2642c00f62e6SJames Smart struct sli4_wcqe_xri_aborted *axri, 2643c00f62e6SJames Smart struct lpfc_io_buf *lpfc_ncmd) 2644318083adSJames Smart { 2645318083adSJames Smart uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 2646952c303bSDick Kennedy struct nvmefc_fcp_req *nvme_cmd = NULL; 2647c00f62e6SJames Smart struct lpfc_nodelist *ndlp = lpfc_ncmd->ndlp; 2648318083adSJames Smart 2649318083adSJames Smart 2650952c303bSDick Kennedy if (ndlp) 2651318083adSJames Smart lpfc_sli4_abts_err_handler(phba, ndlp, axri); 265286c67379SJames Smart 265386c67379SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 2654c00f62e6SJames Smart "6311 nvme_cmd %p xri x%x tag x%x abort complete and " 2655c00f62e6SJames Smart "xri released\n", 2656952c303bSDick Kennedy lpfc_ncmd->nvmeCmd, xri, 2657952c303bSDick Kennedy lpfc_ncmd->cur_iocbq.iotag); 265886c67379SJames Smart 2659952c303bSDick Kennedy /* Aborted NVME commands are required to not complete 2660952c303bSDick Kennedy * before the abort exchange command fully completes. 2661952c303bSDick Kennedy * Once completed, it is available via the put list. 2662952c303bSDick Kennedy */ 26633fd78355SJames Smart if (lpfc_ncmd->nvmeCmd) { 2664952c303bSDick Kennedy nvme_cmd = lpfc_ncmd->nvmeCmd; 2665952c303bSDick Kennedy nvme_cmd->done(nvme_cmd); 26663fd78355SJames Smart lpfc_ncmd->nvmeCmd = NULL; 26673fd78355SJames Smart } 2668318083adSJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 2669318083adSJames Smart } 2670c3725bdcSJames Smart 2671c3725bdcSJames Smart /** 2672c3725bdcSJames Smart * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete 2673c3725bdcSJames Smart * @phba: Pointer to HBA context object. 2674c3725bdcSJames Smart * 2675c3725bdcSJames Smart * This function flushes all wqes in the nvme rings and frees all resources 2676c3725bdcSJames Smart * in the txcmplq. This function does not issue abort wqes for the IO 2677c3725bdcSJames Smart * commands in txcmplq, they will just be returned with 2678c3725bdcSJames Smart * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI 2679c3725bdcSJames Smart * slot has been permanently disabled. 2680c3725bdcSJames Smart **/ 2681c3725bdcSJames Smart void 2682c3725bdcSJames Smart lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba) 2683c3725bdcSJames Smart { 2684c3725bdcSJames Smart struct lpfc_sli_ring *pring; 2685c3725bdcSJames Smart u32 i, wait_cnt = 0; 2686c3725bdcSJames Smart 2687cdb42becSJames Smart if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.hdwq) 2688c3725bdcSJames Smart return; 2689c3725bdcSJames Smart 2690c00f62e6SJames Smart /* Cycle through all IO rings and make sure all outstanding 2691c3725bdcSJames Smart * WQEs have been removed from the txcmplqs. 2692c3725bdcSJames Smart */ 2693cdb42becSJames Smart for (i = 0; i < phba->cfg_hdw_queue; i++) { 2694c00f62e6SJames Smart if (!phba->sli4_hba.hdwq[i].io_wq) 26956a828b0fSJames Smart continue; 2696c00f62e6SJames Smart pring = phba->sli4_hba.hdwq[i].io_wq->pring; 2697c3725bdcSJames Smart 2698d580c613SJames Smart if (!pring) 2699d580c613SJames Smart continue; 2700d580c613SJames Smart 2701c3725bdcSJames Smart /* Retrieve everything on the txcmplq */ 2702c3725bdcSJames Smart while (!list_empty(&pring->txcmplq)) { 2703c3725bdcSJames Smart msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); 2704c3725bdcSJames Smart wait_cnt++; 2705c3725bdcSJames Smart 2706c3725bdcSJames Smart /* The sleep is 10mS. Every ten seconds, 2707c3725bdcSJames Smart * dump a message. Something is wrong. 2708c3725bdcSJames Smart */ 2709c3725bdcSJames Smart if ((wait_cnt % 1000) == 0) { 2710c3725bdcSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 2711c3725bdcSJames Smart "6178 NVME IO not empty, " 2712c3725bdcSJames Smart "cnt %d\n", wait_cnt); 2713c3725bdcSJames Smart } 2714c3725bdcSJames Smart } 2715c3725bdcSJames Smart } 2716c3725bdcSJames Smart } 271784f2ddf8SJames Smart 271884f2ddf8SJames Smart void 271984f2ddf8SJames Smart lpfc_nvme_cancel_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn) 272084f2ddf8SJames Smart { 272184f2ddf8SJames Smart #if (IS_ENABLED(CONFIG_NVME_FC)) 272284f2ddf8SJames Smart struct lpfc_io_buf *lpfc_ncmd; 272384f2ddf8SJames Smart struct nvmefc_fcp_req *nCmd; 272484f2ddf8SJames Smart struct lpfc_nvme_fcpreq_priv *freqpriv; 272584f2ddf8SJames Smart 272684f2ddf8SJames Smart if (!pwqeIn->context1) { 272784f2ddf8SJames Smart lpfc_sli_release_iocbq(phba, pwqeIn); 272884f2ddf8SJames Smart return; 272984f2ddf8SJames Smart } 273084f2ddf8SJames Smart /* For abort iocb just return, IO iocb will do a done call */ 273184f2ddf8SJames Smart if (bf_get(wqe_cmnd, &pwqeIn->wqe.gen_req.wqe_com) == 273284f2ddf8SJames Smart CMD_ABORT_XRI_CX) { 273384f2ddf8SJames Smart lpfc_sli_release_iocbq(phba, pwqeIn); 273484f2ddf8SJames Smart return; 273584f2ddf8SJames Smart } 273684f2ddf8SJames Smart lpfc_ncmd = (struct lpfc_io_buf *)pwqeIn->context1; 273784f2ddf8SJames Smart 273884f2ddf8SJames Smart spin_lock(&lpfc_ncmd->buf_lock); 273984f2ddf8SJames Smart if (!lpfc_ncmd->nvmeCmd) { 274084f2ddf8SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 274184f2ddf8SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 274284f2ddf8SJames Smart return; 274384f2ddf8SJames Smart } 274484f2ddf8SJames Smart 274584f2ddf8SJames Smart nCmd = lpfc_ncmd->nvmeCmd; 274684f2ddf8SJames Smart lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR, 274784f2ddf8SJames Smart "6194 NVME Cancel xri %x\n", 274884f2ddf8SJames Smart lpfc_ncmd->cur_iocbq.sli4_xritag); 274984f2ddf8SJames Smart 275084f2ddf8SJames Smart nCmd->transferred_length = 0; 275184f2ddf8SJames Smart nCmd->rcv_rsplen = 0; 275284f2ddf8SJames Smart nCmd->status = NVME_SC_INTERNAL; 275384f2ddf8SJames Smart freqpriv = nCmd->private; 275484f2ddf8SJames Smart freqpriv->nvme_buf = NULL; 275584f2ddf8SJames Smart lpfc_ncmd->nvmeCmd = NULL; 275684f2ddf8SJames Smart 275784f2ddf8SJames Smart spin_unlock(&lpfc_ncmd->buf_lock); 275884f2ddf8SJames Smart nCmd->done(nCmd); 275984f2ddf8SJames Smart 276084f2ddf8SJames Smart /* Call release with XB=1 to queue the IO into the abort list. */ 276184f2ddf8SJames Smart lpfc_release_nvme_buf(phba, lpfc_ncmd); 276284f2ddf8SJames Smart #endif 276384f2ddf8SJames Smart } 2764