blob: c944f220406e06a1fdfa5e438d4000e12036d9a9 [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 Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 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>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
James Smartf60cb932019-05-14 14:58:05 -070033#include <uapi/scsi/fc/fc_fs.h>
34#include <uapi/scsi/fc/fc_els.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050048
49static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
50 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050051static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
52 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010053static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp, uint8_t retry);
56static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050058
dea31012005-04-17 16:05:31 -050059static int lpfc_max_els_tries = 3;
60
James Smarte59058c2008-08-24 21:49:00 -040061/**
James Smart3621a712009-04-06 18:47:14 -040062 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040063 * @vport: pointer to a host virtual N_Port data structure.
64 *
65 * This routine checks whether there is an outstanding host link
66 * attention event during the discovery process with the @vport. It is done
67 * by reading the HBA's Host Attention (HA) register. If there is any host
68 * link attention events during this @vport's discovery process, the @vport
69 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
70 * be issued if the link state is not already in host link cleared state,
71 * and a return code shall indicate whether the host link attention event
72 * had happened.
73 *
74 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
75 * state in LPFC_VPORT_READY, the request for checking host link attention
76 * event will be ignored and a return code shall indicate no host link
77 * attention event had happened.
78 *
79 * Return codes
80 * 0 - no host link attention event happened
81 * 1 - host link attention event happened
82 **/
James Smart858c9f62007-06-17 19:56:39 -050083int
James Smart2e0fef82007-06-17 19:56:36 -050084lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050085{
James Smart2e0fef82007-06-17 19:56:36 -050086 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050088 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050089
James Smart2e0fef82007-06-17 19:56:36 -050090 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040091 phba->link_state == LPFC_LINK_DOWN ||
92 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050093 return 0;
94
95 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050096 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 return 1;
dea31012005-04-17 16:05:31 -050098
99 if (!(ha_copy & HA_LATT))
100 return 0;
101
102 /* Pending Link Event during Discovery */
Dick Kennedy372c1872020-06-30 14:50:00 -0700103 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400104 "0237 Pending Link Event during "
105 "Discovery: State x%x\n",
106 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500107
108 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300109 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500110 * LATT processing should call lpfc_linkdown() which
111 * will cleanup any left over in-progress discovery
112 * events.
113 */
James Smart2e0fef82007-06-17 19:56:36 -0500114 spin_lock_irq(shost->host_lock);
115 vport->fc_flag |= FC_ABORT_DISCOVERY;
116 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500117
James Smart92d7f7b2007-06-17 19:56:38 -0500118 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500119 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500120
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500121 return 1;
dea31012005-04-17 16:05:31 -0500122}
123
James Smarte59058c2008-08-24 21:49:00 -0400124/**
James Smart3621a712009-04-06 18:47:14 -0400125 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400126 * @vport: pointer to a host virtual N_Port data structure.
127 * @expectRsp: flag indicating whether response is expected.
128 * @cmdSize: size of the ELS command.
129 * @retry: number of retries to the command IOCB when it fails.
130 * @ndlp: pointer to a node-list data structure.
131 * @did: destination identifier.
132 * @elscmd: the ELS command code.
133 *
134 * This routine is used for allocating a lpfc-IOCB data structure from
135 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
136 * passed into the routine for discovery state machine to issue an Extended
137 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
138 * and preparation routine that is used by all the discovery state machine
139 * routines and the ELS command-specific fields will be later set up by
140 * the individual discovery machine routines after calling this routine
141 * allocating and preparing a generic IOCB data structure. It fills in the
142 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
143 * payload and response payload (if expected). The reference count on the
144 * ndlp is incremented by 1 and the reference to the ndlp is put into
145 * context1 of the IOCB data structure for this IOCB to hold the ndlp
146 * reference for the command's callback function to access later.
147 *
148 * Return code
149 * Pointer to the newly allocated/prepared els iocb data structure
150 * NULL - when els iocb data structure allocation/preparation failed
151 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400152struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500153lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154 uint16_t cmdSize, uint8_t retry,
155 struct lpfc_nodelist *ndlp, uint32_t did,
156 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500157{
James Smart2e0fef82007-06-17 19:56:36 -0500158 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400159 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500160 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161 struct ulp_bde64 *bpl;
162 IOCB_t *icmd;
163
dea31012005-04-17 16:05:31 -0500164
James Smart2e0fef82007-06-17 19:56:36 -0500165 if (!lpfc_is_link_up(phba))
166 return NULL;
dea31012005-04-17 16:05:31 -0500167
dea31012005-04-17 16:05:31 -0500168 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400169 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500170
171 if (elsiocb == NULL)
172 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500173
James Smart0c287582009-06-10 17:22:56 -0400174 /*
175 * If this command is for fabric controller and HBA running
176 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
177 */
178 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400179 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400180 ((elscmd == ELS_CMD_FLOGI) ||
181 (elscmd == ELS_CMD_FDISC) ||
182 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500183 switch (elscmd) {
184 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500192 & LPFC_FIP_ELS_ID_MASK);
193 break;
194 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500197 & LPFC_FIP_ELS_ID_MASK);
198 break;
199 }
James Smart0c287582009-06-10 17:22:56 -0400200 else
James Smartc8685952009-11-18 15:39:16 -0500201 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400202
dea31012005-04-17 16:05:31 -0500203 icmd = &elsiocb->iocb;
204
205 /* fill in BDEs for command */
206 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400207 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
208 if (pcmd)
209 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500210 if (!pcmd || !pcmd->virt)
211 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500212
213 INIT_LIST_HEAD(&pcmd->list);
214
215 /* Allocate buffer for response payload */
216 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500217 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500218 if (prsp)
219 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
220 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500221 if (!prsp || !prsp->virt)
222 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500223 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500224 } else
dea31012005-04-17 16:05:31 -0500225 prsp = NULL;
dea31012005-04-17 16:05:31 -0500226
227 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500228 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500229 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500230 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
231 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500232 if (!pbuflist || !pbuflist->virt)
233 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500234
235 INIT_LIST_HEAD(&pbuflist->list);
236
dea31012005-04-17 16:05:31 -0500237 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400238 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500241 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400242
243 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500244 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400245 if (elscmd == ELS_CMD_FLOGI)
246 icmd->ulpTimeout = FF_DEF_RATOV * 2;
James Smart30e196c2018-10-23 13:41:03 -0700247 else if (elscmd == ELS_CMD_LOGO)
248 icmd->ulpTimeout = phba->fc_ratov;
James Smart88f43a02013-04-17 20:19:44 -0400249 else
250 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500251 } else {
James Smart939723a2012-05-09 21:19:03 -0400252 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500257 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
258 }
dea31012005-04-17 16:05:31 -0500259 icmd->ulpBdeCount = 1;
260 icmd->ulpLe = 1;
261 icmd->ulpClass = CLASS3;
262
James Smart939723a2012-05-09 21:19:03 -0400263 /*
264 * If we have NPIV enabled, we want to send ELS traffic by VPI.
265 * For SLI4, since the driver controls VPIs we also want to include
266 * all ELS pt2pt protocol traffic as well.
267 */
268 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269 ((phba->sli_rev == LPFC_SLI_REV4) &&
270 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500271
James Smart939723a2012-05-09 21:19:03 -0400272 if (expectRsp) {
273 icmd->un.elsreq64.myID = vport->fc_myDID;
274
275 /* For ELS_REQUEST64_CR, use the VPI by default */
276 icmd->ulpContext = phba->vpi_ids[vport->vpi];
277 }
278
James Smart92d7f7b2007-06-17 19:56:38 -0500279 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500280 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
281 if (elscmd == ELS_CMD_ECHO)
282 icmd->ulpCt_l = 0; /* context = invalid RPI */
283 else
284 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500285 }
286
dea31012005-04-17 16:05:31 -0500287 bpl = (struct ulp_bde64 *) pbuflist->virt;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290 bpl->tus.f.bdeSize = cmdSize;
291 bpl->tus.f.bdeFlags = 0;
292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
293
294 if (expectRsp) {
295 bpl++;
296 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400299 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500300 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 }
302
James Smart329f9bc2007-04-25 09:53:01 -0400303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500305 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500306 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
308
309 if (prsp) {
310 list_add(&prsp->list, &pcmd->list);
311 }
dea31012005-04-17 16:05:31 -0500312 if (expectRsp) {
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
James Smartdea16bd2018-11-29 16:09:30 -0800316 "NPORT x%x I/O tag: x%x, port state:x%x "
317 "rpi x%x fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400318 elscmd, did, elsiocb->iotag,
James Smartdea16bd2018-11-29 16:09:30 -0800319 vport->port_state, ndlp->nlp_rpi,
James Smarte74c03c2013-04-17 20:15:19 -0400320 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500321 } else {
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400325 "NPORT x%x I/O tag: x%x, size: x%x "
James Smartdea16bd2018-11-29 16:09:30 -0800326 "port_state x%x rpi x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400328 cmdSize, vport->port_state,
James Smartdea16bd2018-11-29 16:09:30 -0800329 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -0500330 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500331 return elsiocb;
dea31012005-04-17 16:05:31 -0500332
James Smartfa4066b2008-01-11 01:53:27 -0500333els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500334 if (expectRsp)
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500336 kfree(pbuflist);
337
338els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
340 kfree(prsp);
341
342els_iocb_free_pcmb_exit:
343 kfree(pcmd);
344 lpfc_sli_release_iocbq(phba, elsiocb);
345 return NULL;
346}
dea31012005-04-17 16:05:31 -0500347
James Smarte59058c2008-08-24 21:49:00 -0400348/**
James Smart3621a712009-04-06 18:47:14 -0400349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400350 * @vport: pointer to a host virtual N_Port data structure.
351 *
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
358 * with the @vport.
359 *
360 * Return code
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
363 **/
James Smart3772a992009-05-22 14:50:54 -0400364int
James Smart92d7f7b2007-06-17 19:56:38 -0500365lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
366{
367 struct lpfc_hba *phba = vport->phba;
368 LPFC_MBOXQ_t *mbox;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
372 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400373 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500374
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart307e3382020-11-15 11:26:30 -0800377 if (!ndlp) {
James Smart98c9ea52007-10-27 13:37:33 -0400378 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500379 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400380 }
James Smart92d7f7b2007-06-17 19:56:38 -0500381
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400383 if (!mbox) {
384 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500385 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400386 }
James Smart92d7f7b2007-06-17 19:56:38 -0500387
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
391 mbox->vport = vport;
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400400 if (!mbox) {
401 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500402 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400403 }
James Smart40426292010-12-15 17:58:10 -0500404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
405 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400406 if (rc) {
407 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500408 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400409 }
James Smart92d7f7b2007-06-17 19:56:38 -0500410
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
412 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
415 */
James Smart3e1f0712018-11-29 16:09:29 -0800416 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -0800417 if (!mbox->ctx_ndlp) {
418 err = 6;
419 goto fail_no_ndlp;
420 }
James Smart92d7f7b2007-06-17 19:56:38 -0500421
James Smart0b727fe2007-10-27 13:37:25 -0400422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400423 if (rc == MBX_NOT_FINISHED) {
James Smart4430f7f2020-11-15 11:26:31 -0800424 err = 7;
James Smart92d7f7b2007-06-17 19:56:38 -0500425 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400426 }
James Smart92d7f7b2007-06-17 19:56:38 -0500427
428 return 0;
429
430fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500431 /* decrement the reference count on ndlp just incremented
432 * for the failed mbox command.
433 */
James Smart92d7f7b2007-06-17 19:56:38 -0500434 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -0800435fail_no_ndlp:
James Smart3e1f0712018-11-29 16:09:29 -0800436 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart92d7f7b2007-06-17 19:56:38 -0500437 lpfc_mbuf_free(phba, mp->virt, mp->phys);
438 kfree(mp);
439fail_free_mbox:
440 mempool_free(mbox, phba->mbox_mem_pool);
441
442fail:
443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -0700444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
445 "0249 Cannot issue Register Fabric login: Err %d\n",
446 err);
James Smart92d7f7b2007-06-17 19:56:38 -0500447 return -ENXIO;
448}
449
James Smarte59058c2008-08-24 21:49:00 -0400450/**
James Smart6fb120a2009-05-22 14:52:59 -0400451 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
452 * @vport: pointer to a host virtual N_Port data structure.
453 *
454 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500455 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400456 *
457 * Return code
458 * 0 - successfully issued REG_VFI for @vport
459 * A failure code otherwise.
460 **/
James Smart1b511972011-12-13 13:23:09 -0500461int
James Smart6fb120a2009-05-22 14:52:59 -0400462lpfc_issue_reg_vfi(struct lpfc_vport *vport)
463{
464 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500465 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400466 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500467 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400468 int rc = 0;
469
James Smart939723a2012-05-09 21:19:03 -0400470 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500471 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400472 !(phba->link_flag & LS_LOOPBACK_MODE) &&
473 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500474 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart307e3382020-11-15 11:26:30 -0800475 if (!ndlp) {
James Smart1b511972011-12-13 13:23:09 -0500476 rc = -ENODEV;
477 goto fail;
478 }
James Smart6fb120a2009-05-22 14:52:59 -0400479 }
480
James Smart6fb120a2009-05-22 14:52:59 -0400481 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
482 if (!mboxq) {
483 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500484 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400485 }
James Smartd6de08c2015-12-16 18:11:53 -0500486
487 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
488 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
489 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
490 if (!dmabuf) {
491 rc = -ENOMEM;
492 goto fail;
493 }
494 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
495 if (!dmabuf->virt) {
496 rc = -ENOMEM;
497 goto fail;
498 }
499 memcpy(dmabuf->virt, &phba->fc_fabparam,
500 sizeof(struct serv_parm));
501 }
502
James Smart6fb120a2009-05-22 14:52:59 -0400503 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500504 if (dmabuf)
505 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
506 else
507 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500508
James Smart6fb120a2009-05-22 14:52:59 -0400509 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
510 mboxq->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -0800511 mboxq->ctx_buf = dmabuf;
James Smart6fb120a2009-05-22 14:52:59 -0400512 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
513 if (rc == MBX_NOT_FINISHED) {
514 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500515 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400516 }
517 return 0;
518
James Smart6fb120a2009-05-22 14:52:59 -0400519fail:
James Smartd6de08c2015-12-16 18:11:53 -0500520 if (mboxq)
521 mempool_free(mboxq, phba->mbox_mem_pool);
522 if (dmabuf) {
523 if (dmabuf->virt)
524 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
525 kfree(dmabuf);
526 }
527
James Smart6fb120a2009-05-22 14:52:59 -0400528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -0700529 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
530 "0289 Issue Register VFI failed: Err %d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -0400531 return rc;
532}
533
534/**
James Smart1b511972011-12-13 13:23:09 -0500535 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
536 * @vport: pointer to a host virtual N_Port data structure.
537 *
538 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
539 * the @vport. This mailbox command is necessary for SLI4 port only.
540 *
541 * Return code
542 * 0 - successfully issued REG_VFI for @vport
543 * A failure code otherwise.
544 **/
545int
546lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
547{
548 struct lpfc_hba *phba = vport->phba;
549 struct Scsi_Host *shost;
550 LPFC_MBOXQ_t *mboxq;
551 int rc;
552
553 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
554 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1b511972011-12-13 13:23:09 -0500556 "2556 UNREG_VFI mbox allocation failed"
557 "HBA state x%x\n", phba->pport->port_state);
558 return -ENOMEM;
559 }
560
561 lpfc_unreg_vfi(mboxq, vport);
562 mboxq->vport = vport;
563 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
564
565 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
566 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700567 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1b511972011-12-13 13:23:09 -0500568 "2557 UNREG_VFI issue mbox failed rc x%x "
569 "HBA state x%x\n",
570 rc, phba->pport->port_state);
571 mempool_free(mboxq, phba->mbox_mem_pool);
572 return -EIO;
573 }
574
575 shost = lpfc_shost_from_vport(vport);
576 spin_lock_irq(shost->host_lock);
577 vport->fc_flag &= ~FC_VFI_REGISTERED;
578 spin_unlock_irq(shost->host_lock);
579 return 0;
580}
581
582/**
James Smart92494142011-02-16 12:39:44 -0500583 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
584 * @vport: pointer to a host virtual N_Port data structure.
585 * @sp: pointer to service parameter data structure.
586 *
587 * This routine is called from FLOGI/FDISC completion handler functions.
588 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter else return
590 * 0. This function also set flag in the vport data structure to delay
591 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
592 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
593 * node nodename is changed in the completion service parameter.
594 *
595 * Return code
596 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
597 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
598 *
599 **/
600static uint8_t
601lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
602 struct serv_parm *sp)
603{
James Smart8eb8b962016-07-06 12:36:08 -0700604 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500605 uint8_t fabric_param_changed = 0;
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
607
608 if ((vport->fc_prevDID != vport->fc_myDID) ||
609 memcmp(&vport->fabric_portname, &sp->portName,
610 sizeof(struct lpfc_name)) ||
611 memcmp(&vport->fabric_nodename, &sp->nodeName,
James Smartaeb3c812017-04-21 16:05:02 -0700612 sizeof(struct lpfc_name)) ||
613 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
James Smart92494142011-02-16 12:39:44 -0500614 fabric_param_changed = 1;
James Smartaeb3c812017-04-21 16:05:02 -0700615 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
616 }
James Smart92494142011-02-16 12:39:44 -0500617 /*
618 * Word 1 Bit 31 in common service parameter is overloaded.
619 * Word 1 Bit 31 in FLOGI request is multiple NPort request
620 * Word 1 Bit 31 in FLOGI response is clean address bit
621 *
622 * If fabric parameter is changed and clean address bit is
623 * cleared delay nport discovery if
624 * - vport->fc_prevDID != 0 (not initial discovery) OR
625 * - lpfc_delay_discovery module parameter is set.
626 */
627 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700628 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500629 spin_lock_irq(shost->host_lock);
630 vport->fc_flag |= FC_DISC_DELAYED;
631 spin_unlock_irq(shost->host_lock);
632 }
633
634 return fabric_param_changed;
635}
636
637
638/**
James Smart3621a712009-04-06 18:47:14 -0400639 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400640 * @vport: pointer to a host virtual N_Port data structure.
641 * @ndlp: pointer to a node-list data structure.
642 * @sp: pointer to service parameter data structure.
643 * @irsp: pointer to the IOCB within the lpfc response IOCB.
644 *
645 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
646 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
647 * port in a fabric topology. It properly sets up the parameters to the @ndlp
648 * from the IOCB response. It also check the newly assigned N_Port ID to the
649 * @vport against the previously assigned N_Port ID. If it is different from
650 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
651 * is invoked on all the remaining nodes with the @vport to unregister the
652 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
653 * is invoked to register login to the fabric.
654 *
655 * Return code
656 * 0 - Success (currently, always return 0)
657 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500658static int
James Smart2e0fef82007-06-17 19:56:36 -0500659lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
660 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500661{
James Smart2e0fef82007-06-17 19:56:36 -0500662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
663 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500664 struct lpfc_nodelist *np;
665 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500666 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500667
James Smart2e0fef82007-06-17 19:56:36 -0500668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_FABRIC;
670 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500671
672 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
673 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
674 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
675
James Smart12265f62010-10-22 11:05:53 -0400676 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500677 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
678
James Smart76a95d72010-11-20 23:11:48 -0500679 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500680 spin_lock_irq(shost->host_lock);
681 vport->fc_flag |= FC_PUBLIC_LOOP;
682 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500683 }
684
James Smart2e0fef82007-06-17 19:56:36 -0500685 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500686 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500687 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500688 ndlp->nlp_class_sup = 0;
689 if (sp->cls1.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS1;
691 if (sp->cls2.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS2;
693 if (sp->cls3.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS3;
695 if (sp->cls4.classValid)
696 ndlp->nlp_class_sup |= FC_COS_CLASS4;
697 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
698 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500699
700 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500701 if (fabric_param_changed) {
702 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700703 if (phba->cfg_enable_SmartSAN ||
704 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500705 /* Setup appropriate attribute masks */
706 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700707 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500708 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
709 else
710 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700711 } else {
712 vport->fdmi_hba_mask = 0;
713 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500714 }
715
716 }
James Smart92494142011-02-16 12:39:44 -0500717 memcpy(&vport->fabric_portname, &sp->portName,
718 sizeof(struct lpfc_name));
719 memcpy(&vport->fabric_nodename, &sp->nodeName,
720 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500721 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
722
James Smart92d7f7b2007-06-17 19:56:38 -0500723 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
724 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400725 lpfc_printf_vlog(vport, KERN_WARNING,
726 LOG_ELS | LOG_VPORT,
727 "1816 FLOGI NPIV supported, "
728 "response data 0x%x\n",
729 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500730 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500731 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500732 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500733 } else {
734 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400735 to call reg_vnpid atleast for the physcial host */
736 lpfc_printf_vlog(vport, KERN_WARNING,
737 LOG_ELS | LOG_VPORT,
738 "1817 Fabric does not support NPIV "
739 "- configuring single port mode.\n");
James 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 }
744 }
745
James Smartae05ebe2013-03-01 16:35:38 -0500746 /*
747 * For FC we need to do some special processing because of the SLI
748 * Port's default settings of the Common Service Parameters.
749 */
James Smartd6de08c2015-12-16 18:11:53 -0500750 if ((phba->sli_rev == LPFC_SLI_REV4) &&
751 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500752 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500753 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500754 lpfc_unregister_fcf_prep(phba);
755
756 /* This should just update the VFI CSPs*/
757 if (vport->fc_flag & FC_VFI_REGISTERED)
758 lpfc_issue_reg_vfi(vport);
759 }
760
James Smart92494142011-02-16 12:39:44 -0500761 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
763
764 /* If our NportID changed, we need to ensure all
765 * remaining NPORTs get unreg_login'ed.
766 */
767 list_for_each_entry_safe(np, next_np,
768 &vport->fc_nodes, nlp_listp) {
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
771 continue;
James Smartc6adba12020-11-15 11:26:34 -0800772 spin_lock_irq(&np->lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500773 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -0800774 spin_unlock_irq(&np->lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500775 lpfc_unreg_rpi(vport, np);
776 }
James Smart78730cf2010-04-06 15:06:30 -0400777 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400778
James Smart5248a742011-07-22 18:37:06 -0400779 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400780 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500781 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500782 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
785 }
James Smart27aa1b72012-05-09 21:18:49 -0400786
787 /*
788 * For SLI3 and SLI4, the VPI needs to be reregistered in
789 * response to this fabric parameter change event.
790 */
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
796 /*
797 * Driver needs to re-reg VPI in order for f/w
798 * to update the MAC address.
799 */
James Smart9589b0622011-04-16 11:03:17 -0400800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400801 lpfc_register_new_vport(phba, vport, ndlp);
802 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500803 }
804
James Smart6fb120a2009-05-22 14:52:59 -0400805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
810 else
811 lpfc_issue_fabric_reglogin(vport);
812 } else {
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500820 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500821 else {
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400825 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500826 }
James Smart92d7f7b2007-06-17 19:56:38 -0500827 }
dea31012005-04-17 16:05:31 -0500828 return 0;
dea31012005-04-17 16:05:31 -0500829}
James Smart1b511972011-12-13 13:23:09 -0500830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @sp: pointer to service parameter data structure.
836 *
837 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
838 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
839 * in a point-to-point topology. First, the @vport's N_Port Name is compared
840 * with the received N_Port Name: if the @vport's N_Port Name is greater than
841 * the received N_Port Name lexicographically, this node shall assign local
842 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
843 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
844 * this node shall just wait for the remote node to issue PLOGI and assign
845 * N_Port IDs.
846 *
847 * Return code
848 * 0 - Success
849 * -ENXIO - Fail
850 **/
dea31012005-04-17 16:05:31 -0500851static int
James Smart2e0fef82007-06-17 19:56:36 -0500852lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500854{
James Smart2e0fef82007-06-17 19:56:36 -0500855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500857 LPFC_MBOXQ_t *mbox;
858 int rc;
859
James Smart2e0fef82007-06-17 19:56:36 -0500860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500862 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864
James Smartd33d0eb2017-11-20 16:00:34 -0800865 /* If we are pt2pt with another NPort, force NPIV off! */
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
867
James Smartd6de08c2015-12-16 18:11:53 -0500868 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
871
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
876 }
877
James Smart2e0fef82007-06-17 19:56:36 -0500878 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500879 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400880
dea31012005-04-17 16:05:31 -0500881 if (rc >= 0) {
882 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500886
887 /*
James Smartd6de08c2015-12-16 18:11:53 -0500888 * N_Port ID cannot be 0, set our Id to LocalID
889 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500890 */
891
892 /* not equal */
893 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500894 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500895
James Smarte47c9092008-02-08 18:49:26 -0500896 /* Decrement ndlp reference count indicating that ndlp can be
897 * safely released when other references to it are done.
898 */
James Smart329f9bc2007-04-25 09:53:01 -0400899 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500900
James Smart2e0fef82007-06-17 19:56:36 -0500901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500902 if (!ndlp) {
903 /*
904 * Cannot find existing Fabric ndlp, so allocate a
905 * new one
906 */
James Smart9d3d3402017-04-21 16:05:00 -0700907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500908 if (!ndlp)
909 goto fail;
dea31012005-04-17 16:05:31 -0500910 }
911
912 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500913 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500914 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500915 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500916 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartc6adba12020-11-15 11:26:34 -0800918 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -0500919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -0800920 spin_unlock_irq(&ndlp->lock);
James Smartd33d0eb2017-11-20 16:00:34 -0800921
922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
923 if (!mbox)
924 goto fail;
925
926 lpfc_config_link(phba, mbox);
927
928 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
929 mbox->vport = vport;
930 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
931 if (rc == MBX_NOT_FINISHED) {
932 mempool_free(mbox, phba->mbox_mem_pool);
933 goto fail;
934 }
935 } else {
James Smarte47c9092008-02-08 18:49:26 -0500936 /* This side will wait for the PLOGI, decrement ndlp reference
937 * count indicating that ndlp can be released when other
938 * references to it are done.
939 */
James Smart329f9bc2007-04-25 09:53:01 -0400940 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500941
James Smartd33d0eb2017-11-20 16:00:34 -0800942 /* Start discovery - this should just do CLEAR_LA */
943 lpfc_disc_start(vport);
James Smarte74c03c2013-04-17 20:15:19 -0400944 }
dea31012005-04-17 16:05:31 -0500945
dea31012005-04-17 16:05:31 -0500946 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500947fail:
dea31012005-04-17 16:05:31 -0500948 return -ENXIO;
949}
950
James Smarte59058c2008-08-24 21:49:00 -0400951/**
James Smart3621a712009-04-06 18:47:14 -0400952 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400953 * @phba: pointer to lpfc hba data structure.
954 * @cmdiocb: pointer to lpfc command iocb data structure.
955 * @rspiocb: pointer to lpfc response iocb data structure.
956 *
957 * This routine is the top-level completion callback function for issuing
958 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
959 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
960 * retry has been made (either immediately or delayed with lpfc_els_retry()
961 * returning 1), the command IOCB will be released and function returned.
962 * If the retry attempt has been given up (possibly reach the maximum
963 * number of retries), one additional decrement of ndlp reference shall be
964 * invoked before going out after releasing the command IOCB. This will
965 * actually release the remote node (Note, lpfc_els_free_iocb() will also
966 * invoke one decrement of ndlp reference count). If no error reported in
967 * the IOCB status, the command Port ID field is used to determine whether
968 * this is a point-to-point topology or a fabric topology: if the Port ID
969 * field is assigned, it is a fabric topology; otherwise, it is a
970 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
971 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
972 * specific topology completion conditions.
973 **/
dea31012005-04-17 16:05:31 -0500974static void
James Smart329f9bc2007-04-25 09:53:01 -0400975lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
976 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500977{
James Smart2e0fef82007-06-17 19:56:36 -0500978 struct lpfc_vport *vport = cmdiocb->vport;
979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500980 IOCB_t *irsp = &rspiocb->iocb;
981 struct lpfc_nodelist *ndlp = cmdiocb->context1;
982 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
983 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500984 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500985 int rc;
986
987 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500988 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500989 /* One additional decrement on node reference count to
990 * trigger the release of the node
991 */
James Smart329f9bc2007-04-25 09:53:01 -0400992 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500993 goto out;
994 }
995
James Smart858c9f62007-06-17 19:56:39 -0500996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
997 "FLOGI cmpl: status:x%x/x%x state:x%x",
998 irsp->ulpStatus, irsp->un.ulpWord[4],
999 vport->port_state);
1000
dea31012005-04-17 16:05:31 -05001001 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001002 /*
James Smarta93ff372010-10-22 11:06:08 -04001003 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001004 * due to new FCF discovery
1005 */
1006 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001007 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1008 if (phba->link_state < LPFC_LINK_UP)
1009 goto stop_rr_fcf_flogi;
1010 if ((phba->fcoe_cvl_eventtag_attn ==
1011 phba->fcoe_cvl_eventtag) &&
1012 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001013 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1014 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001015 goto stop_rr_fcf_flogi;
1016 else
1017 phba->fcoe_cvl_eventtag_attn =
1018 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001019 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001020 "2611 FLOGI failed on FCF (x%x), "
1021 "status:x%x/x%x, tmo:x%x, perform "
1022 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001023 phba->fcf.current_rec.fcf_indx,
1024 irsp->ulpStatus, irsp->un.ulpWord[4],
1025 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001026 lpfc_sli4_set_fcf_flogi_fail(phba,
1027 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001028 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001029 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1030 if (rc)
1031 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001032 }
1033
James Smart80c17842012-03-01 22:35:45 -05001034stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001035 /* FLOGI failure */
James Smartc73455e2017-11-20 16:00:28 -08001036 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1037 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1038 IOERR_LOOP_OPEN_FAILURE)))
Dick Kennedy372c1872020-06-30 14:50:00 -07001039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1040 "2858 FLOGI failure Status:x%x/x%x TMO"
1041 ":x%x Data x%x x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, phba->hba_flag,
1044 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001045
dea31012005-04-17 16:05:31 -05001046 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001047 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001048 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001049
Dick Kennedy372c1872020-06-30 14:50:00 -07001050 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
James Smarte62245d2019-08-14 16:57:08 -07001051 "0150 FLOGI failure Status:x%x/x%x "
1052 "xri x%x TMO:x%x\n",
1053 irsp->ulpStatus, irsp->un.ulpWord[4],
1054 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1055
James Smartae9e28f2017-05-15 15:20:51 -07001056 /* If this is not a loop open failure, bail out */
1057 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1059 IOERR_LOOP_OPEN_FAILURE)))
1060 goto flogifail;
1061
dea31012005-04-17 16:05:31 -05001062 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001066
James Smart329f9bc2007-04-25 09:53:01 -04001067 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1070 */
James Smart1b511972011-12-13 13:23:09 -05001071 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1084 } else {
1085 lpfc_sli4_unreg_all_rpis(vport);
1086 }
1087 }
James Smart342b59c2016-03-31 14:12:31 -07001088
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
James Smart4430f7f2020-11-15 11:26:31 -08001092
James Smartff78d8f2011-12-13 13:21:35 -05001093 lpfc_nlp_put(ndlp);
1094 goto out;
dea31012005-04-17 16:05:31 -05001095 }
dea31012005-04-17 16:05:31 -05001096 goto flogifail;
1097 }
James Smart695a8142010-01-26 23:08:03 -05001098 spin_lock_irq(shost->host_lock);
1099 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001100 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001101 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001102
1103 /*
1104 * The FLogI succeeded. Sync the data for the CPU before
1105 * accessing it.
1106 */
1107 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001108 if (!prsp)
1109 goto out;
dea31012005-04-17 16:05:31 -05001110 sp = prsp->virt + sizeof(uint32_t);
1111
1112 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001114 "0101 FLOGI completes successfully, I/O tag:x%x, "
James Smartd496b9a2018-10-23 13:41:08 -07001115 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1116 cmdiocb->iotag, cmdiocb->sli4_xritag,
James Smarte8b62012007-08-02 11:10:09 -04001117 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001118 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1119 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001120
James Smart2e0fef82007-06-17 19:56:36 -05001121 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001122 /*
1123 * If Common Service Parameters indicate Nport
1124 * we are point to point, if Fport we are Fabric.
1125 */
1126 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001127 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001128 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001129 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001130 else {
Dick Kennedy372c1872020-06-30 14:50:00 -07001131 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartdbb6b3a2010-06-08 18:31:37 -04001132 "2831 FLOGI response with cleared Fabric "
1133 "bit fcf_index 0x%x "
1134 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1135 "Fabric Name "
1136 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 phba->fcf.current_rec.fcf_indx,
1138 phba->fcf.current_rec.switch_name[0],
1139 phba->fcf.current_rec.switch_name[1],
1140 phba->fcf.current_rec.switch_name[2],
1141 phba->fcf.current_rec.switch_name[3],
1142 phba->fcf.current_rec.switch_name[4],
1143 phba->fcf.current_rec.switch_name[5],
1144 phba->fcf.current_rec.switch_name[6],
1145 phba->fcf.current_rec.switch_name[7],
1146 phba->fcf.current_rec.fabric_name[0],
1147 phba->fcf.current_rec.fabric_name[1],
1148 phba->fcf.current_rec.fabric_name[2],
1149 phba->fcf.current_rec.fabric_name[3],
1150 phba->fcf.current_rec.fabric_name[4],
1151 phba->fcf.current_rec.fabric_name[5],
1152 phba->fcf.current_rec.fabric_name[6],
1153 phba->fcf.current_rec.fabric_name[7]);
James Smart4430f7f2020-11-15 11:26:31 -08001154
James Smartdbb6b3a2010-06-08 18:31:37 -04001155 lpfc_nlp_put(ndlp);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001159 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001160 phba->fcf.fcf_redisc_attempted = 0; /* reset */
James Smartdbb6b3a2010-06-08 18:31:37 -04001161 goto out;
1162 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001163 if (!rc) {
1164 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001165 if (phba->hba_flag & HBA_FIP_SUPPORT)
1166 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1167 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001168 "2769 FLOGI to FCF (x%x) "
1169 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001170 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001171 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 Smart0c9ab6f2010-02-26 14:15:57 -05001174 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001175 phba->fcf.fcf_redisc_attempted = 0; /* reset */
dea31012005-04-17 16:05:31 -05001176 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001177 }
dea31012005-04-17 16:05:31 -05001178 }
1179
1180flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001181 spin_lock_irq(&phba->hbalock);
1182 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1183 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001184
James Smart329f9bc2007-04-25 09:53:01 -04001185 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05001186 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001187 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001188 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001189
1190 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001191 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001192 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001193 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1194 IOERR_SLI_ABORTED) &&
1195 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001197 (phba->link_state != LPFC_CLEAR_LA)) {
1198 /* If FLOGI failed enable link interrupt. */
1199 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001200 }
dea31012005-04-17 16:05:31 -05001201out:
1202 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001203 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001204}
1205
James Smarte59058c2008-08-24 21:49:00 -04001206/**
James Smart6ede2dd2019-08-14 16:56:44 -07001207 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1208 * aborted during a link down
1209 * @phba: pointer to lpfc hba data structure.
1210 * @cmdiocb: pointer to lpfc command iocb data structure.
1211 * @rspiocb: pointer to lpfc response iocb data structure.
1212 *
1213 */
1214static void
1215lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1216 struct lpfc_iocbq *rspiocb)
1217{
1218 IOCB_t *irsp;
1219 uint32_t *pcmd;
1220 uint32_t cmd;
1221
1222 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1223 cmd = *pcmd;
1224 irsp = &rspiocb->iocb;
1225
1226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1227 "6445 ELS completes after LINK_DOWN: "
1228 " Status %x/%x cmd x%x flg x%x\n",
1229 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1230 cmdiocb->iocb_flag);
1231
1232 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1233 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1234 atomic_dec(&phba->fabric_iocb_count);
1235 }
1236 lpfc_els_free_iocb(phba, cmdiocb);
1237}
1238
1239/**
James Smart3621a712009-04-06 18:47:14 -04001240 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001241 * @vport: pointer to a host virtual N_Port data structure.
1242 * @ndlp: pointer to a node-list data structure.
1243 * @retry: number of retries to the command IOCB.
1244 *
1245 * This routine issues a Fabric Login (FLOGI) Request ELS command
1246 * for a @vport. The initiator service parameters are put into the payload
1247 * of the FLOGI Request IOCB and the top-level callback function pointer
1248 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1249 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1250 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1251 *
1252 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1253 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1254 * will be stored into the context1 field of the IOCB for the completion
1255 * callback function to the FLOGI ELS command.
1256 *
1257 * Return code
1258 * 0 - successfully issued flogi iocb for @vport
1259 * 1 - failed to issue flogi iocb for @vport
1260 **/
dea31012005-04-17 16:05:31 -05001261static int
James Smart2e0fef82007-06-17 19:56:36 -05001262lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001263 uint8_t retry)
1264{
James Smart2e0fef82007-06-17 19:56:36 -05001265 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001266 struct serv_parm *sp;
1267 IOCB_t *icmd;
1268 struct lpfc_iocbq *elsiocb;
James Smart0a9e9682018-11-29 16:09:36 -08001269 struct lpfc_iocbq defer_flogi_acc;
dea31012005-04-17 16:05:31 -05001270 uint8_t *pcmd;
1271 uint16_t cmdsize;
James Smart0a9e9682018-11-29 16:09:36 -08001272 uint32_t tmo, did;
dea31012005-04-17 16:05:31 -05001273 int rc;
1274
James Smart92d7f7b2007-06-17 19:56:38 -05001275 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001276 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1277 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001278
James Smart488d1462006-03-07 15:02:37 -05001279 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001280 return 1;
dea31012005-04-17 16:05:31 -05001281
1282 icmd = &elsiocb->iocb;
1283 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1284
1285 /* For FLOGI request, remainder of payload is service parameters */
1286 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001287 pcmd += sizeof(uint32_t);
1288 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001289 sp = (struct serv_parm *) pcmd;
1290
1291 /* Setup CSPs accordingly for Fabric */
1292 sp->cmn.e_d_tov = 0;
1293 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001294 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001295 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001296 if (sp->cmn.fcphLow < FC_PH3)
1297 sp->cmn.fcphLow = FC_PH3;
1298 if (sp->cmn.fcphHigh < FC_PH3)
1299 sp->cmn.fcphHigh = FC_PH3;
1300
James Smartc31098c2011-04-16 11:03:33 -04001301 if (phba->sli_rev == LPFC_SLI_REV4) {
1302 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1303 LPFC_SLI_INTF_IF_TYPE_0) {
1304 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1305 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1306 /* FLOGI needs to be 3 for WQE FCFI */
1307 /* Set the fcfi to the fcfi we registered with */
1308 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1309 }
James Smart0f378872012-10-31 14:45:01 -04001310 /* Can't do SLI4 class2 without support sequence coalescing */
1311 sp->cls2.classValid = 0;
1312 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001313 } else {
James Smart0f378872012-10-31 14:45:01 -04001314 /* Historical, setting sequential-delivery bit for SLI3 */
1315 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1316 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001317 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1318 sp->cmn.request_multiple_Nport = 1;
1319 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1320 icmd->ulpCt_h = 1;
1321 icmd->ulpCt_l = 0;
1322 } else
1323 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001324 }
1325
James Smart76a95d72010-11-20 23:11:48 -05001326 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001327 icmd->un.elsreq64.myID = 0;
1328 icmd->un.elsreq64.fl = 1;
1329 }
1330
dea31012005-04-17 16:05:31 -05001331 tmo = phba->fc_ratov;
1332 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001334 phba->fc_ratov = tmo;
1335
1336 phba->fc_stat.elsXmitFLOGI++;
1337 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001338
1339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1340 "Issue FLOGI: opt:x%x",
1341 phba->sli3_options, 0, 0);
1342
James Smart4430f7f2020-11-15 11:26:31 -08001343 elsiocb->context1 = lpfc_nlp_get(ndlp);
1344 if (!elsiocb->context1)
1345 goto out;
1346
James Smart92d7f7b2007-06-17 19:56:38 -05001347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001348 if (rc == IOCB_ERROR)
1349 lpfc_nlp_put(ndlp);
James Smart0a9e9682018-11-29 16:09:36 -08001350
1351 phba->hba_flag |= HBA_FLOGI_ISSUED;
1352
1353 /* Check for a deferred FLOGI ACC condition */
1354 if (phba->defer_flogi_acc_flag) {
1355 did = vport->fc_myDID;
1356 vport->fc_myDID = Fabric_DID;
1357
1358 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1359
1360 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1361 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1362 phba->defer_flogi_acc_ox_id;
1363
1364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1365 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1366 " ox_id: x%x, hba_flag x%x\n",
1367 phba->defer_flogi_acc_rx_id,
1368 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1369
1370 /* Send deferred FLOGI ACC */
1371 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1372 ndlp, NULL);
1373
1374 phba->defer_flogi_acc_flag = false;
1375
1376 vport->fc_myDID = did;
1377 }
1378
James Smart4430f7f2020-11-15 11:26:31 -08001379 if (!rc)
1380 return 0;
1381 out:
1382 lpfc_els_free_iocb(phba, elsiocb);
1383 return 1;
dea31012005-04-17 16:05:31 -05001384}
1385
James Smarte59058c2008-08-24 21:49:00 -04001386/**
James Smart3621a712009-04-06 18:47:14 -04001387 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001388 * @phba: pointer to lpfc hba data structure.
1389 *
1390 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1391 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1392 * list and issues an abort IOCB commond on each outstanding IOCB that
1393 * contains a active Fabric_DID ndlp. Note that this function is to issue
1394 * the abort IOCB command on all the outstanding IOCBs, thus when this
1395 * function returns, it does not guarantee all the IOCBs are actually aborted.
1396 *
1397 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001398 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001399 **/
dea31012005-04-17 16:05:31 -05001400int
James Smart2e0fef82007-06-17 19:56:36 -05001401lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001402{
1403 struct lpfc_sli_ring *pring;
1404 struct lpfc_iocbq *iocb, *next_iocb;
1405 struct lpfc_nodelist *ndlp;
1406 IOCB_t *icmd;
1407
1408 /* Abort outstanding I/O on NPort <nlp_DID> */
1409 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001410 "0201 Abort outstanding I/O on NPort x%x\n",
1411 Fabric_DID);
dea31012005-04-17 16:05:31 -05001412
James Smart895427b2017-02-12 13:52:30 -08001413 pring = lpfc_phba_elsring(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001414 if (unlikely(!pring))
1415 return -EIO;
dea31012005-04-17 16:05:31 -05001416
1417 /*
1418 * Check the txcmplq for an iocb that matches the nport the driver is
1419 * searching for.
1420 */
James Smart2e0fef82007-06-17 19:56:36 -05001421 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001422 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1423 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001424 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001425 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart307e3382020-11-15 11:26:30 -08001426 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
James Smartdb7531d2020-11-15 11:26:44 -08001427 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1428 NULL);
dea31012005-04-17 16:05:31 -05001429 }
1430 }
James Smart2e0fef82007-06-17 19:56:36 -05001431 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001432
1433 return 0;
1434}
1435
James Smarte59058c2008-08-24 21:49:00 -04001436/**
James Smart3621a712009-04-06 18:47:14 -04001437 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001438 * @vport: pointer to a host virtual N_Port data structure.
1439 *
1440 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1441 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1442 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1443 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1444 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1445 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1446 * @vport.
1447 *
1448 * Return code
1449 * 0 - failed to issue initial flogi for @vport
1450 * 1 - successfully issued initial flogi for @vport
1451 **/
dea31012005-04-17 16:05:31 -05001452int
James Smart2e0fef82007-06-17 19:56:36 -05001453lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001454{
1455 struct lpfc_nodelist *ndlp;
1456
James Smart98c9ea52007-10-27 13:37:33 -04001457 vport->port_state = LPFC_FLOGI;
1458 lpfc_set_disctmo(vport);
1459
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001460 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001462 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001463 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001464 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001465 if (!ndlp)
1466 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001467 /* Set the node type */
1468 ndlp->nlp_type |= NLP_FABRIC;
James Smart307e3382020-11-15 11:26:30 -08001469
James Smarte47c9092008-02-08 18:49:26 -05001470 /* Put ndlp onto node list */
1471 lpfc_enqueue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001472 }
James Smart87af33f2007-10-27 13:37:43 -04001473
James Smart5ac6b302010-10-22 11:05:36 -04001474 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001475 /* This decrement of reference count to node shall kick off
1476 * the release of the node.
1477 */
James Smart329f9bc2007-04-25 09:53:01 -04001478 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001479 return 0;
1480 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001481 return 1;
dea31012005-04-17 16:05:31 -05001482}
1483
James Smarte59058c2008-08-24 21:49:00 -04001484/**
James Smart3621a712009-04-06 18:47:14 -04001485 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001486 * @vport: pointer to a host virtual N_Port data structure.
1487 *
1488 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1489 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1490 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1491 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1492 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1493 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1494 * @vport.
1495 *
1496 * Return code
1497 * 0 - failed to issue initial fdisc for @vport
1498 * 1 - successfully issued initial fdisc for @vport
1499 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001500int
1501lpfc_initial_fdisc(struct lpfc_vport *vport)
1502{
James Smart92d7f7b2007-06-17 19:56:38 -05001503 struct lpfc_nodelist *ndlp;
1504
1505 /* First look for the Fabric ndlp */
1506 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1507 if (!ndlp) {
1508 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001509 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001510 if (!ndlp)
1511 return 0;
James Smartb3f2e672020-11-15 11:26:37 -08001512
1513 /* NPIV is only supported in Fabrics. */
1514 ndlp->nlp_type |= NLP_FABRIC;
1515
James Smarte47c9092008-02-08 18:49:26 -05001516 /* Put ndlp onto node list */
1517 lpfc_enqueue_node(vport, ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001518 }
James Smarte47c9092008-02-08 18:49:26 -05001519
James Smart92d7f7b2007-06-17 19:56:38 -05001520 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001521 /* decrement node reference count to trigger the release of
1522 * the node.
1523 */
James Smart92d7f7b2007-06-17 19:56:38 -05001524 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001525 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001526 }
1527 return 1;
1528}
James Smart87af33f2007-10-27 13:37:43 -04001529
James Smarte59058c2008-08-24 21:49:00 -04001530/**
James Smart3621a712009-04-06 18:47:14 -04001531 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001532 * @vport: pointer to a host virtual N_Port data structure.
1533 *
1534 * This routine checks whether there are more remaining Port Logins
1535 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1536 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1537 * to issue ELS PLOGIs up to the configured discover threads with the
1538 * @vport (@vport->cfg_discovery_threads). The function also decrement
1539 * the @vport's num_disc_node by 1 if it is not already 0.
1540 **/
James Smart87af33f2007-10-27 13:37:43 -04001541void
James Smart2e0fef82007-06-17 19:56:36 -05001542lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001543{
James Smart2e0fef82007-06-17 19:56:36 -05001544 if (vport->num_disc_nodes)
1545 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001546
1547 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001548 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1549 "0232 Continue discovery with %d PLOGIs to go "
1550 "Data: x%x x%x x%x\n",
1551 vport->num_disc_nodes, vport->fc_plogi_cnt,
1552 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001553 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001554 if (vport->fc_flag & FC_NLP_MORE)
1555 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001556 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001557
dea31012005-04-17 16:05:31 -05001558 return;
1559}
1560
James Smarte59058c2008-08-24 21:49:00 -04001561/**
James Smarte9b11082020-11-15 11:26:33 -08001562 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001563 * @phba: pointer to lpfc hba data structure.
1564 * @prsp: pointer to response IOCB payload.
1565 * @ndlp: pointer to a node-list data structure.
1566 *
1567 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1568 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1569 * The following cases are considered N_Port confirmed:
1570 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1571 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1572 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1573 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1574 * 1) if there is a node on vport list other than the @ndlp with the same
1575 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1576 * on that node to release the RPI associated with the node; 2) if there is
1577 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1578 * into, a new node shall be allocated (or activated). In either case, the
1579 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1580 * be released and the new_ndlp shall be put on to the vport node list and
1581 * its pointer returned as the confirmed node.
1582 *
1583 * Note that before the @ndlp got "released", the keepDID from not-matching
1584 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1585 * of the @ndlp. This is because the release of @ndlp is actually to put it
1586 * into an inactive state on the vport node list and the vport node list
1587 * management algorithm does not allow two node with a same DID.
1588 *
1589 * Return code
1590 * pointer to the PLOGI N_Port @ndlp
1591 **/
James Smart488d1462006-03-07 15:02:37 -05001592static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001593lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001594 struct lpfc_nodelist *ndlp)
1595{
James Smarta0f2d3e2017-02-12 13:52:31 -08001596 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001597 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -05001598 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001599 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001600 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart92ea83a2018-11-29 16:09:34 -08001601 uint32_t keep_new_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001602 uint16_t keep_nlp_state;
James Smart92ea83a2018-11-29 16:09:34 -08001603 u32 keep_nlp_fc4_type = 0;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001604 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smartcff261f2013-12-17 20:29:47 -05001605 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001606
James Smart2fb9bd82006-12-02 13:33:57 -05001607 /* Fabric nodes can have the same WWPN so we don't bother searching
1608 * by WWPN. Just return the ndlp that was given to us.
1609 */
1610 if (ndlp->nlp_type & NLP_FABRIC)
1611 return ndlp;
1612
James Smart92d7f7b2007-06-17 19:56:38 -05001613 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001614 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001615
James Smart685f0bf2007-04-25 09:53:08 -04001616 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001617 * we have for that ndlp. If not, we have some work to do.
1618 */
James Smart2e0fef82007-06-17 19:56:36 -05001619 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001620
James Smartd83ca3e2018-10-23 13:41:09 -07001621 /* return immediately if the WWPN matches ndlp */
James Smart307e3382020-11-15 11:26:30 -08001622 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -05001623 return ndlp;
James Smartd83ca3e2018-10-23 13:41:09 -07001624
James Smartcff261f2013-12-17 20:29:47 -05001625 if (phba->sli_rev == LPFC_SLI_REV4) {
1626 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1627 GFP_KERNEL);
1628 if (active_rrqs_xri_bitmap)
1629 memset(active_rrqs_xri_bitmap, 0,
1630 phba->cfg_rrq_xri_bitmap_sz);
1631 }
James Smart488d1462006-03-07 15:02:37 -05001632
James Smartd83ca3e2018-10-23 13:41:09 -07001633 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1634 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1635 "new_ndlp x%x x%x x%x\n",
1636 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1637 (new_ndlp ? new_ndlp->nlp_DID : 0),
1638 (new_ndlp ? new_ndlp->nlp_flag : 0),
1639 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
James Smart34f5ad82012-08-03 12:35:03 -04001640
James Smart488d1462006-03-07 15:02:37 -05001641 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001642 rc = memcmp(&ndlp->nlp_portname, name,
1643 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001644 if (!rc) {
1645 if (active_rrqs_xri_bitmap)
1646 mempool_free(active_rrqs_xri_bitmap,
1647 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001648 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001649 }
James Smart9d3d3402017-04-21 16:05:00 -07001650 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
James Smartcff261f2013-12-17 20:29:47 -05001651 if (!new_ndlp) {
1652 if (active_rrqs_xri_bitmap)
1653 mempool_free(active_rrqs_xri_bitmap,
1654 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001655 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001656 }
James Smart19ca7602010-11-20 23:11:55 -05001657 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001658 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001659 if (phba->sli_rev == LPFC_SLI_REV4 &&
1660 active_rrqs_xri_bitmap)
1661 memcpy(active_rrqs_xri_bitmap,
1662 new_ndlp->active_rrqs_xri_bitmap,
1663 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001664 }
James Smart488d1462006-03-07 15:02:37 -05001665
James Smartd83ca3e2018-10-23 13:41:09 -07001666 /* At this point in this routine, we know new_ndlp will be
1667 * returned. however, any previous GID_FTs that were done
1668 * would have updated nlp_fc4_type in ndlp, so we must ensure
1669 * new_ndlp has the right value.
1670 */
James Smart92ea83a2018-11-29 16:09:34 -08001671 if (vport->fc_flag & FC_FABRIC) {
1672 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
James Smartd83ca3e2018-10-23 13:41:09 -07001673 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
James Smart92ea83a2018-11-29 16:09:34 -08001674 }
James Smartd83ca3e2018-10-23 13:41:09 -07001675
James Smart2e0fef82007-06-17 19:56:36 -05001676 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001677 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001678 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001679 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001680 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1681 ndlp->active_rrqs_xri_bitmap,
1682 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001683
James Smartc6adba12020-11-15 11:26:34 -08001684 /* Lock both ndlps */
1685 spin_lock_irq(&ndlp->lock);
1686 spin_lock_irq(&new_ndlp->lock);
James Smart92ea83a2018-11-29 16:09:34 -08001687 keep_new_nlp_flag = new_ndlp->nlp_flag;
1688 keep_nlp_flag = ndlp->nlp_flag;
James Smarte5abba42015-05-21 13:55:27 -04001689 new_ndlp->nlp_flag = ndlp->nlp_flag;
James Smartdea16bd2018-11-29 16:09:30 -08001690
1691 /* if new_ndlp had NLP_UNREG_INP set, keep it */
James Smart92ea83a2018-11-29 16:09:34 -08001692 if (keep_new_nlp_flag & NLP_UNREG_INP)
James Smartdea16bd2018-11-29 16:09:30 -08001693 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1694 else
1695 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1696
James Smart92ea83a2018-11-29 16:09:34 -08001697 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1698 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1699 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001700 else
James Smart92ea83a2018-11-29 16:09:34 -08001701 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1702
1703 ndlp->nlp_flag = keep_new_nlp_flag;
1704
1705 /* if ndlp had NLP_UNREG_INP set, keep it */
1706 if (keep_nlp_flag & NLP_UNREG_INP)
1707 ndlp->nlp_flag |= NLP_UNREG_INP;
1708 else
1709 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1710
1711 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1712 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1713 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1714 else
1715 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001716
James Smartc6adba12020-11-15 11:26:34 -08001717 spin_unlock_irq(&new_ndlp->lock);
1718 spin_unlock_irq(&ndlp->lock);
James Smart0ff10d42008-01-11 01:52:36 -05001719
James Smart953ceed2015-05-22 10:42:37 -04001720 /* Set nlp_states accordingly */
1721 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001722 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001723
Dick Kennedy4adc0412017-08-23 16:55:37 -07001724 /* interchange the nvme remoteport structs */
1725 keep_nrport = new_ndlp->nrport;
1726 new_ndlp->nrport = ndlp->nrport;
1727
James Smart2e0fef82007-06-17 19:56:36 -05001728 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001729 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1730 /* The new_ndlp is replacing ndlp totally, so we need
1731 * to put ndlp on UNUSED list and try to free it.
1732 */
James Smart34f5ad82012-08-03 12:35:03 -04001733 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1734 "3179 PLOGI confirm NEW: %x %x\n",
1735 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001736
James Smart92ea83a2018-11-29 16:09:34 -08001737 /* Two ndlps cannot have the same did on the nodelist.
1738 * Note: for this case, ndlp has a NULL WWPN so setting
1739 * the nlp_fc4_type isn't required.
1740 */
James Smart58da1ff2008-04-07 10:15:56 -04001741 ndlp->nlp_DID = keepDID;
James Smart49382502017-11-20 16:00:38 -08001742 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smartcff261f2013-12-17 20:29:47 -05001743 if (phba->sli_rev == LPFC_SLI_REV4 &&
1744 active_rrqs_xri_bitmap)
1745 memcpy(ndlp->active_rrqs_xri_bitmap,
1746 active_rrqs_xri_bitmap,
1747 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001748
James Smart307e3382020-11-15 11:26:30 -08001749 } else {
James Smart34f5ad82012-08-03 12:35:03 -04001750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1751 "3180 PLOGI confirm SWAP: %x %x\n",
1752 new_ndlp->nlp_DID, keepDID);
1753
James Smart2e0fef82007-06-17 19:56:36 -05001754 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001755
James Smart92ea83a2018-11-29 16:09:34 -08001756 /* Two ndlps cannot have the same did and the fc4
1757 * type must be transferred because the ndlp is in
1758 * flight.
1759 */
James Smart58da1ff2008-04-07 10:15:56 -04001760 ndlp->nlp_DID = keepDID;
James Smart92ea83a2018-11-29 16:09:34 -08001761 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1762
James Smartcff261f2013-12-17 20:29:47 -05001763 if (phba->sli_rev == LPFC_SLI_REV4 &&
1764 active_rrqs_xri_bitmap)
1765 memcpy(ndlp->active_rrqs_xri_bitmap,
1766 active_rrqs_xri_bitmap,
1767 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001768
James Smart953ceed2015-05-22 10:42:37 -04001769 /* Since we are switching over to the new_ndlp,
1770 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001771 */
1772 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1773 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001774 keep_nlp_state = NLP_STE_NPR_NODE;
1775 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
Dick Kennedy4adc0412017-08-23 16:55:37 -07001776 ndlp->nrport = keep_nrport;
James Smart92795652006-07-06 15:50:02 -04001777 }
James Smart307e3382020-11-15 11:26:30 -08001778
1779 /*
1780 * If ndlp is not associated with any rport we can drop it here else
1781 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1782 */
1783 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1784 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1785
James Smartcff261f2013-12-17 20:29:47 -05001786 if (phba->sli_rev == LPFC_SLI_REV4 &&
1787 active_rrqs_xri_bitmap)
1788 mempool_free(active_rrqs_xri_bitmap,
1789 phba->active_rrq_pool);
James Smartd83ca3e2018-10-23 13:41:09 -07001790
1791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1792 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1793 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1794 new_ndlp->nlp_fc4_type);
1795
James Smart488d1462006-03-07 15:02:37 -05001796 return new_ndlp;
1797}
1798
James Smarte59058c2008-08-24 21:49:00 -04001799/**
James Smart3621a712009-04-06 18:47:14 -04001800 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001801 * @vport: pointer to a host virtual N_Port data structure.
1802 *
1803 * This routine checks whether more Registration State Change
1804 * Notifications (RSCNs) came in while the discovery state machine was in
1805 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1806 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1807 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1808 * handling the RSCNs.
1809 **/
James Smart87af33f2007-10-27 13:37:43 -04001810void
1811lpfc_end_rscn(struct lpfc_vport *vport)
1812{
1813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1814
1815 if (vport->fc_flag & FC_RSCN_MODE) {
1816 /*
1817 * Check to see if more RSCNs came in while we were
1818 * processing this one.
1819 */
1820 if (vport->fc_rscn_id_cnt ||
1821 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1822 lpfc_els_handle_rscn(vport);
1823 else {
1824 spin_lock_irq(shost->host_lock);
1825 vport->fc_flag &= ~FC_RSCN_MODE;
1826 spin_unlock_irq(shost->host_lock);
1827 }
1828 }
1829}
1830
James Smarte59058c2008-08-24 21:49:00 -04001831/**
James Smart19ca7602010-11-20 23:11:55 -05001832 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1833 * @phba: pointer to lpfc hba data structure.
1834 * @cmdiocb: pointer to lpfc command iocb data structure.
1835 * @rspiocb: pointer to lpfc response iocb data structure.
1836 *
1837 * This routine will call the clear rrq function to free the rrq and
1838 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1839 * exist then the clear_rrq is still called because the rrq needs to
1840 * be freed.
1841 **/
1842
1843static void
1844lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1845 struct lpfc_iocbq *rspiocb)
1846{
1847 struct lpfc_vport *vport = cmdiocb->vport;
1848 IOCB_t *irsp;
1849 struct lpfc_nodelist *ndlp;
1850 struct lpfc_node_rrq *rrq;
1851
1852 /* we pass cmdiocb to state machine which needs rspiocb as well */
1853 rrq = cmdiocb->context_un.rrq;
1854 cmdiocb->context_un.rsp_iocb = rspiocb;
1855
1856 irsp = &rspiocb->iocb;
1857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1858 "RRQ cmpl: status:x%x/x%x did:x%x",
1859 irsp->ulpStatus, irsp->un.ulpWord[4],
1860 irsp->un.elsreq64.remoteID);
1861
1862 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart307e3382020-11-15 11:26:30 -08001863 if (!ndlp || ndlp != rrq->ndlp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart19ca7602010-11-20 23:11:55 -05001865 "2882 RRQ completes to NPort x%x "
1866 "with no ndlp. Data: x%x x%x x%x\n",
1867 irsp->un.elsreq64.remoteID,
1868 irsp->ulpStatus, irsp->un.ulpWord[4],
1869 irsp->ulpIoTag);
1870 goto out;
1871 }
1872
1873 /* rrq completes to NPort <nlp_DID> */
1874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1875 "2880 RRQ completes to NPort x%x "
1876 "Data: x%x x%x x%x x%x x%x\n",
1877 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1878 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1879
1880 if (irsp->ulpStatus) {
1881 /* Check for retry */
1882 /* RRQ failed Don't print the vport to vport rjts */
1883 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1884 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1885 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1886 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07001887 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1888 "2881 RRQ failure DID:%06X Status:"
1889 "x%x/x%x\n",
1890 ndlp->nlp_DID, irsp->ulpStatus,
1891 irsp->un.ulpWord[4]);
James Smart19ca7602010-11-20 23:11:55 -05001892 }
1893out:
1894 if (rrq)
1895 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
James Smart4430f7f2020-11-15 11:26:31 -08001896
James Smart19ca7602010-11-20 23:11:55 -05001897 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001898 lpfc_nlp_put(ndlp);
James Smart19ca7602010-11-20 23:11:55 -05001899 return;
1900}
1901/**
James Smart3621a712009-04-06 18:47:14 -04001902 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001903 * @phba: pointer to lpfc hba data structure.
1904 * @cmdiocb: pointer to lpfc command iocb data structure.
1905 * @rspiocb: pointer to lpfc response iocb data structure.
1906 *
1907 * This routine is the completion callback function for issuing the Port
1908 * Login (PLOGI) command. For PLOGI completion, there must be an active
1909 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001910 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001911 * ignored and command IOCB released. The PLOGI response IOCB status is
1912 * checked for error conditons. If there is error status reported, PLOGI
1913 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1914 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1915 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1916 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1917 * there are additional N_Port nodes with the vport that need to perform
1918 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1919 * PLOGIs.
1920 **/
dea31012005-04-17 16:05:31 -05001921static void
James Smart2e0fef82007-06-17 19:56:36 -05001922lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1923 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001924{
James Smart2e0fef82007-06-17 19:56:36 -05001925 struct lpfc_vport *vport = cmdiocb->vport;
1926 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001927 IOCB_t *irsp;
James Smart4430f7f2020-11-15 11:26:31 -08001928 struct lpfc_nodelist *ndlp, *free_ndlp;
James Smart92795652006-07-06 15:50:02 -04001929 struct lpfc_dmabuf *prsp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07001930 int disc;
dea31012005-04-17 16:05:31 -05001931
dea31012005-04-17 16:05:31 -05001932 /* we pass cmdiocb to state machine which needs rspiocb as well */
1933 cmdiocb->context_un.rsp_iocb = rspiocb;
1934
1935 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1937 "PLOGI cmpl: status:x%x/x%x did:x%x",
1938 irsp->ulpStatus, irsp->un.ulpWord[4],
1939 irsp->un.elsreq64.remoteID);
1940
James Smart2e0fef82007-06-17 19:56:36 -05001941 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart307e3382020-11-15 11:26:30 -08001942 if (!ndlp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001943 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001944 "0136 PLOGI completes to NPort x%x "
1945 "with no ndlp. Data: x%x x%x x%x\n",
1946 irsp->un.elsreq64.remoteID,
1947 irsp->ulpStatus, irsp->un.ulpWord[4],
1948 irsp->ulpIoTag);
James Smart9d8de4412020-11-30 10:12:26 -08001949 goto out_freeiocb;
James Smarted957682007-06-17 19:56:37 -05001950 }
dea31012005-04-17 16:05:31 -05001951
1952 /* Since ndlp can be freed in the disc state machine, note if this node
1953 * is being used during discovery.
1954 */
James Smartc6adba12020-11-15 11:26:34 -08001955 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001956 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001957 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08001958 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001959
1960 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08001962 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04001963 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08001964 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1965 irsp->ulpStatus, irsp->un.ulpWord[4],
1966 disc, vport->num_disc_nodes);
1967
dea31012005-04-17 16:05:31 -05001968 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001969 if (lpfc_els_chk_latt(vport)) {
James Smartc6adba12020-11-15 11:26:34 -08001970 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001971 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08001972 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001973 goto out;
1974 }
1975
dea31012005-04-17 16:05:31 -05001976 if (irsp->ulpStatus) {
1977 /* Check for retry */
1978 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1979 /* ELS command is being retried */
1980 if (disc) {
James Smartc6adba12020-11-15 11:26:34 -08001981 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001982 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08001983 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05001984 }
1985 goto out;
1986 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001987 /* PLOGI failed Don't print the vport to vport rjts */
1988 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1989 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1990 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1991 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07001992 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05001993 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1994 ndlp->nlp_DID, irsp->ulpStatus,
1995 irsp->un.ulpWord[4]);
James Smart52edb2c2020-11-15 11:26:35 -08001996
1997 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1998 if (lpfc_error_lost_link(irsp))
1999 goto check_plogi;
2000 else
2001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2002 NLP_EVT_CMPL_PLOGI);
2003
2004 /* As long as this node is not registered with the scsi or nvme
2005 * transport, it is no longer an active node. Otherwise
2006 * devloss handles the final cleanup.
James Smarte9b11082020-11-15 11:26:33 -08002007 */
James Smart52edb2c2020-11-15 11:26:35 -08002008 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2009 spin_lock_irq(&ndlp->lock);
2010 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2011 spin_unlock_irq(&ndlp->lock);
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002012 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smarte9b11082020-11-15 11:26:33 -08002013 NLP_EVT_DEVICE_RM);
James Smart52edb2c2020-11-15 11:26:35 -08002014 }
dea31012005-04-17 16:05:31 -05002015 } else {
2016 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04002017 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05002018 cmdiocb->context2)->list.next,
2019 struct lpfc_dmabuf, list);
2020 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002021 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smarte9b11082020-11-15 11:26:33 -08002022 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002023 }
2024
James Smart52edb2c2020-11-15 11:26:35 -08002025 check_plogi:
James Smart2e0fef82007-06-17 19:56:36 -05002026 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05002027 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002028 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05002029
James Smart2e0fef82007-06-17 19:56:36 -05002030 if (vport->num_disc_nodes == 0) {
2031 spin_lock_irq(shost->host_lock);
2032 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2033 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002034
James Smart2e0fef82007-06-17 19:56:36 -05002035 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04002036 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05002037 }
2038 }
2039
2040out:
James Smart4430f7f2020-11-15 11:26:31 -08002041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2042 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2043 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2044
James Smart9d8de4412020-11-30 10:12:26 -08002045out_freeiocb:
James Smart4430f7f2020-11-15 11:26:31 -08002046 /* Release the reference on the original I/O request. */
2047 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2048
dea31012005-04-17 16:05:31 -05002049 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002050 lpfc_nlp_put(free_ndlp);
dea31012005-04-17 16:05:31 -05002051 return;
2052}
2053
James Smarte59058c2008-08-24 21:49:00 -04002054/**
James Smart3621a712009-04-06 18:47:14 -04002055 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002056 * @vport: pointer to a host virtual N_Port data structure.
2057 * @did: destination port identifier.
2058 * @retry: number of retries to the command IOCB.
2059 *
2060 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2061 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2062 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2063 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2064 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2065 *
2066 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2067 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2068 * will be stored into the context1 field of the IOCB for the completion
2069 * callback function to the PLOGI ELS command.
2070 *
2071 * Return code
2072 * 0 - Successfully issued a plogi for @vport
2073 * 1 - failed to issue a plogi for @vport
2074 **/
dea31012005-04-17 16:05:31 -05002075int
James Smart2e0fef82007-06-17 19:56:36 -05002076lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05002077{
James Smart2e0fef82007-06-17 19:56:36 -05002078 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002079 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04002080 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002081 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002082 uint8_t *pcmd;
2083 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002084 int ret;
dea31012005-04-17 16:05:31 -05002085
James Smart98c9ea52007-10-27 13:37:33 -04002086 ndlp = lpfc_findnode_did(vport, did);
James Smartdea16bd2018-11-29 16:09:30 -08002087
2088 if (ndlp) {
2089 /* Defer the processing of the issue PLOGI until after the
2090 * outstanding UNREG_RPI mbox command completes, unless we
2091 * are going offline. This logic does not apply for Fabric DIDs
2092 */
2093 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2094 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2095 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2097 "4110 Issue PLOGI x%x deferred "
James Smart32350662019-08-14 16:57:06 -07002098 "on NPort x%x rpi x%x Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08002099 ndlp->nlp_defer_did, ndlp->nlp_DID,
2100 ndlp->nlp_rpi, ndlp);
2101
2102 /* We can only defer 1st PLOGI */
2103 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2104 ndlp->nlp_defer_did = did;
2105 return 0;
2106 }
James Smartdea16bd2018-11-29 16:09:30 -08002107 }
James Smart98c9ea52007-10-27 13:37:33 -04002108
James Smarte47c9092008-02-08 18:49:26 -05002109 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05002110 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002111 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002112 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002113 if (!elsiocb)
2114 return 1;
dea31012005-04-17 16:05:31 -05002115
James Smartc6adba12020-11-15 11:26:34 -08002116 spin_lock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002117 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
James Smartc6adba12020-11-15 11:26:34 -08002118 spin_unlock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002119
dea31012005-04-17 16:05:31 -05002120 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2121
2122 /* For PLOGI request, remainder of payload is service parameters */
2123 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002124 pcmd += sizeof(uint32_t);
2125 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002126 sp = (struct serv_parm *) pcmd;
2127
James Smart5ac6b302010-10-22 11:05:36 -04002128 /*
2129 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2130 * to device on remote loops work.
2131 */
2132 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2133 sp->cmn.altBbCredit = 1;
2134
dea31012005-04-17 16:05:31 -05002135 if (sp->cmn.fcphLow < FC_PH_4_3)
2136 sp->cmn.fcphLow = FC_PH_4_3;
2137
2138 if (sp->cmn.fcphHigh < FC_PH3)
2139 sp->cmn.fcphHigh = FC_PH3;
2140
James Smarte0165f22016-12-19 15:07:20 -08002141 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002142 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002143 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002144
James Smart858c9f62007-06-17 19:56:39 -05002145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2146 "Issue PLOGI: did:x%x",
2147 did, 0, 0);
2148
James Smart8c258642017-02-12 13:52:36 -08002149 /* If our firmware supports this feature, convey that
2150 * information to the target using the vendor specific field.
2151 */
2152 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2153 sp->cmn.valid_vendor_ver_level = 1;
2154 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2155 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2156 }
2157
dea31012005-04-17 16:05:31 -05002158 phba->fc_stat.elsXmitPLOGI++;
2159 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05002160
James Smart4430f7f2020-11-15 11:26:31 -08002161 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2162 "Issue PLOGI: did:x%x refcnt %d",
2163 did, kref_read(&ndlp->kref), 0);
2164 elsiocb->context1 = lpfc_nlp_get(ndlp);
2165 if (!elsiocb->context1)
2166 goto io_err;
2167
2168 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2169 if (ret) {
2170 lpfc_nlp_put(ndlp);
2171 goto io_err;
dea31012005-04-17 16:05:31 -05002172 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002173 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08002174
2175 io_err:
2176 lpfc_els_free_iocb(phba, elsiocb);
2177 return 1;
dea31012005-04-17 16:05:31 -05002178}
2179
James Smarte59058c2008-08-24 21:49:00 -04002180/**
James Smart3621a712009-04-06 18:47:14 -04002181 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002182 * @phba: pointer to lpfc hba data structure.
2183 * @cmdiocb: pointer to lpfc command iocb data structure.
2184 * @rspiocb: pointer to lpfc response iocb data structure.
2185 *
2186 * This routine is the completion callback function for a Process Login
2187 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2188 * status. If there is error status reported, PRLI retry shall be attempted
2189 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2190 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2191 * ndlp to mark the PRLI completion.
2192 **/
dea31012005-04-17 16:05:31 -05002193static void
James Smart2e0fef82007-06-17 19:56:36 -05002194lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2195 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002196{
James Smart2e0fef82007-06-17 19:56:36 -05002197 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002198 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002199 struct lpfc_nodelist *ndlp;
James Smart2332e6e2019-11-04 16:57:01 -08002200 char *mode;
Dick Kennedy372c1872020-06-30 14:50:00 -07002201 u32 loglevel;
dea31012005-04-17 16:05:31 -05002202
dea31012005-04-17 16:05:31 -05002203 /* we pass cmdiocb to state machine which needs rspiocb as well */
2204 cmdiocb->context_un.rsp_iocb = rspiocb;
2205
2206 irsp = &(rspiocb->iocb);
2207 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smartc6adba12020-11-15 11:26:34 -08002208 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002209 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002210
2211 /* Driver supports multiple FC4 types. Counters matter. */
2212 vport->fc_prli_sent--;
2213 ndlp->fc4_prli_sent--;
James Smartc6adba12020-11-15 11:26:34 -08002214 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002215
James Smart858c9f62007-06-17 19:56:39 -05002216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2217 "PRLI cmpl: status:x%x/x%x did:x%x",
2218 irsp->ulpStatus, irsp->un.ulpWord[4],
2219 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002220
dea31012005-04-17 16:05:31 -05002221 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002222 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002223 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002224 "Data: x%x x%x x%x x%x\n",
2225 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002226 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002227
dea31012005-04-17 16:05:31 -05002228 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002229 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002230 goto out;
2231
2232 if (irsp->ulpStatus) {
2233 /* Check for retry */
2234 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2235 /* ELS command is being retried */
2236 goto out;
2237 }
James Smart31200462017-05-15 15:20:42 -07002238
James Smart2332e6e2019-11-04 16:57:01 -08002239 /* If we don't send GFT_ID to Fabric, a PRLI error
2240 * could be expected.
2241 */
2242 if ((vport->fc_flag & FC_FABRIC) ||
Dick Kennedy372c1872020-06-30 14:50:00 -07002243 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
James Smart2332e6e2019-11-04 16:57:01 -08002244 mode = KERN_ERR;
Dick Kennedy372c1872020-06-30 14:50:00 -07002245 loglevel = LOG_TRACE_EVENT;
2246 } else {
James Smart2332e6e2019-11-04 16:57:01 -08002247 mode = KERN_INFO;
Dick Kennedy372c1872020-06-30 14:50:00 -07002248 loglevel = LOG_ELS;
2249 }
James Smart2332e6e2019-11-04 16:57:01 -08002250
dea31012005-04-17 16:05:31 -05002251 /* PRLI failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002252 lpfc_printf_vlog(vport, mode, loglevel,
James Smart31200462017-05-15 15:20:42 -07002253 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2254 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002255 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002256 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2257
dea31012005-04-17 16:05:31 -05002258 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002259 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002260 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002261 else
James Smart2e0fef82007-06-17 19:56:36 -05002262 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002263 NLP_EVT_CMPL_PRLI);
James Smart52edb2c2020-11-15 11:26:35 -08002264
2265 /* As long as this node is not registered with the SCSI
2266 * or NVMe transport and no other PRLIs are outstanding,
2267 * it is no longer an active node. Otherwise devloss
2268 * handles the final cleanup.
2269 */
2270 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2271 !ndlp->fc4_prli_sent) {
2272 spin_lock_irq(&ndlp->lock);
2273 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2274 spin_unlock_irq(&ndlp->lock);
2275 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2276 NLP_EVT_DEVICE_RM);
2277 }
James Smartdea16bd2018-11-29 16:09:30 -08002278 } else {
James Smarta0f2d3e2017-02-12 13:52:31 -08002279 /* Good status, call state machine. However, if another
2280 * PRLI is outstanding, don't call the state machine
2281 * because final disposition to Mapped or Unmapped is
2282 * completed there.
2283 */
James Smart2e0fef82007-06-17 19:56:36 -05002284 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002285 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002286 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002287
dea31012005-04-17 16:05:31 -05002288out:
2289 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002290 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002291 return;
2292}
2293
James Smarte59058c2008-08-24 21:49:00 -04002294/**
James Smart3621a712009-04-06 18:47:14 -04002295 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002296 * @vport: pointer to a host virtual N_Port data structure.
2297 * @ndlp: pointer to a node-list data structure.
2298 * @retry: number of retries to the command IOCB.
2299 *
2300 * This routine issues a Process Login (PRLI) ELS command for the
2301 * @vport. The PRLI service parameters are set up in the payload of the
2302 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2303 * is put to the IOCB completion callback func field before invoking the
2304 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2305 *
2306 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2307 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2308 * will be stored into the context1 field of the IOCB for the completion
2309 * callback function to the PRLI ELS command.
2310 *
2311 * Return code
2312 * 0 - successfully issued prli iocb command for @vport
2313 * 1 - failed to issue prli iocb command for @vport
2314 **/
dea31012005-04-17 16:05:31 -05002315int
James Smart2e0fef82007-06-17 19:56:36 -05002316lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002317 uint8_t retry)
2318{
James Smart4430f7f2020-11-15 11:26:31 -08002319 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002320 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002321 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002322 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002323 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002324 uint8_t *pcmd;
2325 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002326 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002327
Dick Kennedy991f0c02017-08-23 16:55:39 -07002328 /*
2329 * If we are in RSCN mode, the FC4 types supported from a
2330 * previous GFT_ID command may not be accurate. So, if we
2331 * are a NVME Initiator, always look for the possibility of
2332 * the remote NPort beng a NVME Target.
2333 */
2334 if (phba->sli_rev == LPFC_SLI_REV4 &&
2335 vport->fc_flag & FC_RSCN_MODE &&
2336 vport->nvmei_support)
2337 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002338 local_nlp_type = ndlp->nlp_fc4_type;
2339
James Smart9de416a2017-12-08 17:18:07 -08002340 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2341 * fields here before any of them can complete.
2342 */
2343 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2344 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2345 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smartdea16bd2018-11-29 16:09:30 -08002346 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
James Smart9de416a2017-12-08 17:18:07 -08002347 ndlp->nvme_fb_size = 0;
2348
James Smarta0f2d3e2017-02-12 13:52:31 -08002349 send_next_prli:
2350 if (local_nlp_type & NLP_FC4_FCP) {
2351 /* Payload is 4 + 16 = 20 x14 bytes. */
2352 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2353 elscmd = ELS_CMD_PRLI;
2354 } else if (local_nlp_type & NLP_FC4_NVME) {
2355 /* Payload is 4 + 20 = 24 x18 bytes. */
2356 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2357 elscmd = ELS_CMD_NVMEPRLI;
2358 } else {
2359 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2360 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2361 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2362 return 1;
2363 }
James Smart09559e82017-06-15 22:56:46 -07002364
2365 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2366 * FC4 type, implicitly LOGO.
2367 */
2368 if (phba->sli_rev == LPFC_SLI_REV3 &&
2369 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2370 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2371 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2372 ndlp->nlp_type);
2373 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2374 return 1;
2375 }
2376
James Smart2e0fef82007-06-17 19:56:36 -05002377 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002378 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002379 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002380 return 1;
dea31012005-04-17 16:05:31 -05002381
dea31012005-04-17 16:05:31 -05002382 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2383
2384 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002385 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002386
James Smarta0f2d3e2017-02-12 13:52:31 -08002387 if (local_nlp_type & NLP_FC4_FCP) {
2388 /* Remainder of payload is FCP PRLI parameter page.
2389 * Note: this data structure is defined as
2390 * BE/LE in the structure definition so no
2391 * byte swap call is made.
2392 */
2393 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2394 pcmd += sizeof(uint32_t);
2395 npr = (PRLI *)pcmd;
2396
2397 /*
2398 * If our firmware version is 3.20 or later,
2399 * set the following bits for FC-TAPE support.
2400 */
2401 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2402 npr->ConfmComplAllowed = 1;
2403 npr->Retry = 1;
2404 npr->TaskRetryIdReq = 1;
2405 }
2406 npr->estabImagePair = 1;
2407 npr->readXferRdyDis = 1;
2408 if (vport->cfg_first_burst_size)
2409 npr->writeXferRdyDis = 1;
2410
2411 /* For FCP support */
2412 npr->prliType = PRLI_FCP_TYPE;
2413 npr->initiatorFunc = 1;
2414 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2415
2416 /* Remove FCP type - processed. */
2417 local_nlp_type &= ~NLP_FC4_FCP;
2418 } else if (local_nlp_type & NLP_FC4_NVME) {
2419 /* Remainder of payload is NVME PRLI parameter page.
2420 * This data structure is the newer definition that
2421 * uses bf macros so a byte swap is required.
2422 */
2423 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2424 pcmd += sizeof(uint32_t);
2425 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2426 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2427 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
James Smart0d8af092019-08-14 16:57:10 -07002428 if (phba->nsler) {
2429 bf_set(prli_nsler, npr_nvme, 1);
2430 bf_set(prli_conf, npr_nvme, 1);
2431 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002432
2433 /* Only initiators request first burst. */
2434 if ((phba->cfg_nvme_enable_fb) &&
2435 !phba->nvmet_support)
2436 bf_set(prli_fba, npr_nvme, 1);
2437
James Smart8c258642017-02-12 13:52:36 -08002438 if (phba->nvmet_support) {
2439 bf_set(prli_tgt, npr_nvme, 1);
2440 bf_set(prli_disc, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002441 } else {
2442 bf_set(prli_init, npr_nvme, 1);
James Smarta5ff0682018-01-30 15:58:56 -08002443 bf_set(prli_conf, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002444 }
James Smarta5ff0682018-01-30 15:58:56 -08002445
James Smarta0f2d3e2017-02-12 13:52:31 -08002446 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2447 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2448 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2449
2450 /* Remove NVME type - processed. */
2451 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002452 }
dea31012005-04-17 16:05:31 -05002453
2454 phba->fc_stat.elsXmitPRLI++;
2455 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smartc6adba12020-11-15 11:26:34 -08002456 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002457 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002458
2459 /* The vport counters are used for lpfc_scan_finished, but
2460 * the ndlp is used to track outstanding PRLIs for different
2461 * FC4 types.
2462 */
2463 vport->fc_prli_sent++;
2464 ndlp->fc4_prli_sent++;
James Smartc6adba12020-11-15 11:26:34 -08002465 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002466
2467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2468 "Issue PRLI: did:x%x refcnt %d",
2469 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2470 elsiocb->context1 = lpfc_nlp_get(ndlp);
2471 if (!elsiocb->context1)
2472 goto io_err;
2473
2474 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2475 if (rc == IOCB_ERROR)
2476 goto node_err;
James Smarta0f2d3e2017-02-12 13:52:31 -08002477
James Smarta0f2d3e2017-02-12 13:52:31 -08002478
2479 /* The driver supports 2 FC4 types. Make sure
2480 * a PRLI is issued for all types before exiting.
2481 */
James Smart09559e82017-06-15 22:56:46 -07002482 if (phba->sli_rev == LPFC_SLI_REV4 &&
2483 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002484 goto send_next_prli;
James Smart4430f7f2020-11-15 11:26:31 -08002485 else
2486 return 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002487
James Smart4430f7f2020-11-15 11:26:31 -08002488 node_err:
2489 lpfc_nlp_put(ndlp);
2490 io_err:
James Smartc6adba12020-11-15 11:26:34 -08002491 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002492 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smartc6adba12020-11-15 11:26:34 -08002493 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002494 lpfc_els_free_iocb(phba, elsiocb);
2495 return 1;
dea31012005-04-17 16:05:31 -05002496}
2497
James Smarte59058c2008-08-24 21:49:00 -04002498/**
James Smart3621a712009-04-06 18:47:14 -04002499 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002500 * @vport: pointer to a host virtual N_Port data structure.
2501 *
2502 * This routine performs Registration State Change Notification (RSCN)
2503 * discovery for a @vport. If the @vport's node port recovery count is not
2504 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2505 * the nodes that need recovery. If none of the PLOGI were needed through
2506 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2507 * invoked to check and handle possible more RSCN came in during the period
2508 * of processing the current ones.
2509 **/
2510static void
2511lpfc_rscn_disc(struct lpfc_vport *vport)
2512{
2513 lpfc_can_disctmo(vport);
2514
2515 /* RSCN discovery */
2516 /* go thru NPR nodes and issue ELS PLOGIs */
2517 if (vport->fc_npr_cnt)
2518 if (lpfc_els_disc_plogi(vport))
2519 return;
2520
2521 lpfc_end_rscn(vport);
2522}
2523
2524/**
James Smart3621a712009-04-06 18:47:14 -04002525 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002526 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2527 *
2528 * This function is called when the final ADISC is completed during discovery.
2529 * This function handles clearing link attention or issuing reg_vpi depending
2530 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2531 * discovery.
2532 * This function is called with no locks held.
2533 **/
2534static void
2535lpfc_adisc_done(struct lpfc_vport *vport)
2536{
2537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2538 struct lpfc_hba *phba = vport->phba;
2539
2540 /*
2541 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2542 * and continue discovery.
2543 */
2544 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002545 !(vport->fc_flag & FC_RSCN_MODE) &&
2546 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002547 /* The ADISCs are complete. Doesn't matter if they
2548 * succeeded or failed because the ADISC completion
2549 * routine guarantees to call the state machine and
2550 * the RPI is either unregistered (failed ADISC response)
2551 * or the RPI is still valid and the node is marked
2552 * mapped for a target. The exchanges should be in the
2553 * correct state. This code is specific to SLI3.
2554 */
2555 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002556 lpfc_issue_reg_vpi(phba, vport);
2557 return;
2558 }
2559 /*
2560 * For SLI2, we need to set port_state to READY
2561 * and continue discovery.
2562 */
2563 if (vport->port_state < LPFC_VPORT_READY) {
2564 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002565 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002566 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2567 vport->num_disc_nodes = 0;
2568 /* go thru NPR list, issue ELS PLOGIs */
2569 if (vport->fc_npr_cnt)
2570 lpfc_els_disc_plogi(vport);
2571 if (!vport->num_disc_nodes) {
2572 spin_lock_irq(shost->host_lock);
2573 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2574 spin_unlock_irq(shost->host_lock);
2575 lpfc_can_disctmo(vport);
2576 lpfc_end_rscn(vport);
2577 }
2578 }
2579 vport->port_state = LPFC_VPORT_READY;
2580 } else
2581 lpfc_rscn_disc(vport);
2582}
2583
2584/**
James Smart3621a712009-04-06 18:47:14 -04002585 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002586 * @vport: pointer to a host virtual N_Port data structure.
2587 *
2588 * This routine determines whether there are more ndlps on a @vport
2589 * node list need to have Address Discover (ADISC) issued. If so, it will
2590 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2591 * remaining nodes which need to have ADISC sent.
2592 **/
James Smart0ff10d42008-01-11 01:52:36 -05002593void
James Smart2e0fef82007-06-17 19:56:36 -05002594lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002595{
James Smart2e0fef82007-06-17 19:56:36 -05002596 if (vport->num_disc_nodes)
2597 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002598 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002599 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2600 "0210 Continue discovery with %d ADISCs to go "
2601 "Data: x%x x%x x%x\n",
2602 vport->num_disc_nodes, vport->fc_adisc_cnt,
2603 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002604 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002605 if (vport->fc_flag & FC_NLP_MORE) {
2606 lpfc_set_disctmo(vport);
2607 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002608 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002609 }
James Smart90160e02008-08-24 21:49:45 -04002610 if (!vport->num_disc_nodes)
2611 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002612 return;
2613}
2614
James Smarte59058c2008-08-24 21:49:00 -04002615/**
James Smart3621a712009-04-06 18:47:14 -04002616 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002617 * @phba: pointer to lpfc hba data structure.
2618 * @cmdiocb: pointer to lpfc command iocb data structure.
2619 * @rspiocb: pointer to lpfc response iocb data structure.
2620 *
2621 * This routine is the completion function for issuing the Address Discover
2622 * (ADISC) command. It first checks to see whether link went down during
2623 * the discovery process. If so, the node will be marked as node port
2624 * recovery for issuing discover IOCB by the link attention handler and
2625 * exit. Otherwise, the response status is checked. If error was reported
2626 * in the response status, the ADISC command shall be retried by invoking
2627 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2628 * the response status, the state machine is invoked to set transition
2629 * with respect to NLP_EVT_CMPL_ADISC event.
2630 **/
dea31012005-04-17 16:05:31 -05002631static void
James Smart2e0fef82007-06-17 19:56:36 -05002632lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2633 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002634{
James Smart2e0fef82007-06-17 19:56:36 -05002635 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002636 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002637 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002638 int disc;
dea31012005-04-17 16:05:31 -05002639
2640 /* we pass cmdiocb to state machine which needs rspiocb as well */
2641 cmdiocb->context_un.rsp_iocb = rspiocb;
2642
2643 irsp = &(rspiocb->iocb);
2644 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002645
James Smart858c9f62007-06-17 19:56:39 -05002646 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2647 "ADISC cmpl: status:x%x/x%x did:x%x",
2648 irsp->ulpStatus, irsp->un.ulpWord[4],
2649 ndlp->nlp_DID);
2650
dea31012005-04-17 16:05:31 -05002651 /* Since ndlp can be freed in the disc state machine, note if this node
2652 * is being used during discovery.
2653 */
James Smartc6adba12020-11-15 11:26:34 -08002654 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002655 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002656 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smartc6adba12020-11-15 11:26:34 -08002657 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002658 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002659 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2660 "0104 ADISC completes to NPort x%x "
2661 "Data: x%x x%x x%x x%x x%x\n",
2662 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2663 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002664 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002665 if (lpfc_els_chk_latt(vport)) {
James Smartc6adba12020-11-15 11:26:34 -08002666 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002667 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002668 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002669 goto out;
2670 }
2671
2672 if (irsp->ulpStatus) {
2673 /* Check for retry */
2674 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2675 /* ELS command is being retried */
2676 if (disc) {
James Smartc6adba12020-11-15 11:26:34 -08002677 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002678 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002679 spin_unlock_irq(&ndlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05002680 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002681 }
2682 goto out;
2683 }
2684 /* ADISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002685 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05002686 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2687 ndlp->nlp_DID, irsp->ulpStatus,
2688 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002689 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart52edb2c2020-11-15 11:26:35 -08002690 if (lpfc_error_lost_link(irsp))
2691 goto check_adisc;
2692 else
James Smart2e0fef82007-06-17 19:56:36 -05002693 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002694 NLP_EVT_CMPL_ADISC);
James Smart52edb2c2020-11-15 11:26:35 -08002695
2696 /* As long as this node is not registered with the SCSI or NVMe
2697 * transport, it is no longer an active node. Otherwise
2698 * devloss handles the final cleanup.
2699 */
2700 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2701 spin_lock_irq(&ndlp->lock);
2702 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2703 spin_unlock_irq(&ndlp->lock);
2704 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2705 NLP_EVT_DEVICE_RM);
2706 }
James Smarte47c9092008-02-08 18:49:26 -05002707 } else
dea31012005-04-17 16:05:31 -05002708 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002709 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002710 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002711
James Smart52edb2c2020-11-15 11:26:35 -08002712 check_adisc:
James Smart90160e02008-08-24 21:49:45 -04002713 /* Check to see if there are more ADISCs to be sent */
2714 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002715 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002716out:
2717 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002718 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002719 return;
2720}
2721
James Smarte59058c2008-08-24 21:49:00 -04002722/**
James Smart3621a712009-04-06 18:47:14 -04002723 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002724 * @vport: pointer to a virtual N_Port data structure.
2725 * @ndlp: pointer to a node-list data structure.
2726 * @retry: number of retries to the command IOCB.
2727 *
2728 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2729 * @vport. It prepares the payload of the ADISC ELS command, updates the
2730 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2731 * to issue the ADISC ELS command.
2732 *
2733 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2734 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2735 * will be stored into the context1 field of the IOCB for the completion
2736 * callback function to the ADISC ELS command.
2737 *
2738 * Return code
2739 * 0 - successfully issued adisc
2740 * 1 - failed to issue adisc
2741 **/
dea31012005-04-17 16:05:31 -05002742int
James Smart2e0fef82007-06-17 19:56:36 -05002743lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002744 uint8_t retry)
2745{
James Smart4430f7f2020-11-15 11:26:31 -08002746 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002747 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002748 ADISC *ap;
dea31012005-04-17 16:05:31 -05002749 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002750 uint8_t *pcmd;
2751 uint16_t cmdsize;
2752
James Smart92d7f7b2007-06-17 19:56:38 -05002753 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002754 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2755 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002756 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002757 return 1;
dea31012005-04-17 16:05:31 -05002758
dea31012005-04-17 16:05:31 -05002759 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2760
2761 /* For ADISC request, remainder of payload is service parameters */
2762 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002763 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002764
2765 /* Fill in ADISC payload */
2766 ap = (ADISC *) pcmd;
2767 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002768 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2769 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002770 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002771
2772 phba->fc_stat.elsXmitADISC++;
2773 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smartc6adba12020-11-15 11:26:34 -08002774 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002775 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smartc6adba12020-11-15 11:26:34 -08002776 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002777 elsiocb->context1 = lpfc_nlp_get(ndlp);
2778 if (!elsiocb->context1)
2779 goto node_err;
2780
2781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2782 "Issue ADISC: did:x%x refcnt %d",
2783 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2784 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2785 if (rc == IOCB_ERROR)
2786 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002787 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08002788
2789 io_err:
2790 lpfc_nlp_put(ndlp);
2791 node_err:
James Smartc6adba12020-11-15 11:26:34 -08002792 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002793 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smartc6adba12020-11-15 11:26:34 -08002794 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002795 lpfc_els_free_iocb(phba, elsiocb);
2796 return 1;
dea31012005-04-17 16:05:31 -05002797}
2798
James Smarte59058c2008-08-24 21:49:00 -04002799/**
James Smart3621a712009-04-06 18:47:14 -04002800 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002801 * @phba: pointer to lpfc hba data structure.
2802 * @cmdiocb: pointer to lpfc command iocb data structure.
2803 * @rspiocb: pointer to lpfc response iocb data structure.
2804 *
2805 * This routine is the completion function for issuing the ELS Logout (LOGO)
2806 * command. If no error status was reported from the LOGO response, the
2807 * state machine of the associated ndlp shall be invoked for transition with
2808 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2809 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2810 **/
dea31012005-04-17 16:05:31 -05002811static void
James Smart2e0fef82007-06-17 19:56:36 -05002812lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2813 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002814{
James Smart2e0fef82007-06-17 19:56:36 -05002815 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2816 struct lpfc_vport *vport = ndlp->vport;
dea31012005-04-17 16:05:31 -05002817 IOCB_t *irsp;
James Smart086a3452012-08-14 14:25:21 -04002818 unsigned long flags;
2819 uint32_t skip_recovery = 0;
James Smart31051242021-01-04 10:02:34 -08002820 int wake_up_waiter = 0;
dea31012005-04-17 16:05:31 -05002821
dea31012005-04-17 16:05:31 -05002822 /* we pass cmdiocb to state machine which needs rspiocb as well */
2823 cmdiocb->context_un.rsp_iocb = rspiocb;
2824
2825 irsp = &(rspiocb->iocb);
James Smartc6adba12020-11-15 11:26:34 -08002826 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002827 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart31051242021-01-04 10:02:34 -08002828 if (ndlp->upcall_flags & NLP_WAIT_FOR_LOGO) {
2829 wake_up_waiter = 1;
2830 ndlp->upcall_flags &= ~NLP_WAIT_FOR_LOGO;
2831 }
James Smartc6adba12020-11-15 11:26:34 -08002832 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002833
James Smart858c9f62007-06-17 19:56:39 -05002834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2835 "LOGO cmpl: status:x%x/x%x did:x%x",
2836 irsp->ulpStatus, irsp->un.ulpWord[4],
2837 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002838
dea31012005-04-17 16:05:31 -05002839 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2841 "0105 LOGO completes to NPort x%x "
James Smarta70e63e2020-11-15 11:26:38 -08002842 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2843 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2844 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarte8b62012007-08-02 11:10:09 -04002845 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002846
James Smart086a3452012-08-14 14:25:21 -04002847 if (lpfc_els_chk_latt(vport)) {
2848 skip_recovery = 1;
2849 goto out;
2850 }
2851
James Smart30e196c2018-10-23 13:41:03 -07002852 /* The LOGO will not be retried on failure. A LOGO was
2853 * issued to the remote rport and a ACC or RJT or no Answer are
2854 * all acceptable. Note the failure and move forward with
2855 * discovery. The PLOGI will retry.
2856 */
dea31012005-04-17 16:05:31 -05002857 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -05002858 /* LOGO failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002859 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart30e196c2018-10-23 13:41:03 -07002860 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002861 ndlp->nlp_DID, irsp->ulpStatus,
2862 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002863 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002864 if (lpfc_error_lost_link(irsp)) {
2865 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002866 goto out;
James Smart086a3452012-08-14 14:25:21 -04002867 }
2868 }
2869
2870 /* Call state machine. This will unregister the rpi if needed. */
2871 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2872
James Smarta70e63e2020-11-15 11:26:38 -08002873 /* The driver sets this flag for an NPIV instance that doesn't want to
2874 * log into the remote port.
2875 */
2876 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2877 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2878 NLP_EVT_DEVICE_RM);
2879 lpfc_els_free_iocb(phba, cmdiocb);
2880 lpfc_nlp_put(ndlp);
2881
2882 /* Presume the node was released. */
2883 return;
2884 }
2885
dea31012005-04-17 16:05:31 -05002886out:
James Smart4430f7f2020-11-15 11:26:31 -08002887 /* Driver is done with the IO. */
dea31012005-04-17 16:05:31 -05002888 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002889 lpfc_nlp_put(ndlp);
2890
James Smart8e062ce2021-01-04 10:02:26 -08002891 /* At this point, the LOGO processing is complete. NOTE: For a
2892 * pt2pt topology, we are assuming the NPortID will only change
2893 * on link up processing. For a LOGO / PLOGI initiated by the
2894 * Initiator, we are assuming the NPortID is not going to change.
2895 */
James Smart086a3452012-08-14 14:25:21 -04002896
James Smart31051242021-01-04 10:02:34 -08002897 if (wake_up_waiter && ndlp->logo_waitq)
2898 wake_up(ndlp->logo_waitq);
James Smart086a3452012-08-14 14:25:21 -04002899 /*
2900 * If the node is a target, the handling attempts to recover the port.
2901 * For any other port type, the rpi is unregistered as an implicit
2902 * LOGO.
2903 */
James Smart30e196c2018-10-23 13:41:03 -07002904 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2905 skip_recovery == 0) {
James Smart086a3452012-08-14 14:25:21 -04002906 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartc6adba12020-11-15 11:26:34 -08002907 spin_lock_irqsave(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -04002908 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08002909 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -04002910
2911 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2912 "3187 LOGO completes to NPort x%x: Start "
2913 "Recovery Data: x%x x%x x%x x%x\n",
2914 ndlp->nlp_DID, irsp->ulpStatus,
2915 irsp->un.ulpWord[4], irsp->ulpTimeout,
2916 vport->num_disc_nodes);
2917 lpfc_disc_start(vport);
James Smart52edb2c2020-11-15 11:26:35 -08002918 return;
James Smart086a3452012-08-14 14:25:21 -04002919 }
James Smart52edb2c2020-11-15 11:26:35 -08002920
2921 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
2922 * driver sends a LOGO to the rport to cleanup. For fabric and
2923 * initiator ports cleanup the node as long as it the node is not
2924 * register with the transport.
2925 */
2926 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2927 spin_lock_irq(&ndlp->lock);
2928 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2929 spin_unlock_irq(&ndlp->lock);
2930 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2931 NLP_EVT_DEVICE_RM);
2932 }
dea31012005-04-17 16:05:31 -05002933}
2934
James Smarte59058c2008-08-24 21:49:00 -04002935/**
James Smart3621a712009-04-06 18:47:14 -04002936 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002937 * @vport: pointer to a virtual N_Port data structure.
2938 * @ndlp: pointer to a node-list data structure.
2939 * @retry: number of retries to the command IOCB.
2940 *
2941 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2942 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2943 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2944 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2945 *
2946 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2947 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2948 * will be stored into the context1 field of the IOCB for the completion
2949 * callback function to the LOGO ELS command.
2950 *
James Smart30e196c2018-10-23 13:41:03 -07002951 * Callers of this routine are expected to unregister the RPI first
2952 *
James Smarte59058c2008-08-24 21:49:00 -04002953 * Return code
2954 * 0 - successfully issued logo
2955 * 1 - failed to issue logo
2956 **/
dea31012005-04-17 16:05:31 -05002957int
James Smart2e0fef82007-06-17 19:56:36 -05002958lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002959 uint8_t retry)
2960{
James Smart2e0fef82007-06-17 19:56:36 -05002961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002962 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002963 uint8_t *pcmd;
2964 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002965 int rc;
dea31012005-04-17 16:05:31 -05002966
James Smartc6adba12020-11-15 11:26:34 -08002967 spin_lock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04002968 if (ndlp->nlp_flag & NLP_LOGO_SND) {
James Smartc6adba12020-11-15 11:26:34 -08002969 spin_unlock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04002970 return 0;
2971 }
James Smartc6adba12020-11-15 11:26:34 -08002972 spin_unlock_irq(&ndlp->lock);
James Smart98c9ea52007-10-27 13:37:33 -04002973
James Smart92d7f7b2007-06-17 19:56:38 -05002974 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2976 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002977 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002978 return 1;
dea31012005-04-17 16:05:31 -05002979
dea31012005-04-17 16:05:31 -05002980 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2981 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002982 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002983
2984 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002985 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002986 pcmd += sizeof(uint32_t);
2987 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002988
2989 phba->fc_stat.elsXmitLOGO++;
2990 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smartc6adba12020-11-15 11:26:34 -08002991 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05002992 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002993 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smartc6adba12020-11-15 11:26:34 -08002994 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08002995 elsiocb->context1 = lpfc_nlp_get(ndlp);
2996 if (!elsiocb->context1)
2997 goto node_err;
2998
2999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3000 "Issue LOGO: did:x%x refcnt %d",
3001 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
James Smart3772a992009-05-22 14:50:54 -04003002 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08003003 if (rc == IOCB_ERROR)
3004 goto io_err;
James Smart30e196c2018-10-23 13:41:03 -07003005
James Smartc6adba12020-11-15 11:26:34 -08003006 spin_lock_irq(&ndlp->lock);
James Smart30e196c2018-10-23 13:41:03 -07003007 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartc6adba12020-11-15 11:26:34 -08003008 spin_unlock_irq(&ndlp->lock);
James Smart30e196c2018-10-23 13:41:03 -07003009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003010 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003011
3012 io_err:
3013 lpfc_nlp_put(ndlp);
3014 node_err:
James Smartc6adba12020-11-15 11:26:34 -08003015 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08003016 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -08003017 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08003018 lpfc_els_free_iocb(phba, elsiocb);
3019 return 1;
dea31012005-04-17 16:05:31 -05003020}
3021
James Smarte59058c2008-08-24 21:49:00 -04003022/**
James Smart3621a712009-04-06 18:47:14 -04003023 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04003024 * @phba: pointer to lpfc hba data structure.
3025 * @cmdiocb: pointer to lpfc command iocb data structure.
3026 * @rspiocb: pointer to lpfc response iocb data structure.
3027 *
3028 * This routine is a generic completion callback function for ELS commands.
3029 * Specifically, it is the callback function which does not need to perform
3030 * any command specific operations. It is currently used by the ELS command
James Smartdf3fe762020-02-10 09:31:55 -08003031 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3032 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3033 * Other than certain debug loggings, this callback function simply invokes the
James Smarte59058c2008-08-24 21:49:00 -04003034 * lpfc_els_chk_latt() routine to check whether link went down during the
3035 * discovery process.
3036 **/
dea31012005-04-17 16:05:31 -05003037static void
James Smart2e0fef82007-06-17 19:56:36 -05003038lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3039 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003040{
James Smart2e0fef82007-06-17 19:56:36 -05003041 struct lpfc_vport *vport = cmdiocb->vport;
James Smart4430f7f2020-11-15 11:26:31 -08003042 struct lpfc_nodelist *free_ndlp;
dea31012005-04-17 16:05:31 -05003043 IOCB_t *irsp;
3044
3045 irsp = &rspiocb->iocb;
3046
James Smart858c9f62007-06-17 19:56:39 -05003047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
James Smartdf3fe762020-02-10 09:31:55 -08003048 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3049 irsp->ulpStatus, irsp->un.ulpWord[4],
3050 irsp->un.elsreq64.remoteID);
3051
dea31012005-04-17 16:05:31 -05003052 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003053 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3054 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3055 irsp->ulpIoTag, irsp->ulpStatus,
3056 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smartdf3fe762020-02-10 09:31:55 -08003057
3058 /* Check to see if link went down during discovery */
3059 lpfc_els_chk_latt(vport);
James Smart4430f7f2020-11-15 11:26:31 -08003060
3061 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3062
James Smartdf3fe762020-02-10 09:31:55 -08003063 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003064 lpfc_nlp_put(free_ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003065}
3066
3067/**
3068 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3069 * @phba: pointer to lpfc hba data structure.
3070 * @cmdiocb: pointer to lpfc command iocb data structure.
3071 * @rspiocb: pointer to lpfc response iocb data structure.
3072 *
3073 * This routine is a generic completion callback function for Discovery ELS cmd.
3074 * Currently used by the ELS command issuing routines for the ELS State Change
3075 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3076 * These commands will be retried once only for ELS timeout errors.
3077 **/
3078static void
3079lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3080 struct lpfc_iocbq *rspiocb)
3081{
3082 struct lpfc_vport *vport = cmdiocb->vport;
3083 IOCB_t *irsp;
3084 struct lpfc_els_rdf_rsp *prdf;
3085 struct lpfc_dmabuf *pcmd, *prsp;
3086 u32 *pdata;
3087 u32 cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003088 struct lpfc_nodelist *ndlp = cmdiocb->context1;
James Smartdf3fe762020-02-10 09:31:55 -08003089
3090 irsp = &rspiocb->iocb;
3091
3092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3093 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3094 irsp->ulpStatus, irsp->un.ulpWord[4],
3095 irsp->un.elsreq64.remoteID);
3096 /* ELS cmd tag <ulpIoTag> completes */
3097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3098 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3099 "x%x\n",
3100 irsp->ulpIoTag, irsp->ulpStatus,
3101 irsp->un.ulpWord[4], irsp->ulpTimeout,
3102 cmdiocb->retry);
3103
3104 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3105 if (!pcmd)
3106 goto out;
3107
3108 pdata = (u32 *)pcmd->virt;
3109 if (!pdata)
3110 goto out;
3111 cmd = *pdata;
3112
3113 /* Only 1 retry for ELS Timeout only */
3114 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3115 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3116 IOERR_SEQUENCE_TIMEOUT)) {
3117 cmdiocb->retry++;
3118 if (cmdiocb->retry <= 1) {
3119 switch (cmd) {
3120 case ELS_CMD_SCR:
3121 lpfc_issue_els_scr(vport, cmdiocb->retry);
3122 break;
3123 case ELS_CMD_RDF:
3124 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3125 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3126 break;
3127 }
3128 goto out;
3129 }
3130 phba->fc_stat.elsRetryExceeded++;
3131 }
3132 if (irsp->ulpStatus) {
3133 /* ELS discovery cmd completes with error */
3134 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3135 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3136 irsp->ulpStatus, irsp->un.ulpWord[4]);
3137 goto out;
3138 }
3139
3140 /* The RDF response doesn't have any impact on the running driver
3141 * but the notification descriptors are dumped here for support.
3142 */
3143 if (cmd == ELS_CMD_RDF) {
3144 int i;
3145
3146 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3147 if (!prsp)
3148 goto out;
3149
3150 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3151 if (!prdf)
3152 goto out;
3153
3154 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3155 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3156 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
Colin Ian King162e2502020-02-21 15:48:41 +00003157 "4677 Fabric RDF Notification Grant Data: "
James Smartdf3fe762020-02-10 09:31:55 -08003158 "0x%08x\n",
3159 be32_to_cpu(
3160 prdf->reg_d1.desc_tags[i]));
3161 }
3162
3163out:
dea31012005-04-17 16:05:31 -05003164 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05003165 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05003166 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003167 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003168 return;
3169}
3170
James Smarte59058c2008-08-24 21:49:00 -04003171/**
James Smart3621a712009-04-06 18:47:14 -04003172 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003173 * @vport: pointer to a host virtual N_Port data structure.
James Smartdf3fe762020-02-10 09:31:55 -08003174 * @retry: retry counter for the command IOCB.
James Smarte59058c2008-08-24 21:49:00 -04003175 *
3176 * This routine issues a State Change Request (SCR) to a fabric node
James Smartdf3fe762020-02-10 09:31:55 -08003177 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
James Smarte59058c2008-08-24 21:49:00 -04003178 * first search the @vport node list to find the matching ndlp. If no such
3179 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3180 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3181 * routine is invoked to send the SCR IOCB.
3182 *
3183 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3184 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3185 * will be stored into the context1 field of the IOCB for the completion
3186 * callback function to the SCR ELS command.
3187 *
3188 * Return code
3189 * 0 - Successfully issued scr command
3190 * 1 - Failed to issue scr command
3191 **/
dea31012005-04-17 16:05:31 -05003192int
James Smartdf3fe762020-02-10 09:31:55 -08003193lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
dea31012005-04-17 16:05:31 -05003194{
James Smart4430f7f2020-11-15 11:26:31 -08003195 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003196 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003197 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003198 uint8_t *pcmd;
3199 uint16_t cmdsize;
3200 struct lpfc_nodelist *ndlp;
3201
James Smart92d7f7b2007-06-17 19:56:38 -05003202 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05003203
James Smartdf3fe762020-02-10 09:31:55 -08003204 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003205 if (!ndlp) {
James Smartdf3fe762020-02-10 09:31:55 -08003206 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003207 if (!ndlp)
3208 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003209 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003210 }
dea31012005-04-17 16:05:31 -05003211
James Smart2e0fef82007-06-17 19:56:36 -05003212 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3213 ndlp->nlp_DID, ELS_CMD_SCR);
3214
James Smart4430f7f2020-11-15 11:26:31 -08003215 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003216 return 1;
dea31012005-04-17 16:05:31 -05003217
dea31012005-04-17 16:05:31 -05003218 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3219
3220 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05003221 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003222
3223 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003224 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05003225 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3226
James Smart858c9f62007-06-17 19:56:39 -05003227 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3228 "Issue SCR: did:x%x",
3229 ndlp->nlp_DID, 0, 0);
3230
dea31012005-04-17 16:05:31 -05003231 phba->fc_stat.elsXmitSCR++;
James Smartdf3fe762020-02-10 09:31:55 -08003232 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003233 elsiocb->context1 = lpfc_nlp_get(ndlp);
3234 if (!elsiocb->context1)
3235 goto node_err;
3236
3237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3238 "Issue SCR: did:x%x refcnt %d",
3239 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3240
3241 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3242 if (rc == IOCB_ERROR)
3243 goto io_err;
3244
3245 /* Keep the ndlp just in case RDF is being sent */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003246 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003247
3248 io_err:
3249 lpfc_nlp_put(ndlp);
3250 node_err:
3251 lpfc_els_free_iocb(phba, elsiocb);
3252 return 1;
dea31012005-04-17 16:05:31 -05003253}
3254
James Smarte59058c2008-08-24 21:49:00 -04003255/**
James Smartf60cb932019-05-14 14:58:05 -07003256 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3257 * or the other nport (pt2pt).
3258 * @vport: pointer to a host virtual N_Port data structure.
3259 * @retry: number of retries to the command IOCB.
3260 *
3261 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3262 * when connected to a fabric, or to the remote port when connected
3263 * in point-to-point mode. When sent to the Fabric Controller, it will
3264 * replay the RSCN to registered recipients.
3265 *
3266 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3267 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3268 * will be stored into the context1 field of the IOCB for the completion
3269 * callback function to the RSCN ELS command.
3270 *
3271 * Return code
3272 * 0 - Successfully issued RSCN command
3273 * 1 - Failed to issue RSCN command
3274 **/
3275int
3276lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3277{
James Smart4430f7f2020-11-15 11:26:31 -08003278 int rc = 0;
James Smartf60cb932019-05-14 14:58:05 -07003279 struct lpfc_hba *phba = vport->phba;
3280 struct lpfc_iocbq *elsiocb;
3281 struct lpfc_nodelist *ndlp;
3282 struct {
3283 struct fc_els_rscn rscn;
3284 struct fc_els_rscn_page portid;
3285 } *event;
3286 uint32_t nportid;
3287 uint16_t cmdsize = sizeof(*event);
3288
3289 /* Not supported for private loop */
3290 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3291 !(vport->fc_flag & FC_PUBLIC_LOOP))
3292 return 1;
3293
3294 if (vport->fc_flag & FC_PT2PT) {
3295 /* find any mapped nport - that would be the other nport */
3296 ndlp = lpfc_findnode_mapped(vport);
3297 if (!ndlp)
3298 return 1;
3299 } else {
3300 nportid = FC_FID_FCTRL;
3301 /* find the fabric controller node */
3302 ndlp = lpfc_findnode_did(vport, nportid);
3303 if (!ndlp) {
3304 /* if one didn't exist, make one */
3305 ndlp = lpfc_nlp_init(vport, nportid);
3306 if (!ndlp)
3307 return 1;
3308 lpfc_enqueue_node(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003309 }
3310 }
3311
3312 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3313 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3314
James Smart4430f7f2020-11-15 11:26:31 -08003315 if (!elsiocb)
James Smartf60cb932019-05-14 14:58:05 -07003316 return 1;
James Smartf60cb932019-05-14 14:58:05 -07003317
3318 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3319
3320 event->rscn.rscn_cmd = ELS_RSCN;
3321 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3322 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3323
3324 nportid = vport->fc_myDID;
3325 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3326 event->portid.rscn_page_flags = 0;
3327 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3328 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3329 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3330
James Smart4430f7f2020-11-15 11:26:31 -08003331 phba->fc_stat.elsXmitRSCN++;
3332 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3333 elsiocb->context1 = lpfc_nlp_get(ndlp);
3334 if (!elsiocb->context1)
3335 goto node_err;
3336
James Smartf60cb932019-05-14 14:58:05 -07003337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3338 "Issue RSCN: did:x%x",
3339 ndlp->nlp_DID, 0, 0);
3340
James Smart4430f7f2020-11-15 11:26:31 -08003341 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3342 if (rc == IOCB_ERROR)
3343 goto io_err;
James Smart8aaa7bc2020-10-20 13:27:17 -07003344
James Smartf60cb932019-05-14 14:58:05 -07003345 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3346 * trigger the release of node.
3347 */
3348 if (!(vport->fc_flag & FC_PT2PT))
3349 lpfc_nlp_put(ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003350 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003351io_err:
3352 lpfc_nlp_put(ndlp);
3353node_err:
3354 lpfc_els_free_iocb(phba, elsiocb);
3355 return 1;
James Smartf60cb932019-05-14 14:58:05 -07003356}
3357
3358/**
James Smart3621a712009-04-06 18:47:14 -04003359 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003360 * @vport: pointer to a host virtual N_Port data structure.
3361 * @nportid: N_Port identifier to the remote node.
3362 * @retry: number of retries to the command IOCB.
3363 *
3364 * This routine issues a Fibre Channel Address Resolution Response
3365 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3366 * is passed into the function. It first search the @vport node list to find
3367 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3368 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3369 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3370 *
3371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3373 * will be stored into the context1 field of the IOCB for the completion
3374 * callback function to the PARPR ELS command.
3375 *
3376 * Return code
3377 * 0 - Successfully issued farpr command
3378 * 1 - Failed to issue farpr command
3379 **/
dea31012005-04-17 16:05:31 -05003380static int
James Smart2e0fef82007-06-17 19:56:36 -05003381lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05003382{
James Smart4430f7f2020-11-15 11:26:31 -08003383 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003384 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003385 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003386 FARP *fp;
3387 uint8_t *pcmd;
3388 uint32_t *lp;
3389 uint16_t cmdsize;
3390 struct lpfc_nodelist *ondlp;
3391 struct lpfc_nodelist *ndlp;
3392
James Smart92d7f7b2007-06-17 19:56:38 -05003393 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05003394
James Smarte47c9092008-02-08 18:49:26 -05003395 ndlp = lpfc_findnode_did(vport, nportid);
3396 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003397 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003398 if (!ndlp)
3399 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003400 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003401 }
James Smart2e0fef82007-06-17 19:56:36 -05003402
3403 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3404 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart4430f7f2020-11-15 11:26:31 -08003405 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003406 return 1;
dea31012005-04-17 16:05:31 -05003407
dea31012005-04-17 16:05:31 -05003408 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3409
3410 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003411 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003412
3413 /* Fill in FARPR payload */
3414 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003415 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003416 lp = (uint32_t *) pcmd;
3417 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003418 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003419 fp->Rflags = 0;
3420 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3421
James Smart92d7f7b2007-06-17 19:56:38 -05003422 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3423 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003424 ondlp = lpfc_findnode_did(vport, nportid);
James Smart307e3382020-11-15 11:26:30 -08003425 if (ondlp) {
dea31012005-04-17 16:05:31 -05003426 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003427 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003428 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003429 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003430 }
3431
James Smart858c9f62007-06-17 19:56:39 -05003432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3433 "Issue FARPR: did:x%x",
3434 ndlp->nlp_DID, 0, 0);
3435
dea31012005-04-17 16:05:31 -05003436 phba->fc_stat.elsXmitFARPR++;
3437 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003438 elsiocb->context1 = lpfc_nlp_get(ndlp);
3439 if (!elsiocb->context1) {
3440 lpfc_els_free_iocb(phba, elsiocb);
3441 return 1;
3442 }
3443
3444 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3445 if (rc == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003446 /* The additional lpfc_nlp_put will cause the following
3447 * lpfc_els_free_iocb routine to trigger the release of
3448 * the node.
3449 */
James Smart329f9bc2007-04-25 09:53:01 -04003450 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003451 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003452 return 1;
dea31012005-04-17 16:05:31 -05003453 }
James Smartfa4066b2008-01-11 01:53:27 -05003454 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3455 * trigger the release of the node.
3456 */
James Smartdf3fe762020-02-10 09:31:55 -08003457 /* Don't release reference count as RDF is likely outstanding */
3458 return 0;
3459}
3460
3461/**
3462 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3463 * @vport: pointer to a host virtual N_Port data structure.
3464 * @retry: retry counter for the command IOCB.
3465 *
3466 * This routine issues an ELS RDF to the Fabric Controller to register
3467 * for diagnostic functions.
3468 *
3469 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3470 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3471 * will be stored into the context1 field of the IOCB for the completion
3472 * callback function to the RDF ELS command.
3473 *
3474 * Return code
3475 * 0 - Successfully issued rdf command
3476 * 1 - Failed to issue rdf command
3477 **/
3478int
3479lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3480{
3481 struct lpfc_hba *phba = vport->phba;
3482 struct lpfc_iocbq *elsiocb;
3483 struct lpfc_els_rdf_req *prdf;
3484 struct lpfc_nodelist *ndlp;
3485 uint16_t cmdsize;
James Smart4430f7f2020-11-15 11:26:31 -08003486 int rc;
James Smartdf3fe762020-02-10 09:31:55 -08003487
3488 cmdsize = sizeof(*prdf);
3489
3490 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3491 if (!ndlp) {
3492 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3493 if (!ndlp)
3494 return -ENODEV;
3495 lpfc_enqueue_node(vport, ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003496 }
3497
3498 /* RDF ELS is not required on an NPIV VN_Port. */
3499 if (vport->port_type == LPFC_NPIV_PORT) {
3500 lpfc_nlp_put(ndlp);
3501 return -EACCES;
3502 }
3503
3504 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3505 ndlp->nlp_DID, ELS_CMD_RDF);
James Smart4430f7f2020-11-15 11:26:31 -08003506 if (!elsiocb)
James Smartdf3fe762020-02-10 09:31:55 -08003507 return -ENOMEM;
James Smartdf3fe762020-02-10 09:31:55 -08003508
3509 /* Configure the payload for the supported FPIN events. */
3510 prdf = (struct lpfc_els_rdf_req *)
3511 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3512 memset(prdf, 0, cmdsize);
3513 prdf->rdf.fpin_cmd = ELS_RDF;
3514 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3515 sizeof(struct fc_els_rdf));
3516 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3517 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3518 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3519 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3520 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
James Smart441f6b52020-08-28 10:53:31 -07003521 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3522 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3523 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
James Smartdf3fe762020-02-10 09:31:55 -08003524
James Smartdf3fe762020-02-10 09:31:55 -08003525 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3526 "6444 Xmit RDF to remote NPORT x%x\n",
3527 ndlp->nlp_DID);
3528
3529 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003530 elsiocb->context1 = lpfc_nlp_get(ndlp);
3531 if (!elsiocb->context1)
3532 goto node_err;
James Smartdf3fe762020-02-10 09:31:55 -08003533
James Smart4430f7f2020-11-15 11:26:31 -08003534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3535 "Issue RDF: did:x%x refcnt %d",
3536 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3537
3538 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3539 if (rc == IOCB_ERROR)
3540 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003541 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003542
3543 io_err:
3544 lpfc_nlp_put(ndlp);
3545 node_err:
3546 lpfc_els_free_iocb(phba, elsiocb);
3547 return -EIO;
dea31012005-04-17 16:05:31 -05003548}
3549
James Smarte59058c2008-08-24 21:49:00 -04003550/**
James Smart3621a712009-04-06 18:47:14 -04003551 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003552 * @vport: pointer to a host virtual N_Port data structure.
3553 * @nlp: pointer to a node-list data structure.
3554 *
3555 * This routine cancels the timer with a delayed IOCB-command retry for
3556 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3557 * removes the ELS retry event if it presents. In addition, if the
3558 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3559 * commands are sent for the @vport's nodes that require issuing discovery
3560 * ADISC.
3561 **/
dea31012005-04-17 16:05:31 -05003562void
James Smart2e0fef82007-06-17 19:56:36 -05003563lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003564{
James Smart2e0fef82007-06-17 19:56:36 -05003565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003566 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003567
James Smart0d2b6b82008-06-14 22:52:47 -04003568 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3569 return;
James Smartc6adba12020-11-15 11:26:34 -08003570 spin_lock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05003571 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08003572 spin_unlock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05003573 del_timer_sync(&nlp->nlp_delayfunc);
3574 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003575 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003576 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003577 /* Decrement nlp reference count held for the delayed retry */
3578 evtp = &nlp->els_retry_evt;
3579 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3580 }
James Smartfdcebe22006-03-07 15:04:01 -05003581 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smartc6adba12020-11-15 11:26:34 -08003582 spin_lock_irq(&nlp->lock);
James Smartfdcebe22006-03-07 15:04:01 -05003583 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08003584 spin_unlock_irq(&nlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05003585 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003586 if (vport->port_state < LPFC_VPORT_READY) {
3587 /* Check if there are more ADISCs to be sent */
3588 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003589 } else {
3590 /* Check if there are more PLOGIs to be sent */
3591 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003592 if (vport->num_disc_nodes == 0) {
3593 spin_lock_irq(shost->host_lock);
3594 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3595 spin_unlock_irq(shost->host_lock);
3596 lpfc_can_disctmo(vport);
3597 lpfc_end_rscn(vport);
3598 }
James Smartfdcebe22006-03-07 15:04:01 -05003599 }
3600 }
3601 }
3602 return;
3603}
3604
James Smarte59058c2008-08-24 21:49:00 -04003605/**
James Smart3621a712009-04-06 18:47:14 -04003606 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01003607 * @t: pointer to the timer function associated data (ndlp).
James Smarte59058c2008-08-24 21:49:00 -04003608 *
3609 * This routine is invoked by the ndlp delayed-function timer to check
3610 * whether there is any pending ELS retry event(s) with the node. If not, it
3611 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3612 * adds the delayed events to the HBA work list and invokes the
3613 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3614 * event. Note that lpfc_nlp_get() is called before posting the event to
3615 * the work list to hold reference count of ndlp so that it guarantees the
3616 * reference to ndlp will still be available when the worker thread gets
3617 * to the event associated with the ndlp.
3618 **/
James Smartfdcebe22006-03-07 15:04:01 -05003619void
Kees Cookf22eb4d2017-09-06 20:24:26 -07003620lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05003621{
Kees Cookf22eb4d2017-09-06 20:24:26 -07003622 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05003623 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003624 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003625 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003626 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003627
James Smart92d7f7b2007-06-17 19:56:38 -05003628 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003629 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003630 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003631 return;
3632 }
3633
James Smartfa4066b2008-01-11 01:53:27 -05003634 /* We need to hold the node by incrementing the reference
3635 * count until the queued work is done
3636 */
3637 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003638 if (evtp->evt_arg1) {
3639 evtp->evt = LPFC_EVT_ELS_RETRY;
3640 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003641 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003642 }
James Smart92d7f7b2007-06-17 19:56:38 -05003643 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003644 return;
3645}
3646
James Smarte59058c2008-08-24 21:49:00 -04003647/**
James Smart3621a712009-04-06 18:47:14 -04003648 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003649 * @ndlp: pointer to a node-list data structure.
3650 *
3651 * This routine is the worker-thread handler for processing the @ndlp delayed
3652 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3653 * the last ELS command from the associated ndlp and invokes the proper ELS
3654 * function according to the delayed ELS command to retry the command.
3655 **/
dea31012005-04-17 16:05:31 -05003656void
3657lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3658{
James Smart2e0fef82007-06-17 19:56:36 -05003659 struct lpfc_vport *vport = ndlp->vport;
James Smarteb016562014-09-03 12:58:06 -04003660 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003661
James Smartc6adba12020-11-15 11:26:34 -08003662 spin_lock_irq(&ndlp->lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003663 cmd = ndlp->nlp_last_elscmd;
3664 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003665
3666 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smartc6adba12020-11-15 11:26:34 -08003667 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05003668 return;
3669 }
3670
3671 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08003672 spin_unlock_irq(&ndlp->lock);
James Smart1a169682006-03-07 15:04:06 -05003673 /*
3674 * If a discovery event readded nlp_delayfunc after timer
3675 * firing and before processing the timer, cancel the
3676 * nlp_delayfunc.
3677 */
3678 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003679 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003680 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003681
3682 switch (cmd) {
3683 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003684 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003685 break;
3686 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003687 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003688 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003690 }
dea31012005-04-17 16:05:31 -05003691 break;
3692 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003693 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003694 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003695 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003696 }
dea31012005-04-17 16:05:31 -05003697 break;
3698 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003699 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003700 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003701 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003702 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003703 }
dea31012005-04-17 16:05:31 -05003704 break;
3705 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003706 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003707 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003708 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003709 }
dea31012005-04-17 16:05:31 -05003710 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003711 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003712 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3713 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003714 break;
dea31012005-04-17 16:05:31 -05003715 }
3716 return;
3717}
3718
James Smarte59058c2008-08-24 21:49:00 -04003719/**
James Smart5cca2ab2018-10-23 13:41:04 -07003720 * lpfc_link_reset - Issue link reset
3721 * @vport: pointer to a virtual N_Port data structure.
3722 *
3723 * This routine performs link reset by sending INIT_LINK mailbox command.
3724 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3725 * INIT_LINK mailbox command.
3726 *
3727 * Return code
3728 * 0 - Link reset initiated successfully
3729 * 1 - Failed to initiate link reset
3730 **/
3731int
3732lpfc_link_reset(struct lpfc_vport *vport)
3733{
3734 struct lpfc_hba *phba = vport->phba;
3735 LPFC_MBOXQ_t *mbox;
3736 uint32_t control;
3737 int rc;
3738
3739 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3740 "2851 Attempt link reset\n");
3741 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3742 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003743 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07003744 "2852 Failed to allocate mbox memory");
3745 return 1;
3746 }
3747
3748 /* Enable Link attention interrupts */
3749 if (phba->sli_rev <= LPFC_SLI_REV3) {
3750 spin_lock_irq(&phba->hbalock);
3751 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3752 control = readl(phba->HCregaddr);
3753 control |= HC_LAINT_ENA;
3754 writel(control, phba->HCregaddr);
3755 readl(phba->HCregaddr); /* flush */
3756 spin_unlock_irq(&phba->hbalock);
3757 }
3758
3759 lpfc_init_link(phba, mbox, phba->cfg_topology,
3760 phba->cfg_link_speed);
3761 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3762 mbox->vport = vport;
3763 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3764 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003765 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07003766 "2853 Failed to issue INIT_LINK "
3767 "mbox command, rc:x%x\n", rc);
3768 mempool_free(mbox, phba->mbox_mem_pool);
3769 return 1;
3770 }
3771
3772 return 0;
3773}
3774
3775/**
James Smart3621a712009-04-06 18:47:14 -04003776 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003777 * @phba: pointer to lpfc hba data structure.
3778 * @cmdiocb: pointer to lpfc command iocb data structure.
3779 * @rspiocb: pointer to lpfc response iocb data structure.
3780 *
3781 * This routine makes a retry decision on an ELS command IOCB, which has
3782 * failed. The following ELS IOCBs use this function for retrying the command
3783 * when previously issued command responsed with error status: FLOGI, PLOGI,
3784 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3785 * returned error status, it makes the decision whether a retry shall be
3786 * issued for the command, and whether a retry shall be made immediately or
3787 * delayed. In the former case, the corresponding ELS command issuing-function
3788 * is called to retry the command. In the later case, the ELS command shall
3789 * be posted to the ndlp delayed event and delayed function timer set to the
3790 * ndlp for the delayed command issusing.
3791 *
3792 * Return code
3793 * 0 - No retry of els command is made
3794 * 1 - Immediate or delayed retry of els command is made
3795 **/
dea31012005-04-17 16:05:31 -05003796static int
James Smart2e0fef82007-06-17 19:56:36 -05003797lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3798 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003799{
James Smart2e0fef82007-06-17 19:56:36 -05003800 struct lpfc_vport *vport = cmdiocb->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003801 IOCB_t *irsp = &rspiocb->iocb;
3802 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3803 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003804 uint32_t *elscmd;
3805 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003806 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003807 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003808 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003809 uint32_t did;
James Smart5cca2ab2018-10-23 13:41:04 -07003810 int link_reset = 0, rc;
dea31012005-04-17 16:05:31 -05003811
James Smart488d1462006-03-07 15:02:37 -05003812
dea31012005-04-17 16:05:31 -05003813 /* Note: context2 may be 0 for internal driver abort
3814 * of delays ELS command.
3815 */
3816
3817 if (pcmd && pcmd->virt) {
3818 elscmd = (uint32_t *) (pcmd->virt);
3819 cmd = *elscmd++;
3820 }
3821
James Smart307e3382020-11-15 11:26:30 -08003822 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05003823 did = ndlp->nlp_DID;
3824 else {
3825 /* We should only hit this case for retrying PLOGI */
3826 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003827 ndlp = lpfc_findnode_did(vport, did);
James Smart307e3382020-11-15 11:26:30 -08003828 if (!ndlp && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003829 return 1;
3830 }
3831
James Smart858c9f62007-06-17 19:56:39 -05003832 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3833 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3834 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3835
dea31012005-04-17 16:05:31 -05003836 switch (irsp->ulpStatus) {
3837 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003838 break;
James Smart1151e3e2011-02-16 12:39:35 -05003839 case IOSTAT_REMOTE_STOP:
3840 if (phba->sli_rev == LPFC_SLI_REV4) {
3841 /* This IO was aborted by the target, we don't
3842 * know the rxid and because we did not send the
3843 * ABTS we cannot generate and RRQ.
3844 */
3845 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003846 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003847 }
3848 break;
dea31012005-04-17 16:05:31 -05003849 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003850 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003851 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003852 if (cmd == ELS_CMD_FLOGI) {
3853 if (PCI_DEVICE_ID_HORNET ==
3854 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003855 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003856 phba->pport->fc_myDID = 0;
3857 phba->alpa_map[0] = 0;
3858 phba->alpa_map[1] = 0;
3859 }
3860 }
James Smart2e0fef82007-06-17 19:56:36 -05003861 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003862 delay = 1000;
dea31012005-04-17 16:05:31 -05003863 retry = 1;
3864 break;
3865
James Smart92d7f7b2007-06-17 19:56:38 -05003866 case IOERR_ILLEGAL_COMMAND:
Dick Kennedy372c1872020-06-30 14:50:00 -07003867 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart7f5f3d02008-02-08 18:50:14 -05003868 "0124 Retry illegal cmd x%x "
3869 "retry:x%x delay:x%x\n",
3870 cmd, cmdiocb->retry, delay);
3871 retry = 1;
3872 /* All command's retry policy */
3873 maxretry = 8;
3874 if (cmdiocb->retry > 2)
3875 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003876 break;
3877
dea31012005-04-17 16:05:31 -05003878 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003879 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003880 retry = 1;
3881 if (cmdiocb->retry > 100)
3882 delay = 100;
3883 maxretry = 250;
3884 break;
3885
3886 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003887 delay = 100;
dea31012005-04-17 16:05:31 -05003888 retry = 1;
3889 break;
3890
3891 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003892 if (cmd == ELS_CMD_PLOGI &&
3893 did == NameServer_DID) {
3894 /* Continue forever if plogi to */
3895 /* the nameserver fails */
3896 maxretry = 0;
3897 delay = 100;
3898 }
dea31012005-04-17 16:05:31 -05003899 retry = 1;
3900 break;
James Smart5cca2ab2018-10-23 13:41:04 -07003901
3902 case IOERR_SEQUENCE_TIMEOUT:
3903 if (cmd == ELS_CMD_PLOGI &&
3904 did == NameServer_DID &&
3905 (cmdiocb->retry + 1) == maxretry) {
3906 /* Reset the Link */
3907 link_reset = 1;
3908 break;
3909 }
3910 retry = 1;
3911 delay = 100;
3912 break;
dea31012005-04-17 16:05:31 -05003913 }
3914 break;
3915
3916 case IOSTAT_NPORT_RJT:
3917 case IOSTAT_FABRIC_RJT:
3918 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3919 retry = 1;
3920 break;
3921 }
3922 break;
3923
3924 case IOSTAT_NPORT_BSY:
3925 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003926 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003927 retry = 1;
3928 break;
3929
3930 case IOSTAT_LS_RJT:
3931 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3932 /* Added for Vendor specifc support
3933 * Just keep retrying for these Rsn / Exp codes
3934 */
3935 switch (stat.un.b.lsRjtRsnCode) {
3936 case LSRJT_UNABLE_TPC:
James Smartdea37e82017-06-01 21:07:07 -07003937 /* The driver has a VALID PLOGI but the rport has
3938 * rejected the PRLI - can't do it now. Delay
Dick Kennedy678768d2020-08-03 14:02:26 -07003939 * for 1 second and try again.
3940 *
3941 * However, if explanation is REQ_UNSUPPORTED there's
3942 * no point to retry PRLI.
James Smartdea37e82017-06-01 21:07:07 -07003943 */
Dick Kennedy678768d2020-08-03 14:02:26 -07003944 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3945 stat.un.b.lsRjtRsnCodeExp !=
3946 LSEXP_REQ_UNSUPPORTED) {
James Smartdea37e82017-06-01 21:07:07 -07003947 delay = 1000;
3948 maxretry = lpfc_max_els_tries + 1;
3949 retry = 1;
3950 break;
3951 }
3952
3953 /* Legacy bug fix code for targets with PLOGI delays. */
dea31012005-04-17 16:05:31 -05003954 if (stat.un.b.lsRjtRsnCodeExp ==
3955 LSEXP_CMD_IN_PROGRESS) {
3956 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003957 delay = 1000;
dea31012005-04-17 16:05:31 -05003958 maxretry = 48;
3959 }
3960 retry = 1;
3961 break;
3962 }
James Smartffc95492010-06-07 15:23:17 -04003963 if (stat.un.b.lsRjtRsnCodeExp ==
3964 LSEXP_CANT_GIVE_DATA) {
3965 if (cmd == ELS_CMD_PLOGI) {
3966 delay = 1000;
3967 maxretry = 48;
3968 }
3969 retry = 1;
3970 break;
3971 }
James Smartdea37e82017-06-01 21:07:07 -07003972 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003973 delay = 1000;
dea31012005-04-17 16:05:31 -05003974 maxretry = lpfc_max_els_tries + 1;
3975 retry = 1;
3976 break;
3977 }
James Smart92d7f7b2007-06-17 19:56:38 -05003978 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3979 (cmd == ELS_CMD_FDISC) &&
3980 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
Dick Kennedy372c1872020-06-30 14:50:00 -07003981 lpfc_printf_vlog(vport, KERN_ERR,
3982 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003983 "0125 FDISC Failed (x%x). "
3984 "Fabric out of resources\n",
3985 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003986 lpfc_vport_set_state(vport,
3987 FC_VPORT_NO_FABRIC_RSCS);
3988 }
dea31012005-04-17 16:05:31 -05003989 break;
3990
3991 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003992 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003993 (cmd == ELS_CMD_PRLI) ||
3994 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003995 delay = 1000;
dea31012005-04-17 16:05:31 -05003996 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003997 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003998 /* FDISC retry policy */
3999 maxretry = 48;
4000 if (cmdiocb->retry >= 32)
4001 delay = 1000;
dea31012005-04-17 16:05:31 -05004002 }
4003 retry = 1;
4004 break;
James Smart92d7f7b2007-06-17 19:56:38 -05004005
4006 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05004007 /* There are some cases where switches return this
4008 * error when they are not ready and should be returning
4009 * Logical Busy. We should delay every time.
4010 */
4011 if (cmd == ELS_CMD_FDISC &&
4012 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4013 maxretry = 3;
4014 delay = 1000;
4015 retry = 1;
James Smart44fd7fe2017-08-23 16:55:47 -07004016 } else if (cmd == ELS_CMD_FLOGI &&
4017 stat.un.b.lsRjtRsnCodeExp ==
4018 LSEXP_NOTHING_MORE) {
4019 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4020 retry = 1;
Dick Kennedy372c1872020-06-30 14:50:00 -07004021 lpfc_printf_vlog(vport, KERN_ERR,
4022 LOG_TRACE_EVENT,
James Smart44fd7fe2017-08-23 16:55:47 -07004023 "0820 FLOGI Failed (x%x). "
4024 "BBCredit Not Supported\n",
4025 stat.un.lsRjtError);
James Smart7f5f3d02008-02-08 18:50:14 -05004026 }
James Smart44fd7fe2017-08-23 16:55:47 -07004027 break;
4028
James Smart92d7f7b2007-06-17 19:56:38 -05004029 case LSRJT_PROTOCOL_ERR:
4030 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4031 (cmd == ELS_CMD_FDISC) &&
4032 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4033 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4034 ) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004035 lpfc_printf_vlog(vport, KERN_ERR,
4036 LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04004037 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04004038 "Fabric Detected Bad WWN\n",
4039 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05004040 lpfc_vport_set_state(vport,
4041 FC_VPORT_FABRIC_REJ_WWN);
4042 }
4043 break;
James Smart7bdedb32016-07-06 12:36:00 -07004044 case LSRJT_VENDOR_UNIQUE:
4045 if ((stat.un.b.vendorUnique == 0x45) &&
4046 (cmd == ELS_CMD_FLOGI)) {
4047 goto out_retry;
4048 }
4049 break;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004050 case LSRJT_CMD_UNSUPPORTED:
4051 /* lpfc nvmet returns this type of LS_RJT when it
4052 * receives an FCP PRLI because lpfc nvmet only
4053 * support NVME. ELS request is terminated for FCP4
4054 * on this rport.
4055 */
4056 if (stat.un.b.lsRjtRsnCodeExp ==
4057 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
James Smartc6adba12020-11-15 11:26:34 -08004058 spin_lock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004059 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
James Smartc6adba12020-11-15 11:26:34 -08004060 spin_unlock_irq(&ndlp->lock);
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004061 retry = 0;
4062 goto out_retry;
4063 }
4064 break;
dea31012005-04-17 16:05:31 -05004065 }
4066 break;
4067
4068 case IOSTAT_INTERMED_RSP:
4069 case IOSTAT_BA_RJT:
4070 break;
4071
4072 default:
4073 break;
4074 }
4075
James Smart5cca2ab2018-10-23 13:41:04 -07004076 if (link_reset) {
4077 rc = lpfc_link_reset(vport);
4078 if (rc) {
4079 /* Do not give up. Retry PLOGI one more time and attempt
4080 * link reset if PLOGI fails again.
4081 */
4082 retry = 1;
4083 delay = 100;
4084 goto out_retry;
4085 }
4086 return 1;
4087 }
4088
James Smart488d1462006-03-07 15:02:37 -05004089 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05004090 retry = 1;
dea31012005-04-17 16:05:31 -05004091
James Smartdf9e1b52011-12-13 13:22:17 -05004092 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05004093 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05004094 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004095 /* FLOGI retry policy */
4096 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05004097 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04004098 if (phba->link_flag != LS_LOOPBACK_MODE)
4099 maxretry = 0;
4100 else
4101 maxretry = 2;
4102
James Smart6669f9b2009-10-02 15:16:45 -04004103 if (cmdiocb->retry >= 100)
4104 delay = 5000;
4105 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04004106 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05004107 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4108 /* retry FDISCs every second up to devloss */
4109 retry = 1;
4110 maxretry = vport->cfg_devloss_tmo;
4111 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04004112 }
4113
James Smart6669f9b2009-10-02 15:16:45 -04004114 cmdiocb->retry++;
4115 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05004116 phba->fc_stat.elsRetryExceeded++;
4117 retry = 0;
4118 }
4119
James Smarted957682007-06-17 19:56:37 -05004120 if ((vport->load_flag & FC_UNLOADING) != 0)
4121 retry = 0;
4122
James Smart7bdedb32016-07-06 12:36:00 -07004123out_retry:
dea31012005-04-17 16:05:31 -05004124 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04004125 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4126 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4127 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4129 "2849 Stop retry ELS command "
4130 "x%x to remote NPORT x%x, "
4131 "Data: x%x x%x\n", cmd, did,
4132 cmdiocb->retry, delay);
4133 return 0;
4134 }
4135 }
dea31012005-04-17 16:05:31 -05004136
4137 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004138 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4139 "0107 Retry ELS command x%x to remote "
4140 "NPORT x%x Data: x%x x%x\n",
4141 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05004142
James Smart858c9f62007-06-17 19:56:39 -05004143 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4144 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04004145 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4146 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05004147 /* Don't reset timer for no resources */
4148
dea31012005-04-17 16:05:31 -05004149 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05004150 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05004151 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05004152 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004153 }
4154
4155 phba->fc_stat.elsXmitRetry++;
James Smart307e3382020-11-15 11:26:30 -08004156 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05004157 phba->fc_stat.elsDelayRetry++;
4158 ndlp->nlp_retry = cmdiocb->retry;
4159
James Smart92d7f7b2007-06-17 19:56:38 -05004160 /* delay is specified in milliseconds */
4161 mod_timer(&ndlp->nlp_delayfunc,
4162 jiffies + msecs_to_jiffies(delay));
James Smartc6adba12020-11-15 11:26:34 -08004163 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004164 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08004165 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004166
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004167 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08004168 if ((cmd == ELS_CMD_PRLI) ||
4169 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05004170 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04004171 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004172 else
4173 lpfc_nlp_set_state(vport, ndlp,
4174 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004175 ndlp->nlp_last_elscmd = cmd;
4176
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004177 return 1;
dea31012005-04-17 16:05:31 -05004178 }
4179 switch (cmd) {
4180 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004181 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004182 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05004183 case ELS_CMD_FDISC:
4184 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4185 return 1;
dea31012005-04-17 16:05:31 -05004186 case ELS_CMD_PLOGI:
James Smart307e3382020-11-15 11:26:30 -08004187 if (ndlp) {
James Smart488d1462006-03-07 15:02:37 -05004188 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004189 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004190 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05004191 }
James Smart2e0fef82007-06-17 19:56:36 -05004192 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004193 return 1;
dea31012005-04-17 16:05:31 -05004194 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004195 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4197 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004198 return 1;
dea31012005-04-17 16:05:31 -05004199 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08004200 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004201 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4203 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004204 return 1;
dea31012005-04-17 16:05:31 -05004205 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004206 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04004207 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004208 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004209 return 1;
dea31012005-04-17 16:05:31 -05004210 }
4211 }
dea31012005-04-17 16:05:31 -05004212 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04004213 if (logerr) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004214 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart98c9ea52007-10-27 13:37:33 -04004215 "0137 No retry ELS command x%x to remote "
4216 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4217 cmd, did, irsp->ulpStatus,
4218 irsp->un.ulpWord[4]);
4219 }
4220 else {
4221 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04004222 "0108 No retry ELS command x%x to remote "
4223 "NPORT x%x Retried:%d Error:x%x/%x\n",
4224 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4225 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04004226 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004227 return 0;
dea31012005-04-17 16:05:31 -05004228}
4229
James Smarte59058c2008-08-24 21:49:00 -04004230/**
James Smart3621a712009-04-06 18:47:14 -04004231 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04004232 * @phba: pointer to lpfc hba data structure.
4233 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4234 *
4235 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4236 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4237 * checks to see whether there is a lpfc DMA buffer associated with the
4238 * response of the command IOCB. If so, it will be released before releasing
4239 * the lpfc DMA buffer associated with the IOCB itself.
4240 *
4241 * Return code
4242 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4243 **/
James Smart09372822008-01-11 01:52:54 -05004244static int
James Smart87af33f2007-10-27 13:37:43 -04004245lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4246{
4247 struct lpfc_dmabuf *buf_ptr;
4248
James Smarte59058c2008-08-24 21:49:00 -04004249 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04004250 if (!list_empty(&buf_ptr1->list)) {
4251 list_remove_head(&buf_ptr1->list, buf_ptr,
4252 struct lpfc_dmabuf,
4253 list);
4254 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4255 kfree(buf_ptr);
4256 }
4257 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4258 kfree(buf_ptr1);
4259 return 0;
4260}
4261
James Smarte59058c2008-08-24 21:49:00 -04004262/**
James Smart3621a712009-04-06 18:47:14 -04004263 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04004264 * @phba: pointer to lpfc hba data structure.
4265 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4266 *
4267 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4268 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4269 * pool.
4270 *
4271 * Return code
4272 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4273 **/
James Smart09372822008-01-11 01:52:54 -05004274static int
James Smart87af33f2007-10-27 13:37:43 -04004275lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4276{
4277 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4278 kfree(buf_ptr);
4279 return 0;
4280}
4281
James Smarte59058c2008-08-24 21:49:00 -04004282/**
James Smart3621a712009-04-06 18:47:14 -04004283 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04004284 * @phba: pointer to lpfc hba data structure.
4285 * @elsiocb: pointer to lpfc els command iocb data structure.
4286 *
4287 * This routine frees a command IOCB and its associated resources. The
4288 * command IOCB data structure contains the reference to various associated
4289 * resources, these fields must be set to NULL if the associated reference
4290 * not present:
4291 * context1 - reference to ndlp
4292 * context2 - reference to cmd
4293 * context2->next - reference to rsp
4294 * context3 - reference to bpl
4295 *
4296 * It first properly decrements the reference count held on ndlp for the
4297 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4298 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4299 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4300 * adds the DMA buffer the @phba data structure for the delayed release.
4301 * If reference to the Buffer Pointer List (BPL) is present, the
4302 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4303 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4304 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4305 *
4306 * Return code
4307 * 0 - Success (currently, always return 0)
4308 **/
James Smart87af33f2007-10-27 13:37:43 -04004309int
James Smart329f9bc2007-04-25 09:53:01 -04004310lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004311{
4312 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4313
James Smart4430f7f2020-11-15 11:26:31 -08004314 /* The I/O job is complete. Clear the context1 data. */
4315 elsiocb->context1 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04004316
dea31012005-04-17 16:05:31 -05004317 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4318 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05004319 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4320 /* Firmware could still be in progress of DMAing
4321 * payload, so don't free data buffer till after
4322 * a hbeat.
4323 */
4324 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4325 buf_ptr = elsiocb->context2;
4326 elsiocb->context2 = NULL;
4327 if (buf_ptr) {
4328 buf_ptr1 = NULL;
4329 spin_lock_irq(&phba->hbalock);
4330 if (!list_empty(&buf_ptr->list)) {
4331 list_remove_head(&buf_ptr->list,
4332 buf_ptr1, struct lpfc_dmabuf,
4333 list);
4334 INIT_LIST_HEAD(&buf_ptr1->list);
4335 list_add_tail(&buf_ptr1->list,
4336 &phba->elsbuf);
4337 phba->elsbuf_cnt++;
4338 }
4339 INIT_LIST_HEAD(&buf_ptr->list);
4340 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4341 phba->elsbuf_cnt++;
4342 spin_unlock_irq(&phba->hbalock);
4343 }
4344 } else {
4345 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4346 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01004347 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05004348 }
dea31012005-04-17 16:05:31 -05004349 }
4350
4351 if (elsiocb->context3) {
4352 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04004353 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01004354 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05004355 }
James Bottomley604a3e32005-10-29 10:28:33 -05004356 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05004357 return 0;
4358}
4359
James Smarte59058c2008-08-24 21:49:00 -04004360/**
James Smart3621a712009-04-06 18:47:14 -04004361 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04004362 * @phba: pointer to lpfc hba data structure.
4363 * @cmdiocb: pointer to lpfc command iocb data structure.
4364 * @rspiocb: pointer to lpfc response iocb data structure.
4365 *
4366 * This routine is the completion callback function to the Logout (LOGO)
4367 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4368 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4369 * release the ndlp if it has the last reference remaining (reference count
4370 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4371 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4372 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4373 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4374 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4375 * IOCB data structure.
4376 **/
dea31012005-04-17 16:05:31 -05004377static void
James Smart2e0fef82007-06-17 19:56:36 -05004378lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4379 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004380{
James Smart2e0fef82007-06-17 19:56:36 -05004381 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4382 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004383 IOCB_t *irsp;
4384
4385 irsp = &rspiocb->iocb;
4386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4387 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4388 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05004389 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04004390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta70e63e2020-11-15 11:26:38 -08004391 "0109 ACC to LOGO completes to NPort x%x refcnt %d"
James Smarte8b62012007-08-02 11:10:09 -04004392 "Data: x%x x%x x%x\n",
James Smarta70e63e2020-11-15 11:26:38 -08004393 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
4394 ndlp->nlp_state, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04004395
4396 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4397 /* NPort Recovery mode or node is just allocated */
4398 if (!lpfc_nlp_not_used(ndlp)) {
4399 /* If the ndlp is being used by another discovery
4400 * thread, just unregister the RPI.
4401 */
4402 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004403 } else {
4404 /* Indicate the node has already released, should
4405 * not reference to it from within lpfc_els_free_iocb.
4406 */
4407 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04004408 }
dea31012005-04-17 16:05:31 -05004409 }
James Smart73d91e52011-10-10 21:32:10 -04004410
4411 /*
4412 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05004413 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04004414 */
dea31012005-04-17 16:05:31 -05004415 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08004416 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004417}
4418
James Smarte59058c2008-08-24 21:49:00 -04004419/**
James Smart3621a712009-04-06 18:47:14 -04004420 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004421 * @phba: pointer to lpfc hba data structure.
4422 * @pmb: pointer to the driver internal queue element for mailbox command.
4423 *
4424 * This routine is the completion callback function for unregister default
4425 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4426 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4427 * decrements the ndlp reference count held for this completion callback
4428 * function. After that, it invokes the lpfc_nlp_not_used() to check
4429 * whether there is only one reference left on the ndlp. If so, it will
4430 * perform one more decrement and trigger the release of the ndlp.
4431 **/
James Smart858c9f62007-06-17 19:56:39 -05004432void
4433lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4434{
James Smart3e1f0712018-11-29 16:09:29 -08004435 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4436 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart858c9f62007-06-17 19:56:39 -05004437
James Smart3e1f0712018-11-29 16:09:29 -08004438 pmb->ctx_buf = NULL;
4439 pmb->ctx_ndlp = NULL;
James Smartd439d282010-09-29 11:18:45 -04004440
James Smart858c9f62007-06-17 19:56:39 -05004441 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4442 kfree(mp);
4443 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04004444 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04004445 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smarte9b11082020-11-15 11:26:33 -08004446 "0006 rpi x%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004447 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004448 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08004449 ndlp);
James Smart307e3382020-11-15 11:26:30 -08004450 /* This is the end of the default RPI cleanup logic for
James Smarte9b11082020-11-15 11:26:33 -08004451 * this ndlp and it could get released. Clear the nlp_flags to
4452 * prevent any further processing.
James Smart307e3382020-11-15 11:26:30 -08004453 */
James Smarte9b11082020-11-15 11:26:33 -08004454 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4455 lpfc_nlp_put(ndlp);
James Smart307e3382020-11-15 11:26:30 -08004456 lpfc_nlp_not_used(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04004457 }
James Smart3772a992009-05-22 14:50:54 -04004458
James Smart858c9f62007-06-17 19:56:39 -05004459 return;
4460}
4461
James Smarte59058c2008-08-24 21:49:00 -04004462/**
James Smart3621a712009-04-06 18:47:14 -04004463 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004464 * @phba: pointer to lpfc hba data structure.
4465 * @cmdiocb: pointer to lpfc command iocb data structure.
4466 * @rspiocb: pointer to lpfc response iocb data structure.
4467 *
4468 * This routine is the completion callback function for ELS Response IOCB
4469 * command. In normal case, this callback function just properly sets the
4470 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4471 * field in the command IOCB is not NULL, the referred mailbox command will
4472 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4473 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4474 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4475 * routine shall be invoked trying to release the ndlp if no other threads
4476 * are currently referring it.
4477 **/
dea31012005-04-17 16:05:31 -05004478static void
James Smart858c9f62007-06-17 19:56:39 -05004479lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04004480 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004481{
James Smart2e0fef82007-06-17 19:56:36 -05004482 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4483 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4484 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04004485 IOCB_t *irsp;
4486 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05004487 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004488 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04004489 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05004490
James Smart33ccf8d2006-08-17 11:57:58 -04004491 irsp = &rspiocb->iocb;
4492
James Smart43bfea12019-09-21 20:58:57 -07004493 if (!vport) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004494 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartf84f8f92019-10-18 14:18:23 -07004495 "3177 ELS response failed\n");
James Smart43bfea12019-09-21 20:58:57 -07004496 goto out;
4497 }
dea31012005-04-17 16:05:31 -05004498 if (cmdiocb->context_un.mbox)
4499 mbox = cmdiocb->context_un.mbox;
4500
James Smartfa4066b2008-01-11 01:53:27 -05004501 /* First determine if this is a LS_RJT cmpl. Note, this callback
4502 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4503 */
James Smart87af33f2007-10-27 13:37:43 -04004504 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart307e3382020-11-15 11:26:30 -08004505 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05004506 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08004507 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04004508 */
4509 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4510 ls_rjt = 1;
4511 }
4512
dea31012005-04-17 16:05:31 -05004513 /* Check to see if link went down during discovery */
James Smart307e3382020-11-15 11:26:30 -08004514 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05004515 if (mbox) {
James Smart3e1f0712018-11-29 16:09:29 -08004516 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004517 if (mp) {
4518 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4519 kfree(mp);
4520 }
James Smart329f9bc2007-04-25 09:53:01 -04004521 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004522 }
James Smart307e3382020-11-15 11:26:30 -08004523 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05004524 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004525 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004526 /* Indicate the node has already released,
4527 * should not reference to it from within
4528 * the routine lpfc_els_free_iocb.
4529 */
4530 cmdiocb->context1 = NULL;
4531 }
dea31012005-04-17 16:05:31 -05004532 goto out;
4533 }
4534
James Smart858c9f62007-06-17 19:56:39 -05004535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04004536 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004537 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04004538 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05004539 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04004540 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4541 "0110 ELS response tag x%x completes "
4542 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4543 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4544 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4546 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004547 if (mbox) {
James Smart4430f7f2020-11-15 11:26:31 -08004548 if ((rspiocb->iocb.ulpStatus == 0) &&
4549 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07004550 if (!lpfc_unreg_rpi(vport, ndlp) &&
James Smart4430f7f2020-11-15 11:26:31 -08004551 (!(vport->fc_flag & FC_PT2PT))) {
4552 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4553 lpfc_printf_vlog(vport, KERN_INFO,
4554 LOG_DISCOVERY,
4555 "0314 PLOGI recov "
4556 "DID x%x "
4557 "Data: x%x x%x x%x\n",
4558 ndlp->nlp_DID,
4559 ndlp->nlp_state,
4560 ndlp->nlp_rpi,
4561 ndlp->nlp_flag);
4562 mp = mbox->ctx_buf;
4563 if (mp) {
4564 lpfc_mbuf_free(phba, mp->virt,
4565 mp->phys);
4566 kfree(mp);
4567 }
4568 mempool_free(mbox, phba->mbox_mem_pool);
4569 goto out;
Dick Kennedy1fe68472017-08-23 16:55:30 -07004570 }
Dick Kennedy1fe68472017-08-23 16:55:30 -07004571 }
4572
James Smarte47c9092008-02-08 18:49:26 -05004573 /* Increment reference count to ndlp to hold the
4574 * reference to ndlp for the callback function.
4575 */
James Smart3e1f0712018-11-29 16:09:29 -08004576 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08004577 if (!mbox->ctx_ndlp)
4578 goto out;
4579
James Smart2e0fef82007-06-17 19:56:36 -05004580 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004581 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4582 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4583 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4584 }
4585 else {
4586 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4587 ndlp->nlp_prev_state = ndlp->nlp_state;
4588 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05004589 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004590 }
James Smart4b7789b72015-12-16 18:11:55 -05004591
4592 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04004593 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05004594 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05004595 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05004596
4597 /* Decrement the ndlp reference count we
4598 * set for this failed mailbox command.
4599 */
4600 lpfc_nlp_put(ndlp);
4601 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04004602
4603 /* ELS rsp: Cannot issue reg_login for <NPortid> */
Dick Kennedy372c1872020-06-30 14:50:00 -07004604 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart98c9ea52007-10-27 13:37:33 -04004605 "0138 ELS rsp: Cannot issue reg_login for x%x "
4606 "Data: x%x x%x x%x\n",
4607 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4608 ndlp->nlp_rpi);
4609
James Smartfa4066b2008-01-11 01:53:27 -05004610 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004611 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004612 /* Indicate node has already been released,
4613 * should not reference to it from within
4614 * the routine lpfc_els_free_iocb.
4615 */
4616 cmdiocb->context1 = NULL;
4617 }
dea31012005-04-17 16:05:31 -05004618 } else {
James Smart858c9f62007-06-17 19:56:39 -05004619 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4620 if (!lpfc_error_lost_link(irsp) &&
4621 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05004622 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004623 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004624 /* Indicate node has already been
4625 * released, should not reference
4626 * to it from within the routine
4627 * lpfc_els_free_iocb.
4628 */
4629 cmdiocb->context1 = NULL;
4630 }
dea31012005-04-17 16:05:31 -05004631 }
4632 }
James Smart3e1f0712018-11-29 16:09:29 -08004633 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004634 if (mp) {
4635 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4636 kfree(mp);
4637 }
4638 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004639 }
4640out:
James Smart307e3382020-11-15 11:26:30 -08004641 if (ndlp && shost) {
James Smartc6adba12020-11-15 11:26:34 -08004642 spin_lock_irq(&ndlp->lock);
James Smart7b08e892020-08-28 10:53:30 -07004643 if (mbox)
4644 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4645 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
James Smartc6adba12020-11-15 11:26:34 -08004646 spin_unlock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04004647
4648 /* If the node is not being used by another discovery thread,
4649 * and we are sending a reject, we are done with it.
4650 * Release driver reference count here and free associated
4651 * resources.
4652 */
4653 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05004654 if (lpfc_nlp_not_used(ndlp))
4655 /* Indicate node has already been released,
4656 * should not reference to it from within
4657 * the routine lpfc_els_free_iocb.
4658 */
4659 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004660 }
James Smart87af33f2007-10-27 13:37:43 -04004661
James Smart4430f7f2020-11-15 11:26:31 -08004662 /* Release the originating I/O reference. */
dea31012005-04-17 16:05:31 -05004663 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08004664 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004665 return;
4666}
4667
James Smarte59058c2008-08-24 21:49:00 -04004668/**
James Smart3621a712009-04-06 18:47:14 -04004669 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004670 * @vport: pointer to a host virtual N_Port data structure.
4671 * @flag: the els command code to be accepted.
4672 * @oldiocb: pointer to the original lpfc command iocb data structure.
4673 * @ndlp: pointer to a node-list data structure.
4674 * @mbox: pointer to the driver internal queue element for mailbox command.
4675 *
4676 * This routine prepares and issues an Accept (ACC) response IOCB
4677 * command. It uses the @flag to properly set up the IOCB field for the
4678 * specific ACC response command to be issued and invokes the
4679 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4680 * @mbox pointer is passed in, it will be put into the context_un.mbox
4681 * field of the IOCB for the completion callback function to issue the
4682 * mailbox command to the HBA later when callback is invoked.
4683 *
4684 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4685 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4686 * will be stored into the context1 field of the IOCB for the completion
4687 * callback function to the corresponding response ELS IOCB command.
4688 *
4689 * Return code
4690 * 0 - Successfully issued acc response
4691 * 1 - Failed to issue acc response
4692 **/
dea31012005-04-17 16:05:31 -05004693int
James Smart2e0fef82007-06-17 19:56:36 -05004694lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4695 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04004696 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004697{
James Smart2e0fef82007-06-17 19:56:36 -05004698 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004699 IOCB_t *icmd;
4700 IOCB_t *oldcmd;
4701 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004702 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004703 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004704 uint16_t cmdsize;
4705 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004706 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004707
dea31012005-04-17 16:05:31 -05004708 oldcmd = &oldiocb->iocb;
4709
4710 switch (flag) {
4711 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004712 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004713 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4714 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004715 if (!elsiocb) {
James Smartc6adba12020-11-15 11:26:34 -08004716 spin_lock_irq(&ndlp->lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004717 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smartc6adba12020-11-15 11:26:34 -08004718 spin_unlock_irq(&ndlp->lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004719 return 1;
dea31012005-04-17 16:05:31 -05004720 }
James Smart2e0fef82007-06-17 19:56:36 -05004721
dea31012005-04-17 16:05:31 -05004722 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004723 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4724 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004725 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4726 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004727 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004728
4729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4730 "Issue ACC: did:x%x flg:x%x",
4731 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004732 break;
James Smartd6de08c2015-12-16 18:11:53 -05004733 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004734 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004735 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004736 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4737 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004738 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004739 return 1;
James Smart488d1462006-03-07 15:02:37 -05004740
dea31012005-04-17 16:05:31 -05004741 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004742 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4743 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004744 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4745
4746 if (mbox)
4747 elsiocb->context_un.mbox = mbox;
4748
4749 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004750 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004751 sp = (struct serv_parm *)pcmd;
4752
4753 if (flag == ELS_CMD_FLOGI) {
4754 /* Copy the received service parameters back */
4755 memcpy(sp, &phba->fc_fabparam,
4756 sizeof(struct serv_parm));
4757
4758 /* Clear the F_Port bit */
4759 sp->cmn.fPort = 0;
4760
4761 /* Mark all class service parameters as invalid */
4762 sp->cls1.classValid = 0;
4763 sp->cls2.classValid = 0;
4764 sp->cls3.classValid = 0;
4765 sp->cls4.classValid = 0;
4766
4767 /* Copy our worldwide names */
4768 memcpy(&sp->portName, &vport->fc_sparam.portName,
4769 sizeof(struct lpfc_name));
4770 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4771 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004772 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004773 memcpy(pcmd, &vport->fc_sparam,
4774 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004775
James Smart8c258642017-02-12 13:52:36 -08004776 sp->cmn.valid_vendor_ver_level = 0;
4777 memset(sp->un.vendorVersion, 0,
4778 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07004779 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08004780
4781 /* If our firmware supports this feature, convey that
4782 * info to the target using the vendor specific field.
4783 */
4784 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4785 sp->cmn.valid_vendor_ver_level = 1;
4786 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4787 sp->un.vv.flags =
4788 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4789 }
4790 }
4791
James Smart858c9f62007-06-17 19:56:39 -05004792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004793 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004794 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004795 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004796 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004797 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004798 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004799 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4800 if (!elsiocb)
4801 return 1;
4802
4803 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004804 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4805 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004806 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4807
4808 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004809 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004810 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4811 els_pkt_ptr = (ELS_PKT *) pcmd;
4812 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004813
4814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4815 "Issue ACC PRLO: did:x%x flg:x%x",
4816 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004817 break;
dea31012005-04-17 16:05:31 -05004818 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004819 return 1;
dea31012005-04-17 16:05:31 -05004820 }
dea31012005-04-17 16:05:31 -05004821 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smartc6adba12020-11-15 11:26:34 -08004822 spin_lock_irq(&ndlp->lock);
James Smart7c5e5182015-05-22 10:42:43 -04004823 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4824 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4825 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smartc6adba12020-11-15 11:26:34 -08004826 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05004827 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4828 } else {
James Smart858c9f62007-06-17 19:56:39 -05004829 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004830 }
4831
4832 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08004833 elsiocb->context1 = lpfc_nlp_get(ndlp);
4834 if (!elsiocb->context1)
4835 goto node_err;
4836
James Smart3772a992009-05-22 14:50:54 -04004837 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08004838 if (rc == IOCB_ERROR)
4839 goto io_err;
4840
4841 /* Xmit ELS ACC response tag <ulpIoTag> */
4842 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4843 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4844 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4845 "RPI: x%x, fc_flag x%x\n",
4846 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4847 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4848 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004849 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08004850
4851io_err:
4852 lpfc_nlp_put(ndlp);
4853node_err:
4854 lpfc_els_free_iocb(phba, elsiocb);
4855 return 1;
dea31012005-04-17 16:05:31 -05004856}
4857
James Smarte59058c2008-08-24 21:49:00 -04004858/**
James Smart3621a712009-04-06 18:47:14 -04004859 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004860 * @vport: pointer to a virtual N_Port data structure.
Lee Jonesa0e4a642020-07-23 13:24:07 +01004861 * @rejectError: reject response to issue
James Smarte59058c2008-08-24 21:49:00 -04004862 * @oldiocb: pointer to the original lpfc command iocb data structure.
4863 * @ndlp: pointer to a node-list data structure.
4864 * @mbox: pointer to the driver internal queue element for mailbox command.
4865 *
4866 * This routine prepares and issue an Reject (RJT) response IOCB
4867 * command. If a @mbox pointer is passed in, it will be put into the
4868 * context_un.mbox field of the IOCB for the completion callback function
4869 * to issue to the HBA later.
4870 *
4871 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4872 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4873 * will be stored into the context1 field of the IOCB for the completion
4874 * callback function to the reject response ELS IOCB command.
4875 *
4876 * Return code
4877 * 0 - Successfully issued reject response
4878 * 1 - Failed to issue reject response
4879 **/
dea31012005-04-17 16:05:31 -05004880int
James Smart2e0fef82007-06-17 19:56:36 -05004881lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004882 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4883 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004884{
James Smart4430f7f2020-11-15 11:26:31 -08004885 int rc;
James Smart2e0fef82007-06-17 19:56:36 -05004886 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004887 IOCB_t *icmd;
4888 IOCB_t *oldcmd;
4889 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004890 uint8_t *pcmd;
4891 uint16_t cmdsize;
dea31012005-04-17 16:05:31 -05004892
James Smart92d7f7b2007-06-17 19:56:38 -05004893 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004894 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4895 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004896 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004897 return 1;
dea31012005-04-17 16:05:31 -05004898
4899 icmd = &elsiocb->iocb;
4900 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004901 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4902 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004903 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4904
4905 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004906 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004907 *((uint32_t *) (pcmd)) = rejectError;
4908
James Smart51ef4c22007-08-02 11:10:31 -04004909 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004910 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004911
dea31012005-04-17 16:05:31 -05004912 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004913 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4914 "0129 Xmit ELS RJT x%x response tag x%x "
4915 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4916 "rpi x%x\n",
4917 rejectError, elsiocb->iotag,
4918 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4919 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4921 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4922 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4923
dea31012005-04-17 16:05:31 -05004924 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004925 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08004926 elsiocb->context1 = lpfc_nlp_get(ndlp);
4927 if (!elsiocb->context1)
4928 goto node_err;
James Smart51ef4c22007-08-02 11:10:31 -04004929
James Smart4430f7f2020-11-15 11:26:31 -08004930 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4931 if (rc == IOCB_ERROR)
4932 goto io_err;
4933
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004934 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08004935
4936 io_err:
4937 lpfc_nlp_put(ndlp);
4938 node_err:
4939 lpfc_els_free_iocb(phba, elsiocb);
4940 return 1;
dea31012005-04-17 16:05:31 -05004941}
4942
James Smarte59058c2008-08-24 21:49:00 -04004943/**
James Smart3621a712009-04-06 18:47:14 -04004944 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004945 * @vport: pointer to a virtual N_Port data structure.
4946 * @oldiocb: pointer to the original lpfc command iocb data structure.
4947 * @ndlp: pointer to a node-list data structure.
4948 *
4949 * This routine prepares and issues an Accept (ACC) response to Address
4950 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4951 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4952 *
4953 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4954 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4955 * will be stored into the context1 field of the IOCB for the completion
4956 * callback function to the ADISC Accept response ELS IOCB command.
4957 *
4958 * Return code
4959 * 0 - Successfully issued acc adisc response
4960 * 1 - Failed to issue adisc acc response
4961 **/
dea31012005-04-17 16:05:31 -05004962int
James Smart2e0fef82007-06-17 19:56:36 -05004963lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4964 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004965{
James Smart2e0fef82007-06-17 19:56:36 -05004966 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004967 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004968 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004969 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004970 uint8_t *pcmd;
4971 uint16_t cmdsize;
4972 int rc;
4973
James Smart92d7f7b2007-06-17 19:56:38 -05004974 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004975 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4976 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004977 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004978 return 1;
dea31012005-04-17 16:05:31 -05004979
dea31012005-04-17 16:05:31 -05004980 icmd = &elsiocb->iocb;
4981 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004982 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4983 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004984
4985 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004986 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4987 "0130 Xmit ADISC ACC response iotag x%x xri: "
4988 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4989 elsiocb->iotag, elsiocb->iocb.ulpContext,
4990 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4991 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004992 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4993
4994 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004995 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004996
4997 ap = (ADISC *) (pcmd);
4998 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004999 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5000 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05005001 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05005002
James Smart858c9f62007-06-17 19:56:39 -05005003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005004 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5005 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005006
dea31012005-04-17 16:05:31 -05005007 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005008 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005009 elsiocb->context1 = lpfc_nlp_get(ndlp);
5010 if (!elsiocb->context1)
5011 goto node_err;
5012
James Smart3772a992009-05-22 14:50:54 -04005013 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005014 if (rc == IOCB_ERROR)
5015 goto io_err;
James Smartd496b9a2018-10-23 13:41:08 -07005016
5017 /* Xmit ELS ACC response tag <ulpIoTag> */
5018 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5019 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5020 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5021 "RPI: x%x, fc_flag x%x\n",
5022 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5023 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5024 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005025 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005026
5027io_err:
5028 lpfc_nlp_put(ndlp);
5029node_err:
5030 lpfc_els_free_iocb(phba, elsiocb);
5031 return 1;
dea31012005-04-17 16:05:31 -05005032}
5033
James Smarte59058c2008-08-24 21:49:00 -04005034/**
James Smart3621a712009-04-06 18:47:14 -04005035 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005036 * @vport: pointer to a virtual N_Port data structure.
5037 * @oldiocb: pointer to the original lpfc command iocb data structure.
5038 * @ndlp: pointer to a node-list data structure.
5039 *
5040 * This routine prepares and issues an Accept (ACC) response to Process
5041 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5042 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5043 *
5044 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5045 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5046 * will be stored into the context1 field of the IOCB for the completion
5047 * callback function to the PRLI Accept response ELS IOCB command.
5048 *
5049 * Return code
5050 * 0 - Successfully issued acc prli response
5051 * 1 - Failed to issue acc prli response
5052 **/
dea31012005-04-17 16:05:31 -05005053int
James Smart2e0fef82007-06-17 19:56:36 -05005054lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04005055 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005056{
James Smart2e0fef82007-06-17 19:56:36 -05005057 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005058 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08005059 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05005060 lpfc_vpd_t *vpd;
5061 IOCB_t *icmd;
5062 IOCB_t *oldcmd;
5063 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005064 uint8_t *pcmd;
5065 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08005066 uint32_t prli_fc4_req, *req_payload;
5067 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05005068 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08005069 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05005070
James Smarta0f2d3e2017-02-12 13:52:31 -08005071 /* Need the incoming PRLI payload to determine if the ACC is for an
5072 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5073 */
5074 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5075 req_payload = (((uint32_t *)req_buf->virt) + 1);
5076
5077 /* PRLI type payload is at byte 3 for FCP or NVME. */
5078 prli_fc4_req = be32_to_cpu(*req_payload);
5079 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5080 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5081 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5082 prli_fc4_req, *((uint32_t *)req_payload));
5083
5084 if (prli_fc4_req == PRLI_FCP_TYPE) {
5085 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5086 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5087 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5088 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5089 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5090 } else {
5091 return 1;
5092 }
5093
James Smart2e0fef82007-06-17 19:56:36 -05005094 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08005095 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005096 if (!elsiocb)
5097 return 1;
dea31012005-04-17 16:05:31 -05005098
dea31012005-04-17 16:05:31 -05005099 icmd = &elsiocb->iocb;
5100 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005101 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5102 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5103
James Smart5b8bd0c2007-04-25 09:52:49 -04005104 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005105 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5106 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5107 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5108 elsiocb->iotag, elsiocb->iocb.ulpContext,
5109 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5110 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005111 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08005112 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05005113
James Smartc07f10c2017-04-21 16:04:54 -07005114 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005115 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005116
5117 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05005118 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08005119
5120 if (prli_fc4_req == PRLI_FCP_TYPE) {
5121 /*
5122 * If the remote port is a target and our firmware version
5123 * is 3.20 or later, set the following bits for FC-TAPE
5124 * support.
5125 */
5126 npr = (PRLI *) pcmd;
5127 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5128 (vpd->rev.feaLevelHigh >= 0x02)) {
5129 npr->ConfmComplAllowed = 1;
5130 npr->Retry = 1;
5131 npr->TaskRetryIdReq = 1;
5132 }
5133 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5134 npr->estabImagePair = 1;
5135 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05005136 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08005137 npr->prliType = PRLI_FCP_TYPE;
5138 npr->initiatorFunc = 1;
5139 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5140 /* Respond with an NVME PRLI Type */
5141 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5142 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5143 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5144 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08005145 if (phba->nvmet_support) {
5146 bf_set(prli_tgt, npr_nvme, 1);
5147 bf_set(prli_disc, npr_nvme, 1);
5148 if (phba->cfg_nvme_enable_fb) {
5149 bf_set(prli_fba, npr_nvme, 1);
5150
5151 /* TBD. Target mode needs to post buffers
5152 * that support the configured first burst
5153 * byte size.
5154 */
5155 bf_set(prli_fb_sz, npr_nvme,
5156 phba->cfg_nvmet_fb_size);
5157 }
5158 } else {
5159 bf_set(prli_init, npr_nvme, 1);
5160 }
dea31012005-04-17 16:05:31 -05005161
James Smarta0f2d3e2017-02-12 13:52:31 -08005162 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5163 "6015 NVME issue PRLI ACC word1 x%08x "
5164 "word4 x%08x word5 x%08x flag x%x, "
5165 "fcp_info x%x nlp_type x%x\n",
5166 npr_nvme->word1, npr_nvme->word4,
5167 npr_nvme->word5, ndlp->nlp_flag,
5168 ndlp->nlp_fcp_info, ndlp->nlp_type);
5169 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5170 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5171 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5172 } else
5173 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5174 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5175 prli_fc4_req, ndlp->nlp_fc4_type,
5176 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05005177
James Smart858c9f62007-06-17 19:56:39 -05005178 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005179 "Issue ACC PRLI: did:x%x flg:x%x",
5180 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005181
dea31012005-04-17 16:05:31 -05005182 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005183 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005184 elsiocb->context1 = lpfc_nlp_get(ndlp);
5185 if (!elsiocb->context1)
5186 goto node_err;
dea31012005-04-17 16:05:31 -05005187
James Smart3772a992009-05-22 14:50:54 -04005188 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005189 if (rc == IOCB_ERROR)
5190 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005191 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005192
5193 io_err:
5194 lpfc_nlp_put(ndlp);
5195 node_err:
5196 lpfc_els_free_iocb(phba, elsiocb);
5197 return 1;
dea31012005-04-17 16:05:31 -05005198}
5199
James Smarte59058c2008-08-24 21:49:00 -04005200/**
James Smart3621a712009-04-06 18:47:14 -04005201 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005202 * @vport: pointer to a virtual N_Port data structure.
5203 * @format: rnid command format.
5204 * @oldiocb: pointer to the original lpfc command iocb data structure.
5205 * @ndlp: pointer to a node-list data structure.
5206 *
5207 * This routine issues a Request Node Identification Data (RNID) Accept
5208 * (ACC) response. It constructs the RNID ACC response command according to
5209 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5210 * issue the response. Note that this command does not need to hold the ndlp
5211 * reference count for the callback. So, the ndlp reference count taken by
5212 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5213 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5214 * there is no ndlp reference available.
5215 *
5216 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5217 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5218 * will be stored into the context1 field of the IOCB for the completion
5219 * callback function. However, for the RNID Accept Response ELS command,
5220 * this is undone later by this routine after the IOCB is allocated.
5221 *
5222 * Return code
5223 * 0 - Successfully issued acc rnid response
5224 * 1 - Failed to issue acc rnid response
5225 **/
dea31012005-04-17 16:05:31 -05005226static int
James Smart2e0fef82007-06-17 19:56:36 -05005227lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04005228 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005229{
James Smart2e0fef82007-06-17 19:56:36 -05005230 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005231 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05005232 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05005233 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005234 uint8_t *pcmd;
5235 uint16_t cmdsize;
5236 int rc;
5237
James Smart92d7f7b2007-06-17 19:56:38 -05005238 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5239 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005240 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05005241 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005242
James Smart2e0fef82007-06-17 19:56:36 -05005243 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5244 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005245 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005246 return 1;
dea31012005-04-17 16:05:31 -05005247
dea31012005-04-17 16:05:31 -05005248 icmd = &elsiocb->iocb;
5249 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005250 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5251 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5252
James Smart5b8bd0c2007-04-25 09:52:49 -04005253 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5255 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5256 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05005257 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05005258 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005259 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005260
James Smart92d7f7b2007-06-17 19:56:38 -05005261 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05005262 rn = (RNID *) (pcmd);
5263 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05005264 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5265 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5266 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005267 switch (format) {
5268 case 0:
5269 rn->SpecificLen = 0;
5270 break;
5271 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05005272 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005273 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005274 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005275 rn->un.topologyDisc.unitType = RNID_HBA;
5276 rn->un.topologyDisc.physPort = 0;
5277 rn->un.topologyDisc.attachedNodes = 0;
5278 break;
5279 default:
5280 rn->CommonLen = 0;
5281 rn->SpecificLen = 0;
5282 break;
5283 }
5284
James Smart858c9f62007-06-17 19:56:39 -05005285 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005286 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5287 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005288
dea31012005-04-17 16:05:31 -05005289 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005290 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005291 elsiocb->context1 = lpfc_nlp_get(ndlp);
5292 if (!elsiocb->context1)
5293 goto node_err;
dea31012005-04-17 16:05:31 -05005294
James Smart3772a992009-05-22 14:50:54 -04005295 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005296 if (rc == IOCB_ERROR)
5297 goto io_err;
5298
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005299 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005300
5301 io_err:
5302 lpfc_nlp_put(ndlp);
5303 node_err:
5304 lpfc_els_free_iocb(phba, elsiocb);
5305 return 1;
dea31012005-04-17 16:05:31 -05005306}
5307
James Smarte59058c2008-08-24 21:49:00 -04005308/**
James Smart19ca7602010-11-20 23:11:55 -05005309 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5310 * @vport: pointer to a virtual N_Port data structure.
5311 * @iocb: pointer to the lpfc command iocb data structure.
5312 * @ndlp: pointer to a node-list data structure.
5313 *
5314 * Return
5315 **/
5316static void
5317lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08005318 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05005319{
5320 struct lpfc_hba *phba = vport->phba;
5321 uint8_t *pcmd;
5322 struct RRQ *rrq;
5323 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05005324 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05005325 struct lpfc_node_rrq *prrq;
5326
5327
5328 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5329 pcmd += sizeof(uint32_t);
5330 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05005331 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04005332 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05005333
5334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5335 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5336 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05005337 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04005338 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05005339 rxid,
5340 iocb->iotag, iocb->iocb.ulpContext);
5341
5342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5343 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5344 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05005345 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04005346 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05005347 else
5348 xri = rxid;
5349 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05005350 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05005351 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05005352 return;
5353}
5354
5355/**
James Smart12265f62010-10-22 11:05:53 -04005356 * lpfc_els_rsp_echo_acc - Issue echo acc response
5357 * @vport: pointer to a virtual N_Port data structure.
5358 * @data: pointer to echo data to return in the accept.
5359 * @oldiocb: pointer to the original lpfc command iocb data structure.
5360 * @ndlp: pointer to a node-list data structure.
5361 *
5362 * Return code
5363 * 0 - Successfully issued acc echo response
5364 * 1 - Failed to issue acc echo response
5365 **/
5366static int
5367lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5368 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5369{
5370 struct lpfc_hba *phba = vport->phba;
5371 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04005372 uint8_t *pcmd;
5373 uint16_t cmdsize;
5374 int rc;
5375
James Smart12265f62010-10-22 11:05:53 -04005376 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5377
James Smartbf086112011-08-21 21:48:13 -04005378 /* The accumulated length can exceed the BPL_SIZE. For
5379 * now, use this as the limit
5380 */
5381 if (cmdsize > LPFC_BPL_SIZE)
5382 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04005383 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5384 ndlp->nlp_DID, ELS_CMD_ACC);
5385 if (!elsiocb)
5386 return 1;
5387
James Smart7851fe22011-07-22 18:36:52 -04005388 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5389 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5390
James Smart12265f62010-10-22 11:05:53 -04005391 /* Xmit ECHO ACC response tag <ulpIoTag> */
5392 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5393 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5394 elsiocb->iotag, elsiocb->iocb.ulpContext);
5395 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5396 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5397 pcmd += sizeof(uint32_t);
5398 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5399
5400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005401 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5402 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart12265f62010-10-22 11:05:53 -04005403
5404 phba->fc_stat.elsXmitACC++;
5405 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005406 elsiocb->context1 = lpfc_nlp_get(ndlp);
5407 if (!elsiocb->context1)
5408 goto node_err;
James Smart12265f62010-10-22 11:05:53 -04005409
5410 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005411 if (rc == IOCB_ERROR)
5412 goto io_err;
James Smart12265f62010-10-22 11:05:53 -04005413 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005414
5415 io_err:
5416 lpfc_nlp_put(ndlp);
5417 node_err:
5418 lpfc_els_free_iocb(phba, elsiocb);
5419 return 1;
James Smart12265f62010-10-22 11:05:53 -04005420}
5421
5422/**
James Smart3621a712009-04-06 18:47:14 -04005423 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04005424 * @vport: pointer to a host virtual N_Port data structure.
5425 *
5426 * This routine issues Address Discover (ADISC) ELS commands to those
5427 * N_Ports which are in node port recovery state and ADISC has not been issued
5428 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5429 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5430 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5431 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5432 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5433 * IOCBs quit for later pick up. On the other hand, after walking through
5434 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5435 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5436 * no more ADISC need to be sent.
5437 *
5438 * Return code
5439 * The number of N_Ports with adisc issued.
5440 **/
dea31012005-04-17 16:05:31 -05005441int
James Smart2e0fef82007-06-17 19:56:36 -05005442lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005443{
James Smart2e0fef82007-06-17 19:56:36 -05005444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005445 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005446 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05005447
James Smart685f0bf2007-04-25 09:53:08 -04005448 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05005449 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04005450 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5451 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5452 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smartc6adba12020-11-15 11:26:34 -08005453 spin_lock_irq(&ndlp->lock);
James Smart685f0bf2007-04-25 09:53:08 -04005454 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -08005455 spin_unlock_irq(&ndlp->lock);
James Smart685f0bf2007-04-25 09:53:08 -04005456 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005457 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5458 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005459 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05005460 vport->num_disc_nodes++;
5461 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04005462 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005463 spin_lock_irq(shost->host_lock);
5464 vport->fc_flag |= FC_NLP_MORE;
5465 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005466 break;
dea31012005-04-17 16:05:31 -05005467 }
5468 }
5469 }
5470 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05005471 spin_lock_irq(shost->host_lock);
5472 vport->fc_flag &= ~FC_NLP_MORE;
5473 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005474 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005475 return sentadisc;
dea31012005-04-17 16:05:31 -05005476}
5477
James Smarte59058c2008-08-24 21:49:00 -04005478/**
James Smart3621a712009-04-06 18:47:14 -04005479 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04005480 * @vport: pointer to a host virtual N_Port data structure.
5481 *
5482 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5483 * which are in node port recovery state, with a @vport. Each time an ELS
5484 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5485 * the per @vport number of discover count (num_disc_nodes) shall be
5486 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5487 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5488 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5489 * later pick up. On the other hand, after walking through all the ndlps with
5490 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5491 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5492 * PLOGI need to be sent.
5493 *
5494 * Return code
5495 * The number of N_Ports with plogi issued.
5496 **/
dea31012005-04-17 16:05:31 -05005497int
James Smart2e0fef82007-06-17 19:56:36 -05005498lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005499{
James Smart2e0fef82007-06-17 19:56:36 -05005500 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005501 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005502 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05005503
James Smart2e0fef82007-06-17 19:56:36 -05005504 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5505 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04005506 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04005507 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5508 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5509 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04005510 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005511 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5512 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005513 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05005514 vport->num_disc_nodes++;
5515 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04005516 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005517 spin_lock_irq(shost->host_lock);
5518 vport->fc_flag |= FC_NLP_MORE;
5519 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005520 break;
dea31012005-04-17 16:05:31 -05005521 }
5522 }
5523 }
James Smartb4b34172019-10-18 14:18:31 -07005524
5525 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5526 "6452 Discover PLOGI %d flag x%x\n",
5527 sentplogi, vport->fc_flag);
5528
James Smart87af33f2007-10-27 13:37:43 -04005529 if (sentplogi) {
5530 lpfc_set_disctmo(vport);
5531 }
5532 else {
James Smart2e0fef82007-06-17 19:56:36 -05005533 spin_lock_irq(shost->host_lock);
5534 vport->fc_flag &= ~FC_NLP_MORE;
5535 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005536 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005537 return sentplogi;
dea31012005-04-17 16:05:31 -05005538}
5539
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005540static uint32_t
James Smart86478872015-05-21 13:55:21 -04005541lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5542 uint32_t word0)
5543{
5544
5545 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5546 desc->payload.els_req = word0;
5547 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07005548
5549 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04005550}
5551
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005552static uint32_t
James Smart86478872015-05-21 13:55:21 -04005553lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5554 uint8_t *page_a0, uint8_t *page_a2)
5555{
5556 uint16_t wavelength;
5557 uint16_t temperature;
5558 uint16_t rx_power;
5559 uint16_t tx_bias;
5560 uint16_t tx_power;
5561 uint16_t vcc;
5562 uint16_t flag = 0;
5563 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5564 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5565
5566 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5567
5568 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5569 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5570 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5571 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5572
5573 if ((trasn_code_byte4->fc_sw_laser) ||
5574 (trasn_code_byte5->fc_sw_laser_sl) ||
5575 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5576 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5577 } else if (trasn_code_byte4->fc_lw_laser) {
5578 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5579 page_a0[SSF_WAVELENGTH_B0];
5580 if (wavelength == SFP_WAVELENGTH_LC1310)
5581 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5582 if (wavelength == SFP_WAVELENGTH_LL1550)
5583 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5584 }
5585 /* check if its SFP+ */
5586 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5587 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5588 << SFP_FLAG_CT_SHIFT;
5589
5590 /* check if its OPTICAL */
5591 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5592 SFP_FLAG_IS_OPTICAL_PORT : 0)
5593 << SFP_FLAG_IS_OPTICAL_SHIFT;
5594
5595 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5596 page_a2[SFF_TEMPERATURE_B0]);
5597 vcc = (page_a2[SFF_VCC_B1] << 8 |
5598 page_a2[SFF_VCC_B0]);
5599 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5600 page_a2[SFF_TXPOWER_B0]);
5601 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5602 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5603 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5604 page_a2[SFF_RXPOWER_B0]);
5605 desc->sfp_info.temperature = cpu_to_be16(temperature);
5606 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5607 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5608 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5609 desc->sfp_info.vcc = cpu_to_be16(vcc);
5610
5611 desc->sfp_info.flags = cpu_to_be16(flag);
5612 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005613
5614 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04005615}
5616
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005617static uint32_t
James Smart86478872015-05-21 13:55:21 -04005618lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5619 READ_LNK_VAR *stat)
5620{
5621 uint32_t type;
5622
5623 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5624
5625 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5626
5627 desc->info.port_type = cpu_to_be32(type);
5628
5629 desc->info.link_status.link_failure_cnt =
5630 cpu_to_be32(stat->linkFailureCnt);
5631 desc->info.link_status.loss_of_synch_cnt =
5632 cpu_to_be32(stat->lossSyncCnt);
5633 desc->info.link_status.loss_of_signal_cnt =
5634 cpu_to_be32(stat->lossSignalCnt);
5635 desc->info.link_status.primitive_seq_proto_err =
5636 cpu_to_be32(stat->primSeqErrCnt);
5637 desc->info.link_status.invalid_trans_word =
5638 cpu_to_be32(stat->invalidXmitWord);
5639 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5640
5641 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005642
5643 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04005644}
5645
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005646static uint32_t
James Smart56204982016-03-31 14:12:32 -07005647lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5648 struct lpfc_vport *vport)
5649{
James Smart3aaaa312016-07-06 12:35:57 -07005650 uint32_t bbCredit;
5651
James Smart56204982016-03-31 14:12:32 -07005652 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5653
James Smart3aaaa312016-07-06 12:35:57 -07005654 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5655 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5656 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5657 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5658 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5659 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5660 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5661 } else {
James Smart56204982016-03-31 14:12:32 -07005662 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07005663 }
James Smart56204982016-03-31 14:12:32 -07005664
5665 desc->bbc_info.rtt = 0;
5666 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005667
5668 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07005669}
5670
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005671static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005672lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5673 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07005674{
James Smart310429e2016-07-06 12:35:54 -07005675 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005676
5677 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5678
James Smart3aaaa312016-07-06 12:35:57 -07005679 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5680 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5681 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5682 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005683
5684 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5685 flags |= RDP_OET_HIGH_ALARM;
5686 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5687 flags |= RDP_OET_LOW_ALARM;
5688 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5689 flags |= RDP_OET_HIGH_WARNING;
5690 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5691 flags |= RDP_OET_LOW_WARNING;
5692
James Smart56204982016-03-31 14:12:32 -07005693 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5694 desc->oed_info.function_flags = cpu_to_be32(flags);
5695 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005696 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005697}
5698
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005699static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005700lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5701 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005702 uint8_t *page_a2)
5703{
James Smart310429e2016-07-06 12:35:54 -07005704 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005705
5706 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5707
James Smart3aaaa312016-07-06 12:35:57 -07005708 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5709 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5710 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5711 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005712
5713 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5714 flags |= RDP_OET_HIGH_ALARM;
5715 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5716 flags |= RDP_OET_LOW_ALARM;
5717 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5718 flags |= RDP_OET_HIGH_WARNING;
5719 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5720 flags |= RDP_OET_LOW_WARNING;
5721
James Smart56204982016-03-31 14:12:32 -07005722 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5723 desc->oed_info.function_flags = cpu_to_be32(flags);
5724 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005725 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005726}
5727
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005728static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005729lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5730 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005731 uint8_t *page_a2)
5732{
James Smart310429e2016-07-06 12:35:54 -07005733 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005734
5735 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5736
James Smart3aaaa312016-07-06 12:35:57 -07005737 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5738 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5739 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5740 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005741
5742 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5743 flags |= RDP_OET_HIGH_ALARM;
5744 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5745 flags |= RDP_OET_LOW_ALARM;
5746 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5747 flags |= RDP_OET_HIGH_WARNING;
5748 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5749 flags |= RDP_OET_LOW_WARNING;
5750
James Smart56204982016-03-31 14:12:32 -07005751 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5752 desc->oed_info.function_flags = cpu_to_be32(flags);
5753 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005754 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005755}
5756
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005757static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005758lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5759 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005760 uint8_t *page_a2)
5761{
James Smart310429e2016-07-06 12:35:54 -07005762 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005763
5764 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5765
James Smart3aaaa312016-07-06 12:35:57 -07005766 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5767 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5768 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5769 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005770
5771 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5772 flags |= RDP_OET_HIGH_ALARM;
5773 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5774 flags |= RDP_OET_LOW_ALARM;
5775 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5776 flags |= RDP_OET_HIGH_WARNING;
5777 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5778 flags |= RDP_OET_LOW_WARNING;
5779
James Smart56204982016-03-31 14:12:32 -07005780 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5781 desc->oed_info.function_flags = cpu_to_be32(flags);
5782 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005783 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005784}
5785
5786
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005787static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005788lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5789 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005790 uint8_t *page_a2)
5791{
James Smart310429e2016-07-06 12:35:54 -07005792 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005793
5794 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5795
James Smart3aaaa312016-07-06 12:35:57 -07005796 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5797 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5798 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5799 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005800
5801 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5802 flags |= RDP_OET_HIGH_ALARM;
5803 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5804 flags |= RDP_OET_LOW_ALARM;
5805 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5806 flags |= RDP_OET_HIGH_WARNING;
5807 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5808 flags |= RDP_OET_LOW_WARNING;
5809
James Smart56204982016-03-31 14:12:32 -07005810 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5811 desc->oed_info.function_flags = cpu_to_be32(flags);
5812 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005813 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005814}
5815
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005816static uint32_t
James Smart56204982016-03-31 14:12:32 -07005817lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5818 uint8_t *page_a0, struct lpfc_vport *vport)
5819{
5820 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5821 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5822 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5823 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005824 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005825 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5826 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005827 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005828}
5829
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005830static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005831lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5832{
5833 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5834 return 0;
5835 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5836
5837 desc->info.CorrectedBlocks =
5838 cpu_to_be32(stat->fecCorrBlkCount);
5839 desc->info.UncorrectableBlocks =
5840 cpu_to_be32(stat->fecUncorrBlkCount);
5841
5842 desc->length = cpu_to_be32(sizeof(desc->info));
5843
5844 return sizeof(struct fc_fec_rdp_desc);
5845}
5846
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005847static uint32_t
James Smart86478872015-05-21 13:55:21 -04005848lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5849{
5850 uint16_t rdp_cap = 0;
5851 uint16_t rdp_speed;
5852
5853 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5854
James Smart81e75172015-12-16 18:11:59 -05005855 switch (phba->fc_linkspeed) {
5856 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005857 rdp_speed = RDP_PS_1GB;
5858 break;
James Smart81e75172015-12-16 18:11:59 -05005859 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005860 rdp_speed = RDP_PS_2GB;
5861 break;
James Smart81e75172015-12-16 18:11:59 -05005862 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005863 rdp_speed = RDP_PS_4GB;
5864 break;
James Smart81e75172015-12-16 18:11:59 -05005865 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005866 rdp_speed = RDP_PS_8GB;
5867 break;
James Smart81e75172015-12-16 18:11:59 -05005868 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005869 rdp_speed = RDP_PS_10GB;
5870 break;
James Smart81e75172015-12-16 18:11:59 -05005871 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005872 rdp_speed = RDP_PS_16GB;
5873 break;
James Smarta085e872015-12-16 18:12:02 -05005874 case LPFC_LINK_SPEED_32GHZ:
5875 rdp_speed = RDP_PS_32GB;
5876 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005877 case LPFC_LINK_SPEED_64GHZ:
5878 rdp_speed = RDP_PS_64GB;
5879 break;
James Smart86478872015-05-21 13:55:21 -04005880 default:
5881 rdp_speed = RDP_PS_UNKNOWN;
5882 break;
5883 }
5884
5885 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5886
James Smart1dc5ec22018-10-23 13:41:11 -07005887 if (phba->lmt & LMT_128Gb)
5888 rdp_cap |= RDP_PS_128GB;
James Smartfbd8a6b2018-02-22 08:18:45 -08005889 if (phba->lmt & LMT_64Gb)
5890 rdp_cap |= RDP_PS_64GB;
James Smartd38dd522015-08-31 16:48:17 -04005891 if (phba->lmt & LMT_32Gb)
5892 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005893 if (phba->lmt & LMT_16Gb)
5894 rdp_cap |= RDP_PS_16GB;
5895 if (phba->lmt & LMT_10Gb)
5896 rdp_cap |= RDP_PS_10GB;
5897 if (phba->lmt & LMT_8Gb)
5898 rdp_cap |= RDP_PS_8GB;
5899 if (phba->lmt & LMT_4Gb)
5900 rdp_cap |= RDP_PS_4GB;
5901 if (phba->lmt & LMT_2Gb)
5902 rdp_cap |= RDP_PS_2GB;
5903 if (phba->lmt & LMT_1Gb)
5904 rdp_cap |= RDP_PS_1GB;
5905
5906 if (rdp_cap == 0)
5907 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005908 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5909 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005910
5911 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5912 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005913 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005914}
5915
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005916static uint32_t
James Smart86478872015-05-21 13:55:21 -04005917lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005918 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005919{
5920
5921 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5922
James Smartcd46cde2017-03-04 09:30:37 -08005923 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005924 sizeof(desc->port_names.wwnn));
5925
James Smartcd46cde2017-03-04 09:30:37 -08005926 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005927 sizeof(desc->port_names.wwpn));
5928
5929 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005930 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005931}
5932
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005933static uint32_t
James Smart86478872015-05-21 13:55:21 -04005934lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5935 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5936{
5937
5938 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5939 if (vport->fc_flag & FC_FABRIC) {
5940 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005941 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005942
5943 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
James Smartd9f492a2019-08-14 16:57:04 -07005944 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005945 } else { /* Point to Point */
5946 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005947 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005948
James Smartd9f492a2019-08-14 16:57:04 -07005949 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5950 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005951 }
5952
5953 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005954 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005955}
5956
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005957static void
James Smart86478872015-05-21 13:55:21 -04005958lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5959 int status)
5960{
5961 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5962 struct lpfc_vport *vport = ndlp->vport;
5963 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005964 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005965 IOCB_t *icmd;
5966 uint8_t *pcmd;
5967 struct ls_rjt *stat;
5968 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005969 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005970 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005971 int rc;
James Smart86478872015-05-21 13:55:21 -04005972
5973 if (status != SUCCESS)
5974 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005975
5976 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005977 cmdsize = sizeof(struct fc_rdp_res_frame);
5978
5979 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5980 lpfc_max_els_tries, rdp_context->ndlp,
5981 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
James Smart86478872015-05-21 13:55:21 -04005982 if (!elsiocb)
5983 goto free_rdp_context;
5984
5985 icmd = &elsiocb->iocb;
5986 icmd->ulpContext = rdp_context->rx_id;
5987 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5988
5989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5990 "2171 Xmit RDP response tag x%x xri x%x, "
5991 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5992 elsiocb->iotag, elsiocb->iocb.ulpContext,
5993 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5994 ndlp->nlp_rpi);
5995 rdp_res = (struct fc_rdp_res_frame *)
5996 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5997 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5998 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5999 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6000
James Smart310429e2016-07-06 12:35:54 -07006001 /* Update Alarm and Warning */
6002 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6003 phba->sfp_alarm |= *flag_ptr;
6004 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6005 phba->sfp_warning |= *flag_ptr;
6006
James Smart86478872015-05-21 13:55:21 -04006007 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07006008 len = 8;
6009 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6010 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04006011
James Smart6c92d1d2016-07-06 12:35:55 -07006012 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04006013 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07006014 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6015 phba);
6016 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6017 (len + pcmd), &rdp_context->link_stat);
6018 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08006019 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07006020 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6021 (len + pcmd), vport, ndlp);
6022 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05006023 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07006024 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6025 &rdp_context->link_stat, vport);
6026 len += lpfc_rdp_res_oed_temp_desc(phba,
6027 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6028 rdp_context->page_a2);
6029 len += lpfc_rdp_res_oed_voltage_desc(phba,
6030 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6031 rdp_context->page_a2);
6032 len += lpfc_rdp_res_oed_txbias_desc(phba,
6033 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6034 rdp_context->page_a2);
6035 len += lpfc_rdp_res_oed_txpower_desc(phba,
6036 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6037 rdp_context->page_a2);
6038 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6039 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6040 rdp_context->page_a2);
6041 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6042 rdp_context->page_a0, vport);
6043
James Smart6c92d1d2016-07-06 12:35:55 -07006044 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04006045 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6046
James Smarteb8d68c2015-12-16 18:12:00 -05006047 /* Now that we know the true size of the payload, update the BPL */
6048 bpl = (struct ulp_bde64 *)
6049 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07006050 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05006051 bpl->tus.f.bdeFlags = 0;
6052 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6053
James Smart86478872015-05-21 13:55:21 -04006054 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08006055 elsiocb->context1 = lpfc_nlp_get(ndlp);
6056 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006057 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006058 goto free_rdp_context;
6059 }
James Smart86478872015-05-21 13:55:21 -04006060
James Smart4430f7f2020-11-15 11:26:31 -08006061 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6062 if (rc == IOCB_ERROR) {
6063 lpfc_nlp_put(ndlp);
6064 lpfc_els_free_iocb(phba, elsiocb);
6065 }
James Smart86478872015-05-21 13:55:21 -04006066
James Smart4430f7f2020-11-15 11:26:31 -08006067 goto free_rdp_context;
6068
James Smart86478872015-05-21 13:55:21 -04006069error:
6070 cmdsize = 2 * sizeof(uint32_t);
6071 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6072 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart86478872015-05-21 13:55:21 -04006073 if (!elsiocb)
6074 goto free_rdp_context;
6075
6076 icmd = &elsiocb->iocb;
6077 icmd->ulpContext = rdp_context->rx_id;
6078 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6079 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6080
6081 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6082 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6083 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6084
6085 phba->fc_stat.elsXmitLSRJT++;
6086 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08006087 elsiocb->context1 = lpfc_nlp_get(ndlp);
6088 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006089 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006090 goto free_rdp_context;
6091 }
6092
6093 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6094 if (rc == IOCB_ERROR) {
6095 lpfc_nlp_put(ndlp);
6096 lpfc_els_free_iocb(phba, elsiocb);
6097 }
6098
James Smart86478872015-05-21 13:55:21 -04006099free_rdp_context:
James Smart4430f7f2020-11-15 11:26:31 -08006100 /* This reference put is for the original unsolicited RDP. If the
6101 * iocb prep failed, there is no reference to remove.
6102 */
6103 lpfc_nlp_put(ndlp);
James Smart86478872015-05-21 13:55:21 -04006104 kfree(rdp_context);
6105}
6106
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006107static int
James Smart86478872015-05-21 13:55:21 -04006108lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6109{
6110 LPFC_MBOXQ_t *mbox = NULL;
6111 int rc;
6112
6113 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6114 if (!mbox) {
6115 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6116 "7105 failed to allocate mailbox memory");
6117 return 1;
6118 }
6119
6120 if (lpfc_sli4_dump_page_a0(phba, mbox))
6121 goto prep_mbox_fail;
6122 mbox->vport = rdp_context->ndlp->vport;
6123 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
James Smart3e1f0712018-11-29 16:09:29 -08006124 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04006125 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6126 if (rc == MBX_NOT_FINISHED)
6127 goto issue_mbox_fail;
6128
6129 return 0;
6130
6131prep_mbox_fail:
6132issue_mbox_fail:
6133 mempool_free(mbox, phba->mbox_mem_pool);
6134 return 1;
6135}
6136
6137/*
6138 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6139 * @vport: pointer to a host virtual N_Port data structure.
6140 * @cmdiocb: pointer to lpfc command iocb data structure.
6141 * @ndlp: pointer to a node-list data structure.
6142 *
6143 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6144 * IOCB. First, the payload of the unsolicited RDP is checked.
6145 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6146 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6147 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6148 * gather all data and send RDP response.
6149 *
6150 * Return code
6151 * 0 - Sent the acc response
6152 * 1 - Sent the reject response.
6153 */
6154static int
6155lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6156 struct lpfc_nodelist *ndlp)
6157{
6158 struct lpfc_hba *phba = vport->phba;
6159 struct lpfc_dmabuf *pcmd;
6160 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6161 struct fc_rdp_req_frame *rdp_req;
6162 struct lpfc_rdp_context *rdp_context;
6163 IOCB_t *cmd = NULL;
6164 struct ls_rjt stat;
6165
6166 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smart719162b2018-12-10 19:37:01 -08006167 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smarta0f2d3e2017-02-12 13:52:31 -08006168 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04006169 rjt_err = LSRJT_UNABLE_TPC;
6170 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6171 goto error;
6172 }
6173
6174 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6175 rjt_err = LSRJT_UNABLE_TPC;
6176 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6177 goto error;
6178 }
6179
6180 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6181 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6182
James Smart86478872015-05-21 13:55:21 -04006183 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6184 "2422 ELS RDP Request "
6185 "dec len %d tag x%x port_id %d len %d\n",
6186 be32_to_cpu(rdp_req->rdp_des_length),
6187 be32_to_cpu(rdp_req->nport_id_desc.tag),
6188 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6189 be32_to_cpu(rdp_req->nport_id_desc.length));
6190
6191 if (sizeof(struct fc_rdp_nport_desc) !=
6192 be32_to_cpu(rdp_req->rdp_des_length))
6193 goto rjt_logerr;
6194 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6195 goto rjt_logerr;
6196 if (RDP_NPORT_ID_SIZE !=
6197 be32_to_cpu(rdp_req->nport_id_desc.length))
6198 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05006199 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04006200 if (!rdp_context) {
6201 rjt_err = LSRJT_UNABLE_TPC;
6202 goto error;
6203 }
6204
James Smart86478872015-05-21 13:55:21 -04006205 cmd = &cmdiocb->iocb;
6206 rdp_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006207 if (!rdp_context->ndlp) {
6208 kfree(rdp_context);
6209 rjt_err = LSRJT_UNABLE_TPC;
6210 goto error;
6211 }
James Smart86478872015-05-21 13:55:21 -04006212 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6213 rdp_context->rx_id = cmd->ulpContext;
6214 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6215 if (lpfc_get_rdp_info(phba, rdp_context)) {
6216 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6217 "2423 Unable to send mailbox");
6218 kfree(rdp_context);
6219 rjt_err = LSRJT_UNABLE_TPC;
6220 lpfc_nlp_put(ndlp);
6221 goto error;
6222 }
6223
6224 return 0;
6225
6226rjt_logerr:
6227 rjt_err = LSRJT_LOGICAL_ERR;
6228
6229error:
6230 memset(&stat, 0, sizeof(stat));
6231 stat.un.b.lsRjtRsnCode = rjt_err;
6232 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6233 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6234 return 1;
6235}
6236
6237
James Smart8b017a32015-05-21 13:55:18 -04006238static void
6239lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6240{
6241 MAILBOX_t *mb;
6242 IOCB_t *icmd;
6243 uint8_t *pcmd;
6244 struct lpfc_iocbq *elsiocb;
6245 struct lpfc_nodelist *ndlp;
6246 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04006247 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04006248 struct lpfc_lcb_context *lcb_context;
6249 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04006250 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04006251 int rc;
6252
6253 mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006254 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
James Smart8b017a32015-05-21 13:55:18 -04006255 ndlp = lcb_context->ndlp;
James Smart3e1f0712018-11-29 16:09:29 -08006256 pmb->ctx_ndlp = NULL;
6257 pmb->ctx_buf = NULL;
James Smart8b017a32015-05-21 13:55:18 -04006258
James Smart481ad962015-05-22 10:42:35 -04006259 shdr = (union lpfc_sli4_cfg_shdr *)
6260 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6261 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6262 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6263
6264 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6265 "0194 SET_BEACON_CONFIG mailbox "
6266 "completed with status x%x add_status x%x,"
6267 " mbx status x%x\n",
6268 shdr_status, shdr_add_status, mb->mbxStatus);
6269
James Smart66e9e6b2018-06-26 08:24:27 -07006270 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6271 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6272 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
James Smart8b017a32015-05-21 13:55:18 -04006273 mempool_free(pmb, phba->mbox_mem_pool);
6274 goto error;
6275 }
6276
6277 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04006278 cmdsize = sizeof(struct fc_lcb_res_frame);
6279 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6280 lpfc_max_els_tries, ndlp,
6281 ndlp->nlp_DID, ELS_CMD_ACC);
6282
6283 /* Decrement the ndlp reference count from previous mbox command */
6284 lpfc_nlp_put(ndlp);
6285
6286 if (!elsiocb)
6287 goto free_lcb_context;
6288
6289 lcb_res = (struct fc_lcb_res_frame *)
6290 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6291
James Smart24bc3112018-07-31 17:23:23 -07006292 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
James Smart8b017a32015-05-21 13:55:18 -04006293 icmd = &elsiocb->iocb;
6294 icmd->ulpContext = lcb_context->rx_id;
6295 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6296
6297 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6298 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6299 lcb_res->lcb_sub_command = lcb_context->sub_command;
6300 lcb_res->lcb_type = lcb_context->type;
James Smart24bc3112018-07-31 17:23:23 -07006301 lcb_res->capability = lcb_context->capability;
James Smart8b017a32015-05-21 13:55:18 -04006302 lcb_res->lcb_frequency = lcb_context->frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006303 lcb_res->lcb_duration = lcb_context->duration;
James Smart8b017a32015-05-21 13:55:18 -04006304 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6305 phba->fc_stat.elsXmitACC++;
James Smart8b017a32015-05-21 13:55:18 -04006306
James Smart4430f7f2020-11-15 11:26:31 -08006307 elsiocb->context1 = lpfc_nlp_get(ndlp);
6308 if (!elsiocb->context1)
6309 goto node_err;
6310
6311 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6312 if (!rc)
6313 goto out;
6314
6315 lpfc_nlp_put(ndlp);
6316 node_err:
6317 lpfc_els_free_iocb(phba, elsiocb);
6318 out:
James Smart8b017a32015-05-21 13:55:18 -04006319 kfree(lcb_context);
6320 return;
6321
6322error:
6323 cmdsize = sizeof(struct fc_lcb_res_frame);
6324 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6325 lpfc_max_els_tries, ndlp,
6326 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6327 lpfc_nlp_put(ndlp);
6328 if (!elsiocb)
6329 goto free_lcb_context;
6330
6331 icmd = &elsiocb->iocb;
6332 icmd->ulpContext = lcb_context->rx_id;
6333 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6334 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6335
6336 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6337 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6338 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6339
James Smartb114d902018-10-23 13:41:07 -07006340 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6341 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6342
James Smart8b017a32015-05-21 13:55:18 -04006343 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6344 phba->fc_stat.elsXmitLSRJT++;
James Smart4430f7f2020-11-15 11:26:31 -08006345 elsiocb->context1 = lpfc_nlp_get(ndlp);
6346 if (!elsiocb->context1) {
James Smart8b017a32015-05-21 13:55:18 -04006347 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006348 goto free_lcb_context;
6349 }
6350
6351 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6352 if (rc == IOCB_ERROR) {
6353 lpfc_nlp_put(ndlp);
6354 lpfc_els_free_iocb(phba, elsiocb);
6355 }
James Smart8b017a32015-05-21 13:55:18 -04006356free_lcb_context:
6357 kfree(lcb_context);
6358}
6359
6360static int
6361lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6362 struct lpfc_lcb_context *lcb_context,
6363 uint32_t beacon_state)
6364{
6365 struct lpfc_hba *phba = vport->phba;
James Smart66e9e6b2018-06-26 08:24:27 -07006366 union lpfc_sli4_cfg_shdr *cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006367 LPFC_MBOXQ_t *mbox = NULL;
6368 uint32_t len;
6369 int rc;
6370
6371 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6372 if (!mbox)
6373 return 1;
6374
James Smart66e9e6b2018-06-26 08:24:27 -07006375 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006376 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6377 sizeof(struct lpfc_sli4_cfg_mhdr);
6378 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6379 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6380 LPFC_SLI4_MBX_EMBED);
James Smart3e1f0712018-11-29 16:09:29 -08006381 mbox->ctx_ndlp = (void *)lcb_context;
James Smart8b017a32015-05-21 13:55:18 -04006382 mbox->vport = phba->pport;
6383 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6384 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6385 phba->sli4_hba.physical_port);
6386 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6387 beacon_state);
James Smart66e9e6b2018-06-26 08:24:27 -07006388 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6389
6390 /*
6391 * Check bv1s bit before issuing the mailbox
6392 * if bv1s == 1, LCB V1 supported
6393 * else, LCB V0 supported
6394 */
6395
6396 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6397 /* COMMON_SET_BEACON_CONFIG_V1 */
6398 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6399 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6400 bf_set(lpfc_mbx_set_beacon_port_type,
6401 &mbox->u.mqe.un.beacon_config, 0);
6402 bf_set(lpfc_mbx_set_beacon_duration_v1,
6403 &mbox->u.mqe.un.beacon_config,
6404 be16_to_cpu(lcb_context->duration));
6405 } else {
6406 /* COMMON_SET_BEACON_CONFIG_V0 */
6407 if (be16_to_cpu(lcb_context->duration) != 0) {
6408 mempool_free(mbox, phba->mbox_mem_pool);
6409 return 1;
6410 }
6411 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6412 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6413 bf_set(lpfc_mbx_set_beacon_state,
6414 &mbox->u.mqe.un.beacon_config, beacon_state);
6415 bf_set(lpfc_mbx_set_beacon_port_type,
6416 &mbox->u.mqe.un.beacon_config, 1);
6417 bf_set(lpfc_mbx_set_beacon_duration,
6418 &mbox->u.mqe.un.beacon_config,
6419 be16_to_cpu(lcb_context->duration));
6420 }
6421
James Smart8b017a32015-05-21 13:55:18 -04006422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6423 if (rc == MBX_NOT_FINISHED) {
6424 mempool_free(mbox, phba->mbox_mem_pool);
6425 return 1;
6426 }
6427
6428 return 0;
6429}
6430
6431
6432/**
6433 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6434 * @vport: pointer to a host virtual N_Port data structure.
6435 * @cmdiocb: pointer to lpfc command iocb data structure.
6436 * @ndlp: pointer to a node-list data structure.
6437 *
6438 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6439 * First, the payload of the unsolicited LCB is checked.
6440 * Then based on Subcommand beacon will either turn on or off.
6441 *
6442 * Return code
6443 * 0 - Sent the acc response
6444 * 1 - Sent the reject response.
6445 **/
6446static int
6447lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6448 struct lpfc_nodelist *ndlp)
6449{
6450 struct lpfc_hba *phba = vport->phba;
6451 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04006452 uint8_t *lp;
6453 struct fc_lcb_request_frame *beacon;
6454 struct lpfc_lcb_context *lcb_context;
James Smart4430f7f2020-11-15 11:26:31 -08006455 u8 state, rjt_err = 0;
James Smart8b017a32015-05-21 13:55:18 -04006456 struct ls_rjt stat;
6457
James Smart8b017a32015-05-21 13:55:18 -04006458 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6459 lp = (uint8_t *)pcmd->virt;
6460 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6461
6462 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6463 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6464 "type x%x frequency %x duration x%x\n",
6465 lp[0], lp[1], lp[2],
6466 beacon->lcb_command,
6467 beacon->lcb_sub_command,
6468 beacon->lcb_type,
6469 beacon->lcb_frequency,
6470 be16_to_cpu(beacon->lcb_duration));
6471
James Smartd6564e52017-06-15 22:56:50 -07006472 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6473 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04006474 rjt_err = LSRJT_CMD_UNSUPPORTED;
6475 goto rjt;
6476 }
James Smart66e9e6b2018-06-26 08:24:27 -07006477
6478 if (phba->sli_rev < LPFC_SLI_REV4 ||
6479 phba->hba_flag & HBA_FCOE_MODE ||
6480 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6481 LPFC_SLI_INTF_IF_TYPE_2)) {
James Smart8b017a32015-05-21 13:55:18 -04006482 rjt_err = LSRJT_CMD_UNSUPPORTED;
6483 goto rjt;
6484 }
6485
Sudip Mukherjeee7950422015-09-23 19:02:32 +05306486 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6487 if (!lcb_context) {
6488 rjt_err = LSRJT_UNABLE_TPC;
6489 goto rjt;
6490 }
6491
James Smart8b017a32015-05-21 13:55:18 -04006492 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6493 lcb_context->sub_command = beacon->lcb_sub_command;
James Smart66e9e6b2018-06-26 08:24:27 -07006494 lcb_context->capability = 0;
James Smart8b017a32015-05-21 13:55:18 -04006495 lcb_context->type = beacon->lcb_type;
6496 lcb_context->frequency = beacon->lcb_frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006497 lcb_context->duration = beacon->lcb_duration;
James Smart8b017a32015-05-21 13:55:18 -04006498 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6499 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6500 lcb_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006501 if (!lcb_context->ndlp) {
6502 rjt_err = LSRJT_UNABLE_TPC;
Colin Ian King14c1dd92020-11-18 14:13:14 +00006503 goto rjt_free;
James Smart4430f7f2020-11-15 11:26:31 -08006504 }
6505
James Smart8b017a32015-05-21 13:55:18 -04006506 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006507 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6508 "0193 failed to send mail box");
James Smart8b017a32015-05-21 13:55:18 -04006509 lpfc_nlp_put(ndlp);
6510 rjt_err = LSRJT_UNABLE_TPC;
Colin Ian King14c1dd92020-11-18 14:13:14 +00006511 goto rjt_free;
James Smart8b017a32015-05-21 13:55:18 -04006512 }
6513 return 0;
Colin Ian King14c1dd92020-11-18 14:13:14 +00006514
6515rjt_free:
6516 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04006517rjt:
6518 memset(&stat, 0, sizeof(stat));
6519 stat.un.b.lsRjtRsnCode = rjt_err;
6520 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6521 return 1;
6522}
6523
6524
James Smarte59058c2008-08-24 21:49:00 -04006525/**
James Smart3621a712009-04-06 18:47:14 -04006526 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04006527 * @vport: pointer to a host virtual N_Port data structure.
6528 *
6529 * This routine cleans up any Registration State Change Notification
6530 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6531 * @vport together with the host_lock is used to prevent multiple thread
6532 * trying to access the RSCN array on a same @vport at the same time.
6533 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006534void
James Smart2e0fef82007-06-17 19:56:36 -05006535lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006536{
James Smart2e0fef82007-06-17 19:56:36 -05006537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6538 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006539 int i;
6540
James Smart7f5f3d02008-02-08 18:50:14 -05006541 spin_lock_irq(shost->host_lock);
6542 if (vport->fc_rscn_flush) {
6543 /* Another thread is walking fc_rscn_id_list on this vport */
6544 spin_unlock_irq(shost->host_lock);
6545 return;
6546 }
6547 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6548 vport->fc_rscn_flush = 1;
6549 spin_unlock_irq(shost->host_lock);
6550
James Smart2e0fef82007-06-17 19:56:36 -05006551 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006552 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05006553 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05006554 }
James Smart2e0fef82007-06-17 19:56:36 -05006555 spin_lock_irq(shost->host_lock);
6556 vport->fc_rscn_id_cnt = 0;
6557 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6558 spin_unlock_irq(shost->host_lock);
6559 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006560 /* Indicate we are done walking this fc_rscn_id_list */
6561 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006562}
6563
James Smarte59058c2008-08-24 21:49:00 -04006564/**
James Smart3621a712009-04-06 18:47:14 -04006565 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04006566 * @vport: pointer to a host virtual N_Port data structure.
6567 * @did: remote destination port identifier.
6568 *
6569 * This routine checks whether there is any pending Registration State
6570 * Configuration Notification (RSCN) to a @did on @vport.
6571 *
6572 * Return code
6573 * None zero - The @did matched with a pending rscn
6574 * 0 - not able to match @did with a pending rscn
6575 **/
dea31012005-04-17 16:05:31 -05006576int
James Smart2e0fef82007-06-17 19:56:36 -05006577lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006578{
6579 D_ID ns_did;
6580 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05006581 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05006582 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05006583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006584
6585 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05006586
6587 /* Never match fabric nodes for RSCNs */
6588 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05006589 return 0;
dea31012005-04-17 16:05:31 -05006590
6591 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05006592 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006593 return did;
dea31012005-04-17 16:05:31 -05006594
James Smart7f5f3d02008-02-08 18:50:14 -05006595 spin_lock_irq(shost->host_lock);
6596 if (vport->fc_rscn_flush) {
6597 /* Another thread is walking fc_rscn_id_list on this vport */
6598 spin_unlock_irq(shost->host_lock);
6599 return 0;
6600 }
6601 /* Indicate we are walking fc_rscn_id_list on this vport */
6602 vport->fc_rscn_flush = 1;
6603 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05006604 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006605 lp = vport->fc_rscn_id_list[i]->virt;
6606 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6607 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006608 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05006609 rscn_did.un.word = be32_to_cpu(*lp++);
6610 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05006611 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6612 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04006613 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6614 && (ns_did.un.b.area == rscn_did.un.b.area)
6615 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05006616 goto return_did_out;
dea31012005-04-17 16:05:31 -05006617 break;
James Smarteaf15d52008-12-04 22:39:29 -05006618 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05006619 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6620 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05006621 goto return_did_out;
dea31012005-04-17 16:05:31 -05006622 break;
James Smarteaf15d52008-12-04 22:39:29 -05006623 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05006624 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05006625 goto return_did_out;
dea31012005-04-17 16:05:31 -05006626 break;
James Smarteaf15d52008-12-04 22:39:29 -05006627 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05006628 goto return_did_out;
dea31012005-04-17 16:05:31 -05006629 }
6630 }
James Smart92d7f7b2007-06-17 19:56:38 -05006631 }
James Smart7f5f3d02008-02-08 18:50:14 -05006632 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6633 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006634 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05006635return_did_out:
6636 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6637 vport->fc_rscn_flush = 0;
6638 return did;
dea31012005-04-17 16:05:31 -05006639}
6640
James Smarte59058c2008-08-24 21:49:00 -04006641/**
James Smart3621a712009-04-06 18:47:14 -04006642 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04006643 * @vport: pointer to a host virtual N_Port data structure.
6644 *
6645 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6646 * state machine for a @vport's nodes that are with pending RSCN (Registration
6647 * State Change Notification).
6648 *
6649 * Return code
6650 * 0 - Successful (currently alway return 0)
6651 **/
dea31012005-04-17 16:05:31 -05006652static int
James Smart2e0fef82007-06-17 19:56:36 -05006653lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006654{
James Smart685f0bf2007-04-25 09:53:08 -04006655 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05006656
James Smart0d2b6b82008-06-14 22:52:47 -04006657 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05006658 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08006659 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
James Smart0d2b6b82008-06-14 22:52:47 -04006660 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05006661 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006662
6663 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08006664 if (vport->phba->nvmet_support)
6665 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006666
James Smartdea16bd2018-11-29 16:09:30 -08006667 /* If we are in the process of doing discovery on this
6668 * NPort, let it continue on its own.
6669 */
6670 switch (ndlp->nlp_state) {
6671 case NLP_STE_PLOGI_ISSUE:
6672 case NLP_STE_ADISC_ISSUE:
6673 case NLP_STE_REG_LOGIN_ISSUE:
6674 case NLP_STE_PRLI_ISSUE:
6675 case NLP_STE_LOGO_ISSUE:
6676 continue;
6677 }
6678
James Smarta6d10f22019-08-14 16:56:50 -07006679 /* Check to see if we need to NVME rescan this target
6680 * remoteport.
6681 */
6682 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6683 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006684 lpfc_nvme_rescan_port(vport, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08006685
James Smart2e0fef82007-06-17 19:56:36 -05006686 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04006687 NLP_EVT_DEVICE_RECOVERY);
6688 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05006689 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006690 return 0;
dea31012005-04-17 16:05:31 -05006691}
6692
James Smarte59058c2008-08-24 21:49:00 -04006693/**
James Smart3621a712009-04-06 18:47:14 -04006694 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05006695 * @vport: pointer to a host virtual N_Port data structure.
6696 * @cmdiocb: pointer to lpfc command iocb data structure.
6697 *
6698 * lpfc_send_rscn_event sends an RSCN netlink event to management
6699 * applications.
6700 */
6701static void
6702lpfc_send_rscn_event(struct lpfc_vport *vport,
6703 struct lpfc_iocbq *cmdiocb)
6704{
6705 struct lpfc_dmabuf *pcmd;
6706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6707 uint32_t *payload_ptr;
6708 uint32_t payload_len;
6709 struct lpfc_rscn_event_header *rscn_event_data;
6710
6711 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6712 payload_ptr = (uint32_t *) pcmd->virt;
6713 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6714
6715 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6716 payload_len, GFP_KERNEL);
6717 if (!rscn_event_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006718 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05006719 "0147 Failed to allocate memory for RSCN event\n");
6720 return;
6721 }
6722 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6723 rscn_event_data->payload_length = payload_len;
6724 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6725 payload_len);
6726
6727 fc_host_post_vendor_event(shost,
6728 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04006729 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05006730 (char *)rscn_event_data,
6731 LPFC_NL_VENDOR_ID);
6732
6733 kfree(rscn_event_data);
6734}
6735
6736/**
James Smart3621a712009-04-06 18:47:14 -04006737 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04006738 * @vport: pointer to a host virtual N_Port data structure.
6739 * @cmdiocb: pointer to lpfc command iocb data structure.
6740 * @ndlp: pointer to a node-list data structure.
6741 *
6742 * This routine processes an unsolicited RSCN (Registration State Change
6743 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6744 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6745 * discover state machine is about to begin discovery, it just accepts the
6746 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6747 * contains N_Port IDs for other vports on this HBA, it just accepts the
6748 * RSCN and ignore processing it. If the state machine is in the recovery
6749 * state, the fc_rscn_id_list of this @vport is walked and the
6750 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6751 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6752 * routine is invoked to handle the RSCN event.
6753 *
6754 * Return code
6755 * 0 - Just sent the acc response
6756 * 1 - Sent the acc response and waited for name server completion
6757 **/
dea31012005-04-17 16:05:31 -05006758static int
James Smart2e0fef82007-06-17 19:56:36 -05006759lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006760 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006761{
James Smart2e0fef82007-06-17 19:56:36 -05006762 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6763 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006764 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05006765 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05006766 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006767 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05006768 int rscn_id = 0, hba_id = 0;
James Smart2332e6e2019-11-04 16:57:01 -08006769 int i, tmo;
dea31012005-04-17 16:05:31 -05006770
dea31012005-04-17 16:05:31 -05006771 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6772 lp = (uint32_t *) pcmd->virt;
6773
James Smart92d7f7b2007-06-17 19:56:38 -05006774 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6775 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006776 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04006777 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6778 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05006779 vport->fc_flag, payload_len, *lp,
6780 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05006781
6782 /* Send an RSCN event to the management application */
6783 lpfc_send_rscn_event(vport, cmdiocb);
6784
James Smartd2873e42006-08-18 17:46:43 -04006785 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05006786 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04006787 FCH_EVT_RSCN, lp[i]);
6788
James Smartf60cb932019-05-14 14:58:05 -07006789 /* Check if RSCN is coming from a direct-connected remote NPort */
6790 if (vport->fc_flag & FC_PT2PT) {
6791 /* If so, just ACC it, no other action needed for now */
6792 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6793 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6794 *lp, vport->fc_flag, payload_len);
6795 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart6f2589f2019-05-14 14:58:07 -07006796
James Smarta6d10f22019-08-14 16:56:50 -07006797 /* Check to see if we need to NVME rescan this target
6798 * remoteport.
6799 */
6800 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6801 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006802 lpfc_nvme_rescan_port(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07006803 return 0;
6804 }
6805
dea31012005-04-17 16:05:31 -05006806 /* If we are about to begin discovery, just ACC the RSCN.
6807 * Discovery processing will satisfy it.
6808 */
James Smart2e0fef82007-06-17 19:56:36 -05006809 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05006810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6811 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6812 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6813
James Smart51ef4c22007-08-02 11:10:31 -04006814 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006815 return 0;
dea31012005-04-17 16:05:31 -05006816 }
6817
James Smart92d7f7b2007-06-17 19:56:38 -05006818 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6819 * just ACC and ignore it.
6820 */
6821 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04006822 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05006823 i = payload_len;
6824 datap = lp;
6825 while (i > 0) {
6826 nportid = *datap++;
6827 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6828 i -= sizeof(uint32_t);
6829 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04006830 if (lpfc_find_vport_by_did(phba, nportid))
6831 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05006832 }
6833 if (rscn_id == hba_id) {
6834 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006835 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006836 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006837 "Data: x%x x%x x%x x%x\n",
6838 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006839 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006840 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6841 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6842 ndlp->nlp_DID, vport->port_state,
6843 ndlp->nlp_flag);
6844
James Smart92d7f7b2007-06-17 19:56:38 -05006845 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006846 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006847 return 0;
6848 }
6849 }
6850
James Smart7f5f3d02008-02-08 18:50:14 -05006851 spin_lock_irq(shost->host_lock);
6852 if (vport->fc_rscn_flush) {
6853 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006854 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006855 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006856 /* Send back ACC */
6857 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006858 return 0;
6859 }
6860 /* Indicate we are walking fc_rscn_id_list on this vport */
6861 vport->fc_rscn_flush = 1;
6862 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006863 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006864 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006865 /* If we are already processing an RSCN, save the received
6866 * RSCN payload buffer, cmdiocb->context2 to process later.
6867 */
James Smart2e0fef82007-06-17 19:56:36 -05006868 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6870 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6871 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6872
James Smart09372822008-01-11 01:52:54 -05006873 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006874 vport->fc_flag |= FC_RSCN_DEFERRED;
James Smart2332e6e2019-11-04 16:57:01 -08006875
6876 /* Restart disctmo if its already running */
6877 if (vport->fc_flag & FC_DISC_TMO) {
6878 tmo = ((phba->fc_ratov * 3) + 3);
6879 mod_timer(&vport->fc_disctmo,
6880 jiffies + msecs_to_jiffies(1000 * tmo));
6881 }
James Smart92d7f7b2007-06-17 19:56:38 -05006882 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006883 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006884 vport->fc_flag |= FC_RSCN_MODE;
6885 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006886 if (rscn_cnt) {
6887 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6888 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6889 }
6890 if ((rscn_cnt) &&
6891 (payload_len + length <= LPFC_BPL_SIZE)) {
6892 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006893 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006894 memcpy(((uint8_t *)cmd) + length, lp,
6895 payload_len);
6896 } else {
6897 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6898 vport->fc_rscn_id_cnt++;
6899 /* If we zero, cmdiocb->context2, the calling
6900 * routine will not try to free it.
6901 */
6902 cmdiocb->context2 = NULL;
6903 }
dea31012005-04-17 16:05:31 -05006904 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006905 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6906 "0235 Deferred RSCN "
6907 "Data: x%x x%x x%x\n",
6908 vport->fc_rscn_id_cnt, vport->fc_flag,
6909 vport->port_state);
dea31012005-04-17 16:05:31 -05006910 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006911 vport->fc_flag |= FC_RSCN_DISCOVERY;
6912 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006913 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006914 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6915 "0234 ReDiscovery RSCN "
6916 "Data: x%x x%x x%x\n",
6917 vport->fc_rscn_id_cnt, vport->fc_flag,
6918 vport->port_state);
dea31012005-04-17 16:05:31 -05006919 }
James Smart7f5f3d02008-02-08 18:50:14 -05006920 /* Indicate we are done walking fc_rscn_id_list on this vport */
6921 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006922 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006923 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006924 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006925 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006926 return 0;
dea31012005-04-17 16:05:31 -05006927 }
James Smart858c9f62007-06-17 19:56:39 -05006928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6929 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6930 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6931
James Smart2e0fef82007-06-17 19:56:36 -05006932 spin_lock_irq(shost->host_lock);
6933 vport->fc_flag |= FC_RSCN_MODE;
6934 spin_unlock_irq(shost->host_lock);
6935 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006936 /* Indicate we are done walking fc_rscn_id_list on this vport */
6937 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006938 /*
6939 * If we zero, cmdiocb->context2, the calling routine will
6940 * not try to free it.
6941 */
6942 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006943 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006944 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006945 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006946 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006947 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006948 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006949}
6950
James Smarte59058c2008-08-24 21:49:00 -04006951/**
James Smart3621a712009-04-06 18:47:14 -04006952 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006953 * @vport: pointer to a host virtual N_Port data structure.
6954 *
6955 * This routine handles the Registration State Configuration Notification
6956 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6957 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6958 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6959 * NameServer shall be issued. If CT command to the NameServer fails to be
6960 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6961 * RSCN activities with the @vport.
6962 *
6963 * Return code
6964 * 0 - Cleaned up rscn on the @vport
6965 * 1 - Wait for plogi to name server before proceed
6966 **/
dea31012005-04-17 16:05:31 -05006967int
James Smart2e0fef82007-06-17 19:56:36 -05006968lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006969{
6970 struct lpfc_nodelist *ndlp;
James Smart7ea92eb2018-10-23 13:41:10 -07006971 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006972
James Smart92d7f7b2007-06-17 19:56:38 -05006973 /* Ignore RSCN if the port is being torn down. */
6974 if (vport->load_flag & FC_UNLOADING) {
6975 lpfc_els_flush_rscn(vport);
6976 return 0;
6977 }
6978
dea31012005-04-17 16:05:31 -05006979 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006980 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006981
6982 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006983 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07006984 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04006985 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
James Smartb4b34172019-10-18 14:18:31 -07006986 vport->port_state, vport->num_disc_nodes,
6987 vport->gidft_inp);
dea31012005-04-17 16:05:31 -05006988
6989 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006990 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006991 vport->num_disc_nodes = 0;
6992
James Smart2e0fef82007-06-17 19:56:36 -05006993 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08006994 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006995 /* Good ndlp, issue CT Request to NameServer. Need to
6996 * know how many gidfts were issued. If none, then just
6997 * flush the RSCN. Otherwise, the outstanding requests
6998 * need to complete.
6999 */
James Smart7ea92eb2018-10-23 13:41:10 -07007000 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7001 if (lpfc_issue_gidft(vport) > 0)
7002 return 1;
7003 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7004 if (lpfc_issue_gidpt(vport) > 0)
7005 return 1;
7006 } else {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007007 return 1;
James Smart7ea92eb2018-10-23 13:41:10 -07007008 }
dea31012005-04-17 16:05:31 -05007009 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07007010 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05007011 if (ndlp) {
James Smarte47c9092008-02-08 18:49:26 -05007012 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart307e3382020-11-15 11:26:30 -08007013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007014 } else {
James Smart9d3d3402017-04-21 16:05:00 -07007015 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007016 if (!ndlp) {
7017 lpfc_els_flush_rscn(vport);
7018 return 0;
7019 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007020 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007021 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007022 }
James Smarte47c9092008-02-08 18:49:26 -05007023 ndlp->nlp_type |= NLP_FABRIC;
7024 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7025 /* Wait for NameServer login cmpl before we can
7026 * continue
7027 */
7028 return 1;
dea31012005-04-17 16:05:31 -05007029 }
7030
James Smart2e0fef82007-06-17 19:56:36 -05007031 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007032 return 0;
dea31012005-04-17 16:05:31 -05007033}
7034
James Smarte59058c2008-08-24 21:49:00 -04007035/**
James Smart3621a712009-04-06 18:47:14 -04007036 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04007037 * @vport: pointer to a host virtual N_Port data structure.
7038 * @cmdiocb: pointer to lpfc command iocb data structure.
7039 * @ndlp: pointer to a node-list data structure.
7040 *
7041 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7042 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7043 * point topology. As an unsolicited FLOGI should not be received in a loop
7044 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7045 * lpfc_check_sparm() routine is invoked to check the parameters in the
7046 * unsolicited FLOGI. If parameters validation failed, the routine
7047 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7048 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7049 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7050 * will initiate PLOGI. The higher lexicographical value party shall has
7051 * higher priority (as the winning port) and will initiate PLOGI and
7052 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7053 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7054 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7055 *
7056 * Return code
7057 * 0 - Successfully processed the unsolicited flogi
7058 * 1 - Failed to process the unsolicited flogi
7059 **/
dea31012005-04-17 16:05:31 -05007060static int
James Smart2e0fef82007-06-17 19:56:36 -05007061lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04007062 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007063{
James Smart2e0fef82007-06-17 19:56:36 -05007064 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7065 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007066 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7067 uint32_t *lp = (uint32_t *) pcmd->virt;
7068 IOCB_t *icmd = &cmdiocb->iocb;
7069 struct serv_parm *sp;
7070 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05007071 uint32_t cmd, did;
7072 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04007073 uint32_t fc_flag = 0;
7074 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05007075
7076 cmd = *lp++;
7077 sp = (struct serv_parm *) lp;
7078
7079 /* FLOGI received */
7080
James Smart2e0fef82007-06-17 19:56:36 -05007081 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05007082
James Smart76a95d72010-11-20 23:11:48 -05007083 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05007084 /* We should never receive a FLOGI in loop mode, ignore it */
7085 did = icmd->un.elsreq64.remoteID;
7086
7087 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7088 Loop Mode */
Dick Kennedy372c1872020-06-30 14:50:00 -07007089 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04007090 "0113 An FLOGI ELS command x%x was "
7091 "received from DID x%x in Loop Mode\n",
7092 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007093 return 1;
dea31012005-04-17 16:05:31 -05007094 }
7095
James Smartd6de08c2015-12-16 18:11:53 -05007096 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05007097
James Smartd6de08c2015-12-16 18:11:53 -05007098 /*
7099 * If our portname is greater than the remote portname,
7100 * then we initiate Nport login.
7101 */
7102
7103 rc = memcmp(&vport->fc_portname, &sp->portName,
7104 sizeof(struct lpfc_name));
7105
7106 if (!rc) {
7107 if (phba->sli_rev < LPFC_SLI_REV4) {
7108 mbox = mempool_alloc(phba->mbox_mem_pool,
7109 GFP_KERNEL);
7110 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007111 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05007112 lpfc_linkdown(phba);
7113 lpfc_init_link(phba, mbox,
7114 phba->cfg_topology,
7115 phba->cfg_link_speed);
7116 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7117 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7118 mbox->vport = vport;
7119 rc = lpfc_sli_issue_mbox(phba, mbox,
7120 MBX_NOWAIT);
7121 lpfc_set_loopback_flag(phba);
7122 if (rc == MBX_NOT_FINISHED)
7123 mempool_free(mbox, phba->mbox_mem_pool);
7124 return 1;
7125 }
James Smart939723a2012-05-09 21:19:03 -04007126
James Smartd6de08c2015-12-16 18:11:53 -05007127 /* abort the flogi coming back to ourselves
7128 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04007129 */
James Smartd6de08c2015-12-16 18:11:53 -05007130 lpfc_els_abort_flogi(phba);
7131 return 0;
7132
7133 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05007134 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05007135 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05007136 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04007137
James Smartd6de08c2015-12-16 18:11:53 -05007138 /* If we have the high WWPN we can assign our own
7139 * myDID; otherwise, we have to WAIT for a PLOGI
7140 * from the remote NPort to find out what it
7141 * will be.
James Smart939723a2012-05-09 21:19:03 -04007142 */
James Smartd6de08c2015-12-16 18:11:53 -05007143 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05007144 } else {
James Smartd6de08c2015-12-16 18:11:53 -05007145 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05007146 }
7147
James Smartd6de08c2015-12-16 18:11:53 -05007148 /*
7149 * The vport state should go to LPFC_FLOGI only
7150 * AFTER we issue a FLOGI, not receive one.
7151 */
7152 spin_lock_irq(shost->host_lock);
7153 fc_flag = vport->fc_flag;
7154 port_state = vport->port_state;
7155 vport->fc_flag |= FC_PT2PT;
7156 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd496b9a2018-10-23 13:41:08 -07007157
7158 /* Acking an unsol FLOGI. Count 1 for link bounce
7159 * work-around.
7160 */
7161 vport->rcv_flogi_cnt++;
James Smartd6de08c2015-12-16 18:11:53 -05007162 spin_unlock_irq(shost->host_lock);
7163 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7164 "3311 Rcv Flogi PS x%x new PS x%x "
7165 "fc_flag x%x new fc_flag x%x\n",
7166 port_state, vport->port_state,
7167 fc_flag, vport->fc_flag);
7168
7169 /*
7170 * We temporarily set fc_myDID to make it look like we are
7171 * a Fabric. This is done just so we end up with the right
7172 * did / sid on the FLOGI ACC rsp.
7173 */
7174 did = vport->fc_myDID;
7175 vport->fc_myDID = Fabric_DID;
7176
7177 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04007178
James Smart0a9e9682018-11-29 16:09:36 -08007179 /* Defer ACC response until AFTER we issue a FLOGI */
7180 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7181 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7182 phba->defer_flogi_acc_ox_id =
7183 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7184
7185 vport->fc_myDID = did;
7186
7187 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7188 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7189 " ox_id: x%x, hba_flag x%x\n",
7190 phba->defer_flogi_acc_rx_id,
7191 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7192
7193 phba->defer_flogi_acc_flag = true;
7194
7195 return 0;
7196 }
7197
dea31012005-04-17 16:05:31 -05007198 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05007199 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007200
James Smart939723a2012-05-09 21:19:03 -04007201 /* Now lets put fc_myDID back to what its supposed to be */
7202 vport->fc_myDID = did;
7203
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007204 return 0;
dea31012005-04-17 16:05:31 -05007205}
7206
James Smarte59058c2008-08-24 21:49:00 -04007207/**
James Smart3621a712009-04-06 18:47:14 -04007208 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04007209 * @vport: pointer to a host virtual N_Port data structure.
7210 * @cmdiocb: pointer to lpfc command iocb data structure.
7211 * @ndlp: pointer to a node-list data structure.
7212 *
7213 * This routine processes Request Node Identification Data (RNID) IOCB
7214 * received as an ELS unsolicited event. Only when the RNID specified format
7215 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7216 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7217 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7218 * rejected by invoking the lpfc_els_rsp_reject() routine.
7219 *
7220 * Return code
7221 * 0 - Successfully processed rnid iocb (currently always return 0)
7222 **/
dea31012005-04-17 16:05:31 -05007223static int
James Smart2e0fef82007-06-17 19:56:36 -05007224lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7225 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007226{
7227 struct lpfc_dmabuf *pcmd;
7228 uint32_t *lp;
dea31012005-04-17 16:05:31 -05007229 RNID *rn;
7230 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007231
dea31012005-04-17 16:05:31 -05007232 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7233 lp = (uint32_t *) pcmd->virt;
7234
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007235 lp++;
dea31012005-04-17 16:05:31 -05007236 rn = (RNID *) lp;
7237
7238 /* RNID received */
7239
7240 switch (rn->Format) {
7241 case 0:
7242 case RNID_TOPOLOGY_DISC:
7243 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05007244 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007245 break;
7246 default:
7247 /* Reject this request because format not supported */
7248 stat.un.b.lsRjtRsvd0 = 0;
7249 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7250 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7251 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007252 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7253 NULL);
dea31012005-04-17 16:05:31 -05007254 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007255 return 0;
dea31012005-04-17 16:05:31 -05007256}
7257
James Smarte59058c2008-08-24 21:49:00 -04007258/**
James Smart12265f62010-10-22 11:05:53 -04007259 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7260 * @vport: pointer to a host virtual N_Port data structure.
7261 * @cmdiocb: pointer to lpfc command iocb data structure.
7262 * @ndlp: pointer to a node-list data structure.
7263 *
7264 * Return code
7265 * 0 - Successfully processed echo iocb (currently always return 0)
7266 **/
7267static int
7268lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7269 struct lpfc_nodelist *ndlp)
7270{
7271 uint8_t *pcmd;
7272
7273 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7274
7275 /* skip over first word of echo command to find echo data */
7276 pcmd += sizeof(uint32_t);
7277
7278 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7279 return 0;
7280}
7281
7282/**
James Smart3621a712009-04-06 18:47:14 -04007283 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04007284 * @vport: pointer to a host virtual N_Port data structure.
7285 * @cmdiocb: pointer to lpfc command iocb data structure.
7286 * @ndlp: pointer to a node-list data structure.
7287 *
7288 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7289 * received as an ELS unsolicited event. Currently, this function just invokes
7290 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7291 *
7292 * Return code
7293 * 0 - Successfully processed lirr iocb (currently always return 0)
7294 **/
dea31012005-04-17 16:05:31 -05007295static int
James Smart2e0fef82007-06-17 19:56:36 -05007296lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7297 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007298{
7299 struct ls_rjt stat;
7300
7301 /* For now, unconditionally reject this command */
7302 stat.un.b.lsRjtRsvd0 = 0;
7303 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7304 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7305 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007306 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007307 return 0;
7308}
7309
James Smarte59058c2008-08-24 21:49:00 -04007310/**
James Smart5ffc2662009-11-18 15:39:44 -05007311 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7312 * @vport: pointer to a host virtual N_Port data structure.
7313 * @cmdiocb: pointer to lpfc command iocb data structure.
7314 * @ndlp: pointer to a node-list data structure.
7315 *
7316 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7317 * received as an ELS unsolicited event. A request to RRQ shall only
7318 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7319 * Nx_Port N_Port_ID of the target Exchange is the same as the
7320 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7321 * not accepted, an LS_RJT with reason code "Unable to perform
7322 * command request" and reason code explanation "Invalid Originator
7323 * S_ID" shall be returned. For now, we just unconditionally accept
7324 * RRQ from the target.
7325 **/
7326static void
7327lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7328 struct lpfc_nodelist *ndlp)
7329{
7330 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05007331 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7332 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05007333}
7334
7335/**
James Smart12265f62010-10-22 11:05:53 -04007336 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7337 * @phba: pointer to lpfc hba data structure.
7338 * @pmb: pointer to the driver internal queue element for mailbox command.
7339 *
7340 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7341 * mailbox command. This callback function is to actually send the Accept
7342 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7343 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7344 * mailbox command, constructs the RPS response with the link statistics
7345 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7346 * response to the RPS.
7347 *
7348 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7349 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7350 * will be stored into the context1 field of the IOCB for the completion
7351 * callback function to the RPS Accept Response ELS IOCB command.
7352 *
7353 **/
7354static void
7355lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7356{
James Smart4430f7f2020-11-15 11:26:31 -08007357 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04007358 MAILBOX_t *mb;
7359 IOCB_t *icmd;
7360 struct RLS_RSP *rls_rsp;
7361 uint8_t *pcmd;
7362 struct lpfc_iocbq *elsiocb;
7363 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04007364 uint16_t oxid;
7365 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04007366 uint32_t cmdsize;
7367
7368 mb = &pmb->u.mb;
7369
James Smart3e1f0712018-11-29 16:09:29 -08007370 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7371 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7372 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7373 pmb->ctx_buf = NULL;
7374 pmb->ctx_ndlp = NULL;
James Smart12265f62010-10-22 11:05:53 -04007375
7376 if (mb->mbxStatus) {
7377 mempool_free(pmb, phba->mbox_mem_pool);
7378 return;
7379 }
7380
7381 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04007382 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7383 lpfc_max_els_tries, ndlp,
7384 ndlp->nlp_DID, ELS_CMD_ACC);
7385
7386 /* Decrement the ndlp reference count from previous mbox command */
7387 lpfc_nlp_put(ndlp);
7388
James Smart37db57e2012-05-09 21:17:16 -04007389 if (!elsiocb) {
7390 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007391 return;
James Smart37db57e2012-05-09 21:17:16 -04007392 }
James Smart12265f62010-10-22 11:05:53 -04007393
7394 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007395 icmd->ulpContext = rxid;
7396 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04007397
7398 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7399 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7400 pcmd += sizeof(uint32_t); /* Skip past command */
7401 rls_rsp = (struct RLS_RSP *)pcmd;
7402
7403 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7404 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7405 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7406 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7407 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7408 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04007409 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007410 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7411 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7412 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7413 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7414 elsiocb->iotag, elsiocb->iocb.ulpContext,
7415 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7416 ndlp->nlp_rpi);
7417 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7418 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007419 elsiocb->context1 = lpfc_nlp_get(ndlp);
7420 if (!elsiocb->context1)
7421 goto node_err;
7422
7423 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7424 if (rc == IOCB_ERROR)
7425 goto io_err;
7426 return;
7427
7428 io_err:
7429 lpfc_nlp_put(ndlp);
7430 node_err:
7431 lpfc_els_free_iocb(phba, elsiocb);
James Smart12265f62010-10-22 11:05:53 -04007432}
7433
7434/**
James Smart12265f62010-10-22 11:05:53 -04007435 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7436 * @vport: pointer to a host virtual N_Port data structure.
7437 * @cmdiocb: pointer to lpfc command iocb data structure.
7438 * @ndlp: pointer to a node-list data structure.
7439 *
James Smart6cde2e3e2020-01-27 16:23:08 -08007440 * This routine processes Read Link Status (RLS) IOCB received as an
James Smart12265f62010-10-22 11:05:53 -04007441 * ELS unsolicited event. It first checks the remote port state. If the
7442 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7443 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7444 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7445 * for reading the HBA link statistics. It is for the callback function,
7446 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7447 * to actually sending out RPL Accept (ACC) response.
7448 *
7449 * Return codes
7450 * 0 - Successfully processed rls iocb (currently always return 0)
7451 **/
7452static int
7453lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7454 struct lpfc_nodelist *ndlp)
7455{
7456 struct lpfc_hba *phba = vport->phba;
7457 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04007458 struct ls_rjt stat;
7459
7460 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7461 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007462 /* reject the unsolicited RLS request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007463 goto reject_out;
7464
James Smart12265f62010-10-22 11:05:53 -04007465 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7466 if (mbox) {
7467 lpfc_read_lnk_stat(phba, mbox);
James Smart3e1f0712018-11-29 16:09:29 -08007468 mbox->ctx_buf = (void *)((unsigned long)
James Smart7851fe22011-07-22 18:36:52 -04007469 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7470 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart3e1f0712018-11-29 16:09:29 -08007471 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007472 if (!mbox->ctx_ndlp)
7473 goto node_err;
James Smart12265f62010-10-22 11:05:53 -04007474 mbox->vport = vport;
7475 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7476 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7477 != MBX_NOT_FINISHED)
7478 /* Mbox completion will send ELS Response */
7479 return 0;
7480 /* Decrement reference count used for the failed mbox
7481 * command.
7482 */
7483 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007484node_err:
James Smart12265f62010-10-22 11:05:53 -04007485 mempool_free(mbox, phba->mbox_mem_pool);
7486 }
7487reject_out:
7488 /* issue rejection response */
7489 stat.un.b.lsRjtRsvd0 = 0;
7490 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7491 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7492 stat.un.b.vendorUnique = 0;
7493 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7494 return 0;
7495}
7496
7497/**
7498 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7499 * @vport: pointer to a host virtual N_Port data structure.
7500 * @cmdiocb: pointer to lpfc command iocb data structure.
7501 * @ndlp: pointer to a node-list data structure.
7502 *
7503 * This routine processes Read Timout Value (RTV) IOCB received as an
7504 * ELS unsolicited event. It first checks the remote port state. If the
7505 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7506 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7507 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7508 * Value (RTV) unsolicited IOCB event.
7509 *
7510 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7511 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7512 * will be stored into the context1 field of the IOCB for the completion
James Smart6cde2e3e2020-01-27 16:23:08 -08007513 * callback function to the RTV Accept Response ELS IOCB command.
James Smart12265f62010-10-22 11:05:53 -04007514 *
7515 * Return codes
7516 * 0 - Successfully processed rtv iocb (currently always return 0)
7517 **/
7518static int
7519lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7520 struct lpfc_nodelist *ndlp)
7521{
James Smart4430f7f2020-11-15 11:26:31 -08007522 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04007523 struct lpfc_hba *phba = vport->phba;
7524 struct ls_rjt stat;
7525 struct RTV_RSP *rtv_rsp;
7526 uint8_t *pcmd;
7527 struct lpfc_iocbq *elsiocb;
7528 uint32_t cmdsize;
7529
7530
7531 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7532 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007533 /* reject the unsolicited RTV request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007534 goto reject_out;
7535
7536 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7537 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7538 lpfc_max_els_tries, ndlp,
7539 ndlp->nlp_DID, ELS_CMD_ACC);
7540
7541 if (!elsiocb)
7542 return 1;
7543
7544 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
Colin Ian King8fd03fd2017-12-22 00:39:36 +00007545 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart12265f62010-10-22 11:05:53 -04007546 pcmd += sizeof(uint32_t); /* Skip past command */
7547
7548 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04007549 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7550 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04007551
7552 rtv_rsp = (struct RTV_RSP *)pcmd;
7553
7554 /* populate RTV payload */
7555 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7556 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7557 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7558 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7559 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7560
7561 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7562 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7563 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7564 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7565 "Data: x%x x%x x%x\n",
7566 elsiocb->iotag, elsiocb->iocb.ulpContext,
7567 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7568 ndlp->nlp_rpi,
7569 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7570 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7571 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007572 elsiocb->context1 = lpfc_nlp_get(ndlp);
7573 if (!elsiocb->context1) {
James Smart12265f62010-10-22 11:05:53 -04007574 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08007575 return 0;
7576 }
7577
7578 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7579 if (rc == IOCB_ERROR) {
7580 lpfc_nlp_put(ndlp);
7581 lpfc_els_free_iocb(phba, elsiocb);
7582 }
James Smart12265f62010-10-22 11:05:53 -04007583 return 0;
7584
7585reject_out:
7586 /* issue rejection response */
7587 stat.un.b.lsRjtRsvd0 = 0;
7588 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7589 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7590 stat.un.b.vendorUnique = 0;
7591 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7592 return 0;
7593}
7594
James Smart6cde2e3e2020-01-27 16:23:08 -08007595/* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
James Smart19ca7602010-11-20 23:11:55 -05007596 * @vport: pointer to a host virtual N_Port data structure.
7597 * @ndlp: pointer to a node-list data structure.
7598 * @did: DID of the target.
7599 * @rrq: Pointer to the rrq struct.
7600 *
7601 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7602 * Successful the the completion handler will clear the RRQ.
7603 *
7604 * Return codes
7605 * 0 - Successfully sent rrq els iocb.
7606 * 1 - Failed to send rrq els iocb.
7607 **/
7608static int
7609lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7610 uint32_t did, struct lpfc_node_rrq *rrq)
7611{
7612 struct lpfc_hba *phba = vport->phba;
7613 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05007614 struct lpfc_iocbq *elsiocb;
7615 uint8_t *pcmd;
7616 uint16_t cmdsize;
7617 int ret;
7618
7619
7620 if (ndlp != rrq->ndlp)
7621 ndlp = rrq->ndlp;
James Smart307e3382020-11-15 11:26:30 -08007622 if (!ndlp)
James Smart19ca7602010-11-20 23:11:55 -05007623 return 1;
7624
7625 /* If ndlp is not NULL, we will bump the reference count on it */
7626 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7627 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7628 ELS_CMD_RRQ);
7629 if (!elsiocb)
7630 return 1;
7631
James Smart19ca7602010-11-20 23:11:55 -05007632 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7633
7634 /* For RRQ request, remainder of payload is Exchange IDs */
7635 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7636 pcmd += sizeof(uint32_t);
7637 els_rrq = (struct RRQ *) pcmd;
7638
James Smartee0f4fe2012-05-09 21:19:14 -04007639 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05007640 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7641 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7642 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7643 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7644
7645
7646 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7647 "Issue RRQ: did:x%x",
7648 did, rrq->xritag, rrq->rxid);
7649 elsiocb->context_un.rrq = rrq;
7650 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
James Smart4430f7f2020-11-15 11:26:31 -08007651 elsiocb->context1 = lpfc_nlp_get(ndlp);
7652 if (!elsiocb->context1)
7653 goto node_err;
James Smart19ca7602010-11-20 23:11:55 -05007654
James Smart4430f7f2020-11-15 11:26:31 -08007655 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7656 if (ret == IOCB_ERROR)
7657 goto io_err;
James Smart19ca7602010-11-20 23:11:55 -05007658 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08007659
7660 io_err:
7661 lpfc_nlp_put(ndlp);
7662 node_err:
7663 lpfc_els_free_iocb(phba, elsiocb);
7664 return 1;
James Smart19ca7602010-11-20 23:11:55 -05007665}
7666
7667/**
7668 * lpfc_send_rrq - Sends ELS RRQ if needed.
7669 * @phba: pointer to lpfc hba data structure.
7670 * @rrq: pointer to the active rrq.
7671 *
7672 * This routine will call the lpfc_issue_els_rrq if the rrq is
7673 * still active for the xri. If this function returns a failure then
7674 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7675 *
7676 * Returns 0 Success.
7677 * 1 Failure.
7678 **/
7679int
7680lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7681{
7682 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
James Smartc8cb2612019-05-06 17:26:49 -07007683 rrq->nlp_DID);
7684 if (!ndlp)
7685 return 1;
7686
James Smart19ca7602010-11-20 23:11:55 -05007687 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7688 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7689 rrq->nlp_DID, rrq);
7690 else
7691 return 1;
7692}
7693
James Smarte59058c2008-08-24 21:49:00 -04007694/**
James Smart3621a712009-04-06 18:47:14 -04007695 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04007696 * @vport: pointer to a host virtual N_Port data structure.
7697 * @cmdsize: size of the ELS command.
7698 * @oldiocb: pointer to the original lpfc command iocb data structure.
7699 * @ndlp: pointer to a node-list data structure.
7700 *
7701 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7702 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7703 *
7704 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7705 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7706 * will be stored into the context1 field of the IOCB for the completion
7707 * callback function to the RPL Accept Response ELS command.
7708 *
7709 * Return code
7710 * 0 - Successfully issued ACC RPL ELS command
7711 * 1 - Failed to issue ACC RPL ELS command
7712 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05007713static int
James Smart2e0fef82007-06-17 19:56:36 -05007714lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7715 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007716{
James Smart4430f7f2020-11-15 11:26:31 -08007717 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007718 struct lpfc_hba *phba = vport->phba;
7719 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007720 RPL_RSP rpl_rsp;
7721 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007722 uint8_t *pcmd;
7723
James Smart2e0fef82007-06-17 19:56:36 -05007724 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7725 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007726
James Smart488d1462006-03-07 15:02:37 -05007727 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007728 return 1;
James Smart488d1462006-03-07 15:02:37 -05007729
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007730 icmd = &elsiocb->iocb;
7731 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007732 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7733 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007734
7735 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7736 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007737 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007738 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7739 pcmd += sizeof(uint16_t);
7740
7741 /* Setup the RPL ACC payload */
7742 rpl_rsp.listLen = be32_to_cpu(1);
7743 rpl_rsp.index = 0;
7744 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007745 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7746 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007747 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007748 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007749 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7751 "0120 Xmit ELS RPL ACC response tag x%x "
7752 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7753 "rpi x%x\n",
7754 elsiocb->iotag, elsiocb->iocb.ulpContext,
7755 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7756 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007757 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007758 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007759 elsiocb->context1 = lpfc_nlp_get(ndlp);
7760 if (!elsiocb->context1)
7761 goto node_err;
7762
7763 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7764 if (rc == IOCB_ERROR)
7765 goto io_err;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007766 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08007767
7768 io_err:
7769 lpfc_nlp_put(ndlp);
7770 node_err:
7771 lpfc_els_free_iocb(phba, elsiocb);
7772 return 1;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007773}
7774
James Smarte59058c2008-08-24 21:49:00 -04007775/**
James Smart3621a712009-04-06 18:47:14 -04007776 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007777 * @vport: pointer to a host virtual N_Port data structure.
7778 * @cmdiocb: pointer to lpfc command iocb data structure.
7779 * @ndlp: pointer to a node-list data structure.
7780 *
7781 * This routine processes Read Port List (RPL) IOCB received as an ELS
7782 * unsolicited event. It first checks the remote port state. If the remote
7783 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7784 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7785 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7786 * to accept the RPL.
7787 *
7788 * Return code
7789 * 0 - Successfully processed rpl iocb (currently always return 0)
7790 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007791static int
James Smart2e0fef82007-06-17 19:56:36 -05007792lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7793 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007794{
7795 struct lpfc_dmabuf *pcmd;
7796 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007797 uint32_t maxsize;
7798 uint16_t cmdsize;
7799 RPL *rpl;
7800 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007801
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007802 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7803 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007804 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007805 stat.un.b.lsRjtRsvd0 = 0;
7806 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7807 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7808 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007809 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7810 NULL);
James Smart90160e02008-08-24 21:49:45 -04007811 /* rejected the unsolicited RPL request and done with it */
7812 return 0;
dea31012005-04-17 16:05:31 -05007813 }
7814
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007815 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7816 lp = (uint32_t *) pcmd->virt;
7817 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007818 maxsize = be32_to_cpu(rpl->maxsize);
7819
7820 /* We support only one port */
7821 if ((rpl->index == 0) &&
7822 ((maxsize == 0) ||
7823 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7824 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007825 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007826 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7827 }
James Smart2e0fef82007-06-17 19:56:36 -05007828 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007829
7830 return 0;
7831}
7832
James Smarte59058c2008-08-24 21:49:00 -04007833/**
James Smart3621a712009-04-06 18:47:14 -04007834 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007835 * @vport: pointer to a virtual N_Port data structure.
7836 * @cmdiocb: pointer to lpfc command iocb data structure.
7837 * @ndlp: pointer to a node-list data structure.
7838 *
7839 * This routine processes Fibre Channel Address Resolution Protocol
7840 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7841 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7842 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7843 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7844 * remote PortName is compared against the FC PortName stored in the @vport
7845 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7846 * compared against the FC NodeName stored in the @vport data structure.
7847 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7848 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7849 * invoked to send out FARP Response to the remote node. Before sending the
7850 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7851 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7852 * routine is invoked to log into the remote port first.
7853 *
7854 * Return code
7855 * 0 - Either the FARP Match Mode not supported or successfully processed
7856 **/
dea31012005-04-17 16:05:31 -05007857static int
James Smart2e0fef82007-06-17 19:56:36 -05007858lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7859 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007860{
7861 struct lpfc_dmabuf *pcmd;
7862 uint32_t *lp;
7863 IOCB_t *icmd;
7864 FARP *fp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007865 uint32_t cnt, did;
dea31012005-04-17 16:05:31 -05007866
7867 icmd = &cmdiocb->iocb;
7868 did = icmd->un.elsreq64.remoteID;
7869 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7870 lp = (uint32_t *) pcmd->virt;
7871
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007872 lp++;
dea31012005-04-17 16:05:31 -05007873 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007874 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007875 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7876 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007877 /* We will only support match on WWPN or WWNN */
7878 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007879 return 0;
dea31012005-04-17 16:05:31 -05007880 }
7881
7882 cnt = 0;
7883 /* If this FARP command is searching for my portname */
7884 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007885 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007886 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007887 cnt = 1;
7888 }
7889
7890 /* If this FARP command is searching for my nodename */
7891 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007892 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007893 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007894 cnt = 1;
7895 }
7896
7897 if (cnt) {
7898 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7899 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7900 /* Log back into the node before sending the FARP. */
7901 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007902 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007903 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007904 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007905 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007906 }
7907
7908 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007909 if (fp->Rflags & FARP_REQUEST_FARPR)
7910 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007911 }
7912 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007913 return 0;
dea31012005-04-17 16:05:31 -05007914}
7915
James Smarte59058c2008-08-24 21:49:00 -04007916/**
James Smart3621a712009-04-06 18:47:14 -04007917 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007918 * @vport: pointer to a host virtual N_Port data structure.
7919 * @cmdiocb: pointer to lpfc command iocb data structure.
7920 * @ndlp: pointer to a node-list data structure.
7921 *
7922 * This routine processes Fibre Channel Address Resolution Protocol
7923 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7924 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7925 * the FARP response request.
7926 *
7927 * Return code
7928 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7929 **/
dea31012005-04-17 16:05:31 -05007930static int
James Smart2e0fef82007-06-17 19:56:36 -05007931lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7932 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007933{
7934 struct lpfc_dmabuf *pcmd;
7935 uint32_t *lp;
7936 IOCB_t *icmd;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007937 uint32_t did;
dea31012005-04-17 16:05:31 -05007938
7939 icmd = &cmdiocb->iocb;
7940 did = icmd->un.elsreq64.remoteID;
7941 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7942 lp = (uint32_t *) pcmd->virt;
7943
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007944 lp++;
dea31012005-04-17 16:05:31 -05007945 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007946 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7947 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007948 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007949 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007950
7951 return 0;
7952}
7953
James Smarte59058c2008-08-24 21:49:00 -04007954/**
James Smart3621a712009-04-06 18:47:14 -04007955 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007956 * @vport: pointer to a host virtual N_Port data structure.
7957 * @cmdiocb: pointer to lpfc command iocb data structure.
7958 * @fan_ndlp: pointer to a node-list data structure.
7959 *
7960 * This routine processes a Fabric Address Notification (FAN) IOCB
7961 * command received as an ELS unsolicited event. The FAN ELS command will
7962 * only be processed on a physical port (i.e., the @vport represents the
7963 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7964 * compared against those in the phba data structure. If any of those is
7965 * different, the lpfc_initial_flogi() routine is invoked to initialize
7966 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7967 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7968 * is invoked to register login to the fabric.
7969 *
7970 * Return code
7971 * 0 - Successfully processed fan iocb (currently always return 0).
7972 **/
dea31012005-04-17 16:05:31 -05007973static int
James Smart2e0fef82007-06-17 19:56:36 -05007974lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7975 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007976{
James Smart2e0fef82007-06-17 19:56:36 -05007977 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007978 uint32_t *lp;
7979 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007980
James Smart0d2b6b82008-06-14 22:52:47 -04007981 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7982 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7983 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007984 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007985 if ((vport == phba->pport) &&
7986 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007987 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007988 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007989 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007990 sizeof(struct lpfc_name)))) {
7991 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007992 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007993 } else {
7994 /* FAN verified - skip FLOGI */
7995 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007996 if (phba->sli_rev < LPFC_SLI_REV4)
7997 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007998 else {
7999 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8000 "3138 Need register VFI: (x%x/%x)\n",
8001 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04008002 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05008003 }
dea31012005-04-17 16:05:31 -05008004 }
dea31012005-04-17 16:05:31 -05008005 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008006 return 0;
dea31012005-04-17 16:05:31 -05008007}
8008
James Smarte59058c2008-08-24 21:49:00 -04008009/**
James Smart3621a712009-04-06 18:47:14 -04008010 * lpfc_els_timeout - Handler funciton to the els timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01008011 * @t: timer context used to obtain the vport.
James Smarte59058c2008-08-24 21:49:00 -04008012 *
8013 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8014 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8015 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8016 * up the worker thread. It is for the worker thread to invoke the routine
8017 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8018 **/
dea31012005-04-17 16:05:31 -05008019void
Kees Cookf22eb4d2017-09-06 20:24:26 -07008020lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05008021{
Kees Cookf22eb4d2017-09-06 20:24:26 -07008022 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05008023 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04008024 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05008025 unsigned long iflag;
8026
James Smart2e0fef82007-06-17 19:56:36 -05008027 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04008028 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05008029 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05008030 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04008031 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05008032
James Smart06918ac2014-02-20 09:57:57 -05008033 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04008034 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05008035 return;
8036}
8037
James Smart2a9bf3d2010-06-07 15:24:45 -04008038
James Smarte59058c2008-08-24 21:49:00 -04008039/**
James Smart3621a712009-04-06 18:47:14 -04008040 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04008041 * @vport: pointer to a virtual N_Port data structure.
8042 *
8043 * This routine is the actual handler function that processes an ELS timeout
8044 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8045 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8046 * invoking the lpfc_sli_issue_abort_iotag() routine.
8047 **/
dea31012005-04-17 16:05:31 -05008048void
James Smart2e0fef82007-06-17 19:56:36 -05008049lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008050{
James Smart2e0fef82007-06-17 19:56:36 -05008051 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05008052 struct lpfc_sli_ring *pring;
8053 struct lpfc_iocbq *tmp_iocb, *piocb;
8054 IOCB_t *cmd = NULL;
8055 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05008056 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05008057 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05008058 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04008059 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05008060
James Smart2a9bf3d2010-06-07 15:24:45 -04008061
dea31012005-04-17 16:05:31 -05008062 timeout = (uint32_t)(phba->fc_ratov << 1);
8063
James Smart895427b2017-02-12 13:52:30 -08008064 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07008065 if (unlikely(!pring))
8066 return;
James Smart895427b2017-02-12 13:52:30 -08008067
James Smarte3041422020-04-21 13:33:54 -07008068 if (phba->pport->load_flag & FC_UNLOADING)
James Smart06918ac2014-02-20 09:57:57 -05008069 return;
James Smarte3041422020-04-21 13:33:54 -07008070
James Smart2a9bf3d2010-06-07 15:24:45 -04008071 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05008072 if (phba->sli_rev == LPFC_SLI_REV4)
8073 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04008074
James Smart0976e1a2013-12-17 20:29:36 -05008075 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05008076 cmd = &piocb->iocb;
8077
James Smart2e0fef82007-06-17 19:56:36 -05008078 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8079 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8080 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05008081 continue;
James Smart2e0fef82007-06-17 19:56:36 -05008082
8083 if (piocb->vport != vport)
8084 continue;
8085
dea31012005-04-17 16:05:31 -05008086 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05008087 if (pcmd)
8088 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05008089
James Smart92d7f7b2007-06-17 19:56:38 -05008090 if (els_command == ELS_CMD_FARP ||
8091 els_command == ELS_CMD_FARPR ||
8092 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05008093 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05008094
dea31012005-04-17 16:05:31 -05008095 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05008096 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05008097 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05008098 else
dea31012005-04-17 16:05:31 -05008099 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05008100 continue;
8101 }
8102
James Smart2e0fef82007-06-17 19:56:36 -05008103 remote_ID = 0xffffffff;
8104 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05008105 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05008106 else {
8107 struct lpfc_nodelist *ndlp;
8108 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart307e3382020-11-15 11:26:30 -08008109 if (ndlp)
James Smart2e0fef82007-06-17 19:56:36 -05008110 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05008111 }
James Smart2a9bf3d2010-06-07 15:24:45 -04008112 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05008113 }
James Smart0976e1a2013-12-17 20:29:36 -05008114 if (phba->sli_rev == LPFC_SLI_REV4)
8115 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05008116 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04008117
James Smart2a9bf3d2010-06-07 15:24:45 -04008118 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05008119 cmd = &piocb->iocb;
Dick Kennedy372c1872020-06-30 14:50:00 -07008120 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart2a9bf3d2010-06-07 15:24:45 -04008121 "0127 ELS timeout Data: x%x x%x x%x "
8122 "x%x\n", els_command,
8123 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8124 spin_lock_irq(&phba->hbalock);
8125 list_del_init(&piocb->dlist);
James Smartdb7531d2020-11-15 11:26:44 -08008126 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
James Smart2a9bf3d2010-06-07 15:24:45 -04008127 spin_unlock_irq(&phba->hbalock);
8128 }
8129
James Smart895427b2017-02-12 13:52:30 -08008130 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05008131 if (!(phba->pport->load_flag & FC_UNLOADING))
8132 mod_timer(&vport->els_tmofunc,
8133 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05008134}
8135
James Smarte59058c2008-08-24 21:49:00 -04008136/**
James Smart3621a712009-04-06 18:47:14 -04008137 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04008138 * @vport: pointer to a host virtual N_Port data structure.
8139 *
8140 * This routine is used to clean up all the outstanding ELS commands on a
8141 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8142 * routine. After that, it walks the ELS transmit queue to remove all the
8143 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8144 * the IOCBs with a non-NULL completion callback function, the callback
8145 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8146 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8147 * callback function, the IOCB will simply be released. Finally, it walks
8148 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8149 * completion queue IOCB that is associated with the @vport and is not
8150 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8151 * part of the discovery state machine) out to HBA by invoking the
8152 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8153 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8154 * the IOCBs are aborted when this function returns.
8155 **/
dea31012005-04-17 16:05:31 -05008156void
James Smart2e0fef82007-06-17 19:56:36 -05008157lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008158{
James Smart0976e1a2013-12-17 20:29:36 -05008159 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05008160 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08008161 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05008162 struct lpfc_iocbq *tmp_iocb, *piocb;
8163 IOCB_t *cmd = NULL;
James Smartd38b4a52019-09-21 20:59:00 -07008164 unsigned long iflags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008165
8166 lpfc_fabric_abort_vport(vport);
James Smartd38b4a52019-09-21 20:59:00 -07008167
James Smart0976e1a2013-12-17 20:29:36 -05008168 /*
8169 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8170 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8171 * ultimately grabs the ring_lock, the driver must splice the list into
8172 * a working list and release the locks before calling the abort.
8173 */
James Smartd38b4a52019-09-21 20:59:00 -07008174 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart895427b2017-02-12 13:52:30 -08008175 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008176
8177 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8178 if (unlikely(!pring)) {
James Smartd38b4a52019-09-21 20:59:00 -07008179 spin_unlock_irqrestore(&phba->hbalock, iflags);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008180 return;
8181 }
8182
James Smart0976e1a2013-12-17 20:29:36 -05008183 if (phba->sli_rev == LPFC_SLI_REV4)
8184 spin_lock(&pring->ring_lock);
8185
James Smart6ede2dd2019-08-14 16:56:44 -07008186 /* First we need to issue aborts to outstanding cmds on txcmpl */
James Smart0976e1a2013-12-17 20:29:36 -05008187 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8188 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8189 continue;
8190
8191 if (piocb->vport != vport)
8192 continue;
James Smart6ede2dd2019-08-14 16:56:44 -07008193
James Smart15498dc2019-09-21 20:58:59 -07008194 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8195 continue;
8196
James Smart6ede2dd2019-08-14 16:56:44 -07008197 /* On the ELS ring we can have ELS_REQUESTs or
8198 * GEN_REQUESTs waiting for a response.
8199 */
8200 cmd = &piocb->iocb;
8201 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8202 list_add_tail(&piocb->dlist, &abort_list);
8203
8204 /* If the link is down when flushing ELS commands
8205 * the firmware will not complete them till after
8206 * the link comes back up. This may confuse
8207 * discovery for the new link up, so we need to
8208 * change the compl routine to just clean up the iocb
8209 * and avoid any retry logic.
8210 */
8211 if (phba->link_state == LPFC_LINK_DOWN)
8212 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8213 }
8214 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8215 list_add_tail(&piocb->dlist, &abort_list);
James Smart0976e1a2013-12-17 20:29:36 -05008216 }
James Smart6ede2dd2019-08-14 16:56:44 -07008217
James Smart0976e1a2013-12-17 20:29:36 -05008218 if (phba->sli_rev == LPFC_SLI_REV4)
8219 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008220 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6ede2dd2019-08-14 16:56:44 -07008221
8222 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
James Smart0976e1a2013-12-17 20:29:36 -05008223 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smartd38b4a52019-09-21 20:59:00 -07008224 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008225 list_del_init(&piocb->dlist);
James Smartdb7531d2020-11-15 11:26:44 -08008226 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
James Smartd38b4a52019-09-21 20:59:00 -07008227 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008228 }
8229 if (!list_empty(&abort_list))
Dick Kennedy372c1872020-06-30 14:50:00 -07008230 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart0976e1a2013-12-17 20:29:36 -05008231 "3387 abort list for txq not empty\n");
8232 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05008233
James Smartd38b4a52019-09-21 20:59:00 -07008234 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008235 if (phba->sli_rev == LPFC_SLI_REV4)
8236 spin_lock(&pring->ring_lock);
8237
James Smart6ede2dd2019-08-14 16:56:44 -07008238 /* No need to abort the txq list,
8239 * just queue them up for lpfc_sli_cancel_iocbs
8240 */
dea31012005-04-17 16:05:31 -05008241 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8242 cmd = &piocb->iocb;
8243
8244 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8245 continue;
8246 }
8247
8248 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04008249 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8250 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8251 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8252 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05008253 continue;
dea31012005-04-17 16:05:31 -05008254
James Smart2e0fef82007-06-17 19:56:36 -05008255 if (piocb->vport != vport)
8256 continue;
8257
James Smart0976e1a2013-12-17 20:29:36 -05008258 list_del_init(&piocb->list);
8259 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05008260 }
James Smart6ede2dd2019-08-14 16:56:44 -07008261
8262 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8263 if (vport == phba->pport) {
8264 list_for_each_entry_safe(piocb, tmp_iocb,
8265 &phba->fabric_iocb_list, list) {
8266 cmd = &piocb->iocb;
8267 list_del_init(&piocb->list);
8268 list_add_tail(&piocb->list, &abort_list);
8269 }
8270 }
8271
James Smart0976e1a2013-12-17 20:29:36 -05008272 if (phba->sli_rev == LPFC_SLI_REV4)
8273 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008274 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart2534ba72007-04-25 09:52:20 -04008275
James Smart6ede2dd2019-08-14 16:56:44 -07008276 /* Cancel all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05008277 lpfc_sli_cancel_iocbs(phba, &abort_list,
8278 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04008279
dea31012005-04-17 16:05:31 -05008280 return;
8281}
8282
James Smarte59058c2008-08-24 21:49:00 -04008283/**
James Smart3621a712009-04-06 18:47:14 -04008284 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04008285 * @phba: pointer to lpfc hba data structure.
8286 *
8287 * This routine is used to clean up all the outstanding ELS commands on a
8288 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8289 * routine. After that, it walks the ELS transmit queue to remove all the
8290 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8291 * the IOCBs with the completion callback function associated, the callback
8292 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8293 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8294 * callback function associated, the IOCB will simply be released. Finally,
8295 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8296 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8297 * management plane IOCBs that are not part of the discovery state machine)
8298 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8299 **/
James Smart549e55c2007-08-02 11:09:51 -04008300void
8301lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8302{
James Smart0976e1a2013-12-17 20:29:36 -05008303 struct lpfc_vport *vport;
James Smart523128e2018-09-10 10:30:46 -07008304
8305 spin_lock_irq(&phba->port_list_lock);
James Smart0976e1a2013-12-17 20:29:36 -05008306 list_for_each_entry(vport, &phba->port_list, listentry)
8307 lpfc_els_flush_cmd(vport);
James Smart523128e2018-09-10 10:30:46 -07008308 spin_unlock_irq(&phba->port_list_lock);
James Smarta257bf92009-04-06 18:48:10 -04008309
James Smart549e55c2007-08-02 11:09:51 -04008310 return;
8311}
8312
James Smarte59058c2008-08-24 21:49:00 -04008313/**
James Smart3621a712009-04-06 18:47:14 -04008314 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04008315 * @phba: Pointer to hba context object.
8316 * @cmdiocbp: Pointer to command iocb which reported error.
8317 * @rspiocbp: Pointer to response iocb which reported error.
8318 *
8319 * This function sends an event when there is an ELS command
8320 * failure.
8321 **/
8322void
8323lpfc_send_els_failure_event(struct lpfc_hba *phba,
8324 struct lpfc_iocbq *cmdiocbp,
8325 struct lpfc_iocbq *rspiocbp)
8326{
8327 struct lpfc_vport *vport = cmdiocbp->vport;
8328 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8329 struct lpfc_lsrjt_event lsrjt_event;
8330 struct lpfc_fabric_event_header fabric_event;
8331 struct ls_rjt stat;
8332 struct lpfc_nodelist *ndlp;
8333 uint32_t *pcmd;
8334
8335 ndlp = cmdiocbp->context1;
James Smart307e3382020-11-15 11:26:30 -08008336 if (!ndlp)
James Smartea2151b2008-09-07 11:52:10 -04008337 return;
8338
8339 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8340 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8341 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8342 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8343 sizeof(struct lpfc_name));
8344 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8345 sizeof(struct lpfc_name));
8346 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8347 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04008348 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04008349 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8350 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8351 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8352 fc_host_post_vendor_event(shost,
8353 fc_get_event_number(),
8354 sizeof(lsrjt_event),
8355 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05008356 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008357 return;
8358 }
8359 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8360 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8361 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8362 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8363 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8364 else
8365 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8366 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8367 sizeof(struct lpfc_name));
8368 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8369 sizeof(struct lpfc_name));
8370 fc_host_post_vendor_event(shost,
8371 fc_get_event_number(),
8372 sizeof(fabric_event),
8373 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05008374 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008375 return;
8376 }
8377
8378}
8379
8380/**
James Smart3621a712009-04-06 18:47:14 -04008381 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04008382 * @vport: Pointer to vport object.
8383 * @ndlp: Pointer FC node object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01008384 * @payload: ELS command code type.
James Smartea2151b2008-09-07 11:52:10 -04008385 *
8386 * This function posts an event when there is an incoming
8387 * unsolicited ELS command.
8388 **/
8389static void
8390lpfc_send_els_event(struct lpfc_vport *vport,
8391 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05008392 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04008393{
James Smartddcc50f2008-12-04 22:38:46 -05008394 struct lpfc_els_event_header *els_data = NULL;
8395 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04008396 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8397
James Smartddcc50f2008-12-04 22:38:46 -05008398 if (*payload == ELS_CMD_LOGO) {
8399 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8400 if (!logo_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008401 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05008402 "0148 Failed to allocate memory "
8403 "for LOGO event\n");
8404 return;
8405 }
8406 els_data = &logo_data->header;
8407 } else {
8408 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8409 GFP_KERNEL);
8410 if (!els_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008411 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05008412 "0149 Failed to allocate memory "
8413 "for ELS event\n");
8414 return;
8415 }
8416 }
8417 els_data->event_type = FC_REG_ELS_EVENT;
8418 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04008419 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05008420 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008421 break;
8422 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05008423 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008424 break;
8425 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05008426 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8427 break;
8428 case ELS_CMD_LOGO:
8429 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8430 /* Copy the WWPN in the LOGO payload */
8431 memcpy(logo_data->logo_wwpn, &payload[2],
8432 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04008433 break;
8434 default:
Julia Lawalle9161412009-02-08 22:43:19 +01008435 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04008436 return;
8437 }
James Smartddcc50f2008-12-04 22:38:46 -05008438 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8439 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8440 if (*payload == ELS_CMD_LOGO) {
8441 fc_host_post_vendor_event(shost,
8442 fc_get_event_number(),
8443 sizeof(struct lpfc_logo_event),
8444 (char *)logo_data,
8445 LPFC_NL_VENDOR_ID);
8446 kfree(logo_data);
8447 } else {
8448 fc_host_post_vendor_event(shost,
8449 fc_get_event_number(),
8450 sizeof(struct lpfc_els_event_header),
8451 (char *)els_data,
8452 LPFC_NL_VENDOR_ID);
8453 kfree(els_data);
8454 }
James Smartea2151b2008-09-07 11:52:10 -04008455
8456 return;
8457}
8458
8459
James Smartdf3fe762020-02-10 09:31:55 -08008460DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8461 FC_LS_TLV_DTAG_INIT);
8462
8463DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8464 FC_FPIN_LI_EVT_TYPES_INIT);
8465
8466/**
8467 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8468 * @vport: Pointer to vport object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01008469 * @tlv: Pointer to the Link Integrity Notification Descriptor.
James Smartdf3fe762020-02-10 09:31:55 -08008470 *
8471 * This function processes a link integrity FPIN event by
8472 * logging a message
8473 **/
8474static void
8475lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8476{
8477 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8478 const char *li_evt_str;
8479 u32 li_evt;
8480
8481 li_evt = be16_to_cpu(li->event_type);
8482 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8483
8484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8485 "4680 FPIN Link Integrity %s (x%x) "
8486 "Detecting PN x%016llx Attached PN x%016llx "
8487 "Duration %d mSecs Count %d Port Cnt %d\n",
8488 li_evt_str, li_evt,
8489 be64_to_cpu(li->detecting_wwpn),
8490 be64_to_cpu(li->attached_wwpn),
8491 be32_to_cpu(li->event_threshold),
8492 be32_to_cpu(li->event_count),
8493 be32_to_cpu(li->pname_count));
8494}
8495
8496static void
8497lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8498 u32 fpin_length)
8499{
8500 struct fc_tlv_desc *tlv;
8501 const char *dtag_nm;
8502 uint32_t desc_cnt = 0, bytes_remain;
8503 u32 dtag;
8504
8505 /* FPINs handled only if we are in the right discovery state */
8506 if (vport->port_state < LPFC_DISC_AUTH)
8507 return;
8508
8509 /* make sure there is the full fpin header */
8510 if (fpin_length < sizeof(struct fc_els_fpin))
8511 return;
8512
8513 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8514 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8515 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8516
8517 /* process each descriptor */
8518 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8519 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8520
8521 dtag = be32_to_cpu(tlv->desc_tag);
8522 switch (dtag) {
8523 case ELS_DTAG_LNK_INTEGRITY:
8524 lpfc_els_rcv_fpin_li(vport, tlv);
8525 break;
8526 default:
8527 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
Dick Kennedy372c1872020-06-30 14:50:00 -07008528 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartdf3fe762020-02-10 09:31:55 -08008529 "4678 skipped FPIN descriptor[%d]: "
8530 "tag x%x (%s)\n",
8531 desc_cnt, dtag, dtag_nm);
8532 break;
8533 }
8534
8535 desc_cnt++;
8536 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8537 tlv = fc_tlv_next_desc(tlv);
8538 }
8539
8540 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8541 (char *)fpin);
8542}
8543
James Smartea2151b2008-09-07 11:52:10 -04008544/**
James Smart3621a712009-04-06 18:47:14 -04008545 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04008546 * @phba: pointer to lpfc hba data structure.
8547 * @pring: pointer to a SLI ring.
8548 * @vport: pointer to a host virtual N_Port data structure.
8549 * @elsiocb: pointer to lpfc els command iocb data structure.
8550 *
8551 * This routine is used for processing the IOCB associated with a unsolicited
8552 * event. It first determines whether there is an existing ndlp that matches
8553 * the DID from the unsolicited IOCB. If not, it will create a new one with
8554 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8555 * IOCB is then used to invoke the proper routine and to set up proper state
8556 * of the discovery state machine.
8557 **/
James Smarted957682007-06-17 19:56:37 -05008558static void
8559lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05008560 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05008561{
dea31012005-04-17 16:05:31 -05008562 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05008563 struct ls_rjt stat;
James Smartdf3fe762020-02-10 09:31:55 -08008564 uint32_t *payload, payload_len;
James Smart303f2f92013-01-03 15:43:11 -05008565 uint32_t cmd, did, newnode;
James Smartd496b9a2018-10-23 13:41:08 -07008566 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
James Smarted957682007-06-17 19:56:37 -05008567 IOCB_t *icmd = &elsiocb->iocb;
James Smartd496b9a2018-10-23 13:41:08 -07008568 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05008569
James Smarte47c9092008-02-08 18:49:26 -05008570 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05008571 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05008572
dea31012005-04-17 16:05:31 -05008573 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008574 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
James Smartdf3fe762020-02-10 09:31:55 -08008575 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
James Smart92d7f7b2007-06-17 19:56:38 -05008576 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05008577 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04008578 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05008579
James Smart858c9f62007-06-17 19:56:39 -05008580 did = icmd->un.rcvels.remoteID;
8581 if (icmd->ulpStatus) {
8582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8583 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8584 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05008585 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05008586 }
dea31012005-04-17 16:05:31 -05008587
8588 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05008589 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05008590 goto dropit;
dea31012005-04-17 16:05:31 -05008591
James Smartc8685952009-11-18 15:39:16 -05008592 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05008593 if (vport->load_flag & FC_UNLOADING)
8594 goto dropit;
8595
James Smart92494142011-02-16 12:39:44 -05008596 /* If NPort discovery is delayed drop incoming ELS */
8597 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8598 (cmd != ELS_CMD_PLOGI))
8599 goto dropit;
8600
James Smart2e0fef82007-06-17 19:56:36 -05008601 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008602 if (!ndlp) {
dea31012005-04-17 16:05:31 -05008603 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07008604 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05008605 if (!ndlp)
dea31012005-04-17 16:05:31 -05008606 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04008607 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05008608 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05008609 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05008610 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04008611 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
James Smart58da1ff2008-04-07 10:15:56 -04008612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8613 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04008614 }
dea31012005-04-17 16:05:31 -05008615
8616 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05008617
James Smart12838e72014-09-03 12:57:19 -04008618 /*
8619 * Do not process any unsolicited ELS commands
8620 * if the ndlp is in DEV_LOSS
8621 */
James Smartc6adba12020-11-15 11:26:34 -08008622 spin_lock_irq(&ndlp->lock);
James Smart466e8402015-05-21 13:55:28 -04008623 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
James Smartc6adba12020-11-15 11:26:34 -08008624 spin_unlock_irq(&ndlp->lock);
Xiyu Yang7217e6e2020-05-25 22:16:24 +08008625 if (newnode)
8626 lpfc_nlp_put(ndlp);
James Smart12838e72014-09-03 12:57:19 -04008627 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04008628 }
James Smartc6adba12020-11-15 11:26:34 -08008629 spin_unlock_irq(&ndlp->lock);
James Smart12838e72014-09-03 12:57:19 -04008630
James Smart329f9bc2007-04-25 09:53:01 -04008631 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008632 if (!elsiocb->context1)
8633 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05008634 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05008635
8636 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8637 cmd &= ELS_CMD_MASK;
8638 }
8639 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008640 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8641 "0112 ELS command x%x received from NPORT x%x "
James Smarta70e63e2020-11-15 11:26:38 -08008642 "refcnt %d Data: x%x x%x x%x x%x\n",
8643 cmd, did, kref_read(&ndlp->kref), vport->port_state,
8644 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04008645
James Smart0a9e9682018-11-29 16:09:36 -08008646 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
James Smarteec3d312015-08-31 16:48:18 -04008647 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smart0a9e9682018-11-29 16:09:36 -08008648 (cmd != ELS_CMD_FLOGI) &&
8649 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
James Smart401304c2016-10-13 15:06:14 -07008650 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04008651 rjt_exp = LSEXP_NOTHING_MORE;
8652 goto lsrjt;
8653 }
8654
dea31012005-04-17 16:05:31 -05008655 switch (cmd) {
8656 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8658 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8659 did, vport->port_state, ndlp->nlp_flag);
8660
dea31012005-04-17 16:05:31 -05008661 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05008662 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04008663 if (phba->sli_rev == LPFC_SLI_REV4 &&
8664 (phba->pport->fc_flag & FC_PT2PT)) {
8665 vport->fc_prevDID = vport->fc_myDID;
8666 /* Our DID needs to be updated before registering
8667 * the vfi. This is done in lpfc_rcv_plogi but
8668 * that is called after the reg_vfi.
8669 */
8670 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8672 "3312 Remote port assigned DID x%x "
8673 "%x\n", vport->fc_myDID,
8674 vport->fc_prevDID);
8675 }
James Smart858c9f62007-06-17 19:56:39 -05008676
James Smartddcc50f2008-12-04 22:38:46 -05008677 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05008678
8679 /* If Nport discovery is delayed, reject PLOGIs */
8680 if (vport->fc_flag & FC_DISC_DELAYED) {
8681 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008682 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05008683 break;
8684 }
James Smartd6de08c2015-12-16 18:11:53 -05008685
James Smart858c9f62007-06-17 19:56:39 -05008686 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05008687 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8688 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8689 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008690 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05008691 break;
8692 }
dea31012005-04-17 16:05:31 -05008693 }
James Smart87af33f2007-10-27 13:37:43 -04008694
James Smartc6adba12020-11-15 11:26:34 -08008695 spin_lock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04008696 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
James Smartc6adba12020-11-15 11:26:34 -08008697 spin_unlock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04008698
James Smart2e0fef82007-06-17 19:56:36 -05008699 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8700 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05008701
dea31012005-04-17 16:05:31 -05008702 break;
8703 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8705 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8706 did, vport->port_state, ndlp->nlp_flag);
8707
dea31012005-04-17 16:05:31 -05008708 phba->fc_stat.elsRcvFLOGI++;
James Smartd496b9a2018-10-23 13:41:08 -07008709
8710 /* If the driver believes fabric discovery is done and is ready,
8711 * bounce the link. There is some descrepancy.
8712 */
8713 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8714 vport->fc_flag & FC_PT2PT &&
8715 vport->rcv_flogi_cnt >= 1) {
8716 rjt_err = LSRJT_LOGICAL_BSY;
8717 rjt_exp = LSEXP_NOTHING_MORE;
8718 init_link++;
8719 goto lsrjt;
8720 }
8721
James Smart51ef4c22007-08-02 11:10:31 -04008722 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008723 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008724 lpfc_disc_state_machine(vport, ndlp, NULL,
8725 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05008726 break;
8727 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05008728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8729 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8730 did, vport->port_state, ndlp->nlp_flag);
8731
dea31012005-04-17 16:05:31 -05008732 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05008733 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05008734 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008735 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008736 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008737 break;
8738 }
James Smart2e0fef82007-06-17 19:56:36 -05008739 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05008740 break;
8741 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05008742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8743 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8744 did, vport->port_state, ndlp->nlp_flag);
8745
dea31012005-04-17 16:05:31 -05008746 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05008747 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05008748 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008749 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008750 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008751 break;
8752 }
James Smart2e0fef82007-06-17 19:56:36 -05008753 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05008754 break;
James Smart8b017a32015-05-21 13:55:18 -04008755 case ELS_CMD_LCB:
8756 phba->fc_stat.elsRcvLCB++;
8757 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8758 break;
James Smart86478872015-05-21 13:55:21 -04008759 case ELS_CMD_RDP:
8760 phba->fc_stat.elsRcvRDP++;
8761 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8762 break;
dea31012005-04-17 16:05:31 -05008763 case ELS_CMD_RSCN:
8764 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04008765 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008766 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008767 lpfc_disc_state_machine(vport, ndlp, NULL,
8768 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05008769 break;
8770 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05008771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8772 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8773 did, vport->port_state, ndlp->nlp_flag);
8774
James Smartddcc50f2008-12-04 22:38:46 -05008775 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05008776 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008777 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008778 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008779 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008780 break;
8781 }
James Smart2e0fef82007-06-17 19:56:36 -05008782 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8783 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05008784 break;
8785 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05008786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8787 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8788 did, vport->port_state, ndlp->nlp_flag);
8789
dea31012005-04-17 16:05:31 -05008790 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008791 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008792 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008793 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008794 break;
8795 }
James Smart2e0fef82007-06-17 19:56:36 -05008796 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8797 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05008798 break;
8799 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05008800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8801 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8802 did, vport->port_state, ndlp->nlp_flag);
8803
dea31012005-04-17 16:05:31 -05008804 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05008805 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008806 break;
8807 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05008808 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8809 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8810 did, vport->port_state, ndlp->nlp_flag);
8811
dea31012005-04-17 16:05:31 -05008812 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05008813 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008814 break;
8815 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05008816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8817 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8818 did, vport->port_state, ndlp->nlp_flag);
8819
dea31012005-04-17 16:05:31 -05008820 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05008821 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008822 break;
dea31012005-04-17 16:05:31 -05008823 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08008824 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05008825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8826 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8827 did, vport->port_state, ndlp->nlp_flag);
8828
dea31012005-04-17 16:05:31 -05008829 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04008830 if ((vport->port_state < LPFC_DISC_AUTH) &&
8831 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05008832 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008833 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008834 break;
8835 }
James Smart2e0fef82007-06-17 19:56:36 -05008836 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05008837 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008838 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05008839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8840 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8841 did, vport->port_state, ndlp->nlp_flag);
8842
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008843 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05008844 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008845 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008846 lpfc_disc_state_machine(vport, ndlp, NULL,
8847 NLP_EVT_DEVICE_RM);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008848 break;
James Smart12265f62010-10-22 11:05:53 -04008849 case ELS_CMD_RLS:
8850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8851 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8852 did, vport->port_state, ndlp->nlp_flag);
8853
8854 phba->fc_stat.elsRcvRLS++;
8855 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8856 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008857 lpfc_disc_state_machine(vport, ndlp, NULL,
8858 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -04008859 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008860 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05008861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8862 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8863 did, vport->port_state, ndlp->nlp_flag);
8864
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008865 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008866 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008867 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008868 lpfc_disc_state_machine(vport, ndlp, NULL,
8869 NLP_EVT_DEVICE_RM);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008870 break;
dea31012005-04-17 16:05:31 -05008871 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8873 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8874 did, vport->port_state, ndlp->nlp_flag);
8875
dea31012005-04-17 16:05:31 -05008876 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008877 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008878 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008879 lpfc_disc_state_machine(vport, ndlp, NULL,
8880 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05008881 break;
James Smart12265f62010-10-22 11:05:53 -04008882 case ELS_CMD_RTV:
8883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8884 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8885 did, vport->port_state, ndlp->nlp_flag);
8886 phba->fc_stat.elsRcvRTV++;
8887 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8888 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008889 lpfc_disc_state_machine(vport, ndlp, NULL,
8890 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -04008891 break;
James Smart5ffc2662009-11-18 15:39:44 -05008892 case ELS_CMD_RRQ:
8893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8894 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8895 did, vport->port_state, ndlp->nlp_flag);
8896
8897 phba->fc_stat.elsRcvRRQ++;
8898 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8899 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008900 lpfc_disc_state_machine(vport, ndlp, NULL,
8901 NLP_EVT_DEVICE_RM);
James Smart5ffc2662009-11-18 15:39:44 -05008902 break;
James Smart12265f62010-10-22 11:05:53 -04008903 case ELS_CMD_ECHO:
8904 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8905 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8906 did, vport->port_state, ndlp->nlp_flag);
8907
8908 phba->fc_stat.elsRcvECHO++;
8909 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8910 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008911 lpfc_disc_state_machine(vport, ndlp, NULL,
8912 NLP_EVT_DEVICE_RM);
James Smart12265f62010-10-22 11:05:53 -04008913 break;
James Smart303f2f92013-01-03 15:43:11 -05008914 case ELS_CMD_REC:
Colin Ian King8fd03fd2017-12-22 00:39:36 +00008915 /* receive this due to exchange closed */
8916 rjt_err = LSRJT_UNABLE_TPC;
8917 rjt_exp = LSEXP_INVALID_OX_RX;
James Smart303f2f92013-01-03 15:43:11 -05008918 break;
James Smart1a61e542019-04-05 16:04:23 -07008919 case ELS_CMD_FPIN:
James Smartdf3fe762020-02-10 09:31:55 -08008920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8921 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8922 did, vport->port_state, ndlp->nlp_flag);
8923
8924 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8925 payload_len);
8926
8927 /* There are no replies, so no rjt codes */
James Smart1a61e542019-04-05 16:04:23 -07008928 break;
dea31012005-04-17 16:05:31 -05008929 default:
James Smart858c9f62007-06-17 19:56:39 -05008930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8931 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8932 cmd, did, vport->port_state);
8933
dea31012005-04-17 16:05:31 -05008934 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008935 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008936 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008937
8938 /* Unknown ELS command <elsCmd> received from NPORT <did> */
Dick Kennedy372c1872020-06-30 14:50:00 -07008939 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04008940 "0115 Unknown ELS command x%x "
8941 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008942 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008943 lpfc_disc_state_machine(vport, ndlp, NULL,
8944 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05008945 break;
8946 }
8947
James Smarteec3d312015-08-31 16:48:18 -04008948lsrjt:
dea31012005-04-17 16:05:31 -05008949 /* check if need to LS_RJT received ELS cmd */
8950 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008951 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008952 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008953 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008954 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
James Smart4430f7f2020-11-15 11:26:31 -08008955 NULL);
8956 /* Remove the reference from above for new nodes. */
8957 if (newnode)
James Smart9d76d462020-11-15 11:26:36 -08008958 lpfc_disc_state_machine(vport, ndlp, NULL,
8959 NLP_EVT_DEVICE_RM);
dea31012005-04-17 16:05:31 -05008960 }
8961
James Smarte9b11082020-11-15 11:26:33 -08008962 /* Release the reference on this elsiocb, not the ndlp. */
James Smartd7c255b2008-08-24 21:50:00 -04008963 lpfc_nlp_put(elsiocb->context1);
8964 elsiocb->context1 = NULL;
James Smartd496b9a2018-10-23 13:41:08 -07008965
8966 /* Special case. Driver received an unsolicited command that
8967 * unsupportable given the driver's current state. Reset the
8968 * link and start over.
8969 */
8970 if (init_link) {
8971 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8972 if (!mbox)
8973 return;
8974 lpfc_linkdown(phba);
8975 lpfc_init_link(phba, mbox,
8976 phba->cfg_topology,
8977 phba->cfg_link_speed);
8978 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8979 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8980 mbox->vport = vport;
8981 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8982 MBX_NOT_FINISHED)
8983 mempool_free(mbox, phba->mbox_mem_pool);
8984 }
8985
James Smarted957682007-06-17 19:56:37 -05008986 return;
8987
8988dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008989 if (vport && !(vport->load_flag & FC_UNLOADING))
Dick Kennedy372c1872020-06-30 14:50:00 -07008990 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04008991 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008992 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008993 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008994 phba->fc_stat.elsRcvDrop++;
8995}
8996
James Smarte59058c2008-08-24 21:49:00 -04008997/**
James Smart3621a712009-04-06 18:47:14 -04008998 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008999 * @phba: pointer to lpfc hba data structure.
9000 * @pring: pointer to a SLI ring.
9001 * @elsiocb: pointer to lpfc els iocb data structure.
9002 *
9003 * This routine is used to process an unsolicited event received from a SLI
9004 * (Service Level Interface) ring. The actual processing of the data buffer
9005 * associated with the unsolicited event is done by invoking the routine
9006 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
9007 * SLI ring on which the unsolicited event was received.
9008 **/
James Smarted957682007-06-17 19:56:37 -05009009void
9010lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9011 struct lpfc_iocbq *elsiocb)
9012{
9013 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05009014 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05009015 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05009016 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9017 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05009018
James Smartd7c255b2008-08-24 21:50:00 -04009019 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05009020 elsiocb->context2 = NULL;
9021 elsiocb->context3 = NULL;
9022
9023 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9024 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9025 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04009026 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9027 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05009028 phba->fc_stat.NoRcvBuf++;
9029 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05009030 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04009031 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05009032 return;
9033 }
9034
James Smart92d7f7b2007-06-17 19:56:38 -05009035 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9036 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9037 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9038 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9039 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04009040 else
9041 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04009042 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05009043 }
James Smart6d368e52011-05-24 11:44:12 -04009044
James Smart7f5f3d02008-02-08 18:50:14 -05009045 /* If there are no BDEs associated
9046 * with this IOCB, there is nothing to do.
9047 */
James Smarted957682007-06-17 19:56:37 -05009048 if (icmd->ulpBdeCount == 0)
9049 return;
9050
James Smart7f5f3d02008-02-08 18:50:14 -05009051 /* type of ELS cmd is first 32bit word
9052 * in packet
9053 */
James Smarted957682007-06-17 19:56:37 -05009054 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05009055 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05009056 } else {
9057 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9058 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05009059 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9060 paddr);
James Smarted957682007-06-17 19:56:37 -05009061 }
9062
James Smart92d7f7b2007-06-17 19:56:38 -05009063 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9064 /*
9065 * The different unsolicited event handlers would tell us
9066 * if they are done with "mp" by setting context2 to NULL.
9067 */
dea31012005-04-17 16:05:31 -05009068 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009069 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9070 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05009071 }
James Smarted957682007-06-17 19:56:37 -05009072
9073 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05009074 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05009075 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009076 elsiocb->context2 = bdeBuf2;
9077 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05009078 /* free mp if we are done with it */
9079 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009080 lpfc_in_buf_free(phba, elsiocb->context2);
9081 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05009082 }
dea31012005-04-17 16:05:31 -05009083 }
dea31012005-04-17 16:05:31 -05009084}
James Smart92d7f7b2007-06-17 19:56:38 -05009085
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08009086static void
James Smart4258e982015-12-16 18:11:58 -05009087lpfc_start_fdmi(struct lpfc_vport *vport)
9088{
James Smart4258e982015-12-16 18:11:58 -05009089 struct lpfc_nodelist *ndlp;
9090
9091 /* If this is the first time, allocate an ndlp and initialize
9092 * it. Otherwise, make sure the node is enabled and then do the
9093 * login.
9094 */
9095 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9096 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07009097 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05009098 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05009099 ndlp->nlp_type |= NLP_FABRIC;
9100 } else {
9101 return;
9102 }
9103 }
James Smart4258e982015-12-16 18:11:58 -05009104
James Smart307e3382020-11-15 11:26:30 -08009105 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9106 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart4258e982015-12-16 18:11:58 -05009107}
9108
James Smarte59058c2008-08-24 21:49:00 -04009109/**
James Smart3621a712009-04-06 18:47:14 -04009110 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04009111 * @phba: pointer to lpfc hba data structure.
9112 * @vport: pointer to a virtual N_Port data structure.
9113 *
9114 * This routine issues a Port Login (PLOGI) to the Name Server with
9115 * State Change Request (SCR) for a @vport. This routine will create an
9116 * ndlp for the Name Server associated to the @vport if such node does
9117 * not already exist. The PLOGI to Name Server is issued by invoking the
9118 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9119 * (FDMI) is configured to the @vport, a FDMI node will be created and
9120 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9121 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009122void
9123lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9124{
James Smart4258e982015-12-16 18:11:58 -05009125 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05009126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9127
9128 /*
9129 * If lpfc_delay_discovery parameter is set and the clean address
9130 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9131 * discovery.
9132 */
9133 spin_lock_irq(shost->host_lock);
9134 if (vport->fc_flag & FC_DISC_DELAYED) {
9135 spin_unlock_irq(shost->host_lock);
James Smarta70e63e2020-11-15 11:26:38 -08009136 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9137 "3334 Delay fc port discovery for %d secs\n",
9138 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05009139 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04009140 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05009141 return;
9142 }
9143 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009144
9145 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9146 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07009147 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05009148 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05009149 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05009150 lpfc_disc_start(vport);
9151 return;
9152 }
9153 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009154 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009155 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009156 return;
9157 }
James Smart92d7f7b2007-06-17 19:56:38 -05009158 }
James Smart307e3382020-11-15 11:26:30 -08009159
James Smart58da1ff2008-04-07 10:15:56 -04009160 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05009161
9162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9163
9164 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9165 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009166 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009167 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009168 return;
9169 }
9170
James Smart8663cbb2016-03-31 14:12:33 -07009171 if ((phba->cfg_enable_SmartSAN ||
9172 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9173 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05009174 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009175}
9176
James Smarte59058c2008-08-24 21:49:00 -04009177/**
James Smart3621a712009-04-06 18:47:14 -04009178 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04009179 * @phba: pointer to lpfc hba data structure.
9180 * @pmb: pointer to the driver internal queue element for mailbox command.
9181 *
9182 * This routine is the completion callback function to register new vport
9183 * mailbox command. If the new vport mailbox command completes successfully,
9184 * the fabric registration login shall be performed on physical port (the
9185 * new vport created is actually a physical port, with VPI 0) or the port
9186 * login to Name Server for State Change Request (SCR) will be performed
9187 * on virtual port (real virtual port, with VPI greater than 0).
9188 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009189static void
9190lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9191{
9192 struct lpfc_vport *vport = pmb->vport;
9193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart3e1f0712018-11-29 16:09:29 -08009194 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart04c68492009-05-22 14:52:52 -04009195 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05009196 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009197
James Smart09372822008-01-11 01:52:54 -05009198 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009199 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009200 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009201
9202 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009203 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart38b92ef2010-08-04 16:11:39 -04009204 "0915 Register VPI failed : Status: x%x"
9205 " upd bit: x%x \n", mb->mbxStatus,
9206 mb->un.varRegVpi.upd);
9207 if (phba->sli_rev == LPFC_SLI_REV4 &&
9208 mb->un.varRegVpi.upd)
9209 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05009210
9211 switch (mb->mbxStatus) {
9212 case 0x11: /* unsupported feature */
9213 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05009214 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05009215 /* giving up on vport registration */
9216 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9217 spin_lock_irq(shost->host_lock);
9218 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9219 spin_unlock_irq(shost->host_lock);
9220 lpfc_can_disctmo(vport);
9221 break;
James Smart695a8142010-01-26 23:08:03 -05009222 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9223 case 0x20:
9224 spin_lock_irq(shost->host_lock);
9225 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9226 spin_unlock_irq(shost->host_lock);
9227 lpfc_init_vpi(phba, pmb, vport->vpi);
9228 pmb->vport = vport;
9229 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9230 rc = lpfc_sli_issue_mbox(phba, pmb,
9231 MBX_NOWAIT);
9232 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009233 lpfc_printf_vlog(vport, KERN_ERR,
9234 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -05009235 "2732 Failed to issue INIT_VPI"
9236 " mailbox command\n");
9237 } else {
9238 lpfc_nlp_put(ndlp);
9239 return;
9240 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05009241 fallthrough;
James Smart92d7f7b2007-06-17 19:56:38 -05009242 default:
9243 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04009244 if (phba->sli_rev == LPFC_SLI_REV4)
9245 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009246 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05009247 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009248 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009249 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08009250 if (mb->mbxStatus == MBX_NOT_FINISHED)
9251 break;
9252 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9253 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9254 if (phba->sli_rev == LPFC_SLI_REV4)
9255 lpfc_issue_init_vfi(vport);
9256 else
9257 lpfc_initial_flogi(vport);
9258 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05009259 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08009260 }
James Smart92d7f7b2007-06-17 19:56:38 -05009261 break;
9262 }
James Smart92d7f7b2007-06-17 19:56:38 -05009263 } else {
James Smart695a8142010-01-26 23:08:03 -05009264 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05009265 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05009266 spin_unlock_irq(shost->host_lock);
9267 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04009268 if (phba->sli_rev < LPFC_SLI_REV4)
9269 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05009270 else {
James Smartfc2b9892010-02-26 14:15:29 -05009271 /*
9272 * If the physical port is instantiated using
9273 * FDISC, do not start vport discovery.
9274 */
9275 if (vport->port_state != LPFC_FDISC)
9276 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05009277 lpfc_do_scr_ns_plogi(phba, vport);
9278 }
James Smarte9b11082020-11-15 11:26:33 -08009279 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05009280 lpfc_do_scr_ns_plogi(phba, vport);
James Smarte9b11082020-11-15 11:26:33 -08009281 }
James Smart92d7f7b2007-06-17 19:56:38 -05009282 }
James Smart38b92ef2010-08-04 16:11:39 -04009283mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05009284 /* Now, we decrement the ndlp reference count held for this
9285 * callback function
9286 */
9287 lpfc_nlp_put(ndlp);
9288
James Smart92d7f7b2007-06-17 19:56:38 -05009289 mempool_free(pmb, phba->mbox_mem_pool);
9290 return;
9291}
9292
James Smarte59058c2008-08-24 21:49:00 -04009293/**
James Smart3621a712009-04-06 18:47:14 -04009294 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04009295 * @phba: pointer to lpfc hba data structure.
9296 * @vport: pointer to a host virtual N_Port data structure.
9297 * @ndlp: pointer to a node-list data structure.
9298 *
9299 * This routine registers the @vport as a new virtual port with a HBA.
9300 * It is done through a registering vpi mailbox command.
9301 **/
James Smart695a8142010-01-26 23:08:03 -05009302void
James Smart92d7f7b2007-06-17 19:56:38 -05009303lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9304 struct lpfc_nodelist *ndlp)
9305{
James Smart09372822008-01-11 01:52:54 -05009306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009307 LPFC_MBOXQ_t *mbox;
9308
9309 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9310 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04009311 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05009312 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08009313 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08009314 if (!mbox->ctx_ndlp) {
9315 mempool_free(mbox, phba->mbox_mem_pool);
9316 goto mbox_err_exit;
9317 }
9318
James Smart92d7f7b2007-06-17 19:56:38 -05009319 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04009320 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05009321 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05009322 /* mailbox command not success, decrement ndlp
9323 * reference count for this command
9324 */
9325 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009326 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05009327
Dick Kennedy372c1872020-06-30 14:50:00 -07009328 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009329 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05009330 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009331 }
9332 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -07009333 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009334 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05009335 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009336 }
James Smartfa4066b2008-01-11 01:53:27 -05009337 return;
9338
9339mbox_err_exit:
9340 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9341 spin_lock_irq(shost->host_lock);
9342 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9343 spin_unlock_irq(shost->host_lock);
9344 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009345}
9346
James Smarte59058c2008-08-24 21:49:00 -04009347/**
James Smart0c9ab6f2010-02-26 14:15:57 -05009348 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05009349 * @phba: pointer to lpfc hba data structure.
9350 *
James Smart0c9ab6f2010-02-26 14:15:57 -05009351 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05009352 **/
9353void
James Smart0c9ab6f2010-02-26 14:15:57 -05009354lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05009355{
9356 struct lpfc_vport **vports;
9357 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05009358 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05009359 int i;
James Smart695a8142010-01-26 23:08:03 -05009360
9361 /* Treat this failure as linkdown for all vports */
9362 link_state = phba->link_state;
9363 lpfc_linkdown(phba);
9364 phba->link_state = link_state;
9365
9366 vports = lpfc_create_vport_work_array(phba);
9367
9368 if (vports) {
9369 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9370 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9371 if (ndlp)
9372 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9373 lpfc_els_flush_cmd(vports[i]);
9374 }
9375 lpfc_destroy_vport_work_array(phba, vports);
9376 }
James Smart0c9ab6f2010-02-26 14:15:57 -05009377}
9378
9379/**
9380 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9381 * @phba: pointer to lpfc hba data structure.
9382 *
9383 * This routine abort all pending discovery commands and
9384 * start a timer to retry FLOGI for the physical port
9385 * discovery.
9386 **/
9387void
9388lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9389{
9390 struct lpfc_nodelist *ndlp;
James Smart0c9ab6f2010-02-26 14:15:57 -05009391
9392 /* Cancel the all vports retry delay retry timers */
9393 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05009394
9395 /* If fabric require FLOGI, then re-instantiate physical login */
9396 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9397 if (!ndlp)
9398 return;
9399
James Smart256ec0d2013-04-17 20:14:58 -04009400 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smartc6adba12020-11-15 11:26:34 -08009401 spin_lock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -05009402 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08009403 spin_unlock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -05009404 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9405 phba->pport->port_state = LPFC_FLOGI;
9406 return;
9407}
9408
9409/**
9410 * lpfc_fabric_login_reqd - Check if FLOGI required.
9411 * @phba: pointer to lpfc hba data structure.
9412 * @cmdiocb: pointer to FDISC command iocb.
9413 * @rspiocb: pointer to FDISC response iocb.
9414 *
9415 * This routine checks if a FLOGI is reguired for FDISC
9416 * to succeed.
9417 **/
9418static int
9419lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9420 struct lpfc_iocbq *cmdiocb,
9421 struct lpfc_iocbq *rspiocb)
9422{
9423
9424 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9425 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9426 return 0;
9427 else
9428 return 1;
9429}
9430
9431/**
James Smart3621a712009-04-06 18:47:14 -04009432 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009433 * @phba: pointer to lpfc hba data structure.
9434 * @cmdiocb: pointer to lpfc command iocb data structure.
9435 * @rspiocb: pointer to lpfc response iocb data structure.
9436 *
9437 * This routine is the completion callback function to a Fabric Discover
9438 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9439 * single threaded, each FDISC completion callback function will reset
9440 * the discovery timer for all vports such that the timers will not get
9441 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9442 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9443 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9444 * assigned to the vport has been changed with the completion of the FDISC
9445 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9446 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9447 * routine is invoked to register new vport with the HBA. Otherwise, the
9448 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9449 * Server for State Change Request (SCR).
9450 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009451static void
9452lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9453 struct lpfc_iocbq *rspiocb)
9454{
9455 struct lpfc_vport *vport = cmdiocb->vport;
9456 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9457 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9458 struct lpfc_nodelist *np;
9459 struct lpfc_nodelist *next_np;
9460 IOCB_t *irsp = &rspiocb->iocb;
9461 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05009462 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9463 struct serv_parm *sp;
9464 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05009465
James Smarte8b62012007-08-02 11:10:09 -04009466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9467 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9468 irsp->ulpStatus, irsp->un.ulpWord[4],
9469 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05009470 /* Since all FDISCs are being single threaded, we
9471 * must reset the discovery timer for ALL vports
9472 * waiting to send FDISC when one completes.
9473 */
9474 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9475 lpfc_set_disctmo(piocb->vport);
9476 }
9477
James Smart858c9f62007-06-17 19:56:39 -05009478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9479 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9480 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9481
James Smart92d7f7b2007-06-17 19:56:38 -05009482 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05009483
9484 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9485 lpfc_retry_pport_discovery(phba);
9486 goto out;
9487 }
9488
James Smart92d7f7b2007-06-17 19:56:38 -05009489 /* Check for retry */
9490 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9491 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009492 /* FDISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07009493 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6b5151f2012-01-18 16:24:06 -05009494 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04009495 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04009496 goto fdisc_failed;
9497 }
James Smartd7c255b2008-08-24 21:50:00 -04009498 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05009499 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04009500 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04009501 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05009502 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04009503 vport->fc_flag |= FC_PUBLIC_LOOP;
9504 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009505
James Smartd7c255b2008-08-24 21:50:00 -04009506 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9507 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05009508 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04009509 if (!prsp)
9510 goto out;
James Smart92494142011-02-16 12:39:44 -05009511 sp = prsp->virt + sizeof(uint32_t);
9512 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9513 memcpy(&vport->fabric_portname, &sp->portName,
9514 sizeof(struct lpfc_name));
9515 memcpy(&vport->fabric_nodename, &sp->nodeName,
9516 sizeof(struct lpfc_name));
9517 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04009518 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9519 /* If our NportID changed, we need to ensure all
9520 * remaining NPORTs get unreg_login'ed so we can
9521 * issue unreg_vpi.
9522 */
9523 list_for_each_entry_safe(np, next_np,
9524 &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08009525 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
James Smartd7c255b2008-08-24 21:50:00 -04009526 !(np->nlp_flag & NLP_NPR_ADISC))
9527 continue;
James Smartc6adba12020-11-15 11:26:34 -08009528 spin_lock_irq(&ndlp->lock);
James Smartd7c255b2008-08-24 21:50:00 -04009529 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -08009530 spin_unlock_irq(&ndlp->lock);
James Smartd7c255b2008-08-24 21:50:00 -04009531 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05009532 }
James Smart78730cf2010-04-06 15:06:30 -04009533 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04009534
9535 if (phba->sli_rev == LPFC_SLI_REV4)
9536 lpfc_sli4_unreg_all_rpis(vport);
9537
James Smartd7c255b2008-08-24 21:50:00 -04009538 lpfc_mbx_unreg_vpi(vport);
9539 spin_lock_irq(shost->host_lock);
9540 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05009541 if (phba->sli_rev == LPFC_SLI_REV4)
9542 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04009543 else
9544 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04009545 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04009546 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9547 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9548 /*
9549 * Driver needs to re-reg VPI in order for f/w
9550 * to update the MAC address.
9551 */
9552 lpfc_register_new_vport(phba, vport, ndlp);
James Smarte9b11082020-11-15 11:26:33 -08009553 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart5ac6b302010-10-22 11:05:36 -04009554 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009555 }
9556
James Smartecfd03c2010-02-12 14:41:27 -05009557 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9558 lpfc_issue_init_vpi(vport);
9559 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04009560 lpfc_register_new_vport(phba, vport, ndlp);
9561 else
9562 lpfc_do_scr_ns_plogi(phba, vport);
James Smarte9b11082020-11-15 11:26:33 -08009563
9564 /* The FDISC completed successfully. Move the fabric ndlp to
9565 * UNMAPPED state and register with the transport.
9566 */
9567 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartd7c255b2008-08-24 21:50:00 -04009568 goto out;
James Smarte9b11082020-11-15 11:26:33 -08009569
James Smartd7c255b2008-08-24 21:50:00 -04009570fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -07009571 if (vport->fc_vport &&
9572 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -04009573 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04009574 /* Cancel discovery timer */
9575 lpfc_can_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009576out:
9577 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08009578 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009579}
9580
James Smarte59058c2008-08-24 21:49:00 -04009581/**
James Smart3621a712009-04-06 18:47:14 -04009582 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009583 * @vport: pointer to a virtual N_Port data structure.
9584 * @ndlp: pointer to a node-list data structure.
9585 * @retry: number of retries to the command IOCB.
9586 *
9587 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9588 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9589 * routine to issue the IOCB, which makes sure only one outstanding fabric
9590 * IOCB will be sent off HBA at any given time.
9591 *
9592 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9593 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9594 * will be stored into the context1 field of the IOCB for the completion
9595 * callback function to the FDISC ELS command.
9596 *
9597 * Return code
9598 * 0 - Successfully issued fdisc iocb command
9599 * 1 - Failed to issue fdisc iocb command
9600 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009601static int
James Smart92d7f7b2007-06-17 19:56:38 -05009602lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9603 uint8_t retry)
9604{
9605 struct lpfc_hba *phba = vport->phba;
9606 IOCB_t *icmd;
9607 struct lpfc_iocbq *elsiocb;
9608 struct serv_parm *sp;
9609 uint8_t *pcmd;
9610 uint16_t cmdsize;
9611 int did = ndlp->nlp_DID;
9612 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009613
James Smart5ffc2662009-11-18 15:39:44 -05009614 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05009615 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009616 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9617 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9618 ELS_CMD_FDISC);
9619 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05009620 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009621 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009622 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009623 return 1;
9624 }
9625
9626 icmd = &elsiocb->iocb;
9627 icmd->un.elsreq64.myID = 0;
9628 icmd->un.elsreq64.fl = 1;
9629
James Smart73d91e52011-10-10 21:32:10 -04009630 /*
9631 * SLI3 ports require a different context type value than SLI4.
9632 * Catch SLI3 ports here and override the prep.
9633 */
9634 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04009635 icmd->ulpCt_h = 1;
9636 icmd->ulpCt_l = 0;
9637 }
James Smart92d7f7b2007-06-17 19:56:38 -05009638
9639 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9640 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9641 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9642 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9643 sp = (struct serv_parm *) pcmd;
9644 /* Setup CSPs accordingly for Fabric */
9645 sp->cmn.e_d_tov = 0;
9646 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05009647 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009648 sp->cls1.classValid = 0;
9649 sp->cls2.seqDelivery = 1;
9650 sp->cls3.seqDelivery = 1;
9651
9652 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9653 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9654 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9655 pcmd += sizeof(uint32_t); /* Port Name */
9656 memcpy(pcmd, &vport->fc_portname, 8);
9657 pcmd += sizeof(uint32_t); /* Node Name */
9658 pcmd += sizeof(uint32_t); /* Node Name */
9659 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -07009660 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -07009661 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05009662 lpfc_set_disctmo(vport);
9663
9664 phba->fc_stat.elsXmitFDISC++;
9665 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9666
James Smart858c9f62007-06-17 19:56:39 -05009667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9668 "Issue FDISC: did:x%x",
9669 did, 0, 0);
9670
James Smart4430f7f2020-11-15 11:26:31 -08009671 elsiocb->context1 = lpfc_nlp_get(ndlp);
9672 if (!elsiocb->context1)
9673 goto err_out;
9674
James Smart92d7f7b2007-06-17 19:56:38 -05009675 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9676 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08009677 lpfc_nlp_put(ndlp);
9678 goto err_out;
James Smart92d7f7b2007-06-17 19:56:38 -05009679 }
James Smart4430f7f2020-11-15 11:26:31 -08009680
James Smart92d7f7b2007-06-17 19:56:38 -05009681 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05009682 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08009683
9684 err_out:
9685 lpfc_els_free_iocb(phba, elsiocb);
9686 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9687 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9688 "0256 Issue FDISC: Cannot send IOCB\n");
9689 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05009690}
9691
James Smarte59058c2008-08-24 21:49:00 -04009692/**
James Smart3621a712009-04-06 18:47:14 -04009693 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04009694 * @phba: pointer to lpfc hba data structure.
9695 * @cmdiocb: pointer to lpfc command iocb data structure.
9696 * @rspiocb: pointer to lpfc response iocb data structure.
9697 *
9698 * This routine is the completion callback function to the issuing of a LOGO
9699 * ELS command off a vport. It frees the command IOCB and then decrement the
9700 * reference count held on ndlp for this completion function, indicating that
9701 * the reference to the ndlp is no long needed. Note that the
9702 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9703 * callback function and an additional explicit ndlp reference decrementation
9704 * will trigger the actual release of the ndlp.
9705 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009706static void
9707lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9708 struct lpfc_iocbq *rspiocb)
9709{
9710 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05009711 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05009712 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04009713 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05009714
James Smart9589b0622011-04-16 11:03:17 -04009715 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05009716 irsp = &rspiocb->iocb;
9717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9718 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9719 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05009720
James Smart9589b0622011-04-16 11:03:17 -04009721 /* NPIV LOGO completes to NPort <nlp_DID> */
9722 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9723 "2928 NPIV LOGO completes to NPort x%x "
James Smarte9b11082020-11-15 11:26:33 -08009724 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
James Smart9589b0622011-04-16 11:03:17 -04009725 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarte9b11082020-11-15 11:26:33 -08009726 irsp->ulpTimeout, vport->num_disc_nodes,
9727 kref_read(&ndlp->kref), ndlp->nlp_flag,
9728 ndlp->fc4_xpt_flags);
James Smart9589b0622011-04-16 11:03:17 -04009729
9730 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9731 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009732 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04009733 vport->fc_flag &= ~FC_FABRIC;
9734 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009735 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04009736 }
James Smarte9b11082020-11-15 11:26:33 -08009737
9738 /* Safe to release resources now. */
9739 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08009740 lpfc_nlp_put(ndlp);
James Smarte9b11082020-11-15 11:26:33 -08009741 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smart92d7f7b2007-06-17 19:56:38 -05009742}
9743
James Smarte59058c2008-08-24 21:49:00 -04009744/**
James Smart3621a712009-04-06 18:47:14 -04009745 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04009746 * @vport: pointer to a virtual N_Port data structure.
9747 * @ndlp: pointer to a node-list data structure.
9748 *
9749 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9750 *
9751 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9752 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9753 * will be stored into the context1 field of the IOCB for the completion
9754 * callback function to the LOGO ELS command.
9755 *
9756 * Return codes
9757 * 0 - Successfully issued logo off the @vport
9758 * 1 - Failed to issue logo off the @vport
9759 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009760int
9761lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9762{
James Smart4430f7f2020-11-15 11:26:31 -08009763 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009764 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009765 struct lpfc_iocbq *elsiocb;
9766 uint8_t *pcmd;
9767 uint16_t cmdsize;
9768
9769 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9770 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9771 ELS_CMD_LOGO);
9772 if (!elsiocb)
9773 return 1;
9774
James Smart92d7f7b2007-06-17 19:56:38 -05009775 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9776 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9777 pcmd += sizeof(uint32_t);
9778
9779 /* Fill in LOGO payload */
9780 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9781 pcmd += sizeof(uint32_t);
9782 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9783
James Smart858c9f62007-06-17 19:56:39 -05009784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9785 "Issue LOGO npiv did:x%x flg:x%x",
9786 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9787
James Smart92d7f7b2007-06-17 19:56:38 -05009788 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
James Smartc6adba12020-11-15 11:26:34 -08009789 spin_lock_irq(&ndlp->lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009790 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -08009791 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08009792 elsiocb->context1 = lpfc_nlp_get(ndlp);
9793 if (!elsiocb->context1)
9794 goto node_err;
9795 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9796 if (rc == IOCB_ERROR)
9797 goto io_err;
James Smart92d7f7b2007-06-17 19:56:38 -05009798 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08009799
9800 io_err:
9801 lpfc_nlp_put(ndlp);
9802 node_err:
James Smartc6adba12020-11-15 11:26:34 -08009803 spin_lock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08009804 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smartc6adba12020-11-15 11:26:34 -08009805 spin_unlock_irq(&ndlp->lock);
James Smart4430f7f2020-11-15 11:26:31 -08009806 lpfc_els_free_iocb(phba, elsiocb);
9807 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05009808}
9809
James Smarte59058c2008-08-24 21:49:00 -04009810/**
James Smart3621a712009-04-06 18:47:14 -04009811 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01009812 * @t: timer context used to obtain the lpfc hba.
James Smarte59058c2008-08-24 21:49:00 -04009813 *
9814 * This routine is invoked by the fabric iocb block timer after
9815 * timeout. It posts the fabric iocb block timeout event by setting the
9816 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9817 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9818 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9819 * posted event WORKER_FABRIC_BLOCK_TMO.
9820 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009821void
Kees Cookf22eb4d2017-09-06 20:24:26 -07009822lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -05009823{
Kees Cookf22eb4d2017-09-06 20:24:26 -07009824 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -05009825 unsigned long iflags;
9826 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04009827
James Smart92d7f7b2007-06-17 19:56:38 -05009828 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9829 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9830 if (!tmo_posted)
9831 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9832 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9833
James Smart5e9d9b82008-06-14 22:52:53 -04009834 if (!tmo_posted)
9835 lpfc_worker_wake_up(phba);
9836 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009837}
9838
James Smarte59058c2008-08-24 21:49:00 -04009839/**
James Smart3621a712009-04-06 18:47:14 -04009840 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04009841 * @phba: pointer to lpfc hba data structure.
9842 *
9843 * This routine issues one fabric iocb from the driver internal list to
9844 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9845 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9846 * remove one pending fabric iocb from the driver internal list and invokes
9847 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9848 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009849static void
9850lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9851{
9852 struct lpfc_iocbq *iocb;
9853 unsigned long iflags;
9854 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05009855 IOCB_t *cmd;
9856
9857repeat:
9858 iocb = NULL;
9859 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05009860 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05009861 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9862 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9863 list);
9864 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05009865 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05009866 atomic_inc(&phba->fabric_iocb_count);
9867 }
9868 spin_unlock_irqrestore(&phba->hbalock, iflags);
9869 if (iocb) {
9870 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9871 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9872 iocb->iocb_flag |= LPFC_IO_FABRIC;
9873
James Smart858c9f62007-06-17 19:56:39 -05009874 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9875 "Fabric sched1: ste:x%x",
9876 iocb->vport->port_state, 0, 0);
9877
James Smart3772a992009-05-22 14:50:54 -04009878 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009879
9880 if (ret == IOCB_ERROR) {
9881 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9882 iocb->fabric_iocb_cmpl = NULL;
9883 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9884 cmd = &iocb->iocb;
9885 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9886 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9887 iocb->iocb_cmpl(phba, iocb, iocb);
9888
9889 atomic_dec(&phba->fabric_iocb_count);
9890 goto repeat;
9891 }
9892 }
James Smart92d7f7b2007-06-17 19:56:38 -05009893}
9894
James Smarte59058c2008-08-24 21:49:00 -04009895/**
James Smart3621a712009-04-06 18:47:14 -04009896 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009897 * @phba: pointer to lpfc hba data structure.
9898 *
9899 * This routine unblocks the issuing fabric iocb command. The function
9900 * will clear the fabric iocb block bit and then invoke the routine
9901 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9902 * from the driver internal fabric iocb list.
9903 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009904void
9905lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9906{
9907 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9908
9909 lpfc_resume_fabric_iocbs(phba);
9910 return;
9911}
9912
James Smarte59058c2008-08-24 21:49:00 -04009913/**
James Smart3621a712009-04-06 18:47:14 -04009914 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009915 * @phba: pointer to lpfc hba data structure.
9916 *
9917 * This routine blocks the issuing fabric iocb for a specified amount of
9918 * time (currently 100 ms). This is done by set the fabric iocb block bit
9919 * and set up a timeout timer for 100ms. When the block bit is set, no more
9920 * fabric iocb will be issued out of the HBA.
9921 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009922static void
9923lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9924{
9925 int blocked;
9926
9927 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009928 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009929 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009930 mod_timer(&phba->fabric_block_timer,
9931 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009932
9933 return;
9934}
9935
James Smarte59058c2008-08-24 21:49:00 -04009936/**
James Smart3621a712009-04-06 18:47:14 -04009937 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009938 * @phba: pointer to lpfc hba data structure.
9939 * @cmdiocb: pointer to lpfc command iocb data structure.
9940 * @rspiocb: pointer to lpfc response iocb data structure.
9941 *
9942 * This routine is the callback function that is put to the fabric iocb's
9943 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9944 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9945 * function first restores and invokes the original iocb's callback function
9946 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9947 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9948 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009949static void
9950lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9951 struct lpfc_iocbq *rspiocb)
9952{
9953 struct ls_rjt stat;
9954
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309955 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009956
9957 switch (rspiocb->iocb.ulpStatus) {
9958 case IOSTAT_NPORT_RJT:
9959 case IOSTAT_FABRIC_RJT:
9960 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9961 lpfc_block_fabric_iocbs(phba);
9962 }
9963 break;
9964
9965 case IOSTAT_NPORT_BSY:
9966 case IOSTAT_FABRIC_BSY:
9967 lpfc_block_fabric_iocbs(phba);
9968 break;
9969
9970 case IOSTAT_LS_RJT:
9971 stat.un.lsRjtError =
9972 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9973 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9974 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9975 lpfc_block_fabric_iocbs(phba);
9976 break;
9977 }
9978
James Smarta0f2d3e2017-02-12 13:52:31 -08009979 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009980
9981 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9982 cmdiocb->fabric_iocb_cmpl = NULL;
9983 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9984 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9985
9986 atomic_dec(&phba->fabric_iocb_count);
9987 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009988 /* Post any pending iocbs to HBA */
9989 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009990 }
9991}
9992
James Smarte59058c2008-08-24 21:49:00 -04009993/**
James Smart3621a712009-04-06 18:47:14 -04009994 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009995 * @phba: pointer to lpfc hba data structure.
9996 * @iocb: pointer to lpfc command iocb data structure.
9997 *
9998 * This routine is used as the top-level API for issuing a fabric iocb command
9999 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
10000 * function makes sure that only one fabric bound iocb will be outstanding at
10001 * any given time. As such, this function will first check to see whether there
10002 * is already an outstanding fabric iocb on the wire. If so, it will put the
10003 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
10004 * issued later. Otherwise, it will issue the iocb on the wire and update the
10005 * fabric iocb count it indicate that there is one fabric iocb on the wire.
10006 *
10007 * Note, this implementation has a potential sending out fabric IOCBs out of
10008 * order. The problem is caused by the construction of the "ready" boolen does
10009 * not include the condition that the internal fabric IOCB list is empty. As
10010 * such, it is possible a fabric IOCB issued by this routine might be "jump"
10011 * ahead of the fabric IOCBs in the internal list.
10012 *
10013 * Return code
10014 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10015 * IOCB_ERROR - failed to issue fabric iocb
10016 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010010017static int
James Smart92d7f7b2007-06-17 19:56:38 -050010018lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10019{
10020 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -050010021 int ready;
10022 int ret;
10023
James Smarta0f2d3e2017-02-12 13:52:31 -080010024 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -050010025
10026 spin_lock_irqsave(&phba->hbalock, iflags);
10027 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10028 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10029
James Smart7f5f3d02008-02-08 18:50:14 -050010030 if (ready)
10031 /* Increment fabric iocb count to hold the position */
10032 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -050010033 spin_unlock_irqrestore(&phba->hbalock, iflags);
10034 if (ready) {
10035 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10036 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10037 iocb->iocb_flag |= LPFC_IO_FABRIC;
10038
James Smart858c9f62007-06-17 19:56:39 -050010039 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10040 "Fabric sched2: ste:x%x",
10041 iocb->vport->port_state, 0, 0);
10042
James Smart3772a992009-05-22 14:50:54 -040010043 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -050010044
10045 if (ret == IOCB_ERROR) {
10046 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10047 iocb->fabric_iocb_cmpl = NULL;
10048 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10049 atomic_dec(&phba->fabric_iocb_count);
10050 }
10051 } else {
10052 spin_lock_irqsave(&phba->hbalock, iflags);
10053 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10054 spin_unlock_irqrestore(&phba->hbalock, iflags);
10055 ret = IOCB_SUCCESS;
10056 }
10057 return ret;
10058}
10059
James Smarte59058c2008-08-24 21:49:00 -040010060/**
James Smart3621a712009-04-06 18:47:14 -040010061 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010062 * @vport: pointer to a virtual N_Port data structure.
10063 *
10064 * This routine aborts all the IOCBs associated with a @vport from the
10065 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10066 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10067 * list, removes each IOCB associated with the @vport off the list, set the
10068 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10069 * associated with the IOCB.
10070 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010010071static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -050010072{
10073 LIST_HEAD(completions);
10074 struct lpfc_hba *phba = vport->phba;
10075 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -050010076
10077 spin_lock_irq(&phba->hbalock);
10078 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10079 list) {
10080
10081 if (piocb->vport != vport)
10082 continue;
10083
10084 list_move_tail(&piocb->list, &completions);
10085 }
10086 spin_unlock_irq(&phba->hbalock);
10087
James Smarta257bf92009-04-06 18:48:10 -040010088 /* Cancel all the IOCBs from the completions list */
10089 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10090 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010091}
10092
James Smarte59058c2008-08-24 21:49:00 -040010093/**
James Smart3621a712009-04-06 18:47:14 -040010094 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010095 * @ndlp: pointer to a node-list data structure.
10096 *
10097 * This routine aborts all the IOCBs associated with an @ndlp from the
10098 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10099 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10100 * list, removes each IOCB associated with the @ndlp off the list, set the
10101 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10102 * associated with the IOCB.
10103 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010104void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10105{
10106 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -040010107 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -050010108 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -080010109 struct lpfc_sli_ring *pring;
10110
10111 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -050010112
Dick Kennedy1234a6d2017-09-29 17:34:29 -070010113 if (unlikely(!pring))
10114 return;
10115
James Smart92d7f7b2007-06-17 19:56:38 -050010116 spin_lock_irq(&phba->hbalock);
10117 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10118 list) {
10119 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10120
10121 list_move_tail(&piocb->list, &completions);
10122 }
10123 }
10124 spin_unlock_irq(&phba->hbalock);
10125
James Smarta257bf92009-04-06 18:48:10 -040010126 /* Cancel all the IOCBs from the completions list */
10127 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10128 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010129}
10130
James Smarte59058c2008-08-24 21:49:00 -040010131/**
James Smart3621a712009-04-06 18:47:14 -040010132 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010133 * @phba: pointer to lpfc hba data structure.
10134 *
10135 * This routine aborts all the IOCBs currently on the driver internal
10136 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10137 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10138 * list, removes IOCBs off the list, set the status feild to
10139 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10140 * the IOCB.
10141 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010142void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10143{
10144 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -050010145
10146 spin_lock_irq(&phba->hbalock);
10147 list_splice_init(&phba->fabric_iocb_list, &completions);
10148 spin_unlock_irq(&phba->hbalock);
10149
James Smarta257bf92009-04-06 18:48:10 -040010150 /* Cancel all the IOCBs from the completions list */
10151 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10152 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010153}
James Smart6fb120a2009-05-22 14:52:59 -040010154
10155/**
James Smart1151e3e2011-02-16 12:39:35 -050010156 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10157 * @vport: pointer to lpfc vport data structure.
10158 *
10159 * This routine is invoked by the vport cleanup for deletions and the cleanup
10160 * for an ndlp on removal.
10161 **/
10162void
10163lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10164{
10165 struct lpfc_hba *phba = vport->phba;
10166 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10167 unsigned long iflag = 0;
10168
10169 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010170 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010171 list_for_each_entry_safe(sglq_entry, sglq_next,
10172 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
James Smart307e3382020-11-15 11:26:30 -080010173 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10174 lpfc_nlp_put(sglq_entry->ndlp);
James Smart1151e3e2011-02-16 12:39:35 -050010175 sglq_entry->ndlp = NULL;
James Smart307e3382020-11-15 11:26:30 -080010176 }
James Smart1151e3e2011-02-16 12:39:35 -050010177 }
James Smart895427b2017-02-12 13:52:30 -080010178 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010179 spin_unlock_irqrestore(&phba->hbalock, iflag);
10180 return;
10181}
10182
10183/**
James Smart6fb120a2009-05-22 14:52:59 -040010184 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10185 * @phba: pointer to lpfc hba data structure.
10186 * @axri: pointer to the els xri abort wcqe structure.
10187 *
10188 * This routine is invoked by the worker thread to process a SLI4 slow-path
10189 * ELS aborted xri.
10190 **/
10191void
10192lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10193 struct sli4_wcqe_xri_aborted *axri)
10194{
10195 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -050010196 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -040010197 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -050010198
James Smart6fb120a2009-05-22 14:52:59 -040010199 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10200 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -050010201 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -080010202 struct lpfc_sli_ring *pring;
10203
10204 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010205
James Smart0f65ff62010-02-26 14:14:23 -050010206 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010207 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010208 list_for_each_entry_safe(sglq_entry, sglq_next,
10209 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10210 if (sglq_entry->sli4_xritag == xri) {
10211 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -050010212 ndlp = sglq_entry->ndlp;
10213 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -040010214 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -080010215 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -050010216 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -080010217 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010218 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart307e3382020-11-15 11:26:30 -080010219
10220 if (ndlp) {
10221 lpfc_set_rrq_active(phba, ndlp,
10222 sglq_entry->sli4_lxritag,
10223 rxid, 1);
10224 lpfc_nlp_put(ndlp);
10225 }
James Smart589a52d2010-07-14 15:30:54 -040010226
10227 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -070010228 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -040010229 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010230 return;
10231 }
10232 }
James Smart895427b2017-02-12 13:52:30 -080010233 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010234 lxri = lpfc_sli4_xri_inrange(phba, xri);
10235 if (lxri == NO_XRI) {
10236 spin_unlock_irqrestore(&phba->hbalock, iflag);
10237 return;
10238 }
James Smart895427b2017-02-12 13:52:30 -080010239 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010240 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -050010241 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -080010242 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010243 spin_unlock_irqrestore(&phba->hbalock, iflag);
10244 return;
10245 }
10246 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -080010247 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010248 spin_unlock_irqrestore(&phba->hbalock, iflag);
10249 return;
James Smart6fb120a2009-05-22 14:52:59 -040010250}
James Smart086a3452012-08-14 14:25:21 -040010251
10252/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10253 * @vport: pointer to virtual port object.
10254 * @ndlp: nodelist pointer for the impacted node.
10255 *
10256 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10257 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10258 * the driver is required to send a LOGO to the remote node before it
10259 * attempts to recover its login to the remote node.
10260 */
10261void
10262lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10263 struct lpfc_nodelist *ndlp)
10264{
10265 struct Scsi_Host *shost;
10266 struct lpfc_hba *phba;
10267 unsigned long flags = 0;
10268
10269 shost = lpfc_shost_from_vport(vport);
10270 phba = vport->phba;
10271 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10272 lpfc_printf_log(phba, KERN_INFO,
10273 LOG_SLI, "3093 No rport recovery needed. "
10274 "rport in state 0x%x\n", ndlp->nlp_state);
10275 return;
10276 }
Dick Kennedy372c1872020-06-30 14:50:00 -070010277 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart086a3452012-08-14 14:25:21 -040010278 "3094 Start rport recovery on shost id 0x%x "
10279 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10280 "flags 0x%x\n",
10281 shost->host_no, ndlp->nlp_DID,
10282 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10283 ndlp->nlp_flag);
10284 /*
10285 * The rport is not responding. Remove the FCP-2 flag to prevent
10286 * an ADISC in the follow-up recovery code.
10287 */
James Smartc6adba12020-11-15 11:26:34 -080010288 spin_lock_irqsave(&ndlp->lock, flags);
James Smart086a3452012-08-14 14:25:21 -040010289 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart30e196c2018-10-23 13:41:03 -070010290 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
James Smartc6adba12020-11-15 11:26:34 -080010291 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart30e196c2018-10-23 13:41:03 -070010292 lpfc_unreg_rpi(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -040010293}
10294