| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 145e5a8 | 2020-01-27 16:23:12 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term * |
James Smart | 4ae2ebd | 2018-06-26 08:24:31 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 23 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_transport_fc.h> |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 33 | #include <uapi/scsi/fc/fc_fs.h> |
| 34 | #include <uapi/scsi/fc/fc_els.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_logmsg.h" |
| 45 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 46 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 47 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | |
| 49 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 50 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 52 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 53 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 54 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 55 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 56 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 57 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 58 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | static int lpfc_max_els_tries = 3; |
| 60 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 62 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 63 | * @vport: pointer to a host virtual N_Port data structure. |
| 64 | * |
| 65 | * This routine checks whether there is an outstanding host link |
| 66 | * attention event during the discovery process with the @vport. It is done |
| 67 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 68 | * link attention events during this @vport's discovery process, the @vport |
| 69 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 70 | * be issued if the link state is not already in host link cleared state, |
| 71 | * and a return code shall indicate whether the host link attention event |
| 72 | * had happened. |
| 73 | * |
| 74 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 75 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 76 | * event will be ignored and a return code shall indicate no host link |
| 77 | * attention event had happened. |
| 78 | * |
| 79 | * Return codes |
| 80 | * 0 - no host link attention event happened |
| 81 | * 1 - host link attention event happened |
| 82 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 83 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 84 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 87 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 90 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 91 | phba->link_state == LPFC_LINK_DOWN || |
| 92 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | return 0; |
| 94 | |
| 95 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 96 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 97 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 98 | |
| 99 | if (!(ha_copy & HA_LATT)) |
| 100 | return 0; |
| 101 | |
| 102 | /* Pending Link Event during Discovery */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 103 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 104 | "0237 Pending Link Event during " |
| 105 | "Discovery: State x%x\n", |
| 106 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | |
| 108 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 109 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | * LATT processing should call lpfc_linkdown() which |
| 111 | * will cleanup any left over in-progress discovery |
| 112 | * events. |
| 113 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 114 | spin_lock_irq(shost->host_lock); |
| 115 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 116 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 118 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 119 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 121 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | } |
| 123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 125 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 126 | * @vport: pointer to a host virtual N_Port data structure. |
| 127 | * @expectRsp: flag indicating whether response is expected. |
| 128 | * @cmdSize: size of the ELS command. |
| 129 | * @retry: number of retries to the command IOCB when it fails. |
| 130 | * @ndlp: pointer to a node-list data structure. |
| 131 | * @did: destination identifier. |
| 132 | * @elscmd: the ELS command code. |
| 133 | * |
| 134 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 135 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 136 | * passed into the routine for discovery state machine to issue an Extended |
| 137 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 138 | * and preparation routine that is used by all the discovery state machine |
| 139 | * routines and the ELS command-specific fields will be later set up by |
| 140 | * the individual discovery machine routines after calling this routine |
| 141 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 142 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 143 | * payload and response payload (if expected). The reference count on the |
| 144 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 145 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 146 | * reference for the command's callback function to access later. |
| 147 | * |
| 148 | * Return code |
| 149 | * Pointer to the newly allocated/prepared els iocb data structure |
| 150 | * NULL - when els iocb data structure allocation/preparation failed |
| 151 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 152 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 154 | uint16_t cmdSize, uint8_t retry, |
| 155 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 156 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 158 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 159 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 161 | struct ulp_bde64 *bpl; |
| 162 | IOCB_t *icmd; |
| 163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 165 | if (!lpfc_is_link_up(phba)) |
| 166 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 169 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 170 | |
| 171 | if (elsiocb == NULL) |
| 172 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 173 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 174 | /* |
| 175 | * If this command is for fabric controller and HBA running |
| 176 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 177 | */ |
| 178 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 179 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 180 | ((elscmd == ELS_CMD_FLOGI) || |
| 181 | (elscmd == ELS_CMD_FDISC) || |
| 182 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 183 | switch (elscmd) { |
| 184 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 185 | elsiocb->iocb_flag |= |
| 186 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 187 | & LPFC_FIP_ELS_ID_MASK); |
| 188 | break; |
| 189 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 190 | elsiocb->iocb_flag |= |
| 191 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 192 | & LPFC_FIP_ELS_ID_MASK); |
| 193 | break; |
| 194 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 195 | elsiocb->iocb_flag |= |
| 196 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 197 | & LPFC_FIP_ELS_ID_MASK); |
| 198 | break; |
| 199 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 200 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 201 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | icmd = &elsiocb->iocb; |
| 204 | |
| 205 | /* fill in BDEs for command */ |
| 206 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 207 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 208 | if (pcmd) |
| 209 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 210 | if (!pcmd || !pcmd->virt) |
| 211 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | |
| 213 | INIT_LIST_HEAD(&pcmd->list); |
| 214 | |
| 215 | /* Allocate buffer for response payload */ |
| 216 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 217 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | if (prsp) |
| 219 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 220 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 221 | if (!prsp || !prsp->virt) |
| 222 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 224 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | |
| 227 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 228 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 230 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 231 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 232 | if (!pbuflist || !pbuflist->virt) |
| 233 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | |
| 235 | INIT_LIST_HEAD(&pbuflist->list); |
| 236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (expectRsp) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 239 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 240 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 241 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 242 | |
| 243 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 245 | if (elscmd == ELS_CMD_FLOGI) |
| 246 | icmd->ulpTimeout = FF_DEF_RATOV * 2; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 247 | else if (elscmd == ELS_CMD_LOGO) |
| 248 | icmd->ulpTimeout = phba->fc_ratov; |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 249 | else |
| 250 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | } else { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 252 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 253 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 254 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 255 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| 256 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 257 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 258 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 259 | icmd->ulpBdeCount = 1; |
| 260 | icmd->ulpLe = 1; |
| 261 | icmd->ulpClass = CLASS3; |
| 262 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 263 | /* |
| 264 | * If we have NPIV enabled, we want to send ELS traffic by VPI. |
| 265 | * For SLI4, since the driver controls VPIs we also want to include |
| 266 | * all ELS pt2pt protocol traffic as well. |
| 267 | */ |
| 268 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || |
| 269 | ((phba->sli_rev == LPFC_SLI_REV4) && |
| 270 | (vport->fc_flag & FC_PT2PT))) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 271 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 272 | if (expectRsp) { |
| 273 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 274 | |
| 275 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 276 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; |
| 277 | } |
| 278 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 279 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 280 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 281 | if (elscmd == ELS_CMD_ECHO) |
| 282 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 283 | else |
| 284 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 288 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 289 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 290 | bpl->tus.f.bdeSize = cmdSize; |
| 291 | bpl->tus.f.bdeFlags = 0; |
| 292 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 293 | |
| 294 | if (expectRsp) { |
| 295 | bpl++; |
| 296 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 297 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 298 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 299 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 300 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 301 | } |
| 302 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 303 | elsiocb->context2 = pcmd; |
| 304 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 306 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 308 | |
| 309 | if (prsp) { |
| 310 | list_add(&prsp->list, &pcmd->list); |
| 311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 312 | if (expectRsp) { |
| 313 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 314 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 315 | "0116 Xmit ELS command x%x to remote " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 316 | "NPORT x%x I/O tag: x%x, port state:x%x " |
| 317 | "rpi x%x fc_flag:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 318 | elscmd, did, elsiocb->iotag, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 319 | vport->port_state, ndlp->nlp_rpi, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 320 | vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | } else { |
| 322 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 324 | "0117 Xmit ELS response x%x to remote " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 325 | "NPORT x%x I/O tag: x%x, size: x%x " |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 326 | "port_state x%x rpi x%x fc_flag x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 327 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 328 | cmdSize, vport->port_state, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 329 | ndlp->nlp_rpi, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 331 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 332 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 333 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 334 | if (expectRsp) |
| 335 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 336 | kfree(pbuflist); |
| 337 | |
| 338 | els_iocb_free_prsp_exit: |
| 339 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 340 | kfree(prsp); |
| 341 | |
| 342 | els_iocb_free_pcmb_exit: |
| 343 | kfree(pcmd); |
| 344 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 345 | return NULL; |
| 346 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 349 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 350 | * @vport: pointer to a host virtual N_Port data structure. |
| 351 | * |
| 352 | * This routine issues a fabric registration login for a @vport. An |
| 353 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 354 | * The routine invokes two mailbox commands to carry out fabric registration |
| 355 | * login through the HBA firmware: the first mailbox command requests the |
| 356 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 357 | * command requests the HBA to perform the actual fabric registration login |
| 358 | * with the @vport. |
| 359 | * |
| 360 | * Return code |
| 361 | * 0 - successfully issued fabric registration login for @vport |
| 362 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 363 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 364 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 366 | { |
| 367 | struct lpfc_hba *phba = vport->phba; |
| 368 | LPFC_MBOXQ_t *mbox; |
| 369 | struct lpfc_dmabuf *mp; |
| 370 | struct lpfc_nodelist *ndlp; |
| 371 | struct serv_parm *sp; |
| 372 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 373 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | |
| 375 | sp = &phba->fc_fabparam; |
| 376 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 377 | if (!ndlp) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 379 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 380 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | |
| 382 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 383 | if (!mbox) { |
| 384 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 386 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | |
| 388 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 389 | lpfc_config_link(phba, mbox); |
| 390 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 391 | mbox->vport = vport; |
| 392 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { |
| 395 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | |
| 399 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 400 | if (!mbox) { |
| 401 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 403 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 404 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 405 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 406 | if (rc) { |
| 407 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 409 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 410 | |
| 411 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 412 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 413 | /* increment the reference count on ndlp to hold reference |
| 414 | * for the callback routine. |
| 415 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 416 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 417 | if (!mbox->ctx_ndlp) { |
| 418 | err = 6; |
| 419 | goto fail_no_ndlp; |
| 420 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 421 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 422 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 423 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 424 | err = 7; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 425 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 426 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 427 | |
| 428 | return 0; |
| 429 | |
| 430 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 431 | /* decrement the reference count on ndlp just incremented |
| 432 | * for the failed mbox command. |
| 433 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 434 | lpfc_nlp_put(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 435 | fail_no_ndlp: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 436 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 437 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 438 | kfree(mp); |
| 439 | fail_free_mbox: |
| 440 | mempool_free(mbox, phba->mbox_mem_pool); |
| 441 | |
| 442 | fail: |
| 443 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 444 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 445 | "0249 Cannot issue Register Fabric login: Err %d\n", |
| 446 | err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 447 | return -ENXIO; |
| 448 | } |
| 449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 450 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 451 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 452 | * @vport: pointer to a host virtual N_Port data structure. |
| 453 | * |
| 454 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 455 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 456 | * |
| 457 | * Return code |
| 458 | * 0 - successfully issued REG_VFI for @vport |
| 459 | * A failure code otherwise. |
| 460 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 461 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 462 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 463 | { |
| 464 | struct lpfc_hba *phba = vport->phba; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 465 | LPFC_MBOXQ_t *mboxq = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 466 | struct lpfc_nodelist *ndlp; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 467 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 468 | int rc = 0; |
| 469 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 470 | /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 471 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 472 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
| 473 | !(vport->fc_flag & FC_PT2PT)) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 474 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 475 | if (!ndlp) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 476 | rc = -ENODEV; |
| 477 | goto fail; |
| 478 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 479 | } |
| 480 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 481 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 482 | if (!mboxq) { |
| 483 | rc = -ENOMEM; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 484 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 485 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 486 | |
| 487 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
| 488 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { |
| 489 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 490 | if (!dmabuf) { |
| 491 | rc = -ENOMEM; |
| 492 | goto fail; |
| 493 | } |
| 494 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 495 | if (!dmabuf->virt) { |
| 496 | rc = -ENOMEM; |
| 497 | goto fail; |
| 498 | } |
| 499 | memcpy(dmabuf->virt, &phba->fc_fabparam, |
| 500 | sizeof(struct serv_parm)); |
| 501 | } |
| 502 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 503 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 504 | if (dmabuf) |
| 505 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 506 | else |
| 507 | lpfc_reg_vfi(mboxq, vport, 0); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 508 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 509 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 510 | mboxq->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 511 | mboxq->ctx_buf = dmabuf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 512 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 513 | if (rc == MBX_NOT_FINISHED) { |
| 514 | rc = -ENXIO; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 515 | goto fail; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 516 | } |
| 517 | return 0; |
| 518 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 519 | fail: |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 520 | if (mboxq) |
| 521 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 522 | if (dmabuf) { |
| 523 | if (dmabuf->virt) |
| 524 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 525 | kfree(dmabuf); |
| 526 | } |
| 527 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 528 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 529 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 530 | "0289 Issue Register VFI failed: Err %d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 531 | return rc; |
| 532 | } |
| 533 | |
| 534 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 535 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 536 | * @vport: pointer to a host virtual N_Port data structure. |
| 537 | * |
| 538 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 539 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 540 | * |
| 541 | * Return code |
| 542 | * 0 - successfully issued REG_VFI for @vport |
| 543 | * A failure code otherwise. |
| 544 | **/ |
| 545 | int |
| 546 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 547 | { |
| 548 | struct lpfc_hba *phba = vport->phba; |
| 549 | struct Scsi_Host *shost; |
| 550 | LPFC_MBOXQ_t *mboxq; |
| 551 | int rc; |
| 552 | |
| 553 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 554 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 555 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 556 | "2556 UNREG_VFI mbox allocation failed" |
| 557 | "HBA state x%x\n", phba->pport->port_state); |
| 558 | return -ENOMEM; |
| 559 | } |
| 560 | |
| 561 | lpfc_unreg_vfi(mboxq, vport); |
| 562 | mboxq->vport = vport; |
| 563 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 564 | |
| 565 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 566 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 567 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 568 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 569 | "HBA state x%x\n", |
| 570 | rc, phba->pport->port_state); |
| 571 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 572 | return -EIO; |
| 573 | } |
| 574 | |
| 575 | shost = lpfc_shost_from_vport(vport); |
| 576 | spin_lock_irq(shost->host_lock); |
| 577 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 578 | spin_unlock_irq(shost->host_lock); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 583 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 584 | * @vport: pointer to a host virtual N_Port data structure. |
| 585 | * @sp: pointer to service parameter data structure. |
| 586 | * |
| 587 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 588 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 589 | * node nodename is changed in the completion service parameter else return |
| 590 | * 0. This function also set flag in the vport data structure to delay |
| 591 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 592 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 593 | * node nodename is changed in the completion service parameter. |
| 594 | * |
| 595 | * Return code |
| 596 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 597 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 598 | * |
| 599 | **/ |
| 600 | static uint8_t |
| 601 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 602 | struct serv_parm *sp) |
| 603 | { |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 604 | struct lpfc_hba *phba = vport->phba; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 605 | uint8_t fabric_param_changed = 0; |
| 606 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 607 | |
| 608 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 609 | memcmp(&vport->fabric_portname, &sp->portName, |
| 610 | sizeof(struct lpfc_name)) || |
| 611 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 612 | sizeof(struct lpfc_name)) || |
| 613 | (vport->vport_flag & FAWWPN_PARAM_CHG)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 614 | fabric_param_changed = 1; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 615 | vport->vport_flag &= ~FAWWPN_PARAM_CHG; |
| 616 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 617 | /* |
| 618 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 619 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 620 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 621 | * |
| 622 | * If fabric parameter is changed and clean address bit is |
| 623 | * cleared delay nport discovery if |
| 624 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 625 | * - lpfc_delay_discovery module parameter is set. |
| 626 | */ |
| 627 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
James Smart | 8eb8b96 | 2016-07-06 12:36:08 -0700 | [diff] [blame] | 628 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 629 | spin_lock_irq(shost->host_lock); |
| 630 | vport->fc_flag |= FC_DISC_DELAYED; |
| 631 | spin_unlock_irq(shost->host_lock); |
| 632 | } |
| 633 | |
| 634 | return fabric_param_changed; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 639 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 640 | * @vport: pointer to a host virtual N_Port data structure. |
| 641 | * @ndlp: pointer to a node-list data structure. |
| 642 | * @sp: pointer to service parameter data structure. |
| 643 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 644 | * |
| 645 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 646 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 647 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 648 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 649 | * @vport against the previously assigned N_Port ID. If it is different from |
| 650 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 651 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 652 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 653 | * is invoked to register login to the fabric. |
| 654 | * |
| 655 | * Return code |
| 656 | * 0 - Success (currently, always return 0) |
| 657 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 658 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 660 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 662 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 663 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 664 | struct lpfc_nodelist *np; |
| 665 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 666 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 668 | spin_lock_irq(shost->host_lock); |
| 669 | vport->fc_flag |= FC_FABRIC; |
| 670 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | |
| 672 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 673 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 674 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 675 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 676 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 678 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 679 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 680 | spin_lock_irq(shost->host_lock); |
| 681 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 682 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 683 | } |
| 684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 685 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | ndlp->nlp_class_sup = 0; |
| 689 | if (sp->cls1.classValid) |
| 690 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 691 | if (sp->cls2.classValid) |
| 692 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 693 | if (sp->cls3.classValid) |
| 694 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 695 | if (sp->cls4.classValid) |
| 696 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 697 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 698 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 699 | |
| 700 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 701 | if (fabric_param_changed) { |
| 702 | /* Reset FDMI attribute masks based on config parameter */ |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 703 | if (phba->cfg_enable_SmartSAN || |
| 704 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 705 | /* Setup appropriate attribute masks */ |
| 706 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 707 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 708 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 709 | else |
| 710 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 711 | } else { |
| 712 | vport->fdmi_hba_mask = 0; |
| 713 | vport->fdmi_port_mask = 0; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | } |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 717 | memcpy(&vport->fabric_portname, &sp->portName, |
| 718 | sizeof(struct lpfc_name)); |
| 719 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 720 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 722 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 723 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 724 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 725 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 726 | LOG_ELS | LOG_VPORT, |
| 727 | "1816 FLOGI NPIV supported, " |
| 728 | "response data 0x%x\n", |
| 729 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 730 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 731 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 732 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 733 | } else { |
| 734 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 735 | to call reg_vnpid atleast for the physcial host */ |
| 736 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 737 | LOG_ELS | LOG_VPORT, |
| 738 | "1817 Fabric does not support NPIV " |
| 739 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 741 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 742 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 746 | /* |
| 747 | * For FC we need to do some special processing because of the SLI |
| 748 | * Port's default settings of the Common Service Parameters. |
| 749 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 750 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 751 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 752 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 753 | if (fabric_param_changed) |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 754 | lpfc_unregister_fcf_prep(phba); |
| 755 | |
| 756 | /* This should just update the VFI CSPs*/ |
| 757 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 758 | lpfc_issue_reg_vfi(vport); |
| 759 | } |
| 760 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 761 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 762 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 763 | |
| 764 | /* If our NportID changed, we need to ensure all |
| 765 | * remaining NPORTs get unreg_login'ed. |
| 766 | */ |
| 767 | list_for_each_entry_safe(np, next_np, |
| 768 | &vport->fc_nodes, nlp_listp) { |
| 769 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 770 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 771 | continue; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 772 | spin_lock_irq(&np->lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 773 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 774 | spin_unlock_irq(&np->lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 775 | lpfc_unreg_rpi(vport, np); |
| 776 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 777 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 778 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 779 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 780 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 781 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 782 | spin_lock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 783 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 784 | spin_unlock_irq(shost->host_lock); |
| 785 | } |
James Smart | 27aa1b7 | 2012-05-09 21:18:49 -0400 | [diff] [blame] | 786 | |
| 787 | /* |
| 788 | * For SLI3 and SLI4, the VPI needs to be reregistered in |
| 789 | * response to this fabric parameter change event. |
| 790 | */ |
| 791 | spin_lock_irq(shost->host_lock); |
| 792 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 793 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 794 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 795 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 796 | /* |
| 797 | * Driver needs to re-reg VPI in order for f/w |
| 798 | * to update the MAC address. |
| 799 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 800 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 801 | lpfc_register_new_vport(phba, vport, ndlp); |
| 802 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | } |
| 804 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 805 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 806 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 807 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 808 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 809 | lpfc_register_new_vport(phba, vport, ndlp); |
| 810 | else |
| 811 | lpfc_issue_fabric_reglogin(vport); |
| 812 | } else { |
| 813 | ndlp->nlp_type |= NLP_FABRIC; |
| 814 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 815 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 816 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 817 | lpfc_start_fdiscs(phba); |
| 818 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 819 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 820 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 821 | else { |
| 822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 823 | "3135 Need register VFI: (x%x/%x)\n", |
| 824 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 825 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 826 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 827 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 829 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 832 | * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 833 | * @vport: pointer to a host virtual N_Port data structure. |
| 834 | * @ndlp: pointer to a node-list data structure. |
| 835 | * @sp: pointer to service parameter data structure. |
| 836 | * |
| 837 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 838 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 839 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 840 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 841 | * the received N_Port Name lexicographically, this node shall assign local |
| 842 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 843 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 844 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 845 | * N_Port IDs. |
| 846 | * |
| 847 | * Return code |
| 848 | * 0 - Success |
| 849 | * -ENXIO - Fail |
| 850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 852 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 853 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 854 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 855 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 856 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | LPFC_MBOXQ_t *mbox; |
| 858 | int rc; |
| 859 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 860 | spin_lock_irq(shost->host_lock); |
| 861 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 862 | vport->fc_flag |= FC_PT2PT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 863 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 865 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 866 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 867 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 868 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
| 869 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { |
| 870 | lpfc_unregister_fcf_prep(phba); |
| 871 | |
| 872 | spin_lock_irq(shost->host_lock); |
| 873 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 874 | spin_unlock_irq(shost->host_lock); |
| 875 | phba->fc_topology_changed = 0; |
| 876 | } |
| 877 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 878 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 879 | sizeof(vport->fc_portname)); |
James Smart | 2eb6862 | 2012-09-29 11:32:27 -0400 | [diff] [blame] | 880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | if (rc >= 0) { |
| 882 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | spin_lock_irq(shost->host_lock); |
| 884 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 885 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | |
| 887 | /* |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 888 | * N_Port ID cannot be 0, set our Id to LocalID |
| 889 | * the other side will be RemoteID. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | */ |
| 891 | |
| 892 | /* not equal */ |
| 893 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 896 | /* Decrement ndlp reference count indicating that ndlp can be |
| 897 | * safely released when other references to it are done. |
| 898 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 899 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | if (!ndlp) { |
| 903 | /* |
| 904 | * Cannot find existing Fabric ndlp, so allocate a |
| 905 | * new one |
| 906 | */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 907 | ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | if (!ndlp) |
| 909 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 913 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 916 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 918 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 920 | spin_unlock_irq(&ndlp->lock); |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 921 | |
| 922 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 923 | if (!mbox) |
| 924 | goto fail; |
| 925 | |
| 926 | lpfc_config_link(phba, mbox); |
| 927 | |
| 928 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 929 | mbox->vport = vport; |
| 930 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 931 | if (rc == MBX_NOT_FINISHED) { |
| 932 | mempool_free(mbox, phba->mbox_mem_pool); |
| 933 | goto fail; |
| 934 | } |
| 935 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 936 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 937 | * count indicating that ndlp can be released when other |
| 938 | * references to it are done. |
| 939 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 940 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | |
James Smart | d33d0eb | 2017-11-20 16:00:34 -0800 | [diff] [blame] | 942 | /* Start discovery - this should just do CLEAR_LA */ |
| 943 | lpfc_disc_start(vport); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 944 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | return -ENXIO; |
| 949 | } |
| 950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 952 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 953 | * @phba: pointer to lpfc hba data structure. |
| 954 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 955 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 956 | * |
| 957 | * This routine is the top-level completion callback function for issuing |
| 958 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 959 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 960 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 961 | * returning 1), the command IOCB will be released and function returned. |
| 962 | * If the retry attempt has been given up (possibly reach the maximum |
| 963 | * number of retries), one additional decrement of ndlp reference shall be |
| 964 | * invoked before going out after releasing the command IOCB. This will |
| 965 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 966 | * invoke one decrement of ndlp reference count). If no error reported in |
| 967 | * the IOCB status, the command Port ID field is used to determine whether |
| 968 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 969 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 970 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 971 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 972 | * specific topology completion conditions. |
| 973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 975 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 976 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | struct lpfc_vport *vport = cmdiocb->vport; |
| 979 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 980 | IOCB_t *irsp = &rspiocb->iocb; |
| 981 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 982 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 983 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 984 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | int rc; |
| 986 | |
| 987 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 989 | /* One additional decrement on node reference count to |
| 990 | * trigger the release of the node |
| 991 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 992 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | goto out; |
| 994 | } |
| 995 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 996 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 997 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 998 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 999 | vport->port_state); |
| 1000 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1002 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1003 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1004 | * due to new FCF discovery |
| 1005 | */ |
| 1006 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1007 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 1008 | if (phba->link_state < LPFC_LINK_UP) |
| 1009 | goto stop_rr_fcf_flogi; |
| 1010 | if ((phba->fcoe_cvl_eventtag_attn == |
| 1011 | phba->fcoe_cvl_eventtag) && |
| 1012 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1013 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1014 | IOERR_SLI_ABORTED)) |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1015 | goto stop_rr_fcf_flogi; |
| 1016 | else |
| 1017 | phba->fcoe_cvl_eventtag_attn = |
| 1018 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1019 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1020 | "2611 FLOGI failed on FCF (x%x), " |
| 1021 | "status:x%x/x%x, tmo:x%x, perform " |
| 1022 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1023 | phba->fcf.current_rec.fcf_indx, |
| 1024 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1025 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1026 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 1027 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1028 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1029 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 1030 | if (rc) |
| 1031 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 1034 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1035 | /* FLOGI failure */ |
James Smart | c73455e | 2017-11-20 16:00:28 -0800 | [diff] [blame] | 1036 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1037 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1038 | IOERR_LOOP_OPEN_FAILURE))) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1039 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1040 | "2858 FLOGI failure Status:x%x/x%x TMO" |
| 1041 | ":x%x Data x%x x%x\n", |
| 1042 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1043 | irsp->ulpTimeout, phba->hba_flag, |
| 1044 | phba->fcf.fcf_flag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1050 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT, |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 1051 | "0150 FLOGI failure Status:x%x/x%x " |
| 1052 | "xri x%x TMO:x%x\n", |
| 1053 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1054 | cmdiocb->sli4_xritag, irsp->ulpTimeout); |
| 1055 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 1056 | /* If this is not a loop open failure, bail out */ |
| 1057 | if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 1058 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1059 | IOERR_LOOP_OPEN_FAILURE))) |
| 1060 | goto flogifail; |
| 1061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | spin_lock_irq(shost->host_lock); |
| 1064 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1065 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1067 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 1069 | * alpa map would take too long otherwise. |
| 1070 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1071 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1072 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1073 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1074 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1075 | (vport->fc_prevDID != vport->fc_myDID) || |
| 1076 | phba->fc_topology_changed)) { |
| 1077 | if (vport->fc_flag & FC_VFI_REGISTERED) { |
| 1078 | if (phba->fc_topology_changed) { |
| 1079 | lpfc_unregister_fcf_prep(phba); |
| 1080 | spin_lock_irq(shost->host_lock); |
| 1081 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 1082 | spin_unlock_irq(shost->host_lock); |
| 1083 | phba->fc_topology_changed = 0; |
| 1084 | } else { |
| 1085 | lpfc_sli4_unreg_all_rpis(vport); |
| 1086 | } |
| 1087 | } |
James Smart | 342b59c | 2016-03-31 14:12:31 -0700 | [diff] [blame] | 1088 | |
| 1089 | /* Do not register VFI if the driver aborted FLOGI */ |
| 1090 | if (!lpfc_error_lost_link(irsp)) |
| 1091 | lpfc_issue_reg_vfi(vport); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1092 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 1093 | lpfc_nlp_put(ndlp); |
| 1094 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | goto flogifail; |
| 1097 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1098 | spin_lock_irq(shost->host_lock); |
| 1099 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1100 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1101 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | |
| 1103 | /* |
| 1104 | * The FLogI succeeded. Sync the data for the CPU before |
| 1105 | * accessing it. |
| 1106 | */ |
| 1107 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 1108 | if (!prsp) |
| 1109 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | sp = prsp->virt + sizeof(uint32_t); |
| 1111 | |
| 1112 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1113 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 1114 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1115 | "xri x%x Data: x%x x%x x%x x%x x%x %x\n", |
| 1116 | cmdiocb->iotag, cmdiocb->sli4_xritag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1117 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1118 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
| 1119 | vport->port_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1121 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1122 | /* |
| 1123 | * If Common Service Parameters indicate Nport |
| 1124 | * we are point to point, if Fport we are Fabric. |
| 1125 | */ |
| 1126 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1128 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1130 | else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1131 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1132 | "2831 FLOGI response with cleared Fabric " |
| 1133 | "bit fcf_index 0x%x " |
| 1134 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1135 | "Fabric Name " |
| 1136 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1137 | phba->fcf.current_rec.fcf_indx, |
| 1138 | phba->fcf.current_rec.switch_name[0], |
| 1139 | phba->fcf.current_rec.switch_name[1], |
| 1140 | phba->fcf.current_rec.switch_name[2], |
| 1141 | phba->fcf.current_rec.switch_name[3], |
| 1142 | phba->fcf.current_rec.switch_name[4], |
| 1143 | phba->fcf.current_rec.switch_name[5], |
| 1144 | phba->fcf.current_rec.switch_name[6], |
| 1145 | phba->fcf.current_rec.switch_name[7], |
| 1146 | phba->fcf.current_rec.fabric_name[0], |
| 1147 | phba->fcf.current_rec.fabric_name[1], |
| 1148 | phba->fcf.current_rec.fabric_name[2], |
| 1149 | phba->fcf.current_rec.fabric_name[3], |
| 1150 | phba->fcf.current_rec.fabric_name[4], |
| 1151 | phba->fcf.current_rec.fabric_name[5], |
| 1152 | phba->fcf.current_rec.fabric_name[6], |
| 1153 | phba->fcf.current_rec.fabric_name[7]); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1154 | |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1155 | lpfc_nlp_put(ndlp); |
| 1156 | spin_lock_irq(&phba->hbalock); |
| 1157 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1158 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1159 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1160 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1161 | goto out; |
| 1162 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1163 | if (!rc) { |
| 1164 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1165 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1166 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1167 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1168 | "2769 FLOGI to FCF (x%x) " |
| 1169 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1170 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1171 | spin_lock_irq(&phba->hbalock); |
| 1172 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1173 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1174 | spin_unlock_irq(&phba->hbalock); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 1175 | phba->fcf.fcf_redisc_attempted = 0; /* reset */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1177 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | flogifail: |
James Smart | 8fe5c16 | 2015-08-31 16:48:19 -0400 | [diff] [blame] | 1181 | spin_lock_irq(&phba->hbalock); |
| 1182 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 1183 | spin_unlock_irq(&phba->hbalock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1184 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1185 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1186 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1187 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1188 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | |
| 1190 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1191 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1192 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1193 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1194 | IOERR_SLI_ABORTED) && |
| 1195 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 1196 | IOERR_SLI_DOWN))) && |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1197 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1198 | /* If FLOGI failed enable link interrupt. */ |
| 1199 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | out: |
| 1202 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1203 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1206 | /** |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 1207 | * lpfc_cmpl_els_link_down - Completion callback function for ELS command |
| 1208 | * aborted during a link down |
| 1209 | * @phba: pointer to lpfc hba data structure. |
| 1210 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1211 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1212 | * |
| 1213 | */ |
| 1214 | static void |
| 1215 | lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1216 | struct lpfc_iocbq *rspiocb) |
| 1217 | { |
| 1218 | IOCB_t *irsp; |
| 1219 | uint32_t *pcmd; |
| 1220 | uint32_t cmd; |
| 1221 | |
| 1222 | pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt); |
| 1223 | cmd = *pcmd; |
| 1224 | irsp = &rspiocb->iocb; |
| 1225 | |
| 1226 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1227 | "6445 ELS completes after LINK_DOWN: " |
| 1228 | " Status %x/%x cmd x%x flg x%x\n", |
| 1229 | irsp->ulpStatus, irsp->un.ulpWord[4], cmd, |
| 1230 | cmdiocb->iocb_flag); |
| 1231 | |
| 1232 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) { |
| 1233 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 1234 | atomic_dec(&phba->fabric_iocb_count); |
| 1235 | } |
| 1236 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1237 | } |
| 1238 | |
| 1239 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1240 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1241 | * @vport: pointer to a host virtual N_Port data structure. |
| 1242 | * @ndlp: pointer to a node-list data structure. |
| 1243 | * @retry: number of retries to the command IOCB. |
| 1244 | * |
| 1245 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1246 | * for a @vport. The initiator service parameters are put into the payload |
| 1247 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1248 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1249 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1250 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1251 | * |
| 1252 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1253 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1254 | * will be stored into the context1 field of the IOCB for the completion |
| 1255 | * callback function to the FLOGI ELS command. |
| 1256 | * |
| 1257 | * Return code |
| 1258 | * 0 - successfully issued flogi iocb for @vport |
| 1259 | * 1 - failed to issue flogi iocb for @vport |
| 1260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1262 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | uint8_t retry) |
| 1264 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1265 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | struct serv_parm *sp; |
| 1267 | IOCB_t *icmd; |
| 1268 | struct lpfc_iocbq *elsiocb; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1269 | struct lpfc_iocbq defer_flogi_acc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | uint8_t *pcmd; |
| 1271 | uint16_t cmdsize; |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1272 | uint32_t tmo, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | int rc; |
| 1274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1275 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1277 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1278 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1279 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1280 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | |
| 1282 | icmd = &elsiocb->iocb; |
| 1283 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1284 | |
| 1285 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1286 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1287 | pcmd += sizeof(uint32_t); |
| 1288 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | sp = (struct serv_parm *) pcmd; |
| 1290 | |
| 1291 | /* Setup CSPs accordingly for Fabric */ |
| 1292 | sp->cmn.e_d_tov = 0; |
| 1293 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1294 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | sp->cls1.classValid = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | if (sp->cmn.fcphLow < FC_PH3) |
| 1297 | sp->cmn.fcphLow = FC_PH3; |
| 1298 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1299 | sp->cmn.fcphHigh = FC_PH3; |
| 1300 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1301 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1302 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1303 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1304 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1305 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1306 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1307 | /* Set the fcfi to the fcfi we registered with */ |
| 1308 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1309 | } |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1310 | /* Can't do SLI4 class2 without support sequence coalescing */ |
| 1311 | sp->cls2.classValid = 0; |
| 1312 | sp->cls2.seqDelivery = 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1313 | } else { |
James Smart | 0f37887 | 2012-10-31 14:45:01 -0400 | [diff] [blame] | 1314 | /* Historical, setting sequential-delivery bit for SLI3 */ |
| 1315 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; |
| 1316 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1317 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1318 | sp->cmn.request_multiple_Nport = 1; |
| 1319 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1320 | icmd->ulpCt_h = 1; |
| 1321 | icmd->ulpCt_l = 0; |
| 1322 | } else |
| 1323 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1324 | } |
| 1325 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1326 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1327 | icmd->un.elsreq64.myID = 0; |
| 1328 | icmd->un.elsreq64.fl = 1; |
| 1329 | } |
| 1330 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | tmo = phba->fc_ratov; |
| 1332 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | phba->fc_ratov = tmo; |
| 1335 | |
| 1336 | phba->fc_stat.elsXmitFLOGI++; |
| 1337 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1338 | |
| 1339 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1340 | "Issue FLOGI: opt:x%x", |
| 1341 | phba->sli3_options, 0, 0); |
| 1342 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1343 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 1344 | if (!elsiocb->context1) |
| 1345 | goto out; |
| 1346 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1347 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1348 | if (rc == IOCB_ERROR) |
| 1349 | lpfc_nlp_put(ndlp); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1350 | |
| 1351 | phba->hba_flag |= HBA_FLOGI_ISSUED; |
| 1352 | |
| 1353 | /* Check for a deferred FLOGI ACC condition */ |
| 1354 | if (phba->defer_flogi_acc_flag) { |
| 1355 | did = vport->fc_myDID; |
| 1356 | vport->fc_myDID = Fabric_DID; |
| 1357 | |
| 1358 | memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq)); |
| 1359 | |
| 1360 | defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id; |
| 1361 | defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id = |
| 1362 | phba->defer_flogi_acc_ox_id; |
| 1363 | |
| 1364 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1365 | "3354 Xmit deferred FLOGI ACC: rx_id: x%x," |
| 1366 | " ox_id: x%x, hba_flag x%x\n", |
| 1367 | phba->defer_flogi_acc_rx_id, |
| 1368 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 1369 | |
| 1370 | /* Send deferred FLOGI ACC */ |
| 1371 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc, |
| 1372 | ndlp, NULL); |
| 1373 | |
| 1374 | phba->defer_flogi_acc_flag = false; |
| 1375 | |
| 1376 | vport->fc_myDID = did; |
| 1377 | } |
| 1378 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1379 | if (!rc) |
| 1380 | return 0; |
| 1381 | out: |
| 1382 | lpfc_els_free_iocb(phba, elsiocb); |
| 1383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1387 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | * @phba: pointer to lpfc hba data structure. |
| 1389 | * |
| 1390 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1391 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1392 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1393 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1394 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1395 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1396 | * |
| 1397 | * Return code |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1398 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | { |
| 1403 | struct lpfc_sli_ring *pring; |
| 1404 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1405 | struct lpfc_nodelist *ndlp; |
| 1406 | IOCB_t *icmd; |
| 1407 | |
| 1408 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1409 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1410 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1411 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1413 | pring = lpfc_phba_elsring(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1414 | if (unlikely(!pring)) |
| 1415 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1419 | * searching for. |
| 1420 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1421 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1423 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1424 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1426 | if (ndlp && (ndlp->nlp_DID == Fabric_DID)) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 1427 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 1428 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | } |
| 1430 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1436 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1437 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1438 | * @vport: pointer to a host virtual N_Port data structure. |
| 1439 | * |
| 1440 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1441 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1442 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1443 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1444 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1445 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1446 | * @vport. |
| 1447 | * |
| 1448 | * Return code |
| 1449 | * 0 - failed to issue initial flogi for @vport |
| 1450 | * 1 - successfully issued initial flogi for @vport |
| 1451 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1452 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1453 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | { |
| 1455 | struct lpfc_nodelist *ndlp; |
| 1456 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1457 | vport->port_state = LPFC_FLOGI; |
| 1458 | lpfc_set_disctmo(vport); |
| 1459 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1460 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1461 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1462 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1464 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1465 | if (!ndlp) |
| 1466 | return 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1467 | /* Set the node type */ |
| 1468 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1469 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1470 | /* Put ndlp onto node list */ |
| 1471 | lpfc_enqueue_node(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1473 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1474 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1475 | /* This decrement of reference count to node shall kick off |
| 1476 | * the release of the node. |
| 1477 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1478 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1479 | return 0; |
| 1480 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1481 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | } |
| 1483 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1484 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1485 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1486 | * @vport: pointer to a host virtual N_Port data structure. |
| 1487 | * |
| 1488 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1489 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1490 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1491 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1492 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1493 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1494 | * @vport. |
| 1495 | * |
| 1496 | * Return code |
| 1497 | * 0 - failed to issue initial fdisc for @vport |
| 1498 | * 1 - successfully issued initial fdisc for @vport |
| 1499 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1500 | int |
| 1501 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1502 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1503 | struct lpfc_nodelist *ndlp; |
| 1504 | |
| 1505 | /* First look for the Fabric ndlp */ |
| 1506 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1507 | if (!ndlp) { |
| 1508 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1509 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1510 | if (!ndlp) |
| 1511 | return 0; |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 1512 | |
| 1513 | /* NPIV is only supported in Fabrics. */ |
| 1514 | ndlp->nlp_type |= NLP_FABRIC; |
| 1515 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1516 | /* Put ndlp onto node list */ |
| 1517 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1518 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1519 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1520 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1521 | /* decrement node reference count to trigger the release of |
| 1522 | * the node. |
| 1523 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1524 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1525 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1526 | } |
| 1527 | return 1; |
| 1528 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1529 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1530 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1531 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1532 | * @vport: pointer to a host virtual N_Port data structure. |
| 1533 | * |
| 1534 | * This routine checks whether there are more remaining Port Logins |
| 1535 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1536 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1537 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1538 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1539 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1540 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1541 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1542 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | if (vport->num_disc_nodes) |
| 1545 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | |
| 1547 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1548 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1549 | "0232 Continue discovery with %d PLOGIs to go " |
| 1550 | "Data: x%x x%x x%x\n", |
| 1551 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1552 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1554 | if (vport->fc_flag & FC_NLP_MORE) |
| 1555 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 1556 | lpfc_els_disc_plogi(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | return; |
| 1559 | } |
| 1560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1561 | /** |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 1562 | * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1563 | * @phba: pointer to lpfc hba data structure. |
| 1564 | * @prsp: pointer to response IOCB payload. |
| 1565 | * @ndlp: pointer to a node-list data structure. |
| 1566 | * |
| 1567 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1568 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1569 | * The following cases are considered N_Port confirmed: |
| 1570 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1571 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1572 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1573 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1574 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1575 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1576 | * on that node to release the RPI associated with the node; 2) if there is |
| 1577 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1578 | * into, a new node shall be allocated (or activated). In either case, the |
| 1579 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1580 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1581 | * its pointer returned as the confirmed node. |
| 1582 | * |
| 1583 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1584 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1585 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1586 | * into an inactive state on the vport node list and the vport node list |
| 1587 | * management algorithm does not allow two node with a same DID. |
| 1588 | * |
| 1589 | * Return code |
| 1590 | * pointer to the PLOGI N_Port @ndlp |
| 1591 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1592 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1593 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1594 | struct lpfc_nodelist *ndlp) |
| 1595 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1596 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1597 | struct lpfc_nodelist *new_ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1598 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1599 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1600 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1601 | uint32_t keep_new_nlp_flag = 0; |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1602 | uint16_t keep_nlp_state; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1603 | u32 keep_nlp_fc4_type = 0; |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1604 | struct lpfc_nvme_rport *keep_nrport = NULL; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1605 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1606 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1607 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1608 | * by WWPN. Just return the ndlp that was given to us. |
| 1609 | */ |
| 1610 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1611 | return ndlp; |
| 1612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1613 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1614 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1615 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1616 | /* Now we find out if the NPort we are logging into, matches the WWPN |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1617 | * we have for that ndlp. If not, we have some work to do. |
| 1618 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1620 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1621 | /* return immediately if the WWPN matches ndlp */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1622 | if (new_ndlp == ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1623 | return ndlp; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1624 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1625 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1626 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, |
| 1627 | GFP_KERNEL); |
| 1628 | if (active_rrqs_xri_bitmap) |
| 1629 | memset(active_rrqs_xri_bitmap, 0, |
| 1630 | phba->cfg_rrq_xri_bitmap_sz); |
| 1631 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1632 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1633 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1634 | "3178 PLOGI confirm: ndlp x%x x%x x%x: " |
| 1635 | "new_ndlp x%x x%x x%x\n", |
| 1636 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type, |
| 1637 | (new_ndlp ? new_ndlp->nlp_DID : 0), |
| 1638 | (new_ndlp ? new_ndlp->nlp_flag : 0), |
| 1639 | (new_ndlp ? new_ndlp->nlp_fc4_type : 0)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1640 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1641 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1643 | sizeof(struct lpfc_name)); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1644 | if (!rc) { |
| 1645 | if (active_rrqs_xri_bitmap) |
| 1646 | mempool_free(active_rrqs_xri_bitmap, |
| 1647 | phba->active_rrq_pool); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1648 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1649 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 1650 | new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1651 | if (!new_ndlp) { |
| 1652 | if (active_rrqs_xri_bitmap) |
| 1653 | mempool_free(active_rrqs_xri_bitmap, |
| 1654 | phba->active_rrq_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1655 | return ndlp; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1656 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1657 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1658 | keepDID = new_ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1659 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1660 | active_rrqs_xri_bitmap) |
| 1661 | memcpy(active_rrqs_xri_bitmap, |
| 1662 | new_ndlp->active_rrqs_xri_bitmap, |
| 1663 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1664 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1665 | |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1666 | /* At this point in this routine, we know new_ndlp will be |
| 1667 | * returned. however, any previous GID_FTs that were done |
| 1668 | * would have updated nlp_fc4_type in ndlp, so we must ensure |
| 1669 | * new_ndlp has the right value. |
| 1670 | */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1671 | if (vport->fc_flag & FC_FABRIC) { |
| 1672 | keep_nlp_fc4_type = new_ndlp->nlp_fc4_type; |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1673 | new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1674 | } |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1677 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1678 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1679 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1680 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
| 1681 | ndlp->active_rrqs_xri_bitmap, |
| 1682 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1683 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1684 | /* Lock both ndlps */ |
| 1685 | spin_lock_irq(&ndlp->lock); |
| 1686 | spin_lock_irq(&new_ndlp->lock); |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1687 | keep_new_nlp_flag = new_ndlp->nlp_flag; |
| 1688 | keep_nlp_flag = ndlp->nlp_flag; |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1689 | new_ndlp->nlp_flag = ndlp->nlp_flag; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1690 | |
| 1691 | /* if new_ndlp had NLP_UNREG_INP set, keep it */ |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1692 | if (keep_new_nlp_flag & NLP_UNREG_INP) |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1693 | new_ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1694 | else |
| 1695 | new_ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1696 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1697 | /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1698 | if (keep_new_nlp_flag & NLP_RPI_REGISTERED) |
| 1699 | new_ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1700 | else |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1701 | new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
| 1702 | |
| 1703 | ndlp->nlp_flag = keep_new_nlp_flag; |
| 1704 | |
| 1705 | /* if ndlp had NLP_UNREG_INP set, keep it */ |
| 1706 | if (keep_nlp_flag & NLP_UNREG_INP) |
| 1707 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 1708 | else |
| 1709 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 1710 | |
| 1711 | /* if ndlp had NLP_RPI_REGISTERED set, keep it */ |
| 1712 | if (keep_nlp_flag & NLP_RPI_REGISTERED) |
| 1713 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 1714 | else |
| 1715 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 1716 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1717 | spin_unlock_irq(&new_ndlp->lock); |
| 1718 | spin_unlock_irq(&ndlp->lock); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1719 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1720 | /* Set nlp_states accordingly */ |
| 1721 | keep_nlp_state = new_ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1723 | |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1724 | /* interchange the nvme remoteport structs */ |
| 1725 | keep_nrport = new_ndlp->nrport; |
| 1726 | new_ndlp->nrport = ndlp->nrport; |
| 1727 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1728 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1729 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1730 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1731 | * to put ndlp on UNUSED list and try to free it. |
| 1732 | */ |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1733 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1734 | "3179 PLOGI confirm NEW: %x %x\n", |
| 1735 | new_ndlp->nlp_DID, keepDID); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1736 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1737 | /* Two ndlps cannot have the same did on the nodelist. |
| 1738 | * Note: for this case, ndlp has a NULL WWPN so setting |
| 1739 | * the nlp_fc4_type isn't required. |
| 1740 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1741 | ndlp->nlp_DID = keepDID; |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 1742 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1743 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1744 | active_rrqs_xri_bitmap) |
| 1745 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1746 | active_rrqs_xri_bitmap, |
| 1747 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | e5abba4 | 2015-05-21 13:55:27 -0400 | [diff] [blame] | 1748 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1749 | } else { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1750 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1751 | "3180 PLOGI confirm SWAP: %x %x\n", |
| 1752 | new_ndlp->nlp_DID, keepDID); |
| 1753 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1755 | |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1756 | /* Two ndlps cannot have the same did and the fc4 |
| 1757 | * type must be transferred because the ndlp is in |
| 1758 | * flight. |
| 1759 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1760 | ndlp->nlp_DID = keepDID; |
James Smart | 92ea83a | 2018-11-29 16:09:34 -0800 | [diff] [blame] | 1761 | ndlp->nlp_fc4_type = keep_nlp_fc4_type; |
| 1762 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1763 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1764 | active_rrqs_xri_bitmap) |
| 1765 | memcpy(ndlp->active_rrqs_xri_bitmap, |
| 1766 | active_rrqs_xri_bitmap, |
| 1767 | phba->cfg_rrq_xri_bitmap_sz); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1768 | |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1769 | /* Since we are switching over to the new_ndlp, |
| 1770 | * reset the old ndlp state |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 1771 | */ |
| 1772 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 1773 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 953ceed | 2015-05-22 10:42:37 -0400 | [diff] [blame] | 1774 | keep_nlp_state = NLP_STE_NPR_NODE; |
| 1775 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); |
Dick Kennedy | 4adc041 | 2017-08-23 16:55:37 -0700 | [diff] [blame] | 1776 | ndlp->nrport = keep_nrport; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1777 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1778 | |
| 1779 | /* |
| 1780 | * If ndlp is not associated with any rport we can drop it here else |
| 1781 | * let dev_loss_tmo_callbk trigger DEVICE_RM event |
| 1782 | */ |
| 1783 | if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE)) |
| 1784 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 1785 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1786 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 1787 | active_rrqs_xri_bitmap) |
| 1788 | mempool_free(active_rrqs_xri_bitmap, |
| 1789 | phba->active_rrq_pool); |
James Smart | d83ca3e | 2018-10-23 13:41:09 -0700 | [diff] [blame] | 1790 | |
| 1791 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, |
| 1792 | "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n", |
| 1793 | new_ndlp->nlp_DID, new_ndlp->nlp_flag, |
| 1794 | new_ndlp->nlp_fc4_type); |
| 1795 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1796 | return new_ndlp; |
| 1797 | } |
| 1798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1800 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1801 | * @vport: pointer to a host virtual N_Port data structure. |
| 1802 | * |
| 1803 | * This routine checks whether more Registration State Change |
| 1804 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1805 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1806 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1807 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1808 | * handling the RSCNs. |
| 1809 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1810 | void |
| 1811 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1812 | { |
| 1813 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1814 | |
| 1815 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1816 | /* |
| 1817 | * Check to see if more RSCNs came in while we were |
| 1818 | * processing this one. |
| 1819 | */ |
| 1820 | if (vport->fc_rscn_id_cnt || |
| 1821 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1822 | lpfc_els_handle_rscn(vport); |
| 1823 | else { |
| 1824 | spin_lock_irq(shost->host_lock); |
| 1825 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1826 | spin_unlock_irq(shost->host_lock); |
| 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1831 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1832 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1833 | * @phba: pointer to lpfc hba data structure. |
| 1834 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1835 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1836 | * |
| 1837 | * This routine will call the clear rrq function to free the rrq and |
| 1838 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1839 | * exist then the clear_rrq is still called because the rrq needs to |
| 1840 | * be freed. |
| 1841 | **/ |
| 1842 | |
| 1843 | static void |
| 1844 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1845 | struct lpfc_iocbq *rspiocb) |
| 1846 | { |
| 1847 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1848 | IOCB_t *irsp; |
| 1849 | struct lpfc_nodelist *ndlp; |
| 1850 | struct lpfc_node_rrq *rrq; |
| 1851 | |
| 1852 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1853 | rrq = cmdiocb->context_un.rrq; |
| 1854 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1855 | |
| 1856 | irsp = &rspiocb->iocb; |
| 1857 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1858 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1859 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1860 | irsp->un.elsreq64.remoteID); |
| 1861 | |
| 1862 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1863 | if (!ndlp || ndlp != rrq->ndlp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1864 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1865 | "2882 RRQ completes to NPort x%x " |
| 1866 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1867 | irsp->un.elsreq64.remoteID, |
| 1868 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1869 | irsp->ulpIoTag); |
| 1870 | goto out; |
| 1871 | } |
| 1872 | |
| 1873 | /* rrq completes to NPort <nlp_DID> */ |
| 1874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1875 | "2880 RRQ completes to NPort x%x " |
| 1876 | "Data: x%x x%x x%x x%x x%x\n", |
| 1877 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1878 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1879 | |
| 1880 | if (irsp->ulpStatus) { |
| 1881 | /* Check for retry */ |
| 1882 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1883 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1884 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1885 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1886 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1887 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1888 | "2881 RRQ failure DID:%06X Status:" |
| 1889 | "x%x/x%x\n", |
| 1890 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1891 | irsp->un.ulpWord[4]); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1892 | } |
| 1893 | out: |
| 1894 | if (rrq) |
| 1895 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1896 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1897 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1898 | lpfc_nlp_put(ndlp); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1899 | return; |
| 1900 | } |
| 1901 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1902 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1903 | * @phba: pointer to lpfc hba data structure. |
| 1904 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1905 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1906 | * |
| 1907 | * This routine is the completion callback function for issuing the Port |
| 1908 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1909 | * ndlp on the vport node list that matches the remote node ID from the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1910 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1911 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1912 | * checked for error conditons. If there is error status reported, PLOGI |
| 1913 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1914 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1915 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1916 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1917 | * there are additional N_Port nodes with the vport that need to perform |
| 1918 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1919 | * PLOGIs. |
| 1920 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1923 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1925 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1926 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | IOCB_t *irsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 1928 | struct lpfc_nodelist *ndlp, *free_ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1929 | struct lpfc_dmabuf *prsp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 1930 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1933 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1934 | |
| 1935 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1936 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1937 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1938 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1939 | irsp->un.elsreq64.remoteID); |
| 1940 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1941 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1942 | if (!ndlp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1943 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1944 | "0136 PLOGI completes to NPort x%x " |
| 1945 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1946 | irsp->un.elsreq64.remoteID, |
| 1947 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1948 | irsp->ulpIoTag); |
James Smart | 9d8de441 | 2020-11-30 10:12:26 -0800 | [diff] [blame] | 1949 | goto out_freeiocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1950 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | |
| 1952 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1953 | * is being used during discovery. |
| 1954 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1955 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1957 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1958 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | |
| 1960 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1962 | "0102 PLOGI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1963 | "Data: x%x x%x x%x x%x x%x\n", |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1964 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
| 1965 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1966 | disc, vport->num_disc_nodes); |
| 1967 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | if (lpfc_els_chk_latt(vport)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1970 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1972 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | goto out; |
| 1974 | } |
| 1975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | if (irsp->ulpStatus) { |
| 1977 | /* Check for retry */ |
| 1978 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1979 | /* ELS command is being retried */ |
| 1980 | if (disc) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1981 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 1983 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | } |
| 1985 | goto out; |
| 1986 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1987 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1988 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1989 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1990 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1991 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1992 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1993 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1994 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1995 | irsp->un.ulpWord[4]); |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 1996 | |
| 1997 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
| 1998 | if (lpfc_error_lost_link(irsp)) |
| 1999 | goto check_plogi; |
| 2000 | else |
| 2001 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2002 | NLP_EVT_CMPL_PLOGI); |
| 2003 | |
| 2004 | /* As long as this node is not registered with the scsi or nvme |
| 2005 | * transport, it is no longer an active node. Otherwise |
| 2006 | * devloss handles the final cleanup. |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2007 | */ |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2008 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { |
| 2009 | spin_lock_irq(&ndlp->lock); |
| 2010 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 2011 | spin_unlock_irq(&ndlp->lock); |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2012 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2013 | NLP_EVT_DEVICE_RM); |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2014 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | } else { |
| 2016 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 2017 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2018 | cmdiocb->context2)->list.next, |
| 2019 | struct lpfc_dmabuf, list); |
| 2020 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 2021 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2022 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | } |
| 2024 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2025 | check_plogi: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2026 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2030 | if (vport->num_disc_nodes == 0) { |
| 2031 | spin_lock_irq(shost->host_lock); |
| 2032 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2033 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2034 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2035 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2036 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | out: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2041 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 2042 | "PLOGI Cmpl PUT: did:x%x refcnt %d", |
| 2043 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2044 | |
James Smart | 9d8de441 | 2020-11-30 10:12:26 -0800 | [diff] [blame] | 2045 | out_freeiocb: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2046 | /* Release the reference on the original I/O request. */ |
| 2047 | free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
| 2048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2050 | lpfc_nlp_put(free_ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | return; |
| 2052 | } |
| 2053 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2054 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2055 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2056 | * @vport: pointer to a host virtual N_Port data structure. |
| 2057 | * @did: destination port identifier. |
| 2058 | * @retry: number of retries to the command IOCB. |
| 2059 | * |
| 2060 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 2061 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 2062 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 2063 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 2064 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 2065 | * |
| 2066 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2067 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2068 | * will be stored into the context1 field of the IOCB for the completion |
| 2069 | * callback function to the PLOGI ELS command. |
| 2070 | * |
| 2071 | * Return code |
| 2072 | * 0 - Successfully issued a plogi for @vport |
| 2073 | * 1 - failed to issue a plogi for @vport |
| 2074 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2076 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | struct serv_parm *sp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2080 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | uint8_t *pcmd; |
| 2083 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2084 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2086 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2087 | |
| 2088 | if (ndlp) { |
| 2089 | /* Defer the processing of the issue PLOGI until after the |
| 2090 | * outstanding UNREG_RPI mbox command completes, unless we |
| 2091 | * are going offline. This logic does not apply for Fabric DIDs |
| 2092 | */ |
| 2093 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2094 | ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && |
| 2095 | !(vport->fc_flag & FC_OFFLINE_MODE)) { |
| 2096 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2097 | "4110 Issue PLOGI x%x deferred " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2098 | "on NPort x%x rpi x%x Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2099 | ndlp->nlp_defer_did, ndlp->nlp_DID, |
| 2100 | ndlp->nlp_rpi, ndlp); |
| 2101 | |
| 2102 | /* We can only defer 1st PLOGI */ |
| 2103 | if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) |
| 2104 | ndlp->nlp_defer_did = did; |
| 2105 | return 0; |
| 2106 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2107 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2108 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2109 | /* If ndlp is not NULL, we will bump the reference count on it */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2110 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2111 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2112 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2113 | if (!elsiocb) |
| 2114 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2116 | spin_lock_irq(&ndlp->lock); |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2117 | ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2118 | spin_unlock_irq(&ndlp->lock); |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 2119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2121 | |
| 2122 | /* For PLOGI request, remainder of payload is service parameters */ |
| 2123 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2124 | pcmd += sizeof(uint32_t); |
| 2125 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | sp = (struct serv_parm *) pcmd; |
| 2127 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2128 | /* |
| 2129 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 2130 | * to device on remote loops work. |
| 2131 | */ |
| 2132 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 2133 | sp->cmn.altBbCredit = 1; |
| 2134 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 2136 | sp->cmn.fcphLow = FC_PH_4_3; |
| 2137 | |
| 2138 | if (sp->cmn.fcphHigh < FC_PH3) |
| 2139 | sp->cmn.fcphHigh = FC_PH3; |
| 2140 | |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2141 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2142 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 2143 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 2144 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2145 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2146 | "Issue PLOGI: did:x%x", |
| 2147 | did, 0, 0); |
| 2148 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2149 | /* If our firmware supports this feature, convey that |
| 2150 | * information to the target using the vendor specific field. |
| 2151 | */ |
| 2152 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 2153 | sp->cmn.valid_vendor_ver_level = 1; |
| 2154 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 2155 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 2156 | } |
| 2157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | phba->fc_stat.elsXmitPLOGI++; |
| 2159 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2160 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2161 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2162 | "Issue PLOGI: did:x%x refcnt %d", |
| 2163 | did, kref_read(&ndlp->kref), 0); |
| 2164 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2165 | if (!elsiocb->context1) |
| 2166 | goto io_err; |
| 2167 | |
| 2168 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2169 | if (ret) { |
| 2170 | lpfc_nlp_put(ndlp); |
| 2171 | goto io_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2173 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2174 | |
| 2175 | io_err: |
| 2176 | lpfc_els_free_iocb(phba, elsiocb); |
| 2177 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | } |
| 2179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2180 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2181 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2182 | * @phba: pointer to lpfc hba data structure. |
| 2183 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2184 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2185 | * |
| 2186 | * This routine is the completion callback function for a Process Login |
| 2187 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 2188 | * status. If there is error status reported, PRLI retry shall be attempted |
| 2189 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 2190 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 2191 | * ndlp to mark the PRLI completion. |
| 2192 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2194 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2195 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2197 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | struct lpfc_nodelist *ndlp; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2200 | char *mode; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2201 | u32 loglevel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2204 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2205 | |
| 2206 | irsp = &(rspiocb->iocb); |
| 2207 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2208 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2210 | |
| 2211 | /* Driver supports multiple FC4 types. Counters matter. */ |
| 2212 | vport->fc_prli_sent--; |
| 2213 | ndlp->fc4_prli_sent--; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2214 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2216 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2217 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 2218 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2219 | ndlp->nlp_DID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2220 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2222 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2223 | "0103 PRLI completes to NPort x%06x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2224 | "Data: x%x x%x x%x x%x\n", |
| 2225 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2226 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2229 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | goto out; |
| 2231 | |
| 2232 | if (irsp->ulpStatus) { |
| 2233 | /* Check for retry */ |
| 2234 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2235 | /* ELS command is being retried */ |
| 2236 | goto out; |
| 2237 | } |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2238 | |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2239 | /* If we don't send GFT_ID to Fabric, a PRLI error |
| 2240 | * could be expected. |
| 2241 | */ |
| 2242 | if ((vport->fc_flag & FC_FABRIC) || |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2243 | (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) { |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2244 | mode = KERN_ERR; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2245 | loglevel = LOG_TRACE_EVENT; |
| 2246 | } else { |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2247 | mode = KERN_INFO; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2248 | loglevel = LOG_ELS; |
| 2249 | } |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 2250 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | /* PRLI failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2252 | lpfc_printf_vlog(vport, mode, loglevel, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2253 | "2754 PRLI failure DID:%06X Status:x%x/x%x, " |
| 2254 | "data: x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2255 | ndlp->nlp_DID, irsp->ulpStatus, |
James Smart | 3120046 | 2017-05-15 15:20:42 -0700 | [diff] [blame] | 2256 | irsp->un.ulpWord[4], ndlp->fc4_prli_sent); |
| 2257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2259 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2261 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2262 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2263 | NLP_EVT_CMPL_PRLI); |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2264 | |
| 2265 | /* As long as this node is not registered with the SCSI |
| 2266 | * or NVMe transport and no other PRLIs are outstanding, |
| 2267 | * it is no longer an active node. Otherwise devloss |
| 2268 | * handles the final cleanup. |
| 2269 | */ |
| 2270 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) && |
| 2271 | !ndlp->fc4_prli_sent) { |
| 2272 | spin_lock_irq(&ndlp->lock); |
| 2273 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 2274 | spin_unlock_irq(&ndlp->lock); |
| 2275 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2276 | NLP_EVT_DEVICE_RM); |
| 2277 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2278 | } else { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2279 | /* Good status, call state machine. However, if another |
| 2280 | * PRLI is outstanding, don't call the state machine |
| 2281 | * because final disposition to Mapped or Unmapped is |
| 2282 | * completed there. |
| 2283 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2285 | NLP_EVT_CMPL_PRLI); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2286 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | out: |
| 2289 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2290 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | return; |
| 2292 | } |
| 2293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2295 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2296 | * @vport: pointer to a host virtual N_Port data structure. |
| 2297 | * @ndlp: pointer to a node-list data structure. |
| 2298 | * @retry: number of retries to the command IOCB. |
| 2299 | * |
| 2300 | * This routine issues a Process Login (PRLI) ELS command for the |
| 2301 | * @vport. The PRLI service parameters are set up in the payload of the |
| 2302 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 2303 | * is put to the IOCB completion callback func field before invoking the |
| 2304 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 2305 | * |
| 2306 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2307 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2308 | * will be stored into the context1 field of the IOCB for the completion |
| 2309 | * callback function to the PRLI ELS command. |
| 2310 | * |
| 2311 | * Return code |
| 2312 | * 0 - successfully issued prli iocb command for @vport |
| 2313 | * 1 - failed to issue prli iocb command for @vport |
| 2314 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2316 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | uint8_t retry) |
| 2318 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2319 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2322 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | uint8_t *pcmd; |
| 2325 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2326 | u32 local_nlp_type, elscmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | |
Dick Kennedy | 991f0c0 | 2017-08-23 16:55:39 -0700 | [diff] [blame] | 2328 | /* |
| 2329 | * If we are in RSCN mode, the FC4 types supported from a |
| 2330 | * previous GFT_ID command may not be accurate. So, if we |
| 2331 | * are a NVME Initiator, always look for the possibility of |
| 2332 | * the remote NPort beng a NVME Target. |
| 2333 | */ |
| 2334 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2335 | vport->fc_flag & FC_RSCN_MODE && |
| 2336 | vport->nvmei_support) |
| 2337 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2338 | local_nlp_type = ndlp->nlp_fc4_type; |
| 2339 | |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2340 | /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp |
| 2341 | * fields here before any of them can complete. |
| 2342 | */ |
| 2343 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 2344 | ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); |
| 2345 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2346 | ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC); |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2347 | ndlp->nvme_fb_size = 0; |
| 2348 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2349 | send_next_prli: |
| 2350 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2351 | /* Payload is 4 + 16 = 20 x14 bytes. */ |
| 2352 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
| 2353 | elscmd = ELS_CMD_PRLI; |
| 2354 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2355 | /* Payload is 4 + 20 = 24 x18 bytes. */ |
| 2356 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); |
| 2357 | elscmd = ELS_CMD_NVMEPRLI; |
| 2358 | } else { |
| 2359 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2360 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", |
| 2361 | ndlp->nlp_fc4_type, ndlp->nlp_DID); |
| 2362 | return 1; |
| 2363 | } |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2364 | |
| 2365 | /* SLI3 ports don't support NVME. If this rport is a strict NVME |
| 2366 | * FC4 type, implicitly LOGO. |
| 2367 | */ |
| 2368 | if (phba->sli_rev == LPFC_SLI_REV3 && |
| 2369 | ndlp->nlp_fc4_type == NLP_FC4_NVME) { |
| 2370 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2371 | "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n", |
| 2372 | ndlp->nlp_type); |
| 2373 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
| 2374 | return 1; |
| 2375 | } |
| 2376 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2378 | ndlp->nlp_DID, elscmd); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2379 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2380 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2383 | |
| 2384 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2385 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2387 | if (local_nlp_type & NLP_FC4_FCP) { |
| 2388 | /* Remainder of payload is FCP PRLI parameter page. |
| 2389 | * Note: this data structure is defined as |
| 2390 | * BE/LE in the structure definition so no |
| 2391 | * byte swap call is made. |
| 2392 | */ |
| 2393 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; |
| 2394 | pcmd += sizeof(uint32_t); |
| 2395 | npr = (PRLI *)pcmd; |
| 2396 | |
| 2397 | /* |
| 2398 | * If our firmware version is 3.20 or later, |
| 2399 | * set the following bits for FC-TAPE support. |
| 2400 | */ |
| 2401 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2402 | npr->ConfmComplAllowed = 1; |
| 2403 | npr->Retry = 1; |
| 2404 | npr->TaskRetryIdReq = 1; |
| 2405 | } |
| 2406 | npr->estabImagePair = 1; |
| 2407 | npr->readXferRdyDis = 1; |
| 2408 | if (vport->cfg_first_burst_size) |
| 2409 | npr->writeXferRdyDis = 1; |
| 2410 | |
| 2411 | /* For FCP support */ |
| 2412 | npr->prliType = PRLI_FCP_TYPE; |
| 2413 | npr->initiatorFunc = 1; |
| 2414 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; |
| 2415 | |
| 2416 | /* Remove FCP type - processed. */ |
| 2417 | local_nlp_type &= ~NLP_FC4_FCP; |
| 2418 | } else if (local_nlp_type & NLP_FC4_NVME) { |
| 2419 | /* Remainder of payload is NVME PRLI parameter page. |
| 2420 | * This data structure is the newer definition that |
| 2421 | * uses bf macros so a byte swap is required. |
| 2422 | */ |
| 2423 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; |
| 2424 | pcmd += sizeof(uint32_t); |
| 2425 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; |
| 2426 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 2427 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 2428 | if (phba->nsler) { |
| 2429 | bf_set(prli_nsler, npr_nvme, 1); |
| 2430 | bf_set(prli_conf, npr_nvme, 1); |
| 2431 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2432 | |
| 2433 | /* Only initiators request first burst. */ |
| 2434 | if ((phba->cfg_nvme_enable_fb) && |
| 2435 | !phba->nvmet_support) |
| 2436 | bf_set(prli_fba, npr_nvme, 1); |
| 2437 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2438 | if (phba->nvmet_support) { |
| 2439 | bf_set(prli_tgt, npr_nvme, 1); |
| 2440 | bf_set(prli_disc, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2441 | } else { |
| 2442 | bf_set(prli_init, npr_nvme, 1); |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2443 | bf_set(prli_conf, npr_nvme, 1); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 2444 | } |
James Smart | a5ff068 | 2018-01-30 15:58:56 -0800 | [diff] [blame] | 2445 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2446 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 2447 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 2448 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; |
| 2449 | |
| 2450 | /* Remove NVME type - processed. */ |
| 2451 | local_nlp_type &= ~NLP_FC4_NVME; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | |
| 2454 | phba->fc_stat.elsXmitPRLI++; |
| 2455 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2456 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 9de416a | 2017-12-08 17:18:07 -0800 | [diff] [blame] | 2458 | |
| 2459 | /* The vport counters are used for lpfc_scan_finished, but |
| 2460 | * the ndlp is used to track outstanding PRLIs for different |
| 2461 | * FC4 types. |
| 2462 | */ |
| 2463 | vport->fc_prli_sent++; |
| 2464 | ndlp->fc4_prli_sent++; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2465 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2466 | |
| 2467 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2468 | "Issue PRLI: did:x%x refcnt %d", |
| 2469 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2470 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2471 | if (!elsiocb->context1) |
| 2472 | goto io_err; |
| 2473 | |
| 2474 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2475 | if (rc == IOCB_ERROR) |
| 2476 | goto node_err; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2477 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2478 | |
| 2479 | /* The driver supports 2 FC4 types. Make sure |
| 2480 | * a PRLI is issued for all types before exiting. |
| 2481 | */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 2482 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2483 | local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2484 | goto send_next_prli; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2485 | else |
| 2486 | return 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 2487 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2488 | node_err: |
| 2489 | lpfc_nlp_put(ndlp); |
| 2490 | io_err: |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2491 | spin_lock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2492 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2493 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2494 | lpfc_els_free_iocb(phba, elsiocb); |
| 2495 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | } |
| 2497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2499 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2500 | * @vport: pointer to a host virtual N_Port data structure. |
| 2501 | * |
| 2502 | * This routine performs Registration State Change Notification (RSCN) |
| 2503 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2504 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2505 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2506 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2507 | * invoked to check and handle possible more RSCN came in during the period |
| 2508 | * of processing the current ones. |
| 2509 | **/ |
| 2510 | static void |
| 2511 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2512 | { |
| 2513 | lpfc_can_disctmo(vport); |
| 2514 | |
| 2515 | /* RSCN discovery */ |
| 2516 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2517 | if (vport->fc_npr_cnt) |
| 2518 | if (lpfc_els_disc_plogi(vport)) |
| 2519 | return; |
| 2520 | |
| 2521 | lpfc_end_rscn(vport); |
| 2522 | } |
| 2523 | |
| 2524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2525 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2526 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2527 | * |
| 2528 | * This function is called when the final ADISC is completed during discovery. |
| 2529 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2530 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2531 | * discovery. |
| 2532 | * This function is called with no locks held. |
| 2533 | **/ |
| 2534 | static void |
| 2535 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2536 | { |
| 2537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2538 | struct lpfc_hba *phba = vport->phba; |
| 2539 | |
| 2540 | /* |
| 2541 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2542 | * and continue discovery. |
| 2543 | */ |
| 2544 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2545 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2546 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | d454c91 | 2014-12-30 12:08:58 -0500 | [diff] [blame] | 2547 | /* The ADISCs are complete. Doesn't matter if they |
| 2548 | * succeeded or failed because the ADISC completion |
| 2549 | * routine guarantees to call the state machine and |
| 2550 | * the RPI is either unregistered (failed ADISC response) |
| 2551 | * or the RPI is still valid and the node is marked |
| 2552 | * mapped for a target. The exchanges should be in the |
| 2553 | * correct state. This code is specific to SLI3. |
| 2554 | */ |
| 2555 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2556 | lpfc_issue_reg_vpi(phba, vport); |
| 2557 | return; |
| 2558 | } |
| 2559 | /* |
| 2560 | * For SLI2, we need to set port_state to READY |
| 2561 | * and continue discovery. |
| 2562 | */ |
| 2563 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2564 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 2565 | lpfc_issue_clear_la(phba, vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2566 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2567 | vport->num_disc_nodes = 0; |
| 2568 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2569 | if (vport->fc_npr_cnt) |
| 2570 | lpfc_els_disc_plogi(vport); |
| 2571 | if (!vport->num_disc_nodes) { |
| 2572 | spin_lock_irq(shost->host_lock); |
| 2573 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2574 | spin_unlock_irq(shost->host_lock); |
| 2575 | lpfc_can_disctmo(vport); |
| 2576 | lpfc_end_rscn(vport); |
| 2577 | } |
| 2578 | } |
| 2579 | vport->port_state = LPFC_VPORT_READY; |
| 2580 | } else |
| 2581 | lpfc_rscn_disc(vport); |
| 2582 | } |
| 2583 | |
| 2584 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2585 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2586 | * @vport: pointer to a host virtual N_Port data structure. |
| 2587 | * |
| 2588 | * This routine determines whether there are more ndlps on a @vport |
| 2589 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2590 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2591 | * remaining nodes which need to have ADISC sent. |
| 2592 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2593 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2594 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2596 | if (vport->num_disc_nodes) |
| 2597 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2599 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2600 | "0210 Continue discovery with %d ADISCs to go " |
| 2601 | "Data: x%x x%x x%x\n", |
| 2602 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2603 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2606 | lpfc_set_disctmo(vport); |
| 2607 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2608 | lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2610 | if (!vport->num_disc_nodes) |
| 2611 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | return; |
| 2613 | } |
| 2614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2616 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2617 | * @phba: pointer to lpfc hba data structure. |
| 2618 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2619 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2620 | * |
| 2621 | * This routine is the completion function for issuing the Address Discover |
| 2622 | * (ADISC) command. It first checks to see whether link went down during |
| 2623 | * the discovery process. If so, the node will be marked as node port |
| 2624 | * recovery for issuing discover IOCB by the link attention handler and |
| 2625 | * exit. Otherwise, the response status is checked. If error was reported |
| 2626 | * in the response status, the ADISC command shall be retried by invoking |
| 2627 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2628 | * the response status, the state machine is invoked to set transition |
| 2629 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2632 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2633 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2638 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | |
| 2640 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2641 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2642 | |
| 2643 | irsp = &(rspiocb->iocb); |
| 2644 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2646 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2647 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2648 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2649 | ndlp->nlp_DID); |
| 2650 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2652 | * is being used during discovery. |
| 2653 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2654 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2656 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2657 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2659 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2660 | "0104 ADISC completes to NPort x%x " |
| 2661 | "Data: x%x x%x x%x x%x x%x\n", |
| 2662 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2663 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | if (lpfc_els_chk_latt(vport)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2666 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2668 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | goto out; |
| 2670 | } |
| 2671 | |
| 2672 | if (irsp->ulpStatus) { |
| 2673 | /* Check for retry */ |
| 2674 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2675 | /* ELS command is being retried */ |
| 2676 | if (disc) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2677 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2679 | spin_unlock_irq(&ndlp->lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2680 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | } |
| 2682 | goto out; |
| 2683 | } |
| 2684 | /* ADISC failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2685 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2686 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2687 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2688 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2690 | if (lpfc_error_lost_link(irsp)) |
| 2691 | goto check_adisc; |
| 2692 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2693 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2694 | NLP_EVT_CMPL_ADISC); |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2695 | |
| 2696 | /* As long as this node is not registered with the SCSI or NVMe |
| 2697 | * transport, it is no longer an active node. Otherwise |
| 2698 | * devloss handles the final cleanup. |
| 2699 | */ |
| 2700 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { |
| 2701 | spin_lock_irq(&ndlp->lock); |
| 2702 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 2703 | spin_unlock_irq(&ndlp->lock); |
| 2704 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2705 | NLP_EVT_DEVICE_RM); |
| 2706 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2707 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2712 | check_adisc: |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2713 | /* Check to see if there are more ADISCs to be sent */ |
| 2714 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2715 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | out: |
| 2717 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2718 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | return; |
| 2720 | } |
| 2721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2722 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2723 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2724 | * @vport: pointer to a virtual N_Port data structure. |
| 2725 | * @ndlp: pointer to a node-list data structure. |
| 2726 | * @retry: number of retries to the command IOCB. |
| 2727 | * |
| 2728 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2729 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2730 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2731 | * to issue the ADISC ELS command. |
| 2732 | * |
| 2733 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2734 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2735 | * will be stored into the context1 field of the IOCB for the completion |
| 2736 | * callback function to the ADISC ELS command. |
| 2737 | * |
| 2738 | * Return code |
| 2739 | * 0 - successfully issued adisc |
| 2740 | * 1 - failed to issue adisc |
| 2741 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | uint8_t retry) |
| 2745 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2746 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2747 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | ADISC *ap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2749 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | uint8_t *pcmd; |
| 2751 | uint16_t cmdsize; |
| 2752 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2753 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2755 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2756 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2757 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2760 | |
| 2761 | /* For ADISC request, remainder of payload is service parameters */ |
| 2762 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2763 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | |
| 2765 | /* Fill in ADISC payload */ |
| 2766 | ap = (ADISC *) pcmd; |
| 2767 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2768 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2769 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2770 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | |
| 2772 | phba->fc_stat.elsXmitADISC++; |
| 2773 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2774 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2776 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2777 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2778 | if (!elsiocb->context1) |
| 2779 | goto node_err; |
| 2780 | |
| 2781 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2782 | "Issue ADISC: did:x%x refcnt %d", |
| 2783 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 2784 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 2785 | if (rc == IOCB_ERROR) |
| 2786 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2787 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2788 | |
| 2789 | io_err: |
| 2790 | lpfc_nlp_put(ndlp); |
| 2791 | node_err: |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2792 | spin_lock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2793 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2794 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2795 | lpfc_els_free_iocb(phba, elsiocb); |
| 2796 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2797 | } |
| 2798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2800 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2801 | * @phba: pointer to lpfc hba data structure. |
| 2802 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2803 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2804 | * |
| 2805 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2806 | * command. If no error status was reported from the LOGO response, the |
| 2807 | * state machine of the associated ndlp shall be invoked for transition with |
| 2808 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2809 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2810 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2812 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2813 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2815 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2816 | struct lpfc_vport *vport = ndlp->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | IOCB_t *irsp; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2818 | unsigned long flags; |
| 2819 | uint32_t skip_recovery = 0; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame^] | 2820 | int wake_up_waiter = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2823 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2824 | |
| 2825 | irsp = &(rspiocb->iocb); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2826 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame^] | 2828 | if (ndlp->upcall_flags & NLP_WAIT_FOR_LOGO) { |
| 2829 | wake_up_waiter = 1; |
| 2830 | ndlp->upcall_flags &= ~NLP_WAIT_FOR_LOGO; |
| 2831 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2832 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2834 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2835 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2836 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2837 | ndlp->nlp_DID); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2838 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2840 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2841 | "0105 LOGO completes to NPort x%x " |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2842 | "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n", |
| 2843 | ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag, |
| 2844 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2845 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2847 | if (lpfc_els_chk_latt(vport)) { |
| 2848 | skip_recovery = 1; |
| 2849 | goto out; |
| 2850 | } |
| 2851 | |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2852 | /* The LOGO will not be retried on failure. A LOGO was |
| 2853 | * issued to the remote rport and a ACC or RJT or no Answer are |
| 2854 | * all acceptable. Note the failure and move forward with |
| 2855 | * discovery. The PLOGI will retry. |
| 2856 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | if (irsp->ulpStatus) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | /* LOGO failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2859 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2860 | "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2861 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2862 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2864 | if (lpfc_error_lost_link(irsp)) { |
| 2865 | skip_recovery = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | goto out; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | /* Call state machine. This will unregister the rpi if needed. */ |
| 2871 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| 2872 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2873 | /* The driver sets this flag for an NPIV instance that doesn't want to |
| 2874 | * log into the remote port. |
| 2875 | */ |
| 2876 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2877 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2878 | NLP_EVT_DEVICE_RM); |
| 2879 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2880 | lpfc_nlp_put(ndlp); |
| 2881 | |
| 2882 | /* Presume the node was released. */ |
| 2883 | return; |
| 2884 | } |
| 2885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | out: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2887 | /* Driver is done with the IO. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2889 | lpfc_nlp_put(ndlp); |
| 2890 | |
James Smart | 8e062ce | 2021-01-04 10:02:26 -0800 | [diff] [blame] | 2891 | /* At this point, the LOGO processing is complete. NOTE: For a |
| 2892 | * pt2pt topology, we are assuming the NPortID will only change |
| 2893 | * on link up processing. For a LOGO / PLOGI initiated by the |
| 2894 | * Initiator, we are assuming the NPortID is not going to change. |
| 2895 | */ |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2896 | |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame^] | 2897 | if (wake_up_waiter && ndlp->logo_waitq) |
| 2898 | wake_up(ndlp->logo_waitq); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2899 | /* |
| 2900 | * If the node is a target, the handling attempts to recover the port. |
| 2901 | * For any other port type, the rpi is unregistered as an implicit |
| 2902 | * LOGO. |
| 2903 | */ |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2904 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) && |
| 2905 | skip_recovery == 0) { |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2906 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2907 | spin_lock_irqsave(&ndlp->lock, flags); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2908 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2909 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2910 | |
| 2911 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2912 | "3187 LOGO completes to NPort x%x: Start " |
| 2913 | "Recovery Data: x%x x%x x%x x%x\n", |
| 2914 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2915 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 2916 | vport->num_disc_nodes); |
| 2917 | lpfc_disc_start(vport); |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2918 | return; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2919 | } |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 2920 | |
| 2921 | /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the |
| 2922 | * driver sends a LOGO to the rport to cleanup. For fabric and |
| 2923 | * initiator ports cleanup the node as long as it the node is not |
| 2924 | * register with the transport. |
| 2925 | */ |
| 2926 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { |
| 2927 | spin_lock_irq(&ndlp->lock); |
| 2928 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 2929 | spin_unlock_irq(&ndlp->lock); |
| 2930 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2931 | NLP_EVT_DEVICE_RM); |
| 2932 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | } |
| 2934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2935 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2936 | * lpfc_issue_els_logo - Issue a logo to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2937 | * @vport: pointer to a virtual N_Port data structure. |
| 2938 | * @ndlp: pointer to a node-list data structure. |
| 2939 | * @retry: number of retries to the command IOCB. |
| 2940 | * |
| 2941 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2942 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2943 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2944 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2945 | * |
| 2946 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2947 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2948 | * will be stored into the context1 field of the IOCB for the completion |
| 2949 | * callback function to the LOGO ELS command. |
| 2950 | * |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 2951 | * Callers of this routine are expected to unregister the RPI first |
| 2952 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2953 | * Return code |
| 2954 | * 0 - successfully issued logo |
| 2955 | * 1 - failed to issue logo |
| 2956 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2958 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | uint8_t retry) |
| 2960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2961 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | uint8_t *pcmd; |
| 2964 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2965 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2967 | spin_lock_irq(&ndlp->lock); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2968 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2969 | spin_unlock_irq(&ndlp->lock); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2970 | return 0; |
| 2971 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2972 | spin_unlock_irq(&ndlp->lock); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2973 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2974 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2975 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2976 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2977 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2981 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2982 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | |
| 2984 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2985 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2986 | pcmd += sizeof(uint32_t); |
| 2987 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | |
| 2989 | phba->fc_stat.elsXmitLOGO++; |
| 2990 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2991 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 2993 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2994 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2995 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 2996 | if (!elsiocb->context1) |
| 2997 | goto node_err; |
| 2998 | |
| 2999 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3000 | "Issue LOGO: did:x%x refcnt %d", |
| 3001 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3002 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3003 | if (rc == IOCB_ERROR) |
| 3004 | goto io_err; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 3005 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3006 | spin_lock_irq(&ndlp->lock); |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 3007 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3008 | spin_unlock_irq(&ndlp->lock); |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 3009 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3010 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3011 | |
| 3012 | io_err: |
| 3013 | lpfc_nlp_put(ndlp); |
| 3014 | node_err: |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3015 | spin_lock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3016 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3017 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3018 | lpfc_els_free_iocb(phba, elsiocb); |
| 3019 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3023 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3024 | * @phba: pointer to lpfc hba data structure. |
| 3025 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3026 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3027 | * |
| 3028 | * This routine is a generic completion callback function for ELS commands. |
| 3029 | * Specifically, it is the callback function which does not need to perform |
| 3030 | * any command specific operations. It is currently used by the ELS command |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3031 | * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel |
| 3032 | * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). |
| 3033 | * Other than certain debug loggings, this callback function simply invokes the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3034 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 3035 | * discovery process. |
| 3036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3037 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3039 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3041 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3042 | struct lpfc_nodelist *free_ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3043 | IOCB_t *irsp; |
| 3044 | |
| 3045 | irsp = &rspiocb->iocb; |
| 3046 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3047 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3048 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3049 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3050 | irsp->un.elsreq64.remoteID); |
| 3051 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3053 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3054 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 3055 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3056 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3057 | |
| 3058 | /* Check to see if link went down during discovery */ |
| 3059 | lpfc_els_chk_latt(vport); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3060 | |
| 3061 | free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
| 3062 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3063 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3064 | lpfc_nlp_put(free_ndlp); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | /** |
| 3068 | * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd |
| 3069 | * @phba: pointer to lpfc hba data structure. |
| 3070 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3071 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3072 | * |
| 3073 | * This routine is a generic completion callback function for Discovery ELS cmd. |
| 3074 | * Currently used by the ELS command issuing routines for the ELS State Change |
| 3075 | * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf(). |
| 3076 | * These commands will be retried once only for ELS timeout errors. |
| 3077 | **/ |
| 3078 | static void |
| 3079 | lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3080 | struct lpfc_iocbq *rspiocb) |
| 3081 | { |
| 3082 | struct lpfc_vport *vport = cmdiocb->vport; |
| 3083 | IOCB_t *irsp; |
| 3084 | struct lpfc_els_rdf_rsp *prdf; |
| 3085 | struct lpfc_dmabuf *pcmd, *prsp; |
| 3086 | u32 *pdata; |
| 3087 | u32 cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3088 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3089 | |
| 3090 | irsp = &rspiocb->iocb; |
| 3091 | |
| 3092 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3093 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 3094 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 3095 | irsp->un.elsreq64.remoteID); |
| 3096 | /* ELS cmd tag <ulpIoTag> completes */ |
| 3097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3098 | "0217 ELS cmd tag x%x completes Data: x%x x%x x%x " |
| 3099 | "x%x\n", |
| 3100 | irsp->ulpIoTag, irsp->ulpStatus, |
| 3101 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 3102 | cmdiocb->retry); |
| 3103 | |
| 3104 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3105 | if (!pcmd) |
| 3106 | goto out; |
| 3107 | |
| 3108 | pdata = (u32 *)pcmd->virt; |
| 3109 | if (!pdata) |
| 3110 | goto out; |
| 3111 | cmd = *pdata; |
| 3112 | |
| 3113 | /* Only 1 retry for ELS Timeout only */ |
| 3114 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 3115 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3116 | IOERR_SEQUENCE_TIMEOUT)) { |
| 3117 | cmdiocb->retry++; |
| 3118 | if (cmdiocb->retry <= 1) { |
| 3119 | switch (cmd) { |
| 3120 | case ELS_CMD_SCR: |
| 3121 | lpfc_issue_els_scr(vport, cmdiocb->retry); |
| 3122 | break; |
| 3123 | case ELS_CMD_RDF: |
| 3124 | cmdiocb->context1 = NULL; /* save ndlp refcnt */ |
| 3125 | lpfc_issue_els_rdf(vport, cmdiocb->retry); |
| 3126 | break; |
| 3127 | } |
| 3128 | goto out; |
| 3129 | } |
| 3130 | phba->fc_stat.elsRetryExceeded++; |
| 3131 | } |
| 3132 | if (irsp->ulpStatus) { |
| 3133 | /* ELS discovery cmd completes with error */ |
| 3134 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 3135 | "4203 ELS cmd x%x error: x%x x%X\n", cmd, |
| 3136 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
| 3137 | goto out; |
| 3138 | } |
| 3139 | |
| 3140 | /* The RDF response doesn't have any impact on the running driver |
| 3141 | * but the notification descriptors are dumped here for support. |
| 3142 | */ |
| 3143 | if (cmd == ELS_CMD_RDF) { |
| 3144 | int i; |
| 3145 | |
| 3146 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 3147 | if (!prsp) |
| 3148 | goto out; |
| 3149 | |
| 3150 | prdf = (struct lpfc_els_rdf_rsp *)prsp->virt; |
| 3151 | if (!prdf) |
| 3152 | goto out; |
| 3153 | |
| 3154 | for (i = 0; i < ELS_RDF_REG_TAG_CNT && |
| 3155 | i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++) |
| 3156 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
Colin Ian King | 162e250 | 2020-02-21 15:48:41 +0000 | [diff] [blame] | 3157 | "4677 Fabric RDF Notification Grant Data: " |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3158 | "0x%08x\n", |
| 3159 | be32_to_cpu( |
| 3160 | prdf->reg_d1.desc_tags[i])); |
| 3161 | } |
| 3162 | |
| 3163 | out: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3165 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3167 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | return; |
| 3169 | } |
| 3170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3172 | * lpfc_issue_els_scr - Issue a scr to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | * @vport: pointer to a host virtual N_Port data structure. |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3174 | * @retry: retry counter for the command IOCB. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3175 | * |
| 3176 | * This routine issues a State Change Request (SCR) to a fabric node |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3177 | * on a @vport. The remote node is Fabric Controller (0xfffffd). It |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3178 | * first search the @vport node list to find the matching ndlp. If no such |
| 3179 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 3180 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 3181 | * routine is invoked to send the SCR IOCB. |
| 3182 | * |
| 3183 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3184 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3185 | * will be stored into the context1 field of the IOCB for the completion |
| 3186 | * callback function to the SCR ELS command. |
| 3187 | * |
| 3188 | * Return code |
| 3189 | * 0 - Successfully issued scr command |
| 3190 | * 1 - Failed to issue scr command |
| 3191 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | int |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3193 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3195 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3196 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | uint8_t *pcmd; |
| 3199 | uint16_t cmdsize; |
| 3200 | struct lpfc_nodelist *ndlp; |
| 3201 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3202 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3204 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3205 | if (!ndlp) { |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3206 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3207 | if (!ndlp) |
| 3208 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3209 | lpfc_enqueue_node(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3210 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3212 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3213 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 3214 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3215 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3216 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3219 | |
| 3220 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3221 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | |
| 3223 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3224 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 3226 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3227 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3228 | "Issue SCR: did:x%x", |
| 3229 | ndlp->nlp_DID, 0, 0); |
| 3230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | phba->fc_stat.elsXmitSCR++; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3232 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3233 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3234 | if (!elsiocb->context1) |
| 3235 | goto node_err; |
| 3236 | |
| 3237 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3238 | "Issue SCR: did:x%x refcnt %d", |
| 3239 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 3240 | |
| 3241 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3242 | if (rc == IOCB_ERROR) |
| 3243 | goto io_err; |
| 3244 | |
| 3245 | /* Keep the ndlp just in case RDF is being sent */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3246 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3247 | |
| 3248 | io_err: |
| 3249 | lpfc_nlp_put(ndlp); |
| 3250 | node_err: |
| 3251 | lpfc_els_free_iocb(phba, elsiocb); |
| 3252 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | } |
| 3254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3255 | /** |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3256 | * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric) |
| 3257 | * or the other nport (pt2pt). |
| 3258 | * @vport: pointer to a host virtual N_Port data structure. |
| 3259 | * @retry: number of retries to the command IOCB. |
| 3260 | * |
| 3261 | * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD) |
| 3262 | * when connected to a fabric, or to the remote port when connected |
| 3263 | * in point-to-point mode. When sent to the Fabric Controller, it will |
| 3264 | * replay the RSCN to registered recipients. |
| 3265 | * |
| 3266 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3267 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3268 | * will be stored into the context1 field of the IOCB for the completion |
| 3269 | * callback function to the RSCN ELS command. |
| 3270 | * |
| 3271 | * Return code |
| 3272 | * 0 - Successfully issued RSCN command |
| 3273 | * 1 - Failed to issue RSCN command |
| 3274 | **/ |
| 3275 | int |
| 3276 | lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry) |
| 3277 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3278 | int rc = 0; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3279 | struct lpfc_hba *phba = vport->phba; |
| 3280 | struct lpfc_iocbq *elsiocb; |
| 3281 | struct lpfc_nodelist *ndlp; |
| 3282 | struct { |
| 3283 | struct fc_els_rscn rscn; |
| 3284 | struct fc_els_rscn_page portid; |
| 3285 | } *event; |
| 3286 | uint32_t nportid; |
| 3287 | uint16_t cmdsize = sizeof(*event); |
| 3288 | |
| 3289 | /* Not supported for private loop */ |
| 3290 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
| 3291 | !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 3292 | return 1; |
| 3293 | |
| 3294 | if (vport->fc_flag & FC_PT2PT) { |
| 3295 | /* find any mapped nport - that would be the other nport */ |
| 3296 | ndlp = lpfc_findnode_mapped(vport); |
| 3297 | if (!ndlp) |
| 3298 | return 1; |
| 3299 | } else { |
| 3300 | nportid = FC_FID_FCTRL; |
| 3301 | /* find the fabric controller node */ |
| 3302 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3303 | if (!ndlp) { |
| 3304 | /* if one didn't exist, make one */ |
| 3305 | ndlp = lpfc_nlp_init(vport, nportid); |
| 3306 | if (!ndlp) |
| 3307 | return 1; |
| 3308 | lpfc_enqueue_node(vport, ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3313 | ndlp->nlp_DID, ELS_CMD_RSCN_XMT); |
| 3314 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3315 | if (!elsiocb) |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3316 | return 1; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3317 | |
| 3318 | event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 3319 | |
| 3320 | event->rscn.rscn_cmd = ELS_RSCN; |
| 3321 | event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page); |
| 3322 | event->rscn.rscn_plen = cpu_to_be16(cmdsize); |
| 3323 | |
| 3324 | nportid = vport->fc_myDID; |
| 3325 | /* appears that page flags must be 0 for fabric to broadcast RSCN */ |
| 3326 | event->portid.rscn_page_flags = 0; |
| 3327 | event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16; |
| 3328 | event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8; |
| 3329 | event->portid.rscn_fid[2] = nportid & 0x000000FF; |
| 3330 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3331 | phba->fc_stat.elsXmitRSCN++; |
| 3332 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| 3333 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3334 | if (!elsiocb->context1) |
| 3335 | goto node_err; |
| 3336 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3337 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3338 | "Issue RSCN: did:x%x", |
| 3339 | ndlp->nlp_DID, 0, 0); |
| 3340 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3341 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3342 | if (rc == IOCB_ERROR) |
| 3343 | goto io_err; |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 3344 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3345 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3346 | * trigger the release of node. |
| 3347 | */ |
| 3348 | if (!(vport->fc_flag & FC_PT2PT)) |
| 3349 | lpfc_nlp_put(ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3350 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3351 | io_err: |
| 3352 | lpfc_nlp_put(ndlp); |
| 3353 | node_err: |
| 3354 | lpfc_els_free_iocb(phba, elsiocb); |
| 3355 | return 1; |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3359 | * lpfc_issue_els_farpr - Issue a farp to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3360 | * @vport: pointer to a host virtual N_Port data structure. |
| 3361 | * @nportid: N_Port identifier to the remote node. |
| 3362 | * @retry: number of retries to the command IOCB. |
| 3363 | * |
| 3364 | * This routine issues a Fibre Channel Address Resolution Response |
| 3365 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 3366 | * is passed into the function. It first search the @vport node list to find |
| 3367 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 3368 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 3369 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 3370 | * |
| 3371 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3372 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3373 | * will be stored into the context1 field of the IOCB for the completion |
| 3374 | * callback function to the PARPR ELS command. |
| 3375 | * |
| 3376 | * Return code |
| 3377 | * 0 - Successfully issued farpr command |
| 3378 | * 1 - Failed to issue farpr command |
| 3379 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3383 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | FARP *fp; |
| 3387 | uint8_t *pcmd; |
| 3388 | uint32_t *lp; |
| 3389 | uint16_t cmdsize; |
| 3390 | struct lpfc_nodelist *ondlp; |
| 3391 | struct lpfc_nodelist *ndlp; |
| 3392 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3393 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3395 | ndlp = lpfc_findnode_did(vport, nportid); |
| 3396 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3397 | ndlp = lpfc_nlp_init(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3398 | if (!ndlp) |
| 3399 | return 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3400 | lpfc_enqueue_node(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3401 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | |
| 3403 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3404 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3405 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3406 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3409 | |
| 3410 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3411 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | |
| 3413 | /* Fill in FARPR payload */ |
| 3414 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3415 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | lp = (uint32_t *) pcmd; |
| 3417 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | fp->Rflags = 0; |
| 3420 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 3421 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3422 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3423 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3424 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3425 | if (ondlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3427 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3429 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | } |
| 3431 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3432 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3433 | "Issue FARPR: did:x%x", |
| 3434 | ndlp->nlp_DID, 0, 0); |
| 3435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3436 | phba->fc_stat.elsXmitFARPR++; |
| 3437 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3438 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3439 | if (!elsiocb->context1) { |
| 3440 | lpfc_els_free_iocb(phba, elsiocb); |
| 3441 | return 1; |
| 3442 | } |
| 3443 | |
| 3444 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3445 | if (rc == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3446 | /* The additional lpfc_nlp_put will cause the following |
| 3447 | * lpfc_els_free_iocb routine to trigger the release of |
| 3448 | * the node. |
| 3449 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3450 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3452 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3454 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 3455 | * trigger the release of the node. |
| 3456 | */ |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3457 | /* Don't release reference count as RDF is likely outstanding */ |
| 3458 | return 0; |
| 3459 | } |
| 3460 | |
| 3461 | /** |
| 3462 | * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric. |
| 3463 | * @vport: pointer to a host virtual N_Port data structure. |
| 3464 | * @retry: retry counter for the command IOCB. |
| 3465 | * |
| 3466 | * This routine issues an ELS RDF to the Fabric Controller to register |
| 3467 | * for diagnostic functions. |
| 3468 | * |
| 3469 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3470 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3471 | * will be stored into the context1 field of the IOCB for the completion |
| 3472 | * callback function to the RDF ELS command. |
| 3473 | * |
| 3474 | * Return code |
| 3475 | * 0 - Successfully issued rdf command |
| 3476 | * 1 - Failed to issue rdf command |
| 3477 | **/ |
| 3478 | int |
| 3479 | lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry) |
| 3480 | { |
| 3481 | struct lpfc_hba *phba = vport->phba; |
| 3482 | struct lpfc_iocbq *elsiocb; |
| 3483 | struct lpfc_els_rdf_req *prdf; |
| 3484 | struct lpfc_nodelist *ndlp; |
| 3485 | uint16_t cmdsize; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3486 | int rc; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3487 | |
| 3488 | cmdsize = sizeof(*prdf); |
| 3489 | |
| 3490 | ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); |
| 3491 | if (!ndlp) { |
| 3492 | ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); |
| 3493 | if (!ndlp) |
| 3494 | return -ENODEV; |
| 3495 | lpfc_enqueue_node(vport, ndlp); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | /* RDF ELS is not required on an NPIV VN_Port. */ |
| 3499 | if (vport->port_type == LPFC_NPIV_PORT) { |
| 3500 | lpfc_nlp_put(ndlp); |
| 3501 | return -EACCES; |
| 3502 | } |
| 3503 | |
| 3504 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 3505 | ndlp->nlp_DID, ELS_CMD_RDF); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3506 | if (!elsiocb) |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3507 | return -ENOMEM; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3508 | |
| 3509 | /* Configure the payload for the supported FPIN events. */ |
| 3510 | prdf = (struct lpfc_els_rdf_req *) |
| 3511 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 3512 | memset(prdf, 0, cmdsize); |
| 3513 | prdf->rdf.fpin_cmd = ELS_RDF; |
| 3514 | prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) - |
| 3515 | sizeof(struct fc_els_rdf)); |
| 3516 | prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER); |
| 3517 | prdf->reg_d1.reg_desc.desc_len = cpu_to_be32( |
| 3518 | FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1)); |
| 3519 | prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT); |
| 3520 | prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY); |
James Smart | 441f6b5 | 2020-08-28 10:53:31 -0700 | [diff] [blame] | 3521 | prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY); |
| 3522 | prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST); |
| 3523 | prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION); |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3524 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3525 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3526 | "6444 Xmit RDF to remote NPORT x%x\n", |
| 3527 | ndlp->nlp_DID); |
| 3528 | |
| 3529 | elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3530 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 3531 | if (!elsiocb->context1) |
| 3532 | goto node_err; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 3533 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3534 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3535 | "Issue RDF: did:x%x refcnt %d", |
| 3536 | ndlp->nlp_DID, kref_read(&ndlp->kref), 0); |
| 3537 | |
| 3538 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3539 | if (rc == IOCB_ERROR) |
| 3540 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3541 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3542 | |
| 3543 | io_err: |
| 3544 | lpfc_nlp_put(ndlp); |
| 3545 | node_err: |
| 3546 | lpfc_els_free_iocb(phba, elsiocb); |
| 3547 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | } |
| 3549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3551 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3552 | * @vport: pointer to a host virtual N_Port data structure. |
| 3553 | * @nlp: pointer to a node-list data structure. |
| 3554 | * |
| 3555 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 3556 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 3557 | * removes the ELS retry event if it presents. In addition, if the |
| 3558 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 3559 | * commands are sent for the @vport's nodes that require issuing discovery |
| 3560 | * ADISC. |
| 3561 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3563 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3564 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3565 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3566 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3567 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3568 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 3569 | return; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3570 | spin_lock_irq(&nlp->lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3571 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3572 | spin_unlock_irq(&nlp->lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3573 | del_timer_sync(&nlp->nlp_delayfunc); |
| 3574 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3575 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3576 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3577 | /* Decrement nlp reference count held for the delayed retry */ |
| 3578 | evtp = &nlp->els_retry_evt; |
| 3579 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 3580 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3581 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3582 | spin_lock_irq(&nlp->lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3583 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3584 | spin_unlock_irq(&nlp->lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3585 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3586 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3587 | /* Check if there are more ADISCs to be sent */ |
| 3588 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3589 | } else { |
| 3590 | /* Check if there are more PLOGIs to be sent */ |
| 3591 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 3592 | if (vport->num_disc_nodes == 0) { |
| 3593 | spin_lock_irq(shost->host_lock); |
| 3594 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3595 | spin_unlock_irq(shost->host_lock); |
| 3596 | lpfc_can_disctmo(vport); |
| 3597 | lpfc_end_rscn(vport); |
| 3598 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | } |
| 3602 | return; |
| 3603 | } |
| 3604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3605 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3606 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 3607 | * @t: pointer to the timer function associated data (ndlp). |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3608 | * |
| 3609 | * This routine is invoked by the ndlp delayed-function timer to check |
| 3610 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 3611 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 3612 | * adds the delayed events to the HBA work list and invokes the |
| 3613 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 3614 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 3615 | * the work list to hold reference count of ndlp so that it guarantees the |
| 3616 | * reference to ndlp will still be available when the worker thread gets |
| 3617 | * to the event associated with the ndlp. |
| 3618 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 3619 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3620 | lpfc_els_retry_delay(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3622 | struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3623 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3624 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3625 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3630 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | return; |
| 3632 | } |
| 3633 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3634 | /* We need to hold the node by incrementing the reference |
| 3635 | * count until the queued work is done |
| 3636 | */ |
| 3637 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3638 | if (evtp->evt_arg1) { |
| 3639 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 3640 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3641 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3642 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3643 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | return; |
| 3645 | } |
| 3646 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3648 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3649 | * @ndlp: pointer to a node-list data structure. |
| 3650 | * |
| 3651 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 3652 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 3653 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 3654 | * function according to the delayed ELS command to retry the command. |
| 3655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | void |
| 3657 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 3658 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3660 | uint32_t cmd, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3662 | spin_lock_irq(&ndlp->lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3663 | cmd = ndlp->nlp_last_elscmd; |
| 3664 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | |
| 3666 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3667 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | return; |
| 3669 | } |
| 3670 | |
| 3671 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3672 | spin_unlock_irq(&ndlp->lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 3673 | /* |
| 3674 | * If a discovery event readded nlp_delayfunc after timer |
| 3675 | * firing and before processing the timer, cancel the |
| 3676 | * nlp_delayfunc. |
| 3677 | */ |
| 3678 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3680 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | |
| 3682 | switch (cmd) { |
| 3683 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3684 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | break; |
| 3686 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3687 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3688 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3689 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3690 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | break; |
| 3692 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3693 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3694 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3695 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3696 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | break; |
| 3698 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3699 | case ELS_CMD_NVMEPRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3701 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3702 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3703 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | break; |
| 3705 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3706 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3707 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 3708 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 3709 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3711 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3712 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 3713 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3714 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | } |
| 3716 | return; |
| 3717 | } |
| 3718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3719 | /** |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3720 | * lpfc_link_reset - Issue link reset |
| 3721 | * @vport: pointer to a virtual N_Port data structure. |
| 3722 | * |
| 3723 | * This routine performs link reset by sending INIT_LINK mailbox command. |
| 3724 | * For SLI-3 adapter, link attention interrupt is enabled before issuing |
| 3725 | * INIT_LINK mailbox command. |
| 3726 | * |
| 3727 | * Return code |
| 3728 | * 0 - Link reset initiated successfully |
| 3729 | * 1 - Failed to initiate link reset |
| 3730 | **/ |
| 3731 | int |
| 3732 | lpfc_link_reset(struct lpfc_vport *vport) |
| 3733 | { |
| 3734 | struct lpfc_hba *phba = vport->phba; |
| 3735 | LPFC_MBOXQ_t *mbox; |
| 3736 | uint32_t control; |
| 3737 | int rc; |
| 3738 | |
| 3739 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3740 | "2851 Attempt link reset\n"); |
| 3741 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3742 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3743 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3744 | "2852 Failed to allocate mbox memory"); |
| 3745 | return 1; |
| 3746 | } |
| 3747 | |
| 3748 | /* Enable Link attention interrupts */ |
| 3749 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3750 | spin_lock_irq(&phba->hbalock); |
| 3751 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3752 | control = readl(phba->HCregaddr); |
| 3753 | control |= HC_LAINT_ENA; |
| 3754 | writel(control, phba->HCregaddr); |
| 3755 | readl(phba->HCregaddr); /* flush */ |
| 3756 | spin_unlock_irq(&phba->hbalock); |
| 3757 | } |
| 3758 | |
| 3759 | lpfc_init_link(phba, mbox, phba->cfg_topology, |
| 3760 | phba->cfg_link_speed); |
| 3761 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3762 | mbox->vport = vport; |
| 3763 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 3764 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3765 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3766 | "2853 Failed to issue INIT_LINK " |
| 3767 | "mbox command, rc:x%x\n", rc); |
| 3768 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3769 | return 1; |
| 3770 | } |
| 3771 | |
| 3772 | return 0; |
| 3773 | } |
| 3774 | |
| 3775 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3776 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3777 | * @phba: pointer to lpfc hba data structure. |
| 3778 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3779 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3780 | * |
| 3781 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 3782 | * failed. The following ELS IOCBs use this function for retrying the command |
| 3783 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 3784 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 3785 | * returned error status, it makes the decision whether a retry shall be |
| 3786 | * issued for the command, and whether a retry shall be made immediately or |
| 3787 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 3788 | * is called to retry the command. In the later case, the ELS command shall |
| 3789 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 3790 | * ndlp for the delayed command issusing. |
| 3791 | * |
| 3792 | * Return code |
| 3793 | * 0 - No retry of els command is made |
| 3794 | * 1 - Immediate or delayed retry of els command is made |
| 3795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3797 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3798 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3800 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | IOCB_t *irsp = &rspiocb->iocb; |
| 3802 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3803 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | uint32_t *elscmd; |
| 3805 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3807 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3809 | uint32_t did; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3810 | int link_reset = 0, rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3812 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | /* Note: context2 may be 0 for internal driver abort |
| 3814 | * of delays ELS command. |
| 3815 | */ |
| 3816 | |
| 3817 | if (pcmd && pcmd->virt) { |
| 3818 | elscmd = (uint32_t *) (pcmd->virt); |
| 3819 | cmd = *elscmd++; |
| 3820 | } |
| 3821 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3822 | if (ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3823 | did = ndlp->nlp_DID; |
| 3824 | else { |
| 3825 | /* We should only hit this case for retrying PLOGI */ |
| 3826 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3828 | if (!ndlp && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3829 | return 1; |
| 3830 | } |
| 3831 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3832 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3833 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 3834 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 3835 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | switch (irsp->ulpStatus) { |
| 3837 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3839 | case IOSTAT_REMOTE_STOP: |
| 3840 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3841 | /* This IO was aborted by the target, we don't |
| 3842 | * know the rxid and because we did not send the |
| 3843 | * ABTS we cannot generate and RRQ. |
| 3844 | */ |
| 3845 | lpfc_set_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3846 | cmdiocb->sli4_lxritag, 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3847 | } |
| 3848 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | case IOSTAT_LOCAL_REJECT: |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3850 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3852 | if (cmd == ELS_CMD_FLOGI) { |
| 3853 | if (PCI_DEVICE_ID_HORNET == |
| 3854 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3855 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3856 | phba->pport->fc_myDID = 0; |
| 3857 | phba->alpa_map[0] = 0; |
| 3858 | phba->alpa_map[1] = 0; |
| 3859 | } |
| 3860 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3861 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3862 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | retry = 1; |
| 3864 | break; |
| 3865 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3866 | case IOERR_ILLEGAL_COMMAND: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3867 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3868 | "0124 Retry illegal cmd x%x " |
| 3869 | "retry:x%x delay:x%x\n", |
| 3870 | cmd, cmdiocb->retry, delay); |
| 3871 | retry = 1; |
| 3872 | /* All command's retry policy */ |
| 3873 | maxretry = 8; |
| 3874 | if (cmdiocb->retry > 2) |
| 3875 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3876 | break; |
| 3877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3879 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3880 | retry = 1; |
| 3881 | if (cmdiocb->retry > 100) |
| 3882 | delay = 100; |
| 3883 | maxretry = 250; |
| 3884 | break; |
| 3885 | |
| 3886 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3887 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | retry = 1; |
| 3889 | break; |
| 3890 | |
| 3891 | case IOERR_INVALID_RPI: |
James Smart | 5b5b36a | 2013-01-03 15:43:19 -0500 | [diff] [blame] | 3892 | if (cmd == ELS_CMD_PLOGI && |
| 3893 | did == NameServer_DID) { |
| 3894 | /* Continue forever if plogi to */ |
| 3895 | /* the nameserver fails */ |
| 3896 | maxretry = 0; |
| 3897 | delay = 100; |
| 3898 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | retry = 1; |
| 3900 | break; |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 3901 | |
| 3902 | case IOERR_SEQUENCE_TIMEOUT: |
| 3903 | if (cmd == ELS_CMD_PLOGI && |
| 3904 | did == NameServer_DID && |
| 3905 | (cmdiocb->retry + 1) == maxretry) { |
| 3906 | /* Reset the Link */ |
| 3907 | link_reset = 1; |
| 3908 | break; |
| 3909 | } |
| 3910 | retry = 1; |
| 3911 | delay = 100; |
| 3912 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | } |
| 3914 | break; |
| 3915 | |
| 3916 | case IOSTAT_NPORT_RJT: |
| 3917 | case IOSTAT_FABRIC_RJT: |
| 3918 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3919 | retry = 1; |
| 3920 | break; |
| 3921 | } |
| 3922 | break; |
| 3923 | |
| 3924 | case IOSTAT_NPORT_BSY: |
| 3925 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3926 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | retry = 1; |
| 3928 | break; |
| 3929 | |
| 3930 | case IOSTAT_LS_RJT: |
| 3931 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3932 | /* Added for Vendor specifc support |
| 3933 | * Just keep retrying for these Rsn / Exp codes |
| 3934 | */ |
| 3935 | switch (stat.un.b.lsRjtRsnCode) { |
| 3936 | case LSRJT_UNABLE_TPC: |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3937 | /* The driver has a VALID PLOGI but the rport has |
| 3938 | * rejected the PRLI - can't do it now. Delay |
Dick Kennedy | 678768d | 2020-08-03 14:02:26 -0700 | [diff] [blame] | 3939 | * for 1 second and try again. |
| 3940 | * |
| 3941 | * However, if explanation is REQ_UNSUPPORTED there's |
| 3942 | * no point to retry PRLI. |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3943 | */ |
Dick Kennedy | 678768d | 2020-08-03 14:02:26 -0700 | [diff] [blame] | 3944 | if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) && |
| 3945 | stat.un.b.lsRjtRsnCodeExp != |
| 3946 | LSEXP_REQ_UNSUPPORTED) { |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3947 | delay = 1000; |
| 3948 | maxretry = lpfc_max_els_tries + 1; |
| 3949 | retry = 1; |
| 3950 | break; |
| 3951 | } |
| 3952 | |
| 3953 | /* Legacy bug fix code for targets with PLOGI delays. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3955 | LSEXP_CMD_IN_PROGRESS) { |
| 3956 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3957 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | maxretry = 48; |
| 3959 | } |
| 3960 | retry = 1; |
| 3961 | break; |
| 3962 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3963 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3964 | LSEXP_CANT_GIVE_DATA) { |
| 3965 | if (cmd == ELS_CMD_PLOGI) { |
| 3966 | delay = 1000; |
| 3967 | maxretry = 48; |
| 3968 | } |
| 3969 | retry = 1; |
| 3970 | break; |
| 3971 | } |
James Smart | dea37e8 | 2017-06-01 21:07:07 -0700 | [diff] [blame] | 3972 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3973 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | maxretry = lpfc_max_els_tries + 1; |
| 3975 | retry = 1; |
| 3976 | break; |
| 3977 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3978 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3979 | (cmd == ELS_CMD_FDISC) && |
| 3980 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3981 | lpfc_printf_vlog(vport, KERN_ERR, |
| 3982 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3983 | "0125 FDISC Failed (x%x). " |
| 3984 | "Fabric out of resources\n", |
| 3985 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3986 | lpfc_vport_set_state(vport, |
| 3987 | FC_VPORT_NO_FABRIC_RSCS); |
| 3988 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | break; |
| 3990 | |
| 3991 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3992 | if ((cmd == ELS_CMD_PLOGI) || |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3993 | (cmd == ELS_CMD_PRLI) || |
| 3994 | (cmd == ELS_CMD_NVMEPRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3995 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3998 | /* FDISC retry policy */ |
| 3999 | maxretry = 48; |
| 4000 | if (cmdiocb->retry >= 32) |
| 4001 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | } |
| 4003 | retry = 1; |
| 4004 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4005 | |
| 4006 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4007 | /* There are some cases where switches return this |
| 4008 | * error when they are not ready and should be returning |
| 4009 | * Logical Busy. We should delay every time. |
| 4010 | */ |
| 4011 | if (cmd == ELS_CMD_FDISC && |
| 4012 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 4013 | maxretry = 3; |
| 4014 | delay = 1000; |
| 4015 | retry = 1; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4016 | } else if (cmd == ELS_CMD_FLOGI && |
| 4017 | stat.un.b.lsRjtRsnCodeExp == |
| 4018 | LSEXP_NOTHING_MORE) { |
| 4019 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 4020 | retry = 1; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4021 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4022 | LOG_TRACE_EVENT, |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4023 | "0820 FLOGI Failed (x%x). " |
| 4024 | "BBCredit Not Supported\n", |
| 4025 | stat.un.lsRjtError); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4026 | } |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4027 | break; |
| 4028 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4029 | case LSRJT_PROTOCOL_ERR: |
| 4030 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 4031 | (cmd == ELS_CMD_FDISC) && |
| 4032 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 4033 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 4034 | ) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4035 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4036 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4037 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4038 | "Fabric Detected Bad WWN\n", |
| 4039 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4040 | lpfc_vport_set_state(vport, |
| 4041 | FC_VPORT_FABRIC_REJ_WWN); |
| 4042 | } |
| 4043 | break; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4044 | case LSRJT_VENDOR_UNIQUE: |
| 4045 | if ((stat.un.b.vendorUnique == 0x45) && |
| 4046 | (cmd == ELS_CMD_FLOGI)) { |
| 4047 | goto out_retry; |
| 4048 | } |
| 4049 | break; |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 4050 | case LSRJT_CMD_UNSUPPORTED: |
| 4051 | /* lpfc nvmet returns this type of LS_RJT when it |
| 4052 | * receives an FCP PRLI because lpfc nvmet only |
| 4053 | * support NVME. ELS request is terminated for FCP4 |
| 4054 | * on this rport. |
| 4055 | */ |
| 4056 | if (stat.un.b.lsRjtRsnCodeExp == |
| 4057 | LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4058 | spin_lock_irq(&ndlp->lock); |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 4059 | ndlp->nlp_flag |= NLP_FCP_PRLI_RJT; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4060 | spin_unlock_irq(&ndlp->lock); |
Dick Kennedy | 8db1c2b | 2017-08-23 16:55:36 -0700 | [diff] [blame] | 4061 | retry = 0; |
| 4062 | goto out_retry; |
| 4063 | } |
| 4064 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | } |
| 4066 | break; |
| 4067 | |
| 4068 | case IOSTAT_INTERMED_RSP: |
| 4069 | case IOSTAT_BA_RJT: |
| 4070 | break; |
| 4071 | |
| 4072 | default: |
| 4073 | break; |
| 4074 | } |
| 4075 | |
James Smart | 5cca2ab | 2018-10-23 13:41:04 -0700 | [diff] [blame] | 4076 | if (link_reset) { |
| 4077 | rc = lpfc_link_reset(vport); |
| 4078 | if (rc) { |
| 4079 | /* Do not give up. Retry PLOGI one more time and attempt |
| 4080 | * link reset if PLOGI fails again. |
| 4081 | */ |
| 4082 | retry = 1; |
| 4083 | delay = 100; |
| 4084 | goto out_retry; |
| 4085 | } |
| 4086 | return 1; |
| 4087 | } |
| 4088 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4089 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4092 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4093 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4094 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4095 | /* FLOGI retry policy */ |
| 4096 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4097 | /* retry FLOGI forever */ |
James Smart | 6eae430 | 2015-04-07 15:07:23 -0400 | [diff] [blame] | 4098 | if (phba->link_flag != LS_LOOPBACK_MODE) |
| 4099 | maxretry = 0; |
| 4100 | else |
| 4101 | maxretry = 2; |
| 4102 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4103 | if (cmdiocb->retry >= 100) |
| 4104 | delay = 5000; |
| 4105 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4106 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4107 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 4108 | /* retry FDISCs every second up to devloss */ |
| 4109 | retry = 1; |
| 4110 | maxretry = vport->cfg_devloss_tmo; |
| 4111 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4112 | } |
| 4113 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4114 | cmdiocb->retry++; |
| 4115 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | phba->fc_stat.elsRetryExceeded++; |
| 4117 | retry = 0; |
| 4118 | } |
| 4119 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4120 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 4121 | retry = 0; |
| 4122 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4123 | out_retry: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4125 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 4126 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 4127 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 4128 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4129 | "2849 Stop retry ELS command " |
| 4130 | "x%x to remote NPORT x%x, " |
| 4131 | "Data: x%x x%x\n", cmd, did, |
| 4132 | cmdiocb->retry, delay); |
| 4133 | return 0; |
| 4134 | } |
| 4135 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 | |
| 4137 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4138 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4139 | "0107 Retry ELS command x%x to remote " |
| 4140 | "NPORT x%x Data: x%x x%x\n", |
| 4141 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4143 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 4144 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 4145 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
| 4146 | IOERR_NO_RESOURCES))) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4147 | /* Don't reset timer for no resources */ |
| 4148 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4151 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | phba->fc_stat.elsXmitRetry++; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4156 | if (ndlp && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | phba->fc_stat.elsDelayRetry++; |
| 4158 | ndlp->nlp_retry = cmdiocb->retry; |
| 4159 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4160 | /* delay is specified in milliseconds */ |
| 4161 | mod_timer(&ndlp->nlp_delayfunc, |
| 4162 | jiffies + msecs_to_jiffies(delay)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4163 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4165 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4167 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4168 | if ((cmd == ELS_CMD_PRLI) || |
| 4169 | (cmd == ELS_CMD_NVMEPRLI)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4170 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 4c1b64b | 2012-09-29 11:31:11 -0400 | [diff] [blame] | 4171 | NLP_STE_PRLI_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4172 | else |
| 4173 | lpfc_nlp_set_state(vport, ndlp, |
| 4174 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | ndlp->nlp_last_elscmd = cmd; |
| 4176 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4177 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | } |
| 4179 | switch (cmd) { |
| 4180 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4181 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4182 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | case ELS_CMD_FDISC: |
| 4184 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 4185 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | case ELS_CMD_PLOGI: |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4187 | if (ndlp) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4188 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4189 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4190 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4191 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4192 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4193 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4195 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4196 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4197 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4198 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4200 | case ELS_CMD_NVMEPRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4201 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 4203 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4204 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4206 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4207 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4209 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
| 4211 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4213 | if (logerr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4214 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4215 | "0137 No retry ELS command x%x to remote " |
| 4216 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 4217 | cmd, did, irsp->ulpStatus, |
| 4218 | irsp->un.ulpWord[4]); |
| 4219 | } |
| 4220 | else { |
| 4221 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4222 | "0108 No retry ELS command x%x to remote " |
| 4223 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 4224 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 4225 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4226 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4227 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | } |
| 4229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4231 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4232 | * @phba: pointer to lpfc hba data structure. |
| 4233 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 4234 | * |
| 4235 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 4236 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 4237 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 4238 | * response of the command IOCB. If so, it will be released before releasing |
| 4239 | * the lpfc DMA buffer associated with the IOCB itself. |
| 4240 | * |
| 4241 | * Return code |
| 4242 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4243 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4244 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4245 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 4246 | { |
| 4247 | struct lpfc_dmabuf *buf_ptr; |
| 4248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4249 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4250 | if (!list_empty(&buf_ptr1->list)) { |
| 4251 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 4252 | struct lpfc_dmabuf, |
| 4253 | list); |
| 4254 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4255 | kfree(buf_ptr); |
| 4256 | } |
| 4257 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 4258 | kfree(buf_ptr1); |
| 4259 | return 0; |
| 4260 | } |
| 4261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4263 | * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | * @phba: pointer to lpfc hba data structure. |
| 4265 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 4266 | * |
| 4267 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 4268 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 4269 | * pool. |
| 4270 | * |
| 4271 | * Return code |
| 4272 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 4273 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4274 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4275 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 4276 | { |
| 4277 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4278 | kfree(buf_ptr); |
| 4279 | return 0; |
| 4280 | } |
| 4281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4283 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4284 | * @phba: pointer to lpfc hba data structure. |
| 4285 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 4286 | * |
| 4287 | * This routine frees a command IOCB and its associated resources. The |
| 4288 | * command IOCB data structure contains the reference to various associated |
| 4289 | * resources, these fields must be set to NULL if the associated reference |
| 4290 | * not present: |
| 4291 | * context1 - reference to ndlp |
| 4292 | * context2 - reference to cmd |
| 4293 | * context2->next - reference to rsp |
| 4294 | * context3 - reference to bpl |
| 4295 | * |
| 4296 | * It first properly decrements the reference count held on ndlp for the |
| 4297 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 4298 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 4299 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 4300 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 4301 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 4302 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 4303 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 4304 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 4305 | * |
| 4306 | * Return code |
| 4307 | * 0 - Success (currently, always return 0) |
| 4308 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4309 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4310 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | { |
| 4312 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
| 4313 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4314 | /* The I/O job is complete. Clear the context1 data. */ |
| 4315 | elsiocb->context1 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 4318 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4319 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 4320 | /* Firmware could still be in progress of DMAing |
| 4321 | * payload, so don't free data buffer till after |
| 4322 | * a hbeat. |
| 4323 | */ |
| 4324 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 4325 | buf_ptr = elsiocb->context2; |
| 4326 | elsiocb->context2 = NULL; |
| 4327 | if (buf_ptr) { |
| 4328 | buf_ptr1 = NULL; |
| 4329 | spin_lock_irq(&phba->hbalock); |
| 4330 | if (!list_empty(&buf_ptr->list)) { |
| 4331 | list_remove_head(&buf_ptr->list, |
| 4332 | buf_ptr1, struct lpfc_dmabuf, |
| 4333 | list); |
| 4334 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 4335 | list_add_tail(&buf_ptr1->list, |
| 4336 | &phba->elsbuf); |
| 4337 | phba->elsbuf_cnt++; |
| 4338 | } |
| 4339 | INIT_LIST_HEAD(&buf_ptr->list); |
| 4340 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 4341 | phba->elsbuf_cnt++; |
| 4342 | spin_unlock_irq(&phba->hbalock); |
| 4343 | } |
| 4344 | } else { |
| 4345 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 4346 | lpfc_els_free_data(phba, buf_ptr1); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4347 | elsiocb->context2 = NULL; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4348 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | if (elsiocb->context3) { |
| 4352 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4353 | lpfc_els_free_bpl(phba, buf_ptr); |
Johannes Thumshirn | 8667f51 | 2017-01-10 12:05:54 +0100 | [diff] [blame] | 4354 | elsiocb->context3 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4356 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | return 0; |
| 4358 | } |
| 4359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4360 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4361 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4362 | * @phba: pointer to lpfc hba data structure. |
| 4363 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4364 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4365 | * |
| 4366 | * This routine is the completion callback function to the Logout (LOGO) |
| 4367 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 4368 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 4369 | * release the ndlp if it has the last reference remaining (reference count |
| 4370 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 4371 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 4372 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 4373 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 4374 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 4375 | * IOCB data structure. |
| 4376 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4378 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4379 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4382 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4383 | IOCB_t *irsp; |
| 4384 | |
| 4385 | irsp = &rspiocb->iocb; |
| 4386 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4387 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 4388 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4390 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 4391 | "0109 ACC to LOGO completes to NPort x%x refcnt %d" |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4392 | "Data: x%x x%x x%x\n", |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 4393 | ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag, |
| 4394 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4395 | |
| 4396 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 4397 | /* NPort Recovery mode or node is just allocated */ |
| 4398 | if (!lpfc_nlp_not_used(ndlp)) { |
| 4399 | /* If the ndlp is being used by another discovery |
| 4400 | * thread, just unregister the RPI. |
| 4401 | */ |
| 4402 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4403 | } else { |
| 4404 | /* Indicate the node has already released, should |
| 4405 | * not reference to it from within lpfc_els_free_iocb. |
| 4406 | */ |
| 4407 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4408 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4410 | |
| 4411 | /* |
| 4412 | * The driver received a LOGO from the rport and has ACK'd it. |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4413 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4414 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4416 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4417 | } |
| 4418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4420 | * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4421 | * @phba: pointer to lpfc hba data structure. |
| 4422 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4423 | * |
| 4424 | * This routine is the completion callback function for unregister default |
| 4425 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 4426 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 4427 | * decrements the ndlp reference count held for this completion callback |
| 4428 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 4429 | * whether there is only one reference left on the ndlp. If so, it will |
| 4430 | * perform one more decrement and trigger the release of the ndlp. |
| 4431 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4432 | void |
| 4433 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4434 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4435 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4436 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4437 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4438 | pmb->ctx_buf = NULL; |
| 4439 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4440 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4441 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4442 | kfree(mp); |
| 4443 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4444 | if (ndlp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4445 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 4446 | "0006 rpi x%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4447 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4448 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4449 | ndlp); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4450 | /* This is the end of the default RPI cleanup logic for |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 4451 | * this ndlp and it could get released. Clear the nlp_flags to |
| 4452 | * prevent any further processing. |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4453 | */ |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 4454 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 4455 | lpfc_nlp_put(ndlp); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4456 | lpfc_nlp_not_used(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4457 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4458 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4459 | return; |
| 4460 | } |
| 4461 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4462 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4463 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4464 | * @phba: pointer to lpfc hba data structure. |
| 4465 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4466 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 4467 | * |
| 4468 | * This routine is the completion callback function for ELS Response IOCB |
| 4469 | * command. In normal case, this callback function just properly sets the |
| 4470 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 4471 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 4472 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 4473 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 4474 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 4475 | * routine shall be invoked trying to release the ndlp if no other threads |
| 4476 | * are currently referring it. |
| 4477 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4478 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4479 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4480 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4483 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 4484 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4485 | IOCB_t *irsp; |
| 4486 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4489 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4491 | irsp = &rspiocb->iocb; |
| 4492 | |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4493 | if (!vport) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4494 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f84f8f9 | 2019-10-18 14:18:23 -0700 | [diff] [blame] | 4495 | "3177 ELS response failed\n"); |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4496 | goto out; |
| 4497 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | if (cmdiocb->context_un.mbox) |
| 4499 | mbox = cmdiocb->context_un.mbox; |
| 4500 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4501 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 4502 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 4503 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4504 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4505 | if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4506 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4507 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4508 | */ |
| 4509 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 4510 | ls_rjt = 1; |
| 4511 | } |
| 4512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | /* Check to see if link went down during discovery */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4514 | if (!ndlp || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4515 | if (mbox) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4516 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4517 | if (mp) { |
| 4518 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4519 | kfree(mp); |
| 4520 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4521 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4523 | if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4524 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4525 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4526 | /* Indicate the node has already released, |
| 4527 | * should not reference to it from within |
| 4528 | * the routine lpfc_els_free_iocb. |
| 4529 | */ |
| 4530 | cmdiocb->context1 = NULL; |
| 4531 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | goto out; |
| 4533 | } |
| 4534 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4535 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4536 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4537 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4538 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4540 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4541 | "0110 ELS response tag x%x completes " |
| 4542 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 4543 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 4544 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 4545 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4546 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | if (mbox) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4548 | if ((rspiocb->iocb.ulpStatus == 0) && |
| 4549 | (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4550 | if (!lpfc_unreg_rpi(vport, ndlp) && |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4551 | (!(vport->fc_flag & FC_PT2PT))) { |
| 4552 | if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) { |
| 4553 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4554 | LOG_DISCOVERY, |
| 4555 | "0314 PLOGI recov " |
| 4556 | "DID x%x " |
| 4557 | "Data: x%x x%x x%x\n", |
| 4558 | ndlp->nlp_DID, |
| 4559 | ndlp->nlp_state, |
| 4560 | ndlp->nlp_rpi, |
| 4561 | ndlp->nlp_flag); |
| 4562 | mp = mbox->ctx_buf; |
| 4563 | if (mp) { |
| 4564 | lpfc_mbuf_free(phba, mp->virt, |
| 4565 | mp->phys); |
| 4566 | kfree(mp); |
| 4567 | } |
| 4568 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4569 | goto out; |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4570 | } |
Dick Kennedy | 1fe6847 | 2017-08-23 16:55:30 -0700 | [diff] [blame] | 4571 | } |
| 4572 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4573 | /* Increment reference count to ndlp to hold the |
| 4574 | * reference to ndlp for the callback function. |
| 4575 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4576 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4577 | if (!mbox->ctx_ndlp) |
| 4578 | goto out; |
| 4579 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4580 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4581 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 4582 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4583 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4584 | } |
| 4585 | else { |
| 4586 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 4587 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 4588 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4589 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4590 | } |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4591 | |
| 4592 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4593 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4594 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | goto out; |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 4596 | |
| 4597 | /* Decrement the ndlp reference count we |
| 4598 | * set for this failed mailbox command. |
| 4599 | */ |
| 4600 | lpfc_nlp_put(ndlp); |
| 4601 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4602 | |
| 4603 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4604 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4605 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 4606 | "Data: x%x x%x x%x\n", |
| 4607 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4608 | ndlp->nlp_rpi); |
| 4609 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4610 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4611 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4612 | /* Indicate node has already been released, |
| 4613 | * should not reference to it from within |
| 4614 | * the routine lpfc_els_free_iocb. |
| 4615 | */ |
| 4616 | cmdiocb->context1 = NULL; |
| 4617 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4618 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4619 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 4620 | if (!lpfc_error_lost_link(irsp) && |
| 4621 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4622 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4623 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4624 | /* Indicate node has already been |
| 4625 | * released, should not reference |
| 4626 | * to it from within the routine |
| 4627 | * lpfc_els_free_iocb. |
| 4628 | */ |
| 4629 | cmdiocb->context1 = NULL; |
| 4630 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | } |
| 4632 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4633 | mp = (struct lpfc_dmabuf *)mbox->ctx_buf; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 4634 | if (mp) { |
| 4635 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4636 | kfree(mp); |
| 4637 | } |
| 4638 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4639 | } |
| 4640 | out: |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4641 | if (ndlp && shost) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4642 | spin_lock_irq(&ndlp->lock); |
James Smart | 7b08e89 | 2020-08-28 10:53:30 -0700 | [diff] [blame] | 4643 | if (mbox) |
| 4644 | ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; |
| 4645 | ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4646 | spin_unlock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4647 | |
| 4648 | /* If the node is not being used by another discovery thread, |
| 4649 | * and we are sending a reject, we are done with it. |
| 4650 | * Release driver reference count here and free associated |
| 4651 | * resources. |
| 4652 | */ |
| 4653 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4654 | if (lpfc_nlp_not_used(ndlp)) |
| 4655 | /* Indicate node has already been released, |
| 4656 | * should not reference to it from within |
| 4657 | * the routine lpfc_els_free_iocb. |
| 4658 | */ |
| 4659 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4661 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4662 | /* Release the originating I/O reference. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4664 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | return; |
| 4666 | } |
| 4667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4669 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4670 | * @vport: pointer to a host virtual N_Port data structure. |
| 4671 | * @flag: the els command code to be accepted. |
| 4672 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4673 | * @ndlp: pointer to a node-list data structure. |
| 4674 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4675 | * |
| 4676 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 4677 | * command. It uses the @flag to properly set up the IOCB field for the |
| 4678 | * specific ACC response command to be issued and invokes the |
| 4679 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 4680 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 4681 | * field of the IOCB for the completion callback function to issue the |
| 4682 | * mailbox command to the HBA later when callback is invoked. |
| 4683 | * |
| 4684 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4685 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4686 | * will be stored into the context1 field of the IOCB for the completion |
| 4687 | * callback function to the corresponding response ELS IOCB command. |
| 4688 | * |
| 4689 | * Return code |
| 4690 | * 0 - Successfully issued acc response |
| 4691 | * 1 - Failed to issue acc response |
| 4692 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 4695 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4696 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4697 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4698 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4699 | IOCB_t *icmd; |
| 4700 | IOCB_t *oldcmd; |
| 4701 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | uint8_t *pcmd; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4703 | struct serv_parm *sp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | uint16_t cmdsize; |
| 4705 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4706 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | oldcmd = &oldiocb->iocb; |
| 4709 | |
| 4710 | switch (flag) { |
| 4711 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4712 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4713 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4714 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4715 | if (!elsiocb) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4716 | spin_lock_irq(&ndlp->lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4717 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4718 | spin_unlock_irq(&ndlp->lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4719 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4721 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4723 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4724 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4725 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4726 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4727 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4728 | |
| 4729 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4730 | "Issue ACC: did:x%x flg:x%x", |
| 4731 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | break; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4733 | case ELS_CMD_FLOGI: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4735 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4736 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 4737 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4738 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4739 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4740 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4742 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4743 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4744 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4745 | |
| 4746 | if (mbox) |
| 4747 | elsiocb->context_un.mbox = mbox; |
| 4748 | |
| 4749 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4750 | pcmd += sizeof(uint32_t); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4751 | sp = (struct serv_parm *)pcmd; |
| 4752 | |
| 4753 | if (flag == ELS_CMD_FLOGI) { |
| 4754 | /* Copy the received service parameters back */ |
| 4755 | memcpy(sp, &phba->fc_fabparam, |
| 4756 | sizeof(struct serv_parm)); |
| 4757 | |
| 4758 | /* Clear the F_Port bit */ |
| 4759 | sp->cmn.fPort = 0; |
| 4760 | |
| 4761 | /* Mark all class service parameters as invalid */ |
| 4762 | sp->cls1.classValid = 0; |
| 4763 | sp->cls2.classValid = 0; |
| 4764 | sp->cls3.classValid = 0; |
| 4765 | sp->cls4.classValid = 0; |
| 4766 | |
| 4767 | /* Copy our worldwide names */ |
| 4768 | memcpy(&sp->portName, &vport->fc_sparam.portName, |
| 4769 | sizeof(struct lpfc_name)); |
| 4770 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, |
| 4771 | sizeof(struct lpfc_name)); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4772 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4773 | memcpy(pcmd, &vport->fc_sparam, |
| 4774 | sizeof(struct serv_parm)); |
James Smart | e0165f2 | 2016-12-19 15:07:20 -0800 | [diff] [blame] | 4775 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4776 | sp->cmn.valid_vendor_ver_level = 0; |
| 4777 | memset(sp->un.vendorVersion, 0, |
| 4778 | sizeof(sp->un.vendorVersion)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 4779 | sp->cmn.bbRcvSizeMsb &= 0xF; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4780 | |
| 4781 | /* If our firmware supports this feature, convey that |
| 4782 | * info to the target using the vendor specific field. |
| 4783 | */ |
| 4784 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { |
| 4785 | sp->cmn.valid_vendor_ver_level = 1; |
| 4786 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); |
| 4787 | sp->un.vv.flags = |
| 4788 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); |
| 4789 | } |
| 4790 | } |
| 4791 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4792 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 4793 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4794 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4795 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4796 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4797 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4798 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4799 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 4800 | if (!elsiocb) |
| 4801 | return 1; |
| 4802 | |
| 4803 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4804 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4805 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4806 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4807 | |
| 4808 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4809 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4810 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 4811 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 4812 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4813 | |
| 4814 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4815 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 4816 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 4817 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4818 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4819 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4822 | spin_lock_irq(&ndlp->lock); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4823 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4824 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) |
| 4825 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4826 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4827 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 4828 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4829 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4833 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 4834 | if (!elsiocb->context1) |
| 4835 | goto node_err; |
| 4836 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4837 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4838 | if (rc == IOCB_ERROR) |
| 4839 | goto io_err; |
| 4840 | |
| 4841 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 4842 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4843 | "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " |
| 4844 | "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x " |
| 4845 | "RPI: x%x, fc_flag x%x\n", |
| 4846 | rc, elsiocb->iotag, elsiocb->sli4_xritag, |
| 4847 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4848 | ndlp->nlp_rpi, vport->fc_flag); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4849 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4850 | |
| 4851 | io_err: |
| 4852 | lpfc_nlp_put(ndlp); |
| 4853 | node_err: |
| 4854 | lpfc_els_free_iocb(phba, elsiocb); |
| 4855 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | } |
| 4857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4858 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4859 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4860 | * @vport: pointer to a virtual N_Port data structure. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 4861 | * @rejectError: reject response to issue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4862 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4863 | * @ndlp: pointer to a node-list data structure. |
| 4864 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 4865 | * |
| 4866 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 4867 | * command. If a @mbox pointer is passed in, it will be put into the |
| 4868 | * context_un.mbox field of the IOCB for the completion callback function |
| 4869 | * to issue to the HBA later. |
| 4870 | * |
| 4871 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4872 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4873 | * will be stored into the context1 field of the IOCB for the completion |
| 4874 | * callback function to the reject response ELS IOCB command. |
| 4875 | * |
| 4876 | * Return code |
| 4877 | * 0 - Successfully issued reject response |
| 4878 | * 1 - Failed to issue reject response |
| 4879 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4880 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4881 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4882 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 4883 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4885 | int rc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4886 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4887 | IOCB_t *icmd; |
| 4888 | IOCB_t *oldcmd; |
| 4889 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | uint8_t *pcmd; |
| 4891 | uint16_t cmdsize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4893 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4894 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4895 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4896 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4897 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | |
| 4899 | icmd = &elsiocb->iocb; |
| 4900 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4901 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4902 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4903 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4904 | |
| 4905 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4906 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | *((uint32_t *) (pcmd)) = rejectError; |
| 4908 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4909 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4910 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4912 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4913 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4914 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 4915 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4916 | "rpi x%x\n", |
| 4917 | rejectError, elsiocb->iotag, |
| 4918 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 4919 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4920 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4921 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 4922 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 4923 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4924 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4925 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4926 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 4927 | if (!elsiocb->context1) |
| 4928 | goto node_err; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4929 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4930 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4931 | if (rc == IOCB_ERROR) |
| 4932 | goto io_err; |
| 4933 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4934 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4935 | |
| 4936 | io_err: |
| 4937 | lpfc_nlp_put(ndlp); |
| 4938 | node_err: |
| 4939 | lpfc_els_free_iocb(phba, elsiocb); |
| 4940 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 | } |
| 4942 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4943 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4944 | * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4945 | * @vport: pointer to a virtual N_Port data structure. |
| 4946 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4947 | * @ndlp: pointer to a node-list data structure. |
| 4948 | * |
| 4949 | * This routine prepares and issues an Accept (ACC) response to Address |
| 4950 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 4951 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 4952 | * |
| 4953 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4954 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4955 | * will be stored into the context1 field of the IOCB for the completion |
| 4956 | * callback function to the ADISC Accept response ELS IOCB command. |
| 4957 | * |
| 4958 | * Return code |
| 4959 | * 0 - Successfully issued acc adisc response |
| 4960 | * 1 - Failed to issue adisc acc response |
| 4961 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4963 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 4964 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4966 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4968 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | uint8_t *pcmd; |
| 4971 | uint16_t cmdsize; |
| 4972 | int rc; |
| 4973 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4974 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4976 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4977 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4980 | icmd = &elsiocb->iocb; |
| 4981 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4982 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4983 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4984 | |
| 4985 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4986 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4987 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 4988 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 4989 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4990 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4991 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4993 | |
| 4994 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4995 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4996 | |
| 4997 | ap = (ADISC *) (pcmd); |
| 4998 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4999 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5000 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5001 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5002 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5003 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5004 | "Issue ACC ADISC: did:x%x flg:x%x refcnt %d", |
| 5005 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5007 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5008 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5009 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5010 | if (!elsiocb->context1) |
| 5011 | goto node_err; |
| 5012 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5013 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5014 | if (rc == IOCB_ERROR) |
| 5015 | goto io_err; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 5016 | |
| 5017 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 5018 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5019 | "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " |
| 5020 | "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x " |
| 5021 | "RPI: x%x, fc_flag x%x\n", |
| 5022 | rc, elsiocb->iotag, elsiocb->sli4_xritag, |
| 5023 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5024 | ndlp->nlp_rpi, vport->fc_flag); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5025 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5026 | |
| 5027 | io_err: |
| 5028 | lpfc_nlp_put(ndlp); |
| 5029 | node_err: |
| 5030 | lpfc_els_free_iocb(phba, elsiocb); |
| 5031 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5032 | } |
| 5033 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5034 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5035 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5036 | * @vport: pointer to a virtual N_Port data structure. |
| 5037 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5038 | * @ndlp: pointer to a node-list data structure. |
| 5039 | * |
| 5040 | * This routine prepares and issues an Accept (ACC) response to Process |
| 5041 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 5042 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 5043 | * |
| 5044 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5045 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5046 | * will be stored into the context1 field of the IOCB for the completion |
| 5047 | * callback function to the PRLI Accept response ELS IOCB command. |
| 5048 | * |
| 5049 | * Return code |
| 5050 | * 0 - Successfully issued acc prli response |
| 5051 | * 1 - Failed to issue acc prli response |
| 5052 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5054 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5055 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5057 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5058 | PRLI *npr; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5059 | struct lpfc_nvme_prli *npr_nvme; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5060 | lpfc_vpd_t *vpd; |
| 5061 | IOCB_t *icmd; |
| 5062 | IOCB_t *oldcmd; |
| 5063 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5064 | uint8_t *pcmd; |
| 5065 | uint16_t cmdsize; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5066 | uint32_t prli_fc4_req, *req_payload; |
| 5067 | struct lpfc_dmabuf *req_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5068 | int rc; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5069 | u32 elsrspcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5070 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5071 | /* Need the incoming PRLI payload to determine if the ACC is for an |
| 5072 | * FC4 or NVME PRLI type. The PRLI type is at word 1. |
| 5073 | */ |
| 5074 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; |
| 5075 | req_payload = (((uint32_t *)req_buf->virt) + 1); |
| 5076 | |
| 5077 | /* PRLI type payload is at byte 3 for FCP or NVME. */ |
| 5078 | prli_fc4_req = be32_to_cpu(*req_payload); |
| 5079 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; |
| 5080 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5081 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", |
| 5082 | prli_fc4_req, *((uint32_t *)req_payload)); |
| 5083 | |
| 5084 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5085 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
| 5086 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 5087 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5088 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); |
| 5089 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); |
| 5090 | } else { |
| 5091 | return 1; |
| 5092 | } |
| 5093 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5094 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5095 | ndlp->nlp_DID, elsrspcmd); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5096 | if (!elsiocb) |
| 5097 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5098 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | icmd = &elsiocb->iocb; |
| 5100 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5101 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5102 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5103 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5104 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5106 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 5107 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5108 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5109 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5110 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5112 | memset(pcmd, 0, cmdsize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | |
James Smart | c07f10c | 2017-04-21 16:04:54 -0700 | [diff] [blame] | 5114 | *((uint32_t *)(pcmd)) = elsrspcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5115 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5116 | |
| 5117 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | vpd = &phba->vpd; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5119 | |
| 5120 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
| 5121 | /* |
| 5122 | * If the remote port is a target and our firmware version |
| 5123 | * is 3.20 or later, set the following bits for FC-TAPE |
| 5124 | * support. |
| 5125 | */ |
| 5126 | npr = (PRLI *) pcmd; |
| 5127 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 5128 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| 5129 | npr->ConfmComplAllowed = 1; |
| 5130 | npr->Retry = 1; |
| 5131 | npr->TaskRetryIdReq = 1; |
| 5132 | } |
| 5133 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 5134 | npr->estabImagePair = 1; |
| 5135 | npr->readXferRdyDis = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5136 | npr->ConfmComplAllowed = 1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5137 | npr->prliType = PRLI_FCP_TYPE; |
| 5138 | npr->initiatorFunc = 1; |
| 5139 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { |
| 5140 | /* Respond with an NVME PRLI Type */ |
| 5141 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; |
| 5142 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); |
| 5143 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ |
| 5144 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5145 | if (phba->nvmet_support) { |
| 5146 | bf_set(prli_tgt, npr_nvme, 1); |
| 5147 | bf_set(prli_disc, npr_nvme, 1); |
| 5148 | if (phba->cfg_nvme_enable_fb) { |
| 5149 | bf_set(prli_fba, npr_nvme, 1); |
| 5150 | |
| 5151 | /* TBD. Target mode needs to post buffers |
| 5152 | * that support the configured first burst |
| 5153 | * byte size. |
| 5154 | */ |
| 5155 | bf_set(prli_fb_sz, npr_nvme, |
| 5156 | phba->cfg_nvmet_fb_size); |
| 5157 | } |
| 5158 | } else { |
| 5159 | bf_set(prli_init, npr_nvme, 1); |
| 5160 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5162 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
| 5163 | "6015 NVME issue PRLI ACC word1 x%08x " |
| 5164 | "word4 x%08x word5 x%08x flag x%x, " |
| 5165 | "fcp_info x%x nlp_type x%x\n", |
| 5166 | npr_nvme->word1, npr_nvme->word4, |
| 5167 | npr_nvme->word5, ndlp->nlp_flag, |
| 5168 | ndlp->nlp_fcp_info, ndlp->nlp_type); |
| 5169 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
| 5170 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); |
| 5171 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); |
| 5172 | } else |
| 5173 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5174 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", |
| 5175 | prli_fc4_req, ndlp->nlp_fc4_type, |
| 5176 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5178 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5179 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 5180 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5182 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5183 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5184 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5185 | if (!elsiocb->context1) |
| 5186 | goto node_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5187 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5188 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5189 | if (rc == IOCB_ERROR) |
| 5190 | goto io_err; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5191 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5192 | |
| 5193 | io_err: |
| 5194 | lpfc_nlp_put(ndlp); |
| 5195 | node_err: |
| 5196 | lpfc_els_free_iocb(phba, elsiocb); |
| 5197 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | } |
| 5199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5201 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5202 | * @vport: pointer to a virtual N_Port data structure. |
| 5203 | * @format: rnid command format. |
| 5204 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5205 | * @ndlp: pointer to a node-list data structure. |
| 5206 | * |
| 5207 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 5208 | * (ACC) response. It constructs the RNID ACC response command according to |
| 5209 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 5210 | * issue the response. Note that this command does not need to hold the ndlp |
| 5211 | * reference count for the callback. So, the ndlp reference count taken by |
| 5212 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 5213 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 5214 | * there is no ndlp reference available. |
| 5215 | * |
| 5216 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5217 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5218 | * will be stored into the context1 field of the IOCB for the completion |
| 5219 | * callback function. However, for the RNID Accept Response ELS command, |
| 5220 | * this is undone later by this routine after the IOCB is allocated. |
| 5221 | * |
| 5222 | * Return code |
| 5223 | * 0 - Successfully issued acc rnid response |
| 5224 | * 1 - Failed to issue acc rnid response |
| 5225 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5227 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5228 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5229 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5230 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5231 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5232 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | uint8_t *pcmd; |
| 5235 | uint16_t cmdsize; |
| 5236 | int rc; |
| 5237 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5238 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 5239 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5241 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5244 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5245 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5246 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5247 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | icmd = &elsiocb->iocb; |
| 5249 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5250 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5251 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 5252 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5253 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5254 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5255 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 5256 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5259 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5260 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5261 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | rn = (RNID *) (pcmd); |
| 5263 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5264 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 5265 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5266 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | switch (format) { |
| 5268 | case 0: |
| 5269 | rn->SpecificLen = 0; |
| 5270 | break; |
| 5271 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5272 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5273 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5274 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5275 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 5276 | rn->un.topologyDisc.physPort = 0; |
| 5277 | rn->un.topologyDisc.attachedNodes = 0; |
| 5278 | break; |
| 5279 | default: |
| 5280 | rn->CommonLen = 0; |
| 5281 | rn->SpecificLen = 0; |
| 5282 | break; |
| 5283 | } |
| 5284 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5285 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5286 | "Issue ACC RNID: did:x%x flg:x%x refcnt %d", |
| 5287 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5288 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5290 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5291 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5292 | if (!elsiocb->context1) |
| 5293 | goto node_err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5295 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5296 | if (rc == IOCB_ERROR) |
| 5297 | goto io_err; |
| 5298 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5299 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5300 | |
| 5301 | io_err: |
| 5302 | lpfc_nlp_put(ndlp); |
| 5303 | node_err: |
| 5304 | lpfc_els_free_iocb(phba, elsiocb); |
| 5305 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5306 | } |
| 5307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5308 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5309 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 5310 | * @vport: pointer to a virtual N_Port data structure. |
| 5311 | * @iocb: pointer to the lpfc command iocb data structure. |
| 5312 | * @ndlp: pointer to a node-list data structure. |
| 5313 | * |
| 5314 | * Return |
| 5315 | **/ |
| 5316 | static void |
| 5317 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5318 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5319 | { |
| 5320 | struct lpfc_hba *phba = vport->phba; |
| 5321 | uint8_t *pcmd; |
| 5322 | struct RRQ *rrq; |
| 5323 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5324 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5325 | struct lpfc_node_rrq *prrq; |
| 5326 | |
| 5327 | |
| 5328 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 5329 | pcmd += sizeof(uint32_t); |
| 5330 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5331 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5332 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5333 | |
| 5334 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5335 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 5336 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5337 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5338 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5339 | rxid, |
| 5340 | iocb->iotag, iocb->iocb.ulpContext); |
| 5341 | |
| 5342 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 5343 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 5344 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5345 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5346 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5347 | else |
| 5348 | xri = rxid; |
| 5349 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5350 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5351 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5352 | return; |
| 5353 | } |
| 5354 | |
| 5355 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5356 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 5357 | * @vport: pointer to a virtual N_Port data structure. |
| 5358 | * @data: pointer to echo data to return in the accept. |
| 5359 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5360 | * @ndlp: pointer to a node-list data structure. |
| 5361 | * |
| 5362 | * Return code |
| 5363 | * 0 - Successfully issued acc echo response |
| 5364 | * 1 - Failed to issue acc echo response |
| 5365 | **/ |
| 5366 | static int |
| 5367 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 5368 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 5369 | { |
| 5370 | struct lpfc_hba *phba = vport->phba; |
| 5371 | struct lpfc_iocbq *elsiocb; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5372 | uint8_t *pcmd; |
| 5373 | uint16_t cmdsize; |
| 5374 | int rc; |
| 5375 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5376 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 5377 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5378 | /* The accumulated length can exceed the BPL_SIZE. For |
| 5379 | * now, use this as the limit |
| 5380 | */ |
| 5381 | if (cmdsize > LPFC_BPL_SIZE) |
| 5382 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5383 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5384 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5385 | if (!elsiocb) |
| 5386 | return 1; |
| 5387 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5388 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 5389 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 5390 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5391 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 5392 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5393 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 5394 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 5395 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5396 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5397 | pcmd += sizeof(uint32_t); |
| 5398 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 5399 | |
| 5400 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5401 | "Issue ACC ECHO: did:x%x flg:x%x refcnt %d", |
| 5402 | ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5403 | |
| 5404 | phba->fc_stat.elsXmitACC++; |
| 5405 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5406 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 5407 | if (!elsiocb->context1) |
| 5408 | goto node_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5409 | |
| 5410 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5411 | if (rc == IOCB_ERROR) |
| 5412 | goto io_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5413 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 5414 | |
| 5415 | io_err: |
| 5416 | lpfc_nlp_put(ndlp); |
| 5417 | node_err: |
| 5418 | lpfc_els_free_iocb(phba, elsiocb); |
| 5419 | return 1; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5423 | * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5424 | * @vport: pointer to a host virtual N_Port data structure. |
| 5425 | * |
| 5426 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 5427 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 5428 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 5429 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 5430 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 5431 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 5432 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 5433 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 5434 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 5435 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 5436 | * no more ADISC need to be sent. |
| 5437 | * |
| 5438 | * Return code |
| 5439 | * The number of N_Ports with adisc issued. |
| 5440 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5442 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5444 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5446 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5448 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5450 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 5451 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5452 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5453 | spin_lock_irq(&ndlp->lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5454 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5455 | spin_unlock_irq(&ndlp->lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5456 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 5458 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5459 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5460 | vport->num_disc_nodes++; |
| 5461 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5462 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5463 | spin_lock_irq(shost->host_lock); |
| 5464 | vport->fc_flag |= FC_NLP_MORE; |
| 5465 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5466 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5467 | } |
| 5468 | } |
| 5469 | } |
| 5470 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5471 | spin_lock_irq(shost->host_lock); |
| 5472 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5473 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5475 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | } |
| 5477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5479 | * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5480 | * @vport: pointer to a host virtual N_Port data structure. |
| 5481 | * |
| 5482 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 5483 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 5484 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 5485 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 5486 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 5487 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 5488 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 5489 | * later pick up. On the other hand, after walking through all the ndlps with |
| 5490 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 5491 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 5492 | * PLOGI need to be sent. |
| 5493 | * |
| 5494 | * Return code |
| 5495 | * The number of N_Ports with plogi issued. |
| 5496 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5497 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5498 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5500 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5502 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5503 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5504 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 5505 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5506 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5507 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 5508 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 5509 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5510 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5511 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5512 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5513 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5514 | vport->num_disc_nodes++; |
| 5515 | if (vport->num_disc_nodes >= |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 5516 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5517 | spin_lock_irq(shost->host_lock); |
| 5518 | vport->fc_flag |= FC_NLP_MORE; |
| 5519 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5520 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5521 | } |
| 5522 | } |
| 5523 | } |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5524 | |
| 5525 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5526 | "6452 Discover PLOGI %d flag x%x\n", |
| 5527 | sentplogi, vport->fc_flag); |
| 5528 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5529 | if (sentplogi) { |
| 5530 | lpfc_set_disctmo(vport); |
| 5531 | } |
| 5532 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | spin_lock_irq(shost->host_lock); |
| 5534 | vport->fc_flag &= ~FC_NLP_MORE; |
| 5535 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5537 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5538 | } |
| 5539 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5540 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5541 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
| 5542 | uint32_t word0) |
| 5543 | { |
| 5544 | |
| 5545 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); |
| 5546 | desc->payload.els_req = word0; |
| 5547 | desc->length = cpu_to_be32(sizeof(desc->payload)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5548 | |
| 5549 | return sizeof(struct fc_rdp_link_service_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5550 | } |
| 5551 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5552 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5553 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
| 5554 | uint8_t *page_a0, uint8_t *page_a2) |
| 5555 | { |
| 5556 | uint16_t wavelength; |
| 5557 | uint16_t temperature; |
| 5558 | uint16_t rx_power; |
| 5559 | uint16_t tx_bias; |
| 5560 | uint16_t tx_power; |
| 5561 | uint16_t vcc; |
| 5562 | uint16_t flag = 0; |
| 5563 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; |
| 5564 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; |
| 5565 | |
| 5566 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); |
| 5567 | |
| 5568 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) |
| 5569 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; |
| 5570 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) |
| 5571 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; |
| 5572 | |
| 5573 | if ((trasn_code_byte4->fc_sw_laser) || |
| 5574 | (trasn_code_byte5->fc_sw_laser_sl) || |
| 5575 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ |
| 5576 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); |
| 5577 | } else if (trasn_code_byte4->fc_lw_laser) { |
| 5578 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | |
| 5579 | page_a0[SSF_WAVELENGTH_B0]; |
| 5580 | if (wavelength == SFP_WAVELENGTH_LC1310) |
| 5581 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; |
| 5582 | if (wavelength == SFP_WAVELENGTH_LL1550) |
| 5583 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; |
| 5584 | } |
| 5585 | /* check if its SFP+ */ |
| 5586 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? |
| 5587 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) |
| 5588 | << SFP_FLAG_CT_SHIFT; |
| 5589 | |
| 5590 | /* check if its OPTICAL */ |
| 5591 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? |
| 5592 | SFP_FLAG_IS_OPTICAL_PORT : 0) |
| 5593 | << SFP_FLAG_IS_OPTICAL_SHIFT; |
| 5594 | |
| 5595 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | |
| 5596 | page_a2[SFF_TEMPERATURE_B0]); |
| 5597 | vcc = (page_a2[SFF_VCC_B1] << 8 | |
| 5598 | page_a2[SFF_VCC_B0]); |
| 5599 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | |
| 5600 | page_a2[SFF_TXPOWER_B0]); |
| 5601 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | |
| 5602 | page_a2[SFF_TX_BIAS_CURRENT_B0]); |
| 5603 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | |
| 5604 | page_a2[SFF_RXPOWER_B0]); |
| 5605 | desc->sfp_info.temperature = cpu_to_be16(temperature); |
| 5606 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); |
| 5607 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); |
| 5608 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); |
| 5609 | desc->sfp_info.vcc = cpu_to_be16(vcc); |
| 5610 | |
| 5611 | desc->sfp_info.flags = cpu_to_be16(flag); |
| 5612 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5613 | |
| 5614 | return sizeof(struct fc_rdp_sfp_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5615 | } |
| 5616 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5617 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5618 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
| 5619 | READ_LNK_VAR *stat) |
| 5620 | { |
| 5621 | uint32_t type; |
| 5622 | |
| 5623 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); |
| 5624 | |
| 5625 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; |
| 5626 | |
| 5627 | desc->info.port_type = cpu_to_be32(type); |
| 5628 | |
| 5629 | desc->info.link_status.link_failure_cnt = |
| 5630 | cpu_to_be32(stat->linkFailureCnt); |
| 5631 | desc->info.link_status.loss_of_synch_cnt = |
| 5632 | cpu_to_be32(stat->lossSyncCnt); |
| 5633 | desc->info.link_status.loss_of_signal_cnt = |
| 5634 | cpu_to_be32(stat->lossSignalCnt); |
| 5635 | desc->info.link_status.primitive_seq_proto_err = |
| 5636 | cpu_to_be32(stat->primSeqErrCnt); |
| 5637 | desc->info.link_status.invalid_trans_word = |
| 5638 | cpu_to_be32(stat->invalidXmitWord); |
| 5639 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); |
| 5640 | |
| 5641 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5642 | |
| 5643 | return sizeof(struct fc_rdp_link_error_status_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5644 | } |
| 5645 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5646 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5647 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
| 5648 | struct lpfc_vport *vport) |
| 5649 | { |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5650 | uint32_t bbCredit; |
| 5651 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5652 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
| 5653 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5654 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
| 5655 | (vport->fc_sparam.cmn.bbCreditMsb << 8); |
| 5656 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); |
| 5657 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
| 5658 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | |
| 5659 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); |
| 5660 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); |
| 5661 | } else { |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5662 | desc->bbc_info.attached_port_bbc = 0; |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5663 | } |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5664 | |
| 5665 | desc->bbc_info.rtt = 0; |
| 5666 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5667 | |
| 5668 | return sizeof(struct fc_rdp_bbc_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5671 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5672 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
| 5673 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5674 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5675 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5676 | |
| 5677 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5678 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5679 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
| 5680 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; |
| 5681 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; |
| 5682 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5683 | |
| 5684 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5685 | flags |= RDP_OET_HIGH_ALARM; |
| 5686 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5687 | flags |= RDP_OET_LOW_ALARM; |
| 5688 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) |
| 5689 | flags |= RDP_OET_HIGH_WARNING; |
| 5690 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) |
| 5691 | flags |= RDP_OET_LOW_WARNING; |
| 5692 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5693 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
| 5694 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5695 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5696 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5697 | } |
| 5698 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5699 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5700 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
| 5701 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5702 | uint8_t *page_a2) |
| 5703 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5704 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5705 | |
| 5706 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5707 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5708 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
| 5709 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; |
| 5710 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; |
| 5711 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5712 | |
| 5713 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5714 | flags |= RDP_OET_HIGH_ALARM; |
| 5715 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5716 | flags |= RDP_OET_LOW_ALARM; |
| 5717 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) |
| 5718 | flags |= RDP_OET_HIGH_WARNING; |
| 5719 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) |
| 5720 | flags |= RDP_OET_LOW_WARNING; |
| 5721 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5722 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
| 5723 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5724 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5725 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5726 | } |
| 5727 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5728 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5729 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
| 5730 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5731 | uint8_t *page_a2) |
| 5732 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5733 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5734 | |
| 5735 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5736 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5737 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
| 5738 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; |
| 5739 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; |
| 5740 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5741 | |
| 5742 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5743 | flags |= RDP_OET_HIGH_ALARM; |
| 5744 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5745 | flags |= RDP_OET_LOW_ALARM; |
| 5746 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) |
| 5747 | flags |= RDP_OET_HIGH_WARNING; |
| 5748 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) |
| 5749 | flags |= RDP_OET_LOW_WARNING; |
| 5750 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5751 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
| 5752 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5753 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5754 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5757 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5758 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
| 5759 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5760 | uint8_t *page_a2) |
| 5761 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5762 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5763 | |
| 5764 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5765 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5766 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
| 5767 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; |
| 5768 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; |
| 5769 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5770 | |
| 5771 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5772 | flags |= RDP_OET_HIGH_ALARM; |
| 5773 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5774 | flags |= RDP_OET_LOW_ALARM; |
| 5775 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) |
| 5776 | flags |= RDP_OET_HIGH_WARNING; |
| 5777 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) |
| 5778 | flags |= RDP_OET_LOW_WARNING; |
| 5779 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5780 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5781 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5782 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5783 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5787 | static uint32_t |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5788 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
| 5789 | struct fc_rdp_oed_sfp_desc *desc, |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5790 | uint8_t *page_a2) |
| 5791 | { |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5792 | uint32_t flags = 0; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5793 | |
| 5794 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); |
| 5795 | |
James Smart | 3aaaa31 | 2016-07-06 12:35:57 -0700 | [diff] [blame] | 5796 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
| 5797 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; |
| 5798 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; |
| 5799 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5800 | |
| 5801 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5802 | flags |= RDP_OET_HIGH_ALARM; |
| 5803 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5804 | flags |= RDP_OET_LOW_ALARM; |
| 5805 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) |
| 5806 | flags |= RDP_OET_HIGH_WARNING; |
| 5807 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) |
| 5808 | flags |= RDP_OET_LOW_WARNING; |
| 5809 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5810 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
| 5811 | desc->oed_info.function_flags = cpu_to_be32(flags); |
| 5812 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5813 | return sizeof(struct fc_rdp_oed_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5814 | } |
| 5815 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5816 | static uint32_t |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5817 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
| 5818 | uint8_t *page_a0, struct lpfc_vport *vport) |
| 5819 | { |
| 5820 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); |
| 5821 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); |
| 5822 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); |
| 5823 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5824 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5825 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
| 5826 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5827 | return sizeof(struct fc_rdp_opd_sfp_desc); |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5828 | } |
| 5829 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5830 | static uint32_t |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5831 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
| 5832 | { |
| 5833 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) |
| 5834 | return 0; |
| 5835 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); |
| 5836 | |
| 5837 | desc->info.CorrectedBlocks = |
| 5838 | cpu_to_be32(stat->fecCorrBlkCount); |
| 5839 | desc->info.UncorrectableBlocks = |
| 5840 | cpu_to_be32(stat->fecUncorrBlkCount); |
| 5841 | |
| 5842 | desc->length = cpu_to_be32(sizeof(desc->info)); |
| 5843 | |
| 5844 | return sizeof(struct fc_fec_rdp_desc); |
| 5845 | } |
| 5846 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5847 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5848 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
| 5849 | { |
| 5850 | uint16_t rdp_cap = 0; |
| 5851 | uint16_t rdp_speed; |
| 5852 | |
| 5853 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); |
| 5854 | |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5855 | switch (phba->fc_linkspeed) { |
| 5856 | case LPFC_LINK_SPEED_1GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5857 | rdp_speed = RDP_PS_1GB; |
| 5858 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5859 | case LPFC_LINK_SPEED_2GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5860 | rdp_speed = RDP_PS_2GB; |
| 5861 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5862 | case LPFC_LINK_SPEED_4GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5863 | rdp_speed = RDP_PS_4GB; |
| 5864 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5865 | case LPFC_LINK_SPEED_8GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5866 | rdp_speed = RDP_PS_8GB; |
| 5867 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5868 | case LPFC_LINK_SPEED_10GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5869 | rdp_speed = RDP_PS_10GB; |
| 5870 | break; |
James Smart | 81e7517 | 2015-12-16 18:11:59 -0500 | [diff] [blame] | 5871 | case LPFC_LINK_SPEED_16GHZ: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5872 | rdp_speed = RDP_PS_16GB; |
| 5873 | break; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5874 | case LPFC_LINK_SPEED_32GHZ: |
| 5875 | rdp_speed = RDP_PS_32GB; |
| 5876 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5877 | case LPFC_LINK_SPEED_64GHZ: |
| 5878 | rdp_speed = RDP_PS_64GB; |
| 5879 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5880 | default: |
| 5881 | rdp_speed = RDP_PS_UNKNOWN; |
| 5882 | break; |
| 5883 | } |
| 5884 | |
| 5885 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); |
| 5886 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5887 | if (phba->lmt & LMT_128Gb) |
| 5888 | rdp_cap |= RDP_PS_128GB; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5889 | if (phba->lmt & LMT_64Gb) |
| 5890 | rdp_cap |= RDP_PS_64GB; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5891 | if (phba->lmt & LMT_32Gb) |
| 5892 | rdp_cap |= RDP_PS_32GB; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5893 | if (phba->lmt & LMT_16Gb) |
| 5894 | rdp_cap |= RDP_PS_16GB; |
| 5895 | if (phba->lmt & LMT_10Gb) |
| 5896 | rdp_cap |= RDP_PS_10GB; |
| 5897 | if (phba->lmt & LMT_8Gb) |
| 5898 | rdp_cap |= RDP_PS_8GB; |
| 5899 | if (phba->lmt & LMT_4Gb) |
| 5900 | rdp_cap |= RDP_PS_4GB; |
| 5901 | if (phba->lmt & LMT_2Gb) |
| 5902 | rdp_cap |= RDP_PS_2GB; |
| 5903 | if (phba->lmt & LMT_1Gb) |
| 5904 | rdp_cap |= RDP_PS_1GB; |
| 5905 | |
| 5906 | if (rdp_cap == 0) |
| 5907 | rdp_cap = RDP_CAP_UNKNOWN; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 5908 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
| 5909 | rdp_cap |= RDP_CAP_USER_CONFIGURED; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5910 | |
| 5911 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); |
| 5912 | desc->length = cpu_to_be32(sizeof(desc->info)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5913 | return sizeof(struct fc_rdp_port_speed_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5914 | } |
| 5915 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5916 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5917 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5918 | struct lpfc_vport *vport) |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5919 | { |
| 5920 | |
| 5921 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5922 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5923 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5924 | sizeof(desc->port_names.wwnn)); |
| 5925 | |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 5926 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5927 | sizeof(desc->port_names.wwpn)); |
| 5928 | |
| 5929 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5930 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5931 | } |
| 5932 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5933 | static uint32_t |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5934 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
| 5935 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5936 | { |
| 5937 | |
| 5938 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); |
| 5939 | if (vport->fc_flag & FC_FABRIC) { |
| 5940 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5941 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5942 | |
| 5943 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5944 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5945 | } else { /* Point to Point */ |
| 5946 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5947 | sizeof(desc->port_names.wwnn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5948 | |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 5949 | memcpy(desc->port_names.wwpn, &ndlp->nlp_portname, |
| 5950 | sizeof(desc->port_names.wwpn)); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | desc->length = cpu_to_be32(sizeof(desc->port_names)); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5954 | return sizeof(struct fc_rdp_port_name_desc); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5955 | } |
| 5956 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5957 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5958 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
| 5959 | int status) |
| 5960 | { |
| 5961 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; |
| 5962 | struct lpfc_vport *vport = ndlp->vport; |
| 5963 | struct lpfc_iocbq *elsiocb; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5964 | struct ulp_bde64 *bpl; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5965 | IOCB_t *icmd; |
| 5966 | uint8_t *pcmd; |
| 5967 | struct ls_rjt *stat; |
| 5968 | struct fc_rdp_res_frame *rdp_res; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5969 | uint32_t cmdsize, len; |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5970 | uint16_t *flag_ptr; |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 5971 | int rc; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5972 | |
| 5973 | if (status != SUCCESS) |
| 5974 | goto error; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 5975 | |
| 5976 | /* This will change once we know the true size of the RDP payload */ |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5977 | cmdsize = sizeof(struct fc_rdp_res_frame); |
| 5978 | |
| 5979 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, |
| 5980 | lpfc_max_els_tries, rdp_context->ndlp, |
| 5981 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 5982 | if (!elsiocb) |
| 5983 | goto free_rdp_context; |
| 5984 | |
| 5985 | icmd = &elsiocb->iocb; |
| 5986 | icmd->ulpContext = rdp_context->rx_id; |
| 5987 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 5988 | |
| 5989 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5990 | "2171 Xmit RDP response tag x%x xri x%x, " |
| 5991 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", |
| 5992 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5993 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5994 | ndlp->nlp_rpi); |
| 5995 | rdp_res = (struct fc_rdp_res_frame *) |
| 5996 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5997 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5998 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); |
| 5999 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 6000 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 6001 | /* Update Alarm and Warning */ |
| 6002 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); |
| 6003 | phba->sfp_alarm |= *flag_ptr; |
| 6004 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); |
| 6005 | phba->sfp_warning |= *flag_ptr; |
| 6006 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6007 | /* For RDP payload */ |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6008 | len = 8; |
| 6009 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) |
| 6010 | (len + pcmd), ELS_CMD_RDP); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6011 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6012 | len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd), |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6013 | rdp_context->page_a0, rdp_context->page_a2); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6014 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
| 6015 | phba); |
| 6016 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) |
| 6017 | (len + pcmd), &rdp_context->link_stat); |
| 6018 | len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) |
James Smart | cd46cde | 2017-03-04 09:30:37 -0800 | [diff] [blame] | 6019 | (len + pcmd), vport); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6020 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
| 6021 | (len + pcmd), vport, ndlp); |
| 6022 | len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6023 | &rdp_context->link_stat); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6024 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), |
| 6025 | &rdp_context->link_stat, vport); |
| 6026 | len += lpfc_rdp_res_oed_temp_desc(phba, |
| 6027 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6028 | rdp_context->page_a2); |
| 6029 | len += lpfc_rdp_res_oed_voltage_desc(phba, |
| 6030 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6031 | rdp_context->page_a2); |
| 6032 | len += lpfc_rdp_res_oed_txbias_desc(phba, |
| 6033 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6034 | rdp_context->page_a2); |
| 6035 | len += lpfc_rdp_res_oed_txpower_desc(phba, |
| 6036 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6037 | rdp_context->page_a2); |
| 6038 | len += lpfc_rdp_res_oed_rxpower_desc(phba, |
| 6039 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), |
| 6040 | rdp_context->page_a2); |
| 6041 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), |
| 6042 | rdp_context->page_a0, vport); |
| 6043 | |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6044 | rdp_res->length = cpu_to_be32(len - 8); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6045 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6046 | |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 6047 | /* Now that we know the true size of the payload, update the BPL */ |
| 6048 | bpl = (struct ulp_bde64 *) |
| 6049 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); |
James Smart | 6c92d1d | 2016-07-06 12:35:55 -0700 | [diff] [blame] | 6050 | bpl->tus.f.bdeSize = len; |
James Smart | eb8d68c | 2015-12-16 18:12:00 -0500 | [diff] [blame] | 6051 | bpl->tus.f.bdeFlags = 0; |
| 6052 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 6053 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6054 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6055 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6056 | if (!elsiocb->context1) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6057 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6058 | goto free_rdp_context; |
| 6059 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6060 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6061 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6062 | if (rc == IOCB_ERROR) { |
| 6063 | lpfc_nlp_put(ndlp); |
| 6064 | lpfc_els_free_iocb(phba, elsiocb); |
| 6065 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6066 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6067 | goto free_rdp_context; |
| 6068 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6069 | error: |
| 6070 | cmdsize = 2 * sizeof(uint32_t); |
| 6071 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, |
| 6072 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6073 | if (!elsiocb) |
| 6074 | goto free_rdp_context; |
| 6075 | |
| 6076 | icmd = &elsiocb->iocb; |
| 6077 | icmd->ulpContext = rdp_context->rx_id; |
| 6078 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; |
| 6079 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6080 | |
| 6081 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 6082 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6083 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6084 | |
| 6085 | phba->fc_stat.elsXmitLSRJT++; |
| 6086 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6087 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6088 | if (!elsiocb->context1) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6089 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6090 | goto free_rdp_context; |
| 6091 | } |
| 6092 | |
| 6093 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6094 | if (rc == IOCB_ERROR) { |
| 6095 | lpfc_nlp_put(ndlp); |
| 6096 | lpfc_els_free_iocb(phba, elsiocb); |
| 6097 | } |
| 6098 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6099 | free_rdp_context: |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6100 | /* This reference put is for the original unsolicited RDP. If the |
| 6101 | * iocb prep failed, there is no reference to remove. |
| 6102 | */ |
| 6103 | lpfc_nlp_put(ndlp); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6104 | kfree(rdp_context); |
| 6105 | } |
| 6106 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6107 | static int |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6108 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
| 6109 | { |
| 6110 | LPFC_MBOXQ_t *mbox = NULL; |
| 6111 | int rc; |
| 6112 | |
| 6113 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6114 | if (!mbox) { |
| 6115 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, |
| 6116 | "7105 failed to allocate mailbox memory"); |
| 6117 | return 1; |
| 6118 | } |
| 6119 | |
| 6120 | if (lpfc_sli4_dump_page_a0(phba, mbox)) |
| 6121 | goto prep_mbox_fail; |
| 6122 | mbox->vport = rdp_context->ndlp->vport; |
| 6123 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6124 | mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6125 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6126 | if (rc == MBX_NOT_FINISHED) |
| 6127 | goto issue_mbox_fail; |
| 6128 | |
| 6129 | return 0; |
| 6130 | |
| 6131 | prep_mbox_fail: |
| 6132 | issue_mbox_fail: |
| 6133 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6134 | return 1; |
| 6135 | } |
| 6136 | |
| 6137 | /* |
| 6138 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. |
| 6139 | * @vport: pointer to a host virtual N_Port data structure. |
| 6140 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6141 | * @ndlp: pointer to a node-list data structure. |
| 6142 | * |
| 6143 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) |
| 6144 | * IOCB. First, the payload of the unsolicited RDP is checked. |
| 6145 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 |
| 6146 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, |
| 6147 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl |
| 6148 | * gather all data and send RDP response. |
| 6149 | * |
| 6150 | * Return code |
| 6151 | * 0 - Sent the acc response |
| 6152 | * 1 - Sent the reject response. |
| 6153 | */ |
| 6154 | static int |
| 6155 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6156 | struct lpfc_nodelist *ndlp) |
| 6157 | { |
| 6158 | struct lpfc_hba *phba = vport->phba; |
| 6159 | struct lpfc_dmabuf *pcmd; |
| 6160 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; |
| 6161 | struct fc_rdp_req_frame *rdp_req; |
| 6162 | struct lpfc_rdp_context *rdp_context; |
| 6163 | IOCB_t *cmd = NULL; |
| 6164 | struct ls_rjt stat; |
| 6165 | |
| 6166 | if (phba->sli_rev < LPFC_SLI_REV4 || |
James Smart | 719162b | 2018-12-10 19:37:01 -0800 | [diff] [blame] | 6167 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6168 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6169 | rjt_err = LSRJT_UNABLE_TPC; |
| 6170 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6171 | goto error; |
| 6172 | } |
| 6173 | |
| 6174 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { |
| 6175 | rjt_err = LSRJT_UNABLE_TPC; |
| 6176 | rjt_expl = LSEXP_REQ_UNSUPPORTED; |
| 6177 | goto error; |
| 6178 | } |
| 6179 | |
| 6180 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6181 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; |
| 6182 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6183 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6184 | "2422 ELS RDP Request " |
| 6185 | "dec len %d tag x%x port_id %d len %d\n", |
| 6186 | be32_to_cpu(rdp_req->rdp_des_length), |
| 6187 | be32_to_cpu(rdp_req->nport_id_desc.tag), |
| 6188 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), |
| 6189 | be32_to_cpu(rdp_req->nport_id_desc.length)); |
| 6190 | |
| 6191 | if (sizeof(struct fc_rdp_nport_desc) != |
| 6192 | be32_to_cpu(rdp_req->rdp_des_length)) |
| 6193 | goto rjt_logerr; |
| 6194 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) |
| 6195 | goto rjt_logerr; |
| 6196 | if (RDP_NPORT_ID_SIZE != |
| 6197 | be32_to_cpu(rdp_req->nport_id_desc.length)) |
| 6198 | goto rjt_logerr; |
Punit Vara | 699acd6 | 2015-12-16 18:12:07 -0500 | [diff] [blame] | 6199 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6200 | if (!rdp_context) { |
| 6201 | rjt_err = LSRJT_UNABLE_TPC; |
| 6202 | goto error; |
| 6203 | } |
| 6204 | |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6205 | cmd = &cmdiocb->iocb; |
| 6206 | rdp_context->ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6207 | if (!rdp_context->ndlp) { |
| 6208 | kfree(rdp_context); |
| 6209 | rjt_err = LSRJT_UNABLE_TPC; |
| 6210 | goto error; |
| 6211 | } |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 6212 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; |
| 6213 | rdp_context->rx_id = cmd->ulpContext; |
| 6214 | rdp_context->cmpl = lpfc_els_rdp_cmpl; |
| 6215 | if (lpfc_get_rdp_info(phba, rdp_context)) { |
| 6216 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, |
| 6217 | "2423 Unable to send mailbox"); |
| 6218 | kfree(rdp_context); |
| 6219 | rjt_err = LSRJT_UNABLE_TPC; |
| 6220 | lpfc_nlp_put(ndlp); |
| 6221 | goto error; |
| 6222 | } |
| 6223 | |
| 6224 | return 0; |
| 6225 | |
| 6226 | rjt_logerr: |
| 6227 | rjt_err = LSRJT_LOGICAL_ERR; |
| 6228 | |
| 6229 | error: |
| 6230 | memset(&stat, 0, sizeof(stat)); |
| 6231 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6232 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; |
| 6233 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6234 | return 1; |
| 6235 | } |
| 6236 | |
| 6237 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6238 | static void |
| 6239 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6240 | { |
| 6241 | MAILBOX_t *mb; |
| 6242 | IOCB_t *icmd; |
| 6243 | uint8_t *pcmd; |
| 6244 | struct lpfc_iocbq *elsiocb; |
| 6245 | struct lpfc_nodelist *ndlp; |
| 6246 | struct ls_rjt *stat; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6247 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6248 | struct lpfc_lcb_context *lcb_context; |
| 6249 | struct fc_lcb_res_frame *lcb_res; |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6250 | uint32_t cmdsize, shdr_status, shdr_add_status; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6251 | int rc; |
| 6252 | |
| 6253 | mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6254 | lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6255 | ndlp = lcb_context->ndlp; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6256 | pmb->ctx_ndlp = NULL; |
| 6257 | pmb->ctx_buf = NULL; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6258 | |
James Smart | 481ad96 | 2015-05-22 10:42:35 -0400 | [diff] [blame] | 6259 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6260 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; |
| 6261 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6262 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6263 | |
| 6264 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, |
| 6265 | "0194 SET_BEACON_CONFIG mailbox " |
| 6266 | "completed with status x%x add_status x%x," |
| 6267 | " mbx status x%x\n", |
| 6268 | shdr_status, shdr_add_status, mb->mbxStatus); |
| 6269 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6270 | if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status || |
| 6271 | (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) || |
| 6272 | (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6273 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6274 | goto error; |
| 6275 | } |
| 6276 | |
| 6277 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6278 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6279 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6280 | lpfc_max_els_tries, ndlp, |
| 6281 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 6282 | |
| 6283 | /* Decrement the ndlp reference count from previous mbox command */ |
| 6284 | lpfc_nlp_put(ndlp); |
| 6285 | |
| 6286 | if (!elsiocb) |
| 6287 | goto free_lcb_context; |
| 6288 | |
| 6289 | lcb_res = (struct fc_lcb_res_frame *) |
| 6290 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6291 | |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6292 | memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame)); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6293 | icmd = &elsiocb->iocb; |
| 6294 | icmd->ulpContext = lcb_context->rx_id; |
| 6295 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6296 | |
| 6297 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6298 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; |
| 6299 | lcb_res->lcb_sub_command = lcb_context->sub_command; |
| 6300 | lcb_res->lcb_type = lcb_context->type; |
James Smart | 24bc311 | 2018-07-31 17:23:23 -0700 | [diff] [blame] | 6301 | lcb_res->capability = lcb_context->capability; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6302 | lcb_res->lcb_frequency = lcb_context->frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6303 | lcb_res->lcb_duration = lcb_context->duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6304 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6305 | phba->fc_stat.elsXmitACC++; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6306 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6307 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6308 | if (!elsiocb->context1) |
| 6309 | goto node_err; |
| 6310 | |
| 6311 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6312 | if (!rc) |
| 6313 | goto out; |
| 6314 | |
| 6315 | lpfc_nlp_put(ndlp); |
| 6316 | node_err: |
| 6317 | lpfc_els_free_iocb(phba, elsiocb); |
| 6318 | out: |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6319 | kfree(lcb_context); |
| 6320 | return; |
| 6321 | |
| 6322 | error: |
| 6323 | cmdsize = sizeof(struct fc_lcb_res_frame); |
| 6324 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 6325 | lpfc_max_els_tries, ndlp, |
| 6326 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 6327 | lpfc_nlp_put(ndlp); |
| 6328 | if (!elsiocb) |
| 6329 | goto free_lcb_context; |
| 6330 | |
| 6331 | icmd = &elsiocb->iocb; |
| 6332 | icmd->ulpContext = lcb_context->rx_id; |
| 6333 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; |
| 6334 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); |
| 6335 | |
| 6336 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; |
| 6337 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); |
| 6338 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 6339 | |
James Smart | b114d90 | 2018-10-23 13:41:07 -0700 | [diff] [blame] | 6340 | if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) |
| 6341 | stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; |
| 6342 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6343 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 6344 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6345 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 6346 | if (!elsiocb->context1) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6347 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6348 | goto free_lcb_context; |
| 6349 | } |
| 6350 | |
| 6351 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 6352 | if (rc == IOCB_ERROR) { |
| 6353 | lpfc_nlp_put(ndlp); |
| 6354 | lpfc_els_free_iocb(phba, elsiocb); |
| 6355 | } |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6356 | free_lcb_context: |
| 6357 | kfree(lcb_context); |
| 6358 | } |
| 6359 | |
| 6360 | static int |
| 6361 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, |
| 6362 | struct lpfc_lcb_context *lcb_context, |
| 6363 | uint32_t beacon_state) |
| 6364 | { |
| 6365 | struct lpfc_hba *phba = vport->phba; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6366 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6367 | LPFC_MBOXQ_t *mbox = NULL; |
| 6368 | uint32_t len; |
| 6369 | int rc; |
| 6370 | |
| 6371 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6372 | if (!mbox) |
| 6373 | return 1; |
| 6374 | |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6375 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6376 | len = sizeof(struct lpfc_mbx_set_beacon_config) - |
| 6377 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6378 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6379 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, |
| 6380 | LPFC_SLI4_MBX_EMBED); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6381 | mbox->ctx_ndlp = (void *)lcb_context; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6382 | mbox->vport = phba->pport; |
| 6383 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; |
| 6384 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, |
| 6385 | phba->sli4_hba.physical_port); |
| 6386 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, |
| 6387 | beacon_state); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6388 | mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */ |
| 6389 | |
| 6390 | /* |
| 6391 | * Check bv1s bit before issuing the mailbox |
| 6392 | * if bv1s == 1, LCB V1 supported |
| 6393 | * else, LCB V0 supported |
| 6394 | */ |
| 6395 | |
| 6396 | if (phba->sli4_hba.pc_sli4_params.bv1s) { |
| 6397 | /* COMMON_SET_BEACON_CONFIG_V1 */ |
| 6398 | cfg_shdr->request.word9 = BEACON_VERSION_V1; |
| 6399 | lcb_context->capability |= LCB_CAPABILITY_DURATION; |
| 6400 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6401 | &mbox->u.mqe.un.beacon_config, 0); |
| 6402 | bf_set(lpfc_mbx_set_beacon_duration_v1, |
| 6403 | &mbox->u.mqe.un.beacon_config, |
| 6404 | be16_to_cpu(lcb_context->duration)); |
| 6405 | } else { |
| 6406 | /* COMMON_SET_BEACON_CONFIG_V0 */ |
| 6407 | if (be16_to_cpu(lcb_context->duration) != 0) { |
| 6408 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6409 | return 1; |
| 6410 | } |
| 6411 | cfg_shdr->request.word9 = BEACON_VERSION_V0; |
| 6412 | lcb_context->capability &= ~(LCB_CAPABILITY_DURATION); |
| 6413 | bf_set(lpfc_mbx_set_beacon_state, |
| 6414 | &mbox->u.mqe.un.beacon_config, beacon_state); |
| 6415 | bf_set(lpfc_mbx_set_beacon_port_type, |
| 6416 | &mbox->u.mqe.un.beacon_config, 1); |
| 6417 | bf_set(lpfc_mbx_set_beacon_duration, |
| 6418 | &mbox->u.mqe.un.beacon_config, |
| 6419 | be16_to_cpu(lcb_context->duration)); |
| 6420 | } |
| 6421 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6422 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6423 | if (rc == MBX_NOT_FINISHED) { |
| 6424 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6425 | return 1; |
| 6426 | } |
| 6427 | |
| 6428 | return 0; |
| 6429 | } |
| 6430 | |
| 6431 | |
| 6432 | /** |
| 6433 | * lpfc_els_rcv_lcb - Process an unsolicited LCB |
| 6434 | * @vport: pointer to a host virtual N_Port data structure. |
| 6435 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6436 | * @ndlp: pointer to a node-list data structure. |
| 6437 | * |
| 6438 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. |
| 6439 | * First, the payload of the unsolicited LCB is checked. |
| 6440 | * Then based on Subcommand beacon will either turn on or off. |
| 6441 | * |
| 6442 | * Return code |
| 6443 | * 0 - Sent the acc response |
| 6444 | * 1 - Sent the reject response. |
| 6445 | **/ |
| 6446 | static int |
| 6447 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 6448 | struct lpfc_nodelist *ndlp) |
| 6449 | { |
| 6450 | struct lpfc_hba *phba = vport->phba; |
| 6451 | struct lpfc_dmabuf *pcmd; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6452 | uint8_t *lp; |
| 6453 | struct fc_lcb_request_frame *beacon; |
| 6454 | struct lpfc_lcb_context *lcb_context; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6455 | u8 state, rjt_err = 0; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6456 | struct ls_rjt stat; |
| 6457 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6458 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 6459 | lp = (uint8_t *)pcmd->virt; |
| 6460 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; |
| 6461 | |
| 6462 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6463 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " |
| 6464 | "type x%x frequency %x duration x%x\n", |
| 6465 | lp[0], lp[1], lp[2], |
| 6466 | beacon->lcb_command, |
| 6467 | beacon->lcb_sub_command, |
| 6468 | beacon->lcb_type, |
| 6469 | beacon->lcb_frequency, |
| 6470 | be16_to_cpu(beacon->lcb_duration)); |
| 6471 | |
James Smart | d6564e5 | 2017-06-15 22:56:50 -0700 | [diff] [blame] | 6472 | if (beacon->lcb_sub_command != LPFC_LCB_ON && |
| 6473 | beacon->lcb_sub_command != LPFC_LCB_OFF) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6474 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6475 | goto rjt; |
| 6476 | } |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6477 | |
| 6478 | if (phba->sli_rev < LPFC_SLI_REV4 || |
| 6479 | phba->hba_flag & HBA_FCOE_MODE || |
| 6480 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
| 6481 | LPFC_SLI_INTF_IF_TYPE_2)) { |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6482 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| 6483 | goto rjt; |
| 6484 | } |
| 6485 | |
Sudip Mukherjee | e795042 | 2015-09-23 19:02:32 +0530 | [diff] [blame] | 6486 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
| 6487 | if (!lcb_context) { |
| 6488 | rjt_err = LSRJT_UNABLE_TPC; |
| 6489 | goto rjt; |
| 6490 | } |
| 6491 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6492 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
| 6493 | lcb_context->sub_command = beacon->lcb_sub_command; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6494 | lcb_context->capability = 0; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6495 | lcb_context->type = beacon->lcb_type; |
| 6496 | lcb_context->frequency = beacon->lcb_frequency; |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 6497 | lcb_context->duration = beacon->lcb_duration; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6498 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 6499 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; |
| 6500 | lcb_context->ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6501 | if (!lcb_context->ndlp) { |
| 6502 | rjt_err = LSRJT_UNABLE_TPC; |
Colin Ian King | 14c1dd9 | 2020-11-18 14:13:14 +0000 | [diff] [blame] | 6503 | goto rjt_free; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 6504 | } |
| 6505 | |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6506 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6507 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, |
| 6508 | "0193 failed to send mail box"); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6509 | lpfc_nlp_put(ndlp); |
| 6510 | rjt_err = LSRJT_UNABLE_TPC; |
Colin Ian King | 14c1dd9 | 2020-11-18 14:13:14 +0000 | [diff] [blame] | 6511 | goto rjt_free; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6512 | } |
| 6513 | return 0; |
Colin Ian King | 14c1dd9 | 2020-11-18 14:13:14 +0000 | [diff] [blame] | 6514 | |
| 6515 | rjt_free: |
| 6516 | kfree(lcb_context); |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 6517 | rjt: |
| 6518 | memset(&stat, 0, sizeof(stat)); |
| 6519 | stat.un.b.lsRjtRsnCode = rjt_err; |
| 6520 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 6521 | return 1; |
| 6522 | } |
| 6523 | |
| 6524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6526 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6527 | * @vport: pointer to a host virtual N_Port data structure. |
| 6528 | * |
| 6529 | * This routine cleans up any Registration State Change Notification |
| 6530 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 6531 | * @vport together with the host_lock is used to prevent multiple thread |
| 6532 | * trying to access the RSCN array on a same @vport at the same time. |
| 6533 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6534 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6535 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6538 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6539 | int i; |
| 6540 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6541 | spin_lock_irq(shost->host_lock); |
| 6542 | if (vport->fc_rscn_flush) { |
| 6543 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6544 | spin_unlock_irq(shost->host_lock); |
| 6545 | return; |
| 6546 | } |
| 6547 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 6548 | vport->fc_rscn_flush = 1; |
| 6549 | spin_unlock_irq(shost->host_lock); |
| 6550 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6551 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6552 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6553 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6554 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6555 | spin_lock_irq(shost->host_lock); |
| 6556 | vport->fc_rscn_id_cnt = 0; |
| 6557 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 6558 | spin_unlock_irq(shost->host_lock); |
| 6559 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6560 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 6561 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6562 | } |
| 6563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6564 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6565 | * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6566 | * @vport: pointer to a host virtual N_Port data structure. |
| 6567 | * @did: remote destination port identifier. |
| 6568 | * |
| 6569 | * This routine checks whether there is any pending Registration State |
| 6570 | * Configuration Notification (RSCN) to a @did on @vport. |
| 6571 | * |
| 6572 | * Return code |
| 6573 | * None zero - The @did matched with a pending rscn |
| 6574 | * 0 - not able to match @did with a pending rscn |
| 6575 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6576 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6577 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6578 | { |
| 6579 | D_ID ns_did; |
| 6580 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6581 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6582 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6583 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6584 | |
| 6585 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6586 | |
| 6587 | /* Never match fabric nodes for RSCNs */ |
| 6588 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6589 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6590 | |
| 6591 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6592 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6593 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6594 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6595 | spin_lock_irq(shost->host_lock); |
| 6596 | if (vport->fc_rscn_flush) { |
| 6597 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 6598 | spin_unlock_irq(shost->host_lock); |
| 6599 | return 0; |
| 6600 | } |
| 6601 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6602 | vport->fc_rscn_flush = 1; |
| 6603 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6604 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6605 | lp = vport->fc_rscn_id_list[i]->virt; |
| 6606 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6607 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6608 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6609 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 6610 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6611 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 6612 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6613 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6614 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 6615 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6616 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6617 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6618 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6619 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 6620 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6621 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6622 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6623 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6624 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6625 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6626 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 6627 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6628 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6629 | } |
| 6630 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6631 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6632 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6633 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6634 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6635 | return_did_out: |
| 6636 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 6637 | vport->fc_rscn_flush = 0; |
| 6638 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6639 | } |
| 6640 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6641 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6642 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6643 | * @vport: pointer to a host virtual N_Port data structure. |
| 6644 | * |
| 6645 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 6646 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 6647 | * State Change Notification). |
| 6648 | * |
| 6649 | * Return code |
| 6650 | * 0 - Successful (currently alway return 0) |
| 6651 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6652 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6653 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6654 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6655 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6656 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6657 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6658 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6659 | if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6660 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6661 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6662 | |
| 6663 | /* NVME Target mode does not do RSCN Recovery. */ |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 6664 | if (vport->phba->nvmet_support) |
| 6665 | continue; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6666 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6667 | /* If we are in the process of doing discovery on this |
| 6668 | * NPort, let it continue on its own. |
| 6669 | */ |
| 6670 | switch (ndlp->nlp_state) { |
| 6671 | case NLP_STE_PLOGI_ISSUE: |
| 6672 | case NLP_STE_ADISC_ISSUE: |
| 6673 | case NLP_STE_REG_LOGIN_ISSUE: |
| 6674 | case NLP_STE_PRLI_ISSUE: |
| 6675 | case NLP_STE_LOGO_ISSUE: |
| 6676 | continue; |
| 6677 | } |
| 6678 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6679 | /* Check to see if we need to NVME rescan this target |
| 6680 | * remoteport. |
| 6681 | */ |
| 6682 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6683 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6684 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 6685 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6686 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 6687 | NLP_EVT_DEVICE_RECOVERY); |
| 6688 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6689 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6690 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6691 | } |
| 6692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6694 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6695 | * @vport: pointer to a host virtual N_Port data structure. |
| 6696 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6697 | * |
| 6698 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 6699 | * applications. |
| 6700 | */ |
| 6701 | static void |
| 6702 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 6703 | struct lpfc_iocbq *cmdiocb) |
| 6704 | { |
| 6705 | struct lpfc_dmabuf *pcmd; |
| 6706 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6707 | uint32_t *payload_ptr; |
| 6708 | uint32_t payload_len; |
| 6709 | struct lpfc_rscn_event_header *rscn_event_data; |
| 6710 | |
| 6711 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6712 | payload_ptr = (uint32_t *) pcmd->virt; |
| 6713 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 6714 | |
| 6715 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 6716 | payload_len, GFP_KERNEL); |
| 6717 | if (!rscn_event_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6718 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6719 | "0147 Failed to allocate memory for RSCN event\n"); |
| 6720 | return; |
| 6721 | } |
| 6722 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 6723 | rscn_event_data->payload_length = payload_len; |
| 6724 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 6725 | payload_len); |
| 6726 | |
| 6727 | fc_host_post_vendor_event(shost, |
| 6728 | fc_get_event_number(), |
Ales Novak | 6599eaa | 2015-08-31 16:48:16 -0400 | [diff] [blame] | 6729 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6730 | (char *)rscn_event_data, |
| 6731 | LPFC_NL_VENDOR_ID); |
| 6732 | |
| 6733 | kfree(rscn_event_data); |
| 6734 | } |
| 6735 | |
| 6736 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6737 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6738 | * @vport: pointer to a host virtual N_Port data structure. |
| 6739 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6740 | * @ndlp: pointer to a node-list data structure. |
| 6741 | * |
| 6742 | * This routine processes an unsolicited RSCN (Registration State Change |
| 6743 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 6744 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 6745 | * discover state machine is about to begin discovery, it just accepts the |
| 6746 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 6747 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 6748 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 6749 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 6750 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 6751 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 6752 | * routine is invoked to handle the RSCN event. |
| 6753 | * |
| 6754 | * Return code |
| 6755 | * 0 - Just sent the acc response |
| 6756 | * 1 - Sent the acc response and waited for name server completion |
| 6757 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6758 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6759 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6760 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6761 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6762 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6763 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6764 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6765 | uint32_t *lp, *datap; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6766 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6767 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6768 | int rscn_id = 0, hba_id = 0; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6769 | int i, tmo; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6770 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6771 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 6772 | lp = (uint32_t *) pcmd->virt; |
| 6773 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6774 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 6775 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6776 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6777 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6778 | "0214 RSCN received Data: x%x x%x x%x x%x\n", |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6779 | vport->fc_flag, payload_len, *lp, |
| 6780 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6781 | |
| 6782 | /* Send an RSCN event to the management application */ |
| 6783 | lpfc_send_rscn_event(vport, cmdiocb); |
| 6784 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6785 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6786 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 6787 | FCH_EVT_RSCN, lp[i]); |
| 6788 | |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6789 | /* Check if RSCN is coming from a direct-connected remote NPort */ |
| 6790 | if (vport->fc_flag & FC_PT2PT) { |
| 6791 | /* If so, just ACC it, no other action needed for now */ |
| 6792 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6793 | "2024 pt2pt RSCN %08x Data: x%x x%x\n", |
| 6794 | *lp, vport->fc_flag, payload_len); |
| 6795 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6796 | |
James Smart | a6d10f2 | 2019-08-14 16:56:50 -0700 | [diff] [blame] | 6797 | /* Check to see if we need to NVME rescan this target |
| 6798 | * remoteport. |
| 6799 | */ |
| 6800 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME && |
| 6801 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) |
James Smart | 6f2589f | 2019-05-14 14:58:07 -0700 | [diff] [blame] | 6802 | lpfc_nvme_rescan_port(vport, ndlp); |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 6803 | return 0; |
| 6804 | } |
| 6805 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6806 | /* If we are about to begin discovery, just ACC the RSCN. |
| 6807 | * Discovery processing will satisfy it. |
| 6808 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6809 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6810 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6811 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 6812 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6813 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6814 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6815 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6816 | } |
| 6817 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6818 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 6819 | * just ACC and ignore it. |
| 6820 | */ |
| 6821 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6822 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6823 | i = payload_len; |
| 6824 | datap = lp; |
| 6825 | while (i > 0) { |
| 6826 | nportid = *datap++; |
| 6827 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 6828 | i -= sizeof(uint32_t); |
| 6829 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6830 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 6831 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6832 | } |
| 6833 | if (rscn_id == hba_id) { |
| 6834 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6835 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6836 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6837 | "Data: x%x x%x x%x x%x\n", |
| 6838 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6839 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6840 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6841 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 6842 | ndlp->nlp_DID, vport->port_state, |
| 6843 | ndlp->nlp_flag); |
| 6844 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6845 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6846 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6847 | return 0; |
| 6848 | } |
| 6849 | } |
| 6850 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6851 | spin_lock_irq(shost->host_lock); |
| 6852 | if (vport->fc_rscn_flush) { |
| 6853 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6854 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 6855 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6856 | /* Send back ACC */ |
| 6857 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6858 | return 0; |
| 6859 | } |
| 6860 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 6861 | vport->fc_rscn_flush = 1; |
| 6862 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6863 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6864 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6865 | /* If we are already processing an RSCN, save the received |
| 6866 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 6867 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6868 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6869 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6870 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 6871 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6872 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6873 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6874 | vport->fc_flag |= FC_RSCN_DEFERRED; |
James Smart | 2332e6e | 2019-11-04 16:57:01 -0800 | [diff] [blame] | 6875 | |
| 6876 | /* Restart disctmo if its already running */ |
| 6877 | if (vport->fc_flag & FC_DISC_TMO) { |
| 6878 | tmo = ((phba->fc_ratov * 3) + 3); |
| 6879 | mod_timer(&vport->fc_disctmo, |
| 6880 | jiffies + msecs_to_jiffies(1000 * tmo)); |
| 6881 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6882 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6883 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6884 | vport->fc_flag |= FC_RSCN_MODE; |
| 6885 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6886 | if (rscn_cnt) { |
| 6887 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 6888 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 6889 | } |
| 6890 | if ((rscn_cnt) && |
| 6891 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 6892 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6893 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6894 | memcpy(((uint8_t *)cmd) + length, lp, |
| 6895 | payload_len); |
| 6896 | } else { |
| 6897 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 6898 | vport->fc_rscn_id_cnt++; |
| 6899 | /* If we zero, cmdiocb->context2, the calling |
| 6900 | * routine will not try to free it. |
| 6901 | */ |
| 6902 | cmdiocb->context2 = NULL; |
| 6903 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6904 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6905 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6906 | "0235 Deferred RSCN " |
| 6907 | "Data: x%x x%x x%x\n", |
| 6908 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6909 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6910 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6911 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 6912 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6913 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6914 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 6915 | "0234 ReDiscovery RSCN " |
| 6916 | "Data: x%x x%x x%x\n", |
| 6917 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 6918 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6919 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6920 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6921 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6922 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6923 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6924 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6925 | lpfc_rscn_recovery_check(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6926 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6927 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6928 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6929 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 6930 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 6931 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6932 | spin_lock_irq(shost->host_lock); |
| 6933 | vport->fc_flag |= FC_RSCN_MODE; |
| 6934 | spin_unlock_irq(shost->host_lock); |
| 6935 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6936 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 6937 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6938 | /* |
| 6939 | * If we zero, cmdiocb->context2, the calling routine will |
| 6940 | * not try to free it. |
| 6941 | */ |
| 6942 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6943 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6944 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6945 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6946 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6947 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6948 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6949 | } |
| 6950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6952 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6953 | * @vport: pointer to a host virtual N_Port data structure. |
| 6954 | * |
| 6955 | * This routine handles the Registration State Configuration Notification |
| 6956 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 6957 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 6958 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 6959 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 6960 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 6961 | * RSCN activities with the @vport. |
| 6962 | * |
| 6963 | * Return code |
| 6964 | * 0 - Cleaned up rscn on the @vport |
| 6965 | * 1 - Wait for plogi to name server before proceed |
| 6966 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6967 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6968 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6969 | { |
| 6970 | struct lpfc_nodelist *ndlp; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 6971 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6972 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6973 | /* Ignore RSCN if the port is being torn down. */ |
| 6974 | if (vport->load_flag & FC_UNLOADING) { |
| 6975 | lpfc_els_flush_rscn(vport); |
| 6976 | return 0; |
| 6977 | } |
| 6978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6979 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6980 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6981 | |
| 6982 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6983 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6984 | "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6985 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 6986 | vport->port_state, vport->num_disc_nodes, |
| 6987 | vport->gidft_inp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6988 | |
| 6989 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6990 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6991 | vport->num_disc_nodes = 0; |
| 6992 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6993 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6994 | if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 6995 | /* Good ndlp, issue CT Request to NameServer. Need to |
| 6996 | * know how many gidfts were issued. If none, then just |
| 6997 | * flush the RSCN. Otherwise, the outstanding requests |
| 6998 | * need to complete. |
| 6999 | */ |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 7000 | if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) { |
| 7001 | if (lpfc_issue_gidft(vport) > 0) |
| 7002 | return 1; |
| 7003 | } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) { |
| 7004 | if (lpfc_issue_gidpt(vport) > 0) |
| 7005 | return 1; |
| 7006 | } else { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7007 | return 1; |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 7008 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7009 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 7010 | /* Nameserver login in question. Revalidate. */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7011 | if (ndlp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7012 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 7013 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7014 | } else { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 7015 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7016 | if (!ndlp) { |
| 7017 | lpfc_els_flush_rscn(vport); |
| 7018 | return 0; |
| 7019 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7020 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7021 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7022 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7023 | ndlp->nlp_type |= NLP_FABRIC; |
| 7024 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 7025 | /* Wait for NameServer login cmpl before we can |
| 7026 | * continue |
| 7027 | */ |
| 7028 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7029 | } |
| 7030 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7031 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7032 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7033 | } |
| 7034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7035 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7036 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7037 | * @vport: pointer to a host virtual N_Port data structure. |
| 7038 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7039 | * @ndlp: pointer to a node-list data structure. |
| 7040 | * |
| 7041 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 7042 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 7043 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 7044 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 7045 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 7046 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 7047 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 7048 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 7049 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 7050 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 7051 | * higher priority (as the winning port) and will initiate PLOGI and |
| 7052 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 7053 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 7054 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 7055 | * |
| 7056 | * Return code |
| 7057 | * 0 - Successfully processed the unsolicited flogi |
| 7058 | * 1 - Failed to process the unsolicited flogi |
| 7059 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7060 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7061 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7062 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7063 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7064 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7065 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7066 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7067 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 7068 | IOCB_t *icmd = &cmdiocb->iocb; |
| 7069 | struct serv_parm *sp; |
| 7070 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7071 | uint32_t cmd, did; |
| 7072 | int rc; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 7073 | uint32_t fc_flag = 0; |
| 7074 | uint32_t port_state = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7075 | |
| 7076 | cmd = *lp++; |
| 7077 | sp = (struct serv_parm *) lp; |
| 7078 | |
| 7079 | /* FLOGI received */ |
| 7080 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7081 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7082 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7083 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7084 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 7085 | did = icmd->un.elsreq64.remoteID; |
| 7086 | |
| 7087 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 7088 | Loop Mode */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7089 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7090 | "0113 An FLOGI ELS command x%x was " |
| 7091 | "received from DID x%x in Loop Mode\n", |
| 7092 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7093 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7094 | } |
| 7095 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7096 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7097 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7098 | /* |
| 7099 | * If our portname is greater than the remote portname, |
| 7100 | * then we initiate Nport login. |
| 7101 | */ |
| 7102 | |
| 7103 | rc = memcmp(&vport->fc_portname, &sp->portName, |
| 7104 | sizeof(struct lpfc_name)); |
| 7105 | |
| 7106 | if (!rc) { |
| 7107 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 7108 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 7109 | GFP_KERNEL); |
| 7110 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7111 | return 1; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7112 | lpfc_linkdown(phba); |
| 7113 | lpfc_init_link(phba, mbox, |
| 7114 | phba->cfg_topology, |
| 7115 | phba->cfg_link_speed); |
| 7116 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 7117 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 7118 | mbox->vport = vport; |
| 7119 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 7120 | MBX_NOWAIT); |
| 7121 | lpfc_set_loopback_flag(phba); |
| 7122 | if (rc == MBX_NOT_FINISHED) |
| 7123 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7124 | return 1; |
| 7125 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7126 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7127 | /* abort the flogi coming back to ourselves |
| 7128 | * due to external loopback on the port. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7129 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7130 | lpfc_els_abort_flogi(phba); |
| 7131 | return 0; |
| 7132 | |
| 7133 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7134 | spin_lock_irq(shost->host_lock); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7135 | vport->fc_flag |= FC_PT2PT_PLOGI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7136 | spin_unlock_irq(shost->host_lock); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7137 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7138 | /* If we have the high WWPN we can assign our own |
| 7139 | * myDID; otherwise, we have to WAIT for a PLOGI |
| 7140 | * from the remote NPort to find out what it |
| 7141 | * will be. |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7142 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7143 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7144 | } else { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7145 | vport->fc_myDID = PT2PT_RemoteID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7146 | } |
| 7147 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7148 | /* |
| 7149 | * The vport state should go to LPFC_FLOGI only |
| 7150 | * AFTER we issue a FLOGI, not receive one. |
| 7151 | */ |
| 7152 | spin_lock_irq(shost->host_lock); |
| 7153 | fc_flag = vport->fc_flag; |
| 7154 | port_state = vport->port_state; |
| 7155 | vport->fc_flag |= FC_PT2PT; |
| 7156 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 7157 | |
| 7158 | /* Acking an unsol FLOGI. Count 1 for link bounce |
| 7159 | * work-around. |
| 7160 | */ |
| 7161 | vport->rcv_flogi_cnt++; |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7162 | spin_unlock_irq(shost->host_lock); |
| 7163 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7164 | "3311 Rcv Flogi PS x%x new PS x%x " |
| 7165 | "fc_flag x%x new fc_flag x%x\n", |
| 7166 | port_state, vport->port_state, |
| 7167 | fc_flag, vport->fc_flag); |
| 7168 | |
| 7169 | /* |
| 7170 | * We temporarily set fc_myDID to make it look like we are |
| 7171 | * a Fabric. This is done just so we end up with the right |
| 7172 | * did / sid on the FLOGI ACC rsp. |
| 7173 | */ |
| 7174 | did = vport->fc_myDID; |
| 7175 | vport->fc_myDID = Fabric_DID; |
| 7176 | |
| 7177 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 7178 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 7179 | /* Defer ACC response until AFTER we issue a FLOGI */ |
| 7180 | if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) { |
| 7181 | phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext; |
| 7182 | phba->defer_flogi_acc_ox_id = |
| 7183 | cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
| 7184 | |
| 7185 | vport->fc_myDID = did; |
| 7186 | |
| 7187 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7188 | "3344 Deferring FLOGI ACC: rx_id: x%x," |
| 7189 | " ox_id: x%x, hba_flag x%x\n", |
| 7190 | phba->defer_flogi_acc_rx_id, |
| 7191 | phba->defer_flogi_acc_ox_id, phba->hba_flag); |
| 7192 | |
| 7193 | phba->defer_flogi_acc_flag = true; |
| 7194 | |
| 7195 | return 0; |
| 7196 | } |
| 7197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7198 | /* Send back ACC */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 7199 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7200 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7201 | /* Now lets put fc_myDID back to what its supposed to be */ |
| 7202 | vport->fc_myDID = did; |
| 7203 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7204 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7205 | } |
| 7206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7208 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7209 | * @vport: pointer to a host virtual N_Port data structure. |
| 7210 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7211 | * @ndlp: pointer to a node-list data structure. |
| 7212 | * |
| 7213 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 7214 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 7215 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 7216 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 7217 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 7218 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 7219 | * |
| 7220 | * Return code |
| 7221 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 7222 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7223 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7224 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7225 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7226 | { |
| 7227 | struct lpfc_dmabuf *pcmd; |
| 7228 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7229 | RNID *rn; |
| 7230 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7232 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7233 | lp = (uint32_t *) pcmd->virt; |
| 7234 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7235 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7236 | rn = (RNID *) lp; |
| 7237 | |
| 7238 | /* RNID received */ |
| 7239 | |
| 7240 | switch (rn->Format) { |
| 7241 | case 0: |
| 7242 | case RNID_TOPOLOGY_DISC: |
| 7243 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7244 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7245 | break; |
| 7246 | default: |
| 7247 | /* Reject this request because format not supported */ |
| 7248 | stat.un.b.lsRjtRsvd0 = 0; |
| 7249 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7250 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7251 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7252 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7253 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7254 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7255 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7256 | } |
| 7257 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7258 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7259 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 7260 | * @vport: pointer to a host virtual N_Port data structure. |
| 7261 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7262 | * @ndlp: pointer to a node-list data structure. |
| 7263 | * |
| 7264 | * Return code |
| 7265 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 7266 | **/ |
| 7267 | static int |
| 7268 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7269 | struct lpfc_nodelist *ndlp) |
| 7270 | { |
| 7271 | uint8_t *pcmd; |
| 7272 | |
| 7273 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 7274 | |
| 7275 | /* skip over first word of echo command to find echo data */ |
| 7276 | pcmd += sizeof(uint32_t); |
| 7277 | |
| 7278 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 7279 | return 0; |
| 7280 | } |
| 7281 | |
| 7282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7283 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7284 | * @vport: pointer to a host virtual N_Port data structure. |
| 7285 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7286 | * @ndlp: pointer to a node-list data structure. |
| 7287 | * |
| 7288 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 7289 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 7290 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 7291 | * |
| 7292 | * Return code |
| 7293 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 7294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7295 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7296 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7297 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7298 | { |
| 7299 | struct ls_rjt stat; |
| 7300 | |
| 7301 | /* For now, unconditionally reject this command */ |
| 7302 | stat.un.b.lsRjtRsvd0 = 0; |
| 7303 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7304 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7305 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7306 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7307 | return 0; |
| 7308 | } |
| 7309 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7310 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7311 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 7312 | * @vport: pointer to a host virtual N_Port data structure. |
| 7313 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7314 | * @ndlp: pointer to a node-list data structure. |
| 7315 | * |
| 7316 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 7317 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 7318 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 7319 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 7320 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 7321 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 7322 | * command request" and reason code explanation "Invalid Originator |
| 7323 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 7324 | * RRQ from the target. |
| 7325 | **/ |
| 7326 | static void |
| 7327 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7328 | struct lpfc_nodelist *ndlp) |
| 7329 | { |
| 7330 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7331 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 7332 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7336 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 7337 | * @phba: pointer to lpfc hba data structure. |
| 7338 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 7339 | * |
| 7340 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 7341 | * mailbox command. This callback function is to actually send the Accept |
| 7342 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 7343 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 7344 | * mailbox command, constructs the RPS response with the link statistics |
| 7345 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 7346 | * response to the RPS. |
| 7347 | * |
| 7348 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7349 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7350 | * will be stored into the context1 field of the IOCB for the completion |
| 7351 | * callback function to the RPS Accept Response ELS IOCB command. |
| 7352 | * |
| 7353 | **/ |
| 7354 | static void |
| 7355 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7356 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7357 | int rc = 0; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7358 | MAILBOX_t *mb; |
| 7359 | IOCB_t *icmd; |
| 7360 | struct RLS_RSP *rls_rsp; |
| 7361 | uint8_t *pcmd; |
| 7362 | struct lpfc_iocbq *elsiocb; |
| 7363 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7364 | uint16_t oxid; |
| 7365 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7366 | uint32_t cmdsize; |
| 7367 | |
| 7368 | mb = &pmb->u.mb; |
| 7369 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7370 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 7371 | rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff); |
| 7372 | oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff); |
| 7373 | pmb->ctx_buf = NULL; |
| 7374 | pmb->ctx_ndlp = NULL; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7375 | |
| 7376 | if (mb->mbxStatus) { |
| 7377 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7378 | return; |
| 7379 | } |
| 7380 | |
| 7381 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7382 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7383 | lpfc_max_els_tries, ndlp, |
| 7384 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7385 | |
| 7386 | /* Decrement the ndlp reference count from previous mbox command */ |
| 7387 | lpfc_nlp_put(ndlp); |
| 7388 | |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7389 | if (!elsiocb) { |
| 7390 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7391 | return; |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7392 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7393 | |
| 7394 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7395 | icmd->ulpContext = rxid; |
| 7396 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7397 | |
| 7398 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7399 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 7400 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7401 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 7402 | |
| 7403 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 7404 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 7405 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 7406 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 7407 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 7408 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
James Smart | 37db57e | 2012-05-09 21:17:16 -0400 | [diff] [blame] | 7409 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7410 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7411 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7412 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 7413 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 7414 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7415 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7416 | ndlp->nlp_rpi); |
| 7417 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7418 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7419 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7420 | if (!elsiocb->context1) |
| 7421 | goto node_err; |
| 7422 | |
| 7423 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7424 | if (rc == IOCB_ERROR) |
| 7425 | goto io_err; |
| 7426 | return; |
| 7427 | |
| 7428 | io_err: |
| 7429 | lpfc_nlp_put(ndlp); |
| 7430 | node_err: |
| 7431 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7432 | } |
| 7433 | |
| 7434 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7435 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 7436 | * @vport: pointer to a host virtual N_Port data structure. |
| 7437 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7438 | * @ndlp: pointer to a node-list data structure. |
| 7439 | * |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7440 | * This routine processes Read Link Status (RLS) IOCB received as an |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7441 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7442 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7443 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7444 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 7445 | * for reading the HBA link statistics. It is for the callback function, |
| 7446 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 7447 | * to actually sending out RPL Accept (ACC) response. |
| 7448 | * |
| 7449 | * Return codes |
| 7450 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 7451 | **/ |
| 7452 | static int |
| 7453 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7454 | struct lpfc_nodelist *ndlp) |
| 7455 | { |
| 7456 | struct lpfc_hba *phba = vport->phba; |
| 7457 | LPFC_MBOXQ_t *mbox; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7458 | struct ls_rjt stat; |
| 7459 | |
| 7460 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7461 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7462 | /* reject the unsolicited RLS request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7463 | goto reject_out; |
| 7464 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7465 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 7466 | if (mbox) { |
| 7467 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7468 | mbox->ctx_buf = (void *)((unsigned long) |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7469 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 7470 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7471 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7472 | if (!mbox->ctx_ndlp) |
| 7473 | goto node_err; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7474 | mbox->vport = vport; |
| 7475 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 7476 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 7477 | != MBX_NOT_FINISHED) |
| 7478 | /* Mbox completion will send ELS Response */ |
| 7479 | return 0; |
| 7480 | /* Decrement reference count used for the failed mbox |
| 7481 | * command. |
| 7482 | */ |
| 7483 | lpfc_nlp_put(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7484 | node_err: |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7485 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7486 | } |
| 7487 | reject_out: |
| 7488 | /* issue rejection response */ |
| 7489 | stat.un.b.lsRjtRsvd0 = 0; |
| 7490 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7491 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7492 | stat.un.b.vendorUnique = 0; |
| 7493 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7494 | return 0; |
| 7495 | } |
| 7496 | |
| 7497 | /** |
| 7498 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 7499 | * @vport: pointer to a host virtual N_Port data structure. |
| 7500 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7501 | * @ndlp: pointer to a node-list data structure. |
| 7502 | * |
| 7503 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 7504 | * ELS unsolicited event. It first checks the remote port state. If the |
| 7505 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 7506 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 7507 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 7508 | * Value (RTV) unsolicited IOCB event. |
| 7509 | * |
| 7510 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7511 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7512 | * will be stored into the context1 field of the IOCB for the completion |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7513 | * callback function to the RTV Accept Response ELS IOCB command. |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7514 | * |
| 7515 | * Return codes |
| 7516 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 7517 | **/ |
| 7518 | static int |
| 7519 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7520 | struct lpfc_nodelist *ndlp) |
| 7521 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7522 | int rc = 0; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7523 | struct lpfc_hba *phba = vport->phba; |
| 7524 | struct ls_rjt stat; |
| 7525 | struct RTV_RSP *rtv_rsp; |
| 7526 | uint8_t *pcmd; |
| 7527 | struct lpfc_iocbq *elsiocb; |
| 7528 | uint32_t cmdsize; |
| 7529 | |
| 7530 | |
| 7531 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7532 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7533 | /* reject the unsolicited RTV request and done with it */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7534 | goto reject_out; |
| 7535 | |
| 7536 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 7537 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 7538 | lpfc_max_els_tries, ndlp, |
| 7539 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 7540 | |
| 7541 | if (!elsiocb) |
| 7542 | return 1; |
| 7543 | |
| 7544 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 7545 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7546 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 7547 | |
| 7548 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7549 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 7550 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7551 | |
| 7552 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 7553 | |
| 7554 | /* populate RTV payload */ |
| 7555 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 7556 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 7557 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 7558 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 7559 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 7560 | |
| 7561 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 7562 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 7563 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 7564 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 7565 | "Data: x%x x%x x%x\n", |
| 7566 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7567 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7568 | ndlp->nlp_rpi, |
| 7569 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 7570 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 7571 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7572 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7573 | if (!elsiocb->context1) { |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7574 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7575 | return 0; |
| 7576 | } |
| 7577 | |
| 7578 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7579 | if (rc == IOCB_ERROR) { |
| 7580 | lpfc_nlp_put(ndlp); |
| 7581 | lpfc_els_free_iocb(phba, elsiocb); |
| 7582 | } |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 7583 | return 0; |
| 7584 | |
| 7585 | reject_out: |
| 7586 | /* issue rejection response */ |
| 7587 | stat.un.b.lsRjtRsvd0 = 0; |
| 7588 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7589 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7590 | stat.un.b.vendorUnique = 0; |
| 7591 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 7592 | return 0; |
| 7593 | } |
| 7594 | |
James Smart | 6cde2e3e | 2020-01-27 16:23:08 -0800 | [diff] [blame] | 7595 | /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7596 | * @vport: pointer to a host virtual N_Port data structure. |
| 7597 | * @ndlp: pointer to a node-list data structure. |
| 7598 | * @did: DID of the target. |
| 7599 | * @rrq: Pointer to the rrq struct. |
| 7600 | * |
| 7601 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 7602 | * Successful the the completion handler will clear the RRQ. |
| 7603 | * |
| 7604 | * Return codes |
| 7605 | * 0 - Successfully sent rrq els iocb. |
| 7606 | * 1 - Failed to send rrq els iocb. |
| 7607 | **/ |
| 7608 | static int |
| 7609 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7610 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 7611 | { |
| 7612 | struct lpfc_hba *phba = vport->phba; |
| 7613 | struct RRQ *els_rrq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7614 | struct lpfc_iocbq *elsiocb; |
| 7615 | uint8_t *pcmd; |
| 7616 | uint16_t cmdsize; |
| 7617 | int ret; |
| 7618 | |
| 7619 | |
| 7620 | if (ndlp != rrq->ndlp) |
| 7621 | ndlp = rrq->ndlp; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 7622 | if (!ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7623 | return 1; |
| 7624 | |
| 7625 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 7626 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 7627 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 7628 | ELS_CMD_RRQ); |
| 7629 | if (!elsiocb) |
| 7630 | return 1; |
| 7631 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7632 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7633 | |
| 7634 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 7635 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 7636 | pcmd += sizeof(uint32_t); |
| 7637 | els_rrq = (struct RRQ *) pcmd; |
| 7638 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 7639 | bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7640 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 7641 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 7642 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 7643 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 7644 | |
| 7645 | |
| 7646 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7647 | "Issue RRQ: did:x%x", |
| 7648 | did, rrq->xritag, rrq->rxid); |
| 7649 | elsiocb->context_un.rrq = rrq; |
| 7650 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7651 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7652 | if (!elsiocb->context1) |
| 7653 | goto node_err; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7654 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7655 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7656 | if (ret == IOCB_ERROR) |
| 7657 | goto io_err; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7658 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7659 | |
| 7660 | io_err: |
| 7661 | lpfc_nlp_put(ndlp); |
| 7662 | node_err: |
| 7663 | lpfc_els_free_iocb(phba, elsiocb); |
| 7664 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 7669 | * @phba: pointer to lpfc hba data structure. |
| 7670 | * @rrq: pointer to the active rrq. |
| 7671 | * |
| 7672 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 7673 | * still active for the xri. If this function returns a failure then |
| 7674 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 7675 | * |
| 7676 | * Returns 0 Success. |
| 7677 | * 1 Failure. |
| 7678 | **/ |
| 7679 | int |
| 7680 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 7681 | { |
| 7682 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
James Smart | c8cb261 | 2019-05-06 17:26:49 -0700 | [diff] [blame] | 7683 | rrq->nlp_DID); |
| 7684 | if (!ndlp) |
| 7685 | return 1; |
| 7686 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7687 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 7688 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 7689 | rrq->nlp_DID, rrq); |
| 7690 | else |
| 7691 | return 1; |
| 7692 | } |
| 7693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7694 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7695 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7696 | * @vport: pointer to a host virtual N_Port data structure. |
| 7697 | * @cmdsize: size of the ELS command. |
| 7698 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 7699 | * @ndlp: pointer to a node-list data structure. |
| 7700 | * |
| 7701 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 7702 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 7703 | * |
| 7704 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7705 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7706 | * will be stored into the context1 field of the IOCB for the completion |
| 7707 | * callback function to the RPL Accept Response ELS command. |
| 7708 | * |
| 7709 | * Return code |
| 7710 | * 0 - Successfully issued ACC RPL ELS command |
| 7711 | * 1 - Failed to issue ACC RPL ELS command |
| 7712 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 7713 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7714 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 7715 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7716 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7717 | int rc = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7718 | struct lpfc_hba *phba = vport->phba; |
| 7719 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7720 | RPL_RSP rpl_rsp; |
| 7721 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7722 | uint8_t *pcmd; |
| 7723 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7724 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 7725 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7726 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7727 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7728 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 7729 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7730 | icmd = &elsiocb->iocb; |
| 7731 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7732 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 7733 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7734 | |
| 7735 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7736 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7737 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7738 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 7739 | pcmd += sizeof(uint16_t); |
| 7740 | |
| 7741 | /* Setup the RPL ACC payload */ |
| 7742 | rpl_rsp.listLen = be32_to_cpu(1); |
| 7743 | rpl_rsp.index = 0; |
| 7744 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7745 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 7746 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7747 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7748 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7749 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7750 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7751 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 7752 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 7753 | "rpi x%x\n", |
| 7754 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 7755 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 7756 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7757 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7758 | phba->fc_stat.elsXmitACC++; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7759 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 7760 | if (!elsiocb->context1) |
| 7761 | goto node_err; |
| 7762 | |
| 7763 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 7764 | if (rc == IOCB_ERROR) |
| 7765 | goto io_err; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7766 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 7767 | |
| 7768 | io_err: |
| 7769 | lpfc_nlp_put(ndlp); |
| 7770 | node_err: |
| 7771 | lpfc_els_free_iocb(phba, elsiocb); |
| 7772 | return 1; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7773 | } |
| 7774 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7775 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7776 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7777 | * @vport: pointer to a host virtual N_Port data structure. |
| 7778 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7779 | * @ndlp: pointer to a node-list data structure. |
| 7780 | * |
| 7781 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 7782 | * unsolicited event. It first checks the remote port state. If the remote |
| 7783 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 7784 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 7785 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 7786 | * to accept the RPL. |
| 7787 | * |
| 7788 | * Return code |
| 7789 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 7790 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7791 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7792 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7793 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7794 | { |
| 7795 | struct lpfc_dmabuf *pcmd; |
| 7796 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7797 | uint32_t maxsize; |
| 7798 | uint16_t cmdsize; |
| 7799 | RPL *rpl; |
| 7800 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7801 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7802 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 7803 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7804 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7805 | stat.un.b.lsRjtRsvd0 = 0; |
| 7806 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 7807 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 7808 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7809 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 7810 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 7811 | /* rejected the unsolicited RPL request and done with it */ |
| 7812 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7813 | } |
| 7814 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7815 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7816 | lp = (uint32_t *) pcmd->virt; |
| 7817 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7818 | maxsize = be32_to_cpu(rpl->maxsize); |
| 7819 | |
| 7820 | /* We support only one port */ |
| 7821 | if ((rpl->index == 0) && |
| 7822 | ((maxsize == 0) || |
| 7823 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 7824 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 7825 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 7826 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 7827 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7828 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7829 | |
| 7830 | return 0; |
| 7831 | } |
| 7832 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7833 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7834 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7835 | * @vport: pointer to a virtual N_Port data structure. |
| 7836 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7837 | * @ndlp: pointer to a node-list data structure. |
| 7838 | * |
| 7839 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7840 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 7841 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 7842 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 7843 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 7844 | * remote PortName is compared against the FC PortName stored in the @vport |
| 7845 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 7846 | * compared against the FC NodeName stored in the @vport data structure. |
| 7847 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 7848 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 7849 | * invoked to send out FARP Response to the remote node. Before sending the |
| 7850 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 7851 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 7852 | * routine is invoked to log into the remote port first. |
| 7853 | * |
| 7854 | * Return code |
| 7855 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 7856 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7857 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7858 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7859 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7860 | { |
| 7861 | struct lpfc_dmabuf *pcmd; |
| 7862 | uint32_t *lp; |
| 7863 | IOCB_t *icmd; |
| 7864 | FARP *fp; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7865 | uint32_t cnt, did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7866 | |
| 7867 | icmd = &cmdiocb->iocb; |
| 7868 | did = icmd->un.elsreq64.remoteID; |
| 7869 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7870 | lp = (uint32_t *) pcmd->virt; |
| 7871 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7872 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7873 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7874 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7875 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7876 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7877 | /* We will only support match on WWPN or WWNN */ |
| 7878 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7879 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | cnt = 0; |
| 7883 | /* If this FARP command is searching for my portname */ |
| 7884 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7885 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7886 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7887 | cnt = 1; |
| 7888 | } |
| 7889 | |
| 7890 | /* If this FARP command is searching for my nodename */ |
| 7891 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7892 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7893 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7894 | cnt = 1; |
| 7895 | } |
| 7896 | |
| 7897 | if (cnt) { |
| 7898 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 7899 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 7900 | /* Log back into the node before sending the FARP. */ |
| 7901 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7902 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7903 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 7904 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7905 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7909 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 7910 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7911 | } |
| 7912 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 7913 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7914 | } |
| 7915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7917 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7918 | * @vport: pointer to a host virtual N_Port data structure. |
| 7919 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7920 | * @ndlp: pointer to a node-list data structure. |
| 7921 | * |
| 7922 | * This routine processes Fibre Channel Address Resolution Protocol |
| 7923 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 7924 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 7925 | * the FARP response request. |
| 7926 | * |
| 7927 | * Return code |
| 7928 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 7929 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7930 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7931 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7932 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7933 | { |
| 7934 | struct lpfc_dmabuf *pcmd; |
| 7935 | uint32_t *lp; |
| 7936 | IOCB_t *icmd; |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7937 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7938 | |
| 7939 | icmd = &cmdiocb->iocb; |
| 7940 | did = icmd->un.elsreq64.remoteID; |
| 7941 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 7942 | lp = (uint32_t *) pcmd->virt; |
| 7943 | |
Bart Van Assche | b27cbd5 | 2019-03-28 11:06:20 -0700 | [diff] [blame] | 7944 | lp++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7945 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7946 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7947 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7948 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 7949 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7950 | |
| 7951 | return 0; |
| 7952 | } |
| 7953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7955 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7956 | * @vport: pointer to a host virtual N_Port data structure. |
| 7957 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7958 | * @fan_ndlp: pointer to a node-list data structure. |
| 7959 | * |
| 7960 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 7961 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 7962 | * only be processed on a physical port (i.e., the @vport represents the |
| 7963 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 7964 | * compared against those in the phba data structure. If any of those is |
| 7965 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 7966 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 7967 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 7968 | * is invoked to register login to the fabric. |
| 7969 | * |
| 7970 | * Return code |
| 7971 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 7972 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7973 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7974 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 7975 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7976 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7977 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7978 | uint32_t *lp; |
| 7979 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7980 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7981 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 7982 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 7983 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7984 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7985 | if ((vport == phba->pport) && |
| 7986 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7987 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7988 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 7989 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7990 | sizeof(struct lpfc_name)))) { |
| 7991 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7992 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 7993 | } else { |
| 7994 | /* FAN verified - skip FLOGI */ |
| 7995 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7996 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 7997 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7998 | else { |
| 7999 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8000 | "3138 Need register VFI: (x%x/%x)\n", |
| 8001 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8002 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8003 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8004 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8005 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 8006 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8007 | } |
| 8008 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8009 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8010 | * lpfc_els_timeout - Handler funciton to the els timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8011 | * @t: timer context used to obtain the vport. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8012 | * |
| 8013 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 8014 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 8015 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 8016 | * up the worker thread. It is for the worker thread to invoke the routine |
| 8017 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 8018 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8019 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8020 | lpfc_els_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8021 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8022 | struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8023 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8024 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8025 | unsigned long iflag; |
| 8026 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8027 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8028 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8029 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8030 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8031 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8032 | |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8033 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8034 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8035 | return; |
| 8036 | } |
| 8037 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8038 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8039 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8040 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8041 | * @vport: pointer to a virtual N_Port data structure. |
| 8042 | * |
| 8043 | * This routine is the actual handler function that processes an ELS timeout |
| 8044 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 8045 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 8046 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 8047 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8048 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8049 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8050 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8051 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8052 | struct lpfc_sli_ring *pring; |
| 8053 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8054 | IOCB_t *cmd = NULL; |
| 8055 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8056 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8057 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8058 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8059 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8060 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8062 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 8063 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8064 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 8065 | if (unlikely(!pring)) |
| 8066 | return; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8067 | |
James Smart | e304142 | 2020-04-21 13:33:54 -0700 | [diff] [blame] | 8068 | if (phba->pport->load_flag & FC_UNLOADING) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8069 | return; |
James Smart | e304142 | 2020-04-21 13:33:54 -0700 | [diff] [blame] | 8070 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8071 | spin_lock_irq(&phba->hbalock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8072 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8073 | spin_lock(&pring->ring_lock); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8074 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8075 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8076 | cmd = &piocb->iocb; |
| 8077 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8078 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 8079 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 8080 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8081 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8082 | |
| 8083 | if (piocb->vport != vport) |
| 8084 | continue; |
| 8085 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8086 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8087 | if (pcmd) |
| 8088 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8089 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8090 | if (els_command == ELS_CMD_FARP || |
| 8091 | els_command == ELS_CMD_FARPR || |
| 8092 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8093 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8095 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8096 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8097 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8098 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8099 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8100 | continue; |
| 8101 | } |
| 8102 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8103 | remote_ID = 0xffffffff; |
| 8104 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8105 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8106 | else { |
| 8107 | struct lpfc_nodelist *ndlp; |
| 8108 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 8109 | if (ndlp) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8110 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8111 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8112 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8113 | } |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8114 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8115 | spin_unlock(&pring->ring_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8116 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 8117 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8118 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | 15026c9 | 2013-12-17 20:30:09 -0500 | [diff] [blame] | 8119 | cmd = &piocb->iocb; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8120 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8121 | "0127 ELS timeout Data: x%x x%x x%x " |
| 8122 | "x%x\n", els_command, |
| 8123 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 8124 | spin_lock_irq(&phba->hbalock); |
| 8125 | list_del_init(&piocb->dlist); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 8126 | lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8127 | spin_unlock_irq(&phba->hbalock); |
| 8128 | } |
| 8129 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8130 | if (!list_empty(&pring->txcmplq)) |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 8131 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 8132 | mod_timer(&vport->els_tmofunc, |
| 8133 | jiffies + msecs_to_jiffies(1000 * timeout)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8134 | } |
| 8135 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8136 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8137 | * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8138 | * @vport: pointer to a host virtual N_Port data structure. |
| 8139 | * |
| 8140 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8141 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 8142 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8143 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8144 | * the IOCBs with a non-NULL completion callback function, the callback |
| 8145 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8146 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 8147 | * callback function, the IOCB will simply be released. Finally, it walks |
| 8148 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 8149 | * completion queue IOCB that is associated with the @vport and is not |
| 8150 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 8151 | * part of the discovery state machine) out to HBA by invoking the |
| 8152 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 8153 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 8154 | * the IOCBs are aborted when this function returns. |
| 8155 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8156 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8157 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8158 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8159 | LIST_HEAD(abort_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8160 | struct lpfc_hba *phba = vport->phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8161 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8162 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 8163 | IOCB_t *cmd = NULL; |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8164 | unsigned long iflags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8165 | |
| 8166 | lpfc_fabric_abort_vport(vport); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8167 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8168 | /* |
| 8169 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate |
| 8170 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag |
| 8171 | * ultimately grabs the ring_lock, the driver must splice the list into |
| 8172 | * a working list and release the locks before calling the abort. |
| 8173 | */ |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8174 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8175 | pring = lpfc_phba_elsring(phba); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8176 | |
| 8177 | /* Bail out if we've no ELS wq, like in PCI error recovery case. */ |
| 8178 | if (unlikely(!pring)) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8179 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Guilherme G. Piccoli | 53cf29d | 2017-05-17 19:02:17 -0300 | [diff] [blame] | 8180 | return; |
| 8181 | } |
| 8182 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8183 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8184 | spin_lock(&pring->ring_lock); |
| 8185 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8186 | /* First we need to issue aborts to outstanding cmds on txcmpl */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8187 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 8188 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 8189 | continue; |
| 8190 | |
| 8191 | if (piocb->vport != vport) |
| 8192 | continue; |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8193 | |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 8194 | if (piocb->iocb_flag & LPFC_DRIVER_ABORTED) |
| 8195 | continue; |
| 8196 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8197 | /* On the ELS ring we can have ELS_REQUESTs or |
| 8198 | * GEN_REQUESTs waiting for a response. |
| 8199 | */ |
| 8200 | cmd = &piocb->iocb; |
| 8201 | if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| 8202 | list_add_tail(&piocb->dlist, &abort_list); |
| 8203 | |
| 8204 | /* If the link is down when flushing ELS commands |
| 8205 | * the firmware will not complete them till after |
| 8206 | * the link comes back up. This may confuse |
| 8207 | * discovery for the new link up, so we need to |
| 8208 | * change the compl routine to just clean up the iocb |
| 8209 | * and avoid any retry logic. |
| 8210 | */ |
| 8211 | if (phba->link_state == LPFC_LINK_DOWN) |
| 8212 | piocb->iocb_cmpl = lpfc_cmpl_els_link_down; |
| 8213 | } |
| 8214 | if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) |
| 8215 | list_add_tail(&piocb->dlist, &abort_list); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8216 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8217 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8218 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8219 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8220 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8221 | |
| 8222 | /* Abort each txcmpl iocb on aborted list and remove the dlist links. */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8223 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8224 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8225 | list_del_init(&piocb->dlist); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 8226 | lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8227 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8228 | } |
| 8229 | if (!list_empty(&abort_list)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8230 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8231 | "3387 abort list for txq not empty\n"); |
| 8232 | INIT_LIST_HEAD(&abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8233 | |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8234 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8235 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8236 | spin_lock(&pring->ring_lock); |
| 8237 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8238 | /* No need to abort the txq list, |
| 8239 | * just queue them up for lpfc_sli_cancel_iocbs |
| 8240 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8241 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 8242 | cmd = &piocb->iocb; |
| 8243 | |
| 8244 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 8245 | continue; |
| 8246 | } |
| 8247 | |
| 8248 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8249 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 8250 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 8251 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 8252 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8253 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8254 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8255 | if (piocb->vport != vport) |
| 8256 | continue; |
| 8257 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8258 | list_del_init(&piocb->list); |
| 8259 | list_add_tail(&piocb->list, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8260 | } |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8261 | |
| 8262 | /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */ |
| 8263 | if (vport == phba->pport) { |
| 8264 | list_for_each_entry_safe(piocb, tmp_iocb, |
| 8265 | &phba->fabric_iocb_list, list) { |
| 8266 | cmd = &piocb->iocb; |
| 8267 | list_del_init(&piocb->list); |
| 8268 | list_add_tail(&piocb->list, &abort_list); |
| 8269 | } |
| 8270 | } |
| 8271 | |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8272 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8273 | spin_unlock(&pring->ring_lock); |
James Smart | d38b4a5 | 2019-09-21 20:59:00 -0700 | [diff] [blame] | 8274 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8275 | |
James Smart | 6ede2dd | 2019-08-14 16:56:44 -0700 | [diff] [blame] | 8276 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8277 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
| 8278 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8279 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8280 | return; |
| 8281 | } |
| 8282 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8283 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8284 | * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8285 | * @phba: pointer to lpfc hba data structure. |
| 8286 | * |
| 8287 | * This routine is used to clean up all the outstanding ELS commands on a |
| 8288 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 8289 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 8290 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 8291 | * the IOCBs with the completion callback function associated, the callback |
| 8292 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 8293 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 8294 | * callback function associated, the IOCB will simply be released. Finally, |
| 8295 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 8296 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 8297 | * management plane IOCBs that are not part of the discovery state machine) |
| 8298 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 8299 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8300 | void |
| 8301 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 8302 | { |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8303 | struct lpfc_vport *vport; |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8304 | |
| 8305 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 0976e1a | 2013-12-17 20:29:36 -0500 | [diff] [blame] | 8306 | list_for_each_entry(vport, &phba->port_list, listentry) |
| 8307 | lpfc_els_flush_cmd(vport); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 8308 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8309 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8310 | return; |
| 8311 | } |
| 8312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8314 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8315 | * @phba: Pointer to hba context object. |
| 8316 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 8317 | * @rspiocbp: Pointer to response iocb which reported error. |
| 8318 | * |
| 8319 | * This function sends an event when there is an ELS command |
| 8320 | * failure. |
| 8321 | **/ |
| 8322 | void |
| 8323 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 8324 | struct lpfc_iocbq *cmdiocbp, |
| 8325 | struct lpfc_iocbq *rspiocbp) |
| 8326 | { |
| 8327 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 8328 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8329 | struct lpfc_lsrjt_event lsrjt_event; |
| 8330 | struct lpfc_fabric_event_header fabric_event; |
| 8331 | struct ls_rjt stat; |
| 8332 | struct lpfc_nodelist *ndlp; |
| 8333 | uint32_t *pcmd; |
| 8334 | |
| 8335 | ndlp = cmdiocbp->context1; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 8336 | if (!ndlp) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8337 | return; |
| 8338 | |
| 8339 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 8340 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 8341 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 8342 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 8343 | sizeof(struct lpfc_name)); |
| 8344 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 8345 | sizeof(struct lpfc_name)); |
| 8346 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8347 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 8348 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8349 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 8350 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 8351 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 8352 | fc_host_post_vendor_event(shost, |
| 8353 | fc_get_event_number(), |
| 8354 | sizeof(lsrjt_event), |
| 8355 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8356 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8357 | return; |
| 8358 | } |
| 8359 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 8360 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 8361 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 8362 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 8363 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 8364 | else |
| 8365 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 8366 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 8367 | sizeof(struct lpfc_name)); |
| 8368 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 8369 | sizeof(struct lpfc_name)); |
| 8370 | fc_host_post_vendor_event(shost, |
| 8371 | fc_get_event_number(), |
| 8372 | sizeof(fabric_event), |
| 8373 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8374 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8375 | return; |
| 8376 | } |
| 8377 | |
| 8378 | } |
| 8379 | |
| 8380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8381 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8382 | * @vport: Pointer to vport object. |
| 8383 | * @ndlp: Pointer FC node object. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8384 | * @payload: ELS command code type. |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8385 | * |
| 8386 | * This function posts an event when there is an incoming |
| 8387 | * unsolicited ELS command. |
| 8388 | **/ |
| 8389 | static void |
| 8390 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 8391 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8392 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8393 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8394 | struct lpfc_els_event_header *els_data = NULL; |
| 8395 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8396 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8397 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8398 | if (*payload == ELS_CMD_LOGO) { |
| 8399 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 8400 | if (!logo_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8401 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8402 | "0148 Failed to allocate memory " |
| 8403 | "for LOGO event\n"); |
| 8404 | return; |
| 8405 | } |
| 8406 | els_data = &logo_data->header; |
| 8407 | } else { |
| 8408 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 8409 | GFP_KERNEL); |
| 8410 | if (!els_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8411 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8412 | "0149 Failed to allocate memory " |
| 8413 | "for ELS event\n"); |
| 8414 | return; |
| 8415 | } |
| 8416 | } |
| 8417 | els_data->event_type = FC_REG_ELS_EVENT; |
| 8418 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8419 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8420 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8421 | break; |
| 8422 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8423 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8424 | break; |
| 8425 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8426 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 8427 | break; |
| 8428 | case ELS_CMD_LOGO: |
| 8429 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 8430 | /* Copy the WWPN in the LOGO payload */ |
| 8431 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 8432 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8433 | break; |
| 8434 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 8435 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8436 | return; |
| 8437 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8438 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 8439 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 8440 | if (*payload == ELS_CMD_LOGO) { |
| 8441 | fc_host_post_vendor_event(shost, |
| 8442 | fc_get_event_number(), |
| 8443 | sizeof(struct lpfc_logo_event), |
| 8444 | (char *)logo_data, |
| 8445 | LPFC_NL_VENDOR_ID); |
| 8446 | kfree(logo_data); |
| 8447 | } else { |
| 8448 | fc_host_post_vendor_event(shost, |
| 8449 | fc_get_event_number(), |
| 8450 | sizeof(struct lpfc_els_event_header), |
| 8451 | (char *)els_data, |
| 8452 | LPFC_NL_VENDOR_ID); |
| 8453 | kfree(els_data); |
| 8454 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8455 | |
| 8456 | return; |
| 8457 | } |
| 8458 | |
| 8459 | |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8460 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag, |
| 8461 | FC_LS_TLV_DTAG_INIT); |
| 8462 | |
| 8463 | DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types, |
| 8464 | FC_FPIN_LI_EVT_TYPES_INIT); |
| 8465 | |
| 8466 | /** |
| 8467 | * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event. |
| 8468 | * @vport: Pointer to vport object. |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 8469 | * @tlv: Pointer to the Link Integrity Notification Descriptor. |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8470 | * |
| 8471 | * This function processes a link integrity FPIN event by |
| 8472 | * logging a message |
| 8473 | **/ |
| 8474 | static void |
| 8475 | lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv) |
| 8476 | { |
| 8477 | struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv; |
| 8478 | const char *li_evt_str; |
| 8479 | u32 li_evt; |
| 8480 | |
| 8481 | li_evt = be16_to_cpu(li->event_type); |
| 8482 | li_evt_str = lpfc_get_fpin_li_event_nm(li_evt); |
| 8483 | |
| 8484 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8485 | "4680 FPIN Link Integrity %s (x%x) " |
| 8486 | "Detecting PN x%016llx Attached PN x%016llx " |
| 8487 | "Duration %d mSecs Count %d Port Cnt %d\n", |
| 8488 | li_evt_str, li_evt, |
| 8489 | be64_to_cpu(li->detecting_wwpn), |
| 8490 | be64_to_cpu(li->attached_wwpn), |
| 8491 | be32_to_cpu(li->event_threshold), |
| 8492 | be32_to_cpu(li->event_count), |
| 8493 | be32_to_cpu(li->pname_count)); |
| 8494 | } |
| 8495 | |
| 8496 | static void |
| 8497 | lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin, |
| 8498 | u32 fpin_length) |
| 8499 | { |
| 8500 | struct fc_tlv_desc *tlv; |
| 8501 | const char *dtag_nm; |
| 8502 | uint32_t desc_cnt = 0, bytes_remain; |
| 8503 | u32 dtag; |
| 8504 | |
| 8505 | /* FPINs handled only if we are in the right discovery state */ |
| 8506 | if (vport->port_state < LPFC_DISC_AUTH) |
| 8507 | return; |
| 8508 | |
| 8509 | /* make sure there is the full fpin header */ |
| 8510 | if (fpin_length < sizeof(struct fc_els_fpin)) |
| 8511 | return; |
| 8512 | |
| 8513 | tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; |
| 8514 | bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc); |
| 8515 | bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); |
| 8516 | |
| 8517 | /* process each descriptor */ |
| 8518 | while (bytes_remain >= FC_TLV_DESC_HDR_SZ && |
| 8519 | bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) { |
| 8520 | |
| 8521 | dtag = be32_to_cpu(tlv->desc_tag); |
| 8522 | switch (dtag) { |
| 8523 | case ELS_DTAG_LNK_INTEGRITY: |
| 8524 | lpfc_els_rcv_fpin_li(vport, tlv); |
| 8525 | break; |
| 8526 | default: |
| 8527 | dtag_nm = lpfc_get_tlv_dtag_nm(dtag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8528 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8529 | "4678 skipped FPIN descriptor[%d]: " |
| 8530 | "tag x%x (%s)\n", |
| 8531 | desc_cnt, dtag, dtag_nm); |
| 8532 | break; |
| 8533 | } |
| 8534 | |
| 8535 | desc_cnt++; |
| 8536 | bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); |
| 8537 | tlv = fc_tlv_next_desc(tlv); |
| 8538 | } |
| 8539 | |
| 8540 | fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length, |
| 8541 | (char *)fpin); |
| 8542 | } |
| 8543 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8544 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8545 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8546 | * @phba: pointer to lpfc hba data structure. |
| 8547 | * @pring: pointer to a SLI ring. |
| 8548 | * @vport: pointer to a host virtual N_Port data structure. |
| 8549 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 8550 | * |
| 8551 | * This routine is used for processing the IOCB associated with a unsolicited |
| 8552 | * event. It first determines whether there is an existing ndlp that matches |
| 8553 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 8554 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 8555 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 8556 | * of the discovery state machine. |
| 8557 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8558 | static void |
| 8559 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8560 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8561 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8562 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8563 | struct ls_rjt stat; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8564 | uint32_t *payload, payload_len; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8565 | uint32_t cmd, did, newnode; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8566 | uint8_t rjt_exp, rjt_err = 0, init_link = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8567 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8568 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8569 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8570 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8571 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8572 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8573 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8574 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8575 | payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8576 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8577 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 8578 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8579 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8580 | did = icmd->un.rcvels.remoteID; |
| 8581 | if (icmd->ulpStatus) { |
| 8582 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8583 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 8584 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8585 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8586 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8587 | |
| 8588 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8589 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8590 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8591 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8592 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8593 | if (vport->load_flag & FC_UNLOADING) |
| 8594 | goto dropit; |
| 8595 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8596 | /* If NPort discovery is delayed drop incoming ELS */ |
| 8597 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 8598 | (cmd != ELS_CMD_PLOGI)) |
| 8599 | goto dropit; |
| 8600 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8601 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 8602 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8603 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 8604 | ndlp = lpfc_nlp_init(vport, did); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8605 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8606 | goto dropit; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8607 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8608 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8609 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8610 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8611 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8612 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 8613 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8614 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8615 | |
| 8616 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 8617 | |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8618 | /* |
| 8619 | * Do not process any unsolicited ELS commands |
| 8620 | * if the ndlp is in DEV_LOSS |
| 8621 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 8622 | spin_lock_irq(&ndlp->lock); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8623 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 8624 | spin_unlock_irq(&ndlp->lock); |
Xiyu Yang | 7217e6e | 2020-05-25 22:16:24 +0800 | [diff] [blame] | 8625 | if (newnode) |
| 8626 | lpfc_nlp_put(ndlp); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8627 | goto dropit; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 8628 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 8629 | spin_unlock_irq(&ndlp->lock); |
James Smart | 12838e7 | 2014-09-03 12:57:19 -0400 | [diff] [blame] | 8630 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 8631 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 8632 | if (!elsiocb->context1) |
| 8633 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8634 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8635 | |
| 8636 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 8637 | cmd &= ELS_CMD_MASK; |
| 8638 | } |
| 8639 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8641 | "0112 ELS command x%x received from NPORT x%x " |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 8642 | "refcnt %d Data: x%x x%x x%x x%x\n", |
| 8643 | cmd, did, kref_read(&ndlp->kref), vport->port_state, |
| 8644 | vport->fc_flag, vport->fc_myDID, vport->fc_prevDID); |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8645 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8646 | /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */ |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8647 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 8648 | (cmd != ELS_CMD_FLOGI) && |
| 8649 | !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) { |
James Smart | 401304c | 2016-10-13 15:06:14 -0700 | [diff] [blame] | 8650 | rjt_err = LSRJT_LOGICAL_BSY; |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8651 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8652 | goto lsrjt; |
| 8653 | } |
| 8654 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8655 | switch (cmd) { |
| 8656 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8657 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8658 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 8659 | did, vport->port_state, ndlp->nlp_flag); |
| 8660 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8661 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8662 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 8663 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 8664 | (phba->pport->fc_flag & FC_PT2PT)) { |
| 8665 | vport->fc_prevDID = vport->fc_myDID; |
| 8666 | /* Our DID needs to be updated before registering |
| 8667 | * the vfi. This is done in lpfc_rcv_plogi but |
| 8668 | * that is called after the reg_vfi. |
| 8669 | */ |
| 8670 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; |
| 8671 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 8672 | "3312 Remote port assigned DID x%x " |
| 8673 | "%x\n", vport->fc_myDID, |
| 8674 | vport->fc_prevDID); |
| 8675 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8676 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8677 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8678 | |
| 8679 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 8680 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 8681 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8682 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 8683 | break; |
| 8684 | } |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 8685 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8686 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8687 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 8688 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 8689 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8690 | rjt_exp = LSEXP_NOTHING_MORE; |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 8691 | break; |
| 8692 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8693 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8694 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 8695 | spin_lock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8696 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 8697 | spin_unlock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8698 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8699 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8700 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8701 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8702 | break; |
| 8703 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8704 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8705 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 8706 | did, vport->port_state, ndlp->nlp_flag); |
| 8707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8708 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8709 | |
| 8710 | /* If the driver believes fabric discovery is done and is ready, |
| 8711 | * bounce the link. There is some descrepancy. |
| 8712 | */ |
| 8713 | if (vport->port_state >= LPFC_LOCAL_CFG_LINK && |
| 8714 | vport->fc_flag & FC_PT2PT && |
| 8715 | vport->rcv_flogi_cnt >= 1) { |
| 8716 | rjt_err = LSRJT_LOGICAL_BSY; |
| 8717 | rjt_exp = LSEXP_NOTHING_MORE; |
| 8718 | init_link++; |
| 8719 | goto lsrjt; |
| 8720 | } |
| 8721 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8722 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8723 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8724 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8725 | NLP_EVT_DEVICE_RM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8726 | break; |
| 8727 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8728 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8729 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 8730 | did, vport->port_state, ndlp->nlp_flag); |
| 8731 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8732 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8733 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8734 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8735 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8736 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8737 | break; |
| 8738 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8739 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8740 | break; |
| 8741 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8742 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8743 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 8744 | did, vport->port_state, ndlp->nlp_flag); |
| 8745 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8746 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8747 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8748 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8749 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8750 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8751 | break; |
| 8752 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8753 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8754 | break; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 8755 | case ELS_CMD_LCB: |
| 8756 | phba->fc_stat.elsRcvLCB++; |
| 8757 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); |
| 8758 | break; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 8759 | case ELS_CMD_RDP: |
| 8760 | phba->fc_stat.elsRcvRDP++; |
| 8761 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); |
| 8762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8763 | case ELS_CMD_RSCN: |
| 8764 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8765 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8766 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8767 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8768 | NLP_EVT_DEVICE_RM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8769 | break; |
| 8770 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8771 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8772 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 8773 | did, vport->port_state, ndlp->nlp_flag); |
| 8774 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 8775 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8776 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8777 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8778 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8779 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8780 | break; |
| 8781 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8782 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8783 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8784 | break; |
| 8785 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8786 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8787 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 8788 | did, vport->port_state, ndlp->nlp_flag); |
| 8789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8790 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8791 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8792 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8793 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8794 | break; |
| 8795 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8796 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 8797 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8798 | break; |
| 8799 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8800 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8801 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 8802 | did, vport->port_state, ndlp->nlp_flag); |
| 8803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8804 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8805 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8806 | break; |
| 8807 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8808 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8809 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 8810 | did, vport->port_state, ndlp->nlp_flag); |
| 8811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8812 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8813 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8814 | break; |
| 8815 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8816 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8817 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 8818 | did, vport->port_state, ndlp->nlp_flag); |
| 8819 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8820 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8821 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8822 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8823 | case ELS_CMD_PRLI: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 8824 | case ELS_CMD_NVMEPRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8825 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8826 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 8827 | did, vport->port_state, ndlp->nlp_flag); |
| 8828 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8829 | phba->fc_stat.elsRcvPRLI++; |
Dick Kennedy | a71e3cd | 2017-03-23 08:47:18 -0400 | [diff] [blame] | 8830 | if ((vport->port_state < LPFC_DISC_AUTH) && |
| 8831 | (vport->fc_flag & FC_FABRIC)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8832 | rjt_err = LSRJT_UNABLE_TPC; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8833 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8834 | break; |
| 8835 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8836 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8837 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8838 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8840 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 8841 | did, vport->port_state, ndlp->nlp_flag); |
| 8842 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8843 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8844 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8845 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8846 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8847 | NLP_EVT_DEVICE_RM); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8848 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8849 | case ELS_CMD_RLS: |
| 8850 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8851 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 8852 | did, vport->port_state, ndlp->nlp_flag); |
| 8853 | |
| 8854 | phba->fc_stat.elsRcvRLS++; |
| 8855 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 8856 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8857 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8858 | NLP_EVT_DEVICE_RM); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8859 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8860 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8861 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8862 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 8863 | did, vport->port_state, ndlp->nlp_flag); |
| 8864 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8865 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8866 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8867 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8868 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8869 | NLP_EVT_DEVICE_RM); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 8870 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8871 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8872 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8873 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 8874 | did, vport->port_state, ndlp->nlp_flag); |
| 8875 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8876 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8877 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8878 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8879 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8880 | NLP_EVT_DEVICE_RM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8881 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8882 | case ELS_CMD_RTV: |
| 8883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8884 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 8885 | did, vport->port_state, ndlp->nlp_flag); |
| 8886 | phba->fc_stat.elsRcvRTV++; |
| 8887 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 8888 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8889 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8890 | NLP_EVT_DEVICE_RM); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8891 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8892 | case ELS_CMD_RRQ: |
| 8893 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8894 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 8895 | did, vport->port_state, ndlp->nlp_flag); |
| 8896 | |
| 8897 | phba->fc_stat.elsRcvRRQ++; |
| 8898 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 8899 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8900 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8901 | NLP_EVT_DEVICE_RM); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8902 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8903 | case ELS_CMD_ECHO: |
| 8904 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8905 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 8906 | did, vport->port_state, ndlp->nlp_flag); |
| 8907 | |
| 8908 | phba->fc_stat.elsRcvECHO++; |
| 8909 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 8910 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8911 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8912 | NLP_EVT_DEVICE_RM); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 8913 | break; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8914 | case ELS_CMD_REC: |
Colin Ian King | 8fd03fd | 2017-12-22 00:39:36 +0000 | [diff] [blame] | 8915 | /* receive this due to exchange closed */ |
| 8916 | rjt_err = LSRJT_UNABLE_TPC; |
| 8917 | rjt_exp = LSEXP_INVALID_OX_RX; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8918 | break; |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8919 | case ELS_CMD_FPIN: |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 8920 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8921 | "RCV FPIN: did:x%x/ste:x%x flg:x%x", |
| 8922 | did, vport->port_state, ndlp->nlp_flag); |
| 8923 | |
| 8924 | lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload, |
| 8925 | payload_len); |
| 8926 | |
| 8927 | /* There are no replies, so no rjt codes */ |
James Smart | 1a61e54 | 2019-04-05 16:04:23 -0700 | [diff] [blame] | 8928 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8929 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8930 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 8931 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 8932 | cmd, did, vport->port_state); |
| 8933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8934 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8935 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8936 | rjt_exp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8937 | |
| 8938 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8939 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8940 | "0115 Unknown ELS command x%x " |
| 8941 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8942 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8943 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8944 | NLP_EVT_DEVICE_RM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8945 | break; |
| 8946 | } |
| 8947 | |
James Smart | eec3d31 | 2015-08-31 16:48:18 -0400 | [diff] [blame] | 8948 | lsrjt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8949 | /* check if need to LS_RJT received ELS cmd */ |
| 8950 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8951 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8952 | stat.un.b.lsRjtRsnCode = rjt_err; |
James Smart | 303f2f9 | 2013-01-03 15:43:11 -0500 | [diff] [blame] | 8953 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8954 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 8955 | NULL); |
| 8956 | /* Remove the reference from above for new nodes. */ |
| 8957 | if (newnode) |
James Smart | 9d76d46 | 2020-11-15 11:26:36 -0800 | [diff] [blame] | 8958 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8959 | NLP_EVT_DEVICE_RM); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8960 | } |
| 8961 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 8962 | /* Release the reference on this elsiocb, not the ndlp. */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8963 | lpfc_nlp_put(elsiocb->context1); |
| 8964 | elsiocb->context1 = NULL; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 8965 | |
| 8966 | /* Special case. Driver received an unsolicited command that |
| 8967 | * unsupportable given the driver's current state. Reset the |
| 8968 | * link and start over. |
| 8969 | */ |
| 8970 | if (init_link) { |
| 8971 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8972 | if (!mbox) |
| 8973 | return; |
| 8974 | lpfc_linkdown(phba); |
| 8975 | lpfc_init_link(phba, mbox, |
| 8976 | phba->cfg_topology, |
| 8977 | phba->cfg_link_speed); |
| 8978 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 8979 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 8980 | mbox->vport = vport; |
| 8981 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 8982 | MBX_NOT_FINISHED) |
| 8983 | mempool_free(mbox, phba->mbox_mem_pool); |
| 8984 | } |
| 8985 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8986 | return; |
| 8987 | |
| 8988 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8989 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8990 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8991 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8992 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 8993 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8994 | phba->fc_stat.elsRcvDrop++; |
| 8995 | } |
| 8996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8998 | * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8999 | * @phba: pointer to lpfc hba data structure. |
| 9000 | * @pring: pointer to a SLI ring. |
| 9001 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 9002 | * |
| 9003 | * This routine is used to process an unsolicited event received from a SLI |
| 9004 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 9005 | * associated with the unsolicited event is done by invoking the routine |
| 9006 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 9007 | * SLI ring on which the unsolicited event was received. |
| 9008 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9009 | void |
| 9010 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9011 | struct lpfc_iocbq *elsiocb) |
| 9012 | { |
| 9013 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9014 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9015 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9016 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 9017 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9018 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9019 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9020 | elsiocb->context2 = NULL; |
| 9021 | elsiocb->context3 = NULL; |
| 9022 | |
| 9023 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 9024 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 9025 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9026 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 9027 | IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9028 | phba->fc_stat.NoRcvBuf++; |
| 9029 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9030 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9031 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9032 | return; |
| 9033 | } |
| 9034 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9035 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 9036 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 9037 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 9038 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 9039 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9040 | else |
| 9041 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9042 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9043 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9044 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9045 | /* If there are no BDEs associated |
| 9046 | * with this IOCB, there is nothing to do. |
| 9047 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9048 | if (icmd->ulpBdeCount == 0) |
| 9049 | return; |
| 9050 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9051 | /* type of ELS cmd is first 32bit word |
| 9052 | * in packet |
| 9053 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9054 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9055 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9056 | } else { |
| 9057 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 9058 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9059 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 9060 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9061 | } |
| 9062 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9063 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 9064 | /* |
| 9065 | * The different unsolicited event handlers would tell us |
| 9066 | * if they are done with "mp" by setting context2 to NULL. |
| 9067 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9068 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9069 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 9070 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9071 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9072 | |
| 9073 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9074 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9075 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9076 | elsiocb->context2 = bdeBuf2; |
| 9077 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9078 | /* free mp if we are done with it */ |
| 9079 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9080 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 9081 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9083 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9084 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9085 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 9086 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9087 | lpfc_start_fdmi(struct lpfc_vport *vport) |
| 9088 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9089 | struct lpfc_nodelist *ndlp; |
| 9090 | |
| 9091 | /* If this is the first time, allocate an ndlp and initialize |
| 9092 | * it. Otherwise, make sure the node is enabled and then do the |
| 9093 | * login. |
| 9094 | */ |
| 9095 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 9096 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 9097 | ndlp = lpfc_nlp_init(vport, FDMI_DID); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9098 | if (ndlp) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9099 | ndlp->nlp_type |= NLP_FABRIC; |
| 9100 | } else { |
| 9101 | return; |
| 9102 | } |
| 9103 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9104 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9105 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 9106 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9107 | } |
| 9108 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9110 | * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9111 | * @phba: pointer to lpfc hba data structure. |
| 9112 | * @vport: pointer to a virtual N_Port data structure. |
| 9113 | * |
| 9114 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 9115 | * State Change Request (SCR) for a @vport. This routine will create an |
| 9116 | * ndlp for the Name Server associated to the @vport if such node does |
| 9117 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 9118 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 9119 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 9120 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 9121 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9122 | void |
| 9123 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 9124 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9125 | struct lpfc_nodelist *ndlp; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9126 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9127 | |
| 9128 | /* |
| 9129 | * If lpfc_delay_discovery parameter is set and the clean address |
| 9130 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 9131 | * discovery. |
| 9132 | */ |
| 9133 | spin_lock_irq(shost->host_lock); |
| 9134 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 9135 | spin_unlock_irq(shost->host_lock); |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 9136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 9137 | "3334 Delay fc port discovery for %d secs\n", |
| 9138 | phba->fc_ratov); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9139 | mod_timer(&vport->delayed_disc_tmo, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9140 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9141 | return; |
| 9142 | } |
| 9143 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9144 | |
| 9145 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 9146 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 9147 | ndlp = lpfc_nlp_init(vport, NameServer_DID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9148 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9149 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9150 | lpfc_disc_start(vport); |
| 9151 | return; |
| 9152 | } |
| 9153 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9154 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9155 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9156 | return; |
| 9157 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9158 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9159 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9160 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9161 | |
| 9162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 9163 | |
| 9164 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 9165 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9166 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9167 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9168 | return; |
| 9169 | } |
| 9170 | |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 9171 | if ((phba->cfg_enable_SmartSAN || |
| 9172 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && |
| 9173 | (vport->load_flag & FC_ALLOW_FDMI)) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 9174 | lpfc_start_fdmi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9175 | } |
| 9176 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9177 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9178 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9179 | * @phba: pointer to lpfc hba data structure. |
| 9180 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 9181 | * |
| 9182 | * This routine is the completion callback function to register new vport |
| 9183 | * mailbox command. If the new vport mailbox command completes successfully, |
| 9184 | * the fabric registration login shall be performed on physical port (the |
| 9185 | * new vport created is actually a physical port, with VPI 0) or the port |
| 9186 | * login to Name Server for State Change Request (SCR) will be performed |
| 9187 | * on virtual port (real virtual port, with VPI greater than 0). |
| 9188 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9189 | static void |
| 9190 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 9191 | { |
| 9192 | struct lpfc_vport *vport = pmb->vport; |
| 9193 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9194 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9195 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9196 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9197 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9198 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9199 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9200 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9201 | |
| 9202 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9203 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9204 | "0915 Register VPI failed : Status: x%x" |
| 9205 | " upd bit: x%x \n", mb->mbxStatus, |
| 9206 | mb->un.varRegVpi.upd); |
| 9207 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 9208 | mb->un.varRegVpi.upd) |
| 9209 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9210 | |
| 9211 | switch (mb->mbxStatus) { |
| 9212 | case 0x11: /* unsupported feature */ |
| 9213 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9214 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9215 | /* giving up on vport registration */ |
| 9216 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9217 | spin_lock_irq(shost->host_lock); |
| 9218 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 9219 | spin_unlock_irq(shost->host_lock); |
| 9220 | lpfc_can_disctmo(vport); |
| 9221 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9222 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 9223 | case 0x20: |
| 9224 | spin_lock_irq(shost->host_lock); |
| 9225 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 9226 | spin_unlock_irq(shost->host_lock); |
| 9227 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 9228 | pmb->vport = vport; |
| 9229 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 9230 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 9231 | MBX_NOWAIT); |
| 9232 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9233 | lpfc_printf_vlog(vport, KERN_ERR, |
| 9234 | LOG_TRACE_EVENT, |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9235 | "2732 Failed to issue INIT_VPI" |
| 9236 | " mailbox command\n"); |
| 9237 | } else { |
| 9238 | lpfc_nlp_put(ndlp); |
| 9239 | return; |
| 9240 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9241 | fallthrough; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9242 | default: |
| 9243 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9244 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9245 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9246 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9247 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9248 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9249 | spin_unlock_irq(shost->host_lock); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9250 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
| 9251 | break; |
| 9252 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && |
| 9253 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { |
| 9254 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9255 | lpfc_issue_init_vfi(vport); |
| 9256 | else |
| 9257 | lpfc_initial_flogi(vport); |
| 9258 | } else { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9259 | lpfc_initial_fdisc(vport); |
James Smart | 5d18153 | 2017-03-04 09:30:25 -0800 | [diff] [blame] | 9260 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9261 | break; |
| 9262 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9263 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9264 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 9265 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9266 | spin_unlock_irq(shost->host_lock); |
| 9267 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9268 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 9269 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9270 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 9271 | /* |
| 9272 | * If the physical port is instantiated using |
| 9273 | * FDISC, do not start vport discovery. |
| 9274 | */ |
| 9275 | if (vport->port_state != LPFC_FDISC) |
| 9276 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9277 | lpfc_do_scr_ns_plogi(phba, vport); |
| 9278 | } |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9279 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9280 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9281 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9282 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9283 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9284 | /* Now, we decrement the ndlp reference count held for this |
| 9285 | * callback function |
| 9286 | */ |
| 9287 | lpfc_nlp_put(ndlp); |
| 9288 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9289 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9290 | return; |
| 9291 | } |
| 9292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9294 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9295 | * @phba: pointer to lpfc hba data structure. |
| 9296 | * @vport: pointer to a host virtual N_Port data structure. |
| 9297 | * @ndlp: pointer to a node-list data structure. |
| 9298 | * |
| 9299 | * This routine registers the @vport as a new virtual port with a HBA. |
| 9300 | * It is done through a registering vpi mailbox command. |
| 9301 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9302 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9303 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 9304 | struct lpfc_nodelist *ndlp) |
| 9305 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9306 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9307 | LPFC_MBOXQ_t *mbox; |
| 9308 | |
| 9309 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9310 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 9311 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9312 | mbox->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9313 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9314 | if (!mbox->ctx_ndlp) { |
| 9315 | mempool_free(mbox, phba->mbox_mem_pool); |
| 9316 | goto mbox_err_exit; |
| 9317 | } |
| 9318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9319 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9320 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9321 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9322 | /* mailbox command not success, decrement ndlp |
| 9323 | * reference count for this command |
| 9324 | */ |
| 9325 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9326 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9327 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9328 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9329 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9330 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9331 | } |
| 9332 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9333 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9334 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9335 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9336 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 9337 | return; |
| 9338 | |
| 9339 | mbox_err_exit: |
| 9340 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9341 | spin_lock_irq(shost->host_lock); |
| 9342 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 9343 | spin_unlock_irq(shost->host_lock); |
| 9344 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9345 | } |
| 9346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9347 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9348 | * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9349 | * @phba: pointer to lpfc hba data structure. |
| 9350 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9351 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9352 | **/ |
| 9353 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9354 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9355 | { |
| 9356 | struct lpfc_vport **vports; |
| 9357 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9358 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9359 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9360 | |
| 9361 | /* Treat this failure as linkdown for all vports */ |
| 9362 | link_state = phba->link_state; |
| 9363 | lpfc_linkdown(phba); |
| 9364 | phba->link_state = link_state; |
| 9365 | |
| 9366 | vports = lpfc_create_vport_work_array(phba); |
| 9367 | |
| 9368 | if (vports) { |
| 9369 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9370 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 9371 | if (ndlp) |
| 9372 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 9373 | lpfc_els_flush_cmd(vports[i]); |
| 9374 | } |
| 9375 | lpfc_destroy_vport_work_array(phba, vports); |
| 9376 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9377 | } |
| 9378 | |
| 9379 | /** |
| 9380 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 9381 | * @phba: pointer to lpfc hba data structure. |
| 9382 | * |
| 9383 | * This routine abort all pending discovery commands and |
| 9384 | * start a timer to retry FLOGI for the physical port |
| 9385 | * discovery. |
| 9386 | **/ |
| 9387 | void |
| 9388 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 9389 | { |
| 9390 | struct lpfc_nodelist *ndlp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 9391 | |
| 9392 | /* Cancel the all vports retry delay retry timers */ |
| 9393 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9394 | |
| 9395 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 9396 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 9397 | if (!ndlp) |
| 9398 | return; |
| 9399 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9400 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9401 | spin_lock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9402 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9403 | spin_unlock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9404 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 9405 | phba->pport->port_state = LPFC_FLOGI; |
| 9406 | return; |
| 9407 | } |
| 9408 | |
| 9409 | /** |
| 9410 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 9411 | * @phba: pointer to lpfc hba data structure. |
| 9412 | * @cmdiocb: pointer to FDISC command iocb. |
| 9413 | * @rspiocb: pointer to FDISC response iocb. |
| 9414 | * |
| 9415 | * This routine checks if a FLOGI is reguired for FDISC |
| 9416 | * to succeed. |
| 9417 | **/ |
| 9418 | static int |
| 9419 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 9420 | struct lpfc_iocbq *cmdiocb, |
| 9421 | struct lpfc_iocbq *rspiocb) |
| 9422 | { |
| 9423 | |
| 9424 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 9425 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 9426 | return 0; |
| 9427 | else |
| 9428 | return 1; |
| 9429 | } |
| 9430 | |
| 9431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9432 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9433 | * @phba: pointer to lpfc hba data structure. |
| 9434 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9435 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9436 | * |
| 9437 | * This routine is the completion callback function to a Fabric Discover |
| 9438 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 9439 | * single threaded, each FDISC completion callback function will reset |
| 9440 | * the discovery timer for all vports such that the timers will not get |
| 9441 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 9442 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 9443 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 9444 | * assigned to the vport has been changed with the completion of the FDISC |
| 9445 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 9446 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 9447 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 9448 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 9449 | * Server for State Change Request (SCR). |
| 9450 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9451 | static void |
| 9452 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9453 | struct lpfc_iocbq *rspiocb) |
| 9454 | { |
| 9455 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9456 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9457 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 9458 | struct lpfc_nodelist *np; |
| 9459 | struct lpfc_nodelist *next_np; |
| 9460 | IOCB_t *irsp = &rspiocb->iocb; |
| 9461 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9462 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 9463 | struct serv_parm *sp; |
| 9464 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9465 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9466 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9467 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 9468 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 9469 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9470 | /* Since all FDISCs are being single threaded, we |
| 9471 | * must reset the discovery timer for ALL vports |
| 9472 | * waiting to send FDISC when one completes. |
| 9473 | */ |
| 9474 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 9475 | lpfc_set_disctmo(piocb->vport); |
| 9476 | } |
| 9477 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9479 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 9480 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 9481 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9482 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9483 | |
| 9484 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 9485 | lpfc_retry_pport_discovery(phba); |
| 9486 | goto out; |
| 9487 | } |
| 9488 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9489 | /* Check for retry */ |
| 9490 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 9491 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9492 | /* FDISC failed */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9493 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9494 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9495 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9496 | goto fdisc_failed; |
| 9497 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9498 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 9499 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9500 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9501 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 9502 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9503 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 9504 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9505 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9506 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 9507 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9508 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9509 | if (!prsp) |
| 9510 | goto out; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 9511 | sp = prsp->virt + sizeof(uint32_t); |
| 9512 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 9513 | memcpy(&vport->fabric_portname, &sp->portName, |
| 9514 | sizeof(struct lpfc_name)); |
| 9515 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 9516 | sizeof(struct lpfc_name)); |
| 9517 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9518 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9519 | /* If our NportID changed, we need to ensure all |
| 9520 | * remaining NPORTs get unreg_login'ed so we can |
| 9521 | * issue unreg_vpi. |
| 9522 | */ |
| 9523 | list_for_each_entry_safe(np, next_np, |
| 9524 | &vport->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 9525 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9526 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 9527 | continue; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9528 | spin_lock_irq(&ndlp->lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9529 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9530 | spin_unlock_irq(&ndlp->lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9531 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9532 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 9533 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9534 | |
| 9535 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9536 | lpfc_sli4_unreg_all_rpis(vport); |
| 9537 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9538 | lpfc_mbx_unreg_vpi(vport); |
| 9539 | spin_lock_irq(shost->host_lock); |
| 9540 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9541 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9542 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 9543 | else |
| 9544 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9545 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 9546 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 9547 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 9548 | /* |
| 9549 | * Driver needs to re-reg VPI in order for f/w |
| 9550 | * to update the MAC address. |
| 9551 | */ |
| 9552 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9553 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 9554 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9555 | } |
| 9556 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 9557 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 9558 | lpfc_issue_init_vpi(vport); |
| 9559 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9560 | lpfc_register_new_vport(phba, vport, ndlp); |
| 9561 | else |
| 9562 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9563 | |
| 9564 | /* The FDISC completed successfully. Move the fabric ndlp to |
| 9565 | * UNMAPPED state and register with the transport. |
| 9566 | */ |
| 9567 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9568 | goto out; |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9569 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9570 | fdisc_failed: |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 9571 | if (vport->fc_vport && |
| 9572 | (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) |
James Smart | c84163d | 2015-05-21 13:55:22 -0400 | [diff] [blame] | 9573 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9574 | /* Cancel discovery timer */ |
| 9575 | lpfc_can_disctmo(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9576 | out: |
| 9577 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9578 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9579 | } |
| 9580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9582 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9583 | * @vport: pointer to a virtual N_Port data structure. |
| 9584 | * @ndlp: pointer to a node-list data structure. |
| 9585 | * @retry: number of retries to the command IOCB. |
| 9586 | * |
| 9587 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 9588 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 9589 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 9590 | * IOCB will be sent off HBA at any given time. |
| 9591 | * |
| 9592 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9593 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9594 | * will be stored into the context1 field of the IOCB for the completion |
| 9595 | * callback function to the FDISC ELS command. |
| 9596 | * |
| 9597 | * Return code |
| 9598 | * 0 - Successfully issued fdisc iocb command |
| 9599 | * 1 - Failed to issue fdisc iocb command |
| 9600 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 9601 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9602 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 9603 | uint8_t retry) |
| 9604 | { |
| 9605 | struct lpfc_hba *phba = vport->phba; |
| 9606 | IOCB_t *icmd; |
| 9607 | struct lpfc_iocbq *elsiocb; |
| 9608 | struct serv_parm *sp; |
| 9609 | uint8_t *pcmd; |
| 9610 | uint16_t cmdsize; |
| 9611 | int did = ndlp->nlp_DID; |
| 9612 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9613 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9614 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9615 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9616 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 9617 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 9618 | ELS_CMD_FDISC); |
| 9619 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9620 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9621 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9622 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9623 | return 1; |
| 9624 | } |
| 9625 | |
| 9626 | icmd = &elsiocb->iocb; |
| 9627 | icmd->un.elsreq64.myID = 0; |
| 9628 | icmd->un.elsreq64.fl = 1; |
| 9629 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9630 | /* |
| 9631 | * SLI3 ports require a different context type value than SLI4. |
| 9632 | * Catch SLI3 ports here and override the prep. |
| 9633 | */ |
| 9634 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9635 | icmd->ulpCt_h = 1; |
| 9636 | icmd->ulpCt_l = 0; |
| 9637 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9638 | |
| 9639 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9640 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 9641 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 9642 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 9643 | sp = (struct serv_parm *) pcmd; |
| 9644 | /* Setup CSPs accordingly for Fabric */ |
| 9645 | sp->cmn.e_d_tov = 0; |
| 9646 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 9647 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9648 | sp->cls1.classValid = 0; |
| 9649 | sp->cls2.seqDelivery = 1; |
| 9650 | sp->cls3.seqDelivery = 1; |
| 9651 | |
| 9652 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 9653 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 9654 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 9655 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 9656 | memcpy(pcmd, &vport->fc_portname, 8); |
| 9657 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9658 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 9659 | memcpy(pcmd, &vport->fc_nodename, 8); |
Dick Kennedy | 176de5b | 2017-08-23 16:55:40 -0700 | [diff] [blame] | 9660 | sp->cmn.valid_vendor_ver_level = 0; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 9661 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9662 | lpfc_set_disctmo(vport); |
| 9663 | |
| 9664 | phba->fc_stat.elsXmitFDISC++; |
| 9665 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 9666 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9667 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9668 | "Issue FDISC: did:x%x", |
| 9669 | did, 0, 0); |
| 9670 | |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9671 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 9672 | if (!elsiocb->context1) |
| 9673 | goto err_out; |
| 9674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9675 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 9676 | if (rc == IOCB_ERROR) { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9677 | lpfc_nlp_put(ndlp); |
| 9678 | goto err_out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9679 | } |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9680 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9681 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9682 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9683 | |
| 9684 | err_out: |
| 9685 | lpfc_els_free_iocb(phba, elsiocb); |
| 9686 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 9687 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 9688 | "0256 Issue FDISC: Cannot send IOCB\n"); |
| 9689 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9690 | } |
| 9691 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9692 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9693 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9694 | * @phba: pointer to lpfc hba data structure. |
| 9695 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9696 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9697 | * |
| 9698 | * This routine is the completion callback function to the issuing of a LOGO |
| 9699 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 9700 | * reference count held on ndlp for this completion function, indicating that |
| 9701 | * the reference to the ndlp is no long needed. Note that the |
| 9702 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 9703 | * callback function and an additional explicit ndlp reference decrementation |
| 9704 | * will trigger the actual release of the ndlp. |
| 9705 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9706 | static void |
| 9707 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9708 | struct lpfc_iocbq *rspiocb) |
| 9709 | { |
| 9710 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9711 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 9712 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9713 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9714 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9715 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9716 | irsp = &rspiocb->iocb; |
| 9717 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9718 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 9719 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9720 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9721 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 9722 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 9723 | "2928 NPIV LOGO completes to NPort x%x " |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9724 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9725 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9726 | irsp->ulpTimeout, vport->num_disc_nodes, |
| 9727 | kref_read(&ndlp->kref), ndlp->nlp_flag, |
| 9728 | ndlp->fc4_xpt_flags); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9729 | |
| 9730 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 9731 | spin_lock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9732 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9733 | vport->fc_flag &= ~FC_FABRIC; |
| 9734 | spin_unlock_irq(shost->host_lock); |
James Smart | 73dc0db | 2015-05-22 10:42:36 -0400 | [diff] [blame] | 9735 | lpfc_can_disctmo(vport); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 9736 | } |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9737 | |
| 9738 | /* Safe to release resources now. */ |
| 9739 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9740 | lpfc_nlp_put(ndlp); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 9741 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9742 | } |
| 9743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9745 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9746 | * @vport: pointer to a virtual N_Port data structure. |
| 9747 | * @ndlp: pointer to a node-list data structure. |
| 9748 | * |
| 9749 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 9750 | * |
| 9751 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 9752 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 9753 | * will be stored into the context1 field of the IOCB for the completion |
| 9754 | * callback function to the LOGO ELS command. |
| 9755 | * |
| 9756 | * Return codes |
| 9757 | * 0 - Successfully issued logo off the @vport |
| 9758 | * 1 - Failed to issue logo off the @vport |
| 9759 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9760 | int |
| 9761 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 9762 | { |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9763 | int rc = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9764 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9765 | struct lpfc_iocbq *elsiocb; |
| 9766 | uint8_t *pcmd; |
| 9767 | uint16_t cmdsize; |
| 9768 | |
| 9769 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 9770 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 9771 | ELS_CMD_LOGO); |
| 9772 | if (!elsiocb) |
| 9773 | return 1; |
| 9774 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9775 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 9776 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 9777 | pcmd += sizeof(uint32_t); |
| 9778 | |
| 9779 | /* Fill in LOGO payload */ |
| 9780 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 9781 | pcmd += sizeof(uint32_t); |
| 9782 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 9783 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9784 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 9785 | "Issue LOGO npiv did:x%x flg:x%x", |
| 9786 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 9787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9788 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9789 | spin_lock_irq(&ndlp->lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9790 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9791 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9792 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 9793 | if (!elsiocb->context1) |
| 9794 | goto node_err; |
| 9795 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 9796 | if (rc == IOCB_ERROR) |
| 9797 | goto io_err; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9798 | return 0; |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9799 | |
| 9800 | io_err: |
| 9801 | lpfc_nlp_put(ndlp); |
| 9802 | node_err: |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9803 | spin_lock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9804 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 9805 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 9806 | lpfc_els_free_iocb(phba, elsiocb); |
| 9807 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9808 | } |
| 9809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9811 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
Lee Jones | a0e4a64 | 2020-07-23 13:24:07 +0100 | [diff] [blame] | 9812 | * @t: timer context used to obtain the lpfc hba. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9813 | * |
| 9814 | * This routine is invoked by the fabric iocb block timer after |
| 9815 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 9816 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 9817 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 9818 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 9819 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 9820 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9821 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9822 | lpfc_fabric_block_timeout(struct timer_list *t) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9823 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 9824 | struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9825 | unsigned long iflags; |
| 9826 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9827 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9828 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 9829 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 9830 | if (!tmo_posted) |
| 9831 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 9832 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 9833 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9834 | if (!tmo_posted) |
| 9835 | lpfc_worker_wake_up(phba); |
| 9836 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9837 | } |
| 9838 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9840 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9841 | * @phba: pointer to lpfc hba data structure. |
| 9842 | * |
| 9843 | * This routine issues one fabric iocb from the driver internal list to |
| 9844 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 9845 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 9846 | * remove one pending fabric iocb from the driver internal list and invokes |
| 9847 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 9848 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9849 | static void |
| 9850 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 9851 | { |
| 9852 | struct lpfc_iocbq *iocb; |
| 9853 | unsigned long iflags; |
| 9854 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9855 | IOCB_t *cmd; |
| 9856 | |
| 9857 | repeat: |
| 9858 | iocb = NULL; |
| 9859 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9860 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9861 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 9862 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 9863 | list); |
| 9864 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9865 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9866 | atomic_inc(&phba->fabric_iocb_count); |
| 9867 | } |
| 9868 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9869 | if (iocb) { |
| 9870 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 9871 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 9872 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 9873 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9874 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 9875 | "Fabric sched1: ste:x%x", |
| 9876 | iocb->vport->port_state, 0, 0); |
| 9877 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9878 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9879 | |
| 9880 | if (ret == IOCB_ERROR) { |
| 9881 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 9882 | iocb->fabric_iocb_cmpl = NULL; |
| 9883 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9884 | cmd = &iocb->iocb; |
| 9885 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 9886 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 9887 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 9888 | |
| 9889 | atomic_dec(&phba->fabric_iocb_count); |
| 9890 | goto repeat; |
| 9891 | } |
| 9892 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9893 | } |
| 9894 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9896 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9897 | * @phba: pointer to lpfc hba data structure. |
| 9898 | * |
| 9899 | * This routine unblocks the issuing fabric iocb command. The function |
| 9900 | * will clear the fabric iocb block bit and then invoke the routine |
| 9901 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 9902 | * from the driver internal fabric iocb list. |
| 9903 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9904 | void |
| 9905 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 9906 | { |
| 9907 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 9908 | |
| 9909 | lpfc_resume_fabric_iocbs(phba); |
| 9910 | return; |
| 9911 | } |
| 9912 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9913 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9914 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9915 | * @phba: pointer to lpfc hba data structure. |
| 9916 | * |
| 9917 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 9918 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 9919 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 9920 | * fabric iocb will be issued out of the HBA. |
| 9921 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9922 | static void |
| 9923 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 9924 | { |
| 9925 | int blocked; |
| 9926 | |
| 9927 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9928 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9929 | if (!blocked) |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9930 | mod_timer(&phba->fabric_block_timer, |
| 9931 | jiffies + msecs_to_jiffies(100)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9932 | |
| 9933 | return; |
| 9934 | } |
| 9935 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9936 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9937 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9938 | * @phba: pointer to lpfc hba data structure. |
| 9939 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 9940 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 9941 | * |
| 9942 | * This routine is the callback function that is put to the fabric iocb's |
| 9943 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 9944 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 9945 | * function first restores and invokes the original iocb's callback function |
| 9946 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 9947 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 9948 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9949 | static void |
| 9950 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9951 | struct lpfc_iocbq *rspiocb) |
| 9952 | { |
| 9953 | struct ls_rjt stat; |
| 9954 | |
Shyam Saini | e01ea5e | 2016-12-24 16:21:07 +0530 | [diff] [blame] | 9955 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9956 | |
| 9957 | switch (rspiocb->iocb.ulpStatus) { |
| 9958 | case IOSTAT_NPORT_RJT: |
| 9959 | case IOSTAT_FABRIC_RJT: |
| 9960 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 9961 | lpfc_block_fabric_iocbs(phba); |
| 9962 | } |
| 9963 | break; |
| 9964 | |
| 9965 | case IOSTAT_NPORT_BSY: |
| 9966 | case IOSTAT_FABRIC_BSY: |
| 9967 | lpfc_block_fabric_iocbs(phba); |
| 9968 | break; |
| 9969 | |
| 9970 | case IOSTAT_LS_RJT: |
| 9971 | stat.un.lsRjtError = |
| 9972 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 9973 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 9974 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 9975 | lpfc_block_fabric_iocbs(phba); |
| 9976 | break; |
| 9977 | } |
| 9978 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 9979 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9980 | |
| 9981 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 9982 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 9983 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 9984 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 9985 | |
| 9986 | atomic_dec(&phba->fabric_iocb_count); |
| 9987 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 9988 | /* Post any pending iocbs to HBA */ |
| 9989 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9990 | } |
| 9991 | } |
| 9992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9993 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9994 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9995 | * @phba: pointer to lpfc hba data structure. |
| 9996 | * @iocb: pointer to lpfc command iocb data structure. |
| 9997 | * |
| 9998 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 9999 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 10000 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 10001 | * any given time. As such, this function will first check to see whether there |
| 10002 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 10003 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 10004 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 10005 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 10006 | * |
| 10007 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 10008 | * order. The problem is caused by the construction of the "ready" boolen does |
| 10009 | * not include the condition that the internal fabric IOCB list is empty. As |
| 10010 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 10011 | * ahead of the fabric IOCBs in the internal list. |
| 10012 | * |
| 10013 | * Return code |
| 10014 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 10015 | * IOCB_ERROR - failed to issue fabric iocb |
| 10016 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 10017 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10018 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 10019 | { |
| 10020 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10021 | int ready; |
| 10022 | int ret; |
| 10023 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 10024 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10025 | |
| 10026 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10027 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 10028 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 10029 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 10030 | if (ready) |
| 10031 | /* Increment fabric iocb count to hold the position */ |
| 10032 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10033 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10034 | if (ready) { |
| 10035 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 10036 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 10037 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 10038 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10039 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 10040 | "Fabric sched2: ste:x%x", |
| 10041 | iocb->vport->port_state, 0, 0); |
| 10042 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10043 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10044 | |
| 10045 | if (ret == IOCB_ERROR) { |
| 10046 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 10047 | iocb->fabric_iocb_cmpl = NULL; |
| 10048 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 10049 | atomic_dec(&phba->fabric_iocb_count); |
| 10050 | } |
| 10051 | } else { |
| 10052 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10053 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 10054 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10055 | ret = IOCB_SUCCESS; |
| 10056 | } |
| 10057 | return ret; |
| 10058 | } |
| 10059 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10060 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10061 | * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10062 | * @vport: pointer to a virtual N_Port data structure. |
| 10063 | * |
| 10064 | * This routine aborts all the IOCBs associated with a @vport from the |
| 10065 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 10066 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 10067 | * list, removes each IOCB associated with the @vport off the list, set the |
| 10068 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 10069 | * associated with the IOCB. |
| 10070 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 10071 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10072 | { |
| 10073 | LIST_HEAD(completions); |
| 10074 | struct lpfc_hba *phba = vport->phba; |
| 10075 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10076 | |
| 10077 | spin_lock_irq(&phba->hbalock); |
| 10078 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 10079 | list) { |
| 10080 | |
| 10081 | if (piocb->vport != vport) |
| 10082 | continue; |
| 10083 | |
| 10084 | list_move_tail(&piocb->list, &completions); |
| 10085 | } |
| 10086 | spin_unlock_irq(&phba->hbalock); |
| 10087 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10088 | /* Cancel all the IOCBs from the completions list */ |
| 10089 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10090 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10091 | } |
| 10092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10094 | * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10095 | * @ndlp: pointer to a node-list data structure. |
| 10096 | * |
| 10097 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 10098 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 10099 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 10100 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 10101 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 10102 | * associated with the IOCB. |
| 10103 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10104 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 10105 | { |
| 10106 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10107 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10108 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10109 | struct lpfc_sli_ring *pring; |
| 10110 | |
| 10111 | pring = lpfc_phba_elsring(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10112 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10113 | if (unlikely(!pring)) |
| 10114 | return; |
| 10115 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10116 | spin_lock_irq(&phba->hbalock); |
| 10117 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 10118 | list) { |
| 10119 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 10120 | |
| 10121 | list_move_tail(&piocb->list, &completions); |
| 10122 | } |
| 10123 | } |
| 10124 | spin_unlock_irq(&phba->hbalock); |
| 10125 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10126 | /* Cancel all the IOCBs from the completions list */ |
| 10127 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10128 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10129 | } |
| 10130 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10131 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10132 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10133 | * @phba: pointer to lpfc hba data structure. |
| 10134 | * |
| 10135 | * This routine aborts all the IOCBs currently on the driver internal |
| 10136 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 10137 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 10138 | * list, removes IOCBs off the list, set the status feild to |
| 10139 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 10140 | * the IOCB. |
| 10141 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10142 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 10143 | { |
| 10144 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10145 | |
| 10146 | spin_lock_irq(&phba->hbalock); |
| 10147 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 10148 | spin_unlock_irq(&phba->hbalock); |
| 10149 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10150 | /* Cancel all the IOCBs from the completions list */ |
| 10151 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10152 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10153 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10154 | |
| 10155 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10156 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 10157 | * @vport: pointer to lpfc vport data structure. |
| 10158 | * |
| 10159 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 10160 | * for an ndlp on removal. |
| 10161 | **/ |
| 10162 | void |
| 10163 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 10164 | { |
| 10165 | struct lpfc_hba *phba = vport->phba; |
| 10166 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10167 | unsigned long iflag = 0; |
| 10168 | |
| 10169 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10170 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10171 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10172 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10173 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) { |
| 10174 | lpfc_nlp_put(sglq_entry->ndlp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10175 | sglq_entry->ndlp = NULL; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10176 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10177 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10178 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 10179 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10180 | return; |
| 10181 | } |
| 10182 | |
| 10183 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10184 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 10185 | * @phba: pointer to lpfc hba data structure. |
| 10186 | * @axri: pointer to the els xri abort wcqe structure. |
| 10187 | * |
| 10188 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 10189 | * ELS aborted xri. |
| 10190 | **/ |
| 10191 | void |
| 10192 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 10193 | struct sli4_wcqe_xri_aborted *axri) |
| 10194 | { |
| 10195 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10196 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10197 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10198 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10199 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 10200 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10201 | struct lpfc_nodelist *ndlp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10202 | struct lpfc_sli_ring *pring; |
| 10203 | |
| 10204 | pring = lpfc_phba_elsring(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10205 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10206 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10207 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10208 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 10209 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 10210 | if (sglq_entry->sli4_xritag == xri) { |
| 10211 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10212 | ndlp = sglq_entry->ndlp; |
| 10213 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10214 | list_add_tail(&sglq_entry->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10215 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10216 | sglq_entry->state = SGL_FREED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10217 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10218 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10219 | |
| 10220 | if (ndlp) { |
| 10221 | lpfc_set_rrq_active(phba, ndlp, |
| 10222 | sglq_entry->sli4_lxritag, |
| 10223 | rxid, 1); |
| 10224 | lpfc_nlp_put(ndlp); |
| 10225 | } |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10226 | |
| 10227 | /* Check if TXQ queue needs to be serviced */ |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10228 | if (pring && !list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 10229 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10230 | return; |
| 10231 | } |
| 10232 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10233 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10234 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 10235 | if (lxri == NO_XRI) { |
| 10236 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10237 | return; |
| 10238 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10239 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10240 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10241 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10242 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10243 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10244 | return; |
| 10245 | } |
| 10246 | sglq_entry->state = SGL_XRI_ABORTED; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10247 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10248 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10249 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 10250 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10251 | |
| 10252 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. |
| 10253 | * @vport: pointer to virtual port object. |
| 10254 | * @ndlp: nodelist pointer for the impacted node. |
| 10255 | * |
| 10256 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE |
| 10257 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, |
| 10258 | * the driver is required to send a LOGO to the remote node before it |
| 10259 | * attempts to recover its login to the remote node. |
| 10260 | */ |
| 10261 | void |
| 10262 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 10263 | struct lpfc_nodelist *ndlp) |
| 10264 | { |
| 10265 | struct Scsi_Host *shost; |
| 10266 | struct lpfc_hba *phba; |
| 10267 | unsigned long flags = 0; |
| 10268 | |
| 10269 | shost = lpfc_shost_from_vport(vport); |
| 10270 | phba = vport->phba; |
| 10271 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 10272 | lpfc_printf_log(phba, KERN_INFO, |
| 10273 | LOG_SLI, "3093 No rport recovery needed. " |
| 10274 | "rport in state 0x%x\n", ndlp->nlp_state); |
| 10275 | return; |
| 10276 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10278 | "3094 Start rport recovery on shost id 0x%x " |
| 10279 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 10280 | "flags 0x%x\n", |
| 10281 | shost->host_no, ndlp->nlp_DID, |
| 10282 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 10283 | ndlp->nlp_flag); |
| 10284 | /* |
| 10285 | * The rport is not responding. Remove the FCP-2 flag to prevent |
| 10286 | * an ADISC in the follow-up recovery code. |
| 10287 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 10288 | spin_lock_irqsave(&ndlp->lock, flags); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10289 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10290 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 10291 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | 30e196c | 2018-10-23 13:41:03 -0700 | [diff] [blame] | 10292 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 10293 | } |
| 10294 | |