blob: e83453bea2aee1eaf2957b5223f8b41685c7760c [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart8dd1c122021-03-01 09:18:08 -08004 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * 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. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050023/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/interrupt.h>
Gaurav Srivastava7e473de2021-06-08 10:05:50 +053028#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050029
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_transport_fc.h>
James Smartf60cb932019-05-14 14:58:05 -070034#include <uapi/scsi/fc/fc_fs.h>
35#include <uapi/scsi/fc/fc_els.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050047#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050048#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050049
50static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
51 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050052static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
53 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010054static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
55static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
56 struct lpfc_nodelist *ndlp, uint8_t retry);
57static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
58 struct lpfc_iocbq *iocb);
James Smart9064aeb2021-08-16 09:28:50 -070059static void lpfc_cmpl_els_edc(struct lpfc_hba *phba,
60 struct lpfc_iocbq *cmdiocb,
61 struct lpfc_iocbq *rspiocb);
Gaurav Srivastava7e473de2021-06-08 10:05:50 +053062static void lpfc_cmpl_els_uvem(struct lpfc_hba *, struct lpfc_iocbq *,
63 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050064
dea31012005-04-17 16:05:31 -050065static int lpfc_max_els_tries = 3;
66
Gaurav Srivastava7e473de2021-06-08 10:05:50 +053067static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport);
68static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max);
69static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid);
70
James Smarte59058c2008-08-24 21:49:00 -040071/**
James Smart3621a712009-04-06 18:47:14 -040072 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040073 * @vport: pointer to a host virtual N_Port data structure.
74 *
75 * This routine checks whether there is an outstanding host link
76 * attention event during the discovery process with the @vport. It is done
77 * by reading the HBA's Host Attention (HA) register. If there is any host
78 * link attention events during this @vport's discovery process, the @vport
79 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
80 * be issued if the link state is not already in host link cleared state,
81 * and a return code shall indicate whether the host link attention event
82 * had happened.
83 *
84 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
85 * state in LPFC_VPORT_READY, the request for checking host link attention
86 * event will be ignored and a return code shall indicate no host link
87 * attention event had happened.
88 *
89 * Return codes
90 * 0 - no host link attention event happened
91 * 1 - host link attention event happened
92 **/
James Smart858c9f62007-06-17 19:56:39 -050093int
James Smart2e0fef82007-06-17 19:56:36 -050094lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050095{
James Smart2e0fef82007-06-17 19:56:36 -050096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
97 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050098 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050099
James Smart2e0fef82007-06-17 19:56:36 -0500100 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -0400101 phba->link_state == LPFC_LINK_DOWN ||
102 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -0500103 return 0;
104
105 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -0500106 if (lpfc_readl(phba->HAregaddr, &ha_copy))
107 return 1;
dea31012005-04-17 16:05:31 -0500108
109 if (!(ha_copy & HA_LATT))
110 return 0;
111
112 /* Pending Link Event during Discovery */
Dick Kennedy372c1872020-06-30 14:50:00 -0700113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400114 "0237 Pending Link Event during "
115 "Discovery: State x%x\n",
116 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500117
118 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300119 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500120 * LATT processing should call lpfc_linkdown() which
121 * will cleanup any left over in-progress discovery
122 * events.
123 */
James Smart2e0fef82007-06-17 19:56:36 -0500124 spin_lock_irq(shost->host_lock);
125 vport->fc_flag |= FC_ABORT_DISCOVERY;
126 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500127
James Smart92d7f7b2007-06-17 19:56:38 -0500128 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500129 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500130
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500131 return 1;
dea31012005-04-17 16:05:31 -0500132}
133
James Smarte59058c2008-08-24 21:49:00 -0400134/**
James Smart3621a712009-04-06 18:47:14 -0400135 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400136 * @vport: pointer to a host virtual N_Port data structure.
137 * @expectRsp: flag indicating whether response is expected.
138 * @cmdSize: size of the ELS command.
139 * @retry: number of retries to the command IOCB when it fails.
140 * @ndlp: pointer to a node-list data structure.
141 * @did: destination identifier.
142 * @elscmd: the ELS command code.
143 *
144 * This routine is used for allocating a lpfc-IOCB data structure from
145 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
146 * passed into the routine for discovery state machine to issue an Extended
147 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
148 * and preparation routine that is used by all the discovery state machine
149 * routines and the ELS command-specific fields will be later set up by
150 * the individual discovery machine routines after calling this routine
151 * allocating and preparing a generic IOCB data structure. It fills in the
152 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
153 * payload and response payload (if expected). The reference count on the
154 * ndlp is incremented by 1 and the reference to the ndlp is put into
155 * context1 of the IOCB data structure for this IOCB to hold the ndlp
156 * reference for the command's callback function to access later.
157 *
158 * Return code
159 * Pointer to the newly allocated/prepared els iocb data structure
160 * NULL - when els iocb data structure allocation/preparation failed
161 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400162struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500163lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
164 uint16_t cmdSize, uint8_t retry,
165 struct lpfc_nodelist *ndlp, uint32_t did,
166 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500167{
James Smart2e0fef82007-06-17 19:56:36 -0500168 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400169 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500170 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
171 struct ulp_bde64 *bpl;
172 IOCB_t *icmd;
173
dea31012005-04-17 16:05:31 -0500174
James Smart2e0fef82007-06-17 19:56:36 -0500175 if (!lpfc_is_link_up(phba))
176 return NULL;
dea31012005-04-17 16:05:31 -0500177
dea31012005-04-17 16:05:31 -0500178 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400179 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500180
181 if (elsiocb == NULL)
182 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500183
James Smart0c287582009-06-10 17:22:56 -0400184 /*
185 * If this command is for fabric controller and HBA running
186 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
187 */
188 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400189 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400190 ((elscmd == ELS_CMD_FLOGI) ||
191 (elscmd == ELS_CMD_FDISC) ||
192 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500193 switch (elscmd) {
194 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500197 & LPFC_FIP_ELS_ID_MASK);
198 break;
199 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400200 elsiocb->iocb_flag |=
201 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500202 & LPFC_FIP_ELS_ID_MASK);
203 break;
204 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400205 elsiocb->iocb_flag |=
206 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500207 & LPFC_FIP_ELS_ID_MASK);
208 break;
209 }
James Smart0c287582009-06-10 17:22:56 -0400210 else
James Smartc8685952009-11-18 15:39:16 -0500211 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400212
dea31012005-04-17 16:05:31 -0500213 icmd = &elsiocb->iocb;
214
215 /* fill in BDEs for command */
216 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400217 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
218 if (pcmd)
219 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500220 if (!pcmd || !pcmd->virt)
221 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500222
223 INIT_LIST_HEAD(&pcmd->list);
224
225 /* Allocate buffer for response payload */
226 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500227 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500228 if (prsp)
229 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500231 if (!prsp || !prsp->virt)
232 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500233 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500234 } else
dea31012005-04-17 16:05:31 -0500235 prsp = NULL;
dea31012005-04-17 16:05:31 -0500236
237 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500238 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500239 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500240 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
241 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500242 if (!pbuflist || !pbuflist->virt)
243 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500244
245 INIT_LIST_HEAD(&pbuflist->list);
246
dea31012005-04-17 16:05:31 -0500247 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400248 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500251 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400252
253 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500254 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400255 if (elscmd == ELS_CMD_FLOGI)
256 icmd->ulpTimeout = FF_DEF_RATOV * 2;
James Smart30e196c2018-10-23 13:41:03 -0700257 else if (elscmd == ELS_CMD_LOGO)
258 icmd->ulpTimeout = phba->fc_ratov;
James Smart88f43a02013-04-17 20:19:44 -0400259 else
260 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500261 } else {
James Smart939723a2012-05-09 21:19:03 -0400262 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
263 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
264 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
265 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
266 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500267 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
268 }
dea31012005-04-17 16:05:31 -0500269 icmd->ulpBdeCount = 1;
270 icmd->ulpLe = 1;
271 icmd->ulpClass = CLASS3;
272
James Smart939723a2012-05-09 21:19:03 -0400273 /*
274 * If we have NPIV enabled, we want to send ELS traffic by VPI.
275 * For SLI4, since the driver controls VPIs we also want to include
276 * all ELS pt2pt protocol traffic as well.
277 */
278 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
279 ((phba->sli_rev == LPFC_SLI_REV4) &&
280 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500281
James Smart939723a2012-05-09 21:19:03 -0400282 if (expectRsp) {
283 icmd->un.elsreq64.myID = vport->fc_myDID;
284
285 /* For ELS_REQUEST64_CR, use the VPI by default */
286 icmd->ulpContext = phba->vpi_ids[vport->vpi];
287 }
288
James Smart92d7f7b2007-06-17 19:56:38 -0500289 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500290 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
291 if (elscmd == ELS_CMD_ECHO)
292 icmd->ulpCt_l = 0; /* context = invalid RPI */
293 else
294 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500295 }
296
dea31012005-04-17 16:05:31 -0500297 bpl = (struct ulp_bde64 *) pbuflist->virt;
298 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
299 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
300 bpl->tus.f.bdeSize = cmdSize;
301 bpl->tus.f.bdeFlags = 0;
302 bpl->tus.w = le32_to_cpu(bpl->tus.w);
303
304 if (expectRsp) {
305 bpl++;
306 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
307 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
308 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400309 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500310 bpl->tus.w = le32_to_cpu(bpl->tus.w);
311 }
312
James Smart329f9bc2007-04-25 09:53:01 -0400313 elsiocb->context2 = pcmd;
314 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500315 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500316 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500317 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
318
319 if (prsp) {
320 list_add(&prsp->list, &pcmd->list);
321 }
dea31012005-04-17 16:05:31 -0500322 if (expectRsp) {
323 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400324 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
325 "0116 Xmit ELS command x%x to remote "
James Smartdea16bd2018-11-29 16:09:30 -0800326 "NPORT x%x I/O tag: x%x, port state:x%x "
Gaurav Srivastava7e473de2021-06-08 10:05:50 +0530327 "rpi x%x fc_flag:x%x nlp_flag:x%x vport:x%p\n",
James Smarte8b62012007-08-02 11:10:09 -0400328 elscmd, did, elsiocb->iotag,
James Smartdea16bd2018-11-29 16:09:30 -0800329 vport->port_state, ndlp->nlp_rpi,
Gaurav Srivastava7e473de2021-06-08 10:05:50 +0530330 vport->fc_flag, ndlp->nlp_flag, vport);
dea31012005-04-17 16:05:31 -0500331 } else {
332 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400333 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
334 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400335 "NPORT x%x I/O tag: x%x, size: x%x "
James Smartdea16bd2018-11-29 16:09:30 -0800336 "port_state x%x rpi x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400337 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400338 cmdSize, vport->port_state,
James Smartdea16bd2018-11-29 16:09:30 -0800339 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -0500340 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500341 return elsiocb;
dea31012005-04-17 16:05:31 -0500342
James Smartfa4066b2008-01-11 01:53:27 -0500343els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500344 if (expectRsp)
345 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500346 kfree(pbuflist);
347
348els_iocb_free_prsp_exit:
349 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
350 kfree(prsp);
351
352els_iocb_free_pcmb_exit:
353 kfree(pcmd);
354 lpfc_sli_release_iocbq(phba, elsiocb);
355 return NULL;
356}
dea31012005-04-17 16:05:31 -0500357
James Smarte59058c2008-08-24 21:49:00 -0400358/**
James Smart3621a712009-04-06 18:47:14 -0400359 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400360 * @vport: pointer to a host virtual N_Port data structure.
361 *
362 * This routine issues a fabric registration login for a @vport. An
363 * active ndlp node with Fabric_DID must already exist for this @vport.
364 * The routine invokes two mailbox commands to carry out fabric registration
365 * login through the HBA firmware: the first mailbox command requests the
366 * HBA to perform link configuration for the @vport; and the second mailbox
367 * command requests the HBA to perform the actual fabric registration login
368 * with the @vport.
369 *
370 * Return code
371 * 0 - successfully issued fabric registration login for @vport
372 * -ENXIO -- failed to issue fabric registration login for @vport
373 **/
James Smart3772a992009-05-22 14:50:54 -0400374int
James Smart92d7f7b2007-06-17 19:56:38 -0500375lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
376{
377 struct lpfc_hba *phba = vport->phba;
378 LPFC_MBOXQ_t *mbox;
379 struct lpfc_dmabuf *mp;
380 struct lpfc_nodelist *ndlp;
381 struct serv_parm *sp;
382 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400383 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500384
385 sp = &phba->fc_fabparam;
386 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart307e3382020-11-15 11:26:30 -0800387 if (!ndlp) {
James Smart98c9ea52007-10-27 13:37:33 -0400388 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500389 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400390 }
James Smart92d7f7b2007-06-17 19:56:38 -0500391
392 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400393 if (!mbox) {
394 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500395 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400396 }
James Smart92d7f7b2007-06-17 19:56:38 -0500397
398 vport->port_state = LPFC_FABRIC_CFG_LINK;
399 lpfc_config_link(phba, mbox);
400 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
401 mbox->vport = vport;
402
James Smart0b727fe2007-10-27 13:37:25 -0400403 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400404 if (rc == MBX_NOT_FINISHED) {
405 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500406 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400407 }
James Smart92d7f7b2007-06-17 19:56:38 -0500408
409 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400410 if (!mbox) {
411 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500412 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400413 }
James Smart40426292010-12-15 17:58:10 -0500414 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
415 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400416 if (rc) {
417 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500418 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400419 }
James Smart92d7f7b2007-06-17 19:56:38 -0500420
421 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
422 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500423 /* increment the reference count on ndlp to hold reference
424 * for the callback routine.
425 */
James Smart3e1f0712018-11-29 16:09:29 -0800426 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -0800427 if (!mbox->ctx_ndlp) {
428 err = 6;
429 goto fail_no_ndlp;
430 }
James Smart92d7f7b2007-06-17 19:56:38 -0500431
James Smart0b727fe2007-10-27 13:37:25 -0400432 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400433 if (rc == MBX_NOT_FINISHED) {
James Smart4430f7f2020-11-15 11:26:31 -0800434 err = 7;
James Smart92d7f7b2007-06-17 19:56:38 -0500435 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400436 }
James Smart92d7f7b2007-06-17 19:56:38 -0500437
438 return 0;
439
440fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500441 /* decrement the reference count on ndlp just incremented
442 * for the failed mbox command.
443 */
James Smart92d7f7b2007-06-17 19:56:38 -0500444 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -0800445fail_no_ndlp:
James Smart3e1f0712018-11-29 16:09:29 -0800446 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart92d7f7b2007-06-17 19:56:38 -0500447 lpfc_mbuf_free(phba, mp->virt, mp->phys);
448 kfree(mp);
449fail_free_mbox:
450 mempool_free(mbox, phba->mbox_mem_pool);
451
452fail:
453 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -0700454 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
455 "0249 Cannot issue Register Fabric login: Err %d\n",
456 err);
James Smart92d7f7b2007-06-17 19:56:38 -0500457 return -ENXIO;
458}
459
James Smarte59058c2008-08-24 21:49:00 -0400460/**
James Smart6fb120a2009-05-22 14:52:59 -0400461 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
462 * @vport: pointer to a host virtual N_Port data structure.
463 *
464 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500465 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400466 *
467 * Return code
468 * 0 - successfully issued REG_VFI for @vport
469 * A failure code otherwise.
470 **/
James Smart1b511972011-12-13 13:23:09 -0500471int
James Smart6fb120a2009-05-22 14:52:59 -0400472lpfc_issue_reg_vfi(struct lpfc_vport *vport)
473{
474 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500475 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400476 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500477 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400478 int rc = 0;
479
James Smart939723a2012-05-09 21:19:03 -0400480 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500481 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400482 !(phba->link_flag & LS_LOOPBACK_MODE) &&
483 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500484 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart307e3382020-11-15 11:26:30 -0800485 if (!ndlp) {
James Smart1b511972011-12-13 13:23:09 -0500486 rc = -ENODEV;
487 goto fail;
488 }
James Smart6fb120a2009-05-22 14:52:59 -0400489 }
490
James Smart6fb120a2009-05-22 14:52:59 -0400491 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
492 if (!mboxq) {
493 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500494 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400495 }
James Smartd6de08c2015-12-16 18:11:53 -0500496
497 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
498 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
499 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
500 if (!dmabuf) {
501 rc = -ENOMEM;
502 goto fail;
503 }
504 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
505 if (!dmabuf->virt) {
506 rc = -ENOMEM;
507 goto fail;
508 }
509 memcpy(dmabuf->virt, &phba->fc_fabparam,
510 sizeof(struct serv_parm));
511 }
512
James Smart6fb120a2009-05-22 14:52:59 -0400513 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500514 if (dmabuf)
515 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
516 else
517 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500518
James Smart6fb120a2009-05-22 14:52:59 -0400519 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
520 mboxq->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -0800521 mboxq->ctx_buf = dmabuf;
James Smart6fb120a2009-05-22 14:52:59 -0400522 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
523 if (rc == MBX_NOT_FINISHED) {
524 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500525 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400526 }
527 return 0;
528
James Smart6fb120a2009-05-22 14:52:59 -0400529fail:
James Smartd6de08c2015-12-16 18:11:53 -0500530 if (mboxq)
531 mempool_free(mboxq, phba->mbox_mem_pool);
532 if (dmabuf) {
533 if (dmabuf->virt)
534 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
535 kfree(dmabuf);
536 }
537
James Smart6fb120a2009-05-22 14:52:59 -0400538 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -0700539 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
540 "0289 Issue Register VFI failed: Err %d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -0400541 return rc;
542}
543
544/**
James Smart1b511972011-12-13 13:23:09 -0500545 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
546 * @vport: pointer to a host virtual N_Port data structure.
547 *
548 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
549 * the @vport. This mailbox command is necessary for SLI4 port only.
550 *
551 * Return code
552 * 0 - successfully issued REG_VFI for @vport
553 * A failure code otherwise.
554 **/
555int
556lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
557{
558 struct lpfc_hba *phba = vport->phba;
559 struct Scsi_Host *shost;
560 LPFC_MBOXQ_t *mboxq;
561 int rc;
562
563 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
564 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700565 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1b511972011-12-13 13:23:09 -0500566 "2556 UNREG_VFI mbox allocation failed"
567 "HBA state x%x\n", phba->pport->port_state);
568 return -ENOMEM;
569 }
570
571 lpfc_unreg_vfi(mboxq, vport);
572 mboxq->vport = vport;
573 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
574
575 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
576 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700577 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1b511972011-12-13 13:23:09 -0500578 "2557 UNREG_VFI issue mbox failed rc x%x "
579 "HBA state x%x\n",
580 rc, phba->pport->port_state);
581 mempool_free(mboxq, phba->mbox_mem_pool);
582 return -EIO;
583 }
584
585 shost = lpfc_shost_from_vport(vport);
586 spin_lock_irq(shost->host_lock);
587 vport->fc_flag &= ~FC_VFI_REGISTERED;
588 spin_unlock_irq(shost->host_lock);
589 return 0;
590}
591
592/**
James Smart92494142011-02-16 12:39:44 -0500593 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
594 * @vport: pointer to a host virtual N_Port data structure.
595 * @sp: pointer to service parameter data structure.
596 *
597 * This routine is called from FLOGI/FDISC completion handler functions.
598 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
599 * node nodename is changed in the completion service parameter else return
600 * 0. This function also set flag in the vport data structure to delay
601 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
602 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
603 * node nodename is changed in the completion service parameter.
604 *
605 * Return code
606 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
607 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
608 *
609 **/
610static uint8_t
611lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
612 struct serv_parm *sp)
613{
James Smart8eb8b962016-07-06 12:36:08 -0700614 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500615 uint8_t fabric_param_changed = 0;
616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
617
618 if ((vport->fc_prevDID != vport->fc_myDID) ||
619 memcmp(&vport->fabric_portname, &sp->portName,
620 sizeof(struct lpfc_name)) ||
621 memcmp(&vport->fabric_nodename, &sp->nodeName,
James Smartaeb3c812017-04-21 16:05:02 -0700622 sizeof(struct lpfc_name)) ||
623 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
James Smart92494142011-02-16 12:39:44 -0500624 fabric_param_changed = 1;
James Smartaeb3c812017-04-21 16:05:02 -0700625 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
626 }
James Smart92494142011-02-16 12:39:44 -0500627 /*
628 * Word 1 Bit 31 in common service parameter is overloaded.
629 * Word 1 Bit 31 in FLOGI request is multiple NPort request
630 * Word 1 Bit 31 in FLOGI response is clean address bit
631 *
632 * If fabric parameter is changed and clean address bit is
633 * cleared delay nport discovery if
634 * - vport->fc_prevDID != 0 (not initial discovery) OR
635 * - lpfc_delay_discovery module parameter is set.
636 */
637 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700638 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500639 spin_lock_irq(shost->host_lock);
640 vport->fc_flag |= FC_DISC_DELAYED;
641 spin_unlock_irq(shost->host_lock);
642 }
643
644 return fabric_param_changed;
645}
646
647
648/**
James Smart3621a712009-04-06 18:47:14 -0400649 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400650 * @vport: pointer to a host virtual N_Port data structure.
651 * @ndlp: pointer to a node-list data structure.
652 * @sp: pointer to service parameter data structure.
653 * @irsp: pointer to the IOCB within the lpfc response IOCB.
654 *
655 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
656 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
657 * port in a fabric topology. It properly sets up the parameters to the @ndlp
658 * from the IOCB response. It also check the newly assigned N_Port ID to the
659 * @vport against the previously assigned N_Port ID. If it is different from
660 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
661 * is invoked on all the remaining nodes with the @vport to unregister the
662 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
663 * is invoked to register login to the fabric.
664 *
665 * Return code
666 * 0 - Success (currently, always return 0)
667 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500668static int
James Smart2e0fef82007-06-17 19:56:36 -0500669lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
670 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500671{
James Smart2e0fef82007-06-17 19:56:36 -0500672 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
673 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500674 struct lpfc_nodelist *np;
675 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500676 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500677
James Smart2e0fef82007-06-17 19:56:36 -0500678 spin_lock_irq(shost->host_lock);
679 vport->fc_flag |= FC_FABRIC;
680 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500681
682 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
683 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
684 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
685
James Smart12265f62010-10-22 11:05:53 -0400686 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500687 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
688
James Smart76a95d72010-11-20 23:11:48 -0500689 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500690 spin_lock_irq(shost->host_lock);
691 vport->fc_flag |= FC_PUBLIC_LOOP;
692 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500693 }
694
James Smart2e0fef82007-06-17 19:56:36 -0500695 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500696 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500697 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500698 ndlp->nlp_class_sup = 0;
699 if (sp->cls1.classValid)
700 ndlp->nlp_class_sup |= FC_COS_CLASS1;
701 if (sp->cls2.classValid)
702 ndlp->nlp_class_sup |= FC_COS_CLASS2;
703 if (sp->cls3.classValid)
704 ndlp->nlp_class_sup |= FC_COS_CLASS3;
705 if (sp->cls4.classValid)
706 ndlp->nlp_class_sup |= FC_COS_CLASS4;
707 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
708 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500709
710 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500711 if (fabric_param_changed) {
712 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700713 if (phba->cfg_enable_SmartSAN ||
714 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500715 /* Setup appropriate attribute masks */
716 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700717 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500718 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
719 else
720 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700721 } else {
722 vport->fdmi_hba_mask = 0;
723 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500724 }
725
726 }
James Smart92494142011-02-16 12:39:44 -0500727 memcpy(&vport->fabric_portname, &sp->portName,
728 sizeof(struct lpfc_name));
729 memcpy(&vport->fabric_nodename, &sp->nodeName,
730 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500731 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
732
James Smart92d7f7b2007-06-17 19:56:38 -0500733 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
734 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400735 lpfc_printf_vlog(vport, KERN_WARNING,
736 LOG_ELS | LOG_VPORT,
737 "1816 FLOGI NPIV supported, "
738 "response data 0x%x\n",
739 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500740 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500741 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500742 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500743 } else {
744 /* Because we asked f/w for NPIV it still expects us
Bjorn Helgaas2468d202021-01-26 15:12:48 -0600745 to call reg_vnpid at least for the physical host */
James Smarte8b62012007-08-02 11:10:09 -0400746 lpfc_printf_vlog(vport, KERN_WARNING,
747 LOG_ELS | LOG_VPORT,
748 "1817 Fabric does not support NPIV "
749 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500750 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500751 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500752 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500753 }
754 }
755
James Smartae05ebe2013-03-01 16:35:38 -0500756 /*
757 * For FC we need to do some special processing because of the SLI
758 * Port's default settings of the Common Service Parameters.
759 */
James Smartd6de08c2015-12-16 18:11:53 -0500760 if ((phba->sli_rev == LPFC_SLI_REV4) &&
761 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500762 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500763 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500764 lpfc_unregister_fcf_prep(phba);
765
766 /* This should just update the VFI CSPs*/
767 if (vport->fc_flag & FC_VFI_REGISTERED)
768 lpfc_issue_reg_vfi(vport);
769 }
770
James Smart92494142011-02-16 12:39:44 -0500771 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500772 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
773
774 /* If our NportID changed, we need to ensure all
775 * remaining NPORTs get unreg_login'ed.
776 */
777 list_for_each_entry_safe(np, next_np,
778 &vport->fc_nodes, nlp_listp) {
779 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
780 !(np->nlp_flag & NLP_NPR_ADISC))
781 continue;
James Smartc6adba12020-11-15 11:26:34 -0800782 spin_lock_irq(&np->lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500783 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -0800784 spin_unlock_irq(&np->lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500785 lpfc_unreg_rpi(vport, np);
786 }
James Smart78730cf2010-04-06 15:06:30 -0400787 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400788
James Smart5248a742011-07-22 18:37:06 -0400789 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400790 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500791 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500792 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500793 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
794 spin_unlock_irq(shost->host_lock);
795 }
James Smart27aa1b72012-05-09 21:18:49 -0400796
797 /*
798 * For SLI3 and SLI4, the VPI needs to be reregistered in
799 * response to this fabric parameter change event.
800 */
801 spin_lock_irq(shost->host_lock);
802 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
803 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400804 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
805 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
806 /*
807 * Driver needs to re-reg VPI in order for f/w
808 * to update the MAC address.
809 */
James Smart9589b0622011-04-16 11:03:17 -0400810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400811 lpfc_register_new_vport(phba, vport, ndlp);
812 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500813 }
814
James Smart6fb120a2009-05-22 14:52:59 -0400815 if (phba->sli_rev < LPFC_SLI_REV4) {
816 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
817 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
818 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
819 lpfc_register_new_vport(phba, vport, ndlp);
820 else
821 lpfc_issue_fabric_reglogin(vport);
822 } else {
823 ndlp->nlp_type |= NLP_FABRIC;
824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500825 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
826 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400827 lpfc_start_fdiscs(phba);
828 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500829 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500830 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500831 else {
832 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
833 "3135 Need register VFI: (x%x/%x)\n",
834 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400835 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500836 }
James Smart92d7f7b2007-06-17 19:56:38 -0500837 }
dea31012005-04-17 16:05:31 -0500838 return 0;
dea31012005-04-17 16:05:31 -0500839}
James Smart1b511972011-12-13 13:23:09 -0500840
James Smarte59058c2008-08-24 21:49:00 -0400841/**
James Smart3621a712009-04-06 18:47:14 -0400842 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400843 * @vport: pointer to a host virtual N_Port data structure.
844 * @ndlp: pointer to a node-list data structure.
845 * @sp: pointer to service parameter data structure.
846 *
847 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
848 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
849 * in a point-to-point topology. First, the @vport's N_Port Name is compared
850 * with the received N_Port Name: if the @vport's N_Port Name is greater than
851 * the received N_Port Name lexicographically, this node shall assign local
852 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
853 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
854 * this node shall just wait for the remote node to issue PLOGI and assign
855 * N_Port IDs.
856 *
857 * Return code
858 * 0 - Success
859 * -ENXIO - Fail
860 **/
dea31012005-04-17 16:05:31 -0500861static int
James Smart2e0fef82007-06-17 19:56:36 -0500862lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
863 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500864{
James Smart2e0fef82007-06-17 19:56:36 -0500865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
866 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500867 LPFC_MBOXQ_t *mbox;
868 int rc;
869
James Smart2e0fef82007-06-17 19:56:36 -0500870 spin_lock_irq(shost->host_lock);
871 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500872 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500873 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500874
James Smartd33d0eb2017-11-20 16:00:34 -0800875 /* If we are pt2pt with another NPort, force NPIV off! */
876 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
877
James Smartd6de08c2015-12-16 18:11:53 -0500878 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
879 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
880 lpfc_unregister_fcf_prep(phba);
881
882 spin_lock_irq(shost->host_lock);
883 vport->fc_flag &= ~FC_VFI_REGISTERED;
884 spin_unlock_irq(shost->host_lock);
885 phba->fc_topology_changed = 0;
886 }
887
James Smart2e0fef82007-06-17 19:56:36 -0500888 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500889 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400890
dea31012005-04-17 16:05:31 -0500891 if (rc >= 0) {
892 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500893 spin_lock_irq(shost->host_lock);
894 vport->fc_flag |= FC_PT2PT_PLOGI;
895 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500896
897 /*
James Smartd6de08c2015-12-16 18:11:53 -0500898 * N_Port ID cannot be 0, set our Id to LocalID
899 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500900 */
901
902 /* not equal */
903 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500904 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500905
James Smarte47c9092008-02-08 18:49:26 -0500906 /* Decrement ndlp reference count indicating that ndlp can be
907 * safely released when other references to it are done.
908 */
James Smart329f9bc2007-04-25 09:53:01 -0400909 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500910
James Smart2e0fef82007-06-17 19:56:36 -0500911 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500912 if (!ndlp) {
913 /*
914 * Cannot find existing Fabric ndlp, so allocate a
915 * new one
916 */
James Smart9d3d3402017-04-21 16:05:00 -0700917 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500918 if (!ndlp)
919 goto fail;
dea31012005-04-17 16:05:31 -0500920 }
921
922 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500923 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500924 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500925 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500926 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500927 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartc6adba12020-11-15 11:26:34 -0800928 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -0500929 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -0800930 spin_unlock_irq(&ndlp->lock);
James Smartd33d0eb2017-11-20 16:00:34 -0800931
932 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
933 if (!mbox)
934 goto fail;
935
936 lpfc_config_link(phba, mbox);
937
938 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
939 mbox->vport = vport;
940 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
941 if (rc == MBX_NOT_FINISHED) {
942 mempool_free(mbox, phba->mbox_mem_pool);
943 goto fail;
944 }
945 } else {
James Smarte47c9092008-02-08 18:49:26 -0500946 /* This side will wait for the PLOGI, decrement ndlp reference
947 * count indicating that ndlp can be released when other
948 * references to it are done.
949 */
James Smart329f9bc2007-04-25 09:53:01 -0400950 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500951
James Smartd33d0eb2017-11-20 16:00:34 -0800952 /* Start discovery - this should just do CLEAR_LA */
953 lpfc_disc_start(vport);
James Smarte74c03c2013-04-17 20:15:19 -0400954 }
dea31012005-04-17 16:05:31 -0500955
dea31012005-04-17 16:05:31 -0500956 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500957fail:
dea31012005-04-17 16:05:31 -0500958 return -ENXIO;
959}
960
James Smarte59058c2008-08-24 21:49:00 -0400961/**
James Smart3621a712009-04-06 18:47:14 -0400962 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400963 * @phba: pointer to lpfc hba data structure.
964 * @cmdiocb: pointer to lpfc command iocb data structure.
965 * @rspiocb: pointer to lpfc response iocb data structure.
966 *
967 * This routine is the top-level completion callback function for issuing
968 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
969 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
970 * retry has been made (either immediately or delayed with lpfc_els_retry()
971 * returning 1), the command IOCB will be released and function returned.
972 * If the retry attempt has been given up (possibly reach the maximum
973 * number of retries), one additional decrement of ndlp reference shall be
974 * invoked before going out after releasing the command IOCB. This will
975 * actually release the remote node (Note, lpfc_els_free_iocb() will also
976 * invoke one decrement of ndlp reference count). If no error reported in
977 * the IOCB status, the command Port ID field is used to determine whether
978 * this is a point-to-point topology or a fabric topology: if the Port ID
979 * field is assigned, it is a fabric topology; otherwise, it is a
980 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
981 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
982 * specific topology completion conditions.
983 **/
dea31012005-04-17 16:05:31 -0500984static void
James Smart329f9bc2007-04-25 09:53:01 -0400985lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
986 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500987{
James Smart2e0fef82007-06-17 19:56:36 -0500988 struct lpfc_vport *vport = cmdiocb->vport;
989 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500990 IOCB_t *irsp = &rspiocb->iocb;
991 struct lpfc_nodelist *ndlp = cmdiocb->context1;
992 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
993 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500994 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500995 int rc;
996
997 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500998 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500999 /* One additional decrement on node reference count to
1000 * trigger the release of the node
1001 */
James Smart329f9bc2007-04-25 09:53:01 -04001002 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001003 goto out;
1004 }
1005
James Smart858c9f62007-06-17 19:56:39 -05001006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1007 "FLOGI cmpl: status:x%x/x%x state:x%x",
1008 irsp->ulpStatus, irsp->un.ulpWord[4],
1009 vport->port_state);
1010
dea31012005-04-17 16:05:31 -05001011 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001012 /*
James Smarta93ff372010-10-22 11:06:08 -04001013 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001014 * due to new FCF discovery
1015 */
1016 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001017 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1018 if (phba->link_state < LPFC_LINK_UP)
1019 goto stop_rr_fcf_flogi;
1020 if ((phba->fcoe_cvl_eventtag_attn ==
1021 phba->fcoe_cvl_eventtag) &&
1022 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001023 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1024 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001025 goto stop_rr_fcf_flogi;
1026 else
1027 phba->fcoe_cvl_eventtag_attn =
1028 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001029 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001030 "2611 FLOGI failed on FCF (x%x), "
1031 "status:x%x/x%x, tmo:x%x, perform "
1032 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001033 phba->fcf.current_rec.fcf_indx,
1034 irsp->ulpStatus, irsp->un.ulpWord[4],
1035 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001036 lpfc_sli4_set_fcf_flogi_fail(phba,
1037 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001038 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001039 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1040 if (rc)
1041 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001042 }
1043
James Smart80c17842012-03-01 22:35:45 -05001044stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001045 /* FLOGI failure */
James Smartc73455e2017-11-20 16:00:28 -08001046 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1047 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1048 IOERR_LOOP_OPEN_FAILURE)))
Dick Kennedy372c1872020-06-30 14:50:00 -07001049 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1050 "2858 FLOGI failure Status:x%x/x%x TMO"
1051 ":x%x Data x%x x%x\n",
1052 irsp->ulpStatus, irsp->un.ulpWord[4],
1053 irsp->ulpTimeout, phba->hba_flag,
1054 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001055
dea31012005-04-17 16:05:31 -05001056 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001057 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001058 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001059
Dick Kennedy372c1872020-06-30 14:50:00 -07001060 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
James Smarte62245d2019-08-14 16:57:08 -07001061 "0150 FLOGI failure Status:x%x/x%x "
James Smart982fc392021-09-10 16:31:47 -07001062 "xri x%x TMO:x%x refcnt %d\n",
James Smarte62245d2019-08-14 16:57:08 -07001063 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart982fc392021-09-10 16:31:47 -07001064 cmdiocb->sli4_xritag, irsp->ulpTimeout,
1065 kref_read(&ndlp->kref));
James Smarte62245d2019-08-14 16:57:08 -07001066
James Smartae9e28f2017-05-15 15:20:51 -07001067 /* If this is not a loop open failure, bail out */
1068 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1069 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1070 IOERR_LOOP_OPEN_FAILURE)))
1071 goto flogifail;
1072
dea31012005-04-17 16:05:31 -05001073 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001074 spin_lock_irq(shost->host_lock);
1075 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1076 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001077
James Smart329f9bc2007-04-25 09:53:01 -04001078 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001079 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1080 * alpa map would take too long otherwise.
1081 */
James Smart1b511972011-12-13 13:23:09 -05001082 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001083 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001084 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1085 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001086 (vport->fc_prevDID != vport->fc_myDID) ||
1087 phba->fc_topology_changed)) {
1088 if (vport->fc_flag & FC_VFI_REGISTERED) {
1089 if (phba->fc_topology_changed) {
1090 lpfc_unregister_fcf_prep(phba);
1091 spin_lock_irq(shost->host_lock);
1092 vport->fc_flag &= ~FC_VFI_REGISTERED;
1093 spin_unlock_irq(shost->host_lock);
1094 phba->fc_topology_changed = 0;
1095 } else {
1096 lpfc_sli4_unreg_all_rpis(vport);
1097 }
1098 }
James Smart342b59c2016-03-31 14:12:31 -07001099
1100 /* Do not register VFI if the driver aborted FLOGI */
1101 if (!lpfc_error_lost_link(irsp))
1102 lpfc_issue_reg_vfi(vport);
James Smart4430f7f2020-11-15 11:26:31 -08001103
James Smartff78d8f2011-12-13 13:21:35 -05001104 lpfc_nlp_put(ndlp);
1105 goto out;
dea31012005-04-17 16:05:31 -05001106 }
dea31012005-04-17 16:05:31 -05001107 goto flogifail;
1108 }
James Smart695a8142010-01-26 23:08:03 -05001109 spin_lock_irq(shost->host_lock);
1110 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001111 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001113
1114 /*
1115 * The FLogI succeeded. Sync the data for the CPU before
1116 * accessing it.
1117 */
1118 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001119 if (!prsp)
1120 goto out;
dea31012005-04-17 16:05:31 -05001121 sp = prsp->virt + sizeof(uint32_t);
1122
1123 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001124 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001125 "0101 FLOGI completes successfully, I/O tag:x%x, "
James Smart982fc392021-09-10 16:31:47 -07001126 "xri x%x Data: x%x x%x x%x x%x x%x x%x x%x %d\n",
James Smartd496b9a2018-10-23 13:41:08 -07001127 cmdiocb->iotag, cmdiocb->sli4_xritag,
James Smarte8b62012007-08-02 11:10:09 -04001128 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001129 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05301130 vport->port_state, vport->fc_flag,
James Smart982fc392021-09-10 16:31:47 -07001131 sp->cmn.priority_tagging, kref_read(&ndlp->kref));
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05301132
1133 if (sp->cmn.priority_tagging)
1134 vport->vmid_flag |= LPFC_VMID_ISSUE_QFPA;
dea31012005-04-17 16:05:31 -05001135
James Smart2e0fef82007-06-17 19:56:36 -05001136 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001137 /*
1138 * If Common Service Parameters indicate Nport
1139 * we are point to point, if Fport we are Fabric.
1140 */
1141 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001142 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001143 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001144 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001145 else {
Dick Kennedy372c1872020-06-30 14:50:00 -07001146 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartdbb6b3a2010-06-08 18:31:37 -04001147 "2831 FLOGI response with cleared Fabric "
1148 "bit fcf_index 0x%x "
1149 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1150 "Fabric Name "
1151 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1152 phba->fcf.current_rec.fcf_indx,
1153 phba->fcf.current_rec.switch_name[0],
1154 phba->fcf.current_rec.switch_name[1],
1155 phba->fcf.current_rec.switch_name[2],
1156 phba->fcf.current_rec.switch_name[3],
1157 phba->fcf.current_rec.switch_name[4],
1158 phba->fcf.current_rec.switch_name[5],
1159 phba->fcf.current_rec.switch_name[6],
1160 phba->fcf.current_rec.switch_name[7],
1161 phba->fcf.current_rec.fabric_name[0],
1162 phba->fcf.current_rec.fabric_name[1],
1163 phba->fcf.current_rec.fabric_name[2],
1164 phba->fcf.current_rec.fabric_name[3],
1165 phba->fcf.current_rec.fabric_name[4],
1166 phba->fcf.current_rec.fabric_name[5],
1167 phba->fcf.current_rec.fabric_name[6],
1168 phba->fcf.current_rec.fabric_name[7]);
James Smart4430f7f2020-11-15 11:26:31 -08001169
James Smartdbb6b3a2010-06-08 18:31:37 -04001170 lpfc_nlp_put(ndlp);
1171 spin_lock_irq(&phba->hbalock);
1172 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001173 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001174 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001175 phba->fcf.fcf_redisc_attempted = 0; /* reset */
James Smartdbb6b3a2010-06-08 18:31:37 -04001176 goto out;
1177 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001178 if (!rc) {
1179 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001180 if (phba->hba_flag & HBA_FIP_SUPPORT)
1181 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1182 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001183 "2769 FLOGI to FCF (x%x) "
1184 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001185 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001186 spin_lock_irq(&phba->hbalock);
1187 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001188 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001189 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001190 phba->fcf.fcf_redisc_attempted = 0; /* reset */
dea31012005-04-17 16:05:31 -05001191 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001192 }
James Smarte30d5512021-05-14 12:55:51 -07001193 } else if (vport->port_state > LPFC_FLOGI &&
1194 vport->fc_flag & FC_PT2PT) {
1195 /*
1196 * In a p2p topology, it is possible that discovery has
1197 * already progressed, and this completion can be ignored.
1198 * Recheck the indicated topology.
1199 */
1200 if (!sp->cmn.fPort)
1201 goto out;
dea31012005-04-17 16:05:31 -05001202 }
1203
1204flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001205 spin_lock_irq(&phba->hbalock);
1206 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1207 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001208
James Smart858c9f62007-06-17 19:56:39 -05001209 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001210 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001211 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001212
1213 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001214 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001215 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001216 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1217 IOERR_SLI_ABORTED) &&
1218 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1219 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001220 (phba->link_state != LPFC_CLEAR_LA)) {
1221 /* If FLOGI failed enable link interrupt. */
1222 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001223 }
dea31012005-04-17 16:05:31 -05001224out:
James Smart9dd83f72021-03-01 09:18:11 -08001225 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
dea31012005-04-17 16:05:31 -05001226 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001227 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001228}
1229
James Smarte59058c2008-08-24 21:49:00 -04001230/**
James Smart6ede2dd2019-08-14 16:56:44 -07001231 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1232 * aborted during a link down
1233 * @phba: pointer to lpfc hba data structure.
1234 * @cmdiocb: pointer to lpfc command iocb data structure.
1235 * @rspiocb: pointer to lpfc response iocb data structure.
1236 *
1237 */
1238static void
1239lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1240 struct lpfc_iocbq *rspiocb)
1241{
1242 IOCB_t *irsp;
1243 uint32_t *pcmd;
1244 uint32_t cmd;
1245
1246 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1247 cmd = *pcmd;
1248 irsp = &rspiocb->iocb;
1249
1250 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1251 "6445 ELS completes after LINK_DOWN: "
1252 " Status %x/%x cmd x%x flg x%x\n",
1253 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1254 cmdiocb->iocb_flag);
1255
1256 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1257 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1258 atomic_dec(&phba->fabric_iocb_count);
1259 }
1260 lpfc_els_free_iocb(phba, cmdiocb);
1261}
1262
1263/**
James Smart3621a712009-04-06 18:47:14 -04001264 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001265 * @vport: pointer to a host virtual N_Port data structure.
1266 * @ndlp: pointer to a node-list data structure.
1267 * @retry: number of retries to the command IOCB.
1268 *
1269 * This routine issues a Fabric Login (FLOGI) Request ELS command
1270 * for a @vport. The initiator service parameters are put into the payload
1271 * of the FLOGI Request IOCB and the top-level callback function pointer
1272 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1273 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1274 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1275 *
James Smart69b8eff2021-03-01 09:18:19 -08001276 * Note that the ndlp reference count will be incremented by 1 for holding the
1277 * ndlp and the reference to ndlp will be stored into the context1 field of
1278 * the IOCB for the completion callback function to the FLOGI ELS command.
James Smarte59058c2008-08-24 21:49:00 -04001279 *
1280 * Return code
1281 * 0 - successfully issued flogi iocb for @vport
1282 * 1 - failed to issue flogi iocb for @vport
1283 **/
dea31012005-04-17 16:05:31 -05001284static int
James Smart2e0fef82007-06-17 19:56:36 -05001285lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001286 uint8_t retry)
1287{
James Smart2e0fef82007-06-17 19:56:36 -05001288 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001289 struct serv_parm *sp;
1290 IOCB_t *icmd;
1291 struct lpfc_iocbq *elsiocb;
James Smart0a9e9682018-11-29 16:09:36 -08001292 struct lpfc_iocbq defer_flogi_acc;
dea31012005-04-17 16:05:31 -05001293 uint8_t *pcmd;
1294 uint16_t cmdsize;
James Smart0a9e9682018-11-29 16:09:36 -08001295 uint32_t tmo, did;
dea31012005-04-17 16:05:31 -05001296 int rc;
1297
James Smart92d7f7b2007-06-17 19:56:38 -05001298 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001299 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1300 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001301
James Smart488d1462006-03-07 15:02:37 -05001302 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001303 return 1;
dea31012005-04-17 16:05:31 -05001304
1305 icmd = &elsiocb->iocb;
1306 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1307
1308 /* For FLOGI request, remainder of payload is service parameters */
1309 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001310 pcmd += sizeof(uint32_t);
1311 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001312 sp = (struct serv_parm *) pcmd;
1313
1314 /* Setup CSPs accordingly for Fabric */
1315 sp->cmn.e_d_tov = 0;
1316 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001317 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001318 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001319 if (sp->cmn.fcphLow < FC_PH3)
1320 sp->cmn.fcphLow = FC_PH3;
1321 if (sp->cmn.fcphHigh < FC_PH3)
1322 sp->cmn.fcphHigh = FC_PH3;
1323
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05301324 /* Determine if switch supports priority tagging */
1325 if (phba->cfg_vmid_priority_tagging) {
1326 sp->cmn.priority_tagging = 1;
1327 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1328 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) {
1329 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1330 sizeof(phba->wwpn));
1331 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1332 sizeof(phba->wwnn));
1333 }
1334 }
1335
James Smartc31098c2011-04-16 11:03:33 -04001336 if (phba->sli_rev == LPFC_SLI_REV4) {
1337 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1338 LPFC_SLI_INTF_IF_TYPE_0) {
1339 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1340 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1341 /* FLOGI needs to be 3 for WQE FCFI */
1342 /* Set the fcfi to the fcfi we registered with */
1343 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1344 }
James Smart0f378872012-10-31 14:45:01 -04001345 /* Can't do SLI4 class2 without support sequence coalescing */
1346 sp->cls2.classValid = 0;
1347 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001348 } else {
James Smart0f378872012-10-31 14:45:01 -04001349 /* Historical, setting sequential-delivery bit for SLI3 */
1350 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1351 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001352 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1353 sp->cmn.request_multiple_Nport = 1;
1354 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1355 icmd->ulpCt_h = 1;
1356 icmd->ulpCt_l = 0;
1357 } else
1358 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001359 }
1360
James Smart76a95d72010-11-20 23:11:48 -05001361 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001362 icmd->un.elsreq64.myID = 0;
1363 icmd->un.elsreq64.fl = 1;
1364 }
1365
dea31012005-04-17 16:05:31 -05001366 tmo = phba->fc_ratov;
1367 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001368 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001369 phba->fc_ratov = tmo;
1370
1371 phba->fc_stat.elsXmitFLOGI++;
1372 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001373
1374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1375 "Issue FLOGI: opt:x%x",
1376 phba->sli3_options, 0, 0);
1377
James Smart4430f7f2020-11-15 11:26:31 -08001378 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08001379 if (!elsiocb->context1) {
1380 lpfc_els_free_iocb(phba, elsiocb);
1381 return 1;
1382 }
James Smart4430f7f2020-11-15 11:26:31 -08001383
James Smart92d7f7b2007-06-17 19:56:38 -05001384 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08001385 if (rc == IOCB_ERROR) {
1386 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001387 lpfc_nlp_put(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08001388 return 1;
1389 }
James Smart0a9e9682018-11-29 16:09:36 -08001390
James Smart9dd83f72021-03-01 09:18:11 -08001391 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
James Smart0a9e9682018-11-29 16:09:36 -08001392
1393 /* Check for a deferred FLOGI ACC condition */
1394 if (phba->defer_flogi_acc_flag) {
1395 did = vport->fc_myDID;
1396 vport->fc_myDID = Fabric_DID;
1397
1398 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1399
1400 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1401 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1402 phba->defer_flogi_acc_ox_id;
1403
1404 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1405 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1406 " ox_id: x%x, hba_flag x%x\n",
1407 phba->defer_flogi_acc_rx_id,
1408 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1409
1410 /* Send deferred FLOGI ACC */
1411 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1412 ndlp, NULL);
1413
1414 phba->defer_flogi_acc_flag = false;
1415
1416 vport->fc_myDID = did;
1417 }
1418
James Smart8e9a3252021-03-01 09:18:09 -08001419 return 0;
dea31012005-04-17 16:05:31 -05001420}
1421
James Smarte59058c2008-08-24 21:49:00 -04001422/**
James Smart3621a712009-04-06 18:47:14 -04001423 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001424 * @phba: pointer to lpfc hba data structure.
1425 *
1426 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1427 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1428 * list and issues an abort IOCB commond on each outstanding IOCB that
1429 * contains a active Fabric_DID ndlp. Note that this function is to issue
1430 * the abort IOCB command on all the outstanding IOCBs, thus when this
1431 * function returns, it does not guarantee all the IOCBs are actually aborted.
1432 *
1433 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001434 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001435 **/
dea31012005-04-17 16:05:31 -05001436int
James Smart2e0fef82007-06-17 19:56:36 -05001437lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001438{
1439 struct lpfc_sli_ring *pring;
1440 struct lpfc_iocbq *iocb, *next_iocb;
1441 struct lpfc_nodelist *ndlp;
1442 IOCB_t *icmd;
1443
1444 /* Abort outstanding I/O on NPort <nlp_DID> */
1445 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001446 "0201 Abort outstanding I/O on NPort x%x\n",
1447 Fabric_DID);
dea31012005-04-17 16:05:31 -05001448
James Smart895427b2017-02-12 13:52:30 -08001449 pring = lpfc_phba_elsring(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001450 if (unlikely(!pring))
1451 return -EIO;
dea31012005-04-17 16:05:31 -05001452
1453 /*
1454 * Check the txcmplq for an iocb that matches the nport the driver is
1455 * searching for.
1456 */
James Smart2e0fef82007-06-17 19:56:36 -05001457 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001458 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1459 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001460 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001461 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart9dd83f72021-03-01 09:18:11 -08001462 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1463 if ((phba->pport->fc_flag & FC_PT2PT) &&
1464 !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
1465 iocb->fabric_iocb_cmpl =
1466 lpfc_ignore_els_cmpl;
James Smartdb7531d2020-11-15 11:26:44 -08001467 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1468 NULL);
James Smart9dd83f72021-03-01 09:18:11 -08001469 }
dea31012005-04-17 16:05:31 -05001470 }
1471 }
James Smarta22d73b2021-01-04 10:02:38 -08001472 /* Make sure HBA is alive */
1473 lpfc_issue_hb_tmo(phba);
1474
James Smart2e0fef82007-06-17 19:56:36 -05001475 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001476
1477 return 0;
1478}
1479
James Smarte59058c2008-08-24 21:49:00 -04001480/**
James Smart3621a712009-04-06 18:47:14 -04001481 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001482 * @vport: pointer to a host virtual N_Port data structure.
1483 *
1484 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1485 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1486 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1487 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1488 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1489 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1490 * @vport.
1491 *
1492 * Return code
1493 * 0 - failed to issue initial flogi for @vport
1494 * 1 - successfully issued initial flogi for @vport
1495 **/
dea31012005-04-17 16:05:31 -05001496int
James Smart2e0fef82007-06-17 19:56:36 -05001497lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001498{
1499 struct lpfc_nodelist *ndlp;
1500
James Smart98c9ea52007-10-27 13:37:33 -04001501 vport->port_state = LPFC_FLOGI;
1502 lpfc_set_disctmo(vport);
1503
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001504 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001505 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001506 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001507 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001508 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001509 if (!ndlp)
1510 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001511 /* Set the node type */
1512 ndlp->nlp_type |= NLP_FABRIC;
James Smart307e3382020-11-15 11:26:30 -08001513
James Smarte47c9092008-02-08 18:49:26 -05001514 /* Put ndlp onto node list */
1515 lpfc_enqueue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001516 }
James Smart87af33f2007-10-27 13:37:43 -04001517
James Smart5ac6b302010-10-22 11:05:36 -04001518 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001519 /* This decrement of reference count to node shall kick off
1520 * the release of the node.
1521 */
James Smart329f9bc2007-04-25 09:53:01 -04001522 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001523 return 0;
1524 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001525 return 1;
dea31012005-04-17 16:05:31 -05001526}
1527
James Smarte59058c2008-08-24 21:49:00 -04001528/**
James Smart3621a712009-04-06 18:47:14 -04001529 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001530 * @vport: pointer to a host virtual N_Port data structure.
1531 *
1532 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1533 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1534 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1535 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1536 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1537 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1538 * @vport.
1539 *
1540 * Return code
1541 * 0 - failed to issue initial fdisc for @vport
1542 * 1 - successfully issued initial fdisc for @vport
1543 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001544int
1545lpfc_initial_fdisc(struct lpfc_vport *vport)
1546{
James Smart92d7f7b2007-06-17 19:56:38 -05001547 struct lpfc_nodelist *ndlp;
1548
1549 /* First look for the Fabric ndlp */
1550 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1551 if (!ndlp) {
1552 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001553 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001554 if (!ndlp)
1555 return 0;
James Smartb3f2e672020-11-15 11:26:37 -08001556
1557 /* NPIV is only supported in Fabrics. */
1558 ndlp->nlp_type |= NLP_FABRIC;
1559
James Smarte47c9092008-02-08 18:49:26 -05001560 /* Put ndlp onto node list */
1561 lpfc_enqueue_node(vport, ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001562 }
James Smarte47c9092008-02-08 18:49:26 -05001563
James Smart92d7f7b2007-06-17 19:56:38 -05001564 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001565 /* decrement node reference count to trigger the release of
1566 * the node.
1567 */
James Smart92d7f7b2007-06-17 19:56:38 -05001568 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001569 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001570 }
1571 return 1;
1572}
James Smart87af33f2007-10-27 13:37:43 -04001573
James Smarte59058c2008-08-24 21:49:00 -04001574/**
James Smart3621a712009-04-06 18:47:14 -04001575 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001576 * @vport: pointer to a host virtual N_Port data structure.
1577 *
1578 * This routine checks whether there are more remaining Port Logins
1579 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1580 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1581 * to issue ELS PLOGIs up to the configured discover threads with the
1582 * @vport (@vport->cfg_discovery_threads). The function also decrement
1583 * the @vport's num_disc_node by 1 if it is not already 0.
1584 **/
James Smart87af33f2007-10-27 13:37:43 -04001585void
James Smart2e0fef82007-06-17 19:56:36 -05001586lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001587{
James Smart2e0fef82007-06-17 19:56:36 -05001588 if (vport->num_disc_nodes)
1589 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001590
1591 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001592 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1593 "0232 Continue discovery with %d PLOGIs to go "
1594 "Data: x%x x%x x%x\n",
1595 vport->num_disc_nodes, vport->fc_plogi_cnt,
1596 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001597 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001598 if (vport->fc_flag & FC_NLP_MORE)
1599 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001600 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001601
dea31012005-04-17 16:05:31 -05001602 return;
1603}
1604
James Smarte59058c2008-08-24 21:49:00 -04001605/**
James Smarte9b11082020-11-15 11:26:33 -08001606 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001607 * @phba: pointer to lpfc hba data structure.
1608 * @prsp: pointer to response IOCB payload.
1609 * @ndlp: pointer to a node-list data structure.
1610 *
1611 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1612 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1613 * The following cases are considered N_Port confirmed:
1614 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1615 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1616 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1617 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1618 * 1) if there is a node on vport list other than the @ndlp with the same
1619 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1620 * on that node to release the RPI associated with the node; 2) if there is
1621 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1622 * into, a new node shall be allocated (or activated). In either case, the
1623 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1624 * be released and the new_ndlp shall be put on to the vport node list and
1625 * its pointer returned as the confirmed node.
1626 *
1627 * Note that before the @ndlp got "released", the keepDID from not-matching
1628 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1629 * of the @ndlp. This is because the release of @ndlp is actually to put it
1630 * into an inactive state on the vport node list and the vport node list
1631 * management algorithm does not allow two node with a same DID.
1632 *
1633 * Return code
1634 * pointer to the PLOGI N_Port @ndlp
1635 **/
James Smart488d1462006-03-07 15:02:37 -05001636static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001637lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001638 struct lpfc_nodelist *ndlp)
1639{
James Smarta0f2d3e2017-02-12 13:52:31 -08001640 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001641 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -05001642 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001643 uint8_t name[sizeof(struct lpfc_name)];
James Smart309b4772021-03-01 09:18:13 -08001644 uint32_t keepDID = 0, keep_nlp_flag = 0;
James Smart92ea83a2018-11-29 16:09:34 -08001645 uint32_t keep_new_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001646 uint16_t keep_nlp_state;
James Smart92ea83a2018-11-29 16:09:34 -08001647 u32 keep_nlp_fc4_type = 0;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001648 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smartcff261f2013-12-17 20:29:47 -05001649 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001650
James Smart2fb9bd82006-12-02 13:33:57 -05001651 /* Fabric nodes can have the same WWPN so we don't bother searching
1652 * by WWPN. Just return the ndlp that was given to us.
1653 */
1654 if (ndlp->nlp_type & NLP_FABRIC)
1655 return ndlp;
1656
James Smart92d7f7b2007-06-17 19:56:38 -05001657 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001658 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001659
James Smart685f0bf2007-04-25 09:53:08 -04001660 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001661 * we have for that ndlp. If not, we have some work to do.
1662 */
James Smart2e0fef82007-06-17 19:56:36 -05001663 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001664
James Smartd83ca3e2018-10-23 13:41:09 -07001665 /* return immediately if the WWPN matches ndlp */
James Smart309b4772021-03-01 09:18:13 -08001666 if (!new_ndlp || (new_ndlp == ndlp))
James Smart488d1462006-03-07 15:02:37 -05001667 return ndlp;
James Smartd83ca3e2018-10-23 13:41:09 -07001668
James Smart06145682021-07-07 11:43:46 -07001669 /*
1670 * Unregister from backend if not done yet. Could have been skipped
1671 * due to ADISC
1672 */
1673 lpfc_nlp_unreg_node(vport, new_ndlp);
1674
James Smartcff261f2013-12-17 20:29:47 -05001675 if (phba->sli_rev == LPFC_SLI_REV4) {
1676 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1677 GFP_KERNEL);
1678 if (active_rrqs_xri_bitmap)
1679 memset(active_rrqs_xri_bitmap, 0,
1680 phba->cfg_rrq_xri_bitmap_sz);
1681 }
James Smart488d1462006-03-07 15:02:37 -05001682
James Smartd83ca3e2018-10-23 13:41:09 -07001683 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1684 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1685 "new_ndlp x%x x%x x%x\n",
1686 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1687 (new_ndlp ? new_ndlp->nlp_DID : 0),
1688 (new_ndlp ? new_ndlp->nlp_flag : 0),
1689 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
James Smart34f5ad82012-08-03 12:35:03 -04001690
James Smart309b4772021-03-01 09:18:13 -08001691 keepDID = new_ndlp->nlp_DID;
1692
1693 if (phba->sli_rev == LPFC_SLI_REV4 && active_rrqs_xri_bitmap)
1694 memcpy(active_rrqs_xri_bitmap, new_ndlp->active_rrqs_xri_bitmap,
1695 phba->cfg_rrq_xri_bitmap_sz);
James Smart488d1462006-03-07 15:02:37 -05001696
James Smartd83ca3e2018-10-23 13:41:09 -07001697 /* At this point in this routine, we know new_ndlp will be
1698 * returned. however, any previous GID_FTs that were done
1699 * would have updated nlp_fc4_type in ndlp, so we must ensure
1700 * new_ndlp has the right value.
1701 */
James Smart92ea83a2018-11-29 16:09:34 -08001702 if (vport->fc_flag & FC_FABRIC) {
1703 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
James Smartd83ca3e2018-10-23 13:41:09 -07001704 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
James Smart92ea83a2018-11-29 16:09:34 -08001705 }
James Smartd83ca3e2018-10-23 13:41:09 -07001706
James Smart2e0fef82007-06-17 19:56:36 -05001707 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001708 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001709 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001710 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001711 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1712 ndlp->active_rrqs_xri_bitmap,
1713 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001714
James Smartc6adba12020-11-15 11:26:34 -08001715 /* Lock both ndlps */
1716 spin_lock_irq(&ndlp->lock);
1717 spin_lock_irq(&new_ndlp->lock);
James Smart92ea83a2018-11-29 16:09:34 -08001718 keep_new_nlp_flag = new_ndlp->nlp_flag;
1719 keep_nlp_flag = ndlp->nlp_flag;
James Smarte5abba42015-05-21 13:55:27 -04001720 new_ndlp->nlp_flag = ndlp->nlp_flag;
James Smartdea16bd2018-11-29 16:09:30 -08001721
1722 /* if new_ndlp had NLP_UNREG_INP set, keep it */
James Smart92ea83a2018-11-29 16:09:34 -08001723 if (keep_new_nlp_flag & NLP_UNREG_INP)
James Smartdea16bd2018-11-29 16:09:30 -08001724 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1725 else
1726 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1727
James Smart92ea83a2018-11-29 16:09:34 -08001728 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1729 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1730 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001731 else
James Smart92ea83a2018-11-29 16:09:34 -08001732 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1733
James Smart724f6b42021-04-11 18:31:18 -07001734 /*
1735 * Retain the DROPPED flag. This will take care of the init
1736 * refcount when affecting the state change
1737 */
1738 if (keep_new_nlp_flag & NLP_DROPPED)
1739 new_ndlp->nlp_flag |= NLP_DROPPED;
1740 else
1741 new_ndlp->nlp_flag &= ~NLP_DROPPED;
1742
James Smart92ea83a2018-11-29 16:09:34 -08001743 ndlp->nlp_flag = keep_new_nlp_flag;
1744
1745 /* if ndlp had NLP_UNREG_INP set, keep it */
1746 if (keep_nlp_flag & NLP_UNREG_INP)
1747 ndlp->nlp_flag |= NLP_UNREG_INP;
1748 else
1749 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1750
1751 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1752 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1753 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1754 else
1755 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001756
James Smart724f6b42021-04-11 18:31:18 -07001757 /*
1758 * Retain the DROPPED flag. This will take care of the init
1759 * refcount when affecting the state change
1760 */
1761 if (keep_nlp_flag & NLP_DROPPED)
1762 ndlp->nlp_flag |= NLP_DROPPED;
1763 else
1764 ndlp->nlp_flag &= ~NLP_DROPPED;
1765
James Smartc6adba12020-11-15 11:26:34 -08001766 spin_unlock_irq(&new_ndlp->lock);
1767 spin_unlock_irq(&ndlp->lock);
James Smart0ff10d42008-01-11 01:52:36 -05001768
James Smart953ceed2015-05-22 10:42:37 -04001769 /* Set nlp_states accordingly */
1770 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001771 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001772
Dick Kennedy4adc0412017-08-23 16:55:37 -07001773 /* interchange the nvme remoteport structs */
1774 keep_nrport = new_ndlp->nrport;
1775 new_ndlp->nrport = ndlp->nrport;
1776
James Smart2e0fef82007-06-17 19:56:36 -05001777 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001778 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1779 /* The new_ndlp is replacing ndlp totally, so we need
1780 * to put ndlp on UNUSED list and try to free it.
1781 */
James Smart34f5ad82012-08-03 12:35:03 -04001782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1783 "3179 PLOGI confirm NEW: %x %x\n",
1784 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001785
James Smart92ea83a2018-11-29 16:09:34 -08001786 /* Two ndlps cannot have the same did on the nodelist.
1787 * Note: for this case, ndlp has a NULL WWPN so setting
1788 * the nlp_fc4_type isn't required.
1789 */
James Smart58da1ff2008-04-07 10:15:56 -04001790 ndlp->nlp_DID = keepDID;
James Smart49382502017-11-20 16:00:38 -08001791 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smartcff261f2013-12-17 20:29:47 -05001792 if (phba->sli_rev == LPFC_SLI_REV4 &&
1793 active_rrqs_xri_bitmap)
1794 memcpy(ndlp->active_rrqs_xri_bitmap,
1795 active_rrqs_xri_bitmap,
1796 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001797
James Smart307e3382020-11-15 11:26:30 -08001798 } else {
James Smart34f5ad82012-08-03 12:35:03 -04001799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1800 "3180 PLOGI confirm SWAP: %x %x\n",
1801 new_ndlp->nlp_DID, keepDID);
1802
James Smart2e0fef82007-06-17 19:56:36 -05001803 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001804
James Smart92ea83a2018-11-29 16:09:34 -08001805 /* Two ndlps cannot have the same did and the fc4
1806 * type must be transferred because the ndlp is in
1807 * flight.
1808 */
James Smart58da1ff2008-04-07 10:15:56 -04001809 ndlp->nlp_DID = keepDID;
James Smart92ea83a2018-11-29 16:09:34 -08001810 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1811
James Smartcff261f2013-12-17 20:29:47 -05001812 if (phba->sli_rev == LPFC_SLI_REV4 &&
1813 active_rrqs_xri_bitmap)
1814 memcpy(ndlp->active_rrqs_xri_bitmap,
1815 active_rrqs_xri_bitmap,
1816 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001817
James Smart953ceed2015-05-22 10:42:37 -04001818 /* Since we are switching over to the new_ndlp,
1819 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001820 */
1821 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1822 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001823 keep_nlp_state = NLP_STE_NPR_NODE;
1824 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
Dick Kennedy4adc0412017-08-23 16:55:37 -07001825 ndlp->nrport = keep_nrport;
James Smart92795652006-07-06 15:50:02 -04001826 }
James Smart307e3382020-11-15 11:26:30 -08001827
1828 /*
1829 * If ndlp is not associated with any rport we can drop it here else
1830 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1831 */
1832 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1833 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1834
James Smartcff261f2013-12-17 20:29:47 -05001835 if (phba->sli_rev == LPFC_SLI_REV4 &&
1836 active_rrqs_xri_bitmap)
1837 mempool_free(active_rrqs_xri_bitmap,
1838 phba->active_rrq_pool);
James Smartd83ca3e2018-10-23 13:41:09 -07001839
1840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1841 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1842 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1843 new_ndlp->nlp_fc4_type);
1844
James Smart488d1462006-03-07 15:02:37 -05001845 return new_ndlp;
1846}
1847
James Smarte59058c2008-08-24 21:49:00 -04001848/**
James Smart3621a712009-04-06 18:47:14 -04001849 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001850 * @vport: pointer to a host virtual N_Port data structure.
1851 *
1852 * This routine checks whether more Registration State Change
1853 * Notifications (RSCNs) came in while the discovery state machine was in
1854 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1855 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1856 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1857 * handling the RSCNs.
1858 **/
James Smart87af33f2007-10-27 13:37:43 -04001859void
1860lpfc_end_rscn(struct lpfc_vport *vport)
1861{
1862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1863
1864 if (vport->fc_flag & FC_RSCN_MODE) {
1865 /*
1866 * Check to see if more RSCNs came in while we were
1867 * processing this one.
1868 */
1869 if (vport->fc_rscn_id_cnt ||
1870 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1871 lpfc_els_handle_rscn(vport);
1872 else {
1873 spin_lock_irq(shost->host_lock);
1874 vport->fc_flag &= ~FC_RSCN_MODE;
1875 spin_unlock_irq(shost->host_lock);
1876 }
1877 }
1878}
1879
James Smarte59058c2008-08-24 21:49:00 -04001880/**
James Smart19ca7602010-11-20 23:11:55 -05001881 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1882 * @phba: pointer to lpfc hba data structure.
1883 * @cmdiocb: pointer to lpfc command iocb data structure.
1884 * @rspiocb: pointer to lpfc response iocb data structure.
1885 *
1886 * This routine will call the clear rrq function to free the rrq and
1887 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1888 * exist then the clear_rrq is still called because the rrq needs to
1889 * be freed.
1890 **/
1891
1892static void
1893lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1894 struct lpfc_iocbq *rspiocb)
1895{
1896 struct lpfc_vport *vport = cmdiocb->vport;
1897 IOCB_t *irsp;
James Smart2693f5d2021-03-01 09:18:03 -08001898 struct lpfc_nodelist *ndlp = cmdiocb->context1;
James Smart19ca7602010-11-20 23:11:55 -05001899 struct lpfc_node_rrq *rrq;
1900
1901 /* we pass cmdiocb to state machine which needs rspiocb as well */
1902 rrq = cmdiocb->context_un.rrq;
1903 cmdiocb->context_un.rsp_iocb = rspiocb;
1904
1905 irsp = &rspiocb->iocb;
1906 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1907 "RRQ cmpl: status:x%x/x%x did:x%x",
1908 irsp->ulpStatus, irsp->un.ulpWord[4],
1909 irsp->un.elsreq64.remoteID);
1910
James Smart19ca7602010-11-20 23:11:55 -05001911 /* rrq completes to NPort <nlp_DID> */
1912 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart2693f5d2021-03-01 09:18:03 -08001913 "2880 RRQ completes to DID x%x "
James Smart19ca7602010-11-20 23:11:55 -05001914 "Data: x%x x%x x%x x%x x%x\n",
James Smart2693f5d2021-03-01 09:18:03 -08001915 irsp->un.elsreq64.remoteID,
1916 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart19ca7602010-11-20 23:11:55 -05001917 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1918
1919 if (irsp->ulpStatus) {
1920 /* Check for retry */
1921 /* RRQ failed Don't print the vport to vport rjts */
1922 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1923 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1924 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1925 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07001926 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1927 "2881 RRQ failure DID:%06X Status:"
1928 "x%x/x%x\n",
1929 ndlp->nlp_DID, irsp->ulpStatus,
1930 irsp->un.ulpWord[4]);
James Smart19ca7602010-11-20 23:11:55 -05001931 }
James Smart4430f7f2020-11-15 11:26:31 -08001932
James Smart2693f5d2021-03-01 09:18:03 -08001933 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
James Smart19ca7602010-11-20 23:11:55 -05001934 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001935 lpfc_nlp_put(ndlp);
James Smart19ca7602010-11-20 23:11:55 -05001936 return;
1937}
1938/**
James Smart3621a712009-04-06 18:47:14 -04001939 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001940 * @phba: pointer to lpfc hba data structure.
1941 * @cmdiocb: pointer to lpfc command iocb data structure.
1942 * @rspiocb: pointer to lpfc response iocb data structure.
1943 *
1944 * This routine is the completion callback function for issuing the Port
1945 * Login (PLOGI) command. For PLOGI completion, there must be an active
1946 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001947 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001948 * ignored and command IOCB released. The PLOGI response IOCB status is
Bhaskar Chowdhuryf1891f92021-03-24 12:18:29 +05301949 * checked for error conditions. If there is error status reported, PLOGI
James Smarte59058c2008-08-24 21:49:00 -04001950 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1951 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1952 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1953 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1954 * there are additional N_Port nodes with the vport that need to perform
1955 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1956 * PLOGIs.
1957 **/
dea31012005-04-17 16:05:31 -05001958static void
James Smart2e0fef82007-06-17 19:56:36 -05001959lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1960 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001961{
James Smart2e0fef82007-06-17 19:56:36 -05001962 struct lpfc_vport *vport = cmdiocb->vport;
1963 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001964 IOCB_t *irsp;
James Smart4430f7f2020-11-15 11:26:31 -08001965 struct lpfc_nodelist *ndlp, *free_ndlp;
James Smart92795652006-07-06 15:50:02 -04001966 struct lpfc_dmabuf *prsp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07001967 int disc;
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05301968 struct serv_parm *sp = NULL;
dea31012005-04-17 16:05:31 -05001969
dea31012005-04-17 16:05:31 -05001970 /* we pass cmdiocb to state machine which needs rspiocb as well */
1971 cmdiocb->context_un.rsp_iocb = rspiocb;
1972
1973 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1975 "PLOGI cmpl: status:x%x/x%x did:x%x",
1976 irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->un.elsreq64.remoteID);
1978
James Smart2e0fef82007-06-17 19:56:36 -05001979 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart307e3382020-11-15 11:26:30 -08001980 if (!ndlp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001981 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001982 "0136 PLOGI completes to NPort x%x "
1983 "with no ndlp. Data: x%x x%x x%x\n",
1984 irsp->un.elsreq64.remoteID,
1985 irsp->ulpStatus, irsp->un.ulpWord[4],
1986 irsp->ulpIoTag);
James Smart9d8de4412020-11-30 10:12:26 -08001987 goto out_freeiocb;
James Smarted957682007-06-17 19:56:37 -05001988 }
dea31012005-04-17 16:05:31 -05001989
1990 /* Since ndlp can be freed in the disc state machine, note if this node
1991 * is being used during discovery.
1992 */
James Smartc6adba12020-11-15 11:26:34 -08001993 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001994 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001995 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08001996 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001997
1998 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001999 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002000 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002001 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08002002 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2003 irsp->ulpStatus, irsp->un.ulpWord[4],
2004 disc, vport->num_disc_nodes);
2005
dea31012005-04-17 16:05:31 -05002006 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002007 if (lpfc_els_chk_latt(vport)) {
James Smartc6adba12020-11-15 11:26:34 -08002008 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002009 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002010 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002011 goto out;
2012 }
2013
dea31012005-04-17 16:05:31 -05002014 if (irsp->ulpStatus) {
2015 /* Check for retry */
2016 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2017 /* ELS command is being retried */
2018 if (disc) {
James Smartc6adba12020-11-15 11:26:34 -08002019 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002020 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002021 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002022 }
2023 goto out;
2024 }
James Smart2a9bf3d2010-06-07 15:24:45 -04002025 /* PLOGI failed Don't print the vport to vport rjts */
2026 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2027 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2028 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2029 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07002030 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05002031 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2032 ndlp->nlp_DID, irsp->ulpStatus,
2033 irsp->un.ulpWord[4]);
James Smart52edb2c2020-11-15 11:26:35 -08002034
2035 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smartc65436b2021-07-07 11:43:47 -07002036 if (!lpfc_error_lost_link(irsp))
James Smart52edb2c2020-11-15 11:26:35 -08002037 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2038 NLP_EVT_CMPL_PLOGI);
2039
James Smart4012bae2021-05-14 12:55:53 -07002040 /* If a PLOGI collision occurred, the node needs to continue
2041 * with the reglogin process.
2042 */
2043 spin_lock_irq(&ndlp->lock);
2044 if ((ndlp->nlp_flag & (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI)) &&
2045 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
2046 spin_unlock_irq(&ndlp->lock);
2047 goto out;
2048 }
2049 spin_unlock_irq(&ndlp->lock);
2050
2051 /* No PLOGI collision and the node is not registered with the
2052 * scsi or nvme transport. It is no longer an active node. Just
2053 * start the device remove process.
James Smarte9b11082020-11-15 11:26:33 -08002054 */
James Smart52edb2c2020-11-15 11:26:35 -08002055 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2056 spin_lock_irq(&ndlp->lock);
2057 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2058 spin_unlock_irq(&ndlp->lock);
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002059 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smarte9b11082020-11-15 11:26:33 -08002060 NLP_EVT_DEVICE_RM);
James Smart52edb2c2020-11-15 11:26:35 -08002061 }
dea31012005-04-17 16:05:31 -05002062 } else {
2063 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04002064 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05002065 cmdiocb->context2)->list.next,
2066 struct lpfc_dmabuf, list);
2067 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05302068
2069 sp = (struct serv_parm *)((u8 *)prsp->virt +
2070 sizeof(u32));
2071
2072 ndlp->vmid_support = 0;
2073 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2074 (phba->cfg_vmid_priority_tagging &&
2075 sp->cmn.priority_tagging)) {
2076 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2077 "4018 app_hdr_support %d tagging %d DID x%x\n",
2078 sp->cmn.app_hdr_support,
2079 sp->cmn.priority_tagging,
2080 ndlp->nlp_DID);
2081 /* if the dest port supports VMID, mark it in ndlp */
2082 ndlp->vmid_support = 1;
2083 }
2084
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002085 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smarte9b11082020-11-15 11:26:33 -08002086 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002087 }
2088
James Smart2e0fef82007-06-17 19:56:36 -05002089 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05002090 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002091 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05002092
James Smart2e0fef82007-06-17 19:56:36 -05002093 if (vport->num_disc_nodes == 0) {
2094 spin_lock_irq(shost->host_lock);
2095 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2096 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002097
James Smart2e0fef82007-06-17 19:56:36 -05002098 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04002099 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05002100 }
2101 }
2102
2103out:
James Smart4430f7f2020-11-15 11:26:31 -08002104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2105 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2106 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2107
James Smart9d8de4412020-11-30 10:12:26 -08002108out_freeiocb:
James Smart4430f7f2020-11-15 11:26:31 -08002109 /* Release the reference on the original I/O request. */
2110 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2111
dea31012005-04-17 16:05:31 -05002112 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002113 lpfc_nlp_put(free_ndlp);
dea31012005-04-17 16:05:31 -05002114 return;
2115}
2116
James Smarte59058c2008-08-24 21:49:00 -04002117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002119 * @vport: pointer to a host virtual N_Port data structure.
2120 * @did: destination port identifier.
2121 * @retry: number of retries to the command IOCB.
2122 *
2123 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2124 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2125 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
James Smart8dd1c122021-03-01 09:18:08 -08002126 * This routine constructs the proper fields of the PLOGI IOCB and invokes
James Smarte59058c2008-08-24 21:49:00 -04002127 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2128 *
James Smart8dd1c122021-03-01 09:18:08 -08002129 * Note that the ndlp reference count will be incremented by 1 for holding
2130 * the ndlp and the reference to ndlp will be stored into the context1 field
2131 * of the IOCB for the completion callback function to the PLOGI ELS command.
James Smarte59058c2008-08-24 21:49:00 -04002132 *
2133 * Return code
2134 * 0 - Successfully issued a plogi for @vport
2135 * 1 - failed to issue a plogi for @vport
2136 **/
dea31012005-04-17 16:05:31 -05002137int
James Smart2e0fef82007-06-17 19:56:36 -05002138lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05002139{
James Smart2e0fef82007-06-17 19:56:36 -05002140 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002141 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04002142 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002143 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002144 uint8_t *pcmd;
2145 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002146 int ret;
dea31012005-04-17 16:05:31 -05002147
James Smart98c9ea52007-10-27 13:37:33 -04002148 ndlp = lpfc_findnode_did(vport, did);
James Smart8dd1c122021-03-01 09:18:08 -08002149 if (!ndlp)
2150 return 1;
James Smartdea16bd2018-11-29 16:09:30 -08002151
James Smart8dd1c122021-03-01 09:18:08 -08002152 /* Defer the processing of the issue PLOGI until after the
2153 * outstanding UNREG_RPI mbox command completes, unless we
2154 * are going offline. This logic does not apply for Fabric DIDs
2155 */
2156 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2157 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2158 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2159 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2160 "4110 Issue PLOGI x%x deferred "
2161 "on NPort x%x rpi x%x Data: x%px\n",
2162 ndlp->nlp_defer_did, ndlp->nlp_DID,
2163 ndlp->nlp_rpi, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08002164
James Smart8dd1c122021-03-01 09:18:08 -08002165 /* We can only defer 1st PLOGI */
2166 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2167 ndlp->nlp_defer_did = did;
2168 return 0;
James Smartdea16bd2018-11-29 16:09:30 -08002169 }
James Smart98c9ea52007-10-27 13:37:33 -04002170
James Smart92d7f7b2007-06-17 19:56:38 -05002171 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002172 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002173 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002174 if (!elsiocb)
2175 return 1;
dea31012005-04-17 16:05:31 -05002176
James Smartc6adba12020-11-15 11:26:34 -08002177 spin_lock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002178 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
James Smartc6adba12020-11-15 11:26:34 -08002179 spin_unlock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002180
dea31012005-04-17 16:05:31 -05002181 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2182
2183 /* For PLOGI request, remainder of payload is service parameters */
2184 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002185 pcmd += sizeof(uint32_t);
2186 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002187 sp = (struct serv_parm *) pcmd;
2188
James Smart5ac6b302010-10-22 11:05:36 -04002189 /*
2190 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2191 * to device on remote loops work.
2192 */
2193 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2194 sp->cmn.altBbCredit = 1;
2195
dea31012005-04-17 16:05:31 -05002196 if (sp->cmn.fcphLow < FC_PH_4_3)
2197 sp->cmn.fcphLow = FC_PH_4_3;
2198
2199 if (sp->cmn.fcphHigh < FC_PH3)
2200 sp->cmn.fcphHigh = FC_PH3;
2201
James Smarte0165f22016-12-19 15:07:20 -08002202 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002203 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002204 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002205
Gaurav Srivastava7e473de2021-06-08 10:05:50 +05302206 /* Check if the destination port supports VMID */
2207 ndlp->vmid_support = 0;
2208 if (vport->vmid_priority_tagging)
2209 sp->cmn.priority_tagging = 1;
2210 else if (phba->cfg_vmid_app_header &&
2211 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2212 sp->cmn.app_hdr_support = 1;
2213
James Smart858c9f62007-06-17 19:56:39 -05002214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2215 "Issue PLOGI: did:x%x",
2216 did, 0, 0);
2217
James Smart8c258642017-02-12 13:52:36 -08002218 /* If our firmware supports this feature, convey that
2219 * information to the target using the vendor specific field.
2220 */
2221 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2222 sp->cmn.valid_vendor_ver_level = 1;
2223 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2224 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2225 }
2226
dea31012005-04-17 16:05:31 -05002227 phba->fc_stat.elsXmitPLOGI++;
2228 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05002229
James Smart4430f7f2020-11-15 11:26:31 -08002230 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2231 "Issue PLOGI: did:x%x refcnt %d",
2232 did, kref_read(&ndlp->kref), 0);
2233 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08002234 if (!elsiocb->context1) {
2235 lpfc_els_free_iocb(phba, elsiocb);
2236 return 1;
2237 }
James Smart4430f7f2020-11-15 11:26:31 -08002238
2239 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2240 if (ret) {
James Smart8e9a3252021-03-01 09:18:09 -08002241 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002242 lpfc_nlp_put(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08002243 return 1;
dea31012005-04-17 16:05:31 -05002244 }
James Smart4430f7f2020-11-15 11:26:31 -08002245
James Smart8e9a3252021-03-01 09:18:09 -08002246 return 0;
dea31012005-04-17 16:05:31 -05002247}
2248
James Smarte59058c2008-08-24 21:49:00 -04002249/**
James Smart3621a712009-04-06 18:47:14 -04002250 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002251 * @phba: pointer to lpfc hba data structure.
2252 * @cmdiocb: pointer to lpfc command iocb data structure.
2253 * @rspiocb: pointer to lpfc response iocb data structure.
2254 *
2255 * This routine is the completion callback function for a Process Login
2256 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2257 * status. If there is error status reported, PRLI retry shall be attempted
2258 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2259 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2260 * ndlp to mark the PRLI completion.
2261 **/
dea31012005-04-17 16:05:31 -05002262static void
James Smart2e0fef82007-06-17 19:56:36 -05002263lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2264 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002265{
James Smart2e0fef82007-06-17 19:56:36 -05002266 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002267 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002268 struct lpfc_nodelist *ndlp;
James Smart2332e6e2019-11-04 16:57:01 -08002269 char *mode;
Dick Kennedy372c1872020-06-30 14:50:00 -07002270 u32 loglevel;
dea31012005-04-17 16:05:31 -05002271
dea31012005-04-17 16:05:31 -05002272 /* we pass cmdiocb to state machine which needs rspiocb as well */
2273 cmdiocb->context_un.rsp_iocb = rspiocb;
2274
2275 irsp = &(rspiocb->iocb);
2276 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smartc6adba12020-11-15 11:26:34 -08002277 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002278 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002279
2280 /* Driver supports multiple FC4 types. Counters matter. */
2281 vport->fc_prli_sent--;
2282 ndlp->fc4_prli_sent--;
James Smartc6adba12020-11-15 11:26:34 -08002283 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002284
James Smart858c9f62007-06-17 19:56:39 -05002285 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2286 "PRLI cmpl: status:x%x/x%x did:x%x",
2287 irsp->ulpStatus, irsp->un.ulpWord[4],
2288 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002289
dea31012005-04-17 16:05:31 -05002290 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002291 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002292 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002293 "Data: x%x x%x x%x x%x\n",
2294 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002295 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002296
dea31012005-04-17 16:05:31 -05002297 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002298 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002299 goto out;
2300
2301 if (irsp->ulpStatus) {
2302 /* Check for retry */
2303 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2304 /* ELS command is being retried */
2305 goto out;
2306 }
James Smart31200462017-05-15 15:20:42 -07002307
James Smart2332e6e2019-11-04 16:57:01 -08002308 /* If we don't send GFT_ID to Fabric, a PRLI error
2309 * could be expected.
2310 */
2311 if ((vport->fc_flag & FC_FABRIC) ||
Dick Kennedy372c1872020-06-30 14:50:00 -07002312 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
James Smart2332e6e2019-11-04 16:57:01 -08002313 mode = KERN_ERR;
Dick Kennedy372c1872020-06-30 14:50:00 -07002314 loglevel = LOG_TRACE_EVENT;
2315 } else {
James Smart2332e6e2019-11-04 16:57:01 -08002316 mode = KERN_INFO;
Dick Kennedy372c1872020-06-30 14:50:00 -07002317 loglevel = LOG_ELS;
2318 }
James Smart2332e6e2019-11-04 16:57:01 -08002319
dea31012005-04-17 16:05:31 -05002320 /* PRLI failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002321 lpfc_printf_vlog(vport, mode, loglevel,
James Smart31200462017-05-15 15:20:42 -07002322 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2323 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002324 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002325 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2326
dea31012005-04-17 16:05:31 -05002327 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart4e76d4a2021-04-11 18:31:16 -07002328 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002329 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002330 NLP_EVT_CMPL_PRLI);
James Smart52edb2c2020-11-15 11:26:35 -08002331
James Smarta864ee72021-09-10 16:31:51 -07002332 /*
2333 * For P2P topology, retain the node so that PLOGI can be
2334 * attempted on it again.
2335 */
2336 if (vport->fc_flag & FC_PT2PT)
2337 goto out;
2338
James Smart52edb2c2020-11-15 11:26:35 -08002339 /* As long as this node is not registered with the SCSI
2340 * or NVMe transport and no other PRLIs are outstanding,
2341 * it is no longer an active node. Otherwise devloss
2342 * handles the final cleanup.
2343 */
2344 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2345 !ndlp->fc4_prli_sent) {
2346 spin_lock_irq(&ndlp->lock);
2347 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2348 spin_unlock_irq(&ndlp->lock);
2349 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2350 NLP_EVT_DEVICE_RM);
2351 }
James Smartdea16bd2018-11-29 16:09:30 -08002352 } else {
James Smarta0f2d3e2017-02-12 13:52:31 -08002353 /* Good status, call state machine. However, if another
2354 * PRLI is outstanding, don't call the state machine
2355 * because final disposition to Mapped or Unmapped is
2356 * completed there.
2357 */
James Smart2e0fef82007-06-17 19:56:36 -05002358 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002359 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002360 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002361
dea31012005-04-17 16:05:31 -05002362out:
2363 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002364 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002365 return;
2366}
2367
James Smarte59058c2008-08-24 21:49:00 -04002368/**
James Smart3621a712009-04-06 18:47:14 -04002369 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002370 * @vport: pointer to a host virtual N_Port data structure.
2371 * @ndlp: pointer to a node-list data structure.
2372 * @retry: number of retries to the command IOCB.
2373 *
2374 * This routine issues a Process Login (PRLI) ELS command for the
2375 * @vport. The PRLI service parameters are set up in the payload of the
2376 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2377 * is put to the IOCB completion callback func field before invoking the
2378 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2379 *
James Smart69b8eff2021-03-01 09:18:19 -08002380 * Note that the ndlp reference count will be incremented by 1 for holding the
2381 * ndlp and the reference to ndlp will be stored into the context1 field of
2382 * the IOCB for the completion callback function to the PRLI ELS command.
James Smarte59058c2008-08-24 21:49:00 -04002383 *
2384 * Return code
2385 * 0 - successfully issued prli iocb command for @vport
2386 * 1 - failed to issue prli iocb command for @vport
2387 **/
dea31012005-04-17 16:05:31 -05002388int
James Smart2e0fef82007-06-17 19:56:36 -05002389lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002390 uint8_t retry)
2391{
James Smart4430f7f2020-11-15 11:26:31 -08002392 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002393 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002394 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002395 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002396 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002397 uint8_t *pcmd;
2398 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002399 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002400
Dick Kennedy991f0c02017-08-23 16:55:39 -07002401 /*
2402 * If we are in RSCN mode, the FC4 types supported from a
2403 * previous GFT_ID command may not be accurate. So, if we
2404 * are a NVME Initiator, always look for the possibility of
2405 * the remote NPort beng a NVME Target.
2406 */
2407 if (phba->sli_rev == LPFC_SLI_REV4 &&
2408 vport->fc_flag & FC_RSCN_MODE &&
2409 vport->nvmei_support)
2410 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002411 local_nlp_type = ndlp->nlp_fc4_type;
2412
James Smart9de416a2017-12-08 17:18:07 -08002413 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2414 * fields here before any of them can complete.
2415 */
2416 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2417 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2418 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smartdea16bd2018-11-29 16:09:30 -08002419 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
James Smart9de416a2017-12-08 17:18:07 -08002420 ndlp->nvme_fb_size = 0;
2421
James Smarta0f2d3e2017-02-12 13:52:31 -08002422 send_next_prli:
2423 if (local_nlp_type & NLP_FC4_FCP) {
2424 /* Payload is 4 + 16 = 20 x14 bytes. */
2425 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2426 elscmd = ELS_CMD_PRLI;
2427 } else if (local_nlp_type & NLP_FC4_NVME) {
2428 /* Payload is 4 + 20 = 24 x18 bytes. */
2429 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2430 elscmd = ELS_CMD_NVMEPRLI;
2431 } else {
2432 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2433 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2434 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2435 return 1;
2436 }
James Smart09559e82017-06-15 22:56:46 -07002437
2438 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2439 * FC4 type, implicitly LOGO.
2440 */
2441 if (phba->sli_rev == LPFC_SLI_REV3 &&
2442 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2443 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2444 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2445 ndlp->nlp_type);
2446 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2447 return 1;
2448 }
2449
James Smart2e0fef82007-06-17 19:56:36 -05002450 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002451 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002452 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002453 return 1;
dea31012005-04-17 16:05:31 -05002454
dea31012005-04-17 16:05:31 -05002455 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2456
2457 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002458 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002459
James Smarta0f2d3e2017-02-12 13:52:31 -08002460 if (local_nlp_type & NLP_FC4_FCP) {
2461 /* Remainder of payload is FCP PRLI parameter page.
2462 * Note: this data structure is defined as
2463 * BE/LE in the structure definition so no
2464 * byte swap call is made.
2465 */
2466 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2467 pcmd += sizeof(uint32_t);
2468 npr = (PRLI *)pcmd;
2469
2470 /*
2471 * If our firmware version is 3.20 or later,
2472 * set the following bits for FC-TAPE support.
2473 */
2474 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2475 npr->ConfmComplAllowed = 1;
2476 npr->Retry = 1;
2477 npr->TaskRetryIdReq = 1;
2478 }
2479 npr->estabImagePair = 1;
2480 npr->readXferRdyDis = 1;
2481 if (vport->cfg_first_burst_size)
2482 npr->writeXferRdyDis = 1;
2483
2484 /* For FCP support */
2485 npr->prliType = PRLI_FCP_TYPE;
2486 npr->initiatorFunc = 1;
2487 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2488
2489 /* Remove FCP type - processed. */
2490 local_nlp_type &= ~NLP_FC4_FCP;
2491 } else if (local_nlp_type & NLP_FC4_NVME) {
2492 /* Remainder of payload is NVME PRLI parameter page.
2493 * This data structure is the newer definition that
2494 * uses bf macros so a byte swap is required.
2495 */
2496 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2497 pcmd += sizeof(uint32_t);
2498 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2499 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2500 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
James Smart0d8af092019-08-14 16:57:10 -07002501 if (phba->nsler) {
2502 bf_set(prli_nsler, npr_nvme, 1);
2503 bf_set(prli_conf, npr_nvme, 1);
2504 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002505
2506 /* Only initiators request first burst. */
2507 if ((phba->cfg_nvme_enable_fb) &&
2508 !phba->nvmet_support)
2509 bf_set(prli_fba, npr_nvme, 1);
2510
James Smart8c258642017-02-12 13:52:36 -08002511 if (phba->nvmet_support) {
2512 bf_set(prli_tgt, npr_nvme, 1);
2513 bf_set(prli_disc, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002514 } else {
2515 bf_set(prli_init, npr_nvme, 1);
James Smarta5ff0682018-01-30 15:58:56 -08002516 bf_set(prli_conf, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002517 }
James Smarta5ff0682018-01-30 15:58:56 -08002518
James Smarta0f2d3e2017-02-12 13:52:31 -08002519 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2520 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2521 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2522
2523 /* Remove NVME type - processed. */
2524 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002525 }
dea31012005-04-17 16:05:31 -05002526
2527 phba->fc_stat.elsXmitPRLI++;
2528 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smartc6adba12020-11-15 11:26:34 -08002529 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002530 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002531
2532 /* The vport counters are used for lpfc_scan_finished, but
2533 * the ndlp is used to track outstanding PRLIs for different
2534 * FC4 types.
2535 */
2536 vport->fc_prli_sent++;
2537 ndlp->fc4_prli_sent++;
James Smartc6adba12020-11-15 11:26:34 -08002538 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002539
2540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2541 "Issue PRLI: did:x%x refcnt %d",
2542 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2543 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08002544 if (!elsiocb->context1) {
2545 lpfc_els_free_iocb(phba, elsiocb);
2546 goto err;
2547 }
James Smart4430f7f2020-11-15 11:26:31 -08002548
2549 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08002550 if (rc == IOCB_ERROR) {
2551 lpfc_els_free_iocb(phba, elsiocb);
2552 lpfc_nlp_put(ndlp);
2553 goto err;
2554 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002555
James Smarta0f2d3e2017-02-12 13:52:31 -08002556
2557 /* The driver supports 2 FC4 types. Make sure
2558 * a PRLI is issued for all types before exiting.
2559 */
James Smart09559e82017-06-15 22:56:46 -07002560 if (phba->sli_rev == LPFC_SLI_REV4 &&
2561 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002562 goto send_next_prli;
James Smart4430f7f2020-11-15 11:26:31 -08002563 else
2564 return 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002565
James Smart8e9a3252021-03-01 09:18:09 -08002566err:
James Smartc6adba12020-11-15 11:26:34 -08002567 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002568 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smartc6adba12020-11-15 11:26:34 -08002569 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002570 return 1;
dea31012005-04-17 16:05:31 -05002571}
2572
James Smarte59058c2008-08-24 21:49:00 -04002573/**
James Smart3621a712009-04-06 18:47:14 -04002574 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002575 * @vport: pointer to a host virtual N_Port data structure.
2576 *
2577 * This routine performs Registration State Change Notification (RSCN)
2578 * discovery for a @vport. If the @vport's node port recovery count is not
2579 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2580 * the nodes that need recovery. If none of the PLOGI were needed through
2581 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2582 * invoked to check and handle possible more RSCN came in during the period
2583 * of processing the current ones.
2584 **/
2585static void
2586lpfc_rscn_disc(struct lpfc_vport *vport)
2587{
2588 lpfc_can_disctmo(vport);
2589
2590 /* RSCN discovery */
2591 /* go thru NPR nodes and issue ELS PLOGIs */
2592 if (vport->fc_npr_cnt)
2593 if (lpfc_els_disc_plogi(vport))
2594 return;
2595
2596 lpfc_end_rscn(vport);
2597}
2598
2599/**
James Smart3621a712009-04-06 18:47:14 -04002600 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002601 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2602 *
2603 * This function is called when the final ADISC is completed during discovery.
2604 * This function handles clearing link attention or issuing reg_vpi depending
2605 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2606 * discovery.
2607 * This function is called with no locks held.
2608 **/
2609static void
2610lpfc_adisc_done(struct lpfc_vport *vport)
2611{
2612 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2613 struct lpfc_hba *phba = vport->phba;
2614
2615 /*
2616 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2617 * and continue discovery.
2618 */
2619 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002620 !(vport->fc_flag & FC_RSCN_MODE) &&
2621 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart02607fb2021-07-07 11:43:48 -07002622
2623 /*
2624 * If link is down, clear_la and reg_vpi will be done after
2625 * flogi following a link up event
2626 */
2627 if (!lpfc_is_link_up(phba))
2628 return;
2629
James Smartd454c912014-12-30 12:08:58 -05002630 /* The ADISCs are complete. Doesn't matter if they
2631 * succeeded or failed because the ADISC completion
2632 * routine guarantees to call the state machine and
2633 * the RPI is either unregistered (failed ADISC response)
2634 * or the RPI is still valid and the node is marked
2635 * mapped for a target. The exchanges should be in the
2636 * correct state. This code is specific to SLI3.
2637 */
2638 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002639 lpfc_issue_reg_vpi(phba, vport);
2640 return;
2641 }
2642 /*
2643 * For SLI2, we need to set port_state to READY
2644 * and continue discovery.
2645 */
2646 if (vport->port_state < LPFC_VPORT_READY) {
2647 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002648 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002649 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2650 vport->num_disc_nodes = 0;
2651 /* go thru NPR list, issue ELS PLOGIs */
2652 if (vport->fc_npr_cnt)
2653 lpfc_els_disc_plogi(vport);
2654 if (!vport->num_disc_nodes) {
2655 spin_lock_irq(shost->host_lock);
2656 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2657 spin_unlock_irq(shost->host_lock);
2658 lpfc_can_disctmo(vport);
2659 lpfc_end_rscn(vport);
2660 }
2661 }
2662 vport->port_state = LPFC_VPORT_READY;
2663 } else
2664 lpfc_rscn_disc(vport);
2665}
2666
2667/**
James Smart3621a712009-04-06 18:47:14 -04002668 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002669 * @vport: pointer to a host virtual N_Port data structure.
2670 *
2671 * This routine determines whether there are more ndlps on a @vport
2672 * node list need to have Address Discover (ADISC) issued. If so, it will
2673 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2674 * remaining nodes which need to have ADISC sent.
2675 **/
James Smart0ff10d42008-01-11 01:52:36 -05002676void
James Smart2e0fef82007-06-17 19:56:36 -05002677lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002678{
James Smart2e0fef82007-06-17 19:56:36 -05002679 if (vport->num_disc_nodes)
2680 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002681 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2683 "0210 Continue discovery with %d ADISCs to go "
2684 "Data: x%x x%x x%x\n",
2685 vport->num_disc_nodes, vport->fc_adisc_cnt,
2686 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002687 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002688 if (vport->fc_flag & FC_NLP_MORE) {
2689 lpfc_set_disctmo(vport);
2690 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002691 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002692 }
James Smart90160e02008-08-24 21:49:45 -04002693 if (!vport->num_disc_nodes)
2694 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002695 return;
2696}
2697
James Smarte59058c2008-08-24 21:49:00 -04002698/**
James Smart3621a712009-04-06 18:47:14 -04002699 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002700 * @phba: pointer to lpfc hba data structure.
2701 * @cmdiocb: pointer to lpfc command iocb data structure.
2702 * @rspiocb: pointer to lpfc response iocb data structure.
2703 *
2704 * This routine is the completion function for issuing the Address Discover
2705 * (ADISC) command. It first checks to see whether link went down during
2706 * the discovery process. If so, the node will be marked as node port
2707 * recovery for issuing discover IOCB by the link attention handler and
2708 * exit. Otherwise, the response status is checked. If error was reported
2709 * in the response status, the ADISC command shall be retried by invoking
2710 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2711 * the response status, the state machine is invoked to set transition
2712 * with respect to NLP_EVT_CMPL_ADISC event.
2713 **/
dea31012005-04-17 16:05:31 -05002714static void
James Smart2e0fef82007-06-17 19:56:36 -05002715lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2716 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002717{
James Smart2e0fef82007-06-17 19:56:36 -05002718 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002719 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002720 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002721 int disc;
dea31012005-04-17 16:05:31 -05002722
2723 /* we pass cmdiocb to state machine which needs rspiocb as well */
2724 cmdiocb->context_un.rsp_iocb = rspiocb;
2725
2726 irsp = &(rspiocb->iocb);
2727 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002728
James Smart858c9f62007-06-17 19:56:39 -05002729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2730 "ADISC cmpl: status:x%x/x%x did:x%x",
2731 irsp->ulpStatus, irsp->un.ulpWord[4],
2732 ndlp->nlp_DID);
2733
dea31012005-04-17 16:05:31 -05002734 /* Since ndlp can be freed in the disc state machine, note if this node
2735 * is being used during discovery.
2736 */
James Smartc6adba12020-11-15 11:26:34 -08002737 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002738 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002739 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smartc6adba12020-11-15 11:26:34 -08002740 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002741 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002742 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2743 "0104 ADISC completes to NPort x%x "
2744 "Data: x%x x%x x%x x%x x%x\n",
2745 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2746 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002747 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002748 if (lpfc_els_chk_latt(vport)) {
James Smartc6adba12020-11-15 11:26:34 -08002749 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002750 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002751 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002752 goto out;
2753 }
2754
2755 if (irsp->ulpStatus) {
2756 /* Check for retry */
2757 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2758 /* ELS command is being retried */
2759 if (disc) {
James Smartc6adba12020-11-15 11:26:34 -08002760 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002761 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002762 spin_unlock_irq(&ndlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05002763 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002764 }
2765 goto out;
2766 }
2767 /* ADISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002768 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05002769 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2770 ndlp->nlp_DID, irsp->ulpStatus,
2771 irsp->un.ulpWord[4]);
James Smartc65436b2021-07-07 11:43:47 -07002772
2773 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2774 NLP_EVT_CMPL_ADISC);
James Smart52edb2c2020-11-15 11:26:35 -08002775
2776 /* As long as this node is not registered with the SCSI or NVMe
2777 * transport, it is no longer an active node. Otherwise
2778 * devloss handles the final cleanup.
2779 */
2780 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2781 spin_lock_irq(&ndlp->lock);
2782 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2783 spin_unlock_irq(&ndlp->lock);
2784 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2785 NLP_EVT_DEVICE_RM);
2786 }
James Smarte47c9092008-02-08 18:49:26 -05002787 } else
dea31012005-04-17 16:05:31 -05002788 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002789 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002790 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002791
James Smart90160e02008-08-24 21:49:45 -04002792 /* Check to see if there are more ADISCs to be sent */
2793 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002794 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002795out:
2796 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002797 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002798 return;
2799}
2800
James Smarte59058c2008-08-24 21:49:00 -04002801/**
James Smart3621a712009-04-06 18:47:14 -04002802 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002803 * @vport: pointer to a virtual N_Port data structure.
2804 * @ndlp: pointer to a node-list data structure.
2805 * @retry: number of retries to the command IOCB.
2806 *
2807 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2808 * @vport. It prepares the payload of the ADISC ELS command, updates the
2809 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2810 * to issue the ADISC ELS command.
2811 *
James Smart69b8eff2021-03-01 09:18:19 -08002812 * Note that the ndlp reference count will be incremented by 1 for holding the
2813 * ndlp and the reference to ndlp will be stored into the context1 field of
2814 * the IOCB for the completion callback function to the ADISC ELS command.
James Smarte59058c2008-08-24 21:49:00 -04002815 *
2816 * Return code
2817 * 0 - successfully issued adisc
2818 * 1 - failed to issue adisc
2819 **/
dea31012005-04-17 16:05:31 -05002820int
James Smart2e0fef82007-06-17 19:56:36 -05002821lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002822 uint8_t retry)
2823{
James Smart4430f7f2020-11-15 11:26:31 -08002824 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002825 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002826 ADISC *ap;
dea31012005-04-17 16:05:31 -05002827 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002828 uint8_t *pcmd;
2829 uint16_t cmdsize;
2830
James Smart92d7f7b2007-06-17 19:56:38 -05002831 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002832 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2833 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002834 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002835 return 1;
dea31012005-04-17 16:05:31 -05002836
dea31012005-04-17 16:05:31 -05002837 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2838
2839 /* For ADISC request, remainder of payload is service parameters */
2840 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002841 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002842
2843 /* Fill in ADISC payload */
2844 ap = (ADISC *) pcmd;
2845 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002846 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2847 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002848 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002849
2850 phba->fc_stat.elsXmitADISC++;
2851 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smartc6adba12020-11-15 11:26:34 -08002852 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002853 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smartc6adba12020-11-15 11:26:34 -08002854 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002855 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08002856 if (!elsiocb->context1) {
2857 lpfc_els_free_iocb(phba, elsiocb);
2858 goto err;
2859 }
James Smart4430f7f2020-11-15 11:26:31 -08002860
2861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2862 "Issue ADISC: did:x%x refcnt %d",
2863 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2864 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08002865 if (rc == IOCB_ERROR) {
2866 lpfc_els_free_iocb(phba, elsiocb);
2867 lpfc_nlp_put(ndlp);
2868 goto err;
2869 }
2870
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002871 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08002872
James Smart8e9a3252021-03-01 09:18:09 -08002873err:
James Smartc6adba12020-11-15 11:26:34 -08002874 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002875 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smartc6adba12020-11-15 11:26:34 -08002876 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002877 return 1;
dea31012005-04-17 16:05:31 -05002878}
2879
James Smarte59058c2008-08-24 21:49:00 -04002880/**
James Smart3621a712009-04-06 18:47:14 -04002881 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002882 * @phba: pointer to lpfc hba data structure.
2883 * @cmdiocb: pointer to lpfc command iocb data structure.
2884 * @rspiocb: pointer to lpfc response iocb data structure.
2885 *
2886 * This routine is the completion function for issuing the ELS Logout (LOGO)
2887 * command. If no error status was reported from the LOGO response, the
2888 * state machine of the associated ndlp shall be invoked for transition with
James Smart69b8eff2021-03-01 09:18:19 -08002889 * respect to NLP_EVT_CMPL_LOGO event.
James Smarte59058c2008-08-24 21:49:00 -04002890 **/
dea31012005-04-17 16:05:31 -05002891static void
James Smart2e0fef82007-06-17 19:56:36 -05002892lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2893 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002894{
James Smart2e0fef82007-06-17 19:56:36 -05002895 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2896 struct lpfc_vport *vport = ndlp->vport;
dea31012005-04-17 16:05:31 -05002897 IOCB_t *irsp;
James Smart086a3452012-08-14 14:25:21 -04002898 unsigned long flags;
2899 uint32_t skip_recovery = 0;
James Smart31051242021-01-04 10:02:34 -08002900 int wake_up_waiter = 0;
dea31012005-04-17 16:05:31 -05002901
dea31012005-04-17 16:05:31 -05002902 /* we pass cmdiocb to state machine which needs rspiocb as well */
2903 cmdiocb->context_un.rsp_iocb = rspiocb;
2904
2905 irsp = &(rspiocb->iocb);
James Smartc6adba12020-11-15 11:26:34 -08002906 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002907 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smartaf984c82021-10-20 14:14:16 -07002908 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
James Smart31051242021-01-04 10:02:34 -08002909 wake_up_waiter = 1;
James Smartaf984c82021-10-20 14:14:16 -07002910 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
James Smart31051242021-01-04 10:02:34 -08002911 }
James Smartc6adba12020-11-15 11:26:34 -08002912 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002913
James Smart858c9f62007-06-17 19:56:39 -05002914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2915 "LOGO cmpl: status:x%x/x%x did:x%x",
2916 irsp->ulpStatus, irsp->un.ulpWord[4],
2917 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002918
dea31012005-04-17 16:05:31 -05002919 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2921 "0105 LOGO completes to NPort x%x "
James Smarta70e63e2020-11-15 11:26:38 -08002922 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2923 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2924 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarte8b62012007-08-02 11:10:09 -04002925 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002926
James Smart086a3452012-08-14 14:25:21 -04002927 if (lpfc_els_chk_latt(vport)) {
2928 skip_recovery = 1;
2929 goto out;
2930 }
2931
James Smart30e196c2018-10-23 13:41:03 -07002932 /* The LOGO will not be retried on failure. A LOGO was
2933 * issued to the remote rport and a ACC or RJT or no Answer are
2934 * all acceptable. Note the failure and move forward with
2935 * discovery. The PLOGI will retry.
2936 */
dea31012005-04-17 16:05:31 -05002937 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -05002938 /* LOGO failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002939 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart30e196c2018-10-23 13:41:03 -07002940 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002941 ndlp->nlp_DID, irsp->ulpStatus,
2942 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002943 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002944 if (lpfc_error_lost_link(irsp)) {
2945 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002946 goto out;
James Smart086a3452012-08-14 14:25:21 -04002947 }
2948 }
2949
2950 /* Call state machine. This will unregister the rpi if needed. */
2951 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2952
James Smarta70e63e2020-11-15 11:26:38 -08002953 /* The driver sets this flag for an NPIV instance that doesn't want to
2954 * log into the remote port.
2955 */
2956 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
James Smart01131e72021-05-14 12:55:49 -07002957 spin_lock_irq(&ndlp->lock);
2958 if (phba->sli_rev == LPFC_SLI_REV4)
2959 ndlp->nlp_flag |= NLP_RELEASE_RPI;
2960 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2961 spin_unlock_irq(&ndlp->lock);
James Smarta70e63e2020-11-15 11:26:38 -08002962 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2963 NLP_EVT_DEVICE_RM);
2964 lpfc_els_free_iocb(phba, cmdiocb);
2965 lpfc_nlp_put(ndlp);
2966
2967 /* Presume the node was released. */
2968 return;
2969 }
2970
dea31012005-04-17 16:05:31 -05002971out:
James Smart4430f7f2020-11-15 11:26:31 -08002972 /* Driver is done with the IO. */
dea31012005-04-17 16:05:31 -05002973 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002974 lpfc_nlp_put(ndlp);
2975
James Smart8e062ce2021-01-04 10:02:26 -08002976 /* At this point, the LOGO processing is complete. NOTE: For a
2977 * pt2pt topology, we are assuming the NPortID will only change
2978 * on link up processing. For a LOGO / PLOGI initiated by the
2979 * Initiator, we are assuming the NPortID is not going to change.
2980 */
James Smart086a3452012-08-14 14:25:21 -04002981
James Smart31051242021-01-04 10:02:34 -08002982 if (wake_up_waiter && ndlp->logo_waitq)
2983 wake_up(ndlp->logo_waitq);
James Smart086a3452012-08-14 14:25:21 -04002984 /*
2985 * If the node is a target, the handling attempts to recover the port.
2986 * For any other port type, the rpi is unregistered as an implicit
2987 * LOGO.
2988 */
James Smart30e196c2018-10-23 13:41:03 -07002989 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2990 skip_recovery == 0) {
James Smart086a3452012-08-14 14:25:21 -04002991 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartc6adba12020-11-15 11:26:34 -08002992 spin_lock_irqsave(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -04002993 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002994 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -04002995
2996 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2997 "3187 LOGO completes to NPort x%x: Start "
2998 "Recovery Data: x%x x%x x%x x%x\n",
2999 ndlp->nlp_DID, irsp->ulpStatus,
3000 irsp->un.ulpWord[4], irsp->ulpTimeout,
3001 vport->num_disc_nodes);
3002 lpfc_disc_start(vport);
James Smart52edb2c2020-11-15 11:26:35 -08003003 return;
James Smart086a3452012-08-14 14:25:21 -04003004 }
James Smart52edb2c2020-11-15 11:26:35 -08003005
3006 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3007 * driver sends a LOGO to the rport to cleanup. For fabric and
3008 * initiator ports cleanup the node as long as it the node is not
3009 * register with the transport.
3010 */
3011 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
3012 spin_lock_irq(&ndlp->lock);
3013 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3014 spin_unlock_irq(&ndlp->lock);
3015 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3016 NLP_EVT_DEVICE_RM);
3017 }
dea31012005-04-17 16:05:31 -05003018}
3019
James Smarte59058c2008-08-24 21:49:00 -04003020/**
James Smart3621a712009-04-06 18:47:14 -04003021 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003022 * @vport: pointer to a virtual N_Port data structure.
3023 * @ndlp: pointer to a node-list data structure.
3024 * @retry: number of retries to the command IOCB.
3025 *
3026 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3027 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3028 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3029 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3030 *
James Smart69b8eff2021-03-01 09:18:19 -08003031 * Note that the ndlp reference count will be incremented by 1 for holding the
3032 * ndlp and the reference to ndlp will be stored into the context1 field of
3033 * the IOCB for the completion callback function to the LOGO ELS command.
James Smarte59058c2008-08-24 21:49:00 -04003034 *
James Smart30e196c2018-10-23 13:41:03 -07003035 * Callers of this routine are expected to unregister the RPI first
3036 *
James Smarte59058c2008-08-24 21:49:00 -04003037 * Return code
3038 * 0 - successfully issued logo
3039 * 1 - failed to issue logo
3040 **/
dea31012005-04-17 16:05:31 -05003041int
James Smart2e0fef82007-06-17 19:56:36 -05003042lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05003043 uint8_t retry)
3044{
James Smart2e0fef82007-06-17 19:56:36 -05003045 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003046 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003047 uint8_t *pcmd;
3048 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05003049 int rc;
dea31012005-04-17 16:05:31 -05003050
James Smartc6adba12020-11-15 11:26:34 -08003051 spin_lock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04003052 if (ndlp->nlp_flag & NLP_LOGO_SND) {
James Smartc6adba12020-11-15 11:26:34 -08003053 spin_unlock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04003054 return 0;
3055 }
James Smartc6adba12020-11-15 11:26:34 -08003056 spin_unlock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04003057
James Smart92d7f7b2007-06-17 19:56:38 -05003058 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05003059 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3060 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05003061 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003062 return 1;
dea31012005-04-17 16:05:31 -05003063
dea31012005-04-17 16:05:31 -05003064 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3065 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05003066 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003067
3068 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05003069 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05003070 pcmd += sizeof(uint32_t);
3071 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003072
3073 phba->fc_stat.elsXmitLOGO++;
3074 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smartc6adba12020-11-15 11:26:34 -08003075 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05003076 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04003077 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smartc6adba12020-11-15 11:26:34 -08003078 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08003079 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08003080 if (!elsiocb->context1) {
3081 lpfc_els_free_iocb(phba, elsiocb);
3082 goto err;
3083 }
James Smart4430f7f2020-11-15 11:26:31 -08003084
3085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3086 "Issue LOGO: did:x%x refcnt %d",
3087 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
James Smart3772a992009-05-22 14:50:54 -04003088 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08003089 if (rc == IOCB_ERROR) {
3090 lpfc_els_free_iocb(phba, elsiocb);
3091 lpfc_nlp_put(ndlp);
3092 goto err;
3093 }
James Smart30e196c2018-10-23 13:41:03 -07003094
James Smartc6adba12020-11-15 11:26:34 -08003095 spin_lock_irq(&ndlp->lock);
James Smart30e196c2018-10-23 13:41:03 -07003096 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartc6adba12020-11-15 11:26:34 -08003097 spin_unlock_irq(&ndlp->lock);
James Smart30e196c2018-10-23 13:41:03 -07003098 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003099 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003100
James Smart8e9a3252021-03-01 09:18:09 -08003101err:
James Smartc6adba12020-11-15 11:26:34 -08003102 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08003103 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -08003104 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08003105 return 1;
dea31012005-04-17 16:05:31 -05003106}
3107
James Smarte59058c2008-08-24 21:49:00 -04003108/**
James Smart3621a712009-04-06 18:47:14 -04003109 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04003110 * @phba: pointer to lpfc hba data structure.
3111 * @cmdiocb: pointer to lpfc command iocb data structure.
3112 * @rspiocb: pointer to lpfc response iocb data structure.
3113 *
3114 * This routine is a generic completion callback function for ELS commands.
3115 * Specifically, it is the callback function which does not need to perform
3116 * any command specific operations. It is currently used by the ELS command
James Smartdf3fe762020-02-10 09:31:55 -08003117 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3118 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3119 * Other than certain debug loggings, this callback function simply invokes the
James Smarte59058c2008-08-24 21:49:00 -04003120 * lpfc_els_chk_latt() routine to check whether link went down during the
3121 * discovery process.
3122 **/
dea31012005-04-17 16:05:31 -05003123static void
James Smart2e0fef82007-06-17 19:56:36 -05003124lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3125 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003126{
James Smart2e0fef82007-06-17 19:56:36 -05003127 struct lpfc_vport *vport = cmdiocb->vport;
James Smart4430f7f2020-11-15 11:26:31 -08003128 struct lpfc_nodelist *free_ndlp;
dea31012005-04-17 16:05:31 -05003129 IOCB_t *irsp;
3130
3131 irsp = &rspiocb->iocb;
3132
James Smart858c9f62007-06-17 19:56:39 -05003133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
James Smartdf3fe762020-02-10 09:31:55 -08003134 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3135 irsp->ulpStatus, irsp->un.ulpWord[4],
3136 irsp->un.elsreq64.remoteID);
3137
dea31012005-04-17 16:05:31 -05003138 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003139 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3140 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3141 irsp->ulpIoTag, irsp->ulpStatus,
3142 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smartdf3fe762020-02-10 09:31:55 -08003143
3144 /* Check to see if link went down during discovery */
3145 lpfc_els_chk_latt(vport);
James Smart4430f7f2020-11-15 11:26:31 -08003146
3147 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3148
James Smartdf3fe762020-02-10 09:31:55 -08003149 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003150 lpfc_nlp_put(free_ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003151}
3152
3153/**
James Smartfe83e3b2021-05-14 12:55:54 -07003154 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3155 * @vport: pointer to lpfc_vport data structure.
3156 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3157 *
3158 * This routine registers the rpi assigned to the fabric controller
3159 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3160 * state triggering a registration with the SCSI transport.
3161 *
3162 * This routine is single out because the fabric controller node
3163 * does not receive a PLOGI. This routine is consumed by the
3164 * SCR and RDF ELS commands. Callers are expected to qualify
3165 * with SLI4 first.
3166 **/
3167static int
3168lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3169{
3170 int rc = 0;
3171 struct lpfc_hba *phba = vport->phba;
3172 struct lpfc_nodelist *ns_ndlp;
3173 LPFC_MBOXQ_t *mbox;
3174 struct lpfc_dmabuf *mp;
3175
3176 if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
3177 return rc;
3178
3179 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3180 if (!ns_ndlp)
3181 return -ENODEV;
3182
3183 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3184 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3185 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3186 ns_ndlp->nlp_state);
3187 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3188 return -ENODEV;
3189
3190 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3191 if (!mbox) {
3192 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3193 "0936 %s: no memory for reg_login "
3194 "Data: x%x x%x x%x x%x\n", __func__,
3195 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3196 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3197 return -ENOMEM;
3198 }
3199 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3200 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3201 if (rc) {
3202 rc = -EACCES;
3203 goto out;
3204 }
3205
3206 fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3207 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3208 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3209 if (!mbox->ctx_ndlp) {
3210 rc = -ENOMEM;
3211 goto out_mem;
3212 }
3213
3214 mbox->vport = vport;
3215 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3216 if (rc == MBX_NOT_FINISHED) {
3217 rc = -ENODEV;
3218 lpfc_nlp_put(fc_ndlp);
3219 goto out_mem;
3220 }
3221 /* Success path. Exit. */
3222 lpfc_nlp_set_state(vport, fc_ndlp,
3223 NLP_STE_REG_LOGIN_ISSUE);
3224 return 0;
3225
3226 out_mem:
3227 fc_ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3228 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
3229 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3230 kfree(mp);
3231
3232 out:
3233 mempool_free(mbox, phba->mbox_mem_pool);
3234 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3235 "0938 %s: failed to format reg_login "
3236 "Data: x%x x%x x%x x%x\n", __func__,
3237 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3238 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3239 return rc;
3240}
3241
3242/**
James Smartdf3fe762020-02-10 09:31:55 -08003243 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3244 * @phba: pointer to lpfc hba data structure.
3245 * @cmdiocb: pointer to lpfc command iocb data structure.
3246 * @rspiocb: pointer to lpfc response iocb data structure.
3247 *
3248 * This routine is a generic completion callback function for Discovery ELS cmd.
3249 * Currently used by the ELS command issuing routines for the ELS State Change
3250 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3251 * These commands will be retried once only for ELS timeout errors.
3252 **/
3253static void
3254lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3255 struct lpfc_iocbq *rspiocb)
3256{
3257 struct lpfc_vport *vport = cmdiocb->vport;
3258 IOCB_t *irsp;
3259 struct lpfc_els_rdf_rsp *prdf;
3260 struct lpfc_dmabuf *pcmd, *prsp;
3261 u32 *pdata;
3262 u32 cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003263 struct lpfc_nodelist *ndlp = cmdiocb->context1;
James Smartdf3fe762020-02-10 09:31:55 -08003264
3265 irsp = &rspiocb->iocb;
3266
3267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3268 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3269 irsp->ulpStatus, irsp->un.ulpWord[4],
3270 irsp->un.elsreq64.remoteID);
3271 /* ELS cmd tag <ulpIoTag> completes */
James Smart428569e2021-08-16 09:28:49 -07003272 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
James Smartdf3fe762020-02-10 09:31:55 -08003273 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3274 "x%x\n",
3275 irsp->ulpIoTag, irsp->ulpStatus,
3276 irsp->un.ulpWord[4], irsp->ulpTimeout,
3277 cmdiocb->retry);
3278
3279 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3280 if (!pcmd)
3281 goto out;
3282
3283 pdata = (u32 *)pcmd->virt;
3284 if (!pdata)
3285 goto out;
3286 cmd = *pdata;
3287
3288 /* Only 1 retry for ELS Timeout only */
3289 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3290 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3291 IOERR_SEQUENCE_TIMEOUT)) {
3292 cmdiocb->retry++;
3293 if (cmdiocb->retry <= 1) {
3294 switch (cmd) {
3295 case ELS_CMD_SCR:
3296 lpfc_issue_els_scr(vport, cmdiocb->retry);
3297 break;
James Smart9064aeb2021-08-16 09:28:50 -07003298 case ELS_CMD_EDC:
3299 lpfc_issue_els_edc(vport, cmdiocb->retry);
3300 break;
James Smartdf3fe762020-02-10 09:31:55 -08003301 case ELS_CMD_RDF:
3302 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3303 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3304 break;
3305 }
3306 goto out;
3307 }
3308 phba->fc_stat.elsRetryExceeded++;
3309 }
James Smart9064aeb2021-08-16 09:28:50 -07003310 if (cmd == ELS_CMD_EDC) {
3311 /* must be called before checking uplStatus and returning */
3312 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb);
3313 return;
3314 }
James Smartdf3fe762020-02-10 09:31:55 -08003315 if (irsp->ulpStatus) {
3316 /* ELS discovery cmd completes with error */
3317 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3318 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3319 irsp->ulpStatus, irsp->un.ulpWord[4]);
3320 goto out;
3321 }
3322
3323 /* The RDF response doesn't have any impact on the running driver
3324 * but the notification descriptors are dumped here for support.
3325 */
3326 if (cmd == ELS_CMD_RDF) {
3327 int i;
3328
3329 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3330 if (!prsp)
3331 goto out;
3332
3333 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3334 if (!prdf)
3335 goto out;
3336
3337 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3338 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
James Smart428569e2021-08-16 09:28:49 -07003339 lpfc_printf_vlog(vport, KERN_INFO,
3340 LOG_ELS | LOG_CGN_MGMT,
3341 "4677 Fabric RDF Notification Grant "
James Smart02243832021-08-16 09:28:54 -07003342 "Data: 0x%08x Reg: %x %x\n",
James Smart428569e2021-08-16 09:28:49 -07003343 be32_to_cpu(
James Smart02243832021-08-16 09:28:54 -07003344 prdf->reg_d1.desc_tags[i]),
3345 phba->cgn_reg_signal,
3346 phba->cgn_reg_fpin);
James Smartdf3fe762020-02-10 09:31:55 -08003347 }
3348
3349out:
dea31012005-04-17 16:05:31 -05003350 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05003351 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05003352 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003353 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003354 return;
3355}
3356
James Smarte59058c2008-08-24 21:49:00 -04003357/**
James Smart3621a712009-04-06 18:47:14 -04003358 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003359 * @vport: pointer to a host virtual N_Port data structure.
James Smartdf3fe762020-02-10 09:31:55 -08003360 * @retry: retry counter for the command IOCB.
James Smarte59058c2008-08-24 21:49:00 -04003361 *
3362 * This routine issues a State Change Request (SCR) to a fabric node
James Smartdf3fe762020-02-10 09:31:55 -08003363 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
James Smarte59058c2008-08-24 21:49:00 -04003364 * first search the @vport node list to find the matching ndlp. If no such
3365 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3366 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3367 * routine is invoked to send the SCR IOCB.
3368 *
James Smart69b8eff2021-03-01 09:18:19 -08003369 * Note that the ndlp reference count will be incremented by 1 for holding the
3370 * ndlp and the reference to ndlp will be stored into the context1 field of
3371 * the IOCB for the completion callback function to the SCR ELS command.
James Smarte59058c2008-08-24 21:49:00 -04003372 *
3373 * Return code
3374 * 0 - Successfully issued scr command
3375 * 1 - Failed to issue scr command
3376 **/
dea31012005-04-17 16:05:31 -05003377int
James Smartdf3fe762020-02-10 09:31:55 -08003378lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
dea31012005-04-17 16:05:31 -05003379{
James Smart4430f7f2020-11-15 11:26:31 -08003380 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003381 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003382 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003383 uint8_t *pcmd;
3384 uint16_t cmdsize;
3385 struct lpfc_nodelist *ndlp;
3386
James Smart92d7f7b2007-06-17 19:56:38 -05003387 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05003388
James Smartdf3fe762020-02-10 09:31:55 -08003389 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003390 if (!ndlp) {
James Smartdf3fe762020-02-10 09:31:55 -08003391 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003392 if (!ndlp)
3393 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003394 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003395 }
dea31012005-04-17 16:05:31 -05003396
James Smart2e0fef82007-06-17 19:56:36 -05003397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3398 ndlp->nlp_DID, ELS_CMD_SCR);
James Smart4430f7f2020-11-15 11:26:31 -08003399 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003400 return 1;
dea31012005-04-17 16:05:31 -05003401
James Smartfe83e3b2021-05-14 12:55:54 -07003402 if (phba->sli_rev == LPFC_SLI_REV4) {
3403 rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
3404 if (rc) {
James Smartcd6047e2021-07-07 11:43:40 -07003405 lpfc_els_free_iocb(phba, elsiocb);
James Smartfe83e3b2021-05-14 12:55:54 -07003406 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3407 "0937 %s: Failed to reg fc node, rc %d\n",
3408 __func__, rc);
3409 return 1;
3410 }
3411 }
dea31012005-04-17 16:05:31 -05003412 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3413
3414 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05003415 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003416
3417 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003418 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05003419 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3420
James Smart858c9f62007-06-17 19:56:39 -05003421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3422 "Issue SCR: did:x%x",
3423 ndlp->nlp_DID, 0, 0);
3424
dea31012005-04-17 16:05:31 -05003425 phba->fc_stat.elsXmitSCR++;
James Smartdf3fe762020-02-10 09:31:55 -08003426 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003427 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08003428 if (!elsiocb->context1) {
3429 lpfc_els_free_iocb(phba, elsiocb);
3430 return 1;
3431 }
James Smart4430f7f2020-11-15 11:26:31 -08003432
3433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3434 "Issue SCR: did:x%x refcnt %d",
3435 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3436
3437 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08003438 if (rc == IOCB_ERROR) {
3439 lpfc_els_free_iocb(phba, elsiocb);
3440 lpfc_nlp_put(ndlp);
3441 return 1;
3442 }
James Smart4430f7f2020-11-15 11:26:31 -08003443
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003444 return 0;
dea31012005-04-17 16:05:31 -05003445}
3446
James Smarte59058c2008-08-24 21:49:00 -04003447/**
James Smartf60cb932019-05-14 14:58:05 -07003448 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3449 * or the other nport (pt2pt).
3450 * @vport: pointer to a host virtual N_Port data structure.
3451 * @retry: number of retries to the command IOCB.
3452 *
3453 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3454 * when connected to a fabric, or to the remote port when connected
3455 * in point-to-point mode. When sent to the Fabric Controller, it will
3456 * replay the RSCN to registered recipients.
3457 *
James Smart69b8eff2021-03-01 09:18:19 -08003458 * Note that the ndlp reference count will be incremented by 1 for holding the
3459 * ndlp and the reference to ndlp will be stored into the context1 field of
3460 * the IOCB for the completion callback function to the RSCN ELS command.
James Smartf60cb932019-05-14 14:58:05 -07003461 *
3462 * Return code
3463 * 0 - Successfully issued RSCN command
3464 * 1 - Failed to issue RSCN command
3465 **/
3466int
3467lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3468{
James Smart4430f7f2020-11-15 11:26:31 -08003469 int rc = 0;
James Smartf60cb932019-05-14 14:58:05 -07003470 struct lpfc_hba *phba = vport->phba;
3471 struct lpfc_iocbq *elsiocb;
3472 struct lpfc_nodelist *ndlp;
3473 struct {
3474 struct fc_els_rscn rscn;
3475 struct fc_els_rscn_page portid;
3476 } *event;
3477 uint32_t nportid;
3478 uint16_t cmdsize = sizeof(*event);
3479
3480 /* Not supported for private loop */
3481 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3482 !(vport->fc_flag & FC_PUBLIC_LOOP))
3483 return 1;
3484
3485 if (vport->fc_flag & FC_PT2PT) {
3486 /* find any mapped nport - that would be the other nport */
3487 ndlp = lpfc_findnode_mapped(vport);
3488 if (!ndlp)
3489 return 1;
3490 } else {
3491 nportid = FC_FID_FCTRL;
3492 /* find the fabric controller node */
3493 ndlp = lpfc_findnode_did(vport, nportid);
3494 if (!ndlp) {
3495 /* if one didn't exist, make one */
3496 ndlp = lpfc_nlp_init(vport, nportid);
3497 if (!ndlp)
3498 return 1;
3499 lpfc_enqueue_node(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003500 }
3501 }
3502
3503 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3504 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3505
James Smart4430f7f2020-11-15 11:26:31 -08003506 if (!elsiocb)
James Smartf60cb932019-05-14 14:58:05 -07003507 return 1;
James Smartf60cb932019-05-14 14:58:05 -07003508
3509 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3510
3511 event->rscn.rscn_cmd = ELS_RSCN;
3512 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3513 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3514
3515 nportid = vport->fc_myDID;
3516 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3517 event->portid.rscn_page_flags = 0;
3518 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3519 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3520 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3521
James Smart4430f7f2020-11-15 11:26:31 -08003522 phba->fc_stat.elsXmitRSCN++;
3523 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3524 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08003525 if (!elsiocb->context1) {
3526 lpfc_els_free_iocb(phba, elsiocb);
3527 return 1;
3528 }
James Smart4430f7f2020-11-15 11:26:31 -08003529
James Smartf60cb932019-05-14 14:58:05 -07003530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3531 "Issue RSCN: did:x%x",
3532 ndlp->nlp_DID, 0, 0);
3533
James Smart4430f7f2020-11-15 11:26:31 -08003534 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08003535 if (rc == IOCB_ERROR) {
3536 lpfc_els_free_iocb(phba, elsiocb);
3537 lpfc_nlp_put(ndlp);
3538 return 1;
3539 }
James Smart8aaa7bc2020-10-20 13:27:17 -07003540
James Smartf60cb932019-05-14 14:58:05 -07003541 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3542 * trigger the release of node.
3543 */
3544 if (!(vport->fc_flag & FC_PT2PT))
3545 lpfc_nlp_put(ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003546 return 0;
3547}
3548
3549/**
James Smart3621a712009-04-06 18:47:14 -04003550 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003551 * @vport: pointer to a host virtual N_Port data structure.
3552 * @nportid: N_Port identifier to the remote node.
3553 * @retry: number of retries to the command IOCB.
3554 *
3555 * This routine issues a Fibre Channel Address Resolution Response
3556 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3557 * is passed into the function. It first search the @vport node list to find
3558 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3559 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3560 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3561 *
James Smart69b8eff2021-03-01 09:18:19 -08003562 * Note that the ndlp reference count will be incremented by 1 for holding the
3563 * ndlp and the reference to ndlp will be stored into the context1 field of
3564 * the IOCB for the completion callback function to the FARPR ELS command.
James Smarte59058c2008-08-24 21:49:00 -04003565 *
3566 * Return code
3567 * 0 - Successfully issued farpr command
3568 * 1 - Failed to issue farpr command
3569 **/
dea31012005-04-17 16:05:31 -05003570static int
James Smart2e0fef82007-06-17 19:56:36 -05003571lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05003572{
James Smart4430f7f2020-11-15 11:26:31 -08003573 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003574 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003575 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003576 FARP *fp;
3577 uint8_t *pcmd;
3578 uint32_t *lp;
3579 uint16_t cmdsize;
3580 struct lpfc_nodelist *ondlp;
3581 struct lpfc_nodelist *ndlp;
3582
James Smart92d7f7b2007-06-17 19:56:38 -05003583 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05003584
James Smarte47c9092008-02-08 18:49:26 -05003585 ndlp = lpfc_findnode_did(vport, nportid);
3586 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003587 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003588 if (!ndlp)
3589 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003590 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003591 }
James Smart2e0fef82007-06-17 19:56:36 -05003592
3593 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3594 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart4430f7f2020-11-15 11:26:31 -08003595 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003596 return 1;
dea31012005-04-17 16:05:31 -05003597
dea31012005-04-17 16:05:31 -05003598 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3599
3600 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003601 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003602
3603 /* Fill in FARPR payload */
3604 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003605 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003606 lp = (uint32_t *) pcmd;
3607 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003608 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003609 fp->Rflags = 0;
3610 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3611
James Smart92d7f7b2007-06-17 19:56:38 -05003612 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3613 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003614 ondlp = lpfc_findnode_did(vport, nportid);
James Smart307e3382020-11-15 11:26:30 -08003615 if (ondlp) {
dea31012005-04-17 16:05:31 -05003616 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003617 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003618 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003619 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003620 }
3621
James Smart858c9f62007-06-17 19:56:39 -05003622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3623 "Issue FARPR: did:x%x",
3624 ndlp->nlp_DID, 0, 0);
3625
dea31012005-04-17 16:05:31 -05003626 phba->fc_stat.elsXmitFARPR++;
3627 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003628 elsiocb->context1 = lpfc_nlp_get(ndlp);
3629 if (!elsiocb->context1) {
3630 lpfc_els_free_iocb(phba, elsiocb);
3631 return 1;
3632 }
3633
3634 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3635 if (rc == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003636 /* The additional lpfc_nlp_put will cause the following
3637 * lpfc_els_free_iocb routine to trigger the release of
3638 * the node.
3639 */
dea31012005-04-17 16:05:31 -05003640 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08003641 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003642 return 1;
dea31012005-04-17 16:05:31 -05003643 }
James Smartfa4066b2008-01-11 01:53:27 -05003644 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3645 * trigger the release of the node.
3646 */
James Smartdf3fe762020-02-10 09:31:55 -08003647 /* Don't release reference count as RDF is likely outstanding */
3648 return 0;
3649}
3650
3651/**
3652 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3653 * @vport: pointer to a host virtual N_Port data structure.
3654 * @retry: retry counter for the command IOCB.
3655 *
3656 * This routine issues an ELS RDF to the Fabric Controller to register
3657 * for diagnostic functions.
3658 *
James Smart69b8eff2021-03-01 09:18:19 -08003659 * Note that the ndlp reference count will be incremented by 1 for holding the
3660 * ndlp and the reference to ndlp will be stored into the context1 field of
3661 * the IOCB for the completion callback function to the RDF ELS command.
James Smartdf3fe762020-02-10 09:31:55 -08003662 *
3663 * Return code
3664 * 0 - Successfully issued rdf command
3665 * 1 - Failed to issue rdf command
3666 **/
3667int
3668lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3669{
3670 struct lpfc_hba *phba = vport->phba;
3671 struct lpfc_iocbq *elsiocb;
3672 struct lpfc_els_rdf_req *prdf;
3673 struct lpfc_nodelist *ndlp;
3674 uint16_t cmdsize;
James Smart4430f7f2020-11-15 11:26:31 -08003675 int rc;
James Smartdf3fe762020-02-10 09:31:55 -08003676
3677 cmdsize = sizeof(*prdf);
3678
3679 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3680 if (!ndlp) {
3681 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3682 if (!ndlp)
3683 return -ENODEV;
3684 lpfc_enqueue_node(vport, ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003685 }
3686
James Smart2d338eb2021-07-07 11:43:39 -07003687 /* RDF ELS is not required on an NPIV VN_Port. */
3688 if (vport->port_type == LPFC_NPIV_PORT)
James Smartdf3fe762020-02-10 09:31:55 -08003689 return -EACCES;
James Smartdf3fe762020-02-10 09:31:55 -08003690
3691 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3692 ndlp->nlp_DID, ELS_CMD_RDF);
James Smart4430f7f2020-11-15 11:26:31 -08003693 if (!elsiocb)
James Smartdf3fe762020-02-10 09:31:55 -08003694 return -ENOMEM;
James Smartdf3fe762020-02-10 09:31:55 -08003695
3696 /* Configure the payload for the supported FPIN events. */
3697 prdf = (struct lpfc_els_rdf_req *)
3698 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3699 memset(prdf, 0, cmdsize);
3700 prdf->rdf.fpin_cmd = ELS_RDF;
3701 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3702 sizeof(struct fc_els_rdf));
3703 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3704 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3705 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3706 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3707 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
James Smart441f6b52020-08-28 10:53:31 -07003708 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3709 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3710 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
James Smartdf3fe762020-02-10 09:31:55 -08003711
James Smart428569e2021-08-16 09:28:49 -07003712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
James Smart02243832021-08-16 09:28:54 -07003713 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3714 ndlp->nlp_DID, phba->cgn_reg_signal,
3715 phba->cgn_reg_fpin);
James Smartdf3fe762020-02-10 09:31:55 -08003716
James Smart02243832021-08-16 09:28:54 -07003717 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
James Smartdf3fe762020-02-10 09:31:55 -08003718 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003719 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08003720 if (!elsiocb->context1) {
3721 lpfc_els_free_iocb(phba, elsiocb);
3722 return -EIO;
3723 }
James Smartdf3fe762020-02-10 09:31:55 -08003724
James Smart4430f7f2020-11-15 11:26:31 -08003725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3726 "Issue RDF: did:x%x refcnt %d",
3727 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3728
3729 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08003730 if (rc == IOCB_ERROR) {
3731 lpfc_els_free_iocb(phba, elsiocb);
3732 lpfc_nlp_put(ndlp);
3733 return -EIO;
3734 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003735 return 0;
dea31012005-04-17 16:05:31 -05003736}
3737
James Smart8eced802021-05-14 12:55:58 -07003738 /**
3739 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3740 * @vport: pointer to a host virtual N_Port data structure.
3741 * @cmdiocb: pointer to lpfc command iocb data structure.
3742 * @ndlp: pointer to a node-list data structure.
3743 *
3744 * A received RDF implies a possible change to fabric supported diagnostic
3745 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3746 * RDF request to reregister for supported diagnostic functions.
3747 *
3748 * Return code
3749 * 0 - Success
3750 * -EIO - Failed to process received RDF
3751 **/
3752static int
3753lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3754 struct lpfc_nodelist *ndlp)
3755{
3756 /* Send LS_ACC */
3757 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
James Smart428569e2021-08-16 09:28:49 -07003758 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
James Smart8eced802021-05-14 12:55:58 -07003759 "1623 Failed to RDF_ACC from x%x for x%x\n",
3760 ndlp->nlp_DID, vport->fc_myDID);
3761 return -EIO;
3762 }
3763
3764 /* Issue new RDF for reregistering */
3765 if (lpfc_issue_els_rdf(vport, 0)) {
James Smart428569e2021-08-16 09:28:49 -07003766 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
James Smart8eced802021-05-14 12:55:58 -07003767 "2623 Failed to re register RDF for x%x\n",
3768 vport->fc_myDID);
3769 return -EIO;
3770 }
3771
3772 return 0;
3773}
3774
James Smarte59058c2008-08-24 21:49:00 -04003775/**
James Smart9064aeb2021-08-16 09:28:50 -07003776 * lpfc_least_capable_settings - helper function for EDC rsp processing
3777 * @phba: pointer to lpfc hba data structure.
3778 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3779 *
3780 * This helper routine determines the least capable setting for
3781 * congestion signals, signal freq, including scale, from the
3782 * congestion detection descriptor in the EDC rsp. The routine
3783 * sets @phba values in preparation for a set_featues mailbox.
3784 **/
3785static void
3786lpfc_least_capable_settings(struct lpfc_hba *phba,
3787 struct fc_diag_cg_sig_desc *pcgd)
3788{
3789 u32 rsp_sig_cap = 0, drv_sig_cap = 0;
3790 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
James Smart02243832021-08-16 09:28:54 -07003791 struct lpfc_cgn_info *cp;
James Smart7481811c2021-08-16 09:28:56 -07003792 u32 crc;
James Smart02243832021-08-16 09:28:54 -07003793 u16 sig_freq;
James Smart9064aeb2021-08-16 09:28:50 -07003794
3795 /* Get rsp signal and frequency capabilities. */
3796 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
3797 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
3798 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
3799
3800 /* If the Fport does not support signals. Set FPIN only */
3801 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
3802 goto out_no_support;
3803
3804 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3805 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3806 * to milliSeconds.
3807 */
3808 switch (rsp_sig_freq_scale) {
3809 case EDC_CG_SIGFREQ_SEC:
3810 rsp_sig_freq_cyc *= MSEC_PER_SEC;
3811 break;
3812 case EDC_CG_SIGFREQ_MSEC:
3813 rsp_sig_freq_cyc = 1;
3814 break;
3815 default:
3816 goto out_no_support;
3817 }
3818
3819 /* Convenient shorthand. */
3820 drv_sig_cap = phba->cgn_reg_signal;
3821
3822 /* Choose the least capable frequency. */
3823 if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
3824 phba->cgn_sig_freq = rsp_sig_freq_cyc;
3825
3826 /* Should be some common signals support. Settle on least capable
3827 * signal and adjust FPIN values. Initialize defaults to ease the
3828 * decision.
3829 */
3830 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
3831 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3832 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
3833 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
3834 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
3835 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3836 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3837 }
3838 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3839 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3840 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
3841 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
3842 }
3843 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
3844 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3845 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3846 }
3847 }
James Smart02243832021-08-16 09:28:54 -07003848
3849 if (!phba->cgn_i)
3850 return;
3851
3852 /* Update signal frequency in congestion info buffer */
3853 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
3854
3855 /* Frequency (in ms) Signal Warning/Signal Congestion Notifications
3856 * are received by the HBA
3857 */
3858 sig_freq = phba->cgn_sig_freq;
3859
3860 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY)
3861 cp->cgn_warn_freq = cpu_to_le16(sig_freq);
3862 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
3863 cp->cgn_alarm_freq = cpu_to_le16(sig_freq);
3864 cp->cgn_warn_freq = cpu_to_le16(sig_freq);
3865 }
James Smart7481811c2021-08-16 09:28:56 -07003866 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
3867 cp->cgn_info_crc = cpu_to_le32(crc);
James Smart9064aeb2021-08-16 09:28:50 -07003868 return;
3869
3870out_no_support:
3871 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3872 phba->cgn_sig_freq = 0;
3873 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
3874}
3875
3876DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
3877 FC_LS_TLV_DTAG_INIT);
3878
3879/**
3880 * lpfc_cmpl_els_edc - Completion callback function for EDC
3881 * @phba: pointer to lpfc hba data structure.
3882 * @cmdiocb: pointer to lpfc command iocb data structure.
3883 * @rspiocb: pointer to lpfc response iocb data structure.
3884 *
3885 * This routine is the completion callback function for issuing the Exchange
3886 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3887 * notify the FPort of its Congestion and Link Fault capabilities. This
3888 * routine parses the FPort's response and decides on the least common
3889 * values applicable to both FPort and NPort for Warnings and Alarms that
3890 * are communicated via hardware signals.
3891 **/
3892static void
3893lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3894 struct lpfc_iocbq *rspiocb)
3895{
3896 IOCB_t *irsp;
3897 struct fc_els_edc_resp *edc_rsp;
3898 struct fc_tlv_desc *tlv;
3899 struct fc_diag_cg_sig_desc *pcgd;
3900 struct fc_diag_lnkflt_desc *plnkflt;
3901 struct lpfc_dmabuf *pcmd, *prsp;
3902 const char *dtag_nm;
3903 u32 *pdata, dtag;
3904 int desc_cnt = 0, bytes_remain;
3905 bool rcv_cap_desc = false;
3906 struct lpfc_nodelist *ndlp;
3907
3908 irsp = &rspiocb->iocb;
3909 ndlp = cmdiocb->context1;
3910
3911 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
3912 "EDC cmpl: status:x%x/x%x did:x%x",
3913 irsp->ulpStatus, irsp->un.ulpWord[4],
3914 irsp->un.elsreq64.remoteID);
3915
3916 /* ELS cmd tag <ulpIoTag> completes */
3917 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3918 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
3919 irsp->ulpIoTag, irsp->ulpStatus,
3920 irsp->un.ulpWord[4], irsp->ulpTimeout);
3921
3922 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3923 if (!pcmd)
3924 goto out;
3925
3926 pdata = (u32 *)pcmd->virt;
3927 if (!pdata)
3928 goto out;
3929
3930 /* Need to clear signal values, send features MB and RDF with FPIN. */
3931 if (irsp->ulpStatus)
3932 goto out;
3933
3934 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3935 if (!prsp)
3936 goto out;
3937
3938 edc_rsp = prsp->virt;
3939 if (!edc_rsp)
3940 goto out;
3941
3942 /* ELS cmd tag <ulpIoTag> completes */
3943 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3944 "4676 Fabric EDC Rsp: "
3945 "0x%02x, 0x%08x\n",
3946 edc_rsp->acc_hdr.la_cmd,
3947 be32_to_cpu(edc_rsp->desc_list_len));
3948
3949 /*
3950 * Payload length in bytes is the response descriptor list
3951 * length minus the 12 bytes of Link Service Request
3952 * Information descriptor in the reply.
3953 */
3954 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
3955 sizeof(struct fc_els_lsri_desc);
3956 if (bytes_remain <= 0)
3957 goto out;
3958
3959 tlv = edc_rsp->desc;
3960
3961 /*
3962 * cycle through EDC diagnostic descriptors to find the
3963 * congestion signaling capability descriptor
3964 */
3965 while (bytes_remain) {
3966 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
3967 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
3968 "6461 Truncated TLV hdr on "
3969 "Diagnostic descriptor[%d]\n",
3970 desc_cnt);
3971 goto out;
3972 }
3973
3974 dtag = be32_to_cpu(tlv->desc_tag);
3975 switch (dtag) {
3976 case ELS_DTAG_LNK_FAULT_CAP:
3977 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
3978 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
3979 sizeof(struct fc_diag_lnkflt_desc)) {
3980 lpfc_printf_log(
3981 phba, KERN_WARNING, LOG_CGN_MGMT,
3982 "6462 Truncated Link Fault Diagnostic "
3983 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
3984 desc_cnt, bytes_remain,
3985 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
3986 sizeof(struct fc_diag_cg_sig_desc));
3987 goto out;
3988 }
3989 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
3990 lpfc_printf_log(
3991 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3992 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
3993 "0x%08x 0x%08x 0x%08x\n",
3994 be32_to_cpu(plnkflt->desc_tag),
3995 be32_to_cpu(plnkflt->desc_len),
3996 be32_to_cpu(
3997 plnkflt->degrade_activate_threshold),
3998 be32_to_cpu(
3999 plnkflt->degrade_deactivate_threshold),
4000 be32_to_cpu(plnkflt->fec_degrade_interval));
4001 break;
4002 case ELS_DTAG_CG_SIGNAL_CAP:
4003 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4004 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4005 sizeof(struct fc_diag_cg_sig_desc)) {
4006 lpfc_printf_log(
4007 phba, KERN_WARNING, LOG_CGN_MGMT,
4008 "6463 Truncated Cgn Signal Diagnostic "
4009 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4010 desc_cnt, bytes_remain,
4011 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4012 sizeof(struct fc_diag_cg_sig_desc));
4013 goto out;
4014 }
4015
4016 pcgd = (struct fc_diag_cg_sig_desc *)tlv;
4017 lpfc_printf_log(
4018 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4019 "4616 CGN Desc Data: 0x%08x 0x%08x "
4020 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4021 be32_to_cpu(pcgd->desc_tag),
4022 be32_to_cpu(pcgd->desc_len),
4023 be32_to_cpu(pcgd->xmt_signal_capability),
James Smart59936432021-08-30 16:12:43 -07004024 be16_to_cpu(pcgd->xmt_signal_frequency.count),
4025 be16_to_cpu(pcgd->xmt_signal_frequency.units),
James Smart9064aeb2021-08-16 09:28:50 -07004026 be32_to_cpu(pcgd->rcv_signal_capability),
James Smart59936432021-08-30 16:12:43 -07004027 be16_to_cpu(pcgd->rcv_signal_frequency.count),
4028 be16_to_cpu(pcgd->rcv_signal_frequency.units));
James Smart9064aeb2021-08-16 09:28:50 -07004029
4030 /* Compare driver and Fport capabilities and choose
4031 * least common.
4032 */
4033 lpfc_least_capable_settings(phba, pcgd);
4034 rcv_cap_desc = true;
4035 break;
4036 default:
4037 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
4038 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4039 "4919 unknown Diagnostic "
4040 "Descriptor[%d]: tag x%x (%s)\n",
4041 desc_cnt, dtag, dtag_nm);
4042 }
4043
4044 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
4045 tlv = fc_tlv_next_desc(tlv);
4046 desc_cnt++;
4047 }
4048
4049out:
4050 if (!rcv_cap_desc) {
4051 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
4052 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4053 phba->cgn_sig_freq = 0;
4054 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
4055 "4202 EDC rsp error - sending RDF "
4056 "for FPIN only.\n");
4057 }
4058
4059 lpfc_config_cgn_signal(phba);
4060
4061 /* Check to see if link went down during discovery */
4062 lpfc_els_chk_latt(phba->pport);
4063 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4064 "EDC Cmpl: did:x%x refcnt %d",
4065 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4066 lpfc_els_free_iocb(phba, cmdiocb);
4067 lpfc_nlp_put(ndlp);
4068}
4069
4070static void
4071lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_diag_cg_sig_desc *cgd)
4072{
4073 /* We are assuming cgd was zero'ed before calling this routine */
4074
4075 /* Configure the congestion detection capability */
4076 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
4077
4078 /* Descriptor len doesn't include the tag or len fields. */
4079 cgd->desc_len = cpu_to_be32(
4080 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
4081
4082 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4083 * xmt_signal_frequency.count already set to 0.
4084 * xmt_signal_frequency.units already set to 0.
4085 */
4086
4087 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
4088 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4089 * rcv_signal_frequency.count already set to 0.
4090 * rcv_signal_frequency.units already set to 0.
4091 */
4092 phba->cgn_sig_freq = 0;
4093 return;
4094 }
4095 switch (phba->cgn_reg_signal) {
4096 case EDC_CG_SIG_WARN_ONLY:
4097 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
4098 break;
4099 case EDC_CG_SIG_WARN_ALARM:
4100 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
4101 break;
4102 default:
4103 /* rcv_signal_capability left 0 thus no support */
4104 break;
4105 }
4106
4107 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4108 * the completion we settle on the higher frequency.
4109 */
4110 cgd->rcv_signal_frequency.count =
4111 cpu_to_be16(lpfc_fabric_cgn_frequency);
4112 cgd->rcv_signal_frequency.units =
4113 cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
4114}
4115
4116 /**
4117 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4118 * @vport: pointer to a host virtual N_Port data structure.
4119 * @retry: retry counter for the command iocb.
4120 *
4121 * This routine issues an ELS EDC to the F-Port Controller to communicate
4122 * this N_Port's support of hardware signals in its Congestion
4123 * Capabilities Descriptor.
4124 *
4125 * Note: This routine does not check if one or more signals are
4126 * set in the cgn_reg_signal parameter. The caller makes the
4127 * decision to enforce cgn_reg_signal as nonzero or zero depending
4128 * on the conditions. During Fabric requests, the driver
4129 * requires cgn_reg_signals to be nonzero. But a dynamic request
4130 * to set the congestion mode to OFF from Monitor or Manage
4131 * would correctly issue an EDC with no signals enabled to
4132 * turn off switch functionality and then update the FW.
4133 *
4134 * Return code
4135 * 0 - Successfully issued edc command
4136 * 1 - Failed to issue edc command
4137 **/
4138int
4139lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
4140{
4141 struct lpfc_hba *phba = vport->phba;
4142 struct lpfc_iocbq *elsiocb;
4143 struct lpfc_els_edc_req *edc_req;
4144 struct fc_diag_cg_sig_desc *cgn_desc;
4145 u16 cmdsize;
4146 struct lpfc_nodelist *ndlp;
4147 u8 *pcmd = NULL;
4148 u32 edc_req_size, cgn_desc_size;
4149 int rc;
4150
4151 if (vport->port_type == LPFC_NPIV_PORT)
4152 return -EACCES;
4153
4154 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4155 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
4156 return -ENODEV;
4157
4158 /* If HBA doesn't support signals, drop into RDF */
4159 if (!phba->cgn_init_reg_signal)
4160 goto try_rdf;
4161
4162 edc_req_size = sizeof(struct fc_els_edc);
4163 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
4164 cmdsize = edc_req_size + cgn_desc_size;
4165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
4166 ndlp->nlp_DID, ELS_CMD_EDC);
4167 if (!elsiocb)
4168 goto try_rdf;
4169
4170 /* Configure the payload for the supported Diagnostics capabilities. */
4171 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
4172 memset(pcmd, 0, cmdsize);
4173 edc_req = (struct lpfc_els_edc_req *)pcmd;
4174 edc_req->edc.desc_len = cpu_to_be32(cgn_desc_size);
4175 edc_req->edc.edc_cmd = ELS_EDC;
4176
4177 cgn_desc = &edc_req->cgn_desc;
4178
4179 lpfc_format_edc_cgn_desc(phba, cgn_desc);
4180
4181 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
4182
4183 lpfc_printf_vlog(vport, KERN_INFO, LOG_CGN_MGMT,
4184 "4623 Xmit EDC to remote "
4185 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4186 ndlp->nlp_DID, phba->cgn_reg_signal,
4187 phba->cgn_reg_fpin);
4188
4189 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
4190 elsiocb->context1 = lpfc_nlp_get(ndlp);
4191 if (!elsiocb->context1) {
4192 lpfc_els_free_iocb(phba, elsiocb);
4193 return -EIO;
4194 }
4195
4196 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4197 "Issue EDC: did:x%x refcnt %d",
4198 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4199 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4200 if (rc == IOCB_ERROR) {
4201 /* The additional lpfc_nlp_put will cause the following
4202 * lpfc_els_free_iocb routine to trigger the rlease of
4203 * the node.
4204 */
4205 lpfc_els_free_iocb(phba, elsiocb);
4206 lpfc_nlp_put(ndlp);
4207 goto try_rdf;
4208 }
4209 return 0;
4210try_rdf:
4211 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
4212 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4213 rc = lpfc_issue_els_rdf(vport, 0);
4214 return rc;
4215}
4216
4217/**
James Smart3621a712009-04-06 18:47:14 -04004218 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04004219 * @vport: pointer to a host virtual N_Port data structure.
4220 * @nlp: pointer to a node-list data structure.
4221 *
4222 * This routine cancels the timer with a delayed IOCB-command retry for
4223 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4224 * removes the ELS retry event if it presents. In addition, if the
4225 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4226 * commands are sent for the @vport's nodes that require issuing discovery
4227 * ADISC.
4228 **/
dea31012005-04-17 16:05:31 -05004229void
James Smart2e0fef82007-06-17 19:56:36 -05004230lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05004231{
James Smart2e0fef82007-06-17 19:56:36 -05004232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05004233 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05004234
James Smart0d2b6b82008-06-14 22:52:47 -04004235 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
4236 return;
James Smartc6adba12020-11-15 11:26:34 -08004237 spin_lock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05004238 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08004239 spin_unlock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05004240 del_timer_sync(&nlp->nlp_delayfunc);
4241 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05004242 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05004243 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05004244 /* Decrement nlp reference count held for the delayed retry */
4245 evtp = &nlp->els_retry_evt;
4246 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
4247 }
James Smartfdcebe22006-03-07 15:04:01 -05004248 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smartc6adba12020-11-15 11:26:34 -08004249 spin_lock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05004250 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08004251 spin_unlock_irq(&nlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05004252 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04004253 if (vport->port_state < LPFC_VPORT_READY) {
4254 /* Check if there are more ADISCs to be sent */
4255 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004256 } else {
4257 /* Check if there are more PLOGIs to be sent */
4258 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04004259 if (vport->num_disc_nodes == 0) {
4260 spin_lock_irq(shost->host_lock);
4261 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4262 spin_unlock_irq(shost->host_lock);
4263 lpfc_can_disctmo(vport);
4264 lpfc_end_rscn(vport);
4265 }
James Smartfdcebe22006-03-07 15:04:01 -05004266 }
4267 }
4268 }
4269 return;
4270}
4271
James Smarte59058c2008-08-24 21:49:00 -04004272/**
James Smart3621a712009-04-06 18:47:14 -04004273 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01004274 * @t: pointer to the timer function associated data (ndlp).
James Smarte59058c2008-08-24 21:49:00 -04004275 *
4276 * This routine is invoked by the ndlp delayed-function timer to check
4277 * whether there is any pending ELS retry event(s) with the node. If not, it
4278 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4279 * adds the delayed events to the HBA work list and invokes the
4280 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4281 * event. Note that lpfc_nlp_get() is called before posting the event to
4282 * the work list to hold reference count of ndlp so that it guarantees the
4283 * reference to ndlp will still be available when the worker thread gets
4284 * to the event associated with the ndlp.
4285 **/
James Smartfdcebe22006-03-07 15:04:01 -05004286void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004287lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05004288{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004289 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05004290 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05004291 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05004292 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05004293 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05004294
James Smart92d7f7b2007-06-17 19:56:38 -05004295 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05004296 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004297 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05004298 return;
4299 }
4300
James Smartfa4066b2008-01-11 01:53:27 -05004301 /* We need to hold the node by incrementing the reference
4302 * count until the queued work is done
4303 */
4304 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04004305 if (evtp->evt_arg1) {
4306 evtp->evt = LPFC_EVT_ELS_RETRY;
4307 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05004308 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04004309 }
James Smart92d7f7b2007-06-17 19:56:38 -05004310 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05004311 return;
4312}
4313
James Smarte59058c2008-08-24 21:49:00 -04004314/**
James Smart3621a712009-04-06 18:47:14 -04004315 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04004316 * @ndlp: pointer to a node-list data structure.
4317 *
4318 * This routine is the worker-thread handler for processing the @ndlp delayed
4319 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4320 * the last ELS command from the associated ndlp and invokes the proper ELS
4321 * function according to the delayed ELS command to retry the command.
4322 **/
dea31012005-04-17 16:05:31 -05004323void
4324lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
4325{
James Smart2e0fef82007-06-17 19:56:36 -05004326 struct lpfc_vport *vport = ndlp->vport;
James Smarteb016562014-09-03 12:58:06 -04004327 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05004328
James Smartc6adba12020-11-15 11:26:34 -08004329 spin_lock_irq(&ndlp->lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004330 cmd = ndlp->nlp_last_elscmd;
4331 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05004332
4333 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smartc6adba12020-11-15 11:26:34 -08004334 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004335 return;
4336 }
4337
4338 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08004339 spin_unlock_irq(&ndlp->lock);
James Smart1a169682006-03-07 15:04:06 -05004340 /*
4341 * If a discovery event readded nlp_delayfunc after timer
4342 * firing and before processing the timer, cancel the
4343 * nlp_delayfunc.
4344 */
4345 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05004346 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04004347 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05004348
4349 switch (cmd) {
4350 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004351 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05004352 break;
4353 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004354 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004355 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004356 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05004357 }
dea31012005-04-17 16:05:31 -05004358 break;
4359 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05004360 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004361 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004362 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05004363 }
dea31012005-04-17 16:05:31 -05004364 break;
4365 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08004366 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05004367 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004368 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05004370 }
dea31012005-04-17 16:05:31 -05004371 break;
4372 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05004373 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004374 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04004375 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05004376 }
dea31012005-04-17 16:05:31 -05004377 break;
James Smart92d7f7b2007-06-17 19:56:38 -05004378 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05004379 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
4380 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05004381 break;
dea31012005-04-17 16:05:31 -05004382 }
4383 return;
4384}
4385
James Smarte59058c2008-08-24 21:49:00 -04004386/**
James Smart5cca2ab2018-10-23 13:41:04 -07004387 * lpfc_link_reset - Issue link reset
4388 * @vport: pointer to a virtual N_Port data structure.
4389 *
4390 * This routine performs link reset by sending INIT_LINK mailbox command.
4391 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4392 * INIT_LINK mailbox command.
4393 *
4394 * Return code
4395 * 0 - Link reset initiated successfully
4396 * 1 - Failed to initiate link reset
4397 **/
4398int
4399lpfc_link_reset(struct lpfc_vport *vport)
4400{
4401 struct lpfc_hba *phba = vport->phba;
4402 LPFC_MBOXQ_t *mbox;
4403 uint32_t control;
4404 int rc;
4405
4406 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4407 "2851 Attempt link reset\n");
4408 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4409 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004410 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07004411 "2852 Failed to allocate mbox memory");
4412 return 1;
4413 }
4414
4415 /* Enable Link attention interrupts */
4416 if (phba->sli_rev <= LPFC_SLI_REV3) {
4417 spin_lock_irq(&phba->hbalock);
4418 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4419 control = readl(phba->HCregaddr);
4420 control |= HC_LAINT_ENA;
4421 writel(control, phba->HCregaddr);
4422 readl(phba->HCregaddr); /* flush */
4423 spin_unlock_irq(&phba->hbalock);
4424 }
4425
4426 lpfc_init_link(phba, mbox, phba->cfg_topology,
4427 phba->cfg_link_speed);
4428 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4429 mbox->vport = vport;
4430 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4431 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004432 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07004433 "2853 Failed to issue INIT_LINK "
4434 "mbox command, rc:x%x\n", rc);
4435 mempool_free(mbox, phba->mbox_mem_pool);
4436 return 1;
4437 }
4438
4439 return 0;
4440}
4441
4442/**
James Smart3621a712009-04-06 18:47:14 -04004443 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04004444 * @phba: pointer to lpfc hba data structure.
4445 * @cmdiocb: pointer to lpfc command iocb data structure.
4446 * @rspiocb: pointer to lpfc response iocb data structure.
4447 *
4448 * This routine makes a retry decision on an ELS command IOCB, which has
4449 * failed. The following ELS IOCBs use this function for retrying the command
4450 * when previously issued command responsed with error status: FLOGI, PLOGI,
James Smart69b8eff2021-03-01 09:18:19 -08004451 * PRLI, ADISC and FDISC. Based on the ELS command type and the
James Smarte59058c2008-08-24 21:49:00 -04004452 * returned error status, it makes the decision whether a retry shall be
4453 * issued for the command, and whether a retry shall be made immediately or
4454 * delayed. In the former case, the corresponding ELS command issuing-function
4455 * is called to retry the command. In the later case, the ELS command shall
4456 * be posted to the ndlp delayed event and delayed function timer set to the
4457 * ndlp for the delayed command issusing.
4458 *
4459 * Return code
4460 * 0 - No retry of els command is made
4461 * 1 - Immediate or delayed retry of els command is made
4462 **/
dea31012005-04-17 16:05:31 -05004463static int
James Smart2e0fef82007-06-17 19:56:36 -05004464lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4465 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004466{
James Smart2e0fef82007-06-17 19:56:36 -05004467 struct lpfc_vport *vport = cmdiocb->vport;
James Smart2e0fef82007-06-17 19:56:36 -05004468 IOCB_t *irsp = &rspiocb->iocb;
4469 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4470 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05004471 uint32_t *elscmd;
4472 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05004473 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04004474 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004475 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05004476 uint32_t did;
James Smart5cca2ab2018-10-23 13:41:04 -07004477 int link_reset = 0, rc;
dea31012005-04-17 16:05:31 -05004478
James Smart488d1462006-03-07 15:02:37 -05004479
dea31012005-04-17 16:05:31 -05004480 /* Note: context2 may be 0 for internal driver abort
4481 * of delays ELS command.
4482 */
4483
4484 if (pcmd && pcmd->virt) {
4485 elscmd = (uint32_t *) (pcmd->virt);
4486 cmd = *elscmd++;
4487 }
4488
James Smart307e3382020-11-15 11:26:30 -08004489 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05004490 did = ndlp->nlp_DID;
4491 else {
4492 /* We should only hit this case for retrying PLOGI */
4493 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05004494 ndlp = lpfc_findnode_did(vport, did);
James Smart307e3382020-11-15 11:26:30 -08004495 if (!ndlp && (cmd != ELS_CMD_PLOGI))
James Smart148bc642021-03-01 09:18:10 -08004496 return 0;
James Smart488d1462006-03-07 15:02:37 -05004497 }
4498
James Smart858c9f62007-06-17 19:56:39 -05004499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4500 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
James Smart6b6eaf82021-03-01 09:18:05 -08004501 *(((uint32_t *)irsp) + 7), irsp->un.ulpWord[4], did);
James Smart858c9f62007-06-17 19:56:39 -05004502
dea31012005-04-17 16:05:31 -05004503 switch (irsp->ulpStatus) {
4504 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05004505 break;
James Smart1151e3e2011-02-16 12:39:35 -05004506 case IOSTAT_REMOTE_STOP:
4507 if (phba->sli_rev == LPFC_SLI_REV4) {
4508 /* This IO was aborted by the target, we don't
4509 * know the rxid and because we did not send the
4510 * ABTS we cannot generate and RRQ.
4511 */
4512 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04004513 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05004514 }
4515 break;
dea31012005-04-17 16:05:31 -05004516 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04004517 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05004518 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05004519 if (cmd == ELS_CMD_FLOGI) {
4520 if (PCI_DEVICE_ID_HORNET ==
4521 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05004522 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05004523 phba->pport->fc_myDID = 0;
4524 phba->alpa_map[0] = 0;
4525 phba->alpa_map[1] = 0;
4526 }
4527 }
James Smart2e0fef82007-06-17 19:56:36 -05004528 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004529 delay = 1000;
dea31012005-04-17 16:05:31 -05004530 retry = 1;
4531 break;
4532
James Smart92d7f7b2007-06-17 19:56:38 -05004533 case IOERR_ILLEGAL_COMMAND:
Dick Kennedy372c1872020-06-30 14:50:00 -07004534 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart7f5f3d02008-02-08 18:50:14 -05004535 "0124 Retry illegal cmd x%x "
4536 "retry:x%x delay:x%x\n",
4537 cmd, cmdiocb->retry, delay);
4538 retry = 1;
4539 /* All command's retry policy */
4540 maxretry = 8;
4541 if (cmdiocb->retry > 2)
4542 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05004543 break;
4544
dea31012005-04-17 16:05:31 -05004545 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04004546 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05004547 retry = 1;
4548 if (cmdiocb->retry > 100)
4549 delay = 100;
4550 maxretry = 250;
4551 break;
4552
4553 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05004554 delay = 100;
dea31012005-04-17 16:05:31 -05004555 retry = 1;
4556 break;
4557
4558 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05004559 if (cmd == ELS_CMD_PLOGI &&
4560 did == NameServer_DID) {
4561 /* Continue forever if plogi to */
4562 /* the nameserver fails */
4563 maxretry = 0;
4564 delay = 100;
4565 }
dea31012005-04-17 16:05:31 -05004566 retry = 1;
4567 break;
James Smart5cca2ab2018-10-23 13:41:04 -07004568
4569 case IOERR_SEQUENCE_TIMEOUT:
4570 if (cmd == ELS_CMD_PLOGI &&
4571 did == NameServer_DID &&
4572 (cmdiocb->retry + 1) == maxretry) {
4573 /* Reset the Link */
4574 link_reset = 1;
4575 break;
4576 }
4577 retry = 1;
4578 delay = 100;
4579 break;
James Smart15af02d2021-10-20 14:14:14 -07004580 case IOERR_SLI_ABORTED:
4581 /* Retry ELS PLOGI command?
4582 * Possibly the rport just wasn't ready.
4583 */
4584 if (cmd == ELS_CMD_PLOGI) {
4585 /* No retry if state change */
4586 if (ndlp &&
4587 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
4588 goto out_retry;
4589 retry = 1;
4590 maxretry = 2;
4591 }
4592 break;
dea31012005-04-17 16:05:31 -05004593 }
4594 break;
4595
4596 case IOSTAT_NPORT_RJT:
4597 case IOSTAT_FABRIC_RJT:
4598 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4599 retry = 1;
4600 break;
4601 }
4602 break;
4603
4604 case IOSTAT_NPORT_BSY:
4605 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04004606 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05004607 retry = 1;
4608 break;
4609
4610 case IOSTAT_LS_RJT:
4611 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
4612 /* Added for Vendor specifc support
4613 * Just keep retrying for these Rsn / Exp codes
4614 */
4615 switch (stat.un.b.lsRjtRsnCode) {
4616 case LSRJT_UNABLE_TPC:
James Smartdea37e82017-06-01 21:07:07 -07004617 /* The driver has a VALID PLOGI but the rport has
4618 * rejected the PRLI - can't do it now. Delay
Dick Kennedy678768d2020-08-03 14:02:26 -07004619 * for 1 second and try again.
4620 *
4621 * However, if explanation is REQ_UNSUPPORTED there's
4622 * no point to retry PRLI.
James Smartdea37e82017-06-01 21:07:07 -07004623 */
Dick Kennedy678768d2020-08-03 14:02:26 -07004624 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
4625 stat.un.b.lsRjtRsnCodeExp !=
4626 LSEXP_REQ_UNSUPPORTED) {
James Smartdea37e82017-06-01 21:07:07 -07004627 delay = 1000;
4628 maxretry = lpfc_max_els_tries + 1;
4629 retry = 1;
4630 break;
4631 }
4632
4633 /* Legacy bug fix code for targets with PLOGI delays. */
dea31012005-04-17 16:05:31 -05004634 if (stat.un.b.lsRjtRsnCodeExp ==
4635 LSEXP_CMD_IN_PROGRESS) {
4636 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05004637 delay = 1000;
dea31012005-04-17 16:05:31 -05004638 maxretry = 48;
4639 }
4640 retry = 1;
4641 break;
4642 }
James Smartffc95492010-06-07 15:23:17 -04004643 if (stat.un.b.lsRjtRsnCodeExp ==
4644 LSEXP_CANT_GIVE_DATA) {
4645 if (cmd == ELS_CMD_PLOGI) {
4646 delay = 1000;
4647 maxretry = 48;
4648 }
4649 retry = 1;
4650 break;
4651 }
James Smartdea37e82017-06-01 21:07:07 -07004652 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05004653 delay = 1000;
dea31012005-04-17 16:05:31 -05004654 maxretry = lpfc_max_els_tries + 1;
4655 retry = 1;
4656 break;
4657 }
James Smart92d7f7b2007-06-17 19:56:38 -05004658 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4659 (cmd == ELS_CMD_FDISC) &&
4660 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
Dick Kennedy372c1872020-06-30 14:50:00 -07004661 lpfc_printf_vlog(vport, KERN_ERR,
4662 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04004663 "0125 FDISC Failed (x%x). "
4664 "Fabric out of resources\n",
4665 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05004666 lpfc_vport_set_state(vport,
4667 FC_VPORT_NO_FABRIC_RSCS);
4668 }
dea31012005-04-17 16:05:31 -05004669 break;
4670
4671 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05004672 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08004673 (cmd == ELS_CMD_PRLI) ||
4674 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004675 delay = 1000;
dea31012005-04-17 16:05:31 -05004676 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05004677 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04004678 /* FDISC retry policy */
4679 maxretry = 48;
4680 if (cmdiocb->retry >= 32)
4681 delay = 1000;
dea31012005-04-17 16:05:31 -05004682 }
4683 retry = 1;
4684 break;
James Smart92d7f7b2007-06-17 19:56:38 -05004685
4686 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05004687 /* There are some cases where switches return this
4688 * error when they are not ready and should be returning
4689 * Logical Busy. We should delay every time.
4690 */
4691 if (cmd == ELS_CMD_FDISC &&
4692 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4693 maxretry = 3;
4694 delay = 1000;
4695 retry = 1;
James Smart44fd7fe2017-08-23 16:55:47 -07004696 } else if (cmd == ELS_CMD_FLOGI &&
4697 stat.un.b.lsRjtRsnCodeExp ==
4698 LSEXP_NOTHING_MORE) {
4699 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4700 retry = 1;
Dick Kennedy372c1872020-06-30 14:50:00 -07004701 lpfc_printf_vlog(vport, KERN_ERR,
4702 LOG_TRACE_EVENT,
James Smart44fd7fe2017-08-23 16:55:47 -07004703 "0820 FLOGI Failed (x%x). "
4704 "BBCredit Not Supported\n",
4705 stat.un.lsRjtError);
James Smart7f5f3d02008-02-08 18:50:14 -05004706 }
James Smart44fd7fe2017-08-23 16:55:47 -07004707 break;
4708
James Smart92d7f7b2007-06-17 19:56:38 -05004709 case LSRJT_PROTOCOL_ERR:
4710 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4711 (cmd == ELS_CMD_FDISC) &&
4712 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4713 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4714 ) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004715 lpfc_printf_vlog(vport, KERN_ERR,
4716 LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04004717 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04004718 "Fabric Detected Bad WWN\n",
4719 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05004720 lpfc_vport_set_state(vport,
4721 FC_VPORT_FABRIC_REJ_WWN);
4722 }
4723 break;
James Smart7bdedb32016-07-06 12:36:00 -07004724 case LSRJT_VENDOR_UNIQUE:
4725 if ((stat.un.b.vendorUnique == 0x45) &&
4726 (cmd == ELS_CMD_FLOGI)) {
4727 goto out_retry;
4728 }
4729 break;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004730 case LSRJT_CMD_UNSUPPORTED:
4731 /* lpfc nvmet returns this type of LS_RJT when it
4732 * receives an FCP PRLI because lpfc nvmet only
4733 * support NVME. ELS request is terminated for FCP4
4734 * on this rport.
4735 */
4736 if (stat.un.b.lsRjtRsnCodeExp ==
4737 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
James Smartc6adba12020-11-15 11:26:34 -08004738 spin_lock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004739 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
James Smartc6adba12020-11-15 11:26:34 -08004740 spin_unlock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004741 retry = 0;
4742 goto out_retry;
4743 }
4744 break;
dea31012005-04-17 16:05:31 -05004745 }
4746 break;
4747
4748 case IOSTAT_INTERMED_RSP:
4749 case IOSTAT_BA_RJT:
4750 break;
4751
4752 default:
4753 break;
4754 }
4755
James Smart5cca2ab2018-10-23 13:41:04 -07004756 if (link_reset) {
4757 rc = lpfc_link_reset(vport);
4758 if (rc) {
4759 /* Do not give up. Retry PLOGI one more time and attempt
4760 * link reset if PLOGI fails again.
4761 */
4762 retry = 1;
4763 delay = 100;
4764 goto out_retry;
4765 }
4766 return 1;
4767 }
4768
James Smart488d1462006-03-07 15:02:37 -05004769 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05004770 retry = 1;
dea31012005-04-17 16:05:31 -05004771
James Smartdf9e1b52011-12-13 13:22:17 -05004772 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05004773 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05004774 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004775 /* FLOGI retry policy */
4776 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05004777 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04004778 if (phba->link_flag != LS_LOOPBACK_MODE)
4779 maxretry = 0;
4780 else
4781 maxretry = 2;
4782
James Smart6669f9b2009-10-02 15:16:45 -04004783 if (cmdiocb->retry >= 100)
4784 delay = 5000;
4785 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04004786 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05004787 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4788 /* retry FDISCs every second up to devloss */
4789 retry = 1;
4790 maxretry = vport->cfg_devloss_tmo;
4791 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04004792 }
4793
James Smart6669f9b2009-10-02 15:16:45 -04004794 cmdiocb->retry++;
4795 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05004796 phba->fc_stat.elsRetryExceeded++;
4797 retry = 0;
4798 }
4799
James Smarted957682007-06-17 19:56:37 -05004800 if ((vport->load_flag & FC_UNLOADING) != 0)
4801 retry = 0;
4802
James Smart7bdedb32016-07-06 12:36:00 -07004803out_retry:
dea31012005-04-17 16:05:31 -05004804 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04004805 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4806 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4807 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4808 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4809 "2849 Stop retry ELS command "
4810 "x%x to remote NPORT x%x, "
4811 "Data: x%x x%x\n", cmd, did,
4812 cmdiocb->retry, delay);
4813 return 0;
4814 }
4815 }
dea31012005-04-17 16:05:31 -05004816
4817 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4819 "0107 Retry ELS command x%x to remote "
4820 "NPORT x%x Data: x%x x%x\n",
4821 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05004822
James Smart858c9f62007-06-17 19:56:39 -05004823 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4824 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04004825 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4826 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05004827 /* Don't reset timer for no resources */
4828
dea31012005-04-17 16:05:31 -05004829 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05004830 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05004831 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05004832 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004833 }
4834
4835 phba->fc_stat.elsXmitRetry++;
James Smart307e3382020-11-15 11:26:30 -08004836 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05004837 phba->fc_stat.elsDelayRetry++;
4838 ndlp->nlp_retry = cmdiocb->retry;
4839
James Smart92d7f7b2007-06-17 19:56:38 -05004840 /* delay is specified in milliseconds */
4841 mod_timer(&ndlp->nlp_delayfunc,
4842 jiffies + msecs_to_jiffies(delay));
James Smartc6adba12020-11-15 11:26:34 -08004843 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004844 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08004845 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004846
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004847 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08004848 if ((cmd == ELS_CMD_PRLI) ||
4849 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05004850 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04004851 NLP_STE_PRLI_ISSUE);
James Smart06145682021-07-07 11:43:46 -07004852 else if (cmd != ELS_CMD_ADISC)
James Smart858c9f62007-06-17 19:56:39 -05004853 lpfc_nlp_set_state(vport, ndlp,
4854 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004855 ndlp->nlp_last_elscmd = cmd;
4856
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004857 return 1;
dea31012005-04-17 16:05:31 -05004858 }
4859 switch (cmd) {
4860 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004861 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004862 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05004863 case ELS_CMD_FDISC:
4864 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4865 return 1;
dea31012005-04-17 16:05:31 -05004866 case ELS_CMD_PLOGI:
James Smart307e3382020-11-15 11:26:30 -08004867 if (ndlp) {
James Smart488d1462006-03-07 15:02:37 -05004868 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004869 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004870 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05004871 }
James Smart2e0fef82007-06-17 19:56:36 -05004872 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004873 return 1;
dea31012005-04-17 16:05:31 -05004874 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004875 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004876 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4877 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004878 return 1;
dea31012005-04-17 16:05:31 -05004879 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08004880 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004881 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004882 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4883 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004884 return 1;
dea31012005-04-17 16:05:31 -05004885 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004886 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04004887 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004888 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004889 return 1;
dea31012005-04-17 16:05:31 -05004890 }
4891 }
dea31012005-04-17 16:05:31 -05004892 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04004893 if (logerr) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004894 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart98c9ea52007-10-27 13:37:33 -04004895 "0137 No retry ELS command x%x to remote "
4896 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4897 cmd, did, irsp->ulpStatus,
4898 irsp->un.ulpWord[4]);
4899 }
4900 else {
4901 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04004902 "0108 No retry ELS command x%x to remote "
4903 "NPORT x%x Retried:%d Error:x%x/%x\n",
4904 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4905 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04004906 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004907 return 0;
dea31012005-04-17 16:05:31 -05004908}
4909
James Smarte59058c2008-08-24 21:49:00 -04004910/**
James Smart3621a712009-04-06 18:47:14 -04004911 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04004912 * @phba: pointer to lpfc hba data structure.
4913 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4914 *
4915 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4916 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4917 * checks to see whether there is a lpfc DMA buffer associated with the
4918 * response of the command IOCB. If so, it will be released before releasing
4919 * the lpfc DMA buffer associated with the IOCB itself.
4920 *
4921 * Return code
4922 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4923 **/
James Smart09372822008-01-11 01:52:54 -05004924static int
James Smart87af33f2007-10-27 13:37:43 -04004925lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4926{
4927 struct lpfc_dmabuf *buf_ptr;
4928
James Smarte59058c2008-08-24 21:49:00 -04004929 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04004930 if (!list_empty(&buf_ptr1->list)) {
4931 list_remove_head(&buf_ptr1->list, buf_ptr,
4932 struct lpfc_dmabuf,
4933 list);
4934 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4935 kfree(buf_ptr);
4936 }
4937 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4938 kfree(buf_ptr1);
4939 return 0;
4940}
4941
James Smarte59058c2008-08-24 21:49:00 -04004942/**
James Smart3621a712009-04-06 18:47:14 -04004943 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04004944 * @phba: pointer to lpfc hba data structure.
4945 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4946 *
4947 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4948 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4949 * pool.
4950 *
4951 * Return code
4952 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4953 **/
James Smart09372822008-01-11 01:52:54 -05004954static int
James Smart87af33f2007-10-27 13:37:43 -04004955lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4956{
4957 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4958 kfree(buf_ptr);
4959 return 0;
4960}
4961
James Smarte59058c2008-08-24 21:49:00 -04004962/**
James Smart3621a712009-04-06 18:47:14 -04004963 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04004964 * @phba: pointer to lpfc hba data structure.
4965 * @elsiocb: pointer to lpfc els command iocb data structure.
4966 *
4967 * This routine frees a command IOCB and its associated resources. The
4968 * command IOCB data structure contains the reference to various associated
4969 * resources, these fields must be set to NULL if the associated reference
4970 * not present:
4971 * context1 - reference to ndlp
4972 * context2 - reference to cmd
4973 * context2->next - reference to rsp
4974 * context3 - reference to bpl
4975 *
4976 * It first properly decrements the reference count held on ndlp for the
4977 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4978 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4979 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4980 * adds the DMA buffer the @phba data structure for the delayed release.
4981 * If reference to the Buffer Pointer List (BPL) is present, the
4982 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4983 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4984 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4985 *
4986 * Return code
4987 * 0 - Success (currently, always return 0)
4988 **/
James Smart87af33f2007-10-27 13:37:43 -04004989int
James Smart329f9bc2007-04-25 09:53:01 -04004990lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004991{
4992 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4993
James Smart9064aeb2021-08-16 09:28:50 -07004994 /* The I/O iocb is complete. Clear the context1 data. */
James Smart4430f7f2020-11-15 11:26:31 -08004995 elsiocb->context1 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04004996
dea31012005-04-17 16:05:31 -05004997 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4998 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05004999 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
5000 /* Firmware could still be in progress of DMAing
5001 * payload, so don't free data buffer till after
5002 * a hbeat.
5003 */
5004 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
5005 buf_ptr = elsiocb->context2;
5006 elsiocb->context2 = NULL;
5007 if (buf_ptr) {
5008 buf_ptr1 = NULL;
5009 spin_lock_irq(&phba->hbalock);
5010 if (!list_empty(&buf_ptr->list)) {
5011 list_remove_head(&buf_ptr->list,
5012 buf_ptr1, struct lpfc_dmabuf,
5013 list);
5014 INIT_LIST_HEAD(&buf_ptr1->list);
5015 list_add_tail(&buf_ptr1->list,
5016 &phba->elsbuf);
5017 phba->elsbuf_cnt++;
5018 }
5019 INIT_LIST_HEAD(&buf_ptr->list);
5020 list_add_tail(&buf_ptr->list, &phba->elsbuf);
5021 phba->elsbuf_cnt++;
5022 spin_unlock_irq(&phba->hbalock);
5023 }
5024 } else {
5025 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
5026 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01005027 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05005028 }
dea31012005-04-17 16:05:31 -05005029 }
5030
5031 if (elsiocb->context3) {
5032 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04005033 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01005034 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05005035 }
James Bottomley604a3e32005-10-29 10:28:33 -05005036 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05005037 return 0;
5038}
5039
James Smarte59058c2008-08-24 21:49:00 -04005040/**
James Smart3621a712009-04-06 18:47:14 -04005041 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04005042 * @phba: pointer to lpfc hba data structure.
5043 * @cmdiocb: pointer to lpfc command iocb data structure.
5044 * @rspiocb: pointer to lpfc response iocb data structure.
5045 *
5046 * This routine is the completion callback function to the Logout (LOGO)
5047 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5048 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
5049 * release the ndlp if it has the last reference remaining (reference count
5050 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
5051 * field to NULL to inform the following lpfc_els_free_iocb() routine no
5052 * ndlp reference count needs to be decremented. Otherwise, the ndlp
5053 * reference use-count shall be decremented by the lpfc_els_free_iocb()
5054 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
5055 * IOCB data structure.
5056 **/
dea31012005-04-17 16:05:31 -05005057static void
James Smart2e0fef82007-06-17 19:56:36 -05005058lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5059 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05005060{
James Smart2e0fef82007-06-17 19:56:36 -05005061 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5062 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05005063 IOCB_t *irsp;
5064
5065 irsp = &rspiocb->iocb;
5066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5067 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5068 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05005069 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005070 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart3bfab8a2021-04-11 18:31:23 -07005071 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
James Smarte8b62012007-08-02 11:10:09 -04005072 "Data: x%x x%x x%x\n",
James Smarta70e63e2020-11-15 11:26:38 -08005073 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
5074 ndlp->nlp_state, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04005075
James Smartfe83e3b2021-05-14 12:55:54 -07005076 /* This clause allows the LOGO ACC to complete and free resources
5077 * for the Fabric Domain Controller. It does deliberately skip
5078 * the unreg_rpi and release rpi because some fabrics send RDP
5079 * requests after logging out from the initiator.
5080 */
5081 if (ndlp->nlp_type & NLP_FABRIC &&
5082 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
5083 goto out;
5084
James Smart87af33f2007-10-27 13:37:43 -04005085 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
James Smarte77803b2021-07-07 11:43:36 -07005086
5087 /* If PLOGI is being retried, PLOGI completion will cleanup the
5088 * node. The NLP_NPR_2B_DISC flag needs to be retained to make
5089 * progress on nodes discovered from last RSCN.
5090 */
5091 if ((ndlp->nlp_flag & NLP_DELAY_TMO) &&
5092 (ndlp->nlp_last_elscmd == ELS_CMD_PLOGI))
5093 goto out;
5094
James Smart87af33f2007-10-27 13:37:43 -04005095 /* NPort Recovery mode or node is just allocated */
5096 if (!lpfc_nlp_not_used(ndlp)) {
James Smart01131e72021-05-14 12:55:49 -07005097 /* A LOGO is completing and the node is in NPR state.
James Smart0956ba62021-11-23 08:56:46 -08005098 * Just unregister the RPI because the node is still
5099 * required.
James Smart87af33f2007-10-27 13:37:43 -04005100 */
5101 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005102 } else {
5103 /* Indicate the node has already released, should
5104 * not reference to it from within lpfc_els_free_iocb.
5105 */
5106 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04005107 }
dea31012005-04-17 16:05:31 -05005108 }
James Smartfe83e3b2021-05-14 12:55:54 -07005109 out:
James Smart73d91e52011-10-10 21:32:10 -04005110 /*
5111 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05005112 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04005113 */
dea31012005-04-17 16:05:31 -05005114 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08005115 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005116}
5117
James Smarte59058c2008-08-24 21:49:00 -04005118/**
James Smart3621a712009-04-06 18:47:14 -04005119 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005120 * @phba: pointer to lpfc hba data structure.
5121 * @pmb: pointer to the driver internal queue element for mailbox command.
5122 *
5123 * This routine is the completion callback function for unregister default
5124 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5125 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5126 * decrements the ndlp reference count held for this completion callback
5127 * function. After that, it invokes the lpfc_nlp_not_used() to check
5128 * whether there is only one reference left on the ndlp. If so, it will
5129 * perform one more decrement and trigger the release of the ndlp.
5130 **/
James Smart858c9f62007-06-17 19:56:39 -05005131void
5132lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5133{
James Smart3e1f0712018-11-29 16:09:29 -08005134 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5135 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart01131e72021-05-14 12:55:49 -07005136 u32 mbx_flag = pmb->mbox_flag;
5137 u32 mbx_cmd = pmb->u.mb.mbxCommand;
James Smart858c9f62007-06-17 19:56:39 -05005138
James Smart3e1f0712018-11-29 16:09:29 -08005139 pmb->ctx_buf = NULL;
5140 pmb->ctx_ndlp = NULL;
James Smartd439d282010-09-29 11:18:45 -04005141
James Smart01131e72021-05-14 12:55:49 -07005142 if (ndlp) {
5143 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5144 "0006 rpi x%x DID:%x flg:%x %d x%px "
5145 "mbx_cmd x%x mbx_flag x%x x%px\n",
5146 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5147 kref_read(&ndlp->kref), ndlp, mbx_cmd,
5148 mbx_flag, pmb);
5149
5150 /* This ends the default/temporary RPI cleanup logic for this
5151 * ndlp and the node and rpi needs to be released. Free the rpi
5152 * first on an UNREG_LOGIN and then release the final
5153 * references.
5154 */
5155 spin_lock_irq(&ndlp->lock);
5156 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5157 if (mbx_cmd == MBX_UNREG_LOGIN)
5158 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5159 spin_unlock_irq(&ndlp->lock);
5160 lpfc_nlp_put(ndlp);
5161 lpfc_drop_node(ndlp->vport, ndlp);
5162 }
5163
James Smart858c9f62007-06-17 19:56:39 -05005164 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5165 kfree(mp);
5166 mempool_free(pmb, phba->mbox_mem_pool);
James Smart858c9f62007-06-17 19:56:39 -05005167 return;
5168}
5169
James Smarte59058c2008-08-24 21:49:00 -04005170/**
James Smart3621a712009-04-06 18:47:14 -04005171 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005172 * @phba: pointer to lpfc hba data structure.
5173 * @cmdiocb: pointer to lpfc command iocb data structure.
5174 * @rspiocb: pointer to lpfc response iocb data structure.
5175 *
5176 * This routine is the completion callback function for ELS Response IOCB
5177 * command. In normal case, this callback function just properly sets the
5178 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5179 * field in the command IOCB is not NULL, the referred mailbox command will
5180 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
James Smartf866eb02021-04-11 18:31:14 -07005181 * the IOCB.
James Smarte59058c2008-08-24 21:49:00 -04005182 **/
dea31012005-04-17 16:05:31 -05005183static void
James Smart858c9f62007-06-17 19:56:39 -05005184lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04005185 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05005186{
James Smart2e0fef82007-06-17 19:56:36 -05005187 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5188 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
5189 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04005190 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05005191 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005192 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05005193
James Smart33ccf8d2006-08-17 11:57:58 -04005194 irsp = &rspiocb->iocb;
5195
James Smart43bfea12019-09-21 20:58:57 -07005196 if (!vport) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005197 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartf84f8f92019-10-18 14:18:23 -07005198 "3177 ELS response failed\n");
James Smart43bfea12019-09-21 20:58:57 -07005199 goto out;
5200 }
dea31012005-04-17 16:05:31 -05005201 if (cmdiocb->context_un.mbox)
5202 mbox = cmdiocb->context_un.mbox;
5203
dea31012005-04-17 16:05:31 -05005204 /* Check to see if link went down during discovery */
James Smart307e3382020-11-15 11:26:30 -08005205 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05005206 if (mbox) {
James Smart3e1f0712018-11-29 16:09:29 -08005207 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05005208 if (mp) {
5209 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5210 kfree(mp);
5211 }
James Smart329f9bc2007-04-25 09:53:01 -04005212 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005213 }
5214 goto out;
5215 }
5216
James Smart858c9f62007-06-17 19:56:39 -05005217 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04005218 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05005219 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04005220 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05005221 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04005222 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5223 "0110 ELS response tag x%x completes "
James Smart01131e72021-05-14 12:55:49 -07005224 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005225 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
5226 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
5227 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smart01131e72021-05-14 12:55:49 -07005228 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox);
dea31012005-04-17 16:05:31 -05005229 if (mbox) {
James Smart4430f7f2020-11-15 11:26:31 -08005230 if ((rspiocb->iocb.ulpStatus == 0) &&
5231 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07005232 if (!lpfc_unreg_rpi(vport, ndlp) &&
James Smart4430f7f2020-11-15 11:26:31 -08005233 (!(vport->fc_flag & FC_PT2PT))) {
5234 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
5235 lpfc_printf_vlog(vport, KERN_INFO,
5236 LOG_DISCOVERY,
5237 "0314 PLOGI recov "
5238 "DID x%x "
5239 "Data: x%x x%x x%x\n",
5240 ndlp->nlp_DID,
5241 ndlp->nlp_state,
5242 ndlp->nlp_rpi,
5243 ndlp->nlp_flag);
5244 mp = mbox->ctx_buf;
5245 if (mp) {
5246 lpfc_mbuf_free(phba, mp->virt,
5247 mp->phys);
5248 kfree(mp);
5249 }
5250 mempool_free(mbox, phba->mbox_mem_pool);
5251 goto out;
Dick Kennedy1fe68472017-08-23 16:55:30 -07005252 }
Dick Kennedy1fe68472017-08-23 16:55:30 -07005253 }
5254
James Smarte47c9092008-02-08 18:49:26 -05005255 /* Increment reference count to ndlp to hold the
5256 * reference to ndlp for the callback function.
5257 */
James Smart3e1f0712018-11-29 16:09:29 -08005258 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08005259 if (!mbox->ctx_ndlp)
5260 goto out;
5261
James Smart2e0fef82007-06-17 19:56:36 -05005262 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005263 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
5264 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5265 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5266 }
5267 else {
5268 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
5269 ndlp->nlp_prev_state = ndlp->nlp_state;
5270 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05005271 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05005272 }
James Smart4b7789b72015-12-16 18:11:55 -05005273
5274 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04005275 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05005276 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05005277 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05005278
5279 /* Decrement the ndlp reference count we
5280 * set for this failed mailbox command.
5281 */
5282 lpfc_nlp_put(ndlp);
5283 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04005284
5285 /* ELS rsp: Cannot issue reg_login for <NPortid> */
Dick Kennedy372c1872020-06-30 14:50:00 -07005286 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart98c9ea52007-10-27 13:37:33 -04005287 "0138 ELS rsp: Cannot issue reg_login for x%x "
5288 "Data: x%x x%x x%x\n",
5289 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5290 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005291 }
James Smart3e1f0712018-11-29 16:09:29 -08005292 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05005293 if (mp) {
5294 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5295 kfree(mp);
5296 }
5297 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005298 }
5299out:
James Smart307e3382020-11-15 11:26:30 -08005300 if (ndlp && shost) {
James Smartc6adba12020-11-15 11:26:34 -08005301 spin_lock_irq(&ndlp->lock);
James Smart7b08e892020-08-28 10:53:30 -07005302 if (mbox)
5303 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
5304 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
James Smartc6adba12020-11-15 11:26:34 -08005305 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005306 }
James Smart87af33f2007-10-27 13:37:43 -04005307
James Smart01131e72021-05-14 12:55:49 -07005308 /* An SLI4 NPIV instance wants to drop the node at this point under
5309 * these conditions and release the RPI.
5310 */
5311 if (phba->sli_rev == LPFC_SLI_REV4 &&
5312 (vport && vport->port_type == LPFC_NPIV_PORT) &&
James Smart20d22792021-09-10 16:31:48 -07005313 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) &&
James Smart01131e72021-05-14 12:55:49 -07005314 ndlp->nlp_flag & NLP_RELEASE_RPI) {
5315 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart4012bae2021-05-14 12:55:53 -07005316 spin_lock_irq(&ndlp->lock);
5317 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5318 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5319 spin_unlock_irq(&ndlp->lock);
James Smart01131e72021-05-14 12:55:49 -07005320 lpfc_drop_node(vport, ndlp);
5321 }
5322
James Smart4430f7f2020-11-15 11:26:31 -08005323 /* Release the originating I/O reference. */
dea31012005-04-17 16:05:31 -05005324 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08005325 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005326 return;
5327}
5328
James Smarte59058c2008-08-24 21:49:00 -04005329/**
James Smart3621a712009-04-06 18:47:14 -04005330 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005331 * @vport: pointer to a host virtual N_Port data structure.
5332 * @flag: the els command code to be accepted.
5333 * @oldiocb: pointer to the original lpfc command iocb data structure.
5334 * @ndlp: pointer to a node-list data structure.
5335 * @mbox: pointer to the driver internal queue element for mailbox command.
5336 *
5337 * This routine prepares and issues an Accept (ACC) response IOCB
5338 * command. It uses the @flag to properly set up the IOCB field for the
5339 * specific ACC response command to be issued and invokes the
5340 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5341 * @mbox pointer is passed in, it will be put into the context_un.mbox
5342 * field of the IOCB for the completion callback function to issue the
5343 * mailbox command to the HBA later when callback is invoked.
5344 *
James Smart69b8eff2021-03-01 09:18:19 -08005345 * Note that the ndlp reference count will be incremented by 1 for holding the
5346 * ndlp and the reference to ndlp will be stored into the context1 field of
5347 * the IOCB for the completion callback function to the corresponding
5348 * response ELS IOCB command.
James Smarte59058c2008-08-24 21:49:00 -04005349 *
5350 * Return code
5351 * 0 - Successfully issued acc response
5352 * 1 - Failed to issue acc response
5353 **/
dea31012005-04-17 16:05:31 -05005354int
James Smart2e0fef82007-06-17 19:56:36 -05005355lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
5356 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04005357 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05005358{
James Smart2e0fef82007-06-17 19:56:36 -05005359 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005360 IOCB_t *icmd;
5361 IOCB_t *oldcmd;
5362 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005363 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05005364 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05005365 uint16_t cmdsize;
5366 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04005367 ELS_PKT *els_pkt_ptr;
James Smart8eced802021-05-14 12:55:58 -07005368 struct fc_els_rdf_resp *rdf_resp;
dea31012005-04-17 16:05:31 -05005369
dea31012005-04-17 16:05:31 -05005370 oldcmd = &oldiocb->iocb;
5371
5372 switch (flag) {
5373 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05005374 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05005375 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5376 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005377 if (!elsiocb) {
James Smartc6adba12020-11-15 11:26:34 -08005378 spin_lock_irq(&ndlp->lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005379 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smartc6adba12020-11-15 11:26:34 -08005380 spin_unlock_irq(&ndlp->lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005381 return 1;
dea31012005-04-17 16:05:31 -05005382 }
James Smart2e0fef82007-06-17 19:56:36 -05005383
dea31012005-04-17 16:05:31 -05005384 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005385 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5386 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05005387 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5388 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005389 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05005390
5391 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5392 "Issue ACC: did:x%x flg:x%x",
5393 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05005394 break;
James Smartd6de08c2015-12-16 18:11:53 -05005395 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05005396 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05005397 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05005398 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5399 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005400 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005401 return 1;
James Smart488d1462006-03-07 15:02:37 -05005402
dea31012005-04-17 16:05:31 -05005403 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005404 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5405 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05005406 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5407
5408 if (mbox)
5409 elsiocb->context_un.mbox = mbox;
5410
5411 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005412 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05005413 sp = (struct serv_parm *)pcmd;
5414
5415 if (flag == ELS_CMD_FLOGI) {
5416 /* Copy the received service parameters back */
5417 memcpy(sp, &phba->fc_fabparam,
5418 sizeof(struct serv_parm));
5419
5420 /* Clear the F_Port bit */
5421 sp->cmn.fPort = 0;
5422
5423 /* Mark all class service parameters as invalid */
5424 sp->cls1.classValid = 0;
5425 sp->cls2.classValid = 0;
5426 sp->cls3.classValid = 0;
5427 sp->cls4.classValid = 0;
5428
5429 /* Copy our worldwide names */
5430 memcpy(&sp->portName, &vport->fc_sparam.portName,
5431 sizeof(struct lpfc_name));
5432 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
5433 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08005434 } else {
James Smartd6de08c2015-12-16 18:11:53 -05005435 memcpy(pcmd, &vport->fc_sparam,
5436 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08005437
James Smart8c258642017-02-12 13:52:36 -08005438 sp->cmn.valid_vendor_ver_level = 0;
5439 memset(sp->un.vendorVersion, 0,
5440 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07005441 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08005442
5443 /* If our firmware supports this feature, convey that
5444 * info to the target using the vendor specific field.
5445 */
5446 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
5447 sp->cmn.valid_vendor_ver_level = 1;
5448 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
5449 sp->un.vv.flags =
5450 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
5451 }
5452 }
5453
James Smart858c9f62007-06-17 19:56:39 -05005454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05005455 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05005456 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05005457 break;
James Smart82d9a2a2006-04-15 11:53:05 -04005458 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05005459 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05005460 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04005461 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
5462 if (!elsiocb)
5463 return 1;
5464
5465 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005466 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5467 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04005468 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5469
5470 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05005471 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04005472 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
5473 els_pkt_ptr = (ELS_PKT *) pcmd;
5474 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05005475
5476 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5477 "Issue ACC PRLO: did:x%x flg:x%x",
5478 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04005479 break;
James Smart8eced802021-05-14 12:55:58 -07005480 case ELS_CMD_RDF:
5481 cmdsize = sizeof(*rdf_resp);
5482 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5483 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5484 if (!elsiocb)
5485 return 1;
5486
5487 icmd = &elsiocb->iocb;
5488 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5489 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5490 pcmd = (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5491 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5492 memset(rdf_resp, 0, sizeof(*rdf_resp));
5493 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5494
5495 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5496 rdf_resp->desc_list_len = cpu_to_be32(12);
5497
5498 /* FC-LS-5 specifies LS REQ Information descriptor */
5499 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5500 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5501 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5502 break;
dea31012005-04-17 16:05:31 -05005503 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005504 return 1;
dea31012005-04-17 16:05:31 -05005505 }
dea31012005-04-17 16:05:31 -05005506 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smartc6adba12020-11-15 11:26:34 -08005507 spin_lock_irq(&ndlp->lock);
James Smart7c5e5182015-05-22 10:42:43 -04005508 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5509 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
5510 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smartc6adba12020-11-15 11:26:34 -08005511 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005512 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
5513 } else {
James Smart858c9f62007-06-17 19:56:39 -05005514 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05005515 }
5516
5517 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08005518 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08005519 if (!elsiocb->context1) {
5520 lpfc_els_free_iocb(phba, elsiocb);
5521 return 1;
5522 }
James Smart4430f7f2020-11-15 11:26:31 -08005523
James Smart3772a992009-05-22 14:50:54 -04005524 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08005525 if (rc == IOCB_ERROR) {
5526 lpfc_els_free_iocb(phba, elsiocb);
5527 lpfc_nlp_put(ndlp);
5528 return 1;
5529 }
James Smart4430f7f2020-11-15 11:26:31 -08005530
5531 /* Xmit ELS ACC response tag <ulpIoTag> */
5532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5533 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5534 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
James Smart01131e72021-05-14 12:55:49 -07005535 "RPI: x%x, fc_flag x%x refcnt %d\n",
James Smart4430f7f2020-11-15 11:26:31 -08005536 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5537 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smart01131e72021-05-14 12:55:49 -07005538 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005539 return 0;
dea31012005-04-17 16:05:31 -05005540}
5541
James Smarte59058c2008-08-24 21:49:00 -04005542/**
James Smart3bfab8a2021-04-11 18:31:23 -07005543 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005544 * @vport: pointer to a virtual N_Port data structure.
Lee Jonesa0e4a642020-07-23 13:24:07 +01005545 * @rejectError: reject response to issue
James Smarte59058c2008-08-24 21:49:00 -04005546 * @oldiocb: pointer to the original lpfc command iocb data structure.
5547 * @ndlp: pointer to a node-list data structure.
5548 * @mbox: pointer to the driver internal queue element for mailbox command.
5549 *
5550 * This routine prepares and issue an Reject (RJT) response IOCB
5551 * command. If a @mbox pointer is passed in, it will be put into the
5552 * context_un.mbox field of the IOCB for the completion callback function
5553 * to issue to the HBA later.
5554 *
James Smart69b8eff2021-03-01 09:18:19 -08005555 * Note that the ndlp reference count will be incremented by 1 for holding the
5556 * ndlp and the reference to ndlp will be stored into the context1 field of
5557 * the IOCB for the completion callback function to the reject response
5558 * ELS IOCB command.
James Smarte59058c2008-08-24 21:49:00 -04005559 *
5560 * Return code
5561 * 0 - Successfully issued reject response
5562 * 1 - Failed to issue reject response
5563 **/
dea31012005-04-17 16:05:31 -05005564int
James Smart2e0fef82007-06-17 19:56:36 -05005565lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05005566 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5567 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05005568{
James Smart4430f7f2020-11-15 11:26:31 -08005569 int rc;
James Smart2e0fef82007-06-17 19:56:36 -05005570 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005571 IOCB_t *icmd;
5572 IOCB_t *oldcmd;
5573 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005574 uint8_t *pcmd;
5575 uint16_t cmdsize;
dea31012005-04-17 16:05:31 -05005576
James Smart92d7f7b2007-06-17 19:56:38 -05005577 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05005578 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5579 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05005580 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005581 return 1;
dea31012005-04-17 16:05:31 -05005582
5583 icmd = &elsiocb->iocb;
5584 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005585 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5586 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05005587 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5588
5589 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05005590 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005591 *((uint32_t *) (pcmd)) = rejectError;
5592
James Smart51ef4c22007-08-02 11:10:31 -04005593 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05005594 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05005595
dea31012005-04-17 16:05:31 -05005596 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005597 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5598 "0129 Xmit ELS RJT x%x response tag x%x "
5599 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5600 "rpi x%x\n",
5601 rejectError, elsiocb->iotag,
5602 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
5603 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5605 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5606 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5607
dea31012005-04-17 16:05:31 -05005608 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05005609 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005610 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08005611 if (!elsiocb->context1) {
5612 lpfc_els_free_iocb(phba, elsiocb);
5613 return 1;
5614 }
James Smart51ef4c22007-08-02 11:10:31 -04005615
James Smart01131e72021-05-14 12:55:49 -07005616 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
James Smart20d22792021-09-10 16:31:48 -07005617 * node's assigned RPI gets released provided this node is not already
5618 * registered with the transport.
James Smart01131e72021-05-14 12:55:49 -07005619 */
5620 if (phba->sli_rev == LPFC_SLI_REV4 &&
James Smart20d22792021-09-10 16:31:48 -07005621 vport->port_type == LPFC_NPIV_PORT &&
5622 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
James Smart01131e72021-05-14 12:55:49 -07005623 spin_lock_irq(&ndlp->lock);
5624 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5625 spin_unlock_irq(&ndlp->lock);
5626 }
5627
James Smart4430f7f2020-11-15 11:26:31 -08005628 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08005629 if (rc == IOCB_ERROR) {
5630 lpfc_els_free_iocb(phba, elsiocb);
5631 lpfc_nlp_put(ndlp);
5632 return 1;
5633 }
James Smart4430f7f2020-11-15 11:26:31 -08005634
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005635 return 0;
dea31012005-04-17 16:05:31 -05005636}
5637
James Smart9064aeb2021-08-16 09:28:50 -07005638 /**
5639 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5640 * @vport: pointer to a host virtual N_Port data structure.
5641 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5642 * @ndlp: NPort to where rsp is directed
5643 *
5644 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5645 * this N_Port's support of hardware signals in its Congestion
5646 * Capabilities Descriptor.
5647 *
5648 * Return code
5649 * 0 - Successfully issued edc rsp command
5650 * 1 - Failed to issue edc rsp command
5651 **/
5652static int
5653lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5654 struct lpfc_nodelist *ndlp)
5655{
5656 struct lpfc_hba *phba = vport->phba;
5657 struct lpfc_els_edc_rsp *edc_rsp;
5658 struct lpfc_iocbq *elsiocb;
5659 IOCB_t *icmd, *cmd;
5660 uint8_t *pcmd;
5661 int cmdsize, rc;
5662
5663 cmdsize = sizeof(struct lpfc_els_edc_rsp);
5664 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
5665 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5666 if (!elsiocb)
5667 return 1;
5668
5669 icmd = &elsiocb->iocb;
5670 cmd = &cmdiocb->iocb;
5671 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
5672 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
5673 pcmd = (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5674 memset(pcmd, 0, cmdsize);
5675
5676 edc_rsp = (struct lpfc_els_edc_rsp *)pcmd;
5677 edc_rsp->edc_rsp.acc_hdr.la_cmd = ELS_LS_ACC;
5678 edc_rsp->edc_rsp.desc_list_len = cpu_to_be32(
5679 FC_TLV_DESC_LENGTH_FROM_SZ(struct lpfc_els_edc_rsp));
5680 edc_rsp->edc_rsp.lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
5681 edc_rsp->edc_rsp.lsri.desc_len = cpu_to_be32(
5682 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
5683 edc_rsp->edc_rsp.lsri.rqst_w0.cmd = ELS_EDC;
5684 lpfc_format_edc_cgn_desc(phba, &edc_rsp->cgn_desc);
5685
5686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5687 "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
5688 ndlp->nlp_DID, ndlp->nlp_flag,
5689 kref_read(&ndlp->kref));
5690 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5691
5692 phba->fc_stat.elsXmitACC++;
5693 elsiocb->context1 = lpfc_nlp_get(ndlp);
5694 if (!elsiocb->context1) {
5695 lpfc_els_free_iocb(phba, elsiocb);
5696 return 1;
5697 }
5698
5699 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5700 if (rc == IOCB_ERROR) {
5701 lpfc_els_free_iocb(phba, elsiocb);
5702 lpfc_nlp_put(ndlp);
5703 return 1;
5704 }
5705
5706 /* Xmit ELS ACC response tag <ulpIoTag> */
5707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5708 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5709 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5710 "RPI: x%x, fc_flag x%x\n",
5711 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5712 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5713 ndlp->nlp_rpi, vport->fc_flag);
5714
5715 return 0;
5716}
5717
James Smarte59058c2008-08-24 21:49:00 -04005718/**
James Smart3621a712009-04-06 18:47:14 -04005719 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005720 * @vport: pointer to a virtual N_Port data structure.
5721 * @oldiocb: pointer to the original lpfc command iocb data structure.
5722 * @ndlp: pointer to a node-list data structure.
5723 *
5724 * This routine prepares and issues an Accept (ACC) response to Address
5725 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5726 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5727 *
James Smart69b8eff2021-03-01 09:18:19 -08005728 * Note that the ndlp reference count will be incremented by 1 for holding the
5729 * ndlp and the reference to ndlp will be stored into the context1 field of
5730 * the IOCB for the completion callback function to the ADISC Accept response
5731 * ELS IOCB command.
James Smarte59058c2008-08-24 21:49:00 -04005732 *
5733 * Return code
5734 * 0 - Successfully issued acc adisc response
5735 * 1 - Failed to issue adisc acc response
5736 **/
dea31012005-04-17 16:05:31 -05005737int
James Smart2e0fef82007-06-17 19:56:36 -05005738lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5739 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005740{
James Smart2e0fef82007-06-17 19:56:36 -05005741 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005742 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05005743 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05005744 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005745 uint8_t *pcmd;
5746 uint16_t cmdsize;
5747 int rc;
5748
James Smart92d7f7b2007-06-17 19:56:38 -05005749 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05005750 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5751 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005752 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005753 return 1;
dea31012005-04-17 16:05:31 -05005754
dea31012005-04-17 16:05:31 -05005755 icmd = &elsiocb->iocb;
5756 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005757 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5758 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04005759
5760 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005761 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5762 "0130 Xmit ADISC ACC response iotag x%x xri: "
5763 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5764 elsiocb->iotag, elsiocb->iocb.ulpContext,
5765 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5766 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005767 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5768
5769 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005770 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005771
5772 ap = (ADISC *) (pcmd);
5773 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05005774 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5775 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05005776 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05005777
James Smart858c9f62007-06-17 19:56:39 -05005778 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005779 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5780 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005781
dea31012005-04-17 16:05:31 -05005782 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005783 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005784 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08005785 if (!elsiocb->context1) {
5786 lpfc_els_free_iocb(phba, elsiocb);
5787 return 1;
5788 }
James Smart4430f7f2020-11-15 11:26:31 -08005789
James Smart3772a992009-05-22 14:50:54 -04005790 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08005791 if (rc == IOCB_ERROR) {
5792 lpfc_els_free_iocb(phba, elsiocb);
5793 lpfc_nlp_put(ndlp);
5794 return 1;
5795 }
James Smartd496b9a2018-10-23 13:41:08 -07005796
5797 /* Xmit ELS ACC response tag <ulpIoTag> */
5798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5799 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5800 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5801 "RPI: x%x, fc_flag x%x\n",
5802 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5803 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5804 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005805 return 0;
dea31012005-04-17 16:05:31 -05005806}
5807
James Smarte59058c2008-08-24 21:49:00 -04005808/**
James Smart3621a712009-04-06 18:47:14 -04005809 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005810 * @vport: pointer to a virtual N_Port data structure.
5811 * @oldiocb: pointer to the original lpfc command iocb data structure.
5812 * @ndlp: pointer to a node-list data structure.
5813 *
5814 * This routine prepares and issues an Accept (ACC) response to Process
5815 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5816 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5817 *
James Smart69b8eff2021-03-01 09:18:19 -08005818 * Note that the ndlp reference count will be incremented by 1 for holding the
5819 * ndlp and the reference to ndlp will be stored into the context1 field of
5820 * the IOCB for the completion callback function to the PRLI Accept response
5821 * ELS IOCB command.
James Smarte59058c2008-08-24 21:49:00 -04005822 *
5823 * Return code
5824 * 0 - Successfully issued acc prli response
5825 * 1 - Failed to issue acc prli response
5826 **/
dea31012005-04-17 16:05:31 -05005827int
James Smart2e0fef82007-06-17 19:56:36 -05005828lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04005829 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005830{
James Smart2e0fef82007-06-17 19:56:36 -05005831 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005832 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08005833 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05005834 lpfc_vpd_t *vpd;
5835 IOCB_t *icmd;
5836 IOCB_t *oldcmd;
5837 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005838 uint8_t *pcmd;
5839 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08005840 uint32_t prli_fc4_req, *req_payload;
5841 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05005842 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08005843 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05005844
James Smarta0f2d3e2017-02-12 13:52:31 -08005845 /* Need the incoming PRLI payload to determine if the ACC is for an
5846 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5847 */
5848 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5849 req_payload = (((uint32_t *)req_buf->virt) + 1);
5850
5851 /* PRLI type payload is at byte 3 for FCP or NVME. */
5852 prli_fc4_req = be32_to_cpu(*req_payload);
5853 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5854 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5855 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5856 prli_fc4_req, *((uint32_t *)req_payload));
5857
5858 if (prli_fc4_req == PRLI_FCP_TYPE) {
5859 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5860 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5861 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5862 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5863 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5864 } else {
5865 return 1;
5866 }
5867
James Smart2e0fef82007-06-17 19:56:36 -05005868 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08005869 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005870 if (!elsiocb)
5871 return 1;
dea31012005-04-17 16:05:31 -05005872
dea31012005-04-17 16:05:31 -05005873 icmd = &elsiocb->iocb;
5874 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005875 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5876 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5877
James Smart5b8bd0c2007-04-25 09:52:49 -04005878 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5880 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5881 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5882 elsiocb->iotag, elsiocb->iocb.ulpContext,
5883 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5884 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005885 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08005886 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05005887
James Smartc07f10c2017-04-21 16:04:54 -07005888 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005889 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005890
5891 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05005892 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08005893
5894 if (prli_fc4_req == PRLI_FCP_TYPE) {
5895 /*
5896 * If the remote port is a target and our firmware version
5897 * is 3.20 or later, set the following bits for FC-TAPE
5898 * support.
5899 */
5900 npr = (PRLI *) pcmd;
5901 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5902 (vpd->rev.feaLevelHigh >= 0x02)) {
5903 npr->ConfmComplAllowed = 1;
5904 npr->Retry = 1;
5905 npr->TaskRetryIdReq = 1;
5906 }
5907 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5908 npr->estabImagePair = 1;
5909 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05005910 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08005911 npr->prliType = PRLI_FCP_TYPE;
5912 npr->initiatorFunc = 1;
5913 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5914 /* Respond with an NVME PRLI Type */
5915 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5916 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5917 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5918 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08005919 if (phba->nvmet_support) {
5920 bf_set(prli_tgt, npr_nvme, 1);
5921 bf_set(prli_disc, npr_nvme, 1);
5922 if (phba->cfg_nvme_enable_fb) {
5923 bf_set(prli_fba, npr_nvme, 1);
5924
5925 /* TBD. Target mode needs to post buffers
5926 * that support the configured first burst
5927 * byte size.
5928 */
5929 bf_set(prli_fb_sz, npr_nvme,
5930 phba->cfg_nvmet_fb_size);
5931 }
5932 } else {
5933 bf_set(prli_init, npr_nvme, 1);
5934 }
dea31012005-04-17 16:05:31 -05005935
James Smarta0f2d3e2017-02-12 13:52:31 -08005936 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5937 "6015 NVME issue PRLI ACC word1 x%08x "
5938 "word4 x%08x word5 x%08x flag x%x, "
5939 "fcp_info x%x nlp_type x%x\n",
5940 npr_nvme->word1, npr_nvme->word4,
5941 npr_nvme->word5, ndlp->nlp_flag,
5942 ndlp->nlp_fcp_info, ndlp->nlp_type);
5943 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5944 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5945 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5946 } else
5947 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5948 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5949 prli_fc4_req, ndlp->nlp_fc4_type,
5950 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05005951
James Smart858c9f62007-06-17 19:56:39 -05005952 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005953 "Issue ACC PRLI: did:x%x flg:x%x",
5954 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005955
dea31012005-04-17 16:05:31 -05005956 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005957 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005958 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08005959 if (!elsiocb->context1) {
5960 lpfc_els_free_iocb(phba, elsiocb);
5961 return 1;
5962 }
dea31012005-04-17 16:05:31 -05005963
James Smart3772a992009-05-22 14:50:54 -04005964 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08005965 if (rc == IOCB_ERROR) {
5966 lpfc_els_free_iocb(phba, elsiocb);
5967 lpfc_nlp_put(ndlp);
5968 return 1;
5969 }
James Smart4430f7f2020-11-15 11:26:31 -08005970
James Smart8e9a3252021-03-01 09:18:09 -08005971 return 0;
dea31012005-04-17 16:05:31 -05005972}
5973
James Smarte59058c2008-08-24 21:49:00 -04005974/**
James Smart3621a712009-04-06 18:47:14 -04005975 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005976 * @vport: pointer to a virtual N_Port data structure.
5977 * @format: rnid command format.
5978 * @oldiocb: pointer to the original lpfc command iocb data structure.
5979 * @ndlp: pointer to a node-list data structure.
5980 *
5981 * This routine issues a Request Node Identification Data (RNID) Accept
5982 * (ACC) response. It constructs the RNID ACC response command according to
5983 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
James Smart69b8eff2021-03-01 09:18:19 -08005984 * issue the response.
James Smarte59058c2008-08-24 21:49:00 -04005985 *
James Smart69b8eff2021-03-01 09:18:19 -08005986 * Note that the ndlp reference count will be incremented by 1 for holding the
5987 * ndlp and the reference to ndlp will be stored into the context1 field of
5988 * the IOCB for the completion callback function.
James Smarte59058c2008-08-24 21:49:00 -04005989 *
5990 * Return code
5991 * 0 - Successfully issued acc rnid response
5992 * 1 - Failed to issue acc rnid response
5993 **/
dea31012005-04-17 16:05:31 -05005994static int
James Smart2e0fef82007-06-17 19:56:36 -05005995lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04005996 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005997{
James Smart2e0fef82007-06-17 19:56:36 -05005998 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005999 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05006000 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05006001 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05006002 uint8_t *pcmd;
6003 uint16_t cmdsize;
6004 int rc;
6005
James Smart92d7f7b2007-06-17 19:56:38 -05006006 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
6007 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05006008 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05006009 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05006010
James Smart2e0fef82007-06-17 19:56:36 -05006011 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6012 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05006013 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006014 return 1;
dea31012005-04-17 16:05:31 -05006015
dea31012005-04-17 16:05:31 -05006016 icmd = &elsiocb->iocb;
6017 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006018 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6019 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
6020
James Smart5b8bd0c2007-04-25 09:52:49 -04006021 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006022 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6023 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6024 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05006025 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05006026 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006027 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05006028
James Smart92d7f7b2007-06-17 19:56:38 -05006029 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05006030 rn = (RNID *) (pcmd);
6031 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05006032 rn->CommonLen = (2 * sizeof(struct lpfc_name));
6033 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6034 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05006035 switch (format) {
6036 case 0:
6037 rn->SpecificLen = 0;
6038 break;
6039 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05006040 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05006041 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05006042 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05006043 rn->un.topologyDisc.unitType = RNID_HBA;
6044 rn->un.topologyDisc.physPort = 0;
6045 rn->un.topologyDisc.attachedNodes = 0;
6046 break;
6047 default:
6048 rn->CommonLen = 0;
6049 rn->SpecificLen = 0;
6050 break;
6051 }
6052
James Smart858c9f62007-06-17 19:56:39 -05006053 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08006054 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
6055 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05006056
dea31012005-04-17 16:05:31 -05006057 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05006058 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08006059 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08006060 if (!elsiocb->context1) {
6061 lpfc_els_free_iocb(phba, elsiocb);
6062 return 1;
6063 }
dea31012005-04-17 16:05:31 -05006064
James Smart3772a992009-05-22 14:50:54 -04006065 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08006066 if (rc == IOCB_ERROR) {
6067 lpfc_els_free_iocb(phba, elsiocb);
6068 lpfc_nlp_put(ndlp);
6069 return 1;
6070 }
James Smart4430f7f2020-11-15 11:26:31 -08006071
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006072 return 0;
dea31012005-04-17 16:05:31 -05006073}
6074
James Smarte59058c2008-08-24 21:49:00 -04006075/**
James Smart19ca7602010-11-20 23:11:55 -05006076 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6077 * @vport: pointer to a virtual N_Port data structure.
6078 * @iocb: pointer to the lpfc command iocb data structure.
6079 * @ndlp: pointer to a node-list data structure.
6080 *
6081 * Return
6082 **/
6083static void
6084lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08006085 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05006086{
6087 struct lpfc_hba *phba = vport->phba;
6088 uint8_t *pcmd;
6089 struct RRQ *rrq;
6090 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05006091 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05006092 struct lpfc_node_rrq *prrq;
6093
6094
6095 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
6096 pcmd += sizeof(uint32_t);
6097 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05006098 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04006099 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05006100
6101 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6102 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6103 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05006104 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04006105 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05006106 rxid,
6107 iocb->iotag, iocb->iocb.ulpContext);
6108
6109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6110 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
6111 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05006112 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04006113 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05006114 else
6115 xri = rxid;
6116 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05006117 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05006118 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05006119 return;
6120}
6121
6122/**
James Smart12265f62010-10-22 11:05:53 -04006123 * lpfc_els_rsp_echo_acc - Issue echo acc response
6124 * @vport: pointer to a virtual N_Port data structure.
6125 * @data: pointer to echo data to return in the accept.
6126 * @oldiocb: pointer to the original lpfc command iocb data structure.
6127 * @ndlp: pointer to a node-list data structure.
6128 *
6129 * Return code
6130 * 0 - Successfully issued acc echo response
6131 * 1 - Failed to issue acc echo response
6132 **/
6133static int
6134lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
6135 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6136{
6137 struct lpfc_hba *phba = vport->phba;
6138 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04006139 uint8_t *pcmd;
6140 uint16_t cmdsize;
6141 int rc;
6142
James Smart12265f62010-10-22 11:05:53 -04006143 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
6144
James Smartbf086112011-08-21 21:48:13 -04006145 /* The accumulated length can exceed the BPL_SIZE. For
6146 * now, use this as the limit
6147 */
6148 if (cmdsize > LPFC_BPL_SIZE)
6149 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04006150 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6151 ndlp->nlp_DID, ELS_CMD_ACC);
6152 if (!elsiocb)
6153 return 1;
6154
James Smart7851fe22011-07-22 18:36:52 -04006155 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
6156 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
6157
James Smart12265f62010-10-22 11:05:53 -04006158 /* Xmit ECHO ACC response tag <ulpIoTag> */
6159 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6160 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6161 elsiocb->iotag, elsiocb->iocb.ulpContext);
6162 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6163 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6164 pcmd += sizeof(uint32_t);
6165 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
6166
6167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08006168 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
6169 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart12265f62010-10-22 11:05:53 -04006170
6171 phba->fc_stat.elsXmitACC++;
6172 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08006173 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08006174 if (!elsiocb->context1) {
6175 lpfc_els_free_iocb(phba, elsiocb);
6176 return 1;
6177 }
James Smart12265f62010-10-22 11:05:53 -04006178
6179 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08006180 if (rc == IOCB_ERROR) {
6181 lpfc_els_free_iocb(phba, elsiocb);
6182 lpfc_nlp_put(ndlp);
6183 return 1;
6184 }
James Smart4430f7f2020-11-15 11:26:31 -08006185
James Smart8e9a3252021-03-01 09:18:09 -08006186 return 0;
James Smart12265f62010-10-22 11:05:53 -04006187}
6188
6189/**
James Smart3621a712009-04-06 18:47:14 -04006190 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04006191 * @vport: pointer to a host virtual N_Port data structure.
6192 *
6193 * This routine issues Address Discover (ADISC) ELS commands to those
6194 * N_Ports which are in node port recovery state and ADISC has not been issued
6195 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6196 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6197 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6198 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6199 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6200 * IOCBs quit for later pick up. On the other hand, after walking through
6201 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6202 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6203 * no more ADISC need to be sent.
6204 *
6205 * Return code
6206 * The number of N_Ports with adisc issued.
6207 **/
dea31012005-04-17 16:05:31 -05006208int
James Smart2e0fef82007-06-17 19:56:36 -05006209lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006210{
James Smart2e0fef82007-06-17 19:56:36 -05006211 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006212 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006213 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05006214
James Smart685f0bf2007-04-25 09:53:08 -04006215 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05006216 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart06145682021-07-07 11:43:46 -07006217
6218 if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
6219 !(ndlp->nlp_flag & NLP_NPR_ADISC))
6220 continue;
6221
6222 spin_lock_irq(&ndlp->lock);
6223 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
6224 spin_unlock_irq(&ndlp->lock);
6225
6226 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
6227 /* This node was marked for ADISC but was not picked
6228 * for discovery. This is possible if the node was
6229 * missing in gidft response.
6230 *
6231 * At time of marking node for ADISC, we skipped unreg
6232 * from backend
6233 */
6234 lpfc_nlp_unreg_node(vport, ndlp);
James Smartb5073572021-09-10 16:31:52 -07006235 lpfc_unreg_rpi(vport, ndlp);
James Smart06145682021-07-07 11:43:46 -07006236 continue;
dea31012005-04-17 16:05:31 -05006237 }
James Smart06145682021-07-07 11:43:46 -07006238
6239 ndlp->nlp_prev_state = ndlp->nlp_state;
6240 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
6241 lpfc_issue_els_adisc(vport, ndlp, 0);
6242 sentadisc++;
6243 vport->num_disc_nodes++;
6244 if (vport->num_disc_nodes >=
6245 vport->cfg_discovery_threads) {
6246 spin_lock_irq(shost->host_lock);
6247 vport->fc_flag |= FC_NLP_MORE;
6248 spin_unlock_irq(shost->host_lock);
6249 break;
6250 }
6251
dea31012005-04-17 16:05:31 -05006252 }
6253 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05006254 spin_lock_irq(shost->host_lock);
6255 vport->fc_flag &= ~FC_NLP_MORE;
6256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006257 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006258 return sentadisc;
dea31012005-04-17 16:05:31 -05006259}
6260
James Smarte59058c2008-08-24 21:49:00 -04006261/**
James Smart3621a712009-04-06 18:47:14 -04006262 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04006263 * @vport: pointer to a host virtual N_Port data structure.
6264 *
6265 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6266 * which are in node port recovery state, with a @vport. Each time an ELS
6267 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6268 * the per @vport number of discover count (num_disc_nodes) shall be
6269 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6270 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6271 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6272 * later pick up. On the other hand, after walking through all the ndlps with
6273 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6274 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6275 * PLOGI need to be sent.
6276 *
6277 * Return code
6278 * The number of N_Ports with plogi issued.
6279 **/
dea31012005-04-17 16:05:31 -05006280int
James Smart2e0fef82007-06-17 19:56:36 -05006281lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006282{
James Smart2e0fef82007-06-17 19:56:36 -05006283 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006284 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006285 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05006286
James Smart2e0fef82007-06-17 19:56:36 -05006287 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6288 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04006289 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04006290 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
6291 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
6292 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04006293 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006294 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6295 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04006296 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05006297 vport->num_disc_nodes++;
6298 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04006299 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05006300 spin_lock_irq(shost->host_lock);
6301 vport->fc_flag |= FC_NLP_MORE;
6302 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006303 break;
dea31012005-04-17 16:05:31 -05006304 }
6305 }
6306 }
James Smartb4b34172019-10-18 14:18:31 -07006307
6308 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6309 "6452 Discover PLOGI %d flag x%x\n",
6310 sentplogi, vport->fc_flag);
6311
James Smart87af33f2007-10-27 13:37:43 -04006312 if (sentplogi) {
6313 lpfc_set_disctmo(vport);
6314 }
6315 else {
James Smart2e0fef82007-06-17 19:56:36 -05006316 spin_lock_irq(shost->host_lock);
6317 vport->fc_flag &= ~FC_NLP_MORE;
6318 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006319 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006320 return sentplogi;
dea31012005-04-17 16:05:31 -05006321}
6322
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006323static uint32_t
James Smart86478872015-05-21 13:55:21 -04006324lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
6325 uint32_t word0)
6326{
6327
6328 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
6329 desc->payload.els_req = word0;
6330 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07006331
6332 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04006333}
6334
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006335static uint32_t
James Smart86478872015-05-21 13:55:21 -04006336lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
6337 uint8_t *page_a0, uint8_t *page_a2)
6338{
6339 uint16_t wavelength;
6340 uint16_t temperature;
6341 uint16_t rx_power;
6342 uint16_t tx_bias;
6343 uint16_t tx_power;
6344 uint16_t vcc;
6345 uint16_t flag = 0;
6346 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
6347 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
6348
6349 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
6350
6351 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
6352 &page_a0[SSF_TRANSCEIVER_CODE_B4];
6353 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
6354 &page_a0[SSF_TRANSCEIVER_CODE_B5];
6355
6356 if ((trasn_code_byte4->fc_sw_laser) ||
6357 (trasn_code_byte5->fc_sw_laser_sl) ||
6358 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
6359 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
6360 } else if (trasn_code_byte4->fc_lw_laser) {
6361 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
6362 page_a0[SSF_WAVELENGTH_B0];
6363 if (wavelength == SFP_WAVELENGTH_LC1310)
6364 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
6365 if (wavelength == SFP_WAVELENGTH_LL1550)
6366 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
6367 }
6368 /* check if its SFP+ */
6369 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
6370 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
6371 << SFP_FLAG_CT_SHIFT;
6372
6373 /* check if its OPTICAL */
6374 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
6375 SFP_FLAG_IS_OPTICAL_PORT : 0)
6376 << SFP_FLAG_IS_OPTICAL_SHIFT;
6377
6378 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
6379 page_a2[SFF_TEMPERATURE_B0]);
6380 vcc = (page_a2[SFF_VCC_B1] << 8 |
6381 page_a2[SFF_VCC_B0]);
6382 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
6383 page_a2[SFF_TXPOWER_B0]);
6384 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
6385 page_a2[SFF_TX_BIAS_CURRENT_B0]);
6386 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
6387 page_a2[SFF_RXPOWER_B0]);
6388 desc->sfp_info.temperature = cpu_to_be16(temperature);
6389 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
6390 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
6391 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
6392 desc->sfp_info.vcc = cpu_to_be16(vcc);
6393
6394 desc->sfp_info.flags = cpu_to_be16(flag);
6395 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006396
6397 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04006398}
6399
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006400static uint32_t
James Smart86478872015-05-21 13:55:21 -04006401lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
6402 READ_LNK_VAR *stat)
6403{
6404 uint32_t type;
6405
6406 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
6407
6408 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
6409
6410 desc->info.port_type = cpu_to_be32(type);
6411
6412 desc->info.link_status.link_failure_cnt =
6413 cpu_to_be32(stat->linkFailureCnt);
6414 desc->info.link_status.loss_of_synch_cnt =
6415 cpu_to_be32(stat->lossSyncCnt);
6416 desc->info.link_status.loss_of_signal_cnt =
6417 cpu_to_be32(stat->lossSignalCnt);
6418 desc->info.link_status.primitive_seq_proto_err =
6419 cpu_to_be32(stat->primSeqErrCnt);
6420 desc->info.link_status.invalid_trans_word =
6421 cpu_to_be32(stat->invalidXmitWord);
6422 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
6423
6424 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07006425
6426 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04006427}
6428
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006429static uint32_t
James Smart56204982016-03-31 14:12:32 -07006430lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
6431 struct lpfc_vport *vport)
6432{
James Smart3aaaa312016-07-06 12:35:57 -07006433 uint32_t bbCredit;
6434
James Smart56204982016-03-31 14:12:32 -07006435 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
6436
James Smart3aaaa312016-07-06 12:35:57 -07006437 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
6438 (vport->fc_sparam.cmn.bbCreditMsb << 8);
6439 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
6440 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
6441 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
6442 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
6443 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
6444 } else {
James Smart56204982016-03-31 14:12:32 -07006445 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07006446 }
James Smart56204982016-03-31 14:12:32 -07006447
6448 desc->bbc_info.rtt = 0;
6449 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006450
6451 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07006452}
6453
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006454static uint32_t
James Smart310429e2016-07-06 12:35:54 -07006455lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
6456 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07006457{
James Smart310429e2016-07-06 12:35:54 -07006458 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07006459
6460 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6461
James Smart3aaaa312016-07-06 12:35:57 -07006462 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
6463 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
6464 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
6465 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07006466
6467 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6468 flags |= RDP_OET_HIGH_ALARM;
6469 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6470 flags |= RDP_OET_LOW_ALARM;
6471 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6472 flags |= RDP_OET_HIGH_WARNING;
6473 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6474 flags |= RDP_OET_LOW_WARNING;
6475
James Smart56204982016-03-31 14:12:32 -07006476 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
6477 desc->oed_info.function_flags = cpu_to_be32(flags);
6478 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006479 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006480}
6481
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006482static uint32_t
James Smart310429e2016-07-06 12:35:54 -07006483lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
6484 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07006485 uint8_t *page_a2)
6486{
James Smart310429e2016-07-06 12:35:54 -07006487 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07006488
6489 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6490
James Smart3aaaa312016-07-06 12:35:57 -07006491 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
6492 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
6493 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
6494 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07006495
6496 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6497 flags |= RDP_OET_HIGH_ALARM;
6498 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6499 flags |= RDP_OET_LOW_ALARM;
6500 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6501 flags |= RDP_OET_HIGH_WARNING;
6502 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6503 flags |= RDP_OET_LOW_WARNING;
6504
James Smart56204982016-03-31 14:12:32 -07006505 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
6506 desc->oed_info.function_flags = cpu_to_be32(flags);
6507 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006508 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006509}
6510
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006511static uint32_t
James Smart310429e2016-07-06 12:35:54 -07006512lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
6513 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07006514 uint8_t *page_a2)
6515{
James Smart310429e2016-07-06 12:35:54 -07006516 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07006517
6518 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6519
James Smart3aaaa312016-07-06 12:35:57 -07006520 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
6521 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
6522 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
6523 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07006524
6525 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6526 flags |= RDP_OET_HIGH_ALARM;
6527 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
6528 flags |= RDP_OET_LOW_ALARM;
6529 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6530 flags |= RDP_OET_HIGH_WARNING;
6531 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
6532 flags |= RDP_OET_LOW_WARNING;
6533
James Smart56204982016-03-31 14:12:32 -07006534 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
6535 desc->oed_info.function_flags = cpu_to_be32(flags);
6536 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006537 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006538}
6539
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006540static uint32_t
James Smart310429e2016-07-06 12:35:54 -07006541lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
6542 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07006543 uint8_t *page_a2)
6544{
James Smart310429e2016-07-06 12:35:54 -07006545 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07006546
6547 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6548
James Smart3aaaa312016-07-06 12:35:57 -07006549 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
6550 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
6551 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
6552 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07006553
6554 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6555 flags |= RDP_OET_HIGH_ALARM;
6556 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
6557 flags |= RDP_OET_LOW_ALARM;
6558 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6559 flags |= RDP_OET_HIGH_WARNING;
6560 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
6561 flags |= RDP_OET_LOW_WARNING;
6562
James Smart56204982016-03-31 14:12:32 -07006563 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
6564 desc->oed_info.function_flags = cpu_to_be32(flags);
6565 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006566 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006567}
6568
6569
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006570static uint32_t
James Smart310429e2016-07-06 12:35:54 -07006571lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
6572 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07006573 uint8_t *page_a2)
6574{
James Smart310429e2016-07-06 12:35:54 -07006575 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07006576
6577 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6578
James Smart3aaaa312016-07-06 12:35:57 -07006579 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6580 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6581 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6582 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07006583
6584 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6585 flags |= RDP_OET_HIGH_ALARM;
6586 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6587 flags |= RDP_OET_LOW_ALARM;
6588 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6589 flags |= RDP_OET_HIGH_WARNING;
6590 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6591 flags |= RDP_OET_LOW_WARNING;
6592
James Smart56204982016-03-31 14:12:32 -07006593 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6594 desc->oed_info.function_flags = cpu_to_be32(flags);
6595 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006596 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006597}
6598
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006599static uint32_t
James Smart56204982016-03-31 14:12:32 -07006600lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6601 uint8_t *page_a0, struct lpfc_vport *vport)
6602{
6603 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6604 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6605 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6606 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08006607 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07006608 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6609 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07006610 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07006611}
6612
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006613static uint32_t
James Smart4258e982015-12-16 18:11:58 -05006614lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6615{
6616 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6617 return 0;
6618 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6619
6620 desc->info.CorrectedBlocks =
6621 cpu_to_be32(stat->fecCorrBlkCount);
6622 desc->info.UncorrectableBlocks =
6623 cpu_to_be32(stat->fecUncorrBlkCount);
6624
6625 desc->length = cpu_to_be32(sizeof(desc->info));
6626
6627 return sizeof(struct fc_fec_rdp_desc);
6628}
6629
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006630static uint32_t
James Smart86478872015-05-21 13:55:21 -04006631lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6632{
6633 uint16_t rdp_cap = 0;
6634 uint16_t rdp_speed;
6635
6636 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6637
James Smart81e75172015-12-16 18:11:59 -05006638 switch (phba->fc_linkspeed) {
6639 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04006640 rdp_speed = RDP_PS_1GB;
6641 break;
James Smart81e75172015-12-16 18:11:59 -05006642 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04006643 rdp_speed = RDP_PS_2GB;
6644 break;
James Smart81e75172015-12-16 18:11:59 -05006645 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04006646 rdp_speed = RDP_PS_4GB;
6647 break;
James Smart81e75172015-12-16 18:11:59 -05006648 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04006649 rdp_speed = RDP_PS_8GB;
6650 break;
James Smart81e75172015-12-16 18:11:59 -05006651 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04006652 rdp_speed = RDP_PS_10GB;
6653 break;
James Smart81e75172015-12-16 18:11:59 -05006654 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04006655 rdp_speed = RDP_PS_16GB;
6656 break;
James Smarta085e872015-12-16 18:12:02 -05006657 case LPFC_LINK_SPEED_32GHZ:
6658 rdp_speed = RDP_PS_32GB;
6659 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08006660 case LPFC_LINK_SPEED_64GHZ:
6661 rdp_speed = RDP_PS_64GB;
6662 break;
James Smartbfc47782021-07-22 15:17:19 -07006663 case LPFC_LINK_SPEED_128GHZ:
6664 rdp_speed = RDP_PS_128GB;
6665 break;
6666 case LPFC_LINK_SPEED_256GHZ:
6667 rdp_speed = RDP_PS_256GB;
6668 break;
James Smart86478872015-05-21 13:55:21 -04006669 default:
6670 rdp_speed = RDP_PS_UNKNOWN;
6671 break;
6672 }
6673
6674 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6675
James Smartbfc47782021-07-22 15:17:19 -07006676 if (phba->lmt & LMT_256Gb)
6677 rdp_cap |= RDP_PS_256GB;
James Smart1dc5ec22018-10-23 13:41:11 -07006678 if (phba->lmt & LMT_128Gb)
6679 rdp_cap |= RDP_PS_128GB;
James Smartfbd8a6b2018-02-22 08:18:45 -08006680 if (phba->lmt & LMT_64Gb)
6681 rdp_cap |= RDP_PS_64GB;
James Smartd38dd522015-08-31 16:48:17 -04006682 if (phba->lmt & LMT_32Gb)
6683 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04006684 if (phba->lmt & LMT_16Gb)
6685 rdp_cap |= RDP_PS_16GB;
6686 if (phba->lmt & LMT_10Gb)
6687 rdp_cap |= RDP_PS_10GB;
6688 if (phba->lmt & LMT_8Gb)
6689 rdp_cap |= RDP_PS_8GB;
6690 if (phba->lmt & LMT_4Gb)
6691 rdp_cap |= RDP_PS_4GB;
6692 if (phba->lmt & LMT_2Gb)
6693 rdp_cap |= RDP_PS_2GB;
6694 if (phba->lmt & LMT_1Gb)
6695 rdp_cap |= RDP_PS_1GB;
6696
6697 if (rdp_cap == 0)
6698 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07006699 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
6700 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04006701
6702 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
6703 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07006704 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04006705}
6706
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006707static uint32_t
James Smart86478872015-05-21 13:55:21 -04006708lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08006709 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04006710{
6711
6712 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6713
James Smartcd46cde2017-03-04 09:30:37 -08006714 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04006715 sizeof(desc->port_names.wwnn));
6716
James Smartcd46cde2017-03-04 09:30:37 -08006717 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04006718 sizeof(desc->port_names.wwpn));
6719
6720 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07006721 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04006722}
6723
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006724static uint32_t
James Smart86478872015-05-21 13:55:21 -04006725lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
6726 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6727{
6728
6729 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6730 if (vport->fc_flag & FC_FABRIC) {
6731 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07006732 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04006733
6734 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
James Smartd9f492a2019-08-14 16:57:04 -07006735 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04006736 } else { /* Point to Point */
6737 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07006738 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04006739
James Smartd9f492a2019-08-14 16:57:04 -07006740 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
6741 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04006742 }
6743
6744 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07006745 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04006746}
6747
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006748static void
James Smart86478872015-05-21 13:55:21 -04006749lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
6750 int status)
6751{
6752 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
6753 struct lpfc_vport *vport = ndlp->vport;
6754 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05006755 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04006756 IOCB_t *icmd;
6757 uint8_t *pcmd;
6758 struct ls_rjt *stat;
6759 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07006760 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07006761 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07006762 int rc;
James Smart86478872015-05-21 13:55:21 -04006763
6764 if (status != SUCCESS)
6765 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05006766
6767 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04006768 cmdsize = sizeof(struct fc_rdp_res_frame);
6769
6770 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
6771 lpfc_max_els_tries, rdp_context->ndlp,
6772 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
James Smart86478872015-05-21 13:55:21 -04006773 if (!elsiocb)
6774 goto free_rdp_context;
6775
6776 icmd = &elsiocb->iocb;
6777 icmd->ulpContext = rdp_context->rx_id;
6778 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6779
6780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6781 "2171 Xmit RDP response tag x%x xri x%x, "
6782 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
6783 elsiocb->iotag, elsiocb->iocb.ulpContext,
6784 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6785 ndlp->nlp_rpi);
6786 rdp_res = (struct fc_rdp_res_frame *)
6787 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6788 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6789 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
6790 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6791
James Smart310429e2016-07-06 12:35:54 -07006792 /* Update Alarm and Warning */
6793 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6794 phba->sfp_alarm |= *flag_ptr;
6795 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6796 phba->sfp_warning |= *flag_ptr;
6797
James Smart86478872015-05-21 13:55:21 -04006798 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07006799 len = 8;
6800 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6801 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04006802
James Smart6c92d1d2016-07-06 12:35:55 -07006803 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04006804 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07006805 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6806 phba);
6807 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6808 (len + pcmd), &rdp_context->link_stat);
6809 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08006810 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07006811 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6812 (len + pcmd), vport, ndlp);
6813 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05006814 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07006815 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6816 &rdp_context->link_stat, vport);
6817 len += lpfc_rdp_res_oed_temp_desc(phba,
6818 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6819 rdp_context->page_a2);
6820 len += lpfc_rdp_res_oed_voltage_desc(phba,
6821 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6822 rdp_context->page_a2);
6823 len += lpfc_rdp_res_oed_txbias_desc(phba,
6824 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6825 rdp_context->page_a2);
6826 len += lpfc_rdp_res_oed_txpower_desc(phba,
6827 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6828 rdp_context->page_a2);
6829 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6830 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6831 rdp_context->page_a2);
6832 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6833 rdp_context->page_a0, vport);
6834
James Smart6c92d1d2016-07-06 12:35:55 -07006835 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04006836 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6837
James Smarteb8d68c2015-12-16 18:12:00 -05006838 /* Now that we know the true size of the payload, update the BPL */
6839 bpl = (struct ulp_bde64 *)
6840 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07006841 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05006842 bpl->tus.f.bdeFlags = 0;
6843 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6844
James Smart86478872015-05-21 13:55:21 -04006845 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08006846 elsiocb->context1 = lpfc_nlp_get(ndlp);
6847 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006848 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006849 goto free_rdp_context;
6850 }
James Smart86478872015-05-21 13:55:21 -04006851
James Smart4430f7f2020-11-15 11:26:31 -08006852 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6853 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08006854 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08006855 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006856 }
James Smart86478872015-05-21 13:55:21 -04006857
James Smart4430f7f2020-11-15 11:26:31 -08006858 goto free_rdp_context;
6859
James Smart86478872015-05-21 13:55:21 -04006860error:
6861 cmdsize = 2 * sizeof(uint32_t);
6862 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6863 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart86478872015-05-21 13:55:21 -04006864 if (!elsiocb)
6865 goto free_rdp_context;
6866
6867 icmd = &elsiocb->iocb;
6868 icmd->ulpContext = rdp_context->rx_id;
6869 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6870 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6871
6872 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6873 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6874 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6875
6876 phba->fc_stat.elsXmitLSRJT++;
6877 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08006878 elsiocb->context1 = lpfc_nlp_get(ndlp);
6879 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006880 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006881 goto free_rdp_context;
6882 }
6883
6884 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6885 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08006886 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08006887 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006888 }
6889
James Smart86478872015-05-21 13:55:21 -04006890free_rdp_context:
James Smart4430f7f2020-11-15 11:26:31 -08006891 /* This reference put is for the original unsolicited RDP. If the
6892 * iocb prep failed, there is no reference to remove.
6893 */
6894 lpfc_nlp_put(ndlp);
James Smart86478872015-05-21 13:55:21 -04006895 kfree(rdp_context);
6896}
6897
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006898static int
James Smart86478872015-05-21 13:55:21 -04006899lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6900{
6901 LPFC_MBOXQ_t *mbox = NULL;
6902 int rc;
6903
6904 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6905 if (!mbox) {
6906 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6907 "7105 failed to allocate mailbox memory");
6908 return 1;
6909 }
6910
6911 if (lpfc_sli4_dump_page_a0(phba, mbox))
6912 goto prep_mbox_fail;
6913 mbox->vport = rdp_context->ndlp->vport;
6914 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
James Smart3e1f0712018-11-29 16:09:29 -08006915 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04006916 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6917 if (rc == MBX_NOT_FINISHED)
6918 goto issue_mbox_fail;
6919
6920 return 0;
6921
6922prep_mbox_fail:
6923issue_mbox_fail:
6924 mempool_free(mbox, phba->mbox_mem_pool);
6925 return 1;
6926}
6927
6928/*
6929 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6930 * @vport: pointer to a host virtual N_Port data structure.
6931 * @cmdiocb: pointer to lpfc command iocb data structure.
6932 * @ndlp: pointer to a node-list data structure.
6933 *
6934 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6935 * IOCB. First, the payload of the unsolicited RDP is checked.
6936 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6937 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6938 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6939 * gather all data and send RDP response.
6940 *
6941 * Return code
6942 * 0 - Sent the acc response
6943 * 1 - Sent the reject response.
6944 */
6945static int
6946lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6947 struct lpfc_nodelist *ndlp)
6948{
6949 struct lpfc_hba *phba = vport->phba;
6950 struct lpfc_dmabuf *pcmd;
6951 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6952 struct fc_rdp_req_frame *rdp_req;
6953 struct lpfc_rdp_context *rdp_context;
6954 IOCB_t *cmd = NULL;
6955 struct ls_rjt stat;
6956
6957 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smart719162b2018-12-10 19:37:01 -08006958 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smarta0f2d3e2017-02-12 13:52:31 -08006959 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04006960 rjt_err = LSRJT_UNABLE_TPC;
6961 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6962 goto error;
6963 }
6964
6965 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6966 rjt_err = LSRJT_UNABLE_TPC;
6967 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6968 goto error;
6969 }
6970
6971 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6972 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6973
James Smart86478872015-05-21 13:55:21 -04006974 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6975 "2422 ELS RDP Request "
6976 "dec len %d tag x%x port_id %d len %d\n",
6977 be32_to_cpu(rdp_req->rdp_des_length),
6978 be32_to_cpu(rdp_req->nport_id_desc.tag),
6979 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6980 be32_to_cpu(rdp_req->nport_id_desc.length));
6981
6982 if (sizeof(struct fc_rdp_nport_desc) !=
6983 be32_to_cpu(rdp_req->rdp_des_length))
6984 goto rjt_logerr;
6985 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6986 goto rjt_logerr;
6987 if (RDP_NPORT_ID_SIZE !=
6988 be32_to_cpu(rdp_req->nport_id_desc.length))
6989 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05006990 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04006991 if (!rdp_context) {
6992 rjt_err = LSRJT_UNABLE_TPC;
6993 goto error;
6994 }
6995
James Smart86478872015-05-21 13:55:21 -04006996 cmd = &cmdiocb->iocb;
6997 rdp_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006998 if (!rdp_context->ndlp) {
6999 kfree(rdp_context);
7000 rjt_err = LSRJT_UNABLE_TPC;
7001 goto error;
7002 }
James Smart86478872015-05-21 13:55:21 -04007003 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
7004 rdp_context->rx_id = cmd->ulpContext;
7005 rdp_context->cmpl = lpfc_els_rdp_cmpl;
7006 if (lpfc_get_rdp_info(phba, rdp_context)) {
7007 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
7008 "2423 Unable to send mailbox");
7009 kfree(rdp_context);
7010 rjt_err = LSRJT_UNABLE_TPC;
7011 lpfc_nlp_put(ndlp);
7012 goto error;
7013 }
7014
7015 return 0;
7016
7017rjt_logerr:
7018 rjt_err = LSRJT_LOGICAL_ERR;
7019
7020error:
7021 memset(&stat, 0, sizeof(stat));
7022 stat.un.b.lsRjtRsnCode = rjt_err;
7023 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
7024 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7025 return 1;
7026}
7027
7028
James Smart8b017a32015-05-21 13:55:18 -04007029static void
7030lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7031{
7032 MAILBOX_t *mb;
7033 IOCB_t *icmd;
7034 uint8_t *pcmd;
7035 struct lpfc_iocbq *elsiocb;
7036 struct lpfc_nodelist *ndlp;
7037 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04007038 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04007039 struct lpfc_lcb_context *lcb_context;
7040 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04007041 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04007042 int rc;
7043
7044 mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08007045 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
James Smart8b017a32015-05-21 13:55:18 -04007046 ndlp = lcb_context->ndlp;
James Smart3e1f0712018-11-29 16:09:29 -08007047 pmb->ctx_ndlp = NULL;
7048 pmb->ctx_buf = NULL;
James Smart8b017a32015-05-21 13:55:18 -04007049
James Smart481ad962015-05-22 10:42:35 -04007050 shdr = (union lpfc_sli4_cfg_shdr *)
7051 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
7052 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7053 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7054
7055 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
7056 "0194 SET_BEACON_CONFIG mailbox "
7057 "completed with status x%x add_status x%x,"
7058 " mbx status x%x\n",
7059 shdr_status, shdr_add_status, mb->mbxStatus);
7060
James Smart66e9e6b2018-06-26 08:24:27 -07007061 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
7062 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
7063 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
James Smart8b017a32015-05-21 13:55:18 -04007064 mempool_free(pmb, phba->mbox_mem_pool);
7065 goto error;
7066 }
7067
7068 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04007069 cmdsize = sizeof(struct fc_lcb_res_frame);
7070 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7071 lpfc_max_els_tries, ndlp,
7072 ndlp->nlp_DID, ELS_CMD_ACC);
7073
7074 /* Decrement the ndlp reference count from previous mbox command */
7075 lpfc_nlp_put(ndlp);
7076
7077 if (!elsiocb)
7078 goto free_lcb_context;
7079
7080 lcb_res = (struct fc_lcb_res_frame *)
7081 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7082
James Smart24bc3112018-07-31 17:23:23 -07007083 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
James Smart8b017a32015-05-21 13:55:18 -04007084 icmd = &elsiocb->iocb;
7085 icmd->ulpContext = lcb_context->rx_id;
7086 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7087
7088 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7089 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
7090 lcb_res->lcb_sub_command = lcb_context->sub_command;
7091 lcb_res->lcb_type = lcb_context->type;
James Smart24bc3112018-07-31 17:23:23 -07007092 lcb_res->capability = lcb_context->capability;
James Smart8b017a32015-05-21 13:55:18 -04007093 lcb_res->lcb_frequency = lcb_context->frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07007094 lcb_res->lcb_duration = lcb_context->duration;
James Smart8b017a32015-05-21 13:55:18 -04007095 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7096 phba->fc_stat.elsXmitACC++;
James Smart8b017a32015-05-21 13:55:18 -04007097
James Smart4430f7f2020-11-15 11:26:31 -08007098 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08007099 if (!elsiocb->context1) {
7100 lpfc_els_free_iocb(phba, elsiocb);
7101 goto out;
7102 }
James Smart4430f7f2020-11-15 11:26:31 -08007103
7104 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08007105 if (rc == IOCB_ERROR) {
7106 lpfc_els_free_iocb(phba, elsiocb);
7107 lpfc_nlp_put(ndlp);
7108 }
James Smart4430f7f2020-11-15 11:26:31 -08007109 out:
James Smart8b017a32015-05-21 13:55:18 -04007110 kfree(lcb_context);
7111 return;
7112
7113error:
7114 cmdsize = sizeof(struct fc_lcb_res_frame);
7115 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7116 lpfc_max_els_tries, ndlp,
7117 ndlp->nlp_DID, ELS_CMD_LS_RJT);
7118 lpfc_nlp_put(ndlp);
7119 if (!elsiocb)
7120 goto free_lcb_context;
7121
7122 icmd = &elsiocb->iocb;
7123 icmd->ulpContext = lcb_context->rx_id;
7124 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7125 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7126
7127 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
7128 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7129 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7130
James Smartb114d902018-10-23 13:41:07 -07007131 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
7132 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
7133
James Smart8b017a32015-05-21 13:55:18 -04007134 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7135 phba->fc_stat.elsXmitLSRJT++;
James Smart4430f7f2020-11-15 11:26:31 -08007136 elsiocb->context1 = lpfc_nlp_get(ndlp);
7137 if (!elsiocb->context1) {
James Smart8b017a32015-05-21 13:55:18 -04007138 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08007139 goto free_lcb_context;
7140 }
7141
7142 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7143 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08007144 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08007145 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007146 }
James Smart8b017a32015-05-21 13:55:18 -04007147free_lcb_context:
7148 kfree(lcb_context);
7149}
7150
7151static int
7152lpfc_sli4_set_beacon(struct lpfc_vport *vport,
7153 struct lpfc_lcb_context *lcb_context,
7154 uint32_t beacon_state)
7155{
7156 struct lpfc_hba *phba = vport->phba;
James Smart66e9e6b2018-06-26 08:24:27 -07007157 union lpfc_sli4_cfg_shdr *cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04007158 LPFC_MBOXQ_t *mbox = NULL;
7159 uint32_t len;
7160 int rc;
7161
7162 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7163 if (!mbox)
7164 return 1;
7165
James Smart66e9e6b2018-06-26 08:24:27 -07007166 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04007167 len = sizeof(struct lpfc_mbx_set_beacon_config) -
7168 sizeof(struct lpfc_sli4_cfg_mhdr);
7169 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7170 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
7171 LPFC_SLI4_MBX_EMBED);
James Smart3e1f0712018-11-29 16:09:29 -08007172 mbox->ctx_ndlp = (void *)lcb_context;
James Smart8b017a32015-05-21 13:55:18 -04007173 mbox->vport = phba->pport;
7174 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
7175 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
7176 phba->sli4_hba.physical_port);
7177 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
7178 beacon_state);
James Smart66e9e6b2018-06-26 08:24:27 -07007179 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
7180
7181 /*
7182 * Check bv1s bit before issuing the mailbox
7183 * if bv1s == 1, LCB V1 supported
7184 * else, LCB V0 supported
7185 */
7186
7187 if (phba->sli4_hba.pc_sli4_params.bv1s) {
7188 /* COMMON_SET_BEACON_CONFIG_V1 */
7189 cfg_shdr->request.word9 = BEACON_VERSION_V1;
7190 lcb_context->capability |= LCB_CAPABILITY_DURATION;
7191 bf_set(lpfc_mbx_set_beacon_port_type,
7192 &mbox->u.mqe.un.beacon_config, 0);
7193 bf_set(lpfc_mbx_set_beacon_duration_v1,
7194 &mbox->u.mqe.un.beacon_config,
7195 be16_to_cpu(lcb_context->duration));
7196 } else {
7197 /* COMMON_SET_BEACON_CONFIG_V0 */
7198 if (be16_to_cpu(lcb_context->duration) != 0) {
7199 mempool_free(mbox, phba->mbox_mem_pool);
7200 return 1;
7201 }
7202 cfg_shdr->request.word9 = BEACON_VERSION_V0;
7203 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
7204 bf_set(lpfc_mbx_set_beacon_state,
7205 &mbox->u.mqe.un.beacon_config, beacon_state);
7206 bf_set(lpfc_mbx_set_beacon_port_type,
7207 &mbox->u.mqe.un.beacon_config, 1);
7208 bf_set(lpfc_mbx_set_beacon_duration,
7209 &mbox->u.mqe.un.beacon_config,
7210 be16_to_cpu(lcb_context->duration));
7211 }
7212
James Smart8b017a32015-05-21 13:55:18 -04007213 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7214 if (rc == MBX_NOT_FINISHED) {
7215 mempool_free(mbox, phba->mbox_mem_pool);
7216 return 1;
7217 }
7218
7219 return 0;
7220}
7221
7222
7223/**
7224 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7225 * @vport: pointer to a host virtual N_Port data structure.
7226 * @cmdiocb: pointer to lpfc command iocb data structure.
7227 * @ndlp: pointer to a node-list data structure.
7228 *
7229 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7230 * First, the payload of the unsolicited LCB is checked.
7231 * Then based on Subcommand beacon will either turn on or off.
7232 *
7233 * Return code
7234 * 0 - Sent the acc response
7235 * 1 - Sent the reject response.
7236 **/
7237static int
7238lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7239 struct lpfc_nodelist *ndlp)
7240{
7241 struct lpfc_hba *phba = vport->phba;
7242 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04007243 uint8_t *lp;
7244 struct fc_lcb_request_frame *beacon;
7245 struct lpfc_lcb_context *lcb_context;
James Smart4430f7f2020-11-15 11:26:31 -08007246 u8 state, rjt_err = 0;
James Smart8b017a32015-05-21 13:55:18 -04007247 struct ls_rjt stat;
7248
James Smart8b017a32015-05-21 13:55:18 -04007249 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
7250 lp = (uint8_t *)pcmd->virt;
7251 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
7252
7253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7254 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7255 "type x%x frequency %x duration x%x\n",
7256 lp[0], lp[1], lp[2],
7257 beacon->lcb_command,
7258 beacon->lcb_sub_command,
7259 beacon->lcb_type,
7260 beacon->lcb_frequency,
7261 be16_to_cpu(beacon->lcb_duration));
7262
James Smartd6564e52017-06-15 22:56:50 -07007263 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
7264 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04007265 rjt_err = LSRJT_CMD_UNSUPPORTED;
7266 goto rjt;
7267 }
James Smart66e9e6b2018-06-26 08:24:27 -07007268
7269 if (phba->sli_rev < LPFC_SLI_REV4 ||
7270 phba->hba_flag & HBA_FCOE_MODE ||
7271 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7272 LPFC_SLI_INTF_IF_TYPE_2)) {
James Smart8b017a32015-05-21 13:55:18 -04007273 rjt_err = LSRJT_CMD_UNSUPPORTED;
7274 goto rjt;
7275 }
7276
Sudip Mukherjeee7950422015-09-23 19:02:32 +05307277 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
7278 if (!lcb_context) {
7279 rjt_err = LSRJT_UNABLE_TPC;
7280 goto rjt;
7281 }
7282
James Smart8b017a32015-05-21 13:55:18 -04007283 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
7284 lcb_context->sub_command = beacon->lcb_sub_command;
James Smart66e9e6b2018-06-26 08:24:27 -07007285 lcb_context->capability = 0;
James Smart8b017a32015-05-21 13:55:18 -04007286 lcb_context->type = beacon->lcb_type;
7287 lcb_context->frequency = beacon->lcb_frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07007288 lcb_context->duration = beacon->lcb_duration;
James Smart8b017a32015-05-21 13:55:18 -04007289 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7290 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
7291 lcb_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007292 if (!lcb_context->ndlp) {
7293 rjt_err = LSRJT_UNABLE_TPC;
Colin Ian King14c1dd92020-11-18 14:13:14 +00007294 goto rjt_free;
James Smart4430f7f2020-11-15 11:26:31 -08007295 }
7296
James Smart8b017a32015-05-21 13:55:18 -04007297 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007298 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
7299 "0193 failed to send mail box");
James Smart8b017a32015-05-21 13:55:18 -04007300 lpfc_nlp_put(ndlp);
7301 rjt_err = LSRJT_UNABLE_TPC;
Colin Ian King14c1dd92020-11-18 14:13:14 +00007302 goto rjt_free;
James Smart8b017a32015-05-21 13:55:18 -04007303 }
7304 return 0;
Colin Ian King14c1dd92020-11-18 14:13:14 +00007305
7306rjt_free:
7307 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04007308rjt:
7309 memset(&stat, 0, sizeof(stat));
7310 stat.un.b.lsRjtRsnCode = rjt_err;
7311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7312 return 1;
7313}
7314
7315
James Smarte59058c2008-08-24 21:49:00 -04007316/**
James Smart3621a712009-04-06 18:47:14 -04007317 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04007318 * @vport: pointer to a host virtual N_Port data structure.
7319 *
7320 * This routine cleans up any Registration State Change Notification
7321 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7322 * @vport together with the host_lock is used to prevent multiple thread
7323 * trying to access the RSCN array on a same @vport at the same time.
7324 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007325void
James Smart2e0fef82007-06-17 19:56:36 -05007326lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007327{
James Smart2e0fef82007-06-17 19:56:36 -05007328 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7329 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007330 int i;
7331
James Smart7f5f3d02008-02-08 18:50:14 -05007332 spin_lock_irq(shost->host_lock);
7333 if (vport->fc_rscn_flush) {
7334 /* Another thread is walking fc_rscn_id_list on this vport */
7335 spin_unlock_irq(shost->host_lock);
7336 return;
7337 }
7338 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7339 vport->fc_rscn_flush = 1;
7340 spin_unlock_irq(shost->host_lock);
7341
James Smart2e0fef82007-06-17 19:56:36 -05007342 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05007343 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05007344 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05007345 }
James Smart2e0fef82007-06-17 19:56:36 -05007346 spin_lock_irq(shost->host_lock);
7347 vport->fc_rscn_id_cnt = 0;
7348 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
7349 spin_unlock_irq(shost->host_lock);
7350 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007351 /* Indicate we are done walking this fc_rscn_id_list */
7352 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05007353}
7354
James Smarte59058c2008-08-24 21:49:00 -04007355/**
James Smart3621a712009-04-06 18:47:14 -04007356 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04007357 * @vport: pointer to a host virtual N_Port data structure.
7358 * @did: remote destination port identifier.
7359 *
7360 * This routine checks whether there is any pending Registration State
7361 * Configuration Notification (RSCN) to a @did on @vport.
7362 *
7363 * Return code
7364 * None zero - The @did matched with a pending rscn
7365 * 0 - not able to match @did with a pending rscn
7366 **/
dea31012005-04-17 16:05:31 -05007367int
James Smart2e0fef82007-06-17 19:56:36 -05007368lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05007369{
7370 D_ID ns_did;
7371 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05007372 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05007373 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05007374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05007375
7376 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05007377
7378 /* Never match fabric nodes for RSCNs */
7379 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05007380 return 0;
dea31012005-04-17 16:05:31 -05007381
7382 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05007383 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007384 return did;
dea31012005-04-17 16:05:31 -05007385
James Smart7f5f3d02008-02-08 18:50:14 -05007386 spin_lock_irq(shost->host_lock);
7387 if (vport->fc_rscn_flush) {
7388 /* Another thread is walking fc_rscn_id_list on this vport */
7389 spin_unlock_irq(shost->host_lock);
7390 return 0;
7391 }
7392 /* Indicate we are walking fc_rscn_id_list on this vport */
7393 vport->fc_rscn_flush = 1;
7394 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007395 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05007396 lp = vport->fc_rscn_id_list[i]->virt;
7397 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7398 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05007399 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05007400 rscn_did.un.word = be32_to_cpu(*lp++);
7401 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05007402 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
7403 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04007404 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7405 && (ns_did.un.b.area == rscn_did.un.b.area)
7406 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05007407 goto return_did_out;
dea31012005-04-17 16:05:31 -05007408 break;
James Smarteaf15d52008-12-04 22:39:29 -05007409 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05007410 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7411 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05007412 goto return_did_out;
dea31012005-04-17 16:05:31 -05007413 break;
James Smarteaf15d52008-12-04 22:39:29 -05007414 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05007415 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05007416 goto return_did_out;
dea31012005-04-17 16:05:31 -05007417 break;
James Smarteaf15d52008-12-04 22:39:29 -05007418 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05007419 goto return_did_out;
dea31012005-04-17 16:05:31 -05007420 }
7421 }
James Smart92d7f7b2007-06-17 19:56:38 -05007422 }
James Smart7f5f3d02008-02-08 18:50:14 -05007423 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7424 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007425 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05007426return_did_out:
7427 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7428 vport->fc_rscn_flush = 0;
7429 return did;
dea31012005-04-17 16:05:31 -05007430}
7431
James Smarte59058c2008-08-24 21:49:00 -04007432/**
James Smart3621a712009-04-06 18:47:14 -04007433 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04007434 * @vport: pointer to a host virtual N_Port data structure.
7435 *
7436 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7437 * state machine for a @vport's nodes that are with pending RSCN (Registration
7438 * State Change Notification).
7439 *
7440 * Return code
7441 * 0 - Successful (currently alway return 0)
7442 **/
dea31012005-04-17 16:05:31 -05007443static int
James Smart2e0fef82007-06-17 19:56:36 -05007444lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007445{
James Smart685f0bf2007-04-25 09:53:08 -04007446 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05007447
James Smart0d2b6b82008-06-14 22:52:47 -04007448 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05007449 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08007450 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
James Smart0d2b6b82008-06-14 22:52:47 -04007451 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05007452 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07007453
7454 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08007455 if (vport->phba->nvmet_support)
7456 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07007457
James Smartdea16bd2018-11-29 16:09:30 -08007458 /* If we are in the process of doing discovery on this
7459 * NPort, let it continue on its own.
7460 */
7461 switch (ndlp->nlp_state) {
7462 case NLP_STE_PLOGI_ISSUE:
7463 case NLP_STE_ADISC_ISSUE:
7464 case NLP_STE_REG_LOGIN_ISSUE:
7465 case NLP_STE_PRLI_ISSUE:
7466 case NLP_STE_LOGO_ISSUE:
7467 continue;
7468 }
7469
James Smart2e0fef82007-06-17 19:56:36 -05007470 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04007471 NLP_EVT_DEVICE_RECOVERY);
7472 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05007473 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007474 return 0;
dea31012005-04-17 16:05:31 -05007475}
7476
James Smarte59058c2008-08-24 21:49:00 -04007477/**
James Smart3621a712009-04-06 18:47:14 -04007478 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05007479 * @vport: pointer to a host virtual N_Port data structure.
7480 * @cmdiocb: pointer to lpfc command iocb data structure.
7481 *
7482 * lpfc_send_rscn_event sends an RSCN netlink event to management
7483 * applications.
7484 */
7485static void
7486lpfc_send_rscn_event(struct lpfc_vport *vport,
7487 struct lpfc_iocbq *cmdiocb)
7488{
7489 struct lpfc_dmabuf *pcmd;
7490 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7491 uint32_t *payload_ptr;
7492 uint32_t payload_len;
7493 struct lpfc_rscn_event_header *rscn_event_data;
7494
7495 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7496 payload_ptr = (uint32_t *) pcmd->virt;
7497 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
7498
7499 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
7500 payload_len, GFP_KERNEL);
7501 if (!rscn_event_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007502 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05007503 "0147 Failed to allocate memory for RSCN event\n");
7504 return;
7505 }
7506 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
7507 rscn_event_data->payload_length = payload_len;
7508 memcpy(rscn_event_data->rscn_payload, payload_ptr,
7509 payload_len);
7510
7511 fc_host_post_vendor_event(shost,
7512 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04007513 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05007514 (char *)rscn_event_data,
7515 LPFC_NL_VENDOR_ID);
7516
7517 kfree(rscn_event_data);
7518}
7519
7520/**
James Smart3621a712009-04-06 18:47:14 -04007521 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04007522 * @vport: pointer to a host virtual N_Port data structure.
7523 * @cmdiocb: pointer to lpfc command iocb data structure.
7524 * @ndlp: pointer to a node-list data structure.
7525 *
7526 * This routine processes an unsolicited RSCN (Registration State Change
7527 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
7528 * to invoke fc_host_post_event() routine to the FC transport layer. If the
7529 * discover state machine is about to begin discovery, it just accepts the
7530 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
7531 * contains N_Port IDs for other vports on this HBA, it just accepts the
7532 * RSCN and ignore processing it. If the state machine is in the recovery
7533 * state, the fc_rscn_id_list of this @vport is walked and the
7534 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
7535 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
7536 * routine is invoked to handle the RSCN event.
7537 *
7538 * Return code
7539 * 0 - Just sent the acc response
7540 * 1 - Sent the acc response and waited for name server completion
7541 **/
dea31012005-04-17 16:05:31 -05007542static int
James Smart2e0fef82007-06-17 19:56:36 -05007543lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04007544 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007545{
James Smart2e0fef82007-06-17 19:56:36 -05007546 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7547 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007548 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05007549 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05007550 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05007551 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05007552 int rscn_id = 0, hba_id = 0;
James Smart2332e6e2019-11-04 16:57:01 -08007553 int i, tmo;
dea31012005-04-17 16:05:31 -05007554
dea31012005-04-17 16:05:31 -05007555 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7556 lp = (uint32_t *) pcmd->virt;
7557
James Smart92d7f7b2007-06-17 19:56:38 -05007558 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7559 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05007560 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04007561 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7562 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05007563 vport->fc_flag, payload_len, *lp,
7564 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05007565
7566 /* Send an RSCN event to the management application */
7567 lpfc_send_rscn_event(vport, cmdiocb);
7568
James Smartd2873e42006-08-18 17:46:43 -04007569 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05007570 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04007571 FCH_EVT_RSCN, lp[i]);
7572
James Smartf60cb932019-05-14 14:58:05 -07007573 /* Check if RSCN is coming from a direct-connected remote NPort */
7574 if (vport->fc_flag & FC_PT2PT) {
7575 /* If so, just ACC it, no other action needed for now */
7576 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7577 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
7578 *lp, vport->fc_flag, payload_len);
7579 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart6f2589f2019-05-14 14:58:07 -07007580
James Smarta6d10f22019-08-14 16:56:50 -07007581 /* Check to see if we need to NVME rescan this target
7582 * remoteport.
7583 */
7584 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
7585 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07007586 lpfc_nvme_rescan_port(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07007587 return 0;
7588 }
7589
dea31012005-04-17 16:05:31 -05007590 /* If we are about to begin discovery, just ACC the RSCN.
7591 * Discovery processing will satisfy it.
7592 */
James Smart2e0fef82007-06-17 19:56:36 -05007593 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05007594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7595 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
7596 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7597
James Smart51ef4c22007-08-02 11:10:31 -04007598 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007599 return 0;
dea31012005-04-17 16:05:31 -05007600 }
7601
James Smart92d7f7b2007-06-17 19:56:38 -05007602 /* If this RSCN just contains NPortIDs for other vports on this HBA,
7603 * just ACC and ignore it.
7604 */
7605 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04007606 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05007607 i = payload_len;
7608 datap = lp;
7609 while (i > 0) {
7610 nportid = *datap++;
7611 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
7612 i -= sizeof(uint32_t);
7613 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04007614 if (lpfc_find_vport_by_did(phba, nportid))
7615 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05007616 }
7617 if (rscn_id == hba_id) {
7618 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04007619 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04007620 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04007621 "Data: x%x x%x x%x x%x\n",
7622 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05007623 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05007624 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7625 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
7626 ndlp->nlp_DID, vport->port_state,
7627 ndlp->nlp_flag);
7628
James Smart92d7f7b2007-06-17 19:56:38 -05007629 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04007630 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05007631 return 0;
7632 }
7633 }
7634
James Smart7f5f3d02008-02-08 18:50:14 -05007635 spin_lock_irq(shost->host_lock);
7636 if (vport->fc_rscn_flush) {
7637 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05007638 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05007639 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04007640 /* Send back ACC */
7641 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05007642 return 0;
7643 }
7644 /* Indicate we are walking fc_rscn_id_list on this vport */
7645 vport->fc_rscn_flush = 1;
7646 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007647 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05007648 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05007649 /* If we are already processing an RSCN, save the received
7650 * RSCN payload buffer, cmdiocb->context2 to process later.
7651 */
James Smart2e0fef82007-06-17 19:56:36 -05007652 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05007653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7654 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
7655 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7656
James Smart09372822008-01-11 01:52:54 -05007657 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007658 vport->fc_flag |= FC_RSCN_DEFERRED;
James Smart2332e6e2019-11-04 16:57:01 -08007659
7660 /* Restart disctmo if its already running */
7661 if (vport->fc_flag & FC_DISC_TMO) {
7662 tmo = ((phba->fc_ratov * 3) + 3);
7663 mod_timer(&vport->fc_disctmo,
7664 jiffies + msecs_to_jiffies(1000 * tmo));
7665 }
James Smart92d7f7b2007-06-17 19:56:38 -05007666 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05007667 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05007668 vport->fc_flag |= FC_RSCN_MODE;
7669 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007670 if (rscn_cnt) {
7671 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
7672 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
7673 }
7674 if ((rscn_cnt) &&
7675 (payload_len + length <= LPFC_BPL_SIZE)) {
7676 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05007677 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05007678 memcpy(((uint8_t *)cmd) + length, lp,
7679 payload_len);
7680 } else {
7681 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
7682 vport->fc_rscn_id_cnt++;
7683 /* If we zero, cmdiocb->context2, the calling
7684 * routine will not try to free it.
7685 */
7686 cmdiocb->context2 = NULL;
7687 }
dea31012005-04-17 16:05:31 -05007688 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04007689 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7690 "0235 Deferred RSCN "
7691 "Data: x%x x%x x%x\n",
7692 vport->fc_rscn_id_cnt, vport->fc_flag,
7693 vport->port_state);
dea31012005-04-17 16:05:31 -05007694 } else {
James Smart2e0fef82007-06-17 19:56:36 -05007695 vport->fc_flag |= FC_RSCN_DISCOVERY;
7696 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05007697 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04007698 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7699 "0234 ReDiscovery RSCN "
7700 "Data: x%x x%x x%x\n",
7701 vport->fc_rscn_id_cnt, vport->fc_flag,
7702 vport->port_state);
dea31012005-04-17 16:05:31 -05007703 }
James Smart7f5f3d02008-02-08 18:50:14 -05007704 /* Indicate we are done walking fc_rscn_id_list on this vport */
7705 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05007706 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04007707 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007708 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05007709 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007710 return 0;
dea31012005-04-17 16:05:31 -05007711 }
James Smart858c9f62007-06-17 19:56:39 -05007712 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7713 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
7714 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7715
James Smart2e0fef82007-06-17 19:56:36 -05007716 spin_lock_irq(shost->host_lock);
7717 vport->fc_flag |= FC_RSCN_MODE;
7718 spin_unlock_irq(shost->host_lock);
7719 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05007720 /* Indicate we are done walking fc_rscn_id_list on this vport */
7721 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05007722 /*
7723 * If we zero, cmdiocb->context2, the calling routine will
7724 * not try to free it.
7725 */
7726 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05007727 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05007728 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04007729 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007730 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05007731 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05007732 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05007733}
7734
James Smarte59058c2008-08-24 21:49:00 -04007735/**
James Smart3621a712009-04-06 18:47:14 -04007736 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04007737 * @vport: pointer to a host virtual N_Port data structure.
7738 *
7739 * This routine handles the Registration State Configuration Notification
7740 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
7741 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
7742 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
7743 * NameServer shall be issued. If CT command to the NameServer fails to be
7744 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
7745 * RSCN activities with the @vport.
7746 *
7747 * Return code
7748 * 0 - Cleaned up rscn on the @vport
7749 * 1 - Wait for plogi to name server before proceed
7750 **/
dea31012005-04-17 16:05:31 -05007751int
James Smart2e0fef82007-06-17 19:56:36 -05007752lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007753{
7754 struct lpfc_nodelist *ndlp;
James Smart7ea92eb2018-10-23 13:41:10 -07007755 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007756
James Smart92d7f7b2007-06-17 19:56:38 -05007757 /* Ignore RSCN if the port is being torn down. */
7758 if (vport->load_flag & FC_UNLOADING) {
7759 lpfc_els_flush_rscn(vport);
7760 return 0;
7761 }
7762
dea31012005-04-17 16:05:31 -05007763 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05007764 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05007765
7766 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04007767 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07007768 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04007769 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
James Smartb4b34172019-10-18 14:18:31 -07007770 vport->port_state, vport->num_disc_nodes,
7771 vport->gidft_inp);
dea31012005-04-17 16:05:31 -05007772
7773 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05007774 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05007775 vport->num_disc_nodes = 0;
7776
James Smart2e0fef82007-06-17 19:56:36 -05007777 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08007778 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07007779 /* Good ndlp, issue CT Request to NameServer. Need to
7780 * know how many gidfts were issued. If none, then just
7781 * flush the RSCN. Otherwise, the outstanding requests
7782 * need to complete.
7783 */
James Smart7ea92eb2018-10-23 13:41:10 -07007784 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7785 if (lpfc_issue_gidft(vport) > 0)
7786 return 1;
7787 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7788 if (lpfc_issue_gidpt(vport) > 0)
7789 return 1;
7790 } else {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007791 return 1;
James Smart7ea92eb2018-10-23 13:41:10 -07007792 }
dea31012005-04-17 16:05:31 -05007793 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07007794 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05007795 if (ndlp) {
James Smarte47c9092008-02-08 18:49:26 -05007796 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart307e3382020-11-15 11:26:30 -08007797 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007798 } else {
James Smart9d3d3402017-04-21 16:05:00 -07007799 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007800 if (!ndlp) {
7801 lpfc_els_flush_rscn(vport);
7802 return 0;
7803 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007804 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007806 }
James Smarte47c9092008-02-08 18:49:26 -05007807 ndlp->nlp_type |= NLP_FABRIC;
7808 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7809 /* Wait for NameServer login cmpl before we can
7810 * continue
7811 */
7812 return 1;
dea31012005-04-17 16:05:31 -05007813 }
7814
James Smart2e0fef82007-06-17 19:56:36 -05007815 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007816 return 0;
dea31012005-04-17 16:05:31 -05007817}
7818
James Smarte59058c2008-08-24 21:49:00 -04007819/**
James Smart3621a712009-04-06 18:47:14 -04007820 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04007821 * @vport: pointer to a host virtual N_Port data structure.
7822 * @cmdiocb: pointer to lpfc command iocb data structure.
7823 * @ndlp: pointer to a node-list data structure.
7824 *
7825 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7826 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7827 * point topology. As an unsolicited FLOGI should not be received in a loop
7828 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7829 * lpfc_check_sparm() routine is invoked to check the parameters in the
7830 * unsolicited FLOGI. If parameters validation failed, the routine
7831 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7832 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7833 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7834 * will initiate PLOGI. The higher lexicographical value party shall has
7835 * higher priority (as the winning port) and will initiate PLOGI and
7836 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7837 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7838 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7839 *
7840 * Return code
7841 * 0 - Successfully processed the unsolicited flogi
7842 * 1 - Failed to process the unsolicited flogi
7843 **/
dea31012005-04-17 16:05:31 -05007844static int
James Smart2e0fef82007-06-17 19:56:36 -05007845lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04007846 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007847{
James Smart2e0fef82007-06-17 19:56:36 -05007848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7849 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007850 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7851 uint32_t *lp = (uint32_t *) pcmd->virt;
7852 IOCB_t *icmd = &cmdiocb->iocb;
7853 struct serv_parm *sp;
7854 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05007855 uint32_t cmd, did;
7856 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04007857 uint32_t fc_flag = 0;
7858 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05007859
7860 cmd = *lp++;
7861 sp = (struct serv_parm *) lp;
7862
7863 /* FLOGI received */
7864
James Smart2e0fef82007-06-17 19:56:36 -05007865 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05007866
James Smart76a95d72010-11-20 23:11:48 -05007867 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05007868 /* We should never receive a FLOGI in loop mode, ignore it */
7869 did = icmd->un.elsreq64.remoteID;
7870
7871 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7872 Loop Mode */
Dick Kennedy372c1872020-06-30 14:50:00 -07007873 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04007874 "0113 An FLOGI ELS command x%x was "
7875 "received from DID x%x in Loop Mode\n",
7876 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007877 return 1;
dea31012005-04-17 16:05:31 -05007878 }
7879
James Smartd6de08c2015-12-16 18:11:53 -05007880 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05007881
James Smartd6de08c2015-12-16 18:11:53 -05007882 /*
7883 * If our portname is greater than the remote portname,
7884 * then we initiate Nport login.
7885 */
7886
7887 rc = memcmp(&vport->fc_portname, &sp->portName,
7888 sizeof(struct lpfc_name));
7889
7890 if (!rc) {
7891 if (phba->sli_rev < LPFC_SLI_REV4) {
7892 mbox = mempool_alloc(phba->mbox_mem_pool,
7893 GFP_KERNEL);
7894 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007895 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05007896 lpfc_linkdown(phba);
7897 lpfc_init_link(phba, mbox,
7898 phba->cfg_topology,
7899 phba->cfg_link_speed);
7900 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7901 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7902 mbox->vport = vport;
7903 rc = lpfc_sli_issue_mbox(phba, mbox,
7904 MBX_NOWAIT);
7905 lpfc_set_loopback_flag(phba);
7906 if (rc == MBX_NOT_FINISHED)
7907 mempool_free(mbox, phba->mbox_mem_pool);
7908 return 1;
7909 }
James Smart939723a2012-05-09 21:19:03 -04007910
James Smartd6de08c2015-12-16 18:11:53 -05007911 /* abort the flogi coming back to ourselves
7912 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04007913 */
James Smartd6de08c2015-12-16 18:11:53 -05007914 lpfc_els_abort_flogi(phba);
7915 return 0;
7916
7917 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05007918 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05007919 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05007920 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04007921
James Smartd6de08c2015-12-16 18:11:53 -05007922 /* If we have the high WWPN we can assign our own
7923 * myDID; otherwise, we have to WAIT for a PLOGI
7924 * from the remote NPort to find out what it
7925 * will be.
James Smart939723a2012-05-09 21:19:03 -04007926 */
James Smartd6de08c2015-12-16 18:11:53 -05007927 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05007928 } else {
James Smartd6de08c2015-12-16 18:11:53 -05007929 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05007930 }
7931
James Smartd6de08c2015-12-16 18:11:53 -05007932 /*
7933 * The vport state should go to LPFC_FLOGI only
7934 * AFTER we issue a FLOGI, not receive one.
7935 */
7936 spin_lock_irq(shost->host_lock);
7937 fc_flag = vport->fc_flag;
7938 port_state = vport->port_state;
7939 vport->fc_flag |= FC_PT2PT;
7940 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd496b9a2018-10-23 13:41:08 -07007941
7942 /* Acking an unsol FLOGI. Count 1 for link bounce
7943 * work-around.
7944 */
7945 vport->rcv_flogi_cnt++;
James Smartd6de08c2015-12-16 18:11:53 -05007946 spin_unlock_irq(shost->host_lock);
7947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7948 "3311 Rcv Flogi PS x%x new PS x%x "
7949 "fc_flag x%x new fc_flag x%x\n",
7950 port_state, vport->port_state,
7951 fc_flag, vport->fc_flag);
7952
7953 /*
7954 * We temporarily set fc_myDID to make it look like we are
7955 * a Fabric. This is done just so we end up with the right
7956 * did / sid on the FLOGI ACC rsp.
7957 */
7958 did = vport->fc_myDID;
7959 vport->fc_myDID = Fabric_DID;
7960
7961 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04007962
James Smart0a9e9682018-11-29 16:09:36 -08007963 /* Defer ACC response until AFTER we issue a FLOGI */
7964 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7965 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7966 phba->defer_flogi_acc_ox_id =
7967 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7968
7969 vport->fc_myDID = did;
7970
7971 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7972 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7973 " ox_id: x%x, hba_flag x%x\n",
7974 phba->defer_flogi_acc_rx_id,
7975 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7976
7977 phba->defer_flogi_acc_flag = true;
7978
7979 return 0;
7980 }
7981
dea31012005-04-17 16:05:31 -05007982 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05007983 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007984
James Smart939723a2012-05-09 21:19:03 -04007985 /* Now lets put fc_myDID back to what its supposed to be */
7986 vport->fc_myDID = did;
7987
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007988 return 0;
dea31012005-04-17 16:05:31 -05007989}
7990
James Smarte59058c2008-08-24 21:49:00 -04007991/**
James Smart3621a712009-04-06 18:47:14 -04007992 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04007993 * @vport: pointer to a host virtual N_Port data structure.
7994 * @cmdiocb: pointer to lpfc command iocb data structure.
7995 * @ndlp: pointer to a node-list data structure.
7996 *
7997 * This routine processes Request Node Identification Data (RNID) IOCB
7998 * received as an ELS unsolicited event. Only when the RNID specified format
7999 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8000 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8001 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8002 * rejected by invoking the lpfc_els_rsp_reject() routine.
8003 *
8004 * Return code
8005 * 0 - Successfully processed rnid iocb (currently always return 0)
8006 **/
dea31012005-04-17 16:05:31 -05008007static int
James Smart2e0fef82007-06-17 19:56:36 -05008008lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8009 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05008010{
8011 struct lpfc_dmabuf *pcmd;
8012 uint32_t *lp;
dea31012005-04-17 16:05:31 -05008013 RNID *rn;
8014 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05008015
dea31012005-04-17 16:05:31 -05008016 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8017 lp = (uint32_t *) pcmd->virt;
8018
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07008019 lp++;
dea31012005-04-17 16:05:31 -05008020 rn = (RNID *) lp;
8021
8022 /* RNID received */
8023
8024 switch (rn->Format) {
8025 case 0:
8026 case RNID_TOPOLOGY_DISC:
8027 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05008028 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05008029 break;
8030 default:
8031 /* Reject this request because format not supported */
8032 stat.un.b.lsRjtRsvd0 = 0;
8033 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8034 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8035 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05008036 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8037 NULL);
dea31012005-04-17 16:05:31 -05008038 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008039 return 0;
dea31012005-04-17 16:05:31 -05008040}
8041
James Smarte59058c2008-08-24 21:49:00 -04008042/**
James Smart12265f62010-10-22 11:05:53 -04008043 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8044 * @vport: pointer to a host virtual N_Port data structure.
8045 * @cmdiocb: pointer to lpfc command iocb data structure.
8046 * @ndlp: pointer to a node-list data structure.
8047 *
8048 * Return code
8049 * 0 - Successfully processed echo iocb (currently always return 0)
8050 **/
8051static int
8052lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8053 struct lpfc_nodelist *ndlp)
8054{
8055 uint8_t *pcmd;
8056
8057 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
8058
8059 /* skip over first word of echo command to find echo data */
8060 pcmd += sizeof(uint32_t);
8061
8062 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
8063 return 0;
8064}
8065
8066/**
James Smart3621a712009-04-06 18:47:14 -04008067 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04008068 * @vport: pointer to a host virtual N_Port data structure.
8069 * @cmdiocb: pointer to lpfc command iocb data structure.
8070 * @ndlp: pointer to a node-list data structure.
8071 *
8072 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8073 * received as an ELS unsolicited event. Currently, this function just invokes
8074 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8075 *
8076 * Return code
8077 * 0 - Successfully processed lirr iocb (currently always return 0)
8078 **/
dea31012005-04-17 16:05:31 -05008079static int
James Smart2e0fef82007-06-17 19:56:36 -05008080lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8081 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008082{
8083 struct ls_rjt stat;
8084
8085 /* For now, unconditionally reject this command */
8086 stat.un.b.lsRjtRsvd0 = 0;
8087 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8088 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8089 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05008090 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008091 return 0;
8092}
8093
James Smarte59058c2008-08-24 21:49:00 -04008094/**
James Smart5ffc2662009-11-18 15:39:44 -05008095 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8096 * @vport: pointer to a host virtual N_Port data structure.
8097 * @cmdiocb: pointer to lpfc command iocb data structure.
8098 * @ndlp: pointer to a node-list data structure.
8099 *
8100 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8101 * received as an ELS unsolicited event. A request to RRQ shall only
8102 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8103 * Nx_Port N_Port_ID of the target Exchange is the same as the
8104 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8105 * not accepted, an LS_RJT with reason code "Unable to perform
8106 * command request" and reason code explanation "Invalid Originator
8107 * S_ID" shall be returned. For now, we just unconditionally accept
8108 * RRQ from the target.
8109 **/
8110static void
8111lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8112 struct lpfc_nodelist *ndlp)
8113{
8114 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05008115 if (vport->phba->sli_rev == LPFC_SLI_REV4)
8116 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05008117}
8118
8119/**
James Smart12265f62010-10-22 11:05:53 -04008120 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8121 * @phba: pointer to lpfc hba data structure.
8122 * @pmb: pointer to the driver internal queue element for mailbox command.
8123 *
8124 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8125 * mailbox command. This callback function is to actually send the Accept
James Smart69b8eff2021-03-01 09:18:19 -08008126 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
James Smart12265f62010-10-22 11:05:53 -04008127 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
James Smart69b8eff2021-03-01 09:18:19 -08008128 * mailbox command, constructs the RLS response with the link statistics
James Smart12265f62010-10-22 11:05:53 -04008129 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
James Smart69b8eff2021-03-01 09:18:19 -08008130 * response to the RLS.
James Smart12265f62010-10-22 11:05:53 -04008131 *
James Smart69b8eff2021-03-01 09:18:19 -08008132 * Note that the ndlp reference count will be incremented by 1 for holding the
8133 * ndlp and the reference to ndlp will be stored into the context1 field of
8134 * the IOCB for the completion callback function to the RLS Accept Response
8135 * ELS IOCB command.
James Smart12265f62010-10-22 11:05:53 -04008136 *
8137 **/
8138static void
8139lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8140{
James Smart4430f7f2020-11-15 11:26:31 -08008141 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04008142 MAILBOX_t *mb;
8143 IOCB_t *icmd;
8144 struct RLS_RSP *rls_rsp;
8145 uint8_t *pcmd;
8146 struct lpfc_iocbq *elsiocb;
8147 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04008148 uint16_t oxid;
8149 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04008150 uint32_t cmdsize;
8151
8152 mb = &pmb->u.mb;
8153
James Smart3e1f0712018-11-29 16:09:29 -08008154 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
8155 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
8156 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
8157 pmb->ctx_buf = NULL;
8158 pmb->ctx_ndlp = NULL;
James Smart12265f62010-10-22 11:05:53 -04008159
8160 if (mb->mbxStatus) {
8161 mempool_free(pmb, phba->mbox_mem_pool);
8162 return;
8163 }
8164
8165 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04008166 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8167 lpfc_max_els_tries, ndlp,
8168 ndlp->nlp_DID, ELS_CMD_ACC);
8169
8170 /* Decrement the ndlp reference count from previous mbox command */
8171 lpfc_nlp_put(ndlp);
8172
James Smart37db57e2012-05-09 21:17:16 -04008173 if (!elsiocb) {
8174 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04008175 return;
James Smart37db57e2012-05-09 21:17:16 -04008176 }
James Smart12265f62010-10-22 11:05:53 -04008177
8178 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04008179 icmd->ulpContext = rxid;
8180 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04008181
8182 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8183 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8184 pcmd += sizeof(uint32_t); /* Skip past command */
8185 rls_rsp = (struct RLS_RSP *)pcmd;
8186
8187 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
8188 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
8189 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
8190 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
8191 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
8192 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04008193 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04008194 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8195 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8196 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8197 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
8198 elsiocb->iotag, elsiocb->iocb.ulpContext,
8199 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8200 ndlp->nlp_rpi);
8201 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
8202 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08008203 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08008204 if (!elsiocb->context1) {
8205 lpfc_els_free_iocb(phba, elsiocb);
8206 return;
8207 }
James Smart4430f7f2020-11-15 11:26:31 -08008208
8209 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08008210 if (rc == IOCB_ERROR) {
8211 lpfc_els_free_iocb(phba, elsiocb);
8212 lpfc_nlp_put(ndlp);
8213 }
James Smart4430f7f2020-11-15 11:26:31 -08008214 return;
James Smart12265f62010-10-22 11:05:53 -04008215}
8216
8217/**
James Smart12265f62010-10-22 11:05:53 -04008218 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8219 * @vport: pointer to a host virtual N_Port data structure.
8220 * @cmdiocb: pointer to lpfc command iocb data structure.
8221 * @ndlp: pointer to a node-list data structure.
8222 *
James Smart6cde2e3e2020-01-27 16:23:08 -08008223 * This routine processes Read Link Status (RLS) IOCB received as an
James Smart12265f62010-10-22 11:05:53 -04008224 * ELS unsolicited event. It first checks the remote port state. If the
8225 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8226 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8227 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8228 * for reading the HBA link statistics. It is for the callback function,
8229 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8230 * to actually sending out RPL Accept (ACC) response.
8231 *
8232 * Return codes
8233 * 0 - Successfully processed rls iocb (currently always return 0)
8234 **/
8235static int
8236lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8237 struct lpfc_nodelist *ndlp)
8238{
8239 struct lpfc_hba *phba = vport->phba;
8240 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04008241 struct ls_rjt stat;
8242
8243 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8244 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08008245 /* reject the unsolicited RLS request and done with it */
James Smart12265f62010-10-22 11:05:53 -04008246 goto reject_out;
8247
James Smart12265f62010-10-22 11:05:53 -04008248 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
8249 if (mbox) {
8250 lpfc_read_lnk_stat(phba, mbox);
James Smart3e1f0712018-11-29 16:09:29 -08008251 mbox->ctx_buf = (void *)((unsigned long)
James Smart7851fe22011-07-22 18:36:52 -04008252 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
8253 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart3e1f0712018-11-29 16:09:29 -08008254 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008255 if (!mbox->ctx_ndlp)
8256 goto node_err;
James Smart12265f62010-10-22 11:05:53 -04008257 mbox->vport = vport;
8258 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
8259 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8260 != MBX_NOT_FINISHED)
8261 /* Mbox completion will send ELS Response */
8262 return 0;
8263 /* Decrement reference count used for the failed mbox
8264 * command.
8265 */
8266 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008267node_err:
James Smart12265f62010-10-22 11:05:53 -04008268 mempool_free(mbox, phba->mbox_mem_pool);
8269 }
8270reject_out:
8271 /* issue rejection response */
8272 stat.un.b.lsRjtRsvd0 = 0;
8273 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8274 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8275 stat.un.b.vendorUnique = 0;
8276 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8277 return 0;
8278}
8279
8280/**
8281 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8282 * @vport: pointer to a host virtual N_Port data structure.
8283 * @cmdiocb: pointer to lpfc command iocb data structure.
8284 * @ndlp: pointer to a node-list data structure.
8285 *
8286 * This routine processes Read Timout Value (RTV) IOCB received as an
8287 * ELS unsolicited event. It first checks the remote port state. If the
8288 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8289 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8290 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8291 * Value (RTV) unsolicited IOCB event.
8292 *
James Smart69b8eff2021-03-01 09:18:19 -08008293 * Note that the ndlp reference count will be incremented by 1 for holding the
8294 * ndlp and the reference to ndlp will be stored into the context1 field of
8295 * the IOCB for the completion callback function to the RTV Accept Response
8296 * ELS IOCB command.
James Smart12265f62010-10-22 11:05:53 -04008297 *
8298 * Return codes
8299 * 0 - Successfully processed rtv iocb (currently always return 0)
8300 **/
8301static int
8302lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8303 struct lpfc_nodelist *ndlp)
8304{
James Smart4430f7f2020-11-15 11:26:31 -08008305 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04008306 struct lpfc_hba *phba = vport->phba;
8307 struct ls_rjt stat;
8308 struct RTV_RSP *rtv_rsp;
8309 uint8_t *pcmd;
8310 struct lpfc_iocbq *elsiocb;
8311 uint32_t cmdsize;
8312
8313
8314 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8315 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08008316 /* reject the unsolicited RTV request and done with it */
James Smart12265f62010-10-22 11:05:53 -04008317 goto reject_out;
8318
8319 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
8320 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8321 lpfc_max_els_tries, ndlp,
8322 ndlp->nlp_DID, ELS_CMD_ACC);
8323
8324 if (!elsiocb)
8325 return 1;
8326
8327 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
Colin Ian King8fd03fd2017-12-22 00:39:36 +00008328 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart12265f62010-10-22 11:05:53 -04008329 pcmd += sizeof(uint32_t); /* Skip past command */
8330
8331 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04008332 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
8333 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04008334
8335 rtv_rsp = (struct RTV_RSP *)pcmd;
8336
8337 /* populate RTV payload */
8338 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
8339 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
8340 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
8341 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
8342 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
8343
8344 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8345 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8346 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8347 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
8348 "Data: x%x x%x x%x\n",
8349 elsiocb->iotag, elsiocb->iocb.ulpContext,
8350 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8351 ndlp->nlp_rpi,
8352 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
8353 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
8354 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08008355 elsiocb->context1 = lpfc_nlp_get(ndlp);
8356 if (!elsiocb->context1) {
James Smart12265f62010-10-22 11:05:53 -04008357 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08008358 return 0;
8359 }
8360
8361 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8362 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08008363 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08008364 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008365 }
James Smart12265f62010-10-22 11:05:53 -04008366 return 0;
8367
8368reject_out:
8369 /* issue rejection response */
8370 stat.un.b.lsRjtRsvd0 = 0;
8371 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8372 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8373 stat.un.b.vendorUnique = 0;
8374 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8375 return 0;
8376}
8377
James Smart6cde2e3e2020-01-27 16:23:08 -08008378/* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
James Smart19ca7602010-11-20 23:11:55 -05008379 * @vport: pointer to a host virtual N_Port data structure.
8380 * @ndlp: pointer to a node-list data structure.
8381 * @did: DID of the target.
8382 * @rrq: Pointer to the rrq struct.
8383 *
8384 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8385 * Successful the the completion handler will clear the RRQ.
8386 *
8387 * Return codes
8388 * 0 - Successfully sent rrq els iocb.
8389 * 1 - Failed to send rrq els iocb.
8390 **/
8391static int
8392lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8393 uint32_t did, struct lpfc_node_rrq *rrq)
8394{
8395 struct lpfc_hba *phba = vport->phba;
8396 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05008397 struct lpfc_iocbq *elsiocb;
8398 uint8_t *pcmd;
8399 uint16_t cmdsize;
8400 int ret;
8401
James Smart307e3382020-11-15 11:26:30 -08008402 if (!ndlp)
James Smart19ca7602010-11-20 23:11:55 -05008403 return 1;
8404
8405 /* If ndlp is not NULL, we will bump the reference count on it */
8406 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
8407 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
8408 ELS_CMD_RRQ);
8409 if (!elsiocb)
8410 return 1;
8411
James Smart19ca7602010-11-20 23:11:55 -05008412 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8413
8414 /* For RRQ request, remainder of payload is Exchange IDs */
8415 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
8416 pcmd += sizeof(uint32_t);
8417 els_rrq = (struct RRQ *) pcmd;
8418
James Smartee0f4fe2012-05-09 21:19:14 -04008419 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05008420 bf_set(rrq_rxid, els_rrq, rrq->rxid);
8421 bf_set(rrq_did, els_rrq, vport->fc_myDID);
8422 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
8423 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
8424
8425
8426 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8427 "Issue RRQ: did:x%x",
8428 did, rrq->xritag, rrq->rxid);
8429 elsiocb->context_un.rrq = rrq;
8430 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
James Smart2693f5d2021-03-01 09:18:03 -08008431
8432 lpfc_nlp_get(ndlp);
8433 elsiocb->context1 = ndlp;
James Smart19ca7602010-11-20 23:11:55 -05008434
James Smart4430f7f2020-11-15 11:26:31 -08008435 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8436 if (ret == IOCB_ERROR)
8437 goto io_err;
James Smart19ca7602010-11-20 23:11:55 -05008438 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08008439
8440 io_err:
James Smart4430f7f2020-11-15 11:26:31 -08008441 lpfc_els_free_iocb(phba, elsiocb);
James Smart8e9a3252021-03-01 09:18:09 -08008442 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008443 return 1;
James Smart19ca7602010-11-20 23:11:55 -05008444}
8445
8446/**
8447 * lpfc_send_rrq - Sends ELS RRQ if needed.
8448 * @phba: pointer to lpfc hba data structure.
8449 * @rrq: pointer to the active rrq.
8450 *
8451 * This routine will call the lpfc_issue_els_rrq if the rrq is
8452 * still active for the xri. If this function returns a failure then
8453 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8454 *
8455 * Returns 0 Success.
8456 * 1 Failure.
8457 **/
8458int
8459lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
8460{
8461 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
James Smartc8cb2612019-05-06 17:26:49 -07008462 rrq->nlp_DID);
8463 if (!ndlp)
8464 return 1;
8465
James Smart19ca7602010-11-20 23:11:55 -05008466 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
8467 return lpfc_issue_els_rrq(rrq->vport, ndlp,
8468 rrq->nlp_DID, rrq);
8469 else
8470 return 1;
8471}
8472
James Smarte59058c2008-08-24 21:49:00 -04008473/**
James Smart3621a712009-04-06 18:47:14 -04008474 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04008475 * @vport: pointer to a host virtual N_Port data structure.
8476 * @cmdsize: size of the ELS command.
8477 * @oldiocb: pointer to the original lpfc command iocb data structure.
8478 * @ndlp: pointer to a node-list data structure.
8479 *
8480 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
8481 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
8482 *
James Smart69b8eff2021-03-01 09:18:19 -08008483 * Note that the ndlp reference count will be incremented by 1 for holding the
8484 * ndlp and the reference to ndlp will be stored into the context1 field of
8485 * the IOCB for the completion callback function to the RPL Accept Response
8486 * ELS command.
James Smarte59058c2008-08-24 21:49:00 -04008487 *
8488 * Return code
8489 * 0 - Successfully issued ACC RPL ELS command
8490 * 1 - Failed to issue ACC RPL ELS command
8491 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05008492static int
James Smart2e0fef82007-06-17 19:56:36 -05008493lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
8494 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008495{
James Smart4430f7f2020-11-15 11:26:31 -08008496 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05008497 struct lpfc_hba *phba = vport->phba;
8498 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008499 RPL_RSP rpl_rsp;
8500 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008501 uint8_t *pcmd;
8502
James Smart2e0fef82007-06-17 19:56:36 -05008503 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
8504 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008505
James Smart488d1462006-03-07 15:02:37 -05008506 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008507 return 1;
James Smart488d1462006-03-07 15:02:37 -05008508
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008509 icmd = &elsiocb->iocb;
8510 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04008511 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
8512 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008513
8514 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8515 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05008516 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008517 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
8518 pcmd += sizeof(uint16_t);
8519
8520 /* Setup the RPL ACC payload */
8521 rpl_rsp.listLen = be32_to_cpu(1);
8522 rpl_rsp.index = 0;
8523 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05008524 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
8525 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008526 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008527 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008528 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04008529 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8530 "0120 Xmit ELS RPL ACC response tag x%x "
8531 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
8532 "rpi x%x\n",
8533 elsiocb->iotag, elsiocb->iocb.ulpContext,
8534 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8535 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05008536 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008537 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08008538 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -08008539 if (!elsiocb->context1) {
8540 lpfc_els_free_iocb(phba, elsiocb);
8541 return 1;
8542 }
James Smart4430f7f2020-11-15 11:26:31 -08008543
8544 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -08008545 if (rc == IOCB_ERROR) {
8546 lpfc_els_free_iocb(phba, elsiocb);
8547 lpfc_nlp_put(ndlp);
8548 return 1;
8549 }
James Smart4430f7f2020-11-15 11:26:31 -08008550
James Smart8e9a3252021-03-01 09:18:09 -08008551 return 0;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008552}
8553
James Smarte59058c2008-08-24 21:49:00 -04008554/**
James Smart3621a712009-04-06 18:47:14 -04008555 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04008556 * @vport: pointer to a host virtual N_Port data structure.
8557 * @cmdiocb: pointer to lpfc command iocb data structure.
8558 * @ndlp: pointer to a node-list data structure.
8559 *
8560 * This routine processes Read Port List (RPL) IOCB received as an ELS
8561 * unsolicited event. It first checks the remote port state. If the remote
8562 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
8563 * invokes the lpfc_els_rsp_reject() routine to send reject response.
8564 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
8565 * to accept the RPL.
8566 *
8567 * Return code
8568 * 0 - Successfully processed rpl iocb (currently always return 0)
8569 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008570static int
James Smart2e0fef82007-06-17 19:56:36 -05008571lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8572 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05008573{
8574 struct lpfc_dmabuf *pcmd;
8575 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008576 uint32_t maxsize;
8577 uint16_t cmdsize;
8578 RPL *rpl;
8579 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05008580
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05008581 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8582 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04008583 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008584 stat.un.b.lsRjtRsvd0 = 0;
8585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8586 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8587 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05008588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8589 NULL);
James Smart90160e02008-08-24 21:49:45 -04008590 /* rejected the unsolicited RPL request and done with it */
8591 return 0;
dea31012005-04-17 16:05:31 -05008592 }
8593
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008594 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8595 lp = (uint32_t *) pcmd->virt;
8596 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008597 maxsize = be32_to_cpu(rpl->maxsize);
8598
8599 /* We support only one port */
8600 if ((rpl->index == 0) &&
8601 ((maxsize == 0) ||
8602 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
8603 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05008604 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008605 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
8606 }
James Smart2e0fef82007-06-17 19:56:36 -05008607 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05008608
8609 return 0;
8610}
8611
James Smarte59058c2008-08-24 21:49:00 -04008612/**
James Smart3621a712009-04-06 18:47:14 -04008613 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04008614 * @vport: pointer to a virtual N_Port data structure.
8615 * @cmdiocb: pointer to lpfc command iocb data structure.
8616 * @ndlp: pointer to a node-list data structure.
8617 *
8618 * This routine processes Fibre Channel Address Resolution Protocol
8619 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
8620 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
8621 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
8622 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
8623 * remote PortName is compared against the FC PortName stored in the @vport
8624 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
8625 * compared against the FC NodeName stored in the @vport data structure.
8626 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
8627 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
8628 * invoked to send out FARP Response to the remote node. Before sending the
8629 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
8630 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
8631 * routine is invoked to log into the remote port first.
8632 *
8633 * Return code
8634 * 0 - Either the FARP Match Mode not supported or successfully processed
8635 **/
dea31012005-04-17 16:05:31 -05008636static int
James Smart2e0fef82007-06-17 19:56:36 -05008637lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8638 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05008639{
8640 struct lpfc_dmabuf *pcmd;
8641 uint32_t *lp;
8642 IOCB_t *icmd;
8643 FARP *fp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07008644 uint32_t cnt, did;
dea31012005-04-17 16:05:31 -05008645
8646 icmd = &cmdiocb->iocb;
8647 did = icmd->un.elsreq64.remoteID;
8648 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8649 lp = (uint32_t *) pcmd->virt;
8650
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07008651 lp++;
dea31012005-04-17 16:05:31 -05008652 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05008653 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04008654 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8655 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05008656 /* We will only support match on WWPN or WWNN */
8657 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008658 return 0;
dea31012005-04-17 16:05:31 -05008659 }
8660
8661 cnt = 0;
8662 /* If this FARP command is searching for my portname */
8663 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05008664 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05008665 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05008666 cnt = 1;
8667 }
8668
8669 /* If this FARP command is searching for my nodename */
8670 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05008671 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05008672 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05008673 cnt = 1;
8674 }
8675
8676 if (cnt) {
8677 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
8678 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
8679 /* Log back into the node before sending the FARP. */
8680 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05008681 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05008682 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04008683 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05008684 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05008685 }
8686
8687 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05008688 if (fp->Rflags & FARP_REQUEST_FARPR)
8689 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05008690 }
8691 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008692 return 0;
dea31012005-04-17 16:05:31 -05008693}
8694
James Smarte59058c2008-08-24 21:49:00 -04008695/**
James Smart3621a712009-04-06 18:47:14 -04008696 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04008697 * @vport: pointer to a host virtual N_Port data structure.
8698 * @cmdiocb: pointer to lpfc command iocb data structure.
8699 * @ndlp: pointer to a node-list data structure.
8700 *
8701 * This routine processes Fibre Channel Address Resolution Protocol
8702 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
8703 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
8704 * the FARP response request.
8705 *
8706 * Return code
8707 * 0 - Successfully processed FARPR IOCB (currently always return 0)
8708 **/
dea31012005-04-17 16:05:31 -05008709static int
James Smart2e0fef82007-06-17 19:56:36 -05008710lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8711 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05008712{
8713 struct lpfc_dmabuf *pcmd;
8714 uint32_t *lp;
8715 IOCB_t *icmd;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07008716 uint32_t did;
dea31012005-04-17 16:05:31 -05008717
8718 icmd = &cmdiocb->iocb;
8719 did = icmd->un.elsreq64.remoteID;
8720 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8721 lp = (uint32_t *) pcmd->virt;
8722
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07008723 lp++;
dea31012005-04-17 16:05:31 -05008724 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04008725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8726 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05008727 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04008728 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05008729
8730 return 0;
8731}
8732
James Smarte59058c2008-08-24 21:49:00 -04008733/**
James Smart3621a712009-04-06 18:47:14 -04008734 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04008735 * @vport: pointer to a host virtual N_Port data structure.
8736 * @cmdiocb: pointer to lpfc command iocb data structure.
8737 * @fan_ndlp: pointer to a node-list data structure.
8738 *
8739 * This routine processes a Fabric Address Notification (FAN) IOCB
8740 * command received as an ELS unsolicited event. The FAN ELS command will
8741 * only be processed on a physical port (i.e., the @vport represents the
8742 * physical port). The fabric NodeName and PortName from the FAN IOCB are
8743 * compared against those in the phba data structure. If any of those is
8744 * different, the lpfc_initial_flogi() routine is invoked to initialize
8745 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
8746 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
8747 * is invoked to register login to the fabric.
8748 *
8749 * Return code
8750 * 0 - Successfully processed fan iocb (currently always return 0).
8751 **/
dea31012005-04-17 16:05:31 -05008752static int
James Smart2e0fef82007-06-17 19:56:36 -05008753lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8754 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05008755{
James Smart2e0fef82007-06-17 19:56:36 -05008756 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04008757 uint32_t *lp;
8758 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05008759
James Smart0d2b6b82008-06-14 22:52:47 -04008760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
8761 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
8762 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05008763 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04008764 if ((vport == phba->pport) &&
8765 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05008766 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04008767 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05008768 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04008769 sizeof(struct lpfc_name)))) {
8770 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05008771 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04008772 } else {
8773 /* FAN verified - skip FLOGI */
8774 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04008775 if (phba->sli_rev < LPFC_SLI_REV4)
8776 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05008777 else {
8778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8779 "3138 Need register VFI: (x%x/%x)\n",
8780 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04008781 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05008782 }
dea31012005-04-17 16:05:31 -05008783 }
dea31012005-04-17 16:05:31 -05008784 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008785 return 0;
dea31012005-04-17 16:05:31 -05008786}
8787
James Smarte59058c2008-08-24 21:49:00 -04008788/**
James Smart9064aeb2021-08-16 09:28:50 -07008789 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
8790 * @vport: pointer to a host virtual N_Port data structure.
8791 * @cmdiocb: pointer to lpfc command iocb data structure.
8792 * @ndlp: pointer to a node-list data structure.
8793 *
8794 * Return code
8795 * 0 - Successfully processed echo iocb (currently always return 0)
8796 **/
8797static int
8798lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8799 struct lpfc_nodelist *ndlp)
8800{
8801 struct lpfc_hba *phba = vport->phba;
8802 struct fc_els_edc *edc_req;
8803 struct fc_tlv_desc *tlv;
8804 uint8_t *payload;
8805 uint32_t *ptr, dtag;
8806 const char *dtag_nm;
8807 int desc_cnt = 0, bytes_remain;
8808 bool rcv_cap_desc = false;
8809
8810 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
8811
8812 edc_req = (struct fc_els_edc *)payload;
8813 bytes_remain = be32_to_cpu(edc_req->desc_len);
8814
8815 ptr = (uint32_t *)payload;
8816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
8817 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
8818 bytes_remain, be32_to_cpu(*ptr),
8819 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
8820
8821 /* No signal support unless there is a congestion descriptor */
8822 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
8823 phba->cgn_sig_freq = 0;
8824 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
8825
8826 if (bytes_remain <= 0)
8827 goto out;
8828
8829 tlv = edc_req->desc;
8830
8831 /*
8832 * cycle through EDC diagnostic descriptors to find the
8833 * congestion signaling capability descriptor
8834 */
8835 while (bytes_remain && !rcv_cap_desc) {
8836 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
8837 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8838 "6464 Truncated TLV hdr on "
8839 "Diagnostic descriptor[%d]\n",
8840 desc_cnt);
8841 goto out;
8842 }
8843
8844 dtag = be32_to_cpu(tlv->desc_tag);
8845 switch (dtag) {
8846 case ELS_DTAG_LNK_FAULT_CAP:
8847 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
8848 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
8849 sizeof(struct fc_diag_lnkflt_desc)) {
8850 lpfc_printf_log(
8851 phba, KERN_WARNING, LOG_CGN_MGMT,
8852 "6465 Truncated Link Fault Diagnostic "
8853 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
8854 desc_cnt, bytes_remain,
8855 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
8856 sizeof(struct fc_diag_cg_sig_desc));
8857 goto out;
8858 }
8859 /* No action for Link Fault descriptor for now */
8860 break;
8861 case ELS_DTAG_CG_SIGNAL_CAP:
8862 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
8863 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
8864 sizeof(struct fc_diag_cg_sig_desc)) {
8865 lpfc_printf_log(
8866 phba, KERN_WARNING, LOG_CGN_MGMT,
8867 "6466 Truncated cgn signal Diagnostic "
8868 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
8869 desc_cnt, bytes_remain,
8870 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
8871 sizeof(struct fc_diag_cg_sig_desc));
8872 goto out;
8873 }
8874
8875 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
8876 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
8877
8878 /* We start negotiation with lpfc_fabric_cgn_frequency.
8879 * When we process the EDC, we will settle on the
8880 * higher frequency.
8881 */
8882 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
8883
8884 lpfc_least_capable_settings(
8885 phba, (struct fc_diag_cg_sig_desc *)tlv);
8886 rcv_cap_desc = true;
8887 break;
8888 default:
8889 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8890 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8891 "6467 unknown Diagnostic "
8892 "Descriptor[%d]: tag x%x (%s)\n",
8893 desc_cnt, dtag, dtag_nm);
8894 }
8895 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8896 tlv = fc_tlv_next_desc(tlv);
8897 desc_cnt++;
8898 }
8899out:
8900 /* Need to send back an ACC */
8901 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
8902
8903 lpfc_config_cgn_signal(phba);
8904 return 0;
8905}
8906
8907/**
James Smart3621a712009-04-06 18:47:14 -04008908 * lpfc_els_timeout - Handler funciton to the els timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01008909 * @t: timer context used to obtain the vport.
James Smarte59058c2008-08-24 21:49:00 -04008910 *
8911 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8912 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8913 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8914 * up the worker thread. It is for the worker thread to invoke the routine
8915 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8916 **/
dea31012005-04-17 16:05:31 -05008917void
Kees Cookf22eb4d2017-09-06 20:24:26 -07008918lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05008919{
Kees Cookf22eb4d2017-09-06 20:24:26 -07008920 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05008921 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04008922 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05008923 unsigned long iflag;
8924
James Smart2e0fef82007-06-17 19:56:36 -05008925 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04008926 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05008927 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05008928 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04008929 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05008930
James Smart06918ac2014-02-20 09:57:57 -05008931 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04008932 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05008933 return;
8934}
8935
James Smart2a9bf3d2010-06-07 15:24:45 -04008936
James Smarte59058c2008-08-24 21:49:00 -04008937/**
James Smart3621a712009-04-06 18:47:14 -04008938 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04008939 * @vport: pointer to a virtual N_Port data structure.
8940 *
8941 * This routine is the actual handler function that processes an ELS timeout
8942 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8943 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8944 * invoking the lpfc_sli_issue_abort_iotag() routine.
8945 **/
dea31012005-04-17 16:05:31 -05008946void
James Smart2e0fef82007-06-17 19:56:36 -05008947lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008948{
James Smart2e0fef82007-06-17 19:56:36 -05008949 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05008950 struct lpfc_sli_ring *pring;
8951 struct lpfc_iocbq *tmp_iocb, *piocb;
8952 IOCB_t *cmd = NULL;
8953 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05008954 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05008955 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05008956 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04008957 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05008958
James Smart2a9bf3d2010-06-07 15:24:45 -04008959
dea31012005-04-17 16:05:31 -05008960 timeout = (uint32_t)(phba->fc_ratov << 1);
8961
James Smart895427b2017-02-12 13:52:30 -08008962 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07008963 if (unlikely(!pring))
8964 return;
James Smart895427b2017-02-12 13:52:30 -08008965
James Smarte3041422020-04-21 13:33:54 -07008966 if (phba->pport->load_flag & FC_UNLOADING)
James Smart06918ac2014-02-20 09:57:57 -05008967 return;
James Smarte3041422020-04-21 13:33:54 -07008968
James Smart2a9bf3d2010-06-07 15:24:45 -04008969 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05008970 if (phba->sli_rev == LPFC_SLI_REV4)
8971 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04008972
James Smart0976e1a2013-12-17 20:29:36 -05008973 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05008974 cmd = &piocb->iocb;
8975
James Smart2e0fef82007-06-17 19:56:36 -05008976 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8977 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8978 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05008979 continue;
James Smart2e0fef82007-06-17 19:56:36 -05008980
8981 if (piocb->vport != vport)
8982 continue;
8983
dea31012005-04-17 16:05:31 -05008984 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05008985 if (pcmd)
8986 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05008987
James Smart92d7f7b2007-06-17 19:56:38 -05008988 if (els_command == ELS_CMD_FARP ||
8989 els_command == ELS_CMD_FARPR ||
8990 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05008991 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05008992
dea31012005-04-17 16:05:31 -05008993 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05008994 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05008995 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05008996 else
dea31012005-04-17 16:05:31 -05008997 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05008998 continue;
8999 }
9000
James Smart2e0fef82007-06-17 19:56:36 -05009001 remote_ID = 0xffffffff;
9002 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05009003 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05009004 else {
9005 struct lpfc_nodelist *ndlp;
9006 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart307e3382020-11-15 11:26:30 -08009007 if (ndlp)
James Smart2e0fef82007-06-17 19:56:36 -05009008 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05009009 }
James Smart2a9bf3d2010-06-07 15:24:45 -04009010 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05009011 }
James Smart0976e1a2013-12-17 20:29:36 -05009012 if (phba->sli_rev == LPFC_SLI_REV4)
9013 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05009014 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04009015
James Smart2a9bf3d2010-06-07 15:24:45 -04009016 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05009017 cmd = &piocb->iocb;
Dick Kennedy372c1872020-06-30 14:50:00 -07009018 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart2a9bf3d2010-06-07 15:24:45 -04009019 "0127 ELS timeout Data: x%x x%x x%x "
9020 "x%x\n", els_command,
9021 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
9022 spin_lock_irq(&phba->hbalock);
9023 list_del_init(&piocb->dlist);
James Smartdb7531d2020-11-15 11:26:44 -08009024 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
James Smart2a9bf3d2010-06-07 15:24:45 -04009025 spin_unlock_irq(&phba->hbalock);
9026 }
9027
James Smarta22d73b2021-01-04 10:02:38 -08009028 /* Make sure HBA is alive */
9029 lpfc_issue_hb_tmo(phba);
9030
James Smart895427b2017-02-12 13:52:30 -08009031 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05009032 if (!(phba->pport->load_flag & FC_UNLOADING))
9033 mod_timer(&vport->els_tmofunc,
9034 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05009035}
9036
James Smarte59058c2008-08-24 21:49:00 -04009037/**
James Smart3621a712009-04-06 18:47:14 -04009038 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04009039 * @vport: pointer to a host virtual N_Port data structure.
9040 *
9041 * This routine is used to clean up all the outstanding ELS commands on a
9042 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9043 * routine. After that, it walks the ELS transmit queue to remove all the
9044 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9045 * the IOCBs with a non-NULL completion callback function, the callback
9046 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9047 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9048 * callback function, the IOCB will simply be released. Finally, it walks
9049 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9050 * completion queue IOCB that is associated with the @vport and is not
9051 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9052 * part of the discovery state machine) out to HBA by invoking the
9053 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9054 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9055 * the IOCBs are aborted when this function returns.
9056 **/
dea31012005-04-17 16:05:31 -05009057void
James Smart2e0fef82007-06-17 19:56:36 -05009058lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05009059{
James Smart0976e1a2013-12-17 20:29:36 -05009060 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05009061 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08009062 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05009063 struct lpfc_iocbq *tmp_iocb, *piocb;
9064 IOCB_t *cmd = NULL;
James Smartd38b4a52019-09-21 20:59:00 -07009065 unsigned long iflags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009066
9067 lpfc_fabric_abort_vport(vport);
James Smartd38b4a52019-09-21 20:59:00 -07009068
James Smart0976e1a2013-12-17 20:29:36 -05009069 /*
9070 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9071 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9072 * ultimately grabs the ring_lock, the driver must splice the list into
9073 * a working list and release the locks before calling the abort.
9074 */
James Smartd38b4a52019-09-21 20:59:00 -07009075 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart895427b2017-02-12 13:52:30 -08009076 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03009077
9078 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9079 if (unlikely(!pring)) {
James Smartd38b4a52019-09-21 20:59:00 -07009080 spin_unlock_irqrestore(&phba->hbalock, iflags);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03009081 return;
9082 }
9083
James Smart0976e1a2013-12-17 20:29:36 -05009084 if (phba->sli_rev == LPFC_SLI_REV4)
9085 spin_lock(&pring->ring_lock);
9086
James Smart6ede2dd2019-08-14 16:56:44 -07009087 /* First we need to issue aborts to outstanding cmds on txcmpl */
James Smart0976e1a2013-12-17 20:29:36 -05009088 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9089 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
9090 continue;
9091
9092 if (piocb->vport != vport)
9093 continue;
James Smart6ede2dd2019-08-14 16:56:44 -07009094
James Smart15498dc2019-09-21 20:58:59 -07009095 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
9096 continue;
9097
James Smart6ede2dd2019-08-14 16:56:44 -07009098 /* On the ELS ring we can have ELS_REQUESTs or
9099 * GEN_REQUESTs waiting for a response.
9100 */
9101 cmd = &piocb->iocb;
9102 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
9103 list_add_tail(&piocb->dlist, &abort_list);
9104
9105 /* If the link is down when flushing ELS commands
9106 * the firmware will not complete them till after
9107 * the link comes back up. This may confuse
9108 * discovery for the new link up, so we need to
9109 * change the compl routine to just clean up the iocb
9110 * and avoid any retry logic.
9111 */
9112 if (phba->link_state == LPFC_LINK_DOWN)
9113 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
9114 }
9115 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
9116 list_add_tail(&piocb->dlist, &abort_list);
James Smart0976e1a2013-12-17 20:29:36 -05009117 }
James Smart6ede2dd2019-08-14 16:56:44 -07009118
James Smart0976e1a2013-12-17 20:29:36 -05009119 if (phba->sli_rev == LPFC_SLI_REV4)
9120 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07009121 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6ede2dd2019-08-14 16:56:44 -07009122
9123 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
James Smart0976e1a2013-12-17 20:29:36 -05009124 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smartd38b4a52019-09-21 20:59:00 -07009125 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05009126 list_del_init(&piocb->dlist);
James Smartdb7531d2020-11-15 11:26:44 -08009127 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
James Smartd38b4a52019-09-21 20:59:00 -07009128 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05009129 }
James Smarta22d73b2021-01-04 10:02:38 -08009130 /* Make sure HBA is alive */
9131 lpfc_issue_hb_tmo(phba);
9132
James Smart0976e1a2013-12-17 20:29:36 -05009133 if (!list_empty(&abort_list))
Dick Kennedy372c1872020-06-30 14:50:00 -07009134 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart0976e1a2013-12-17 20:29:36 -05009135 "3387 abort list for txq not empty\n");
9136 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05009137
James Smartd38b4a52019-09-21 20:59:00 -07009138 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05009139 if (phba->sli_rev == LPFC_SLI_REV4)
9140 spin_lock(&pring->ring_lock);
9141
James Smart6ede2dd2019-08-14 16:56:44 -07009142 /* No need to abort the txq list,
9143 * just queue them up for lpfc_sli_cancel_iocbs
9144 */
dea31012005-04-17 16:05:31 -05009145 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
9146 cmd = &piocb->iocb;
9147
9148 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
9149 continue;
9150 }
9151
9152 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04009153 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
9154 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
9155 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
9156 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05009157 continue;
dea31012005-04-17 16:05:31 -05009158
James Smart2e0fef82007-06-17 19:56:36 -05009159 if (piocb->vport != vport)
9160 continue;
9161
James Smart0976e1a2013-12-17 20:29:36 -05009162 list_del_init(&piocb->list);
9163 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05009164 }
James Smart6ede2dd2019-08-14 16:56:44 -07009165
9166 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9167 if (vport == phba->pport) {
9168 list_for_each_entry_safe(piocb, tmp_iocb,
9169 &phba->fabric_iocb_list, list) {
9170 cmd = &piocb->iocb;
9171 list_del_init(&piocb->list);
9172 list_add_tail(&piocb->list, &abort_list);
9173 }
9174 }
9175
James Smart0976e1a2013-12-17 20:29:36 -05009176 if (phba->sli_rev == LPFC_SLI_REV4)
9177 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07009178 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart2534ba72007-04-25 09:52:20 -04009179
James Smart6ede2dd2019-08-14 16:56:44 -07009180 /* Cancel all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05009181 lpfc_sli_cancel_iocbs(phba, &abort_list,
9182 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04009183
dea31012005-04-17 16:05:31 -05009184 return;
9185}
9186
James Smarte59058c2008-08-24 21:49:00 -04009187/**
James Smart3621a712009-04-06 18:47:14 -04009188 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04009189 * @phba: pointer to lpfc hba data structure.
9190 *
9191 * This routine is used to clean up all the outstanding ELS commands on a
9192 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9193 * routine. After that, it walks the ELS transmit queue to remove all the
9194 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9195 * the IOCBs with the completion callback function associated, the callback
9196 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9197 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9198 * callback function associated, the IOCB will simply be released. Finally,
9199 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9200 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9201 * management plane IOCBs that are not part of the discovery state machine)
9202 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9203 **/
James Smart549e55c2007-08-02 11:09:51 -04009204void
9205lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
9206{
James Smart0976e1a2013-12-17 20:29:36 -05009207 struct lpfc_vport *vport;
James Smart523128e2018-09-10 10:30:46 -07009208
9209 spin_lock_irq(&phba->port_list_lock);
James Smart0976e1a2013-12-17 20:29:36 -05009210 list_for_each_entry(vport, &phba->port_list, listentry)
9211 lpfc_els_flush_cmd(vport);
James Smart523128e2018-09-10 10:30:46 -07009212 spin_unlock_irq(&phba->port_list_lock);
James Smarta257bf92009-04-06 18:48:10 -04009213
James Smart549e55c2007-08-02 11:09:51 -04009214 return;
9215}
9216
James Smarte59058c2008-08-24 21:49:00 -04009217/**
James Smart3621a712009-04-06 18:47:14 -04009218 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04009219 * @phba: Pointer to hba context object.
9220 * @cmdiocbp: Pointer to command iocb which reported error.
9221 * @rspiocbp: Pointer to response iocb which reported error.
9222 *
9223 * This function sends an event when there is an ELS command
9224 * failure.
9225 **/
9226void
9227lpfc_send_els_failure_event(struct lpfc_hba *phba,
9228 struct lpfc_iocbq *cmdiocbp,
9229 struct lpfc_iocbq *rspiocbp)
9230{
9231 struct lpfc_vport *vport = cmdiocbp->vport;
9232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9233 struct lpfc_lsrjt_event lsrjt_event;
9234 struct lpfc_fabric_event_header fabric_event;
9235 struct ls_rjt stat;
9236 struct lpfc_nodelist *ndlp;
9237 uint32_t *pcmd;
9238
9239 ndlp = cmdiocbp->context1;
James Smart307e3382020-11-15 11:26:30 -08009240 if (!ndlp)
James Smartea2151b2008-09-07 11:52:10 -04009241 return;
9242
9243 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
9244 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
9245 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
9246 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
9247 sizeof(struct lpfc_name));
9248 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
9249 sizeof(struct lpfc_name));
9250 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9251 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04009252 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04009253 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
9254 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
9255 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
9256 fc_host_post_vendor_event(shost,
9257 fc_get_event_number(),
9258 sizeof(lsrjt_event),
9259 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05009260 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04009261 return;
9262 }
9263 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
9264 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
9265 fabric_event.event_type = FC_REG_FABRIC_EVENT;
9266 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
9267 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
9268 else
9269 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
9270 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
9271 sizeof(struct lpfc_name));
9272 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
9273 sizeof(struct lpfc_name));
9274 fc_host_post_vendor_event(shost,
9275 fc_get_event_number(),
9276 sizeof(fabric_event),
9277 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05009278 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04009279 return;
9280 }
9281
9282}
9283
9284/**
James Smart3621a712009-04-06 18:47:14 -04009285 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04009286 * @vport: Pointer to vport object.
9287 * @ndlp: Pointer FC node object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01009288 * @payload: ELS command code type.
James Smartea2151b2008-09-07 11:52:10 -04009289 *
9290 * This function posts an event when there is an incoming
9291 * unsolicited ELS command.
9292 **/
9293static void
9294lpfc_send_els_event(struct lpfc_vport *vport,
9295 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05009296 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04009297{
James Smartddcc50f2008-12-04 22:38:46 -05009298 struct lpfc_els_event_header *els_data = NULL;
9299 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04009300 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9301
James Smartddcc50f2008-12-04 22:38:46 -05009302 if (*payload == ELS_CMD_LOGO) {
9303 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
9304 if (!logo_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009305 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05009306 "0148 Failed to allocate memory "
9307 "for LOGO event\n");
9308 return;
9309 }
9310 els_data = &logo_data->header;
9311 } else {
9312 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
9313 GFP_KERNEL);
9314 if (!els_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009315 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05009316 "0149 Failed to allocate memory "
9317 "for ELS event\n");
9318 return;
9319 }
9320 }
9321 els_data->event_type = FC_REG_ELS_EVENT;
9322 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04009323 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05009324 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04009325 break;
9326 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05009327 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04009328 break;
9329 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05009330 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
9331 break;
9332 case ELS_CMD_LOGO:
9333 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
9334 /* Copy the WWPN in the LOGO payload */
9335 memcpy(logo_data->logo_wwpn, &payload[2],
9336 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04009337 break;
9338 default:
Julia Lawalle9161412009-02-08 22:43:19 +01009339 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04009340 return;
9341 }
James Smartddcc50f2008-12-04 22:38:46 -05009342 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
9343 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
9344 if (*payload == ELS_CMD_LOGO) {
9345 fc_host_post_vendor_event(shost,
9346 fc_get_event_number(),
9347 sizeof(struct lpfc_logo_event),
9348 (char *)logo_data,
9349 LPFC_NL_VENDOR_ID);
9350 kfree(logo_data);
9351 } else {
9352 fc_host_post_vendor_event(shost,
9353 fc_get_event_number(),
9354 sizeof(struct lpfc_els_event_header),
9355 (char *)els_data,
9356 LPFC_NL_VENDOR_ID);
9357 kfree(els_data);
9358 }
James Smartea2151b2008-09-07 11:52:10 -04009359
9360 return;
9361}
9362
9363
James Smartdf3fe762020-02-10 09:31:55 -08009364DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
9365 FC_FPIN_LI_EVT_TYPES_INIT);
9366
James Smart428569e2021-08-16 09:28:49 -07009367DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
9368 FC_FPIN_DELI_EVT_TYPES_INIT);
9369
9370DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
9371 FC_FPIN_CONGN_EVT_TYPES_INIT);
9372
9373DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
9374 fc_fpin_congn_severity_types,
9375 FC_FPIN_CONGN_SEVERITY_INIT);
9376
9377
9378/**
9379 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9380 * @phba: Pointer to phba object.
9381 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9382 * @cnt: count of WWPNs in FPIN payload
9383 *
9384 * This routine is called by LI and PC descriptors.
9385 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9386 */
9387static void
9388lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
9389{
9390 char buf[LPFC_FPIN_WWPN_LINE_SZ];
9391 __be64 wwn;
9392 u64 wwpn;
9393 int i, len;
9394 int line = 0;
9395 int wcnt = 0;
9396 bool endit = false;
9397
9398 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
9399 for (i = 0; i < cnt; i++) {
9400 /* Are we on the last WWPN */
9401 if (i == (cnt - 1))
9402 endit = true;
9403
9404 /* Extract the next WWPN from the payload */
9405 wwn = *wwnlist++;
9406 wwpn = be64_to_cpu(wwn);
Dan Carpentercdbc16c2021-09-16 16:22:51 +03009407 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
James Smart428569e2021-08-16 09:28:49 -07009408 " %016llx", wwpn);
9409
9410 /* Log a message if we are on the last WWPN
9411 * or if we hit the max allowed per message.
9412 */
9413 wcnt++;
9414 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
9415 buf[len] = 0;
9416 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9417 "4686 %s\n", buf);
9418
9419 /* Check if we reached the last WWPN */
9420 if (endit)
9421 return;
9422
9423 /* Limit the number of log message displayed per FPIN */
9424 line++;
9425 if (line == LPFC_FPIN_WWPN_NUM_LINE) {
9426 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9427 "4687 %d WWPNs Truncated\n",
9428 cnt - i - 1);
9429 return;
9430 }
9431
9432 /* Start over with next log message */
9433 wcnt = 0;
9434 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
9435 "Additional WWPNs:");
9436 }
9437 }
9438}
9439
James Smartdf3fe762020-02-10 09:31:55 -08009440/**
9441 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
James Smart428569e2021-08-16 09:28:49 -07009442 * @phba: Pointer to phba object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01009443 * @tlv: Pointer to the Link Integrity Notification Descriptor.
James Smartdf3fe762020-02-10 09:31:55 -08009444 *
James Smart428569e2021-08-16 09:28:49 -07009445 * This function processes a Link Integrity FPIN event by logging a message.
James Smartdf3fe762020-02-10 09:31:55 -08009446 **/
9447static void
James Smart428569e2021-08-16 09:28:49 -07009448lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
James Smartdf3fe762020-02-10 09:31:55 -08009449{
9450 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
9451 const char *li_evt_str;
James Smart428569e2021-08-16 09:28:49 -07009452 u32 li_evt, cnt;
James Smartdf3fe762020-02-10 09:31:55 -08009453
9454 li_evt = be16_to_cpu(li->event_type);
9455 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
James Smart428569e2021-08-16 09:28:49 -07009456 cnt = be32_to_cpu(li->pname_count);
James Smartdf3fe762020-02-10 09:31:55 -08009457
James Smart428569e2021-08-16 09:28:49 -07009458 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9459 "4680 FPIN Link Integrity %s (x%x) "
9460 "Detecting PN x%016llx Attached PN x%016llx "
9461 "Duration %d mSecs Count %d Port Cnt %d\n",
9462 li_evt_str, li_evt,
9463 be64_to_cpu(li->detecting_wwpn),
9464 be64_to_cpu(li->attached_wwpn),
9465 be32_to_cpu(li->event_threshold),
9466 be32_to_cpu(li->event_count), cnt);
9467
9468 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
9469}
9470
9471/**
9472 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
9473 * @phba: Pointer to hba object.
9474 * @tlv: Pointer to the Delivery Notification Descriptor TLV
9475 *
9476 * This function processes a Delivery FPIN event by logging a message.
9477 **/
9478static void
9479lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9480{
9481 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
9482 const char *del_rsn_str;
9483 u32 del_rsn;
9484 __be32 *frame;
9485
9486 del_rsn = be16_to_cpu(del->deli_reason_code);
9487 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
9488
9489 /* Skip over desc_tag/desc_len header to payload */
9490 frame = (__be32 *)(del + 1);
9491
9492 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9493 "4681 FPIN Delivery %s (x%x) "
9494 "Detecting PN x%016llx Attached PN x%016llx "
9495 "DiscHdr0 x%08x "
9496 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
9497 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
9498 del_rsn_str, del_rsn,
9499 be64_to_cpu(del->detecting_wwpn),
9500 be64_to_cpu(del->attached_wwpn),
9501 be32_to_cpu(frame[0]),
9502 be32_to_cpu(frame[1]),
9503 be32_to_cpu(frame[2]),
9504 be32_to_cpu(frame[3]),
9505 be32_to_cpu(frame[4]),
9506 be32_to_cpu(frame[5]));
9507}
9508
9509/**
9510 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
9511 * @phba: Pointer to hba object.
9512 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
9513 *
9514 * This function processes a Peer Congestion FPIN event by logging a message.
9515 **/
9516static void
9517lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9518{
9519 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
9520 const char *pc_evt_str;
9521 u32 pc_evt, cnt;
9522
9523 pc_evt = be16_to_cpu(pc->event_type);
9524 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
9525 cnt = be32_to_cpu(pc->pname_count);
9526
9527 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
9528 "4684 FPIN Peer Congestion %s (x%x) "
9529 "Duration %d mSecs "
9530 "Detecting PN x%016llx Attached PN x%016llx "
9531 "Impacted Port Cnt %d\n",
9532 pc_evt_str, pc_evt,
9533 be32_to_cpu(pc->event_period),
9534 be64_to_cpu(pc->detecting_wwpn),
9535 be64_to_cpu(pc->attached_wwpn),
9536 cnt);
9537
9538 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
9539}
9540
9541/**
9542 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
9543 * @phba: Pointer to hba object.
9544 * @tlv: Pointer to the Congestion Notification Descriptor TLV
9545 *
9546 * This function processes an FPIN Congestion Notifiction. The notification
9547 * could be an Alarm or Warning. This routine feeds that data into driver's
9548 * running congestion algorithm. It also processes the FPIN by
9549 * logging a message. It returns 1 to indicate deliver this message
9550 * to the upper layer or 0 to indicate don't deliver it.
9551 **/
9552static int
9553lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9554{
James Smart02243832021-08-16 09:28:54 -07009555 struct lpfc_cgn_info *cp;
James Smart428569e2021-08-16 09:28:49 -07009556 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
9557 const char *cgn_evt_str;
9558 u32 cgn_evt;
9559 const char *cgn_sev_str;
9560 u32 cgn_sev;
James Smart02243832021-08-16 09:28:54 -07009561 uint16_t value;
James Smart7481811c2021-08-16 09:28:56 -07009562 u32 crc;
James Smart428569e2021-08-16 09:28:49 -07009563 bool nm_log = false;
9564 int rc = 1;
9565
9566 cgn_evt = be16_to_cpu(cgn->event_type);
9567 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
9568 cgn_sev = cgn->severity;
9569 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
9570
9571 /* The driver only takes action on a Credit Stall or Oversubscription
9572 * event type to engage the IO algorithm. The driver prints an
9573 * unmaskable message only for Lost Credit and Credit Stall.
9574 * TODO: Still need to have definition of host action on clear,
9575 * lost credit and device specific event types.
9576 */
9577 switch (cgn_evt) {
9578 case FPIN_CONGN_LOST_CREDIT:
9579 nm_log = true;
9580 break;
9581 case FPIN_CONGN_CREDIT_STALL:
9582 nm_log = true;
9583 fallthrough;
9584 case FPIN_CONGN_OVERSUBSCRIPTION:
9585 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
9586 nm_log = false;
9587 switch (cgn_sev) {
9588 case FPIN_CONGN_SEVERITY_ERROR:
9589 /* Take action here for an Alarm event */
James Smart02243832021-08-16 09:28:54 -07009590 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9591 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
9592 /* Track of alarm cnt for cgn_info */
9593 atomic_inc(&phba->cgn_fabric_alarm_cnt);
9594 /* Track of alarm cnt for SYNC_WQE */
9595 atomic_inc(&phba->cgn_sync_alarm_cnt);
9596 }
9597 goto cleanup;
9598 }
James Smart428569e2021-08-16 09:28:49 -07009599 break;
9600 case FPIN_CONGN_SEVERITY_WARNING:
9601 /* Take action here for a Warning event */
James Smart02243832021-08-16 09:28:54 -07009602 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9603 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
9604 /* Track of warning cnt for cgn_info */
9605 atomic_inc(&phba->cgn_fabric_warn_cnt);
9606 /* Track of warning cnt for SYNC_WQE */
9607 atomic_inc(&phba->cgn_sync_warn_cnt);
9608 }
9609cleanup:
9610 /* Save frequency in ms */
9611 phba->cgn_fpin_frequency =
9612 be32_to_cpu(cgn->event_period);
9613 value = phba->cgn_fpin_frequency;
9614 if (phba->cgn_i) {
9615 cp = (struct lpfc_cgn_info *)
9616 phba->cgn_i->virt;
9617 if (phba->cgn_reg_fpin &
9618 LPFC_CGN_FPIN_ALARM)
9619 cp->cgn_alarm_freq =
9620 cpu_to_le16(value);
9621 if (phba->cgn_reg_fpin &
9622 LPFC_CGN_FPIN_WARN)
9623 cp->cgn_warn_freq =
9624 cpu_to_le16(value);
James Smart7481811c2021-08-16 09:28:56 -07009625 crc = lpfc_cgn_calc_crc32
9626 (cp,
9627 LPFC_CGN_INFO_SZ,
9628 LPFC_CGN_CRC32_SEED);
9629 cp->cgn_info_crc = cpu_to_le32(crc);
James Smart02243832021-08-16 09:28:54 -07009630 }
9631
9632 /* Don't deliver to upper layer since
9633 * driver took action on this tlv.
9634 */
9635 rc = 0;
9636 }
James Smart428569e2021-08-16 09:28:49 -07009637 break;
9638 }
9639 break;
9640 }
9641
9642 /* Change the log level to unmaskable for the following event types. */
9643 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
9644 LOG_CGN_MGMT | LOG_ELS,
9645 "4683 FPIN CONGESTION %s type %s (x%x) Event "
9646 "Duration %d mSecs\n",
9647 cgn_sev_str, cgn_evt_str, cgn_evt,
9648 be32_to_cpu(cgn->event_period));
9649 return rc;
James Smartdf3fe762020-02-10 09:31:55 -08009650}
9651
James Smart74a7baa2021-08-16 09:28:58 -07009652void
James Smart428569e2021-08-16 09:28:49 -07009653lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
James Smartdf3fe762020-02-10 09:31:55 -08009654{
James Smart428569e2021-08-16 09:28:49 -07009655 struct lpfc_hba *phba = vport->phba;
9656 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
9657 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
James Smartdf3fe762020-02-10 09:31:55 -08009658 const char *dtag_nm;
James Smart428569e2021-08-16 09:28:49 -07009659 int desc_cnt = 0, bytes_remain, cnt;
9660 u32 dtag, deliver = 0;
9661 int len;
James Smartdf3fe762020-02-10 09:31:55 -08009662
9663 /* FPINs handled only if we are in the right discovery state */
9664 if (vport->port_state < LPFC_DISC_AUTH)
9665 return;
9666
9667 /* make sure there is the full fpin header */
9668 if (fpin_length < sizeof(struct fc_els_fpin))
9669 return;
9670
James Smart428569e2021-08-16 09:28:49 -07009671 /* Sanity check descriptor length. The desc_len value does not
9672 * include space for the ELS command and the desc_len fields.
9673 */
9674 len = be32_to_cpu(fpin->desc_len);
9675 if (fpin_length < len + sizeof(struct fc_els_fpin)) {
9676 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9677 "4671 Bad ELS FPIN length %d: %d\n",
9678 len, fpin_length);
9679 return;
9680 }
9681
James Smartdf3fe762020-02-10 09:31:55 -08009682 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
James Smart428569e2021-08-16 09:28:49 -07009683 first_tlv = tlv;
James Smartdf3fe762020-02-10 09:31:55 -08009684 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
9685 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
9686
James Smart428569e2021-08-16 09:28:49 -07009687 /* process each descriptor separately */
James Smartdf3fe762020-02-10 09:31:55 -08009688 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
9689 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
James Smartdf3fe762020-02-10 09:31:55 -08009690 dtag = be32_to_cpu(tlv->desc_tag);
9691 switch (dtag) {
9692 case ELS_DTAG_LNK_INTEGRITY:
James Smart428569e2021-08-16 09:28:49 -07009693 lpfc_els_rcv_fpin_li(phba, tlv);
9694 deliver = 1;
9695 break;
9696 case ELS_DTAG_DELIVERY:
9697 lpfc_els_rcv_fpin_del(phba, tlv);
9698 deliver = 1;
9699 break;
9700 case ELS_DTAG_PEER_CONGEST:
9701 lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
9702 deliver = 1;
9703 break;
9704 case ELS_DTAG_CONGESTION:
9705 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
James Smartdf3fe762020-02-10 09:31:55 -08009706 break;
9707 default:
9708 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
James Smart428569e2021-08-16 09:28:49 -07009709 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9710 "4678 unknown FPIN descriptor[%d]: "
9711 "tag x%x (%s)\n",
9712 desc_cnt, dtag, dtag_nm);
9713
9714 /* If descriptor is bad, drop the rest of the data */
9715 return;
9716 }
James Smart7481811c2021-08-16 09:28:56 -07009717 lpfc_cgn_update_stat(phba, dtag);
James Smart428569e2021-08-16 09:28:49 -07009718 cnt = be32_to_cpu(tlv->desc_len);
9719
9720 /* Sanity check descriptor length. The desc_len value does not
9721 * include space for the desc_tag and the desc_len fields.
9722 */
9723 len -= (cnt + sizeof(struct fc_tlv_desc));
9724 if (len < 0) {
9725 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
9726 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9727 "4672 Bad FPIN descriptor TLV length "
9728 "%d: %d %d %s\n",
9729 cnt, len, fpin_length, dtag_nm);
9730 return;
James Smartdf3fe762020-02-10 09:31:55 -08009731 }
9732
James Smart428569e2021-08-16 09:28:49 -07009733 current_tlv = tlv;
James Smartdf3fe762020-02-10 09:31:55 -08009734 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
9735 tlv = fc_tlv_next_desc(tlv);
James Smartdf3fe762020-02-10 09:31:55 -08009736
James Smart428569e2021-08-16 09:28:49 -07009737 /* Format payload such that the FPIN delivered to the
9738 * upper layer is a single descriptor FPIN.
9739 */
9740 if (desc_cnt)
9741 memcpy(first_tlv, current_tlv,
9742 (cnt + sizeof(struct fc_els_fpin)));
9743
9744 /* Adjust the length so that it only reflects a
9745 * single descriptor FPIN.
9746 */
9747 fpin_length = cnt + sizeof(struct fc_els_fpin);
9748 fpin->desc_len = cpu_to_be32(fpin_length);
9749 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
9750
9751 /* Send every descriptor individually to the upper layer */
9752 if (deliver)
9753 fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
9754 fpin_length, (char *)fpin);
9755 desc_cnt++;
9756 }
James Smartdf3fe762020-02-10 09:31:55 -08009757}
9758
James Smartea2151b2008-09-07 11:52:10 -04009759/**
James Smart3621a712009-04-06 18:47:14 -04009760 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04009761 * @phba: pointer to lpfc hba data structure.
9762 * @pring: pointer to a SLI ring.
9763 * @vport: pointer to a host virtual N_Port data structure.
9764 * @elsiocb: pointer to lpfc els command iocb data structure.
9765 *
9766 * This routine is used for processing the IOCB associated with a unsolicited
9767 * event. It first determines whether there is an existing ndlp that matches
9768 * the DID from the unsolicited IOCB. If not, it will create a new one with
9769 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
9770 * IOCB is then used to invoke the proper routine and to set up proper state
9771 * of the discovery state machine.
9772 **/
James Smarted957682007-06-17 19:56:37 -05009773static void
9774lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05009775 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05009776{
dea31012005-04-17 16:05:31 -05009777 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05009778 struct ls_rjt stat;
James Smartdf3fe762020-02-10 09:31:55 -08009779 uint32_t *payload, payload_len;
James Smart303f2f92013-01-03 15:43:11 -05009780 uint32_t cmd, did, newnode;
James Smartd496b9a2018-10-23 13:41:08 -07009781 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
James Smarted957682007-06-17 19:56:37 -05009782 IOCB_t *icmd = &elsiocb->iocb;
James Smartd496b9a2018-10-23 13:41:08 -07009783 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05009784
James Smarte47c9092008-02-08 18:49:26 -05009785 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05009786 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05009787
dea31012005-04-17 16:05:31 -05009788 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009789 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
James Smartdf3fe762020-02-10 09:31:55 -08009790 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
James Smart92d7f7b2007-06-17 19:56:38 -05009791 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05009792 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04009793 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05009794
James Smart858c9f62007-06-17 19:56:39 -05009795 did = icmd->un.rcvels.remoteID;
9796 if (icmd->ulpStatus) {
9797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9798 "RCV Unsol ELS: status:x%x/x%x did:x%x",
9799 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05009800 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05009801 }
dea31012005-04-17 16:05:31 -05009802
9803 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05009804 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05009805 goto dropit;
dea31012005-04-17 16:05:31 -05009806
James Smartc8685952009-11-18 15:39:16 -05009807 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05009808 if (vport->load_flag & FC_UNLOADING)
9809 goto dropit;
9810
James Smart92494142011-02-16 12:39:44 -05009811 /* If NPort discovery is delayed drop incoming ELS */
9812 if ((vport->fc_flag & FC_DISC_DELAYED) &&
9813 (cmd != ELS_CMD_PLOGI))
9814 goto dropit;
9815
James Smart2e0fef82007-06-17 19:56:36 -05009816 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05009817 if (!ndlp) {
dea31012005-04-17 16:05:31 -05009818 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07009819 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05009820 if (!ndlp)
dea31012005-04-17 16:05:31 -05009821 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04009822 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05009823 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05009824 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05009825 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04009826 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
James Smart58da1ff2008-04-07 10:15:56 -04009827 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
9828 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04009829 }
dea31012005-04-17 16:05:31 -05009830
9831 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05009832
James Smart12838e72014-09-03 12:57:19 -04009833 /*
9834 * Do not process any unsolicited ELS commands
9835 * if the ndlp is in DEV_LOSS
9836 */
James Smartc6adba12020-11-15 11:26:34 -08009837 spin_lock_irq(&ndlp->lock);
James Smart466e8402015-05-21 13:55:28 -04009838 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
James Smartc6adba12020-11-15 11:26:34 -08009839 spin_unlock_irq(&ndlp->lock);
Xiyu Yang7217e6e2020-05-25 22:16:24 +08009840 if (newnode)
9841 lpfc_nlp_put(ndlp);
James Smart12838e72014-09-03 12:57:19 -04009842 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04009843 }
James Smartc6adba12020-11-15 11:26:34 -08009844 spin_unlock_irq(&ndlp->lock);
James Smart12838e72014-09-03 12:57:19 -04009845
James Smart329f9bc2007-04-25 09:53:01 -04009846 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08009847 if (!elsiocb->context1)
9848 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05009849 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05009850
9851 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
9852 cmd &= ELS_CMD_MASK;
9853 }
9854 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04009855 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9856 "0112 ELS command x%x received from NPORT x%x "
James Smarta70e63e2020-11-15 11:26:38 -08009857 "refcnt %d Data: x%x x%x x%x x%x\n",
9858 cmd, did, kref_read(&ndlp->kref), vport->port_state,
9859 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04009860
James Smart0a9e9682018-11-29 16:09:36 -08009861 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
James Smarteec3d312015-08-31 16:48:18 -04009862 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smart0a9e9682018-11-29 16:09:36 -08009863 (cmd != ELS_CMD_FLOGI) &&
9864 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
James Smart401304c2016-10-13 15:06:14 -07009865 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04009866 rjt_exp = LSEXP_NOTHING_MORE;
9867 goto lsrjt;
9868 }
9869
dea31012005-04-17 16:05:31 -05009870 switch (cmd) {
9871 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05009872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9873 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
9874 did, vport->port_state, ndlp->nlp_flag);
9875
dea31012005-04-17 16:05:31 -05009876 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05009877 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04009878 if (phba->sli_rev == LPFC_SLI_REV4 &&
9879 (phba->pport->fc_flag & FC_PT2PT)) {
9880 vport->fc_prevDID = vport->fc_myDID;
9881 /* Our DID needs to be updated before registering
9882 * the vfi. This is done in lpfc_rcv_plogi but
9883 * that is called after the reg_vfi.
9884 */
9885 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
9886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9887 "3312 Remote port assigned DID x%x "
9888 "%x\n", vport->fc_myDID,
9889 vport->fc_prevDID);
9890 }
James Smart858c9f62007-06-17 19:56:39 -05009891
James Smartddcc50f2008-12-04 22:38:46 -05009892 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05009893
9894 /* If Nport discovery is delayed, reject PLOGIs */
9895 if (vport->fc_flag & FC_DISC_DELAYED) {
9896 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05009897 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05009898 break;
9899 }
James Smartd6de08c2015-12-16 18:11:53 -05009900
James Smart858c9f62007-06-17 19:56:39 -05009901 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05009902 if (!(phba->pport->fc_flag & FC_PT2PT) ||
9903 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
9904 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05009905 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05009906 break;
9907 }
dea31012005-04-17 16:05:31 -05009908 }
James Smart87af33f2007-10-27 13:37:43 -04009909
James Smartc6adba12020-11-15 11:26:34 -08009910 spin_lock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04009911 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
James Smartc6adba12020-11-15 11:26:34 -08009912 spin_unlock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04009913
James Smart2e0fef82007-06-17 19:56:36 -05009914 lpfc_disc_state_machine(vport, ndlp, elsiocb,
9915 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05009916
dea31012005-04-17 16:05:31 -05009917 break;
9918 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05009919 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9920 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
9921 did, vport->port_state, ndlp->nlp_flag);
9922
dea31012005-04-17 16:05:31 -05009923 phba->fc_stat.elsRcvFLOGI++;
James Smartd496b9a2018-10-23 13:41:08 -07009924
9925 /* If the driver believes fabric discovery is done and is ready,
9926 * bounce the link. There is some descrepancy.
9927 */
9928 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
9929 vport->fc_flag & FC_PT2PT &&
9930 vport->rcv_flogi_cnt >= 1) {
9931 rjt_err = LSRJT_LOGICAL_BSY;
9932 rjt_exp = LSEXP_NOTHING_MORE;
9933 init_link++;
9934 goto lsrjt;
9935 }
9936
James Smart51ef4c22007-08-02 11:10:31 -04009937 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04009938 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08009939 lpfc_disc_state_machine(vport, ndlp, NULL,
9940 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05009941 break;
9942 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05009943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9944 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
9945 did, vport->port_state, ndlp->nlp_flag);
9946
dea31012005-04-17 16:05:31 -05009947 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05009948 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05009949 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05009950 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05009951 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05009952 break;
9953 }
James Smart2e0fef82007-06-17 19:56:36 -05009954 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
James Smarte77803b2021-07-07 11:43:36 -07009955 if (newnode)
9956 lpfc_disc_state_machine(vport, ndlp, NULL,
9957 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05009958 break;
9959 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05009960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9961 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
9962 did, vport->port_state, ndlp->nlp_flag);
9963
dea31012005-04-17 16:05:31 -05009964 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05009965 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05009966 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05009967 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05009968 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05009969 break;
9970 }
James Smart2e0fef82007-06-17 19:56:36 -05009971 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05009972 break;
James Smart8b017a32015-05-21 13:55:18 -04009973 case ELS_CMD_LCB:
9974 phba->fc_stat.elsRcvLCB++;
9975 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
9976 break;
James Smart86478872015-05-21 13:55:21 -04009977 case ELS_CMD_RDP:
9978 phba->fc_stat.elsRcvRDP++;
9979 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
9980 break;
dea31012005-04-17 16:05:31 -05009981 case ELS_CMD_RSCN:
9982 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04009983 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04009984 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08009985 lpfc_disc_state_machine(vport, ndlp, NULL,
9986 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05009987 break;
9988 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05009989 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9990 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
9991 did, vport->port_state, ndlp->nlp_flag);
9992
James Smartddcc50f2008-12-04 22:38:46 -05009993 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05009994 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05009995 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05009996 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05009997 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05009998 break;
9999 }
James Smart2e0fef82007-06-17 19:56:36 -050010000 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10001 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -050010002 break;
10003 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -050010004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10005 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
10006 did, vport->port_state, ndlp->nlp_flag);
10007
dea31012005-04-17 16:05:31 -050010008 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -050010009 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -050010010 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -050010011 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -050010012 break;
10013 }
James Smart2e0fef82007-06-17 19:56:36 -050010014 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10015 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -050010016 break;
10017 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -050010018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10019 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
10020 did, vport->port_state, ndlp->nlp_flag);
10021
dea31012005-04-17 16:05:31 -050010022 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -050010023 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -050010024 break;
10025 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -050010026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10027 "RCV FARP: did:x%x/ste:x%x flg:x%x",
10028 did, vport->port_state, ndlp->nlp_flag);
10029
dea31012005-04-17 16:05:31 -050010030 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -050010031 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -050010032 break;
10033 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -050010034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10035 "RCV FAN: did:x%x/ste:x%x flg:x%x",
10036 did, vport->port_state, ndlp->nlp_flag);
10037
dea31012005-04-17 16:05:31 -050010038 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -050010039 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -050010040 break;
dea31012005-04-17 16:05:31 -050010041 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -080010042 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -050010043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10044 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
10045 did, vport->port_state, ndlp->nlp_flag);
10046
dea31012005-04-17 16:05:31 -050010047 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -040010048 if ((vport->port_state < LPFC_DISC_AUTH) &&
10049 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -050010050 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -050010051 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -050010052 break;
10053 }
James Smart2e0fef82007-06-17 19:56:36 -050010054 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -050010055 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010056 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -050010057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10058 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
10059 did, vport->port_state, ndlp->nlp_flag);
10060
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010061 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -050010062 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -040010063 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010064 lpfc_disc_state_machine(vport, ndlp, NULL,
10065 NLP_EVT_DEVICE_RM);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010066 break;
James Smart12265f62010-10-22 11:05:53 -040010067 case ELS_CMD_RLS:
10068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10069 "RCV RLS: did:x%x/ste:x%x flg:x%x",
10070 did, vport->port_state, ndlp->nlp_flag);
10071
10072 phba->fc_stat.elsRcvRLS++;
10073 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
10074 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010075 lpfc_disc_state_machine(vport, ndlp, NULL,
10076 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -040010077 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010078 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -050010079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10080 "RCV RPL: did:x%x/ste:x%x flg:x%x",
10081 did, vport->port_state, ndlp->nlp_flag);
10082
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010083 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -050010084 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -040010085 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010086 lpfc_disc_state_machine(vport, ndlp, NULL,
10087 NLP_EVT_DEVICE_RM);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -050010088 break;
dea31012005-04-17 16:05:31 -050010089 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -050010090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10091 "RCV RNID: did:x%x/ste:x%x flg:x%x",
10092 did, vport->port_state, ndlp->nlp_flag);
10093
dea31012005-04-17 16:05:31 -050010094 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -050010095 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -040010096 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010097 lpfc_disc_state_machine(vport, ndlp, NULL,
10098 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -050010099 break;
James Smart12265f62010-10-22 11:05:53 -040010100 case ELS_CMD_RTV:
10101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10102 "RCV RTV: did:x%x/ste:x%x flg:x%x",
10103 did, vport->port_state, ndlp->nlp_flag);
10104 phba->fc_stat.elsRcvRTV++;
10105 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
10106 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010107 lpfc_disc_state_machine(vport, ndlp, NULL,
10108 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -040010109 break;
James Smart5ffc2662009-11-18 15:39:44 -050010110 case ELS_CMD_RRQ:
10111 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10112 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
10113 did, vport->port_state, ndlp->nlp_flag);
10114
10115 phba->fc_stat.elsRcvRRQ++;
10116 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
10117 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010118 lpfc_disc_state_machine(vport, ndlp, NULL,
10119 NLP_EVT_DEVICE_RM);
James Smart5ffc2662009-11-18 15:39:44 -050010120 break;
James Smart12265f62010-10-22 11:05:53 -040010121 case ELS_CMD_ECHO:
10122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10123 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
10124 did, vport->port_state, ndlp->nlp_flag);
10125
10126 phba->fc_stat.elsRcvECHO++;
10127 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
10128 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010129 lpfc_disc_state_machine(vport, ndlp, NULL,
10130 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -040010131 break;
James Smart303f2f92013-01-03 15:43:11 -050010132 case ELS_CMD_REC:
Colin Ian King8fd03fd2017-12-22 00:39:36 +000010133 /* receive this due to exchange closed */
10134 rjt_err = LSRJT_UNABLE_TPC;
10135 rjt_exp = LSEXP_INVALID_OX_RX;
James Smart303f2f92013-01-03 15:43:11 -050010136 break;
James Smart1a61e542019-04-05 16:04:23 -070010137 case ELS_CMD_FPIN:
James Smartdf3fe762020-02-10 09:31:55 -080010138 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10139 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
10140 did, vport->port_state, ndlp->nlp_flag);
10141
10142 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
10143 payload_len);
10144
10145 /* There are no replies, so no rjt codes */
James Smart1a61e542019-04-05 16:04:23 -070010146 break;
James Smart9064aeb2021-08-16 09:28:50 -070010147 case ELS_CMD_EDC:
10148 lpfc_els_rcv_edc(vport, elsiocb, ndlp);
10149 break;
James Smart8eced802021-05-14 12:55:58 -070010150 case ELS_CMD_RDF:
10151 phba->fc_stat.elsRcvRDF++;
10152 /* Accept RDF only from fabric controller */
10153 if (did != Fabric_Cntl_DID) {
10154 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
10155 "1115 Received RDF from invalid DID "
10156 "x%x\n", did);
10157 rjt_err = LSRJT_PROTOCOL_ERR;
10158 rjt_exp = LSEXP_NOTHING_MORE;
10159 goto lsrjt;
10160 }
10161
10162 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
10163 break;
dea31012005-04-17 16:05:31 -050010164 default:
James Smart858c9f62007-06-17 19:56:39 -050010165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10166 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10167 cmd, did, vport->port_state);
10168
dea31012005-04-17 16:05:31 -050010169 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -050010170 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -050010171 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -050010172
10173 /* Unknown ELS command <elsCmd> received from NPORT <did> */
Dick Kennedy372c1872020-06-30 14:50:00 -070010174 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010175 "0115 Unknown ELS command x%x "
10176 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -040010177 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010178 lpfc_disc_state_machine(vport, ndlp, NULL,
10179 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -050010180 break;
10181 }
10182
James Smarteec3d312015-08-31 16:48:18 -040010183lsrjt:
dea31012005-04-17 16:05:31 -050010184 /* check if need to LS_RJT received ELS cmd */
10185 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -050010186 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -050010187 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -050010188 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -050010189 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
James Smart4430f7f2020-11-15 11:26:31 -080010190 NULL);
10191 /* Remove the reference from above for new nodes. */
10192 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -080010193 lpfc_disc_state_machine(vport, ndlp, NULL,
10194 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -050010195 }
10196
James Smarte9b11082020-11-15 11:26:33 -080010197 /* Release the reference on this elsiocb, not the ndlp. */
James Smartd7c255b2008-08-24 21:50:00 -040010198 lpfc_nlp_put(elsiocb->context1);
10199 elsiocb->context1 = NULL;
James Smartd496b9a2018-10-23 13:41:08 -070010200
10201 /* Special case. Driver received an unsolicited command that
10202 * unsupportable given the driver's current state. Reset the
10203 * link and start over.
10204 */
10205 if (init_link) {
10206 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10207 if (!mbox)
10208 return;
10209 lpfc_linkdown(phba);
10210 lpfc_init_link(phba, mbox,
10211 phba->cfg_topology,
10212 phba->cfg_link_speed);
10213 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
10214 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10215 mbox->vport = vport;
10216 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
10217 MBX_NOT_FINISHED)
10218 mempool_free(mbox, phba->mbox_mem_pool);
10219 }
10220
James Smarted957682007-06-17 19:56:37 -050010221 return;
10222
10223dropit:
James Smart98c9ea52007-10-27 13:37:33 -040010224 if (vport && !(vport->load_flag & FC_UNLOADING))
Dick Kennedy372c1872020-06-30 14:50:00 -070010225 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -040010226 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -050010227 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -040010228 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -050010229 phba->fc_stat.elsRcvDrop++;
10230}
10231
James Smarte59058c2008-08-24 21:49:00 -040010232/**
James Smart3621a712009-04-06 18:47:14 -040010233 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -040010234 * @phba: pointer to lpfc hba data structure.
10235 * @pring: pointer to a SLI ring.
10236 * @elsiocb: pointer to lpfc els iocb data structure.
10237 *
10238 * This routine is used to process an unsolicited event received from a SLI
10239 * (Service Level Interface) ring. The actual processing of the data buffer
10240 * associated with the unsolicited event is done by invoking the routine
10241 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10242 * SLI ring on which the unsolicited event was received.
10243 **/
James Smarted957682007-06-17 19:56:37 -050010244void
10245lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10246 struct lpfc_iocbq *elsiocb)
10247{
10248 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -050010249 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -050010250 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -050010251 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
10252 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -050010253
James Smartd7c255b2008-08-24 21:50:00 -040010254 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050010255 elsiocb->context2 = NULL;
10256 elsiocb->context3 = NULL;
10257
10258 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
10259 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
10260 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -040010261 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
10262 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -050010263 phba->fc_stat.NoRcvBuf++;
10264 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -050010265 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -040010266 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -050010267 return;
10268 }
10269
James Smart92d7f7b2007-06-17 19:56:38 -050010270 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
10271 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
10272 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
10273 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
10274 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -040010275 else
10276 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -040010277 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -050010278 }
James Smart6d368e52011-05-24 11:44:12 -040010279
James Smart7f5f3d02008-02-08 18:50:14 -050010280 /* If there are no BDEs associated
10281 * with this IOCB, there is nothing to do.
10282 */
James Smarted957682007-06-17 19:56:37 -050010283 if (icmd->ulpBdeCount == 0)
10284 return;
10285
James Smart7f5f3d02008-02-08 18:50:14 -050010286 /* type of ELS cmd is first 32bit word
10287 * in packet
10288 */
James Smarted957682007-06-17 19:56:37 -050010289 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -050010290 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -050010291 } else {
10292 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
10293 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -050010294 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
10295 paddr);
James Smarted957682007-06-17 19:56:37 -050010296 }
10297
James Smart92d7f7b2007-06-17 19:56:38 -050010298 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
10299 /*
10300 * The different unsolicited event handlers would tell us
10301 * if they are done with "mp" by setting context2 to NULL.
10302 */
dea31012005-04-17 16:05:31 -050010303 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -050010304 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
10305 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -050010306 }
James Smarted957682007-06-17 19:56:37 -050010307
10308 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -050010309 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -050010310 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -050010311 elsiocb->context2 = bdeBuf2;
10312 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -050010313 /* free mp if we are done with it */
10314 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -050010315 lpfc_in_buf_free(phba, elsiocb->context2);
10316 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -050010317 }
dea31012005-04-17 16:05:31 -050010318 }
dea31012005-04-17 16:05:31 -050010319}
James Smart92d7f7b2007-06-17 19:56:38 -050010320
Baoyou Xiebd4b3e52016-09-25 13:44:55 +080010321static void
James Smart4258e982015-12-16 18:11:58 -050010322lpfc_start_fdmi(struct lpfc_vport *vport)
10323{
James Smart4258e982015-12-16 18:11:58 -050010324 struct lpfc_nodelist *ndlp;
10325
10326 /* If this is the first time, allocate an ndlp and initialize
10327 * it. Otherwise, make sure the node is enabled and then do the
10328 * login.
10329 */
10330 ndlp = lpfc_findnode_did(vport, FDMI_DID);
10331 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -070010332 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -050010333 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -050010334 ndlp->nlp_type |= NLP_FABRIC;
10335 } else {
10336 return;
10337 }
10338 }
James Smart4258e982015-12-16 18:11:58 -050010339
James Smart307e3382020-11-15 11:26:30 -080010340 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10341 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart4258e982015-12-16 18:11:58 -050010342}
10343
James Smarte59058c2008-08-24 21:49:00 -040010344/**
James Smart3621a712009-04-06 18:47:14 -040010345 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -040010346 * @phba: pointer to lpfc hba data structure.
10347 * @vport: pointer to a virtual N_Port data structure.
10348 *
10349 * This routine issues a Port Login (PLOGI) to the Name Server with
10350 * State Change Request (SCR) for a @vport. This routine will create an
10351 * ndlp for the Name Server associated to the @vport if such node does
10352 * not already exist. The PLOGI to Name Server is issued by invoking the
10353 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10354 * (FDMI) is configured to the @vport, a FDMI node will be created and
10355 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10356 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010357void
10358lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
10359{
James Smart4258e982015-12-16 18:11:58 -050010360 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -050010361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10362
10363 /*
10364 * If lpfc_delay_discovery parameter is set and the clean address
10365 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10366 * discovery.
10367 */
10368 spin_lock_irq(shost->host_lock);
10369 if (vport->fc_flag & FC_DISC_DELAYED) {
10370 spin_unlock_irq(shost->host_lock);
James Smarta70e63e2020-11-15 11:26:38 -080010371 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10372 "3334 Delay fc port discovery for %d secs\n",
10373 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -050010374 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -040010375 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -050010376 return;
10377 }
10378 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -050010379
10380 ndlp = lpfc_findnode_did(vport, NameServer_DID);
10381 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -070010382 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -050010383 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -050010384 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -050010385 lpfc_disc_start(vport);
10386 return;
10387 }
10388 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -070010389 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010390 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -050010391 return;
10392 }
James Smart92d7f7b2007-06-17 19:56:38 -050010393 }
James Smart307e3382020-11-15 11:26:30 -080010394
James Smart58da1ff2008-04-07 10:15:56 -040010395 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -050010396
10397 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10398
10399 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
10400 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -070010401 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010402 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -050010403 return;
10404 }
10405
James Smart8663cbb2016-03-31 14:12:33 -070010406 if ((phba->cfg_enable_SmartSAN ||
10407 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
10408 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -050010409 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -050010410}
10411
James Smarte59058c2008-08-24 21:49:00 -040010412/**
James Smart3621a712009-04-06 18:47:14 -040010413 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -040010414 * @phba: pointer to lpfc hba data structure.
10415 * @pmb: pointer to the driver internal queue element for mailbox command.
10416 *
10417 * This routine is the completion callback function to register new vport
10418 * mailbox command. If the new vport mailbox command completes successfully,
10419 * the fabric registration login shall be performed on physical port (the
10420 * new vport created is actually a physical port, with VPI 0) or the port
10421 * login to Name Server for State Change Request (SCR) will be performed
10422 * on virtual port (real virtual port, with VPI greater than 0).
10423 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010424static void
10425lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
10426{
10427 struct lpfc_vport *vport = pmb->vport;
10428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart3e1f0712018-11-29 16:09:29 -080010429 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart04c68492009-05-22 14:52:52 -040010430 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -050010431 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -050010432
James Smart09372822008-01-11 01:52:54 -050010433 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -050010434 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -050010435 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -050010436
10437 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010438 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart38b92ef2010-08-04 16:11:39 -040010439 "0915 Register VPI failed : Status: x%x"
10440 " upd bit: x%x \n", mb->mbxStatus,
10441 mb->un.varRegVpi.upd);
10442 if (phba->sli_rev == LPFC_SLI_REV4 &&
10443 mb->un.varRegVpi.upd)
10444 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -050010445
10446 switch (mb->mbxStatus) {
10447 case 0x11: /* unsupported feature */
10448 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -050010449 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -050010450 /* giving up on vport registration */
10451 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10452 spin_lock_irq(shost->host_lock);
10453 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
10454 spin_unlock_irq(shost->host_lock);
10455 lpfc_can_disctmo(vport);
10456 break;
James Smart695a8142010-01-26 23:08:03 -050010457 /* If reg_vpi fail with invalid VPI status, re-init VPI */
10458 case 0x20:
10459 spin_lock_irq(shost->host_lock);
10460 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
10461 spin_unlock_irq(shost->host_lock);
10462 lpfc_init_vpi(phba, pmb, vport->vpi);
10463 pmb->vport = vport;
10464 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
10465 rc = lpfc_sli_issue_mbox(phba, pmb,
10466 MBX_NOWAIT);
10467 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010468 lpfc_printf_vlog(vport, KERN_ERR,
10469 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -050010470 "2732 Failed to issue INIT_VPI"
10471 " mailbox command\n");
10472 } else {
10473 lpfc_nlp_put(ndlp);
10474 return;
10475 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -050010476 fallthrough;
James Smart92d7f7b2007-06-17 19:56:38 -050010477 default:
10478 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -040010479 if (phba->sli_rev == LPFC_SLI_REV4)
10480 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -050010481 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -050010482 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -050010483 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -050010484 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -080010485 if (mb->mbxStatus == MBX_NOT_FINISHED)
10486 break;
10487 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
10488 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
10489 if (phba->sli_rev == LPFC_SLI_REV4)
10490 lpfc_issue_init_vfi(vport);
10491 else
10492 lpfc_initial_flogi(vport);
10493 } else {
James Smart7f5f3d02008-02-08 18:50:14 -050010494 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -080010495 }
James Smart92d7f7b2007-06-17 19:56:38 -050010496 break;
10497 }
James Smart92d7f7b2007-06-17 19:56:38 -050010498 } else {
James Smart695a8142010-01-26 23:08:03 -050010499 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -050010500 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -050010501 spin_unlock_irq(shost->host_lock);
10502 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -040010503 if (phba->sli_rev < LPFC_SLI_REV4)
10504 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -050010505 else {
James Smartfc2b9892010-02-26 14:15:29 -050010506 /*
10507 * If the physical port is instantiated using
10508 * FDISC, do not start vport discovery.
10509 */
10510 if (vport->port_state != LPFC_FDISC)
10511 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -050010512 lpfc_do_scr_ns_plogi(phba, vport);
10513 }
James Smarte9b11082020-11-15 11:26:33 -080010514 } else {
James Smart92d7f7b2007-06-17 19:56:38 -050010515 lpfc_do_scr_ns_plogi(phba, vport);
James Smarte9b11082020-11-15 11:26:33 -080010516 }
James Smart92d7f7b2007-06-17 19:56:38 -050010517 }
James Smart38b92ef2010-08-04 16:11:39 -040010518mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -050010519 /* Now, we decrement the ndlp reference count held for this
10520 * callback function
10521 */
10522 lpfc_nlp_put(ndlp);
10523
James Smart92d7f7b2007-06-17 19:56:38 -050010524 mempool_free(pmb, phba->mbox_mem_pool);
10525 return;
10526}
10527
James Smarte59058c2008-08-24 21:49:00 -040010528/**
James Smart3621a712009-04-06 18:47:14 -040010529 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -040010530 * @phba: pointer to lpfc hba data structure.
10531 * @vport: pointer to a host virtual N_Port data structure.
10532 * @ndlp: pointer to a node-list data structure.
10533 *
10534 * This routine registers the @vport as a new virtual port with a HBA.
10535 * It is done through a registering vpi mailbox command.
10536 **/
James Smart695a8142010-01-26 23:08:03 -050010537void
James Smart92d7f7b2007-06-17 19:56:38 -050010538lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
10539 struct lpfc_nodelist *ndlp)
10540{
James Smart09372822008-01-11 01:52:54 -050010541 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -050010542 LPFC_MBOXQ_t *mbox;
10543
10544 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10545 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -040010546 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -050010547 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -080010548 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -080010549 if (!mbox->ctx_ndlp) {
10550 mempool_free(mbox, phba->mbox_mem_pool);
10551 goto mbox_err_exit;
10552 }
10553
James Smart92d7f7b2007-06-17 19:56:38 -050010554 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -040010555 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -050010556 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -050010557 /* mailbox command not success, decrement ndlp
10558 * reference count for this command
10559 */
10560 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050010561 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -050010562
Dick Kennedy372c1872020-06-30 14:50:00 -070010563 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010564 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -050010565 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -050010566 }
10567 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -070010568 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010569 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -050010570 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -050010571 }
James Smartfa4066b2008-01-11 01:53:27 -050010572 return;
10573
10574mbox_err_exit:
10575 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10576 spin_lock_irq(shost->host_lock);
10577 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
10578 spin_unlock_irq(shost->host_lock);
10579 return;
James Smart92d7f7b2007-06-17 19:56:38 -050010580}
10581
James Smarte59058c2008-08-24 21:49:00 -040010582/**
James Smart0c9ab6f2010-02-26 14:15:57 -050010583 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -050010584 * @phba: pointer to lpfc hba data structure.
10585 *
James Smart0c9ab6f2010-02-26 14:15:57 -050010586 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -050010587 **/
10588void
James Smart0c9ab6f2010-02-26 14:15:57 -050010589lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -050010590{
10591 struct lpfc_vport **vports;
10592 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -050010593 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -050010594 int i;
James Smart695a8142010-01-26 23:08:03 -050010595
10596 /* Treat this failure as linkdown for all vports */
10597 link_state = phba->link_state;
10598 lpfc_linkdown(phba);
10599 phba->link_state = link_state;
10600
10601 vports = lpfc_create_vport_work_array(phba);
10602
10603 if (vports) {
10604 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10605 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
10606 if (ndlp)
10607 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
10608 lpfc_els_flush_cmd(vports[i]);
10609 }
10610 lpfc_destroy_vport_work_array(phba, vports);
10611 }
James Smart0c9ab6f2010-02-26 14:15:57 -050010612}
10613
10614/**
10615 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
10616 * @phba: pointer to lpfc hba data structure.
10617 *
10618 * This routine abort all pending discovery commands and
10619 * start a timer to retry FLOGI for the physical port
10620 * discovery.
10621 **/
10622void
10623lpfc_retry_pport_discovery(struct lpfc_hba *phba)
10624{
10625 struct lpfc_nodelist *ndlp;
James Smart0c9ab6f2010-02-26 14:15:57 -050010626
10627 /* Cancel the all vports retry delay retry timers */
10628 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -050010629
10630 /* If fabric require FLOGI, then re-instantiate physical login */
10631 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
10632 if (!ndlp)
10633 return;
10634
James Smart256ec0d2013-04-17 20:14:58 -040010635 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smartc6adba12020-11-15 11:26:34 -080010636 spin_lock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -050010637 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -080010638 spin_unlock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -050010639 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
10640 phba->pport->port_state = LPFC_FLOGI;
10641 return;
10642}
10643
10644/**
10645 * lpfc_fabric_login_reqd - Check if FLOGI required.
10646 * @phba: pointer to lpfc hba data structure.
10647 * @cmdiocb: pointer to FDISC command iocb.
10648 * @rspiocb: pointer to FDISC response iocb.
10649 *
10650 * This routine checks if a FLOGI is reguired for FDISC
10651 * to succeed.
10652 **/
10653static int
10654lpfc_fabric_login_reqd(struct lpfc_hba *phba,
10655 struct lpfc_iocbq *cmdiocb,
10656 struct lpfc_iocbq *rspiocb)
10657{
10658
10659 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
10660 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
10661 return 0;
10662 else
10663 return 1;
10664}
10665
10666/**
James Smart3621a712009-04-06 18:47:14 -040010667 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -040010668 * @phba: pointer to lpfc hba data structure.
10669 * @cmdiocb: pointer to lpfc command iocb data structure.
10670 * @rspiocb: pointer to lpfc response iocb data structure.
10671 *
10672 * This routine is the completion callback function to a Fabric Discover
10673 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
10674 * single threaded, each FDISC completion callback function will reset
10675 * the discovery timer for all vports such that the timers will not get
10676 * unnecessary timeout. The function checks the FDISC IOCB status. If error
10677 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
10678 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
10679 * assigned to the vport has been changed with the completion of the FDISC
10680 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
10681 * are unregistered from the HBA, and then the lpfc_register_new_vport()
10682 * routine is invoked to register new vport with the HBA. Otherwise, the
10683 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
10684 * Server for State Change Request (SCR).
10685 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010686static void
10687lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10688 struct lpfc_iocbq *rspiocb)
10689{
10690 struct lpfc_vport *vport = cmdiocb->vport;
10691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10692 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
10693 struct lpfc_nodelist *np;
10694 struct lpfc_nodelist *next_np;
10695 IOCB_t *irsp = &rspiocb->iocb;
10696 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -050010697 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
10698 struct serv_parm *sp;
10699 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -050010700
James Smarte8b62012007-08-02 11:10:09 -040010701 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10702 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
10703 irsp->ulpStatus, irsp->un.ulpWord[4],
10704 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -050010705 /* Since all FDISCs are being single threaded, we
10706 * must reset the discovery timer for ALL vports
10707 * waiting to send FDISC when one completes.
10708 */
10709 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
10710 lpfc_set_disctmo(piocb->vport);
10711 }
10712
James Smart858c9f62007-06-17 19:56:39 -050010713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
10714 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
10715 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
10716
James Smart92d7f7b2007-06-17 19:56:38 -050010717 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -050010718
10719 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
10720 lpfc_retry_pport_discovery(phba);
10721 goto out;
10722 }
10723
James Smart92d7f7b2007-06-17 19:56:38 -050010724 /* Check for retry */
10725 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
10726 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -050010727 /* FDISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -070010728 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6b5151f2012-01-18 16:24:06 -050010729 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -040010730 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -040010731 goto fdisc_failed;
10732 }
James Smartaf984c82021-10-20 14:14:16 -070010733
10734 lpfc_check_nlp_post_devloss(vport, ndlp);
10735
James Smartd7c255b2008-08-24 21:50:00 -040010736 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -050010737 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -040010738 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -040010739 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -050010740 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -040010741 vport->fc_flag |= FC_PUBLIC_LOOP;
10742 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -050010743
James Smartd7c255b2008-08-24 21:50:00 -040010744 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
10745 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -050010746 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -040010747 if (!prsp)
10748 goto out;
James Smart92494142011-02-16 12:39:44 -050010749 sp = prsp->virt + sizeof(uint32_t);
10750 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
10751 memcpy(&vport->fabric_portname, &sp->portName,
10752 sizeof(struct lpfc_name));
10753 memcpy(&vport->fabric_nodename, &sp->nodeName,
10754 sizeof(struct lpfc_name));
10755 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -040010756 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
10757 /* If our NportID changed, we need to ensure all
10758 * remaining NPORTs get unreg_login'ed so we can
10759 * issue unreg_vpi.
10760 */
10761 list_for_each_entry_safe(np, next_np,
10762 &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -080010763 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
James Smartd7c255b2008-08-24 21:50:00 -040010764 !(np->nlp_flag & NLP_NPR_ADISC))
10765 continue;
James Smartc6adba12020-11-15 11:26:34 -080010766 spin_lock_irq(&ndlp->lock);
James Smartd7c255b2008-08-24 21:50:00 -040010767 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -080010768 spin_unlock_irq(&ndlp->lock);
James Smartd7c255b2008-08-24 21:50:00 -040010769 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -050010770 }
James Smart78730cf2010-04-06 15:06:30 -040010771 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -040010772
10773 if (phba->sli_rev == LPFC_SLI_REV4)
10774 lpfc_sli4_unreg_all_rpis(vport);
10775
James Smartd7c255b2008-08-24 21:50:00 -040010776 lpfc_mbx_unreg_vpi(vport);
10777 spin_lock_irq(shost->host_lock);
10778 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -050010779 if (phba->sli_rev == LPFC_SLI_REV4)
10780 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -040010781 else
10782 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -040010783 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -040010784 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
10785 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
10786 /*
10787 * Driver needs to re-reg VPI in order for f/w
10788 * to update the MAC address.
10789 */
10790 lpfc_register_new_vport(phba, vport, ndlp);
James Smarte9b11082020-11-15 11:26:33 -080010791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart5ac6b302010-10-22 11:05:36 -040010792 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -050010793 }
10794
James Smartecfd03c2010-02-12 14:41:27 -050010795 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
10796 lpfc_issue_init_vpi(vport);
10797 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -040010798 lpfc_register_new_vport(phba, vport, ndlp);
10799 else
10800 lpfc_do_scr_ns_plogi(phba, vport);
James Smarte9b11082020-11-15 11:26:33 -080010801
10802 /* The FDISC completed successfully. Move the fabric ndlp to
10803 * UNMAPPED state and register with the transport.
10804 */
10805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartd7c255b2008-08-24 21:50:00 -040010806 goto out;
James Smarte9b11082020-11-15 11:26:33 -080010807
James Smartd7c255b2008-08-24 21:50:00 -040010808fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -070010809 if (vport->fc_vport &&
10810 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -040010811 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -040010812 /* Cancel discovery timer */
10813 lpfc_can_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -050010814out:
10815 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -080010816 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050010817}
10818
James Smarte59058c2008-08-24 21:49:00 -040010819/**
James Smart3621a712009-04-06 18:47:14 -040010820 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -040010821 * @vport: pointer to a virtual N_Port data structure.
10822 * @ndlp: pointer to a node-list data structure.
10823 * @retry: number of retries to the command IOCB.
10824 *
10825 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
10826 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
10827 * routine to issue the IOCB, which makes sure only one outstanding fabric
10828 * IOCB will be sent off HBA at any given time.
10829 *
James Smart69b8eff2021-03-01 09:18:19 -080010830 * Note that the ndlp reference count will be incremented by 1 for holding the
10831 * ndlp and the reference to ndlp will be stored into the context1 field of
10832 * the IOCB for the completion callback function to the FDISC ELS command.
James Smarte59058c2008-08-24 21:49:00 -040010833 *
10834 * Return code
10835 * 0 - Successfully issued fdisc iocb command
10836 * 1 - Failed to issue fdisc iocb command
10837 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010010838static int
James Smart92d7f7b2007-06-17 19:56:38 -050010839lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
10840 uint8_t retry)
10841{
10842 struct lpfc_hba *phba = vport->phba;
10843 IOCB_t *icmd;
10844 struct lpfc_iocbq *elsiocb;
10845 struct serv_parm *sp;
10846 uint8_t *pcmd;
10847 uint16_t cmdsize;
10848 int did = ndlp->nlp_DID;
10849 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -050010850
James Smart5ffc2662009-11-18 15:39:44 -050010851 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -050010852 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -050010853 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
10854 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
10855 ELS_CMD_FDISC);
10856 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -050010857 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -070010858 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -040010859 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -050010860 return 1;
10861 }
10862
10863 icmd = &elsiocb->iocb;
10864 icmd->un.elsreq64.myID = 0;
10865 icmd->un.elsreq64.fl = 1;
10866
James Smart73d91e52011-10-10 21:32:10 -040010867 /*
10868 * SLI3 ports require a different context type value than SLI4.
10869 * Catch SLI3 ports here and override the prep.
10870 */
10871 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -040010872 icmd->ulpCt_h = 1;
10873 icmd->ulpCt_l = 0;
10874 }
James Smart92d7f7b2007-06-17 19:56:38 -050010875
10876 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
10877 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
10878 pcmd += sizeof(uint32_t); /* CSP Word 1 */
10879 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
10880 sp = (struct serv_parm *) pcmd;
10881 /* Setup CSPs accordingly for Fabric */
10882 sp->cmn.e_d_tov = 0;
10883 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -050010884 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -050010885 sp->cls1.classValid = 0;
10886 sp->cls2.seqDelivery = 1;
10887 sp->cls3.seqDelivery = 1;
10888
10889 pcmd += sizeof(uint32_t); /* CSP Word 2 */
10890 pcmd += sizeof(uint32_t); /* CSP Word 3 */
10891 pcmd += sizeof(uint32_t); /* CSP Word 4 */
10892 pcmd += sizeof(uint32_t); /* Port Name */
10893 memcpy(pcmd, &vport->fc_portname, 8);
10894 pcmd += sizeof(uint32_t); /* Node Name */
10895 pcmd += sizeof(uint32_t); /* Node Name */
10896 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -070010897 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -070010898 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -050010899 lpfc_set_disctmo(vport);
10900
10901 phba->fc_stat.elsXmitFDISC++;
10902 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
10903
James Smart858c9f62007-06-17 19:56:39 -050010904 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
10905 "Issue FDISC: did:x%x",
10906 did, 0, 0);
10907
James Smart4430f7f2020-11-15 11:26:31 -080010908 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -080010909 if (!elsiocb->context1) {
10910 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -080010911 goto err_out;
James Smart8e9a3252021-03-01 09:18:09 -080010912 }
James Smart4430f7f2020-11-15 11:26:31 -080010913
James Smart92d7f7b2007-06-17 19:56:38 -050010914 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
10915 if (rc == IOCB_ERROR) {
James Smart8e9a3252021-03-01 09:18:09 -080010916 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -080010917 lpfc_nlp_put(ndlp);
10918 goto err_out;
James Smart92d7f7b2007-06-17 19:56:38 -050010919 }
James Smart4430f7f2020-11-15 11:26:31 -080010920
James Smart92d7f7b2007-06-17 19:56:38 -050010921 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -050010922 return 0;
James Smart4430f7f2020-11-15 11:26:31 -080010923
10924 err_out:
James Smart4430f7f2020-11-15 11:26:31 -080010925 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10926 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10927 "0256 Issue FDISC: Cannot send IOCB\n");
10928 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -050010929}
10930
James Smarte59058c2008-08-24 21:49:00 -040010931/**
James Smart3621a712009-04-06 18:47:14 -040010932 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -040010933 * @phba: pointer to lpfc hba data structure.
10934 * @cmdiocb: pointer to lpfc command iocb data structure.
10935 * @rspiocb: pointer to lpfc response iocb data structure.
10936 *
10937 * This routine is the completion callback function to the issuing of a LOGO
10938 * ELS command off a vport. It frees the command IOCB and then decrement the
10939 * reference count held on ndlp for this completion function, indicating that
10940 * the reference to the ndlp is no long needed. Note that the
10941 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
10942 * callback function and an additional explicit ndlp reference decrementation
10943 * will trigger the actual release of the ndlp.
10944 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010945static void
10946lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10947 struct lpfc_iocbq *rspiocb)
10948{
10949 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -050010950 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -050010951 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -040010952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -050010953
James Smart9589b0622011-04-16 11:03:17 -040010954 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -050010955 irsp = &rspiocb->iocb;
10956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
10957 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
10958 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -050010959
James Smart9589b0622011-04-16 11:03:17 -040010960 /* NPIV LOGO completes to NPort <nlp_DID> */
10961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10962 "2928 NPIV LOGO completes to NPort x%x "
James Smarte9b11082020-11-15 11:26:33 -080010963 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
James Smart9589b0622011-04-16 11:03:17 -040010964 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarte9b11082020-11-15 11:26:33 -080010965 irsp->ulpTimeout, vport->num_disc_nodes,
10966 kref_read(&ndlp->kref), ndlp->nlp_flag,
10967 ndlp->fc4_xpt_flags);
James Smart9589b0622011-04-16 11:03:17 -040010968
10969 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
10970 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -040010971 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -040010972 vport->fc_flag &= ~FC_FABRIC;
10973 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -040010974 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -040010975 }
James Smarte9b11082020-11-15 11:26:33 -080010976
10977 /* Safe to release resources now. */
10978 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -080010979 lpfc_nlp_put(ndlp);
James Smarte9b11082020-11-15 11:26:33 -080010980 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smart92d7f7b2007-06-17 19:56:38 -050010981}
10982
James Smarte59058c2008-08-24 21:49:00 -040010983/**
James Smart3621a712009-04-06 18:47:14 -040010984 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -040010985 * @vport: pointer to a virtual N_Port data structure.
10986 * @ndlp: pointer to a node-list data structure.
10987 *
10988 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
10989 *
James Smart69b8eff2021-03-01 09:18:19 -080010990 * Note that the ndlp reference count will be incremented by 1 for holding the
10991 * ndlp and the reference to ndlp will be stored into the context1 field of
10992 * the IOCB for the completion callback function to the LOGO ELS command.
James Smarte59058c2008-08-24 21:49:00 -040010993 *
10994 * Return codes
10995 * 0 - Successfully issued logo off the @vport
10996 * 1 - Failed to issue logo off the @vport
10997 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010998int
10999lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
11000{
James Smart4430f7f2020-11-15 11:26:31 -080011001 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -050011002 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -050011003 struct lpfc_iocbq *elsiocb;
11004 uint8_t *pcmd;
11005 uint16_t cmdsize;
11006
11007 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
11008 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
11009 ELS_CMD_LOGO);
11010 if (!elsiocb)
11011 return 1;
11012
James Smart92d7f7b2007-06-17 19:56:38 -050011013 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
11014 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
11015 pcmd += sizeof(uint32_t);
11016
11017 /* Fill in LOGO payload */
11018 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
11019 pcmd += sizeof(uint32_t);
11020 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
11021
James Smart858c9f62007-06-17 19:56:39 -050011022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11023 "Issue LOGO npiv did:x%x flg:x%x",
11024 ndlp->nlp_DID, ndlp->nlp_flag, 0);
11025
James Smart92d7f7b2007-06-17 19:56:38 -050011026 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
James Smartc6adba12020-11-15 11:26:34 -080011027 spin_lock_irq(&ndlp->lock);
James Smart92d7f7b2007-06-17 19:56:38 -050011028 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -080011029 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -080011030 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart8e9a3252021-03-01 09:18:09 -080011031 if (!elsiocb->context1) {
11032 lpfc_els_free_iocb(phba, elsiocb);
11033 goto err;
11034 }
11035
James Smart4430f7f2020-11-15 11:26:31 -080011036 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart8e9a3252021-03-01 09:18:09 -080011037 if (rc == IOCB_ERROR) {
11038 lpfc_els_free_iocb(phba, elsiocb);
11039 lpfc_nlp_put(ndlp);
11040 goto err;
11041 }
James Smart92d7f7b2007-06-17 19:56:38 -050011042 return 0;
James Smart4430f7f2020-11-15 11:26:31 -080011043
James Smart8e9a3252021-03-01 09:18:09 -080011044err:
James Smartc6adba12020-11-15 11:26:34 -080011045 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -080011046 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -080011047 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -080011048 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -050011049}
11050
James Smarte59058c2008-08-24 21:49:00 -040011051/**
James Smart3621a712009-04-06 18:47:14 -040011052 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
Lee Jonesa0e4a642020-07-23 13:24:07 +010011053 * @t: timer context used to obtain the lpfc hba.
James Smarte59058c2008-08-24 21:49:00 -040011054 *
11055 * This routine is invoked by the fabric iocb block timer after
11056 * timeout. It posts the fabric iocb block timeout event by setting the
11057 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11058 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11059 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11060 * posted event WORKER_FABRIC_BLOCK_TMO.
11061 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011062void
Kees Cookf22eb4d2017-09-06 20:24:26 -070011063lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -050011064{
Kees Cookf22eb4d2017-09-06 20:24:26 -070011065 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -050011066 unsigned long iflags;
11067 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -040011068
James Smart92d7f7b2007-06-17 19:56:38 -050011069 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11070 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
11071 if (!tmo_posted)
11072 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
11073 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11074
James Smart5e9d9b82008-06-14 22:52:53 -040011075 if (!tmo_posted)
11076 lpfc_worker_wake_up(phba);
11077 return;
James Smart92d7f7b2007-06-17 19:56:38 -050011078}
11079
James Smarte59058c2008-08-24 21:49:00 -040011080/**
James Smart3621a712009-04-06 18:47:14 -040011081 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -040011082 * @phba: pointer to lpfc hba data structure.
11083 *
11084 * This routine issues one fabric iocb from the driver internal list to
11085 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11086 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11087 * remove one pending fabric iocb from the driver internal list and invokes
11088 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11089 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011090static void
11091lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
11092{
11093 struct lpfc_iocbq *iocb;
11094 unsigned long iflags;
11095 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -050011096 IOCB_t *cmd;
11097
11098repeat:
11099 iocb = NULL;
11100 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -050011101 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -050011102 if (atomic_read(&phba->fabric_iocb_count) == 0) {
11103 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
11104 list);
11105 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -050011106 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -050011107 atomic_inc(&phba->fabric_iocb_count);
11108 }
11109 spin_unlock_irqrestore(&phba->hbalock, iflags);
11110 if (iocb) {
11111 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
11112 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
11113 iocb->iocb_flag |= LPFC_IO_FABRIC;
11114
James Smart858c9f62007-06-17 19:56:39 -050011115 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11116 "Fabric sched1: ste:x%x",
11117 iocb->vport->port_state, 0, 0);
11118
James Smart3772a992009-05-22 14:50:54 -040011119 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -050011120
11121 if (ret == IOCB_ERROR) {
11122 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
11123 iocb->fabric_iocb_cmpl = NULL;
11124 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
11125 cmd = &iocb->iocb;
11126 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
11127 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
11128 iocb->iocb_cmpl(phba, iocb, iocb);
11129
11130 atomic_dec(&phba->fabric_iocb_count);
11131 goto repeat;
11132 }
11133 }
James Smart92d7f7b2007-06-17 19:56:38 -050011134}
11135
James Smarte59058c2008-08-24 21:49:00 -040011136/**
James Smart3621a712009-04-06 18:47:14 -040011137 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -040011138 * @phba: pointer to lpfc hba data structure.
11139 *
11140 * This routine unblocks the issuing fabric iocb command. The function
11141 * will clear the fabric iocb block bit and then invoke the routine
11142 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11143 * from the driver internal fabric iocb list.
11144 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011145void
11146lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
11147{
11148 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11149
11150 lpfc_resume_fabric_iocbs(phba);
11151 return;
11152}
11153
James Smarte59058c2008-08-24 21:49:00 -040011154/**
James Smart3621a712009-04-06 18:47:14 -040011155 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -040011156 * @phba: pointer to lpfc hba data structure.
11157 *
11158 * This routine blocks the issuing fabric iocb for a specified amount of
11159 * time (currently 100 ms). This is done by set the fabric iocb block bit
11160 * and set up a timeout timer for 100ms. When the block bit is set, no more
11161 * fabric iocb will be issued out of the HBA.
11162 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011163static void
11164lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
11165{
11166 int blocked;
11167
11168 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -050011169 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -050011170 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -040011171 mod_timer(&phba->fabric_block_timer,
11172 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -050011173
11174 return;
11175}
11176
James Smarte59058c2008-08-24 21:49:00 -040011177/**
James Smart3621a712009-04-06 18:47:14 -040011178 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -040011179 * @phba: pointer to lpfc hba data structure.
11180 * @cmdiocb: pointer to lpfc command iocb data structure.
11181 * @rspiocb: pointer to lpfc response iocb data structure.
11182 *
11183 * This routine is the callback function that is put to the fabric iocb's
11184 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
11185 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
11186 * function first restores and invokes the original iocb's callback function
11187 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11188 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11189 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011190static void
11191lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11192 struct lpfc_iocbq *rspiocb)
11193{
11194 struct ls_rjt stat;
11195
Shyam Sainie01ea5e2016-12-24 16:21:07 +053011196 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -050011197
11198 switch (rspiocb->iocb.ulpStatus) {
11199 case IOSTAT_NPORT_RJT:
11200 case IOSTAT_FABRIC_RJT:
11201 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
11202 lpfc_block_fabric_iocbs(phba);
11203 }
11204 break;
11205
11206 case IOSTAT_NPORT_BSY:
11207 case IOSTAT_FABRIC_BSY:
11208 lpfc_block_fabric_iocbs(phba);
11209 break;
11210
11211 case IOSTAT_LS_RJT:
11212 stat.un.lsRjtError =
11213 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
11214 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
11215 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
11216 lpfc_block_fabric_iocbs(phba);
11217 break;
11218 }
11219
James Smarta0f2d3e2017-02-12 13:52:31 -080011220 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -050011221
11222 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
11223 cmdiocb->fabric_iocb_cmpl = NULL;
11224 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
11225 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
11226
11227 atomic_dec(&phba->fabric_iocb_count);
11228 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -050011229 /* Post any pending iocbs to HBA */
11230 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -050011231 }
11232}
11233
James Smarte59058c2008-08-24 21:49:00 -040011234/**
James Smart3621a712009-04-06 18:47:14 -040011235 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -040011236 * @phba: pointer to lpfc hba data structure.
11237 * @iocb: pointer to lpfc command iocb data structure.
11238 *
11239 * This routine is used as the top-level API for issuing a fabric iocb command
11240 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11241 * function makes sure that only one fabric bound iocb will be outstanding at
11242 * any given time. As such, this function will first check to see whether there
11243 * is already an outstanding fabric iocb on the wire. If so, it will put the
11244 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11245 * issued later. Otherwise, it will issue the iocb on the wire and update the
11246 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11247 *
11248 * Note, this implementation has a potential sending out fabric IOCBs out of
11249 * order. The problem is caused by the construction of the "ready" boolen does
11250 * not include the condition that the internal fabric IOCB list is empty. As
11251 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11252 * ahead of the fabric IOCBs in the internal list.
11253 *
11254 * Return code
11255 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11256 * IOCB_ERROR - failed to issue fabric iocb
11257 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010011258static int
James Smart92d7f7b2007-06-17 19:56:38 -050011259lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
11260{
11261 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -050011262 int ready;
11263 int ret;
11264
James Smarta0f2d3e2017-02-12 13:52:31 -080011265 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -050011266
11267 spin_lock_irqsave(&phba->hbalock, iflags);
11268 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
11269 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11270
James Smart7f5f3d02008-02-08 18:50:14 -050011271 if (ready)
11272 /* Increment fabric iocb count to hold the position */
11273 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -050011274 spin_unlock_irqrestore(&phba->hbalock, iflags);
11275 if (ready) {
11276 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
11277 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
11278 iocb->iocb_flag |= LPFC_IO_FABRIC;
11279
James Smart858c9f62007-06-17 19:56:39 -050011280 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11281 "Fabric sched2: ste:x%x",
11282 iocb->vport->port_state, 0, 0);
11283
James Smart3772a992009-05-22 14:50:54 -040011284 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -050011285
11286 if (ret == IOCB_ERROR) {
11287 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
11288 iocb->fabric_iocb_cmpl = NULL;
11289 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
11290 atomic_dec(&phba->fabric_iocb_count);
11291 }
11292 } else {
11293 spin_lock_irqsave(&phba->hbalock, iflags);
11294 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
11295 spin_unlock_irqrestore(&phba->hbalock, iflags);
11296 ret = IOCB_SUCCESS;
11297 }
11298 return ret;
11299}
11300
James Smarte59058c2008-08-24 21:49:00 -040011301/**
James Smart3621a712009-04-06 18:47:14 -040011302 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040011303 * @vport: pointer to a virtual N_Port data structure.
11304 *
11305 * This routine aborts all the IOCBs associated with a @vport from the
11306 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11307 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11308 * list, removes each IOCB associated with the @vport off the list, set the
James Smart69b8eff2021-03-01 09:18:19 -080011309 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
James Smarte59058c2008-08-24 21:49:00 -040011310 * associated with the IOCB.
11311 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010011312static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -050011313{
11314 LIST_HEAD(completions);
11315 struct lpfc_hba *phba = vport->phba;
11316 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -050011317
11318 spin_lock_irq(&phba->hbalock);
11319 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11320 list) {
11321
11322 if (piocb->vport != vport)
11323 continue;
11324
11325 list_move_tail(&piocb->list, &completions);
11326 }
11327 spin_unlock_irq(&phba->hbalock);
11328
James Smarta257bf92009-04-06 18:48:10 -040011329 /* Cancel all the IOCBs from the completions list */
11330 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11331 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050011332}
11333
James Smarte59058c2008-08-24 21:49:00 -040011334/**
James Smart3621a712009-04-06 18:47:14 -040011335 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040011336 * @ndlp: pointer to a node-list data structure.
11337 *
11338 * This routine aborts all the IOCBs associated with an @ndlp from the
11339 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11340 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11341 * list, removes each IOCB associated with the @ndlp off the list, set the
James Smart69b8eff2021-03-01 09:18:19 -080011342 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
James Smarte59058c2008-08-24 21:49:00 -040011343 * associated with the IOCB.
11344 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011345void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
11346{
11347 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -040011348 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -050011349 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -080011350 struct lpfc_sli_ring *pring;
11351
11352 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -050011353
Dick Kennedy1234a6d2017-09-29 17:34:29 -070011354 if (unlikely(!pring))
11355 return;
11356
James Smart92d7f7b2007-06-17 19:56:38 -050011357 spin_lock_irq(&phba->hbalock);
11358 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11359 list) {
11360 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
11361
11362 list_move_tail(&piocb->list, &completions);
11363 }
11364 }
11365 spin_unlock_irq(&phba->hbalock);
11366
James Smarta257bf92009-04-06 18:48:10 -040011367 /* Cancel all the IOCBs from the completions list */
11368 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11369 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050011370}
11371
James Smarte59058c2008-08-24 21:49:00 -040011372/**
James Smart3621a712009-04-06 18:47:14 -040011373 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040011374 * @phba: pointer to lpfc hba data structure.
11375 *
11376 * This routine aborts all the IOCBs currently on the driver internal
11377 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11378 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
James Smart69b8eff2021-03-01 09:18:19 -080011379 * list, removes IOCBs off the list, set the status field to
James Smarte59058c2008-08-24 21:49:00 -040011380 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11381 * the IOCB.
11382 **/
James Smart92d7f7b2007-06-17 19:56:38 -050011383void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
11384{
11385 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -050011386
11387 spin_lock_irq(&phba->hbalock);
11388 list_splice_init(&phba->fabric_iocb_list, &completions);
11389 spin_unlock_irq(&phba->hbalock);
11390
James Smarta257bf92009-04-06 18:48:10 -040011391 /* Cancel all the IOCBs from the completions list */
11392 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11393 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050011394}
James Smart6fb120a2009-05-22 14:52:59 -040011395
11396/**
James Smart1151e3e2011-02-16 12:39:35 -050011397 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
11398 * @vport: pointer to lpfc vport data structure.
11399 *
11400 * This routine is invoked by the vport cleanup for deletions and the cleanup
11401 * for an ndlp on removal.
11402 **/
11403void
11404lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
11405{
11406 struct lpfc_hba *phba = vport->phba;
11407 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart88f77022021-09-10 16:31:49 -070011408 struct lpfc_nodelist *ndlp = NULL;
James Smart1151e3e2011-02-16 12:39:35 -050011409 unsigned long iflag = 0;
11410
James Smarta7892412021-04-11 18:31:15 -070011411 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -050011412 list_for_each_entry_safe(sglq_entry, sglq_next,
11413 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
James Smart307e3382020-11-15 11:26:30 -080011414 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
11415 lpfc_nlp_put(sglq_entry->ndlp);
James Smart88f77022021-09-10 16:31:49 -070011416 ndlp = sglq_entry->ndlp;
James Smart1151e3e2011-02-16 12:39:35 -050011417 sglq_entry->ndlp = NULL;
James Smart88f77022021-09-10 16:31:49 -070011418
11419 /* If the xri on the abts_els_sgl list is for the Fport
11420 * node and the vport is unloading, the xri aborted wcqe
11421 * likely isn't coming back. Just release the sgl.
11422 */
11423 if ((vport->load_flag & FC_UNLOADING) &&
11424 ndlp->nlp_DID == Fabric_DID) {
11425 list_del(&sglq_entry->list);
11426 sglq_entry->state = SGL_FREED;
11427 list_add_tail(&sglq_entry->list,
11428 &phba->sli4_hba.lpfc_els_sgl_list);
11429 }
James Smart307e3382020-11-15 11:26:30 -080011430 }
James Smart1151e3e2011-02-16 12:39:35 -050011431 }
James Smarta7892412021-04-11 18:31:15 -070011432 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -050011433 return;
11434}
11435
11436/**
James Smart6fb120a2009-05-22 14:52:59 -040011437 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
11438 * @phba: pointer to lpfc hba data structure.
11439 * @axri: pointer to the els xri abort wcqe structure.
11440 *
11441 * This routine is invoked by the worker thread to process a SLI4 slow-path
11442 * ELS aborted xri.
11443 **/
11444void
11445lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
11446 struct sli4_wcqe_xri_aborted *axri)
11447{
11448 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -050011449 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -040011450 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -050011451
James Smart6fb120a2009-05-22 14:52:59 -040011452 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11453 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -050011454 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -080011455 struct lpfc_sli_ring *pring;
11456
11457 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -040011458
James Smarta7892412021-04-11 18:31:15 -070011459 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
James Smart6fb120a2009-05-22 14:52:59 -040011460 list_for_each_entry_safe(sglq_entry, sglq_next,
11461 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11462 if (sglq_entry->sli4_xritag == xri) {
11463 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -050011464 ndlp = sglq_entry->ndlp;
11465 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -040011466 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -080011467 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -050011468 sglq_entry->state = SGL_FREED;
James Smarta7892412021-04-11 18:31:15 -070011469 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
11470 iflag);
James Smart307e3382020-11-15 11:26:30 -080011471
11472 if (ndlp) {
11473 lpfc_set_rrq_active(phba, ndlp,
11474 sglq_entry->sli4_lxritag,
11475 rxid, 1);
11476 lpfc_nlp_put(ndlp);
11477 }
James Smart589a52d2010-07-14 15:30:54 -040011478
11479 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -070011480 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -040011481 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -040011482 return;
11483 }
11484 }
James Smarta7892412021-04-11 18:31:15 -070011485 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
James Smart7851fe22011-07-22 18:36:52 -040011486 lxri = lpfc_sli4_xri_inrange(phba, xri);
James Smarta7892412021-04-11 18:31:15 -070011487 if (lxri == NO_XRI)
James Smart7851fe22011-07-22 18:36:52 -040011488 return;
James Smarta7892412021-04-11 18:31:15 -070011489
11490 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart7851fe22011-07-22 18:36:52 -040011491 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -050011492 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
11493 spin_unlock_irqrestore(&phba->hbalock, iflag);
11494 return;
11495 }
11496 sglq_entry->state = SGL_XRI_ABORTED;
11497 spin_unlock_irqrestore(&phba->hbalock, iflag);
11498 return;
James Smart6fb120a2009-05-22 14:52:59 -040011499}
James Smart086a3452012-08-14 14:25:21 -040011500
11501/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
11502 * @vport: pointer to virtual port object.
11503 * @ndlp: nodelist pointer for the impacted node.
11504 *
11505 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
11506 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
11507 * the driver is required to send a LOGO to the remote node before it
11508 * attempts to recover its login to the remote node.
11509 */
11510void
11511lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
11512 struct lpfc_nodelist *ndlp)
11513{
11514 struct Scsi_Host *shost;
11515 struct lpfc_hba *phba;
11516 unsigned long flags = 0;
11517
11518 shost = lpfc_shost_from_vport(vport);
11519 phba = vport->phba;
11520 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
11521 lpfc_printf_log(phba, KERN_INFO,
11522 LOG_SLI, "3093 No rport recovery needed. "
11523 "rport in state 0x%x\n", ndlp->nlp_state);
11524 return;
11525 }
Dick Kennedy372c1872020-06-30 14:50:00 -070011526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart086a3452012-08-14 14:25:21 -040011527 "3094 Start rport recovery on shost id 0x%x "
11528 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
11529 "flags 0x%x\n",
11530 shost->host_no, ndlp->nlp_DID,
11531 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
11532 ndlp->nlp_flag);
11533 /*
11534 * The rport is not responding. Remove the FCP-2 flag to prevent
11535 * an ADISC in the follow-up recovery code.
11536 */
James Smartc6adba12020-11-15 11:26:34 -080011537 spin_lock_irqsave(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -040011538 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart30e196c2018-10-23 13:41:03 -070011539 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
James Smartc6adba12020-11-15 11:26:34 -080011540 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart30e196c2018-10-23 13:41:03 -070011541 lpfc_unreg_rpi(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -040011542}
11543
Gaurav Srivastava7e473de2021-06-08 10:05:50 +053011544static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
11545{
11546 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
11547}
11548
11549static void
11550lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
11551{
11552 u32 i;
11553
11554 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
11555 return;
11556
11557 for (i = min; i <= max; i++)
11558 set_bit(i, vport->vmid_priority_range);
11559}
11560
11561static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
11562{
11563 set_bit(ctcl_vmid, vport->vmid_priority_range);
11564}
11565
11566u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
11567{
11568 u32 i;
11569
11570 i = find_first_bit(vport->vmid_priority_range,
11571 LPFC_VMID_MAX_PRIORITY_RANGE);
11572
11573 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
11574 return 0;
11575
11576 clear_bit(i, vport->vmid_priority_range);
11577 return i;
11578}
11579
11580#define MAX_PRIORITY_DESC 255
11581
11582static void
11583lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11584 struct lpfc_iocbq *rspiocb)
11585{
11586 struct lpfc_vport *vport = cmdiocb->vport;
11587 struct priority_range_desc *desc;
11588 struct lpfc_dmabuf *prsp = NULL;
11589 struct lpfc_vmid_priority_range *vmid_range = NULL;
11590 u32 *data;
11591 struct lpfc_dmabuf *dmabuf = cmdiocb->context2;
11592 IOCB_t *irsp = &rspiocb->iocb;
11593 u8 *pcmd, max_desc;
11594 u32 len, i;
11595 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
11596
11597 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
11598 if (!prsp)
11599 goto out;
11600
11601 pcmd = prsp->virt;
11602 data = (u32 *)pcmd;
11603 if (data[0] == ELS_CMD_LS_RJT) {
11604 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
11605 "3277 QFPA LS_RJT x%x x%x\n",
11606 data[0], data[1]);
11607 goto out;
11608 }
11609 if (irsp->ulpStatus) {
11610 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
11611 "6529 QFPA failed with status x%x x%x\n",
11612 irsp->ulpStatus, irsp->un.ulpWord[4]);
11613 goto out;
11614 }
11615
11616 if (!vport->qfpa_res) {
11617 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
11618 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
11619 GFP_KERNEL);
11620 if (!vport->qfpa_res)
11621 goto out;
11622 }
11623
11624 len = *((u32 *)(pcmd + 4));
11625 len = be32_to_cpu(len);
11626 memcpy(vport->qfpa_res, pcmd, len + 8);
11627 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
11628
11629 desc = (struct priority_range_desc *)(pcmd + 8);
11630 vmid_range = vport->vmid_priority.vmid_range;
11631 if (!vmid_range) {
11632 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
11633 GFP_KERNEL);
11634 if (!vmid_range) {
11635 kfree(vport->qfpa_res);
11636 goto out;
11637 }
11638 vport->vmid_priority.vmid_range = vmid_range;
11639 }
11640 vport->vmid_priority.num_descriptors = len;
11641
11642 for (i = 0; i < len; i++, vmid_range++, desc++) {
11643 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
11644 "6539 vmid values low=%d, high=%d, qos=%d, "
11645 "local ve id=%d\n", desc->lo_range,
11646 desc->hi_range, desc->qos_priority,
11647 desc->local_ve_id);
11648
11649 vmid_range->low = desc->lo_range << 1;
11650 if (desc->local_ve_id == QFPA_ODD_ONLY)
11651 vmid_range->low++;
11652 if (desc->qos_priority)
11653 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
11654 vmid_range->qos = desc->qos_priority;
11655
11656 vmid_range->high = desc->hi_range << 1;
11657 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
11658 (desc->local_ve_id == QFPA_EVEN_ODD))
11659 vmid_range->high++;
11660 }
11661 lpfc_init_cs_ctl_bitmap(vport);
11662 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
11663 lpfc_vmid_set_cs_ctl_range(vport,
11664 vport->vmid_priority.vmid_range[i].low,
11665 vport->vmid_priority.vmid_range[i].high);
11666 }
11667
11668 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
11669 out:
11670 lpfc_els_free_iocb(phba, cmdiocb);
11671 lpfc_nlp_put(ndlp);
11672}
11673
11674int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
11675{
11676 struct lpfc_hba *phba = vport->phba;
11677 struct lpfc_nodelist *ndlp;
11678 struct lpfc_iocbq *elsiocb;
11679 u8 *pcmd;
11680 int ret;
11681
11682 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
11683 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
11684 return -ENXIO;
11685
11686 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
11687 ndlp->nlp_DID, ELS_CMD_QFPA);
11688 if (!elsiocb)
11689 return -ENOMEM;
11690
11691 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
11692
11693 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
11694 pcmd += 4;
11695
11696 elsiocb->iocb_cmpl = lpfc_cmpl_els_qfpa;
11697
11698 elsiocb->context1 = lpfc_nlp_get(ndlp);
11699 if (!elsiocb->context1) {
11700 lpfc_els_free_iocb(vport->phba, elsiocb);
11701 return -ENXIO;
11702 }
11703
11704 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
11705 if (ret != IOCB_SUCCESS) {
11706 lpfc_els_free_iocb(phba, elsiocb);
11707 lpfc_nlp_put(ndlp);
11708 return -EIO;
11709 }
11710 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
11711 return 0;
11712}
11713
11714int
11715lpfc_vmid_uvem(struct lpfc_vport *vport,
11716 struct lpfc_vmid *vmid, bool instantiated)
11717{
11718 struct lpfc_vem_id_desc *vem_id_desc;
11719 struct lpfc_nodelist *ndlp;
11720 struct lpfc_iocbq *elsiocb;
11721 struct instantiated_ve_desc *inst_desc;
11722 struct lpfc_vmid_context *vmid_context;
11723 u8 *pcmd;
11724 u32 *len;
11725 int ret = 0;
11726
11727 ndlp = lpfc_findnode_did(vport, Fabric_DID);
11728 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
11729 return -ENXIO;
11730
11731 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
11732 if (!vmid_context)
11733 return -ENOMEM;
11734 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
11735 ndlp, Fabric_DID, ELS_CMD_UVEM);
11736 if (!elsiocb)
11737 goto out;
11738
11739 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
11740 "3427 Host vmid %s %d\n",
11741 vmid->host_vmid, instantiated);
11742 vmid_context->vmp = vmid;
11743 vmid_context->nlp = ndlp;
11744 vmid_context->instantiated = instantiated;
11745 elsiocb->vmid_tag.vmid_context = vmid_context;
11746 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
11747
11748 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid))
11749 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
11750 LPFC_COMPRESS_VMID_SIZE);
11751
11752 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
11753 len = (u32 *)(pcmd + 4);
11754 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
11755
11756 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
11757 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
11758 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
11759 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
11760 LPFC_COMPRESS_VMID_SIZE);
11761
11762 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
11763 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
11764 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
11765 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
11766 LPFC_COMPRESS_VMID_SIZE);
11767
11768 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
11769 bf_set(lpfc_instantiated_local_id, inst_desc,
11770 vmid->un.cs_ctl_vmid);
11771 if (instantiated) {
11772 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
11773 } else {
11774 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
11775 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
11776 }
11777 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
11778
11779 elsiocb->iocb_cmpl = lpfc_cmpl_els_uvem;
11780
11781 elsiocb->context1 = lpfc_nlp_get(ndlp);
11782 if (!elsiocb->context1) {
11783 lpfc_els_free_iocb(vport->phba, elsiocb);
11784 goto out;
11785 }
11786
11787 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
11788 if (ret != IOCB_SUCCESS) {
11789 lpfc_els_free_iocb(vport->phba, elsiocb);
11790 lpfc_nlp_put(ndlp);
11791 goto out;
11792 }
11793
11794 return 0;
11795 out:
11796 kfree(vmid_context);
11797 return -EIO;
11798}
11799
11800static void
11801lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
11802 struct lpfc_iocbq *rspiocb)
11803{
11804 struct lpfc_vport *vport = icmdiocb->vport;
11805 struct lpfc_dmabuf *prsp = NULL;
11806 struct lpfc_vmid_context *vmid_context =
11807 icmdiocb->vmid_tag.vmid_context;
11808 struct lpfc_nodelist *ndlp = icmdiocb->context1;
11809 u8 *pcmd;
11810 u32 *data;
11811 IOCB_t *irsp = &rspiocb->iocb;
11812 struct lpfc_dmabuf *dmabuf = icmdiocb->context2;
11813 struct lpfc_vmid *vmid;
11814
11815 vmid = vmid_context->vmp;
11816 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
11817 ndlp = NULL;
11818
11819 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
11820 if (!prsp)
11821 goto out;
11822 pcmd = prsp->virt;
11823 data = (u32 *)pcmd;
11824 if (data[0] == ELS_CMD_LS_RJT) {
11825 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
11826 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
11827 goto out;
11828 }
11829 if (irsp->ulpStatus) {
11830 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
11831 "4533 UVEM error status %x: %x\n",
11832 irsp->ulpStatus, irsp->un.ulpWord[4]);
11833 goto out;
11834 }
11835 spin_lock(&phba->hbalock);
11836 /* Set IN USE flag */
11837 vport->vmid_flag |= LPFC_VMID_IN_USE;
11838 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
11839 spin_unlock(&phba->hbalock);
11840
11841 if (vmid_context->instantiated) {
11842 write_lock(&vport->vmid_lock);
11843 vmid->flag |= LPFC_VMID_REGISTERED;
11844 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
11845 write_unlock(&vport->vmid_lock);
11846 }
11847
11848 out:
11849 kfree(vmid_context);
11850 lpfc_els_free_iocb(phba, icmdiocb);
11851 lpfc_nlp_put(ndlp);
11852}