blob: 44e99e7872f3f1e8552ea43b20e1d973280a764b [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;
772 spin_lock_irq(shost->host_lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(shost->host_lock);
775 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);
918 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500920 spin_unlock_irq(shost->host_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 Smart07951072007-04-25 09:51:38 -04001427 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001428 }
1429 }
James Smart2e0fef82007-06-17 19:56:36 -05001430 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001431
1432 return 0;
1433}
1434
James Smarte59058c2008-08-24 21:49:00 -04001435/**
James Smart3621a712009-04-06 18:47:14 -04001436 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001437 * @vport: pointer to a host virtual N_Port data structure.
1438 *
1439 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1440 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1441 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1442 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1443 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1444 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1445 * @vport.
1446 *
1447 * Return code
1448 * 0 - failed to issue initial flogi for @vport
1449 * 1 - successfully issued initial flogi for @vport
1450 **/
dea31012005-04-17 16:05:31 -05001451int
James Smart2e0fef82007-06-17 19:56:36 -05001452lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001453{
1454 struct lpfc_nodelist *ndlp;
1455
James Smart98c9ea52007-10-27 13:37:33 -04001456 vport->port_state = LPFC_FLOGI;
1457 lpfc_set_disctmo(vport);
1458
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001459 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001460 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001461 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001462 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001463 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001464 if (!ndlp)
1465 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001466 /* Set the node type */
1467 ndlp->nlp_type |= NLP_FABRIC;
James Smart307e3382020-11-15 11:26:30 -08001468
James Smarte47c9092008-02-08 18:49:26 -05001469 /* Put ndlp onto node list */
1470 lpfc_enqueue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001471 }
James Smart87af33f2007-10-27 13:37:43 -04001472
James Smart5ac6b302010-10-22 11:05:36 -04001473 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001474 /* This decrement of reference count to node shall kick off
1475 * the release of the node.
1476 */
James Smart329f9bc2007-04-25 09:53:01 -04001477 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001478 return 0;
1479 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001480 return 1;
dea31012005-04-17 16:05:31 -05001481}
1482
James Smarte59058c2008-08-24 21:49:00 -04001483/**
James Smart3621a712009-04-06 18:47:14 -04001484 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001485 * @vport: pointer to a host virtual N_Port data structure.
1486 *
1487 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1488 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1489 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1490 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1491 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1492 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1493 * @vport.
1494 *
1495 * Return code
1496 * 0 - failed to issue initial fdisc for @vport
1497 * 1 - successfully issued initial fdisc for @vport
1498 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001499int
1500lpfc_initial_fdisc(struct lpfc_vport *vport)
1501{
James Smart92d7f7b2007-06-17 19:56:38 -05001502 struct lpfc_nodelist *ndlp;
1503
1504 /* First look for the Fabric ndlp */
1505 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1506 if (!ndlp) {
1507 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001508 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001509 if (!ndlp)
1510 return 0;
James Smarte47c9092008-02-08 18:49:26 -05001511 /* Put ndlp onto node list */
1512 lpfc_enqueue_node(vport, ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001513 }
James Smarte47c9092008-02-08 18:49:26 -05001514
James Smart92d7f7b2007-06-17 19:56:38 -05001515 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001516 /* decrement node reference count to trigger the release of
1517 * the node.
1518 */
James Smart92d7f7b2007-06-17 19:56:38 -05001519 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001520 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001521 }
1522 return 1;
1523}
James Smart87af33f2007-10-27 13:37:43 -04001524
James Smarte59058c2008-08-24 21:49:00 -04001525/**
James Smart3621a712009-04-06 18:47:14 -04001526 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001527 * @vport: pointer to a host virtual N_Port data structure.
1528 *
1529 * This routine checks whether there are more remaining Port Logins
1530 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1531 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1532 * to issue ELS PLOGIs up to the configured discover threads with the
1533 * @vport (@vport->cfg_discovery_threads). The function also decrement
1534 * the @vport's num_disc_node by 1 if it is not already 0.
1535 **/
James Smart87af33f2007-10-27 13:37:43 -04001536void
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001538{
James Smart2e0fef82007-06-17 19:56:36 -05001539 if (vport->num_disc_nodes)
1540 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001541
1542 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001543 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1544 "0232 Continue discovery with %d PLOGIs to go "
1545 "Data: x%x x%x x%x\n",
1546 vport->num_disc_nodes, vport->fc_plogi_cnt,
1547 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001548 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001549 if (vport->fc_flag & FC_NLP_MORE)
1550 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001551 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001552
dea31012005-04-17 16:05:31 -05001553 return;
1554}
1555
James Smarte59058c2008-08-24 21:49:00 -04001556/**
James Smart3621a712009-04-06 18:47:14 -04001557 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001558 * @phba: pointer to lpfc hba data structure.
1559 * @prsp: pointer to response IOCB payload.
1560 * @ndlp: pointer to a node-list data structure.
1561 *
1562 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1563 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1564 * The following cases are considered N_Port confirmed:
1565 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1566 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1567 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1568 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1569 * 1) if there is a node on vport list other than the @ndlp with the same
1570 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1571 * on that node to release the RPI associated with the node; 2) if there is
1572 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1573 * into, a new node shall be allocated (or activated). In either case, the
1574 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1575 * be released and the new_ndlp shall be put on to the vport node list and
1576 * its pointer returned as the confirmed node.
1577 *
1578 * Note that before the @ndlp got "released", the keepDID from not-matching
1579 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1580 * of the @ndlp. This is because the release of @ndlp is actually to put it
1581 * into an inactive state on the vport node list and the vport node list
1582 * management algorithm does not allow two node with a same DID.
1583 *
1584 * Return code
1585 * pointer to the PLOGI N_Port @ndlp
1586 **/
James Smart488d1462006-03-07 15:02:37 -05001587static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001588lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001589 struct lpfc_nodelist *ndlp)
1590{
James Smarta0f2d3e2017-02-12 13:52:31 -08001591 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001593 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001594 struct lpfc_rport_data *rdata;
1595 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001596 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001597 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001598 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart92ea83a2018-11-29 16:09:34 -08001599 uint32_t keep_new_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001600 uint16_t keep_nlp_state;
James Smart92ea83a2018-11-29 16:09:34 -08001601 u32 keep_nlp_fc4_type = 0;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001602 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smart38b92ef2010-08-04 16:11:39 -04001603 int put_node;
1604 int put_rport;
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 Smart953ceed2015-05-22 10:42:37 -04001684 spin_lock_irq(shost->host_lock);
James Smart92ea83a2018-11-29 16:09:34 -08001685 keep_new_nlp_flag = new_ndlp->nlp_flag;
1686 keep_nlp_flag = ndlp->nlp_flag;
James Smarte5abba42015-05-21 13:55:27 -04001687 new_ndlp->nlp_flag = ndlp->nlp_flag;
James Smartdea16bd2018-11-29 16:09:30 -08001688
1689 /* if new_ndlp had NLP_UNREG_INP set, keep it */
James Smart92ea83a2018-11-29 16:09:34 -08001690 if (keep_new_nlp_flag & NLP_UNREG_INP)
James Smartdea16bd2018-11-29 16:09:30 -08001691 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1692 else
1693 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1694
James Smart92ea83a2018-11-29 16:09:34 -08001695 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1696 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1697 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001698 else
James Smart92ea83a2018-11-29 16:09:34 -08001699 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1700
1701 ndlp->nlp_flag = keep_new_nlp_flag;
1702
1703 /* if ndlp had NLP_UNREG_INP set, keep it */
1704 if (keep_nlp_flag & NLP_UNREG_INP)
1705 ndlp->nlp_flag |= NLP_UNREG_INP;
1706 else
1707 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1708
1709 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1710 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1711 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1712 else
1713 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001714
James Smart953ceed2015-05-22 10:42:37 -04001715 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001716
James Smart953ceed2015-05-22 10:42:37 -04001717 /* Set nlp_states accordingly */
1718 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001719 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001720
Dick Kennedy4adc0412017-08-23 16:55:37 -07001721 /* interchange the nvme remoteport structs */
1722 keep_nrport = new_ndlp->nrport;
1723 new_ndlp->nrport = ndlp->nrport;
1724
James Smart2e0fef82007-06-17 19:56:36 -05001725 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001726 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1727 /* The new_ndlp is replacing ndlp totally, so we need
1728 * to put ndlp on UNUSED list and try to free it.
1729 */
James Smart34f5ad82012-08-03 12:35:03 -04001730 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1731 "3179 PLOGI confirm NEW: %x %x\n",
1732 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001733
1734 /* Fix up the rport accordingly */
1735 rport = ndlp->rport;
1736 if (rport) {
1737 rdata = rport->dd_data;
1738 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001739 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001740 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001741 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001742 rdata->pnode = lpfc_nlp_get(new_ndlp);
1743 new_ndlp->rport = rport;
1744 }
1745 new_ndlp->nlp_type = ndlp->nlp_type;
1746 }
Dick Kennedy4adc0412017-08-23 16:55:37 -07001747
1748 /* Fix up the nvme rport */
1749 if (ndlp->nrport) {
1750 ndlp->nrport = NULL;
1751 lpfc_nlp_put(ndlp);
1752 }
1753
James Smart92ea83a2018-11-29 16:09:34 -08001754 /* Two ndlps cannot have the same did on the nodelist.
1755 * Note: for this case, ndlp has a NULL WWPN so setting
1756 * the nlp_fc4_type isn't required.
1757 */
James Smart58da1ff2008-04-07 10:15:56 -04001758 ndlp->nlp_DID = keepDID;
James Smart49382502017-11-20 16:00:38 -08001759 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smartcff261f2013-12-17 20:29:47 -05001760 if (phba->sli_rev == LPFC_SLI_REV4 &&
1761 active_rrqs_xri_bitmap)
1762 memcpy(ndlp->active_rrqs_xri_bitmap,
1763 active_rrqs_xri_bitmap,
1764 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001765
James Smart307e3382020-11-15 11:26:30 -08001766 } else {
James Smart34f5ad82012-08-03 12:35:03 -04001767 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1768 "3180 PLOGI confirm SWAP: %x %x\n",
1769 new_ndlp->nlp_DID, keepDID);
1770
James Smart2e0fef82007-06-17 19:56:36 -05001771 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001772
James Smart92ea83a2018-11-29 16:09:34 -08001773 /* Two ndlps cannot have the same did and the fc4
1774 * type must be transferred because the ndlp is in
1775 * flight.
1776 */
James Smart58da1ff2008-04-07 10:15:56 -04001777 ndlp->nlp_DID = keepDID;
James Smart92ea83a2018-11-29 16:09:34 -08001778 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1779
James Smartcff261f2013-12-17 20:29:47 -05001780 if (phba->sli_rev == LPFC_SLI_REV4 &&
1781 active_rrqs_xri_bitmap)
1782 memcpy(ndlp->active_rrqs_xri_bitmap,
1783 active_rrqs_xri_bitmap,
1784 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001785
James Smart953ceed2015-05-22 10:42:37 -04001786 /* Since we are switching over to the new_ndlp,
1787 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001788 */
1789 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1790 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001791 keep_nlp_state = NLP_STE_NPR_NODE;
1792 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001793
Dick Kennedy4adc0412017-08-23 16:55:37 -07001794 /* Previous ndlp no longer active with nvme host transport.
1795 * Remove reference from earlier registration unless the
1796 * nvme host took care of it.
1797 */
1798 if (ndlp->nrport)
1799 lpfc_nlp_put(ndlp);
1800 ndlp->nrport = keep_nrport;
1801
James Smart38b92ef2010-08-04 16:11:39 -04001802 /* Fix up the rport accordingly */
1803 rport = ndlp->rport;
1804 if (rport) {
1805 rdata = rport->dd_data;
1806 put_node = rdata->pnode != NULL;
1807 put_rport = ndlp->rport != NULL;
1808 rdata->pnode = NULL;
1809 ndlp->rport = NULL;
1810 if (put_node)
1811 lpfc_nlp_put(ndlp);
1812 if (put_rport)
1813 put_device(&rport->dev);
1814 }
James Smart92795652006-07-06 15:50:02 -04001815 }
James Smart307e3382020-11-15 11:26:30 -08001816
1817 /*
1818 * If ndlp is not associated with any rport we can drop it here else
1819 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1820 */
1821 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1822 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1823
James Smartcff261f2013-12-17 20:29:47 -05001824 if (phba->sli_rev == LPFC_SLI_REV4 &&
1825 active_rrqs_xri_bitmap)
1826 mempool_free(active_rrqs_xri_bitmap,
1827 phba->active_rrq_pool);
James Smartd83ca3e2018-10-23 13:41:09 -07001828
1829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1830 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1831 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1832 new_ndlp->nlp_fc4_type);
1833
James Smart488d1462006-03-07 15:02:37 -05001834 return new_ndlp;
1835}
1836
James Smarte59058c2008-08-24 21:49:00 -04001837/**
James Smart3621a712009-04-06 18:47:14 -04001838 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001839 * @vport: pointer to a host virtual N_Port data structure.
1840 *
1841 * This routine checks whether more Registration State Change
1842 * Notifications (RSCNs) came in while the discovery state machine was in
1843 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1844 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1845 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1846 * handling the RSCNs.
1847 **/
James Smart87af33f2007-10-27 13:37:43 -04001848void
1849lpfc_end_rscn(struct lpfc_vport *vport)
1850{
1851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1852
1853 if (vport->fc_flag & FC_RSCN_MODE) {
1854 /*
1855 * Check to see if more RSCNs came in while we were
1856 * processing this one.
1857 */
1858 if (vport->fc_rscn_id_cnt ||
1859 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1860 lpfc_els_handle_rscn(vport);
1861 else {
1862 spin_lock_irq(shost->host_lock);
1863 vport->fc_flag &= ~FC_RSCN_MODE;
1864 spin_unlock_irq(shost->host_lock);
1865 }
1866 }
1867}
1868
James Smarte59058c2008-08-24 21:49:00 -04001869/**
James Smart19ca7602010-11-20 23:11:55 -05001870 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1871 * @phba: pointer to lpfc hba data structure.
1872 * @cmdiocb: pointer to lpfc command iocb data structure.
1873 * @rspiocb: pointer to lpfc response iocb data structure.
1874 *
1875 * This routine will call the clear rrq function to free the rrq and
1876 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1877 * exist then the clear_rrq is still called because the rrq needs to
1878 * be freed.
1879 **/
1880
1881static void
1882lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1883 struct lpfc_iocbq *rspiocb)
1884{
1885 struct lpfc_vport *vport = cmdiocb->vport;
1886 IOCB_t *irsp;
1887 struct lpfc_nodelist *ndlp;
1888 struct lpfc_node_rrq *rrq;
1889
1890 /* we pass cmdiocb to state machine which needs rspiocb as well */
1891 rrq = cmdiocb->context_un.rrq;
1892 cmdiocb->context_un.rsp_iocb = rspiocb;
1893
1894 irsp = &rspiocb->iocb;
1895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1896 "RRQ cmpl: status:x%x/x%x did:x%x",
1897 irsp->ulpStatus, irsp->un.ulpWord[4],
1898 irsp->un.elsreq64.remoteID);
1899
1900 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart307e3382020-11-15 11:26:30 -08001901 if (!ndlp || ndlp != rrq->ndlp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001902 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart19ca7602010-11-20 23:11:55 -05001903 "2882 RRQ completes to NPort x%x "
1904 "with no ndlp. Data: x%x x%x x%x\n",
1905 irsp->un.elsreq64.remoteID,
1906 irsp->ulpStatus, irsp->un.ulpWord[4],
1907 irsp->ulpIoTag);
1908 goto out;
1909 }
1910
1911 /* rrq completes to NPort <nlp_DID> */
1912 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1913 "2880 RRQ completes to NPort x%x "
1914 "Data: x%x x%x x%x x%x x%x\n",
1915 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1916 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1917
1918 if (irsp->ulpStatus) {
1919 /* Check for retry */
1920 /* RRQ failed Don't print the vport to vport rjts */
1921 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1922 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1923 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1924 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07001925 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1926 "2881 RRQ failure DID:%06X Status:"
1927 "x%x/x%x\n",
1928 ndlp->nlp_DID, irsp->ulpStatus,
1929 irsp->un.ulpWord[4]);
James Smart19ca7602010-11-20 23:11:55 -05001930 }
1931out:
1932 if (rrq)
1933 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
James Smart4430f7f2020-11-15 11:26:31 -08001934
James Smart19ca7602010-11-20 23:11:55 -05001935 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08001936 lpfc_nlp_put(ndlp);
James Smart19ca7602010-11-20 23:11:55 -05001937 return;
1938}
1939/**
James Smart3621a712009-04-06 18:47:14 -04001940 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001941 * @phba: pointer to lpfc hba data structure.
1942 * @cmdiocb: pointer to lpfc command iocb data structure.
1943 * @rspiocb: pointer to lpfc response iocb data structure.
1944 *
1945 * This routine is the completion callback function for issuing the Port
1946 * Login (PLOGI) command. For PLOGI completion, there must be an active
1947 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001948 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001949 * ignored and command IOCB released. The PLOGI response IOCB status is
1950 * checked for error conditons. If there is error status reported, PLOGI
1951 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1952 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1953 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1954 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1955 * there are additional N_Port nodes with the vport that need to perform
1956 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1957 * PLOGIs.
1958 **/
dea31012005-04-17 16:05:31 -05001959static void
James Smart2e0fef82007-06-17 19:56:36 -05001960lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1961 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001962{
James Smart2e0fef82007-06-17 19:56:36 -05001963 struct lpfc_vport *vport = cmdiocb->vport;
1964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001965 IOCB_t *irsp;
James Smart4430f7f2020-11-15 11:26:31 -08001966 struct lpfc_nodelist *ndlp, *free_ndlp;
James Smart92795652006-07-06 15:50:02 -04001967 struct lpfc_dmabuf *prsp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07001968 int disc;
dea31012005-04-17 16:05:31 -05001969
dea31012005-04-17 16:05:31 -05001970 /* we pass cmdiocb to state machine which needs rspiocb as well */
1971 cmdiocb->context_un.rsp_iocb = rspiocb;
1972
1973 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1975 "PLOGI cmpl: status:x%x/x%x did:x%x",
1976 irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->un.elsreq64.remoteID);
1978
James Smart2e0fef82007-06-17 19:56:36 -05001979 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart307e3382020-11-15 11:26:30 -08001980 if (!ndlp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001981 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001982 "0136 PLOGI completes to NPort x%x "
1983 "with no ndlp. Data: x%x x%x x%x\n",
1984 irsp->un.elsreq64.remoteID,
1985 irsp->ulpStatus, irsp->un.ulpWord[4],
1986 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001987 goto out;
James Smarted957682007-06-17 19:56:37 -05001988 }
dea31012005-04-17 16:05:31 -05001989
1990 /* Since ndlp can be freed in the disc state machine, note if this node
1991 * is being used during discovery.
1992 */
James Smart2e0fef82007-06-17 19:56:36 -05001993 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001994 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001995 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001996 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001997
1998 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001999 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002000 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002001 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08002002 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2003 irsp->ulpStatus, irsp->un.ulpWord[4],
2004 disc, vport->num_disc_nodes);
2005
dea31012005-04-17 16:05:31 -05002006 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002007 if (lpfc_els_chk_latt(vport)) {
2008 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002009 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002010 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002011 goto out;
2012 }
2013
dea31012005-04-17 16:05:31 -05002014 if (irsp->ulpStatus) {
2015 /* Check for retry */
2016 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2017 /* ELS command is being retried */
2018 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002019 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002020 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002021 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002022 }
2023 goto out;
2024 }
James Smart2a9bf3d2010-06-07 15:24:45 -04002025 /* PLOGI failed Don't print the vport to vport rjts */
2026 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2027 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2028 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2029 (phba)->pport->cfg_log_verbose & LOG_ELS)
Dick Kennedy372c1872020-06-30 14:50:00 -07002030 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05002031 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2032 ndlp->nlp_DID, irsp->ulpStatus,
2033 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002034 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002035 if (!lpfc_error_lost_link(irsp))
2036 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2037 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002038 } else {
2039 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04002040 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05002041 cmdiocb->context2)->list.next,
2042 struct lpfc_dmabuf, list);
2043 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002044 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002045 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002046 }
2047
James Smart2e0fef82007-06-17 19:56:36 -05002048 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05002049 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002050 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05002051
James Smart2e0fef82007-06-17 19:56:36 -05002052 if (vport->num_disc_nodes == 0) {
2053 spin_lock_irq(shost->host_lock);
2054 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2055 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002056
James Smart2e0fef82007-06-17 19:56:36 -05002057 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04002058 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05002059 }
2060 }
2061
2062out:
James Smart4430f7f2020-11-15 11:26:31 -08002063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2064 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2065 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2066
2067 /* Release the reference on the original I/O request. */
2068 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2069
dea31012005-04-17 16:05:31 -05002070 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002071 lpfc_nlp_put(free_ndlp);
dea31012005-04-17 16:05:31 -05002072 return;
2073}
2074
James Smarte59058c2008-08-24 21:49:00 -04002075/**
James Smart3621a712009-04-06 18:47:14 -04002076 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002077 * @vport: pointer to a host virtual N_Port data structure.
2078 * @did: destination port identifier.
2079 * @retry: number of retries to the command IOCB.
2080 *
2081 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2082 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2083 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2084 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2085 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2086 *
2087 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2088 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2089 * will be stored into the context1 field of the IOCB for the completion
2090 * callback function to the PLOGI ELS command.
2091 *
2092 * Return code
2093 * 0 - Successfully issued a plogi for @vport
2094 * 1 - failed to issue a plogi for @vport
2095 **/
dea31012005-04-17 16:05:31 -05002096int
James Smart2e0fef82007-06-17 19:56:36 -05002097lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05002098{
James Smart2e0fef82007-06-17 19:56:36 -05002099 struct lpfc_hba *phba = vport->phba;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002100 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05002101 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04002102 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002103 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002104 uint8_t *pcmd;
2105 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002106 int ret;
dea31012005-04-17 16:05:31 -05002107
James Smart98c9ea52007-10-27 13:37:33 -04002108 ndlp = lpfc_findnode_did(vport, did);
James Smartdea16bd2018-11-29 16:09:30 -08002109
2110 if (ndlp) {
2111 /* Defer the processing of the issue PLOGI until after the
2112 * outstanding UNREG_RPI mbox command completes, unless we
2113 * are going offline. This logic does not apply for Fabric DIDs
2114 */
2115 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2116 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2117 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2119 "4110 Issue PLOGI x%x deferred "
James Smart32350662019-08-14 16:57:06 -07002120 "on NPort x%x rpi x%x Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08002121 ndlp->nlp_defer_did, ndlp->nlp_DID,
2122 ndlp->nlp_rpi, ndlp);
2123
2124 /* We can only defer 1st PLOGI */
2125 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2126 ndlp->nlp_defer_did = did;
2127 return 0;
2128 }
James Smartdea16bd2018-11-29 16:09:30 -08002129 }
James Smart98c9ea52007-10-27 13:37:33 -04002130
James Smarte47c9092008-02-08 18:49:26 -05002131 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05002132 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002133 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002134 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002135 if (!elsiocb)
2136 return 1;
dea31012005-04-17 16:05:31 -05002137
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002138 shost = lpfc_shost_from_vport(vport);
2139 spin_lock_irq(shost->host_lock);
2140 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2141 spin_unlock_irq(shost->host_lock);
2142
dea31012005-04-17 16:05:31 -05002143 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2144
2145 /* For PLOGI request, remainder of payload is service parameters */
2146 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002147 pcmd += sizeof(uint32_t);
2148 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002149 sp = (struct serv_parm *) pcmd;
2150
James Smart5ac6b302010-10-22 11:05:36 -04002151 /*
2152 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2153 * to device on remote loops work.
2154 */
2155 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2156 sp->cmn.altBbCredit = 1;
2157
dea31012005-04-17 16:05:31 -05002158 if (sp->cmn.fcphLow < FC_PH_4_3)
2159 sp->cmn.fcphLow = FC_PH_4_3;
2160
2161 if (sp->cmn.fcphHigh < FC_PH3)
2162 sp->cmn.fcphHigh = FC_PH3;
2163
James Smarte0165f22016-12-19 15:07:20 -08002164 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002165 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002166 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002167
James Smart858c9f62007-06-17 19:56:39 -05002168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2169 "Issue PLOGI: did:x%x",
2170 did, 0, 0);
2171
James Smart8c258642017-02-12 13:52:36 -08002172 /* If our firmware supports this feature, convey that
2173 * information to the target using the vendor specific field.
2174 */
2175 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2176 sp->cmn.valid_vendor_ver_level = 1;
2177 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2178 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2179 }
2180
dea31012005-04-17 16:05:31 -05002181 phba->fc_stat.elsXmitPLOGI++;
2182 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05002183
James Smart4430f7f2020-11-15 11:26:31 -08002184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2185 "Issue PLOGI: did:x%x refcnt %d",
2186 did, kref_read(&ndlp->kref), 0);
2187 elsiocb->context1 = lpfc_nlp_get(ndlp);
2188 if (!elsiocb->context1)
2189 goto io_err;
2190
2191 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2192 if (ret) {
2193 lpfc_nlp_put(ndlp);
2194 goto io_err;
dea31012005-04-17 16:05:31 -05002195 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002196 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08002197
2198 io_err:
2199 lpfc_els_free_iocb(phba, elsiocb);
2200 return 1;
dea31012005-04-17 16:05:31 -05002201}
2202
James Smarte59058c2008-08-24 21:49:00 -04002203/**
James Smart3621a712009-04-06 18:47:14 -04002204 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002205 * @phba: pointer to lpfc hba data structure.
2206 * @cmdiocb: pointer to lpfc command iocb data structure.
2207 * @rspiocb: pointer to lpfc response iocb data structure.
2208 *
2209 * This routine is the completion callback function for a Process Login
2210 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2211 * status. If there is error status reported, PRLI retry shall be attempted
2212 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2213 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2214 * ndlp to mark the PRLI completion.
2215 **/
dea31012005-04-17 16:05:31 -05002216static void
James Smart2e0fef82007-06-17 19:56:36 -05002217lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2218 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002219{
James Smart2e0fef82007-06-17 19:56:36 -05002220 struct lpfc_vport *vport = cmdiocb->vport;
2221 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002222 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002223 struct lpfc_nodelist *ndlp;
James Smart2332e6e2019-11-04 16:57:01 -08002224 char *mode;
Dick Kennedy372c1872020-06-30 14:50:00 -07002225 u32 loglevel;
dea31012005-04-17 16:05:31 -05002226
dea31012005-04-17 16:05:31 -05002227 /* we pass cmdiocb to state machine which needs rspiocb as well */
2228 cmdiocb->context_un.rsp_iocb = rspiocb;
2229
2230 irsp = &(rspiocb->iocb);
2231 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002232 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002233 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002234
2235 /* Driver supports multiple FC4 types. Counters matter. */
2236 vport->fc_prli_sent--;
2237 ndlp->fc4_prli_sent--;
James Smart2e0fef82007-06-17 19:56:36 -05002238 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002239
James Smart858c9f62007-06-17 19:56:39 -05002240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2241 "PRLI cmpl: status:x%x/x%x did:x%x",
2242 irsp->ulpStatus, irsp->un.ulpWord[4],
2243 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002244
dea31012005-04-17 16:05:31 -05002245 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002247 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002248 "Data: x%x x%x x%x x%x\n",
2249 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002250 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002251
dea31012005-04-17 16:05:31 -05002252 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002253 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002254 goto out;
2255
2256 if (irsp->ulpStatus) {
2257 /* Check for retry */
2258 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2259 /* ELS command is being retried */
2260 goto out;
2261 }
James Smart31200462017-05-15 15:20:42 -07002262
James Smart2332e6e2019-11-04 16:57:01 -08002263 /* If we don't send GFT_ID to Fabric, a PRLI error
2264 * could be expected.
2265 */
2266 if ((vport->fc_flag & FC_FABRIC) ||
Dick Kennedy372c1872020-06-30 14:50:00 -07002267 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
James Smart2332e6e2019-11-04 16:57:01 -08002268 mode = KERN_ERR;
Dick Kennedy372c1872020-06-30 14:50:00 -07002269 loglevel = LOG_TRACE_EVENT;
2270 } else {
James Smart2332e6e2019-11-04 16:57:01 -08002271 mode = KERN_INFO;
Dick Kennedy372c1872020-06-30 14:50:00 -07002272 loglevel = LOG_ELS;
2273 }
James Smart2332e6e2019-11-04 16:57:01 -08002274
dea31012005-04-17 16:05:31 -05002275 /* PRLI failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002276 lpfc_printf_vlog(vport, mode, loglevel,
James Smart31200462017-05-15 15:20:42 -07002277 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2278 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002279 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002280 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2281
dea31012005-04-17 16:05:31 -05002282 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002283 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002284 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002285 else
James Smart2e0fef82007-06-17 19:56:36 -05002286 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002287 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002288 } else {
James Smarta0f2d3e2017-02-12 13:52:31 -08002289 /* Good status, call state machine. However, if another
2290 * PRLI is outstanding, don't call the state machine
2291 * because final disposition to Mapped or Unmapped is
2292 * completed there.
2293 */
James Smart2e0fef82007-06-17 19:56:36 -05002294 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002295 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002296 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002297
dea31012005-04-17 16:05:31 -05002298out:
2299 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002300 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002301 return;
2302}
2303
James Smarte59058c2008-08-24 21:49:00 -04002304/**
James Smart3621a712009-04-06 18:47:14 -04002305 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002306 * @vport: pointer to a host virtual N_Port data structure.
2307 * @ndlp: pointer to a node-list data structure.
2308 * @retry: number of retries to the command IOCB.
2309 *
2310 * This routine issues a Process Login (PRLI) ELS command for the
2311 * @vport. The PRLI service parameters are set up in the payload of the
2312 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2313 * is put to the IOCB completion callback func field before invoking the
2314 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2315 *
2316 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2317 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2318 * will be stored into the context1 field of the IOCB for the completion
2319 * callback function to the PRLI ELS command.
2320 *
2321 * Return code
2322 * 0 - successfully issued prli iocb command for @vport
2323 * 1 - failed to issue prli iocb command for @vport
2324 **/
dea31012005-04-17 16:05:31 -05002325int
James Smart2e0fef82007-06-17 19:56:36 -05002326lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002327 uint8_t retry)
2328{
James Smart4430f7f2020-11-15 11:26:31 -08002329 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002330 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2331 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002332 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002333 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002334 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002335 uint8_t *pcmd;
2336 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002337 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002338
Dick Kennedy991f0c02017-08-23 16:55:39 -07002339 /*
2340 * If we are in RSCN mode, the FC4 types supported from a
2341 * previous GFT_ID command may not be accurate. So, if we
2342 * are a NVME Initiator, always look for the possibility of
2343 * the remote NPort beng a NVME Target.
2344 */
2345 if (phba->sli_rev == LPFC_SLI_REV4 &&
2346 vport->fc_flag & FC_RSCN_MODE &&
2347 vport->nvmei_support)
2348 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002349 local_nlp_type = ndlp->nlp_fc4_type;
2350
James Smart9de416a2017-12-08 17:18:07 -08002351 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2352 * fields here before any of them can complete.
2353 */
2354 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2355 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2356 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smartdea16bd2018-11-29 16:09:30 -08002357 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
James Smart9de416a2017-12-08 17:18:07 -08002358 ndlp->nvme_fb_size = 0;
2359
James Smarta0f2d3e2017-02-12 13:52:31 -08002360 send_next_prli:
2361 if (local_nlp_type & NLP_FC4_FCP) {
2362 /* Payload is 4 + 16 = 20 x14 bytes. */
2363 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2364 elscmd = ELS_CMD_PRLI;
2365 } else if (local_nlp_type & NLP_FC4_NVME) {
2366 /* Payload is 4 + 20 = 24 x18 bytes. */
2367 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2368 elscmd = ELS_CMD_NVMEPRLI;
2369 } else {
2370 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2371 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2372 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2373 return 1;
2374 }
James Smart09559e82017-06-15 22:56:46 -07002375
2376 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2377 * FC4 type, implicitly LOGO.
2378 */
2379 if (phba->sli_rev == LPFC_SLI_REV3 &&
2380 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2381 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2382 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2383 ndlp->nlp_type);
2384 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2385 return 1;
2386 }
2387
James Smart2e0fef82007-06-17 19:56:36 -05002388 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002389 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002390 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002391 return 1;
dea31012005-04-17 16:05:31 -05002392
dea31012005-04-17 16:05:31 -05002393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2394
2395 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002396 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002397
James Smarta0f2d3e2017-02-12 13:52:31 -08002398 if (local_nlp_type & NLP_FC4_FCP) {
2399 /* Remainder of payload is FCP PRLI parameter page.
2400 * Note: this data structure is defined as
2401 * BE/LE in the structure definition so no
2402 * byte swap call is made.
2403 */
2404 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2405 pcmd += sizeof(uint32_t);
2406 npr = (PRLI *)pcmd;
2407
2408 /*
2409 * If our firmware version is 3.20 or later,
2410 * set the following bits for FC-TAPE support.
2411 */
2412 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2413 npr->ConfmComplAllowed = 1;
2414 npr->Retry = 1;
2415 npr->TaskRetryIdReq = 1;
2416 }
2417 npr->estabImagePair = 1;
2418 npr->readXferRdyDis = 1;
2419 if (vport->cfg_first_burst_size)
2420 npr->writeXferRdyDis = 1;
2421
2422 /* For FCP support */
2423 npr->prliType = PRLI_FCP_TYPE;
2424 npr->initiatorFunc = 1;
2425 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2426
2427 /* Remove FCP type - processed. */
2428 local_nlp_type &= ~NLP_FC4_FCP;
2429 } else if (local_nlp_type & NLP_FC4_NVME) {
2430 /* Remainder of payload is NVME PRLI parameter page.
2431 * This data structure is the newer definition that
2432 * uses bf macros so a byte swap is required.
2433 */
2434 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2435 pcmd += sizeof(uint32_t);
2436 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2437 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2438 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
James Smart0d8af092019-08-14 16:57:10 -07002439 if (phba->nsler) {
2440 bf_set(prli_nsler, npr_nvme, 1);
2441 bf_set(prli_conf, npr_nvme, 1);
2442 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002443
2444 /* Only initiators request first burst. */
2445 if ((phba->cfg_nvme_enable_fb) &&
2446 !phba->nvmet_support)
2447 bf_set(prli_fba, npr_nvme, 1);
2448
James Smart8c258642017-02-12 13:52:36 -08002449 if (phba->nvmet_support) {
2450 bf_set(prli_tgt, npr_nvme, 1);
2451 bf_set(prli_disc, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002452 } else {
2453 bf_set(prli_init, npr_nvme, 1);
James Smarta5ff0682018-01-30 15:58:56 -08002454 bf_set(prli_conf, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002455 }
James Smarta5ff0682018-01-30 15:58:56 -08002456
James Smarta0f2d3e2017-02-12 13:52:31 -08002457 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2458 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2459 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2460
2461 /* Remove NVME type - processed. */
2462 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002463 }
dea31012005-04-17 16:05:31 -05002464
2465 phba->fc_stat.elsXmitPRLI++;
2466 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002467 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002468 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002469
2470 /* The vport counters are used for lpfc_scan_finished, but
2471 * the ndlp is used to track outstanding PRLIs for different
2472 * FC4 types.
2473 */
2474 vport->fc_prli_sent++;
2475 ndlp->fc4_prli_sent++;
James Smart2e0fef82007-06-17 19:56:36 -05002476 spin_unlock_irq(shost->host_lock);
James Smart4430f7f2020-11-15 11:26:31 -08002477
2478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2479 "Issue PRLI: did:x%x refcnt %d",
2480 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2481 elsiocb->context1 = lpfc_nlp_get(ndlp);
2482 if (!elsiocb->context1)
2483 goto io_err;
2484
2485 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2486 if (rc == IOCB_ERROR)
2487 goto node_err;
James Smarta0f2d3e2017-02-12 13:52:31 -08002488
James Smarta0f2d3e2017-02-12 13:52:31 -08002489
2490 /* The driver supports 2 FC4 types. Make sure
2491 * a PRLI is issued for all types before exiting.
2492 */
James Smart09559e82017-06-15 22:56:46 -07002493 if (phba->sli_rev == LPFC_SLI_REV4 &&
2494 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002495 goto send_next_prli;
James Smart4430f7f2020-11-15 11:26:31 -08002496 else
2497 return 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002498
James Smart4430f7f2020-11-15 11:26:31 -08002499 node_err:
2500 lpfc_nlp_put(ndlp);
2501 io_err:
2502 spin_lock_irq(shost->host_lock);
2503 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2504 spin_unlock_irq(shost->host_lock);
2505 lpfc_els_free_iocb(phba, elsiocb);
2506 return 1;
dea31012005-04-17 16:05:31 -05002507}
2508
James Smarte59058c2008-08-24 21:49:00 -04002509/**
James Smart3621a712009-04-06 18:47:14 -04002510 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002511 * @vport: pointer to a host virtual N_Port data structure.
2512 *
2513 * This routine performs Registration State Change Notification (RSCN)
2514 * discovery for a @vport. If the @vport's node port recovery count is not
2515 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2516 * the nodes that need recovery. If none of the PLOGI were needed through
2517 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2518 * invoked to check and handle possible more RSCN came in during the period
2519 * of processing the current ones.
2520 **/
2521static void
2522lpfc_rscn_disc(struct lpfc_vport *vport)
2523{
2524 lpfc_can_disctmo(vport);
2525
2526 /* RSCN discovery */
2527 /* go thru NPR nodes and issue ELS PLOGIs */
2528 if (vport->fc_npr_cnt)
2529 if (lpfc_els_disc_plogi(vport))
2530 return;
2531
2532 lpfc_end_rscn(vport);
2533}
2534
2535/**
James Smart3621a712009-04-06 18:47:14 -04002536 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002537 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2538 *
2539 * This function is called when the final ADISC is completed during discovery.
2540 * This function handles clearing link attention or issuing reg_vpi depending
2541 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2542 * discovery.
2543 * This function is called with no locks held.
2544 **/
2545static void
2546lpfc_adisc_done(struct lpfc_vport *vport)
2547{
2548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2549 struct lpfc_hba *phba = vport->phba;
2550
2551 /*
2552 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2553 * and continue discovery.
2554 */
2555 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002556 !(vport->fc_flag & FC_RSCN_MODE) &&
2557 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002558 /* The ADISCs are complete. Doesn't matter if they
2559 * succeeded or failed because the ADISC completion
2560 * routine guarantees to call the state machine and
2561 * the RPI is either unregistered (failed ADISC response)
2562 * or the RPI is still valid and the node is marked
2563 * mapped for a target. The exchanges should be in the
2564 * correct state. This code is specific to SLI3.
2565 */
2566 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002567 lpfc_issue_reg_vpi(phba, vport);
2568 return;
2569 }
2570 /*
2571 * For SLI2, we need to set port_state to READY
2572 * and continue discovery.
2573 */
2574 if (vport->port_state < LPFC_VPORT_READY) {
2575 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002576 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002577 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2578 vport->num_disc_nodes = 0;
2579 /* go thru NPR list, issue ELS PLOGIs */
2580 if (vport->fc_npr_cnt)
2581 lpfc_els_disc_plogi(vport);
2582 if (!vport->num_disc_nodes) {
2583 spin_lock_irq(shost->host_lock);
2584 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2585 spin_unlock_irq(shost->host_lock);
2586 lpfc_can_disctmo(vport);
2587 lpfc_end_rscn(vport);
2588 }
2589 }
2590 vport->port_state = LPFC_VPORT_READY;
2591 } else
2592 lpfc_rscn_disc(vport);
2593}
2594
2595/**
James Smart3621a712009-04-06 18:47:14 -04002596 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002597 * @vport: pointer to a host virtual N_Port data structure.
2598 *
2599 * This routine determines whether there are more ndlps on a @vport
2600 * node list need to have Address Discover (ADISC) issued. If so, it will
2601 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2602 * remaining nodes which need to have ADISC sent.
2603 **/
James Smart0ff10d42008-01-11 01:52:36 -05002604void
James Smart2e0fef82007-06-17 19:56:36 -05002605lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002606{
James Smart2e0fef82007-06-17 19:56:36 -05002607 if (vport->num_disc_nodes)
2608 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002609 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2611 "0210 Continue discovery with %d ADISCs to go "
2612 "Data: x%x x%x x%x\n",
2613 vport->num_disc_nodes, vport->fc_adisc_cnt,
2614 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002615 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002616 if (vport->fc_flag & FC_NLP_MORE) {
2617 lpfc_set_disctmo(vport);
2618 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002619 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002620 }
James Smart90160e02008-08-24 21:49:45 -04002621 if (!vport->num_disc_nodes)
2622 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002623 return;
2624}
2625
James Smarte59058c2008-08-24 21:49:00 -04002626/**
James Smart3621a712009-04-06 18:47:14 -04002627 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002628 * @phba: pointer to lpfc hba data structure.
2629 * @cmdiocb: pointer to lpfc command iocb data structure.
2630 * @rspiocb: pointer to lpfc response iocb data structure.
2631 *
2632 * This routine is the completion function for issuing the Address Discover
2633 * (ADISC) command. It first checks to see whether link went down during
2634 * the discovery process. If so, the node will be marked as node port
2635 * recovery for issuing discover IOCB by the link attention handler and
2636 * exit. Otherwise, the response status is checked. If error was reported
2637 * in the response status, the ADISC command shall be retried by invoking
2638 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2639 * the response status, the state machine is invoked to set transition
2640 * with respect to NLP_EVT_CMPL_ADISC event.
2641 **/
dea31012005-04-17 16:05:31 -05002642static void
James Smart2e0fef82007-06-17 19:56:36 -05002643lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2644 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002645{
James Smart2e0fef82007-06-17 19:56:36 -05002646 struct lpfc_vport *vport = cmdiocb->vport;
2647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002648 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002649 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002650 int disc;
dea31012005-04-17 16:05:31 -05002651
2652 /* we pass cmdiocb to state machine which needs rspiocb as well */
2653 cmdiocb->context_un.rsp_iocb = rspiocb;
2654
2655 irsp = &(rspiocb->iocb);
2656 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002657
James Smart858c9f62007-06-17 19:56:39 -05002658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2659 "ADISC cmpl: status:x%x/x%x did:x%x",
2660 irsp->ulpStatus, irsp->un.ulpWord[4],
2661 ndlp->nlp_DID);
2662
dea31012005-04-17 16:05:31 -05002663 /* Since ndlp can be freed in the disc state machine, note if this node
2664 * is being used during discovery.
2665 */
James Smart2e0fef82007-06-17 19:56:36 -05002666 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002667 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002668 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002669 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002670 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2672 "0104 ADISC completes to NPort x%x "
2673 "Data: x%x x%x x%x x%x x%x\n",
2674 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2675 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002676 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002677 if (lpfc_els_chk_latt(vport)) {
2678 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002679 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002680 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002681 goto out;
2682 }
2683
2684 if (irsp->ulpStatus) {
2685 /* Check for retry */
2686 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2687 /* ELS command is being retried */
2688 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002689 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002690 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002691 spin_unlock_irq(shost->host_lock);
2692 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002693 }
2694 goto out;
2695 }
2696 /* ADISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002697 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte40a02c2010-02-26 14:13:54 -05002698 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2699 ndlp->nlp_DID, irsp->ulpStatus,
2700 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002701 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002702 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002703 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002704 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002705 } else
dea31012005-04-17 16:05:31 -05002706 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002707 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002708 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002709
James Smart90160e02008-08-24 21:49:45 -04002710 /* Check to see if there are more ADISCs to be sent */
2711 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002712 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002713out:
2714 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002715 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002716 return;
2717}
2718
James Smarte59058c2008-08-24 21:49:00 -04002719/**
James Smart3621a712009-04-06 18:47:14 -04002720 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002721 * @vport: pointer to a virtual N_Port data structure.
2722 * @ndlp: pointer to a node-list data structure.
2723 * @retry: number of retries to the command IOCB.
2724 *
2725 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2726 * @vport. It prepares the payload of the ADISC ELS command, updates the
2727 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2728 * to issue the ADISC ELS command.
2729 *
2730 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2731 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2732 * will be stored into the context1 field of the IOCB for the completion
2733 * callback function to the ADISC ELS command.
2734 *
2735 * Return code
2736 * 0 - successfully issued adisc
2737 * 1 - failed to issue adisc
2738 **/
dea31012005-04-17 16:05:31 -05002739int
James Smart2e0fef82007-06-17 19:56:36 -05002740lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002741 uint8_t retry)
2742{
James Smart4430f7f2020-11-15 11:26:31 -08002743 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2745 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002746 ADISC *ap;
dea31012005-04-17 16:05:31 -05002747 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002748 uint8_t *pcmd;
2749 uint16_t cmdsize;
2750
James Smart92d7f7b2007-06-17 19:56:38 -05002751 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002752 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2753 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002754 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002755 return 1;
dea31012005-04-17 16:05:31 -05002756
dea31012005-04-17 16:05:31 -05002757 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2758
2759 /* For ADISC request, remainder of payload is service parameters */
2760 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002761 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002762
2763 /* Fill in ADISC payload */
2764 ap = (ADISC *) pcmd;
2765 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002766 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2767 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002768 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002769
2770 phba->fc_stat.elsXmitADISC++;
2771 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002772 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002773 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002774 spin_unlock_irq(shost->host_lock);
James Smart4430f7f2020-11-15 11:26:31 -08002775 elsiocb->context1 = lpfc_nlp_get(ndlp);
2776 if (!elsiocb->context1)
2777 goto node_err;
2778
2779 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2780 "Issue ADISC: did:x%x refcnt %d",
2781 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2782 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2783 if (rc == IOCB_ERROR)
2784 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002785 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08002786
2787 io_err:
2788 lpfc_nlp_put(ndlp);
2789 node_err:
2790 spin_lock_irq(shost->host_lock);
2791 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2792 spin_unlock_irq(shost->host_lock);
2793 lpfc_els_free_iocb(phba, elsiocb);
2794 return 1;
dea31012005-04-17 16:05:31 -05002795}
2796
James Smarte59058c2008-08-24 21:49:00 -04002797/**
James Smart3621a712009-04-06 18:47:14 -04002798 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002799 * @phba: pointer to lpfc hba data structure.
2800 * @cmdiocb: pointer to lpfc command iocb data structure.
2801 * @rspiocb: pointer to lpfc response iocb data structure.
2802 *
2803 * This routine is the completion function for issuing the ELS Logout (LOGO)
2804 * command. If no error status was reported from the LOGO response, the
2805 * state machine of the associated ndlp shall be invoked for transition with
2806 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2807 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2808 **/
dea31012005-04-17 16:05:31 -05002809static void
James Smart2e0fef82007-06-17 19:56:36 -05002810lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2811 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002812{
James Smart2e0fef82007-06-17 19:56:36 -05002813 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2814 struct lpfc_vport *vport = ndlp->vport;
2815 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002816 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002817 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002818 unsigned long flags;
2819 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002820
dea31012005-04-17 16:05:31 -05002821 /* we pass cmdiocb to state machine which needs rspiocb as well */
2822 cmdiocb->context_un.rsp_iocb = rspiocb;
2823
2824 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002825 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002826 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002827 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002828
James Smart858c9f62007-06-17 19:56:39 -05002829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2830 "LOGO cmpl: status:x%x/x%x did:x%x",
2831 irsp->ulpStatus, irsp->un.ulpWord[4],
2832 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002833
dea31012005-04-17 16:05:31 -05002834 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2836 "0105 LOGO completes to NPort x%x "
2837 "Data: x%x x%x x%x x%x\n",
2838 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2839 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002840
James Smart086a3452012-08-14 14:25:21 -04002841 if (lpfc_els_chk_latt(vport)) {
2842 skip_recovery = 1;
2843 goto out;
2844 }
2845
2846 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002847 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2848 /* NLP_EVT_DEVICE_RM should unregister the RPI
2849 * which should abort all outstanding IOs.
2850 */
2851 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2852 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002853 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002854 goto out;
2855 }
2856
James Smart30e196c2018-10-23 13:41:03 -07002857 /* The LOGO will not be retried on failure. A LOGO was
2858 * issued to the remote rport and a ACC or RJT or no Answer are
2859 * all acceptable. Note the failure and move forward with
2860 * discovery. The PLOGI will retry.
2861 */
dea31012005-04-17 16:05:31 -05002862 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -05002863 /* LOGO failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07002864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart30e196c2018-10-23 13:41:03 -07002865 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002866 ndlp->nlp_DID, irsp->ulpStatus,
2867 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002868 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002869 if (lpfc_error_lost_link(irsp)) {
2870 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002871 goto out;
James Smart086a3452012-08-14 14:25:21 -04002872 }
2873 }
2874
2875 /* Call state machine. This will unregister the rpi if needed. */
2876 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2877
dea31012005-04-17 16:05:31 -05002878out:
James Smart4430f7f2020-11-15 11:26:31 -08002879 /* Driver is done with the IO. */
dea31012005-04-17 16:05:31 -05002880 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08002881 lpfc_nlp_put(ndlp);
2882
James Smart92494142011-02-16 12:39:44 -05002883 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2884 if ((vport->fc_flag & FC_PT2PT) &&
2885 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2886 phba->pport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002887
James Smartf6e84792019-01-28 11:14:38 -08002888 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2889 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08002890 if (phba->nvmet_support)
2891 lpfc_nvmet_update_targetport(phba);
2892 else
James Smart8c258642017-02-12 13:52:36 -08002893 lpfc_nvme_update_localport(phba->pport);
James Smart8c258642017-02-12 13:52:36 -08002894 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002895
James Smart92494142011-02-16 12:39:44 -05002896 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2897 if (mbox) {
2898 lpfc_config_link(phba, mbox);
2899 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2900 mbox->vport = vport;
2901 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2902 MBX_NOT_FINISHED) {
2903 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002904 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002905 }
2906 }
2907 }
James Smart086a3452012-08-14 14:25:21 -04002908
2909 /*
2910 * If the node is a target, the handling attempts to recover the port.
2911 * For any other port type, the rpi is unregistered as an implicit
2912 * LOGO.
2913 */
James Smart30e196c2018-10-23 13:41:03 -07002914 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2915 skip_recovery == 0) {
James Smart086a3452012-08-14 14:25:21 -04002916 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2917 spin_lock_irqsave(shost->host_lock, flags);
2918 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2919 spin_unlock_irqrestore(shost->host_lock, flags);
2920
2921 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2922 "3187 LOGO completes to NPort x%x: Start "
2923 "Recovery Data: x%x x%x x%x x%x\n",
2924 ndlp->nlp_DID, irsp->ulpStatus,
2925 irsp->un.ulpWord[4], irsp->ulpTimeout,
2926 vport->num_disc_nodes);
2927 lpfc_disc_start(vport);
2928 }
dea31012005-04-17 16:05:31 -05002929 return;
2930}
2931
James Smarte59058c2008-08-24 21:49:00 -04002932/**
James Smart3621a712009-04-06 18:47:14 -04002933 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002934 * @vport: pointer to a virtual N_Port data structure.
2935 * @ndlp: pointer to a node-list data structure.
2936 * @retry: number of retries to the command IOCB.
2937 *
2938 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2939 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2940 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2941 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2942 *
2943 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2944 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2945 * will be stored into the context1 field of the IOCB for the completion
2946 * callback function to the LOGO ELS command.
2947 *
James Smart30e196c2018-10-23 13:41:03 -07002948 * Callers of this routine are expected to unregister the RPI first
2949 *
James Smarte59058c2008-08-24 21:49:00 -04002950 * Return code
2951 * 0 - successfully issued logo
2952 * 1 - failed to issue logo
2953 **/
dea31012005-04-17 16:05:31 -05002954int
James Smart2e0fef82007-06-17 19:56:36 -05002955lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002956 uint8_t retry)
2957{
James Smart2e0fef82007-06-17 19:56:36 -05002958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002960 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002961 uint8_t *pcmd;
2962 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002963 int rc;
dea31012005-04-17 16:05:31 -05002964
James Smart98c9ea52007-10-27 13:37:33 -04002965 spin_lock_irq(shost->host_lock);
2966 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2967 spin_unlock_irq(shost->host_lock);
2968 return 0;
2969 }
2970 spin_unlock_irq(shost->host_lock);
2971
James Smart92d7f7b2007-06-17 19:56:38 -05002972 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002973 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2974 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002975 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002976 return 1;
dea31012005-04-17 16:05:31 -05002977
dea31012005-04-17 16:05:31 -05002978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2979 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002980 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002981
2982 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002983 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002984 pcmd += sizeof(uint32_t);
2985 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002986
2987 phba->fc_stat.elsXmitLOGO++;
2988 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002989 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002990 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002991 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002992 spin_unlock_irq(shost->host_lock);
James Smart4430f7f2020-11-15 11:26:31 -08002993 elsiocb->context1 = lpfc_nlp_get(ndlp);
2994 if (!elsiocb->context1)
2995 goto node_err;
2996
2997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2998 "Issue LOGO: did:x%x refcnt %d",
2999 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
James Smart3772a992009-05-22 14:50:54 -04003000 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08003001 if (rc == IOCB_ERROR)
3002 goto io_err;
James Smart30e196c2018-10-23 13:41:03 -07003003
3004 spin_lock_irq(shost->host_lock);
3005 ndlp->nlp_prev_state = ndlp->nlp_state;
3006 spin_unlock_irq(shost->host_lock);
3007 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003008 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003009
3010 io_err:
3011 lpfc_nlp_put(ndlp);
3012 node_err:
3013 spin_lock_irq(shost->host_lock);
3014 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3015 spin_unlock_irq(shost->host_lock);
3016 lpfc_els_free_iocb(phba, elsiocb);
3017 return 1;
dea31012005-04-17 16:05:31 -05003018}
3019
James Smarte59058c2008-08-24 21:49:00 -04003020/**
James Smart3621a712009-04-06 18:47:14 -04003021 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04003022 * @phba: pointer to lpfc hba data structure.
3023 * @cmdiocb: pointer to lpfc command iocb data structure.
3024 * @rspiocb: pointer to lpfc response iocb data structure.
3025 *
3026 * This routine is a generic completion callback function for ELS commands.
3027 * Specifically, it is the callback function which does not need to perform
3028 * any command specific operations. It is currently used by the ELS command
James Smartdf3fe762020-02-10 09:31:55 -08003029 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3030 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3031 * Other than certain debug loggings, this callback function simply invokes the
James Smarte59058c2008-08-24 21:49:00 -04003032 * lpfc_els_chk_latt() routine to check whether link went down during the
3033 * discovery process.
3034 **/
dea31012005-04-17 16:05:31 -05003035static void
James Smart2e0fef82007-06-17 19:56:36 -05003036lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3037 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003038{
James Smart2e0fef82007-06-17 19:56:36 -05003039 struct lpfc_vport *vport = cmdiocb->vport;
James Smart4430f7f2020-11-15 11:26:31 -08003040 struct lpfc_nodelist *free_ndlp;
dea31012005-04-17 16:05:31 -05003041 IOCB_t *irsp;
3042
3043 irsp = &rspiocb->iocb;
3044
James Smart858c9f62007-06-17 19:56:39 -05003045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
James Smartdf3fe762020-02-10 09:31:55 -08003046 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3047 irsp->ulpStatus, irsp->un.ulpWord[4],
3048 irsp->un.elsreq64.remoteID);
3049
dea31012005-04-17 16:05:31 -05003050 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003051 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3052 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3053 irsp->ulpIoTag, irsp->ulpStatus,
3054 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smartdf3fe762020-02-10 09:31:55 -08003055
3056 /* Check to see if link went down during discovery */
3057 lpfc_els_chk_latt(vport);
James Smart4430f7f2020-11-15 11:26:31 -08003058
3059 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3060
James Smartdf3fe762020-02-10 09:31:55 -08003061 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003062 lpfc_nlp_put(free_ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003063}
3064
3065/**
3066 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3067 * @phba: pointer to lpfc hba data structure.
3068 * @cmdiocb: pointer to lpfc command iocb data structure.
3069 * @rspiocb: pointer to lpfc response iocb data structure.
3070 *
3071 * This routine is a generic completion callback function for Discovery ELS cmd.
3072 * Currently used by the ELS command issuing routines for the ELS State Change
3073 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3074 * These commands will be retried once only for ELS timeout errors.
3075 **/
3076static void
3077lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3078 struct lpfc_iocbq *rspiocb)
3079{
3080 struct lpfc_vport *vport = cmdiocb->vport;
3081 IOCB_t *irsp;
3082 struct lpfc_els_rdf_rsp *prdf;
3083 struct lpfc_dmabuf *pcmd, *prsp;
3084 u32 *pdata;
3085 u32 cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003086 struct lpfc_nodelist *ndlp = cmdiocb->context1;
James Smartdf3fe762020-02-10 09:31:55 -08003087
3088 irsp = &rspiocb->iocb;
3089
3090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3091 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3092 irsp->ulpStatus, irsp->un.ulpWord[4],
3093 irsp->un.elsreq64.remoteID);
3094 /* ELS cmd tag <ulpIoTag> completes */
3095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3096 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3097 "x%x\n",
3098 irsp->ulpIoTag, irsp->ulpStatus,
3099 irsp->un.ulpWord[4], irsp->ulpTimeout,
3100 cmdiocb->retry);
3101
3102 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3103 if (!pcmd)
3104 goto out;
3105
3106 pdata = (u32 *)pcmd->virt;
3107 if (!pdata)
3108 goto out;
3109 cmd = *pdata;
3110
3111 /* Only 1 retry for ELS Timeout only */
3112 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3113 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3114 IOERR_SEQUENCE_TIMEOUT)) {
3115 cmdiocb->retry++;
3116 if (cmdiocb->retry <= 1) {
3117 switch (cmd) {
3118 case ELS_CMD_SCR:
3119 lpfc_issue_els_scr(vport, cmdiocb->retry);
3120 break;
3121 case ELS_CMD_RDF:
3122 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3123 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3124 break;
3125 }
3126 goto out;
3127 }
3128 phba->fc_stat.elsRetryExceeded++;
3129 }
3130 if (irsp->ulpStatus) {
3131 /* ELS discovery cmd completes with error */
3132 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3133 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3134 irsp->ulpStatus, irsp->un.ulpWord[4]);
3135 goto out;
3136 }
3137
3138 /* The RDF response doesn't have any impact on the running driver
3139 * but the notification descriptors are dumped here for support.
3140 */
3141 if (cmd == ELS_CMD_RDF) {
3142 int i;
3143
3144 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3145 if (!prsp)
3146 goto out;
3147
3148 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3149 if (!prdf)
3150 goto out;
3151
3152 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3153 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3154 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
Colin Ian King162e2502020-02-21 15:48:41 +00003155 "4677 Fabric RDF Notification Grant Data: "
James Smartdf3fe762020-02-10 09:31:55 -08003156 "0x%08x\n",
3157 be32_to_cpu(
3158 prdf->reg_d1.desc_tags[i]));
3159 }
3160
3161out:
dea31012005-04-17 16:05:31 -05003162 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05003163 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05003164 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08003165 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003166 return;
3167}
3168
James Smarte59058c2008-08-24 21:49:00 -04003169/**
James Smart3621a712009-04-06 18:47:14 -04003170 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003171 * @vport: pointer to a host virtual N_Port data structure.
James Smartdf3fe762020-02-10 09:31:55 -08003172 * @retry: retry counter for the command IOCB.
James Smarte59058c2008-08-24 21:49:00 -04003173 *
3174 * This routine issues a State Change Request (SCR) to a fabric node
James Smartdf3fe762020-02-10 09:31:55 -08003175 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
James Smarte59058c2008-08-24 21:49:00 -04003176 * first search the @vport node list to find the matching ndlp. If no such
3177 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3178 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3179 * routine is invoked to send the SCR IOCB.
3180 *
3181 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3182 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3183 * will be stored into the context1 field of the IOCB for the completion
3184 * callback function to the SCR ELS command.
3185 *
3186 * Return code
3187 * 0 - Successfully issued scr command
3188 * 1 - Failed to issue scr command
3189 **/
dea31012005-04-17 16:05:31 -05003190int
James Smartdf3fe762020-02-10 09:31:55 -08003191lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
dea31012005-04-17 16:05:31 -05003192{
James Smart4430f7f2020-11-15 11:26:31 -08003193 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003194 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003195 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003196 uint8_t *pcmd;
3197 uint16_t cmdsize;
3198 struct lpfc_nodelist *ndlp;
3199
James Smart92d7f7b2007-06-17 19:56:38 -05003200 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05003201
James Smartdf3fe762020-02-10 09:31:55 -08003202 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003203 if (!ndlp) {
James Smartdf3fe762020-02-10 09:31:55 -08003204 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003205 if (!ndlp)
3206 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003207 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003208 }
dea31012005-04-17 16:05:31 -05003209
James Smart2e0fef82007-06-17 19:56:36 -05003210 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3211 ndlp->nlp_DID, ELS_CMD_SCR);
3212
James Smart4430f7f2020-11-15 11:26:31 -08003213 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003214 return 1;
dea31012005-04-17 16:05:31 -05003215
dea31012005-04-17 16:05:31 -05003216 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3217
3218 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05003219 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003220
3221 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003222 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05003223 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3224
James Smart858c9f62007-06-17 19:56:39 -05003225 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3226 "Issue SCR: did:x%x",
3227 ndlp->nlp_DID, 0, 0);
3228
dea31012005-04-17 16:05:31 -05003229 phba->fc_stat.elsXmitSCR++;
James Smartdf3fe762020-02-10 09:31:55 -08003230 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003231 elsiocb->context1 = lpfc_nlp_get(ndlp);
3232 if (!elsiocb->context1)
3233 goto node_err;
3234
3235 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3236 "Issue SCR: did:x%x refcnt %d",
3237 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3238
3239 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3240 if (rc == IOCB_ERROR)
3241 goto io_err;
3242
3243 /* Keep the ndlp just in case RDF is being sent */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003244 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003245
3246 io_err:
3247 lpfc_nlp_put(ndlp);
3248 node_err:
3249 lpfc_els_free_iocb(phba, elsiocb);
3250 return 1;
dea31012005-04-17 16:05:31 -05003251}
3252
James Smarte59058c2008-08-24 21:49:00 -04003253/**
James Smartf60cb932019-05-14 14:58:05 -07003254 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3255 * or the other nport (pt2pt).
3256 * @vport: pointer to a host virtual N_Port data structure.
3257 * @retry: number of retries to the command IOCB.
3258 *
3259 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3260 * when connected to a fabric, or to the remote port when connected
3261 * in point-to-point mode. When sent to the Fabric Controller, it will
3262 * replay the RSCN to registered recipients.
3263 *
3264 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3265 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3266 * will be stored into the context1 field of the IOCB for the completion
3267 * callback function to the RSCN ELS command.
3268 *
3269 * Return code
3270 * 0 - Successfully issued RSCN command
3271 * 1 - Failed to issue RSCN command
3272 **/
3273int
3274lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3275{
James Smart4430f7f2020-11-15 11:26:31 -08003276 int rc = 0;
James Smartf60cb932019-05-14 14:58:05 -07003277 struct lpfc_hba *phba = vport->phba;
3278 struct lpfc_iocbq *elsiocb;
3279 struct lpfc_nodelist *ndlp;
3280 struct {
3281 struct fc_els_rscn rscn;
3282 struct fc_els_rscn_page portid;
3283 } *event;
3284 uint32_t nportid;
3285 uint16_t cmdsize = sizeof(*event);
3286
3287 /* Not supported for private loop */
3288 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3289 !(vport->fc_flag & FC_PUBLIC_LOOP))
3290 return 1;
3291
3292 if (vport->fc_flag & FC_PT2PT) {
3293 /* find any mapped nport - that would be the other nport */
3294 ndlp = lpfc_findnode_mapped(vport);
3295 if (!ndlp)
3296 return 1;
3297 } else {
3298 nportid = FC_FID_FCTRL;
3299 /* find the fabric controller node */
3300 ndlp = lpfc_findnode_did(vport, nportid);
3301 if (!ndlp) {
3302 /* if one didn't exist, make one */
3303 ndlp = lpfc_nlp_init(vport, nportid);
3304 if (!ndlp)
3305 return 1;
3306 lpfc_enqueue_node(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003307 }
3308 }
3309
3310 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3311 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3312
James Smart4430f7f2020-11-15 11:26:31 -08003313 if (!elsiocb)
James Smartf60cb932019-05-14 14:58:05 -07003314 return 1;
James Smartf60cb932019-05-14 14:58:05 -07003315
3316 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3317
3318 event->rscn.rscn_cmd = ELS_RSCN;
3319 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3320 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3321
3322 nportid = vport->fc_myDID;
3323 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3324 event->portid.rscn_page_flags = 0;
3325 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3326 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3327 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3328
James Smart4430f7f2020-11-15 11:26:31 -08003329 phba->fc_stat.elsXmitRSCN++;
3330 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3331 elsiocb->context1 = lpfc_nlp_get(ndlp);
3332 if (!elsiocb->context1)
3333 goto node_err;
3334
James Smartf60cb932019-05-14 14:58:05 -07003335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3336 "Issue RSCN: did:x%x",
3337 ndlp->nlp_DID, 0, 0);
3338
James Smart4430f7f2020-11-15 11:26:31 -08003339 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3340 if (rc == IOCB_ERROR)
3341 goto io_err;
James Smart8aaa7bc2020-10-20 13:27:17 -07003342
James Smartf60cb932019-05-14 14:58:05 -07003343 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3344 * trigger the release of node.
3345 */
3346 if (!(vport->fc_flag & FC_PT2PT))
3347 lpfc_nlp_put(ndlp);
James Smartf60cb932019-05-14 14:58:05 -07003348 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003349io_err:
3350 lpfc_nlp_put(ndlp);
3351node_err:
3352 lpfc_els_free_iocb(phba, elsiocb);
3353 return 1;
James Smartf60cb932019-05-14 14:58:05 -07003354}
3355
3356/**
James Smart3621a712009-04-06 18:47:14 -04003357 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003358 * @vport: pointer to a host virtual N_Port data structure.
3359 * @nportid: N_Port identifier to the remote node.
3360 * @retry: number of retries to the command IOCB.
3361 *
3362 * This routine issues a Fibre Channel Address Resolution Response
3363 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3364 * is passed into the function. It first search the @vport node list to find
3365 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3366 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3367 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3368 *
3369 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3370 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3371 * will be stored into the context1 field of the IOCB for the completion
3372 * callback function to the PARPR ELS command.
3373 *
3374 * Return code
3375 * 0 - Successfully issued farpr command
3376 * 1 - Failed to issue farpr command
3377 **/
dea31012005-04-17 16:05:31 -05003378static int
James Smart2e0fef82007-06-17 19:56:36 -05003379lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05003380{
James Smart4430f7f2020-11-15 11:26:31 -08003381 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003382 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003383 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003384 FARP *fp;
3385 uint8_t *pcmd;
3386 uint32_t *lp;
3387 uint16_t cmdsize;
3388 struct lpfc_nodelist *ondlp;
3389 struct lpfc_nodelist *ndlp;
3390
James Smart92d7f7b2007-06-17 19:56:38 -05003391 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05003392
James Smarte47c9092008-02-08 18:49:26 -05003393 ndlp = lpfc_findnode_did(vport, nportid);
3394 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003395 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003396 if (!ndlp)
3397 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003398 lpfc_enqueue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003399 }
James Smart2e0fef82007-06-17 19:56:36 -05003400
3401 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3402 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart4430f7f2020-11-15 11:26:31 -08003403 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003404 return 1;
dea31012005-04-17 16:05:31 -05003405
dea31012005-04-17 16:05:31 -05003406 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3407
3408 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003409 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003410
3411 /* Fill in FARPR payload */
3412 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003413 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003414 lp = (uint32_t *) pcmd;
3415 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003416 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003417 fp->Rflags = 0;
3418 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3419
James Smart92d7f7b2007-06-17 19:56:38 -05003420 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3421 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003422 ondlp = lpfc_findnode_did(vport, nportid);
James Smart307e3382020-11-15 11:26:30 -08003423 if (ondlp) {
dea31012005-04-17 16:05:31 -05003424 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003425 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003426 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003427 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003428 }
3429
James Smart858c9f62007-06-17 19:56:39 -05003430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3431 "Issue FARPR: did:x%x",
3432 ndlp->nlp_DID, 0, 0);
3433
dea31012005-04-17 16:05:31 -05003434 phba->fc_stat.elsXmitFARPR++;
3435 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003436 elsiocb->context1 = lpfc_nlp_get(ndlp);
3437 if (!elsiocb->context1) {
3438 lpfc_els_free_iocb(phba, elsiocb);
3439 return 1;
3440 }
3441
3442 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3443 if (rc == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003444 /* The additional lpfc_nlp_put will cause the following
3445 * lpfc_els_free_iocb routine to trigger the release of
3446 * the node.
3447 */
James Smart329f9bc2007-04-25 09:53:01 -04003448 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003449 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003450 return 1;
dea31012005-04-17 16:05:31 -05003451 }
James Smartfa4066b2008-01-11 01:53:27 -05003452 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3453 * trigger the release of the node.
3454 */
James Smartdf3fe762020-02-10 09:31:55 -08003455 /* Don't release reference count as RDF is likely outstanding */
3456 return 0;
3457}
3458
3459/**
3460 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3461 * @vport: pointer to a host virtual N_Port data structure.
3462 * @retry: retry counter for the command IOCB.
3463 *
3464 * This routine issues an ELS RDF to the Fabric Controller to register
3465 * for diagnostic functions.
3466 *
3467 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3468 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3469 * will be stored into the context1 field of the IOCB for the completion
3470 * callback function to the RDF ELS command.
3471 *
3472 * Return code
3473 * 0 - Successfully issued rdf command
3474 * 1 - Failed to issue rdf command
3475 **/
3476int
3477lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3478{
3479 struct lpfc_hba *phba = vport->phba;
3480 struct lpfc_iocbq *elsiocb;
3481 struct lpfc_els_rdf_req *prdf;
3482 struct lpfc_nodelist *ndlp;
3483 uint16_t cmdsize;
James Smart4430f7f2020-11-15 11:26:31 -08003484 int rc;
James Smartdf3fe762020-02-10 09:31:55 -08003485
3486 cmdsize = sizeof(*prdf);
3487
3488 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3489 if (!ndlp) {
3490 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3491 if (!ndlp)
3492 return -ENODEV;
3493 lpfc_enqueue_node(vport, ndlp);
James Smartdf3fe762020-02-10 09:31:55 -08003494 }
3495
3496 /* RDF ELS is not required on an NPIV VN_Port. */
3497 if (vport->port_type == LPFC_NPIV_PORT) {
3498 lpfc_nlp_put(ndlp);
3499 return -EACCES;
3500 }
3501
3502 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3503 ndlp->nlp_DID, ELS_CMD_RDF);
James Smart4430f7f2020-11-15 11:26:31 -08003504 if (!elsiocb)
James Smartdf3fe762020-02-10 09:31:55 -08003505 return -ENOMEM;
James Smartdf3fe762020-02-10 09:31:55 -08003506
3507 /* Configure the payload for the supported FPIN events. */
3508 prdf = (struct lpfc_els_rdf_req *)
3509 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3510 memset(prdf, 0, cmdsize);
3511 prdf->rdf.fpin_cmd = ELS_RDF;
3512 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3513 sizeof(struct fc_els_rdf));
3514 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3515 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3516 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3517 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3518 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
James Smart441f6b52020-08-28 10:53:31 -07003519 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3520 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3521 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
James Smartdf3fe762020-02-10 09:31:55 -08003522
James Smartdf3fe762020-02-10 09:31:55 -08003523 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3524 "6444 Xmit RDF to remote NPORT x%x\n",
3525 ndlp->nlp_DID);
3526
3527 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart4430f7f2020-11-15 11:26:31 -08003528 elsiocb->context1 = lpfc_nlp_get(ndlp);
3529 if (!elsiocb->context1)
3530 goto node_err;
James Smartdf3fe762020-02-10 09:31:55 -08003531
James Smart4430f7f2020-11-15 11:26:31 -08003532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3533 "Issue RDF: did:x%x refcnt %d",
3534 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3535
3536 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3537 if (rc == IOCB_ERROR)
3538 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003539 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08003540
3541 io_err:
3542 lpfc_nlp_put(ndlp);
3543 node_err:
3544 lpfc_els_free_iocb(phba, elsiocb);
3545 return -EIO;
dea31012005-04-17 16:05:31 -05003546}
3547
James Smarte59058c2008-08-24 21:49:00 -04003548/**
James Smart3621a712009-04-06 18:47:14 -04003549 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003550 * @vport: pointer to a host virtual N_Port data structure.
3551 * @nlp: pointer to a node-list data structure.
3552 *
3553 * This routine cancels the timer with a delayed IOCB-command retry for
3554 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3555 * removes the ELS retry event if it presents. In addition, if the
3556 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3557 * commands are sent for the @vport's nodes that require issuing discovery
3558 * ADISC.
3559 **/
dea31012005-04-17 16:05:31 -05003560void
James Smart2e0fef82007-06-17 19:56:36 -05003561lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003562{
James Smart2e0fef82007-06-17 19:56:36 -05003563 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003564 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003565
James Smart0d2b6b82008-06-14 22:52:47 -04003566 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3567 return;
James Smart2e0fef82007-06-17 19:56:36 -05003568 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003569 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003570 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003571 del_timer_sync(&nlp->nlp_delayfunc);
3572 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003573 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003574 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003575 /* Decrement nlp reference count held for the delayed retry */
3576 evtp = &nlp->els_retry_evt;
3577 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3578 }
James Smartfdcebe22006-03-07 15:04:01 -05003579 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05003580 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003581 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05003582 spin_unlock_irq(shost->host_lock);
3583 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003584 if (vport->port_state < LPFC_VPORT_READY) {
3585 /* Check if there are more ADISCs to be sent */
3586 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003587 } else {
3588 /* Check if there are more PLOGIs to be sent */
3589 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003590 if (vport->num_disc_nodes == 0) {
3591 spin_lock_irq(shost->host_lock);
3592 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3593 spin_unlock_irq(shost->host_lock);
3594 lpfc_can_disctmo(vport);
3595 lpfc_end_rscn(vport);
3596 }
James Smartfdcebe22006-03-07 15:04:01 -05003597 }
3598 }
3599 }
3600 return;
3601}
3602
James Smarte59058c2008-08-24 21:49:00 -04003603/**
James Smart3621a712009-04-06 18:47:14 -04003604 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01003605 * @t: pointer to the timer function associated data (ndlp).
James Smarte59058c2008-08-24 21:49:00 -04003606 *
3607 * This routine is invoked by the ndlp delayed-function timer to check
3608 * whether there is any pending ELS retry event(s) with the node. If not, it
3609 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3610 * adds the delayed events to the HBA work list and invokes the
3611 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3612 * event. Note that lpfc_nlp_get() is called before posting the event to
3613 * the work list to hold reference count of ndlp so that it guarantees the
3614 * reference to ndlp will still be available when the worker thread gets
3615 * to the event associated with the ndlp.
3616 **/
James Smartfdcebe22006-03-07 15:04:01 -05003617void
Kees Cookf22eb4d2017-09-06 20:24:26 -07003618lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05003619{
Kees Cookf22eb4d2017-09-06 20:24:26 -07003620 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05003621 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003622 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003623 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003624 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003625
James Smart92d7f7b2007-06-17 19:56:38 -05003626 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003627 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003628 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003629 return;
3630 }
3631
James Smartfa4066b2008-01-11 01:53:27 -05003632 /* We need to hold the node by incrementing the reference
3633 * count until the queued work is done
3634 */
3635 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003636 if (evtp->evt_arg1) {
3637 evtp->evt = LPFC_EVT_ELS_RETRY;
3638 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003639 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003640 }
James Smart92d7f7b2007-06-17 19:56:38 -05003641 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003642 return;
3643}
3644
James Smarte59058c2008-08-24 21:49:00 -04003645/**
James Smart3621a712009-04-06 18:47:14 -04003646 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003647 * @ndlp: pointer to a node-list data structure.
3648 *
3649 * This routine is the worker-thread handler for processing the @ndlp delayed
3650 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3651 * the last ELS command from the associated ndlp and invokes the proper ELS
3652 * function according to the delayed ELS command to retry the command.
3653 **/
dea31012005-04-17 16:05:31 -05003654void
3655lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3656{
James Smart2e0fef82007-06-17 19:56:36 -05003657 struct lpfc_vport *vport = ndlp->vport;
3658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003659 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003660
James Smart2e0fef82007-06-17 19:56:36 -05003661 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003662 cmd = ndlp->nlp_last_elscmd;
3663 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003664
3665 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003667 return;
3668 }
3669
3670 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003671 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003672 /*
3673 * If a discovery event readded nlp_delayfunc after timer
3674 * firing and before processing the timer, cancel the
3675 * nlp_delayfunc.
3676 */
3677 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003678 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003679 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003680
3681 switch (cmd) {
3682 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003683 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003684 break;
3685 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003686 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003687 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003689 }
dea31012005-04-17 16:05:31 -05003690 break;
3691 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003692 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003693 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003694 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003695 }
dea31012005-04-17 16:05:31 -05003696 break;
3697 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003698 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003699 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003700 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003702 }
dea31012005-04-17 16:05:31 -05003703 break;
3704 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003705 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003706 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003708 }
dea31012005-04-17 16:05:31 -05003709 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003710 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003711 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3712 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003713 break;
dea31012005-04-17 16:05:31 -05003714 }
3715 return;
3716}
3717
James Smarte59058c2008-08-24 21:49:00 -04003718/**
James Smart5cca2ab2018-10-23 13:41:04 -07003719 * lpfc_link_reset - Issue link reset
3720 * @vport: pointer to a virtual N_Port data structure.
3721 *
3722 * This routine performs link reset by sending INIT_LINK mailbox command.
3723 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3724 * INIT_LINK mailbox command.
3725 *
3726 * Return code
3727 * 0 - Link reset initiated successfully
3728 * 1 - Failed to initiate link reset
3729 **/
3730int
3731lpfc_link_reset(struct lpfc_vport *vport)
3732{
3733 struct lpfc_hba *phba = vport->phba;
3734 LPFC_MBOXQ_t *mbox;
3735 uint32_t control;
3736 int rc;
3737
3738 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3739 "2851 Attempt link reset\n");
3740 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3741 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003742 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07003743 "2852 Failed to allocate mbox memory");
3744 return 1;
3745 }
3746
3747 /* Enable Link attention interrupts */
3748 if (phba->sli_rev <= LPFC_SLI_REV3) {
3749 spin_lock_irq(&phba->hbalock);
3750 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3751 control = readl(phba->HCregaddr);
3752 control |= HC_LAINT_ENA;
3753 writel(control, phba->HCregaddr);
3754 readl(phba->HCregaddr); /* flush */
3755 spin_unlock_irq(&phba->hbalock);
3756 }
3757
3758 lpfc_init_link(phba, mbox, phba->cfg_topology,
3759 phba->cfg_link_speed);
3760 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3761 mbox->vport = vport;
3762 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3763 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003764 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5cca2ab2018-10-23 13:41:04 -07003765 "2853 Failed to issue INIT_LINK "
3766 "mbox command, rc:x%x\n", rc);
3767 mempool_free(mbox, phba->mbox_mem_pool);
3768 return 1;
3769 }
3770
3771 return 0;
3772}
3773
3774/**
James Smart3621a712009-04-06 18:47:14 -04003775 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003776 * @phba: pointer to lpfc hba data structure.
3777 * @cmdiocb: pointer to lpfc command iocb data structure.
3778 * @rspiocb: pointer to lpfc response iocb data structure.
3779 *
3780 * This routine makes a retry decision on an ELS command IOCB, which has
3781 * failed. The following ELS IOCBs use this function for retrying the command
3782 * when previously issued command responsed with error status: FLOGI, PLOGI,
3783 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3784 * returned error status, it makes the decision whether a retry shall be
3785 * issued for the command, and whether a retry shall be made immediately or
3786 * delayed. In the former case, the corresponding ELS command issuing-function
3787 * is called to retry the command. In the later case, the ELS command shall
3788 * be posted to the ndlp delayed event and delayed function timer set to the
3789 * ndlp for the delayed command issusing.
3790 *
3791 * Return code
3792 * 0 - No retry of els command is made
3793 * 1 - Immediate or delayed retry of els command is made
3794 **/
dea31012005-04-17 16:05:31 -05003795static int
James Smart2e0fef82007-06-17 19:56:36 -05003796lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3797 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003798{
James Smart2e0fef82007-06-17 19:56:36 -05003799 struct lpfc_vport *vport = cmdiocb->vport;
3800 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3801 IOCB_t *irsp = &rspiocb->iocb;
3802 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3803 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
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) {
4058 spin_lock_irq(shost->host_lock);
4059 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4060 spin_unlock_irq(shost->host_lock);
4061 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 Smart2e0fef82007-06-17 19:56:36 -05004163 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004164 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004165 spin_unlock_irq(shost->host_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,
4391 "0109 ACC to LOGO completes to NPort x%x "
4392 "Data: x%x x%x x%x\n",
4393 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4394 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 Smart307e3382020-11-15 11:26:30 -08004446 "0006 rpi%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);
4450 lpfc_nlp_put(ndlp);
4451 /* This is the end of the default RPI cleanup logic for
4452 * this ndlp. If no other discovery threads are using
4453 * this ndlp, free all resources associated with it.
4454 */
4455 lpfc_nlp_not_used(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04004456 }
James Smart3772a992009-05-22 14:50:54 -04004457
James Smart858c9f62007-06-17 19:56:39 -05004458 return;
4459}
4460
James Smarte59058c2008-08-24 21:49:00 -04004461/**
James Smart3621a712009-04-06 18:47:14 -04004462 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004463 * @phba: pointer to lpfc hba data structure.
4464 * @cmdiocb: pointer to lpfc command iocb data structure.
4465 * @rspiocb: pointer to lpfc response iocb data structure.
4466 *
4467 * This routine is the completion callback function for ELS Response IOCB
4468 * command. In normal case, this callback function just properly sets the
4469 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4470 * field in the command IOCB is not NULL, the referred mailbox command will
4471 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4472 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4473 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4474 * routine shall be invoked trying to release the ndlp if no other threads
4475 * are currently referring it.
4476 **/
dea31012005-04-17 16:05:31 -05004477static void
James Smart858c9f62007-06-17 19:56:39 -05004478lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04004479 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004480{
James Smart2e0fef82007-06-17 19:56:36 -05004481 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4482 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4483 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04004484 IOCB_t *irsp;
4485 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05004486 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004487 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04004488 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05004489
James Smart33ccf8d2006-08-17 11:57:58 -04004490 irsp = &rspiocb->iocb;
4491
James Smart43bfea12019-09-21 20:58:57 -07004492 if (!vport) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004493 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartf84f8f92019-10-18 14:18:23 -07004494 "3177 ELS response failed\n");
James Smart43bfea12019-09-21 20:58:57 -07004495 goto out;
4496 }
dea31012005-04-17 16:05:31 -05004497 if (cmdiocb->context_un.mbox)
4498 mbox = cmdiocb->context_un.mbox;
4499
James Smartfa4066b2008-01-11 01:53:27 -05004500 /* First determine if this is a LS_RJT cmpl. Note, this callback
4501 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4502 */
James Smart87af33f2007-10-27 13:37:43 -04004503 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart307e3382020-11-15 11:26:30 -08004504 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05004505 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08004506 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04004507 */
4508 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4509 ls_rjt = 1;
4510 }
4511
dea31012005-04-17 16:05:31 -05004512 /* Check to see if link went down during discovery */
James Smart307e3382020-11-15 11:26:30 -08004513 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05004514 if (mbox) {
James Smart3e1f0712018-11-29 16:09:29 -08004515 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004516 if (mp) {
4517 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4518 kfree(mp);
4519 }
James Smart329f9bc2007-04-25 09:53:01 -04004520 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004521 }
James Smart307e3382020-11-15 11:26:30 -08004522 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05004523 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004524 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004525 /* Indicate the node has already released,
4526 * should not reference to it from within
4527 * the routine lpfc_els_free_iocb.
4528 */
4529 cmdiocb->context1 = NULL;
4530 }
dea31012005-04-17 16:05:31 -05004531 goto out;
4532 }
4533
James Smart858c9f62007-06-17 19:56:39 -05004534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04004535 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004536 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04004537 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05004538 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04004539 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4540 "0110 ELS response tag x%x completes "
4541 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4542 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4543 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4544 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4545 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004546 if (mbox) {
James Smart4430f7f2020-11-15 11:26:31 -08004547 if ((rspiocb->iocb.ulpStatus == 0) &&
4548 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07004549 if (!lpfc_unreg_rpi(vport, ndlp) &&
James Smart4430f7f2020-11-15 11:26:31 -08004550 (!(vport->fc_flag & FC_PT2PT))) {
4551 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4552 lpfc_printf_vlog(vport, KERN_INFO,
4553 LOG_DISCOVERY,
4554 "0314 PLOGI recov "
4555 "DID x%x "
4556 "Data: x%x x%x x%x\n",
4557 ndlp->nlp_DID,
4558 ndlp->nlp_state,
4559 ndlp->nlp_rpi,
4560 ndlp->nlp_flag);
4561 mp = mbox->ctx_buf;
4562 if (mp) {
4563 lpfc_mbuf_free(phba, mp->virt,
4564 mp->phys);
4565 kfree(mp);
4566 }
4567 mempool_free(mbox, phba->mbox_mem_pool);
4568 goto out;
Dick Kennedy1fe68472017-08-23 16:55:30 -07004569 }
Dick Kennedy1fe68472017-08-23 16:55:30 -07004570 }
4571
James Smarte47c9092008-02-08 18:49:26 -05004572 /* Increment reference count to ndlp to hold the
4573 * reference to ndlp for the callback function.
4574 */
James Smart3e1f0712018-11-29 16:09:29 -08004575 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08004576 if (!mbox->ctx_ndlp)
4577 goto out;
4578
James Smart2e0fef82007-06-17 19:56:36 -05004579 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004580 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4581 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4582 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4583 }
4584 else {
4585 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4586 ndlp->nlp_prev_state = ndlp->nlp_state;
4587 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05004588 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004589 }
James Smart4b7789b72015-12-16 18:11:55 -05004590
4591 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04004592 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05004593 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05004594 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05004595
4596 /* Decrement the ndlp reference count we
4597 * set for this failed mailbox command.
4598 */
4599 lpfc_nlp_put(ndlp);
4600 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04004601
4602 /* ELS rsp: Cannot issue reg_login for <NPortid> */
Dick Kennedy372c1872020-06-30 14:50:00 -07004603 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart98c9ea52007-10-27 13:37:33 -04004604 "0138 ELS rsp: Cannot issue reg_login for x%x "
4605 "Data: x%x x%x x%x\n",
4606 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4607 ndlp->nlp_rpi);
4608
James Smartfa4066b2008-01-11 01:53:27 -05004609 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004610 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004611 /* Indicate node has already been released,
4612 * should not reference to it from within
4613 * the routine lpfc_els_free_iocb.
4614 */
4615 cmdiocb->context1 = NULL;
4616 }
dea31012005-04-17 16:05:31 -05004617 } else {
James Smart858c9f62007-06-17 19:56:39 -05004618 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4619 if (!lpfc_error_lost_link(irsp) &&
4620 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05004621 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004622 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004623 /* Indicate node has already been
4624 * released, should not reference
4625 * to it from within the routine
4626 * lpfc_els_free_iocb.
4627 */
4628 cmdiocb->context1 = NULL;
4629 }
dea31012005-04-17 16:05:31 -05004630 }
4631 }
James Smart3e1f0712018-11-29 16:09:29 -08004632 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004633 if (mp) {
4634 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4635 kfree(mp);
4636 }
4637 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004638 }
4639out:
James Smart307e3382020-11-15 11:26:30 -08004640 if (ndlp && shost) {
James Smart2e0fef82007-06-17 19:56:36 -05004641 spin_lock_irq(shost->host_lock);
James Smart7b08e892020-08-28 10:53:30 -07004642 if (mbox)
4643 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4644 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
James Smart2e0fef82007-06-17 19:56:36 -05004645 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04004646
4647 /* If the node is not being used by another discovery thread,
4648 * and we are sending a reject, we are done with it.
4649 * Release driver reference count here and free associated
4650 * resources.
4651 */
4652 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05004653 if (lpfc_nlp_not_used(ndlp))
4654 /* Indicate node has already been released,
4655 * should not reference to it from within
4656 * the routine lpfc_els_free_iocb.
4657 */
4658 cmdiocb->context1 = NULL;
James Smart4b7789b72015-12-16 18:11:55 -05004659
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 Scsi_Host *shost = lpfc_shost_from_vport(vport);
4699 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004700 IOCB_t *icmd;
4701 IOCB_t *oldcmd;
4702 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004703 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004704 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004705 uint16_t cmdsize;
4706 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004707 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004708
dea31012005-04-17 16:05:31 -05004709 oldcmd = &oldiocb->iocb;
4710
4711 switch (flag) {
4712 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004713 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004714 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4715 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004716 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05004717 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004718 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004719 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004720 return 1;
dea31012005-04-17 16:05:31 -05004721 }
James Smart2e0fef82007-06-17 19:56:36 -05004722
dea31012005-04-17 16:05:31 -05004723 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004724 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4725 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004726 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4727 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004728 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004729
4730 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4731 "Issue ACC: did:x%x flg:x%x",
4732 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004733 break;
James Smartd6de08c2015-12-16 18:11:53 -05004734 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004735 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004736 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004737 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4738 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004739 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004740 return 1;
James Smart488d1462006-03-07 15:02:37 -05004741
dea31012005-04-17 16:05:31 -05004742 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004743 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4744 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004745 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4746
4747 if (mbox)
4748 elsiocb->context_un.mbox = mbox;
4749
4750 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004751 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004752 sp = (struct serv_parm *)pcmd;
4753
4754 if (flag == ELS_CMD_FLOGI) {
4755 /* Copy the received service parameters back */
4756 memcpy(sp, &phba->fc_fabparam,
4757 sizeof(struct serv_parm));
4758
4759 /* Clear the F_Port bit */
4760 sp->cmn.fPort = 0;
4761
4762 /* Mark all class service parameters as invalid */
4763 sp->cls1.classValid = 0;
4764 sp->cls2.classValid = 0;
4765 sp->cls3.classValid = 0;
4766 sp->cls4.classValid = 0;
4767
4768 /* Copy our worldwide names */
4769 memcpy(&sp->portName, &vport->fc_sparam.portName,
4770 sizeof(struct lpfc_name));
4771 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4772 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004773 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004774 memcpy(pcmd, &vport->fc_sparam,
4775 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004776
James Smart8c258642017-02-12 13:52:36 -08004777 sp->cmn.valid_vendor_ver_level = 0;
4778 memset(sp->un.vendorVersion, 0,
4779 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07004780 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08004781
4782 /* If our firmware supports this feature, convey that
4783 * info to the target using the vendor specific field.
4784 */
4785 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4786 sp->cmn.valid_vendor_ver_level = 1;
4787 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4788 sp->un.vv.flags =
4789 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4790 }
4791 }
4792
James Smart858c9f62007-06-17 19:56:39 -05004793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004794 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004795 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004796 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004797 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004798 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004799 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004800 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4801 if (!elsiocb)
4802 return 1;
4803
4804 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004805 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4806 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004807 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4808
4809 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004810 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004811 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4812 els_pkt_ptr = (ELS_PKT *) pcmd;
4813 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004814
4815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4816 "Issue ACC PRLO: did:x%x flg:x%x",
4817 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004818 break;
dea31012005-04-17 16:05:31 -05004819 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004820 return 1;
dea31012005-04-17 16:05:31 -05004821 }
dea31012005-04-17 16:05:31 -05004822 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004823 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004824 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4825 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4826 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004827 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004828 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4829 } else {
James Smart858c9f62007-06-17 19:56:39 -05004830 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004831 }
4832
4833 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08004834 elsiocb->context1 = lpfc_nlp_get(ndlp);
4835 if (!elsiocb->context1)
4836 goto node_err;
4837
James Smart3772a992009-05-22 14:50:54 -04004838 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08004839 if (rc == IOCB_ERROR)
4840 goto io_err;
4841
4842 /* Xmit ELS ACC response tag <ulpIoTag> */
4843 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4844 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4845 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4846 "RPI: x%x, fc_flag x%x\n",
4847 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4848 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4849 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004850 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08004851
4852io_err:
4853 lpfc_nlp_put(ndlp);
4854node_err:
4855 lpfc_els_free_iocb(phba, elsiocb);
4856 return 1;
dea31012005-04-17 16:05:31 -05004857}
4858
James Smarte59058c2008-08-24 21:49:00 -04004859/**
James Smart3621a712009-04-06 18:47:14 -04004860 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004861 * @vport: pointer to a virtual N_Port data structure.
Lee Jonesa0e4a642020-07-23 13:24:07 +01004862 * @rejectError: reject response to issue
James Smarte59058c2008-08-24 21:49:00 -04004863 * @oldiocb: pointer to the original lpfc command iocb data structure.
4864 * @ndlp: pointer to a node-list data structure.
4865 * @mbox: pointer to the driver internal queue element for mailbox command.
4866 *
4867 * This routine prepares and issue an Reject (RJT) response IOCB
4868 * command. If a @mbox pointer is passed in, it will be put into the
4869 * context_un.mbox field of the IOCB for the completion callback function
4870 * to issue to the HBA later.
4871 *
4872 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4873 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4874 * will be stored into the context1 field of the IOCB for the completion
4875 * callback function to the reject response ELS IOCB command.
4876 *
4877 * Return code
4878 * 0 - Successfully issued reject response
4879 * 1 - Failed to issue reject response
4880 **/
dea31012005-04-17 16:05:31 -05004881int
James Smart2e0fef82007-06-17 19:56:36 -05004882lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004883 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4884 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004885{
James Smart4430f7f2020-11-15 11:26:31 -08004886 int rc;
James Smart2e0fef82007-06-17 19:56:36 -05004887 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004888 IOCB_t *icmd;
4889 IOCB_t *oldcmd;
4890 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004891 uint8_t *pcmd;
4892 uint16_t cmdsize;
dea31012005-04-17 16:05:31 -05004893
James Smart92d7f7b2007-06-17 19:56:38 -05004894 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004895 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4896 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004897 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004898 return 1;
dea31012005-04-17 16:05:31 -05004899
4900 icmd = &elsiocb->iocb;
4901 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004904 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4905
4906 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004907 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004908 *((uint32_t *) (pcmd)) = rejectError;
4909
James Smart51ef4c22007-08-02 11:10:31 -04004910 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004911 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004912
dea31012005-04-17 16:05:31 -05004913 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4915 "0129 Xmit ELS RJT x%x response tag x%x "
4916 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4917 "rpi x%x\n",
4918 rejectError, elsiocb->iotag,
4919 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4920 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4922 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4923 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4924
dea31012005-04-17 16:05:31 -05004925 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004926 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08004927 elsiocb->context1 = lpfc_nlp_get(ndlp);
4928 if (!elsiocb->context1)
4929 goto node_err;
James Smart51ef4c22007-08-02 11:10:31 -04004930
James Smart4430f7f2020-11-15 11:26:31 -08004931 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4932 if (rc == IOCB_ERROR)
4933 goto io_err;
4934
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004935 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08004936
4937 io_err:
4938 lpfc_nlp_put(ndlp);
4939 node_err:
4940 lpfc_els_free_iocb(phba, elsiocb);
4941 return 1;
dea31012005-04-17 16:05:31 -05004942}
4943
James Smarte59058c2008-08-24 21:49:00 -04004944/**
James Smart3621a712009-04-06 18:47:14 -04004945 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004946 * @vport: pointer to a virtual N_Port data structure.
4947 * @oldiocb: pointer to the original lpfc command iocb data structure.
4948 * @ndlp: pointer to a node-list data structure.
4949 *
4950 * This routine prepares and issues an Accept (ACC) response to Address
4951 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4952 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4953 *
4954 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4955 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4956 * will be stored into the context1 field of the IOCB for the completion
4957 * callback function to the ADISC Accept response ELS IOCB command.
4958 *
4959 * Return code
4960 * 0 - Successfully issued acc adisc response
4961 * 1 - Failed to issue adisc acc response
4962 **/
dea31012005-04-17 16:05:31 -05004963int
James Smart2e0fef82007-06-17 19:56:36 -05004964lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4965 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004966{
James Smart2e0fef82007-06-17 19:56:36 -05004967 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004968 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004969 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004970 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004971 uint8_t *pcmd;
4972 uint16_t cmdsize;
4973 int rc;
4974
James Smart92d7f7b2007-06-17 19:56:38 -05004975 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004976 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4977 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004978 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004979 return 1;
dea31012005-04-17 16:05:31 -05004980
dea31012005-04-17 16:05:31 -05004981 icmd = &elsiocb->iocb;
4982 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004983 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4984 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004985
4986 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004987 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4988 "0130 Xmit ADISC ACC response iotag x%x xri: "
4989 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4990 elsiocb->iotag, elsiocb->iocb.ulpContext,
4991 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4992 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4994
4995 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004996 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004997
4998 ap = (ADISC *) (pcmd);
4999 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05005000 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5001 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05005002 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05005003
James Smart858c9f62007-06-17 19:56:39 -05005004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005005 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5006 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005007
dea31012005-04-17 16:05:31 -05005008 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005009 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005010 elsiocb->context1 = lpfc_nlp_get(ndlp);
5011 if (!elsiocb->context1)
5012 goto node_err;
5013
James Smart3772a992009-05-22 14:50:54 -04005014 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005015 if (rc == IOCB_ERROR)
5016 goto io_err;
James Smartd496b9a2018-10-23 13:41:08 -07005017
5018 /* Xmit ELS ACC response tag <ulpIoTag> */
5019 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5020 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5021 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5022 "RPI: x%x, fc_flag x%x\n",
5023 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5024 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5025 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005026 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005027
5028io_err:
5029 lpfc_nlp_put(ndlp);
5030node_err:
5031 lpfc_els_free_iocb(phba, elsiocb);
5032 return 1;
dea31012005-04-17 16:05:31 -05005033}
5034
James Smarte59058c2008-08-24 21:49:00 -04005035/**
James Smart3621a712009-04-06 18:47:14 -04005036 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005037 * @vport: pointer to a virtual N_Port data structure.
5038 * @oldiocb: pointer to the original lpfc command iocb data structure.
5039 * @ndlp: pointer to a node-list data structure.
5040 *
5041 * This routine prepares and issues an Accept (ACC) response to Process
5042 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5043 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5044 *
5045 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5046 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5047 * will be stored into the context1 field of the IOCB for the completion
5048 * callback function to the PRLI Accept response ELS IOCB command.
5049 *
5050 * Return code
5051 * 0 - Successfully issued acc prli response
5052 * 1 - Failed to issue acc prli response
5053 **/
dea31012005-04-17 16:05:31 -05005054int
James Smart2e0fef82007-06-17 19:56:36 -05005055lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04005056 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005057{
James Smart2e0fef82007-06-17 19:56:36 -05005058 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005059 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08005060 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05005061 lpfc_vpd_t *vpd;
5062 IOCB_t *icmd;
5063 IOCB_t *oldcmd;
5064 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005065 uint8_t *pcmd;
5066 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08005067 uint32_t prli_fc4_req, *req_payload;
5068 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05005069 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08005070 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05005071
James Smarta0f2d3e2017-02-12 13:52:31 -08005072 /* Need the incoming PRLI payload to determine if the ACC is for an
5073 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5074 */
5075 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5076 req_payload = (((uint32_t *)req_buf->virt) + 1);
5077
5078 /* PRLI type payload is at byte 3 for FCP or NVME. */
5079 prli_fc4_req = be32_to_cpu(*req_payload);
5080 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5081 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5082 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5083 prli_fc4_req, *((uint32_t *)req_payload));
5084
5085 if (prli_fc4_req == PRLI_FCP_TYPE) {
5086 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5087 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5088 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5089 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5090 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5091 } else {
5092 return 1;
5093 }
5094
James Smart2e0fef82007-06-17 19:56:36 -05005095 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08005096 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005097 if (!elsiocb)
5098 return 1;
dea31012005-04-17 16:05:31 -05005099
dea31012005-04-17 16:05:31 -05005100 icmd = &elsiocb->iocb;
5101 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005102 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5103 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5104
James Smart5b8bd0c2007-04-25 09:52:49 -04005105 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5107 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5108 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5109 elsiocb->iotag, elsiocb->iocb.ulpContext,
5110 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5111 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005112 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08005113 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05005114
James Smartc07f10c2017-04-21 16:04:54 -07005115 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005116 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005117
5118 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05005119 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08005120
5121 if (prli_fc4_req == PRLI_FCP_TYPE) {
5122 /*
5123 * If the remote port is a target and our firmware version
5124 * is 3.20 or later, set the following bits for FC-TAPE
5125 * support.
5126 */
5127 npr = (PRLI *) pcmd;
5128 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5129 (vpd->rev.feaLevelHigh >= 0x02)) {
5130 npr->ConfmComplAllowed = 1;
5131 npr->Retry = 1;
5132 npr->TaskRetryIdReq = 1;
5133 }
5134 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5135 npr->estabImagePair = 1;
5136 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05005137 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08005138 npr->prliType = PRLI_FCP_TYPE;
5139 npr->initiatorFunc = 1;
5140 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5141 /* Respond with an NVME PRLI Type */
5142 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5143 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5144 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5145 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08005146 if (phba->nvmet_support) {
5147 bf_set(prli_tgt, npr_nvme, 1);
5148 bf_set(prli_disc, npr_nvme, 1);
5149 if (phba->cfg_nvme_enable_fb) {
5150 bf_set(prli_fba, npr_nvme, 1);
5151
5152 /* TBD. Target mode needs to post buffers
5153 * that support the configured first burst
5154 * byte size.
5155 */
5156 bf_set(prli_fb_sz, npr_nvme,
5157 phba->cfg_nvmet_fb_size);
5158 }
5159 } else {
5160 bf_set(prli_init, npr_nvme, 1);
5161 }
dea31012005-04-17 16:05:31 -05005162
James Smarta0f2d3e2017-02-12 13:52:31 -08005163 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5164 "6015 NVME issue PRLI ACC word1 x%08x "
5165 "word4 x%08x word5 x%08x flag x%x, "
5166 "fcp_info x%x nlp_type x%x\n",
5167 npr_nvme->word1, npr_nvme->word4,
5168 npr_nvme->word5, ndlp->nlp_flag,
5169 ndlp->nlp_fcp_info, ndlp->nlp_type);
5170 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5171 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5172 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5173 } else
5174 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5175 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5176 prli_fc4_req, ndlp->nlp_fc4_type,
5177 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05005178
James Smart858c9f62007-06-17 19:56:39 -05005179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005180 "Issue ACC PRLI: did:x%x flg:x%x",
5181 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005182
dea31012005-04-17 16:05:31 -05005183 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005184 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005185 elsiocb->context1 = lpfc_nlp_get(ndlp);
5186 if (!elsiocb->context1)
5187 goto node_err;
dea31012005-04-17 16:05:31 -05005188
James Smart3772a992009-05-22 14:50:54 -04005189 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005190 if (rc == IOCB_ERROR)
5191 goto io_err;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005192 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005193
5194 io_err:
5195 lpfc_nlp_put(ndlp);
5196 node_err:
5197 lpfc_els_free_iocb(phba, elsiocb);
5198 return 1;
dea31012005-04-17 16:05:31 -05005199}
5200
James Smarte59058c2008-08-24 21:49:00 -04005201/**
James Smart3621a712009-04-06 18:47:14 -04005202 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005203 * @vport: pointer to a virtual N_Port data structure.
5204 * @format: rnid command format.
5205 * @oldiocb: pointer to the original lpfc command iocb data structure.
5206 * @ndlp: pointer to a node-list data structure.
5207 *
5208 * This routine issues a Request Node Identification Data (RNID) Accept
5209 * (ACC) response. It constructs the RNID ACC response command according to
5210 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5211 * issue the response. Note that this command does not need to hold the ndlp
5212 * reference count for the callback. So, the ndlp reference count taken by
5213 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5214 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5215 * there is no ndlp reference available.
5216 *
5217 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5218 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5219 * will be stored into the context1 field of the IOCB for the completion
5220 * callback function. However, for the RNID Accept Response ELS command,
5221 * this is undone later by this routine after the IOCB is allocated.
5222 *
5223 * Return code
5224 * 0 - Successfully issued acc rnid response
5225 * 1 - Failed to issue acc rnid response
5226 **/
dea31012005-04-17 16:05:31 -05005227static int
James Smart2e0fef82007-06-17 19:56:36 -05005228lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04005229 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005230{
James Smart2e0fef82007-06-17 19:56:36 -05005231 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005232 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05005233 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05005234 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005235 uint8_t *pcmd;
5236 uint16_t cmdsize;
5237 int rc;
5238
James Smart92d7f7b2007-06-17 19:56:38 -05005239 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5240 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005241 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05005242 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005243
James Smart2e0fef82007-06-17 19:56:36 -05005244 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5245 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005246 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005247 return 1;
dea31012005-04-17 16:05:31 -05005248
dea31012005-04-17 16:05:31 -05005249 icmd = &elsiocb->iocb;
5250 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005251 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5252 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5253
James Smart5b8bd0c2007-04-25 09:52:49 -04005254 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005255 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5256 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5257 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05005258 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05005259 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005260 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005261
James Smart92d7f7b2007-06-17 19:56:38 -05005262 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05005263 rn = (RNID *) (pcmd);
5264 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05005265 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5266 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5267 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005268 switch (format) {
5269 case 0:
5270 rn->SpecificLen = 0;
5271 break;
5272 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05005273 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005274 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005275 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005276 rn->un.topologyDisc.unitType = RNID_HBA;
5277 rn->un.topologyDisc.physPort = 0;
5278 rn->un.topologyDisc.attachedNodes = 0;
5279 break;
5280 default:
5281 rn->CommonLen = 0;
5282 rn->SpecificLen = 0;
5283 break;
5284 }
5285
James Smart858c9f62007-06-17 19:56:39 -05005286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005287 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5288 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -05005289
dea31012005-04-17 16:05:31 -05005290 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005291 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005292 elsiocb->context1 = lpfc_nlp_get(ndlp);
5293 if (!elsiocb->context1)
5294 goto node_err;
dea31012005-04-17 16:05:31 -05005295
James Smart3772a992009-05-22 14:50:54 -04005296 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005297 if (rc == IOCB_ERROR)
5298 goto io_err;
5299
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005300 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005301
5302 io_err:
5303 lpfc_nlp_put(ndlp);
5304 node_err:
5305 lpfc_els_free_iocb(phba, elsiocb);
5306 return 1;
dea31012005-04-17 16:05:31 -05005307}
5308
James Smarte59058c2008-08-24 21:49:00 -04005309/**
James Smart19ca7602010-11-20 23:11:55 -05005310 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5311 * @vport: pointer to a virtual N_Port data structure.
5312 * @iocb: pointer to the lpfc command iocb data structure.
5313 * @ndlp: pointer to a node-list data structure.
5314 *
5315 * Return
5316 **/
5317static void
5318lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08005319 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05005320{
5321 struct lpfc_hba *phba = vport->phba;
5322 uint8_t *pcmd;
5323 struct RRQ *rrq;
5324 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05005325 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05005326 struct lpfc_node_rrq *prrq;
5327
5328
5329 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5330 pcmd += sizeof(uint32_t);
5331 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05005332 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04005333 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05005334
5335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5336 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5337 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05005338 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04005339 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05005340 rxid,
5341 iocb->iotag, iocb->iocb.ulpContext);
5342
5343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5344 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5345 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05005346 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04005347 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05005348 else
5349 xri = rxid;
5350 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05005351 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05005352 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05005353 return;
5354}
5355
5356/**
James Smart12265f62010-10-22 11:05:53 -04005357 * lpfc_els_rsp_echo_acc - Issue echo acc response
5358 * @vport: pointer to a virtual N_Port data structure.
5359 * @data: pointer to echo data to return in the accept.
5360 * @oldiocb: pointer to the original lpfc command iocb data structure.
5361 * @ndlp: pointer to a node-list data structure.
5362 *
5363 * Return code
5364 * 0 - Successfully issued acc echo response
5365 * 1 - Failed to issue acc echo response
5366 **/
5367static int
5368lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5369 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5370{
5371 struct lpfc_hba *phba = vport->phba;
5372 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04005373 uint8_t *pcmd;
5374 uint16_t cmdsize;
5375 int rc;
5376
James Smart12265f62010-10-22 11:05:53 -04005377 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5378
James Smartbf086112011-08-21 21:48:13 -04005379 /* The accumulated length can exceed the BPL_SIZE. For
5380 * now, use this as the limit
5381 */
5382 if (cmdsize > LPFC_BPL_SIZE)
5383 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04005384 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5385 ndlp->nlp_DID, ELS_CMD_ACC);
5386 if (!elsiocb)
5387 return 1;
5388
James Smart7851fe22011-07-22 18:36:52 -04005389 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5390 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5391
James Smart12265f62010-10-22 11:05:53 -04005392 /* Xmit ECHO ACC response tag <ulpIoTag> */
5393 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5394 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5395 elsiocb->iotag, elsiocb->iocb.ulpContext);
5396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5397 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5398 pcmd += sizeof(uint32_t);
5399 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5400
5401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart4430f7f2020-11-15 11:26:31 -08005402 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5403 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smart12265f62010-10-22 11:05:53 -04005404
5405 phba->fc_stat.elsXmitACC++;
5406 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08005407 elsiocb->context1 = lpfc_nlp_get(ndlp);
5408 if (!elsiocb->context1)
5409 goto node_err;
James Smart12265f62010-10-22 11:05:53 -04005410
5411 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart4430f7f2020-11-15 11:26:31 -08005412 if (rc == IOCB_ERROR)
5413 goto io_err;
James Smart12265f62010-10-22 11:05:53 -04005414 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08005415
5416 io_err:
5417 lpfc_nlp_put(ndlp);
5418 node_err:
5419 lpfc_els_free_iocb(phba, elsiocb);
5420 return 1;
James Smart12265f62010-10-22 11:05:53 -04005421}
5422
5423/**
James Smart3621a712009-04-06 18:47:14 -04005424 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04005425 * @vport: pointer to a host virtual N_Port data structure.
5426 *
5427 * This routine issues Address Discover (ADISC) ELS commands to those
5428 * N_Ports which are in node port recovery state and ADISC has not been issued
5429 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5430 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5431 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5432 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5433 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5434 * IOCBs quit for later pick up. On the other hand, after walking through
5435 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5436 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5437 * no more ADISC need to be sent.
5438 *
5439 * Return code
5440 * The number of N_Ports with adisc issued.
5441 **/
dea31012005-04-17 16:05:31 -05005442int
James Smart2e0fef82007-06-17 19:56:36 -05005443lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005444{
James Smart2e0fef82007-06-17 19:56:36 -05005445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005446 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005447 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05005448
James Smart685f0bf2007-04-25 09:53:08 -04005449 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05005450 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04005451 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5452 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5453 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05005454 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005455 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05005456 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005457 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5459 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005460 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05005461 vport->num_disc_nodes++;
5462 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04005463 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005464 spin_lock_irq(shost->host_lock);
5465 vport->fc_flag |= FC_NLP_MORE;
5466 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005467 break;
dea31012005-04-17 16:05:31 -05005468 }
5469 }
5470 }
5471 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05005472 spin_lock_irq(shost->host_lock);
5473 vport->fc_flag &= ~FC_NLP_MORE;
5474 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005475 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005476 return sentadisc;
dea31012005-04-17 16:05:31 -05005477}
5478
James Smarte59058c2008-08-24 21:49:00 -04005479/**
James Smart3621a712009-04-06 18:47:14 -04005480 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04005481 * @vport: pointer to a host virtual N_Port data structure.
5482 *
5483 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5484 * which are in node port recovery state, with a @vport. Each time an ELS
5485 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5486 * the per @vport number of discover count (num_disc_nodes) shall be
5487 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5488 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5489 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5490 * later pick up. On the other hand, after walking through all the ndlps with
5491 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5492 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5493 * PLOGI need to be sent.
5494 *
5495 * Return code
5496 * The number of N_Ports with plogi issued.
5497 **/
dea31012005-04-17 16:05:31 -05005498int
James Smart2e0fef82007-06-17 19:56:36 -05005499lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005500{
James Smart2e0fef82007-06-17 19:56:36 -05005501 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005502 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005503 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05005504
James Smart2e0fef82007-06-17 19:56:36 -05005505 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5506 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04005507 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04005508 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5509 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5510 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04005511 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005512 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5513 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005514 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05005515 vport->num_disc_nodes++;
5516 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04005517 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005518 spin_lock_irq(shost->host_lock);
5519 vport->fc_flag |= FC_NLP_MORE;
5520 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005521 break;
dea31012005-04-17 16:05:31 -05005522 }
5523 }
5524 }
James Smartb4b34172019-10-18 14:18:31 -07005525
5526 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5527 "6452 Discover PLOGI %d flag x%x\n",
5528 sentplogi, vport->fc_flag);
5529
James Smart87af33f2007-10-27 13:37:43 -04005530 if (sentplogi) {
5531 lpfc_set_disctmo(vport);
5532 }
5533 else {
James Smart2e0fef82007-06-17 19:56:36 -05005534 spin_lock_irq(shost->host_lock);
5535 vport->fc_flag &= ~FC_NLP_MORE;
5536 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005537 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005538 return sentplogi;
dea31012005-04-17 16:05:31 -05005539}
5540
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005541static uint32_t
James Smart86478872015-05-21 13:55:21 -04005542lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5543 uint32_t word0)
5544{
5545
5546 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5547 desc->payload.els_req = word0;
5548 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07005549
5550 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04005551}
5552
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005553static uint32_t
James Smart86478872015-05-21 13:55:21 -04005554lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5555 uint8_t *page_a0, uint8_t *page_a2)
5556{
5557 uint16_t wavelength;
5558 uint16_t temperature;
5559 uint16_t rx_power;
5560 uint16_t tx_bias;
5561 uint16_t tx_power;
5562 uint16_t vcc;
5563 uint16_t flag = 0;
5564 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5565 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5566
5567 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5568
5569 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5570 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5571 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5572 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5573
5574 if ((trasn_code_byte4->fc_sw_laser) ||
5575 (trasn_code_byte5->fc_sw_laser_sl) ||
5576 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5577 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5578 } else if (trasn_code_byte4->fc_lw_laser) {
5579 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5580 page_a0[SSF_WAVELENGTH_B0];
5581 if (wavelength == SFP_WAVELENGTH_LC1310)
5582 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5583 if (wavelength == SFP_WAVELENGTH_LL1550)
5584 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5585 }
5586 /* check if its SFP+ */
5587 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5588 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5589 << SFP_FLAG_CT_SHIFT;
5590
5591 /* check if its OPTICAL */
5592 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5593 SFP_FLAG_IS_OPTICAL_PORT : 0)
5594 << SFP_FLAG_IS_OPTICAL_SHIFT;
5595
5596 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5597 page_a2[SFF_TEMPERATURE_B0]);
5598 vcc = (page_a2[SFF_VCC_B1] << 8 |
5599 page_a2[SFF_VCC_B0]);
5600 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5601 page_a2[SFF_TXPOWER_B0]);
5602 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5603 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5604 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5605 page_a2[SFF_RXPOWER_B0]);
5606 desc->sfp_info.temperature = cpu_to_be16(temperature);
5607 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5608 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5609 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5610 desc->sfp_info.vcc = cpu_to_be16(vcc);
5611
5612 desc->sfp_info.flags = cpu_to_be16(flag);
5613 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005614
5615 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04005616}
5617
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005618static uint32_t
James Smart86478872015-05-21 13:55:21 -04005619lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5620 READ_LNK_VAR *stat)
5621{
5622 uint32_t type;
5623
5624 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5625
5626 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5627
5628 desc->info.port_type = cpu_to_be32(type);
5629
5630 desc->info.link_status.link_failure_cnt =
5631 cpu_to_be32(stat->linkFailureCnt);
5632 desc->info.link_status.loss_of_synch_cnt =
5633 cpu_to_be32(stat->lossSyncCnt);
5634 desc->info.link_status.loss_of_signal_cnt =
5635 cpu_to_be32(stat->lossSignalCnt);
5636 desc->info.link_status.primitive_seq_proto_err =
5637 cpu_to_be32(stat->primSeqErrCnt);
5638 desc->info.link_status.invalid_trans_word =
5639 cpu_to_be32(stat->invalidXmitWord);
5640 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5641
5642 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005643
5644 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04005645}
5646
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005647static uint32_t
James Smart56204982016-03-31 14:12:32 -07005648lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5649 struct lpfc_vport *vport)
5650{
James Smart3aaaa312016-07-06 12:35:57 -07005651 uint32_t bbCredit;
5652
James Smart56204982016-03-31 14:12:32 -07005653 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5654
James Smart3aaaa312016-07-06 12:35:57 -07005655 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5656 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5657 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5658 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5659 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5660 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5661 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5662 } else {
James Smart56204982016-03-31 14:12:32 -07005663 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07005664 }
James Smart56204982016-03-31 14:12:32 -07005665
5666 desc->bbc_info.rtt = 0;
5667 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005668
5669 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07005670}
5671
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005672static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005673lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5674 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07005675{
James Smart310429e2016-07-06 12:35:54 -07005676 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005677
5678 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5679
James Smart3aaaa312016-07-06 12:35:57 -07005680 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5681 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5682 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5683 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005684
5685 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5686 flags |= RDP_OET_HIGH_ALARM;
5687 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5688 flags |= RDP_OET_LOW_ALARM;
5689 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5690 flags |= RDP_OET_HIGH_WARNING;
5691 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5692 flags |= RDP_OET_LOW_WARNING;
5693
James Smart56204982016-03-31 14:12:32 -07005694 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5695 desc->oed_info.function_flags = cpu_to_be32(flags);
5696 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005697 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005698}
5699
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005700static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005701lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5702 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005703 uint8_t *page_a2)
5704{
James Smart310429e2016-07-06 12:35:54 -07005705 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005706
5707 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5708
James Smart3aaaa312016-07-06 12:35:57 -07005709 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5710 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5711 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5712 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005713
5714 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5715 flags |= RDP_OET_HIGH_ALARM;
5716 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5717 flags |= RDP_OET_LOW_ALARM;
5718 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5719 flags |= RDP_OET_HIGH_WARNING;
5720 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5721 flags |= RDP_OET_LOW_WARNING;
5722
James Smart56204982016-03-31 14:12:32 -07005723 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5724 desc->oed_info.function_flags = cpu_to_be32(flags);
5725 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005726 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005727}
5728
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005729static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005730lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5731 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005732 uint8_t *page_a2)
5733{
James Smart310429e2016-07-06 12:35:54 -07005734 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005735
5736 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5737
James Smart3aaaa312016-07-06 12:35:57 -07005738 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5739 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5740 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5741 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005742
5743 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5744 flags |= RDP_OET_HIGH_ALARM;
5745 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5746 flags |= RDP_OET_LOW_ALARM;
5747 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5748 flags |= RDP_OET_HIGH_WARNING;
5749 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5750 flags |= RDP_OET_LOW_WARNING;
5751
James Smart56204982016-03-31 14:12:32 -07005752 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5753 desc->oed_info.function_flags = cpu_to_be32(flags);
5754 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005755 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005756}
5757
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005758static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005759lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5760 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005761 uint8_t *page_a2)
5762{
James Smart310429e2016-07-06 12:35:54 -07005763 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005764
5765 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5766
James Smart3aaaa312016-07-06 12:35:57 -07005767 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5768 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5769 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5770 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005771
5772 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5773 flags |= RDP_OET_HIGH_ALARM;
5774 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5775 flags |= RDP_OET_LOW_ALARM;
5776 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5777 flags |= RDP_OET_HIGH_WARNING;
5778 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5779 flags |= RDP_OET_LOW_WARNING;
5780
James Smart56204982016-03-31 14:12:32 -07005781 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5782 desc->oed_info.function_flags = cpu_to_be32(flags);
5783 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005784 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005785}
5786
5787
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005788static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005789lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5790 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005791 uint8_t *page_a2)
5792{
James Smart310429e2016-07-06 12:35:54 -07005793 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005794
5795 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5796
James Smart3aaaa312016-07-06 12:35:57 -07005797 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5798 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5799 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5800 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005801
5802 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5803 flags |= RDP_OET_HIGH_ALARM;
5804 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5805 flags |= RDP_OET_LOW_ALARM;
5806 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5807 flags |= RDP_OET_HIGH_WARNING;
5808 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5809 flags |= RDP_OET_LOW_WARNING;
5810
James Smart56204982016-03-31 14:12:32 -07005811 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5812 desc->oed_info.function_flags = cpu_to_be32(flags);
5813 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005814 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005815}
5816
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005817static uint32_t
James Smart56204982016-03-31 14:12:32 -07005818lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5819 uint8_t *page_a0, struct lpfc_vport *vport)
5820{
5821 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5822 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5823 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5824 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005825 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005826 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5827 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005828 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005829}
5830
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005831static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005832lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5833{
5834 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5835 return 0;
5836 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5837
5838 desc->info.CorrectedBlocks =
5839 cpu_to_be32(stat->fecCorrBlkCount);
5840 desc->info.UncorrectableBlocks =
5841 cpu_to_be32(stat->fecUncorrBlkCount);
5842
5843 desc->length = cpu_to_be32(sizeof(desc->info));
5844
5845 return sizeof(struct fc_fec_rdp_desc);
5846}
5847
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005848static uint32_t
James Smart86478872015-05-21 13:55:21 -04005849lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5850{
5851 uint16_t rdp_cap = 0;
5852 uint16_t rdp_speed;
5853
5854 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5855
James Smart81e75172015-12-16 18:11:59 -05005856 switch (phba->fc_linkspeed) {
5857 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005858 rdp_speed = RDP_PS_1GB;
5859 break;
James Smart81e75172015-12-16 18:11:59 -05005860 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005861 rdp_speed = RDP_PS_2GB;
5862 break;
James Smart81e75172015-12-16 18:11:59 -05005863 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005864 rdp_speed = RDP_PS_4GB;
5865 break;
James Smart81e75172015-12-16 18:11:59 -05005866 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005867 rdp_speed = RDP_PS_8GB;
5868 break;
James Smart81e75172015-12-16 18:11:59 -05005869 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005870 rdp_speed = RDP_PS_10GB;
5871 break;
James Smart81e75172015-12-16 18:11:59 -05005872 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005873 rdp_speed = RDP_PS_16GB;
5874 break;
James Smarta085e872015-12-16 18:12:02 -05005875 case LPFC_LINK_SPEED_32GHZ:
5876 rdp_speed = RDP_PS_32GB;
5877 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005878 case LPFC_LINK_SPEED_64GHZ:
5879 rdp_speed = RDP_PS_64GB;
5880 break;
James Smart86478872015-05-21 13:55:21 -04005881 default:
5882 rdp_speed = RDP_PS_UNKNOWN;
5883 break;
5884 }
5885
5886 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5887
James Smart1dc5ec22018-10-23 13:41:11 -07005888 if (phba->lmt & LMT_128Gb)
5889 rdp_cap |= RDP_PS_128GB;
James Smartfbd8a6b2018-02-22 08:18:45 -08005890 if (phba->lmt & LMT_64Gb)
5891 rdp_cap |= RDP_PS_64GB;
James Smartd38dd522015-08-31 16:48:17 -04005892 if (phba->lmt & LMT_32Gb)
5893 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005894 if (phba->lmt & LMT_16Gb)
5895 rdp_cap |= RDP_PS_16GB;
5896 if (phba->lmt & LMT_10Gb)
5897 rdp_cap |= RDP_PS_10GB;
5898 if (phba->lmt & LMT_8Gb)
5899 rdp_cap |= RDP_PS_8GB;
5900 if (phba->lmt & LMT_4Gb)
5901 rdp_cap |= RDP_PS_4GB;
5902 if (phba->lmt & LMT_2Gb)
5903 rdp_cap |= RDP_PS_2GB;
5904 if (phba->lmt & LMT_1Gb)
5905 rdp_cap |= RDP_PS_1GB;
5906
5907 if (rdp_cap == 0)
5908 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005909 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5910 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005911
5912 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5913 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005914 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005915}
5916
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005917static uint32_t
James Smart86478872015-05-21 13:55:21 -04005918lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005919 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005920{
5921
5922 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5923
James Smartcd46cde2017-03-04 09:30:37 -08005924 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005925 sizeof(desc->port_names.wwnn));
5926
James Smartcd46cde2017-03-04 09:30:37 -08005927 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005928 sizeof(desc->port_names.wwpn));
5929
5930 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005931 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005932}
5933
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005934static uint32_t
James Smart86478872015-05-21 13:55:21 -04005935lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5936 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5937{
5938
5939 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5940 if (vport->fc_flag & FC_FABRIC) {
5941 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005942 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005943
5944 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
James Smartd9f492a2019-08-14 16:57:04 -07005945 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005946 } else { /* Point to Point */
5947 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005948 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005949
James Smartd9f492a2019-08-14 16:57:04 -07005950 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5951 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005952 }
5953
5954 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005955 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005956}
5957
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005958static void
James Smart86478872015-05-21 13:55:21 -04005959lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5960 int status)
5961{
5962 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5963 struct lpfc_vport *vport = ndlp->vport;
5964 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005965 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005966 IOCB_t *icmd;
5967 uint8_t *pcmd;
5968 struct ls_rjt *stat;
5969 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005970 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005971 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005972 int rc;
James Smart86478872015-05-21 13:55:21 -04005973
5974 if (status != SUCCESS)
5975 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005976
5977 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005978 cmdsize = sizeof(struct fc_rdp_res_frame);
5979
5980 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5981 lpfc_max_els_tries, rdp_context->ndlp,
5982 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
James Smart86478872015-05-21 13:55:21 -04005983 if (!elsiocb)
5984 goto free_rdp_context;
5985
5986 icmd = &elsiocb->iocb;
5987 icmd->ulpContext = rdp_context->rx_id;
5988 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5989
5990 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5991 "2171 Xmit RDP response tag x%x xri x%x, "
5992 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5993 elsiocb->iotag, elsiocb->iocb.ulpContext,
5994 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5995 ndlp->nlp_rpi);
5996 rdp_res = (struct fc_rdp_res_frame *)
5997 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5998 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5999 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
6000 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6001
James Smart310429e2016-07-06 12:35:54 -07006002 /* Update Alarm and Warning */
6003 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6004 phba->sfp_alarm |= *flag_ptr;
6005 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6006 phba->sfp_warning |= *flag_ptr;
6007
James Smart86478872015-05-21 13:55:21 -04006008 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07006009 len = 8;
6010 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6011 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04006012
James Smart6c92d1d2016-07-06 12:35:55 -07006013 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04006014 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07006015 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6016 phba);
6017 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6018 (len + pcmd), &rdp_context->link_stat);
6019 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08006020 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07006021 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6022 (len + pcmd), vport, ndlp);
6023 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05006024 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07006025 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6026 &rdp_context->link_stat, vport);
6027 len += lpfc_rdp_res_oed_temp_desc(phba,
6028 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6029 rdp_context->page_a2);
6030 len += lpfc_rdp_res_oed_voltage_desc(phba,
6031 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6032 rdp_context->page_a2);
6033 len += lpfc_rdp_res_oed_txbias_desc(phba,
6034 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6035 rdp_context->page_a2);
6036 len += lpfc_rdp_res_oed_txpower_desc(phba,
6037 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6038 rdp_context->page_a2);
6039 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6040 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6041 rdp_context->page_a2);
6042 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6043 rdp_context->page_a0, vport);
6044
James Smart6c92d1d2016-07-06 12:35:55 -07006045 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04006046 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6047
James Smarteb8d68c2015-12-16 18:12:00 -05006048 /* Now that we know the true size of the payload, update the BPL */
6049 bpl = (struct ulp_bde64 *)
6050 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07006051 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05006052 bpl->tus.f.bdeFlags = 0;
6053 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6054
James Smart86478872015-05-21 13:55:21 -04006055 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08006056 elsiocb->context1 = lpfc_nlp_get(ndlp);
6057 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006058 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006059 goto free_rdp_context;
6060 }
James Smart86478872015-05-21 13:55:21 -04006061
James Smart4430f7f2020-11-15 11:26:31 -08006062 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6063 if (rc == IOCB_ERROR) {
6064 lpfc_nlp_put(ndlp);
6065 lpfc_els_free_iocb(phba, elsiocb);
6066 }
James Smart86478872015-05-21 13:55:21 -04006067
James Smart4430f7f2020-11-15 11:26:31 -08006068 goto free_rdp_context;
6069
James Smart86478872015-05-21 13:55:21 -04006070error:
6071 cmdsize = 2 * sizeof(uint32_t);
6072 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6073 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart86478872015-05-21 13:55:21 -04006074 if (!elsiocb)
6075 goto free_rdp_context;
6076
6077 icmd = &elsiocb->iocb;
6078 icmd->ulpContext = rdp_context->rx_id;
6079 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6081
6082 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6083 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6084 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6085
6086 phba->fc_stat.elsXmitLSRJT++;
6087 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart4430f7f2020-11-15 11:26:31 -08006088 elsiocb->context1 = lpfc_nlp_get(ndlp);
6089 if (!elsiocb->context1) {
James Smart86478872015-05-21 13:55:21 -04006090 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006091 goto free_rdp_context;
6092 }
6093
6094 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6095 if (rc == IOCB_ERROR) {
6096 lpfc_nlp_put(ndlp);
6097 lpfc_els_free_iocb(phba, elsiocb);
6098 }
6099
James Smart86478872015-05-21 13:55:21 -04006100free_rdp_context:
James Smart4430f7f2020-11-15 11:26:31 -08006101 /* This reference put is for the original unsolicited RDP. If the
6102 * iocb prep failed, there is no reference to remove.
6103 */
6104 lpfc_nlp_put(ndlp);
James Smart86478872015-05-21 13:55:21 -04006105 kfree(rdp_context);
6106}
6107
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006108static int
James Smart86478872015-05-21 13:55:21 -04006109lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6110{
6111 LPFC_MBOXQ_t *mbox = NULL;
6112 int rc;
6113
6114 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6115 if (!mbox) {
6116 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6117 "7105 failed to allocate mailbox memory");
6118 return 1;
6119 }
6120
6121 if (lpfc_sli4_dump_page_a0(phba, mbox))
6122 goto prep_mbox_fail;
6123 mbox->vport = rdp_context->ndlp->vport;
6124 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
James Smart3e1f0712018-11-29 16:09:29 -08006125 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04006126 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6127 if (rc == MBX_NOT_FINISHED)
6128 goto issue_mbox_fail;
6129
6130 return 0;
6131
6132prep_mbox_fail:
6133issue_mbox_fail:
6134 mempool_free(mbox, phba->mbox_mem_pool);
6135 return 1;
6136}
6137
6138/*
6139 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6140 * @vport: pointer to a host virtual N_Port data structure.
6141 * @cmdiocb: pointer to lpfc command iocb data structure.
6142 * @ndlp: pointer to a node-list data structure.
6143 *
6144 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6145 * IOCB. First, the payload of the unsolicited RDP is checked.
6146 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6147 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6148 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6149 * gather all data and send RDP response.
6150 *
6151 * Return code
6152 * 0 - Sent the acc response
6153 * 1 - Sent the reject response.
6154 */
6155static int
6156lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6157 struct lpfc_nodelist *ndlp)
6158{
6159 struct lpfc_hba *phba = vport->phba;
6160 struct lpfc_dmabuf *pcmd;
6161 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6162 struct fc_rdp_req_frame *rdp_req;
6163 struct lpfc_rdp_context *rdp_context;
6164 IOCB_t *cmd = NULL;
6165 struct ls_rjt stat;
6166
6167 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smart719162b2018-12-10 19:37:01 -08006168 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smarta0f2d3e2017-02-12 13:52:31 -08006169 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04006170 rjt_err = LSRJT_UNABLE_TPC;
6171 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6172 goto error;
6173 }
6174
6175 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6176 rjt_err = LSRJT_UNABLE_TPC;
6177 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6178 goto error;
6179 }
6180
6181 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6182 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6183
James Smart86478872015-05-21 13:55:21 -04006184 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6185 "2422 ELS RDP Request "
6186 "dec len %d tag x%x port_id %d len %d\n",
6187 be32_to_cpu(rdp_req->rdp_des_length),
6188 be32_to_cpu(rdp_req->nport_id_desc.tag),
6189 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6190 be32_to_cpu(rdp_req->nport_id_desc.length));
6191
6192 if (sizeof(struct fc_rdp_nport_desc) !=
6193 be32_to_cpu(rdp_req->rdp_des_length))
6194 goto rjt_logerr;
6195 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6196 goto rjt_logerr;
6197 if (RDP_NPORT_ID_SIZE !=
6198 be32_to_cpu(rdp_req->nport_id_desc.length))
6199 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05006200 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04006201 if (!rdp_context) {
6202 rjt_err = LSRJT_UNABLE_TPC;
6203 goto error;
6204 }
6205
James Smart86478872015-05-21 13:55:21 -04006206 cmd = &cmdiocb->iocb;
6207 rdp_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006208 if (!rdp_context->ndlp) {
6209 kfree(rdp_context);
6210 rjt_err = LSRJT_UNABLE_TPC;
6211 goto error;
6212 }
James Smart86478872015-05-21 13:55:21 -04006213 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6214 rdp_context->rx_id = cmd->ulpContext;
6215 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6216 if (lpfc_get_rdp_info(phba, rdp_context)) {
6217 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6218 "2423 Unable to send mailbox");
6219 kfree(rdp_context);
6220 rjt_err = LSRJT_UNABLE_TPC;
6221 lpfc_nlp_put(ndlp);
6222 goto error;
6223 }
6224
6225 return 0;
6226
6227rjt_logerr:
6228 rjt_err = LSRJT_LOGICAL_ERR;
6229
6230error:
6231 memset(&stat, 0, sizeof(stat));
6232 stat.un.b.lsRjtRsnCode = rjt_err;
6233 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6234 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6235 return 1;
6236}
6237
6238
James Smart8b017a32015-05-21 13:55:18 -04006239static void
6240lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6241{
6242 MAILBOX_t *mb;
6243 IOCB_t *icmd;
6244 uint8_t *pcmd;
6245 struct lpfc_iocbq *elsiocb;
6246 struct lpfc_nodelist *ndlp;
6247 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04006248 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04006249 struct lpfc_lcb_context *lcb_context;
6250 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04006251 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04006252 int rc;
6253
6254 mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006255 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
James Smart8b017a32015-05-21 13:55:18 -04006256 ndlp = lcb_context->ndlp;
James Smart3e1f0712018-11-29 16:09:29 -08006257 pmb->ctx_ndlp = NULL;
6258 pmb->ctx_buf = NULL;
James Smart8b017a32015-05-21 13:55:18 -04006259
James Smart481ad962015-05-22 10:42:35 -04006260 shdr = (union lpfc_sli4_cfg_shdr *)
6261 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6262 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6263 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6264
6265 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6266 "0194 SET_BEACON_CONFIG mailbox "
6267 "completed with status x%x add_status x%x,"
6268 " mbx status x%x\n",
6269 shdr_status, shdr_add_status, mb->mbxStatus);
6270
James Smart66e9e6b2018-06-26 08:24:27 -07006271 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6272 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6273 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
James Smart8b017a32015-05-21 13:55:18 -04006274 mempool_free(pmb, phba->mbox_mem_pool);
6275 goto error;
6276 }
6277
6278 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04006279 cmdsize = sizeof(struct fc_lcb_res_frame);
6280 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6281 lpfc_max_els_tries, ndlp,
6282 ndlp->nlp_DID, ELS_CMD_ACC);
6283
6284 /* Decrement the ndlp reference count from previous mbox command */
6285 lpfc_nlp_put(ndlp);
6286
6287 if (!elsiocb)
6288 goto free_lcb_context;
6289
6290 lcb_res = (struct fc_lcb_res_frame *)
6291 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6292
James Smart24bc3112018-07-31 17:23:23 -07006293 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
James Smart8b017a32015-05-21 13:55:18 -04006294 icmd = &elsiocb->iocb;
6295 icmd->ulpContext = lcb_context->rx_id;
6296 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6297
6298 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6299 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6300 lcb_res->lcb_sub_command = lcb_context->sub_command;
6301 lcb_res->lcb_type = lcb_context->type;
James Smart24bc3112018-07-31 17:23:23 -07006302 lcb_res->capability = lcb_context->capability;
James Smart8b017a32015-05-21 13:55:18 -04006303 lcb_res->lcb_frequency = lcb_context->frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006304 lcb_res->lcb_duration = lcb_context->duration;
James Smart8b017a32015-05-21 13:55:18 -04006305 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6306 phba->fc_stat.elsXmitACC++;
James Smart8b017a32015-05-21 13:55:18 -04006307
James Smart4430f7f2020-11-15 11:26:31 -08006308 elsiocb->context1 = lpfc_nlp_get(ndlp);
6309 if (!elsiocb->context1)
6310 goto node_err;
6311
6312 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6313 if (!rc)
6314 goto out;
6315
6316 lpfc_nlp_put(ndlp);
6317 node_err:
6318 lpfc_els_free_iocb(phba, elsiocb);
6319 out:
James Smart8b017a32015-05-21 13:55:18 -04006320 kfree(lcb_context);
6321 return;
6322
6323error:
6324 cmdsize = sizeof(struct fc_lcb_res_frame);
6325 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6326 lpfc_max_els_tries, ndlp,
6327 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6328 lpfc_nlp_put(ndlp);
6329 if (!elsiocb)
6330 goto free_lcb_context;
6331
6332 icmd = &elsiocb->iocb;
6333 icmd->ulpContext = lcb_context->rx_id;
6334 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6335 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6336
6337 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6338 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6339 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6340
James Smartb114d902018-10-23 13:41:07 -07006341 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6342 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6343
James Smart8b017a32015-05-21 13:55:18 -04006344 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6345 phba->fc_stat.elsXmitLSRJT++;
James Smart4430f7f2020-11-15 11:26:31 -08006346 elsiocb->context1 = lpfc_nlp_get(ndlp);
6347 if (!elsiocb->context1) {
James Smart8b017a32015-05-21 13:55:18 -04006348 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08006349 goto free_lcb_context;
6350 }
6351
6352 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6353 if (rc == IOCB_ERROR) {
6354 lpfc_nlp_put(ndlp);
6355 lpfc_els_free_iocb(phba, elsiocb);
6356 }
James Smart8b017a32015-05-21 13:55:18 -04006357free_lcb_context:
6358 kfree(lcb_context);
6359}
6360
6361static int
6362lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6363 struct lpfc_lcb_context *lcb_context,
6364 uint32_t beacon_state)
6365{
6366 struct lpfc_hba *phba = vport->phba;
James Smart66e9e6b2018-06-26 08:24:27 -07006367 union lpfc_sli4_cfg_shdr *cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006368 LPFC_MBOXQ_t *mbox = NULL;
6369 uint32_t len;
6370 int rc;
6371
6372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6373 if (!mbox)
6374 return 1;
6375
James Smart66e9e6b2018-06-26 08:24:27 -07006376 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006377 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6378 sizeof(struct lpfc_sli4_cfg_mhdr);
6379 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6380 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6381 LPFC_SLI4_MBX_EMBED);
James Smart3e1f0712018-11-29 16:09:29 -08006382 mbox->ctx_ndlp = (void *)lcb_context;
James Smart8b017a32015-05-21 13:55:18 -04006383 mbox->vport = phba->pport;
6384 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6385 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6386 phba->sli4_hba.physical_port);
6387 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6388 beacon_state);
James Smart66e9e6b2018-06-26 08:24:27 -07006389 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6390
6391 /*
6392 * Check bv1s bit before issuing the mailbox
6393 * if bv1s == 1, LCB V1 supported
6394 * else, LCB V0 supported
6395 */
6396
6397 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6398 /* COMMON_SET_BEACON_CONFIG_V1 */
6399 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6400 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6401 bf_set(lpfc_mbx_set_beacon_port_type,
6402 &mbox->u.mqe.un.beacon_config, 0);
6403 bf_set(lpfc_mbx_set_beacon_duration_v1,
6404 &mbox->u.mqe.un.beacon_config,
6405 be16_to_cpu(lcb_context->duration));
6406 } else {
6407 /* COMMON_SET_BEACON_CONFIG_V0 */
6408 if (be16_to_cpu(lcb_context->duration) != 0) {
6409 mempool_free(mbox, phba->mbox_mem_pool);
6410 return 1;
6411 }
6412 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6413 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6414 bf_set(lpfc_mbx_set_beacon_state,
6415 &mbox->u.mqe.un.beacon_config, beacon_state);
6416 bf_set(lpfc_mbx_set_beacon_port_type,
6417 &mbox->u.mqe.un.beacon_config, 1);
6418 bf_set(lpfc_mbx_set_beacon_duration,
6419 &mbox->u.mqe.un.beacon_config,
6420 be16_to_cpu(lcb_context->duration));
6421 }
6422
James Smart8b017a32015-05-21 13:55:18 -04006423 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6424 if (rc == MBX_NOT_FINISHED) {
6425 mempool_free(mbox, phba->mbox_mem_pool);
6426 return 1;
6427 }
6428
6429 return 0;
6430}
6431
6432
6433/**
6434 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6435 * @vport: pointer to a host virtual N_Port data structure.
6436 * @cmdiocb: pointer to lpfc command iocb data structure.
6437 * @ndlp: pointer to a node-list data structure.
6438 *
6439 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6440 * First, the payload of the unsolicited LCB is checked.
6441 * Then based on Subcommand beacon will either turn on or off.
6442 *
6443 * Return code
6444 * 0 - Sent the acc response
6445 * 1 - Sent the reject response.
6446 **/
6447static int
6448lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6449 struct lpfc_nodelist *ndlp)
6450{
6451 struct lpfc_hba *phba = vport->phba;
6452 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04006453 uint8_t *lp;
6454 struct fc_lcb_request_frame *beacon;
6455 struct lpfc_lcb_context *lcb_context;
James Smart4430f7f2020-11-15 11:26:31 -08006456 u8 state, rjt_err = 0;
James Smart8b017a32015-05-21 13:55:18 -04006457 struct ls_rjt stat;
6458
James Smart8b017a32015-05-21 13:55:18 -04006459 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6460 lp = (uint8_t *)pcmd->virt;
6461 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6462
6463 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6464 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6465 "type x%x frequency %x duration x%x\n",
6466 lp[0], lp[1], lp[2],
6467 beacon->lcb_command,
6468 beacon->lcb_sub_command,
6469 beacon->lcb_type,
6470 beacon->lcb_frequency,
6471 be16_to_cpu(beacon->lcb_duration));
6472
James Smartd6564e52017-06-15 22:56:50 -07006473 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6474 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04006475 rjt_err = LSRJT_CMD_UNSUPPORTED;
6476 goto rjt;
6477 }
James Smart66e9e6b2018-06-26 08:24:27 -07006478
6479 if (phba->sli_rev < LPFC_SLI_REV4 ||
6480 phba->hba_flag & HBA_FCOE_MODE ||
6481 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6482 LPFC_SLI_INTF_IF_TYPE_2)) {
James Smart8b017a32015-05-21 13:55:18 -04006483 rjt_err = LSRJT_CMD_UNSUPPORTED;
6484 goto rjt;
6485 }
6486
Sudip Mukherjeee7950422015-09-23 19:02:32 +05306487 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6488 if (!lcb_context) {
6489 rjt_err = LSRJT_UNABLE_TPC;
6490 goto rjt;
6491 }
6492
James Smart8b017a32015-05-21 13:55:18 -04006493 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6494 lcb_context->sub_command = beacon->lcb_sub_command;
James Smart66e9e6b2018-06-26 08:24:27 -07006495 lcb_context->capability = 0;
James Smart8b017a32015-05-21 13:55:18 -04006496 lcb_context->type = beacon->lcb_type;
6497 lcb_context->frequency = beacon->lcb_frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006498 lcb_context->duration = beacon->lcb_duration;
James Smart8b017a32015-05-21 13:55:18 -04006499 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6500 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6501 lcb_context->ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08006502 if (!lcb_context->ndlp) {
6503 rjt_err = LSRJT_UNABLE_TPC;
6504 goto rjt;
6505 }
6506
James Smart8b017a32015-05-21 13:55:18 -04006507 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006508 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6509 "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05306510 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04006511 lpfc_nlp_put(ndlp);
6512 rjt_err = LSRJT_UNABLE_TPC;
6513 goto rjt;
6514 }
6515 return 0;
6516rjt:
6517 memset(&stat, 0, sizeof(stat));
6518 stat.un.b.lsRjtRsnCode = rjt_err;
6519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6520 return 1;
6521}
6522
6523
James Smarte59058c2008-08-24 21:49:00 -04006524/**
James Smart3621a712009-04-06 18:47:14 -04006525 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04006526 * @vport: pointer to a host virtual N_Port data structure.
6527 *
6528 * This routine cleans up any Registration State Change Notification
6529 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6530 * @vport together with the host_lock is used to prevent multiple thread
6531 * trying to access the RSCN array on a same @vport at the same time.
6532 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006533void
James Smart2e0fef82007-06-17 19:56:36 -05006534lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006535{
James Smart2e0fef82007-06-17 19:56:36 -05006536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006538 int i;
6539
James Smart7f5f3d02008-02-08 18:50:14 -05006540 spin_lock_irq(shost->host_lock);
6541 if (vport->fc_rscn_flush) {
6542 /* Another thread is walking fc_rscn_id_list on this vport */
6543 spin_unlock_irq(shost->host_lock);
6544 return;
6545 }
6546 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6547 vport->fc_rscn_flush = 1;
6548 spin_unlock_irq(shost->host_lock);
6549
James Smart2e0fef82007-06-17 19:56:36 -05006550 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006551 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05006552 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05006553 }
James Smart2e0fef82007-06-17 19:56:36 -05006554 spin_lock_irq(shost->host_lock);
6555 vport->fc_rscn_id_cnt = 0;
6556 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6557 spin_unlock_irq(shost->host_lock);
6558 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006559 /* Indicate we are done walking this fc_rscn_id_list */
6560 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006561}
6562
James Smarte59058c2008-08-24 21:49:00 -04006563/**
James Smart3621a712009-04-06 18:47:14 -04006564 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04006565 * @vport: pointer to a host virtual N_Port data structure.
6566 * @did: remote destination port identifier.
6567 *
6568 * This routine checks whether there is any pending Registration State
6569 * Configuration Notification (RSCN) to a @did on @vport.
6570 *
6571 * Return code
6572 * None zero - The @did matched with a pending rscn
6573 * 0 - not able to match @did with a pending rscn
6574 **/
dea31012005-04-17 16:05:31 -05006575int
James Smart2e0fef82007-06-17 19:56:36 -05006576lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006577{
6578 D_ID ns_did;
6579 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05006580 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05006581 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05006582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006583
6584 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05006585
6586 /* Never match fabric nodes for RSCNs */
6587 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05006588 return 0;
dea31012005-04-17 16:05:31 -05006589
6590 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05006591 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006592 return did;
dea31012005-04-17 16:05:31 -05006593
James Smart7f5f3d02008-02-08 18:50:14 -05006594 spin_lock_irq(shost->host_lock);
6595 if (vport->fc_rscn_flush) {
6596 /* Another thread is walking fc_rscn_id_list on this vport */
6597 spin_unlock_irq(shost->host_lock);
6598 return 0;
6599 }
6600 /* Indicate we are walking fc_rscn_id_list on this vport */
6601 vport->fc_rscn_flush = 1;
6602 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05006603 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006604 lp = vport->fc_rscn_id_list[i]->virt;
6605 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6606 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006607 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05006608 rscn_did.un.word = be32_to_cpu(*lp++);
6609 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05006610 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6611 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04006612 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6613 && (ns_did.un.b.area == rscn_did.un.b.area)
6614 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05006615 goto return_did_out;
dea31012005-04-17 16:05:31 -05006616 break;
James Smarteaf15d52008-12-04 22:39:29 -05006617 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05006618 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6619 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05006620 goto return_did_out;
dea31012005-04-17 16:05:31 -05006621 break;
James Smarteaf15d52008-12-04 22:39:29 -05006622 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05006623 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05006624 goto return_did_out;
dea31012005-04-17 16:05:31 -05006625 break;
James Smarteaf15d52008-12-04 22:39:29 -05006626 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05006627 goto return_did_out;
dea31012005-04-17 16:05:31 -05006628 }
6629 }
James Smart92d7f7b2007-06-17 19:56:38 -05006630 }
James Smart7f5f3d02008-02-08 18:50:14 -05006631 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6632 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006633 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05006634return_did_out:
6635 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6636 vport->fc_rscn_flush = 0;
6637 return did;
dea31012005-04-17 16:05:31 -05006638}
6639
James Smarte59058c2008-08-24 21:49:00 -04006640/**
James Smart3621a712009-04-06 18:47:14 -04006641 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04006642 * @vport: pointer to a host virtual N_Port data structure.
6643 *
6644 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6645 * state machine for a @vport's nodes that are with pending RSCN (Registration
6646 * State Change Notification).
6647 *
6648 * Return code
6649 * 0 - Successful (currently alway return 0)
6650 **/
dea31012005-04-17 16:05:31 -05006651static int
James Smart2e0fef82007-06-17 19:56:36 -05006652lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006653{
James Smart685f0bf2007-04-25 09:53:08 -04006654 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05006655
James Smart0d2b6b82008-06-14 22:52:47 -04006656 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05006657 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08006658 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
James Smart0d2b6b82008-06-14 22:52:47 -04006659 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05006660 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006661
6662 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08006663 if (vport->phba->nvmet_support)
6664 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006665
James Smartdea16bd2018-11-29 16:09:30 -08006666 /* If we are in the process of doing discovery on this
6667 * NPort, let it continue on its own.
6668 */
6669 switch (ndlp->nlp_state) {
6670 case NLP_STE_PLOGI_ISSUE:
6671 case NLP_STE_ADISC_ISSUE:
6672 case NLP_STE_REG_LOGIN_ISSUE:
6673 case NLP_STE_PRLI_ISSUE:
6674 case NLP_STE_LOGO_ISSUE:
6675 continue;
6676 }
6677
James Smarta6d10f22019-08-14 16:56:50 -07006678 /* Check to see if we need to NVME rescan this target
6679 * remoteport.
6680 */
6681 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6682 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006683 lpfc_nvme_rescan_port(vport, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08006684
James Smart2e0fef82007-06-17 19:56:36 -05006685 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04006686 NLP_EVT_DEVICE_RECOVERY);
6687 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05006688 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006689 return 0;
dea31012005-04-17 16:05:31 -05006690}
6691
James Smarte59058c2008-08-24 21:49:00 -04006692/**
James Smart3621a712009-04-06 18:47:14 -04006693 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05006694 * @vport: pointer to a host virtual N_Port data structure.
6695 * @cmdiocb: pointer to lpfc command iocb data structure.
6696 *
6697 * lpfc_send_rscn_event sends an RSCN netlink event to management
6698 * applications.
6699 */
6700static void
6701lpfc_send_rscn_event(struct lpfc_vport *vport,
6702 struct lpfc_iocbq *cmdiocb)
6703{
6704 struct lpfc_dmabuf *pcmd;
6705 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6706 uint32_t *payload_ptr;
6707 uint32_t payload_len;
6708 struct lpfc_rscn_event_header *rscn_event_data;
6709
6710 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6711 payload_ptr = (uint32_t *) pcmd->virt;
6712 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6713
6714 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6715 payload_len, GFP_KERNEL);
6716 if (!rscn_event_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006717 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05006718 "0147 Failed to allocate memory for RSCN event\n");
6719 return;
6720 }
6721 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6722 rscn_event_data->payload_length = payload_len;
6723 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6724 payload_len);
6725
6726 fc_host_post_vendor_event(shost,
6727 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04006728 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05006729 (char *)rscn_event_data,
6730 LPFC_NL_VENDOR_ID);
6731
6732 kfree(rscn_event_data);
6733}
6734
6735/**
James Smart3621a712009-04-06 18:47:14 -04006736 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04006737 * @vport: pointer to a host virtual N_Port data structure.
6738 * @cmdiocb: pointer to lpfc command iocb data structure.
6739 * @ndlp: pointer to a node-list data structure.
6740 *
6741 * This routine processes an unsolicited RSCN (Registration State Change
6742 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6743 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6744 * discover state machine is about to begin discovery, it just accepts the
6745 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6746 * contains N_Port IDs for other vports on this HBA, it just accepts the
6747 * RSCN and ignore processing it. If the state machine is in the recovery
6748 * state, the fc_rscn_id_list of this @vport is walked and the
6749 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6750 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6751 * routine is invoked to handle the RSCN event.
6752 *
6753 * Return code
6754 * 0 - Just sent the acc response
6755 * 1 - Sent the acc response and waited for name server completion
6756 **/
dea31012005-04-17 16:05:31 -05006757static int
James Smart2e0fef82007-06-17 19:56:36 -05006758lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006759 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006760{
James Smart2e0fef82007-06-17 19:56:36 -05006761 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6762 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006763 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05006764 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05006765 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006766 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05006767 int rscn_id = 0, hba_id = 0;
James Smart2332e6e2019-11-04 16:57:01 -08006768 int i, tmo;
dea31012005-04-17 16:05:31 -05006769
dea31012005-04-17 16:05:31 -05006770 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6771 lp = (uint32_t *) pcmd->virt;
6772
James Smart92d7f7b2007-06-17 19:56:38 -05006773 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6774 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006775 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04006776 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6777 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05006778 vport->fc_flag, payload_len, *lp,
6779 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05006780
6781 /* Send an RSCN event to the management application */
6782 lpfc_send_rscn_event(vport, cmdiocb);
6783
James Smartd2873e42006-08-18 17:46:43 -04006784 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05006785 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04006786 FCH_EVT_RSCN, lp[i]);
6787
James Smartf60cb932019-05-14 14:58:05 -07006788 /* Check if RSCN is coming from a direct-connected remote NPort */
6789 if (vport->fc_flag & FC_PT2PT) {
6790 /* If so, just ACC it, no other action needed for now */
6791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6792 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6793 *lp, vport->fc_flag, payload_len);
6794 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart6f2589f2019-05-14 14:58:07 -07006795
James Smarta6d10f22019-08-14 16:56:50 -07006796 /* Check to see if we need to NVME rescan this target
6797 * remoteport.
6798 */
6799 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6800 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006801 lpfc_nvme_rescan_port(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07006802 return 0;
6803 }
6804
dea31012005-04-17 16:05:31 -05006805 /* If we are about to begin discovery, just ACC the RSCN.
6806 * Discovery processing will satisfy it.
6807 */
James Smart2e0fef82007-06-17 19:56:36 -05006808 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05006809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6810 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6811 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6812
James Smart51ef4c22007-08-02 11:10:31 -04006813 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006814 return 0;
dea31012005-04-17 16:05:31 -05006815 }
6816
James Smart92d7f7b2007-06-17 19:56:38 -05006817 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6818 * just ACC and ignore it.
6819 */
6820 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04006821 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05006822 i = payload_len;
6823 datap = lp;
6824 while (i > 0) {
6825 nportid = *datap++;
6826 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6827 i -= sizeof(uint32_t);
6828 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04006829 if (lpfc_find_vport_by_did(phba, nportid))
6830 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05006831 }
6832 if (rscn_id == hba_id) {
6833 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006834 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006835 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006836 "Data: x%x x%x x%x x%x\n",
6837 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006838 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6840 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6841 ndlp->nlp_DID, vport->port_state,
6842 ndlp->nlp_flag);
6843
James Smart92d7f7b2007-06-17 19:56:38 -05006844 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006845 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006846 return 0;
6847 }
6848 }
6849
James Smart7f5f3d02008-02-08 18:50:14 -05006850 spin_lock_irq(shost->host_lock);
6851 if (vport->fc_rscn_flush) {
6852 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006853 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006854 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006855 /* Send back ACC */
6856 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006857 return 0;
6858 }
6859 /* Indicate we are walking fc_rscn_id_list on this vport */
6860 vport->fc_rscn_flush = 1;
6861 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006862 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006863 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006864 /* If we are already processing an RSCN, save the received
6865 * RSCN payload buffer, cmdiocb->context2 to process later.
6866 */
James Smart2e0fef82007-06-17 19:56:36 -05006867 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6869 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6870 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6871
James Smart09372822008-01-11 01:52:54 -05006872 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006873 vport->fc_flag |= FC_RSCN_DEFERRED;
James Smart2332e6e2019-11-04 16:57:01 -08006874
6875 /* Restart disctmo if its already running */
6876 if (vport->fc_flag & FC_DISC_TMO) {
6877 tmo = ((phba->fc_ratov * 3) + 3);
6878 mod_timer(&vport->fc_disctmo,
6879 jiffies + msecs_to_jiffies(1000 * tmo));
6880 }
James Smart92d7f7b2007-06-17 19:56:38 -05006881 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006882 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006883 vport->fc_flag |= FC_RSCN_MODE;
6884 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006885 if (rscn_cnt) {
6886 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6887 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6888 }
6889 if ((rscn_cnt) &&
6890 (payload_len + length <= LPFC_BPL_SIZE)) {
6891 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006892 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006893 memcpy(((uint8_t *)cmd) + length, lp,
6894 payload_len);
6895 } else {
6896 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6897 vport->fc_rscn_id_cnt++;
6898 /* If we zero, cmdiocb->context2, the calling
6899 * routine will not try to free it.
6900 */
6901 cmdiocb->context2 = NULL;
6902 }
dea31012005-04-17 16:05:31 -05006903 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006904 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6905 "0235 Deferred RSCN "
6906 "Data: x%x x%x x%x\n",
6907 vport->fc_rscn_id_cnt, vport->fc_flag,
6908 vport->port_state);
dea31012005-04-17 16:05:31 -05006909 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006910 vport->fc_flag |= FC_RSCN_DISCOVERY;
6911 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006912 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006913 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6914 "0234 ReDiscovery RSCN "
6915 "Data: x%x x%x x%x\n",
6916 vport->fc_rscn_id_cnt, vport->fc_flag,
6917 vport->port_state);
dea31012005-04-17 16:05:31 -05006918 }
James Smart7f5f3d02008-02-08 18:50:14 -05006919 /* Indicate we are done walking fc_rscn_id_list on this vport */
6920 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006921 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006922 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006923 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006924 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006925 return 0;
dea31012005-04-17 16:05:31 -05006926 }
James Smart858c9f62007-06-17 19:56:39 -05006927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6928 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6929 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6930
James Smart2e0fef82007-06-17 19:56:36 -05006931 spin_lock_irq(shost->host_lock);
6932 vport->fc_flag |= FC_RSCN_MODE;
6933 spin_unlock_irq(shost->host_lock);
6934 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006935 /* Indicate we are done walking fc_rscn_id_list on this vport */
6936 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006937 /*
6938 * If we zero, cmdiocb->context2, the calling routine will
6939 * not try to free it.
6940 */
6941 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006942 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006943 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006944 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006945 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006946 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006947 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006948}
6949
James Smarte59058c2008-08-24 21:49:00 -04006950/**
James Smart3621a712009-04-06 18:47:14 -04006951 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006952 * @vport: pointer to a host virtual N_Port data structure.
6953 *
6954 * This routine handles the Registration State Configuration Notification
6955 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6956 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6957 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6958 * NameServer shall be issued. If CT command to the NameServer fails to be
6959 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6960 * RSCN activities with the @vport.
6961 *
6962 * Return code
6963 * 0 - Cleaned up rscn on the @vport
6964 * 1 - Wait for plogi to name server before proceed
6965 **/
dea31012005-04-17 16:05:31 -05006966int
James Smart2e0fef82007-06-17 19:56:36 -05006967lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006968{
6969 struct lpfc_nodelist *ndlp;
James Smart7ea92eb2018-10-23 13:41:10 -07006970 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006971
James Smart92d7f7b2007-06-17 19:56:38 -05006972 /* Ignore RSCN if the port is being torn down. */
6973 if (vport->load_flag & FC_UNLOADING) {
6974 lpfc_els_flush_rscn(vport);
6975 return 0;
6976 }
6977
dea31012005-04-17 16:05:31 -05006978 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006979 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006980
6981 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006982 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07006983 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04006984 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
James Smartb4b34172019-10-18 14:18:31 -07006985 vport->port_state, vport->num_disc_nodes,
6986 vport->gidft_inp);
dea31012005-04-17 16:05:31 -05006987
6988 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006989 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006990 vport->num_disc_nodes = 0;
6991
James Smart2e0fef82007-06-17 19:56:36 -05006992 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08006993 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006994 /* Good ndlp, issue CT Request to NameServer. Need to
6995 * know how many gidfts were issued. If none, then just
6996 * flush the RSCN. Otherwise, the outstanding requests
6997 * need to complete.
6998 */
James Smart7ea92eb2018-10-23 13:41:10 -07006999 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7000 if (lpfc_issue_gidft(vport) > 0)
7001 return 1;
7002 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7003 if (lpfc_issue_gidpt(vport) > 0)
7004 return 1;
7005 } else {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007006 return 1;
James Smart7ea92eb2018-10-23 13:41:10 -07007007 }
dea31012005-04-17 16:05:31 -05007008 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07007009 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05007010 if (ndlp) {
James Smarte47c9092008-02-08 18:49:26 -05007011 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart307e3382020-11-15 11:26:30 -08007012 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007013 } else {
James Smart9d3d3402017-04-21 16:05:00 -07007014 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007015 if (!ndlp) {
7016 lpfc_els_flush_rscn(vport);
7017 return 0;
7018 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007019 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007020 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05007021 }
James Smarte47c9092008-02-08 18:49:26 -05007022 ndlp->nlp_type |= NLP_FABRIC;
7023 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7024 /* Wait for NameServer login cmpl before we can
7025 * continue
7026 */
7027 return 1;
dea31012005-04-17 16:05:31 -05007028 }
7029
James Smart2e0fef82007-06-17 19:56:36 -05007030 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007031 return 0;
dea31012005-04-17 16:05:31 -05007032}
7033
James Smarte59058c2008-08-24 21:49:00 -04007034/**
James Smart3621a712009-04-06 18:47:14 -04007035 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04007036 * @vport: pointer to a host virtual N_Port data structure.
7037 * @cmdiocb: pointer to lpfc command iocb data structure.
7038 * @ndlp: pointer to a node-list data structure.
7039 *
7040 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7041 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7042 * point topology. As an unsolicited FLOGI should not be received in a loop
7043 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7044 * lpfc_check_sparm() routine is invoked to check the parameters in the
7045 * unsolicited FLOGI. If parameters validation failed, the routine
7046 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7047 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7048 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7049 * will initiate PLOGI. The higher lexicographical value party shall has
7050 * higher priority (as the winning port) and will initiate PLOGI and
7051 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7052 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7053 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7054 *
7055 * Return code
7056 * 0 - Successfully processed the unsolicited flogi
7057 * 1 - Failed to process the unsolicited flogi
7058 **/
dea31012005-04-17 16:05:31 -05007059static int
James Smart2e0fef82007-06-17 19:56:36 -05007060lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04007061 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007062{
James Smart2e0fef82007-06-17 19:56:36 -05007063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7064 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007065 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7066 uint32_t *lp = (uint32_t *) pcmd->virt;
7067 IOCB_t *icmd = &cmdiocb->iocb;
7068 struct serv_parm *sp;
7069 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05007070 uint32_t cmd, did;
7071 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04007072 uint32_t fc_flag = 0;
7073 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05007074
7075 cmd = *lp++;
7076 sp = (struct serv_parm *) lp;
7077
7078 /* FLOGI received */
7079
James Smart2e0fef82007-06-17 19:56:36 -05007080 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05007081
James Smart76a95d72010-11-20 23:11:48 -05007082 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05007083 /* We should never receive a FLOGI in loop mode, ignore it */
7084 did = icmd->un.elsreq64.remoteID;
7085
7086 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7087 Loop Mode */
Dick Kennedy372c1872020-06-30 14:50:00 -07007088 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04007089 "0113 An FLOGI ELS command x%x was "
7090 "received from DID x%x in Loop Mode\n",
7091 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007092 return 1;
dea31012005-04-17 16:05:31 -05007093 }
7094
James Smartd6de08c2015-12-16 18:11:53 -05007095 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05007096
James Smartd6de08c2015-12-16 18:11:53 -05007097 /*
7098 * If our portname is greater than the remote portname,
7099 * then we initiate Nport login.
7100 */
7101
7102 rc = memcmp(&vport->fc_portname, &sp->portName,
7103 sizeof(struct lpfc_name));
7104
7105 if (!rc) {
7106 if (phba->sli_rev < LPFC_SLI_REV4) {
7107 mbox = mempool_alloc(phba->mbox_mem_pool,
7108 GFP_KERNEL);
7109 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007110 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05007111 lpfc_linkdown(phba);
7112 lpfc_init_link(phba, mbox,
7113 phba->cfg_topology,
7114 phba->cfg_link_speed);
7115 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7116 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7117 mbox->vport = vport;
7118 rc = lpfc_sli_issue_mbox(phba, mbox,
7119 MBX_NOWAIT);
7120 lpfc_set_loopback_flag(phba);
7121 if (rc == MBX_NOT_FINISHED)
7122 mempool_free(mbox, phba->mbox_mem_pool);
7123 return 1;
7124 }
James Smart939723a2012-05-09 21:19:03 -04007125
James Smartd6de08c2015-12-16 18:11:53 -05007126 /* abort the flogi coming back to ourselves
7127 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04007128 */
James Smartd6de08c2015-12-16 18:11:53 -05007129 lpfc_els_abort_flogi(phba);
7130 return 0;
7131
7132 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05007133 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05007134 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05007135 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04007136
James Smartd6de08c2015-12-16 18:11:53 -05007137 /* If we have the high WWPN we can assign our own
7138 * myDID; otherwise, we have to WAIT for a PLOGI
7139 * from the remote NPort to find out what it
7140 * will be.
James Smart939723a2012-05-09 21:19:03 -04007141 */
James Smartd6de08c2015-12-16 18:11:53 -05007142 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05007143 } else {
James Smartd6de08c2015-12-16 18:11:53 -05007144 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05007145 }
7146
James Smartd6de08c2015-12-16 18:11:53 -05007147 /*
7148 * The vport state should go to LPFC_FLOGI only
7149 * AFTER we issue a FLOGI, not receive one.
7150 */
7151 spin_lock_irq(shost->host_lock);
7152 fc_flag = vport->fc_flag;
7153 port_state = vport->port_state;
7154 vport->fc_flag |= FC_PT2PT;
7155 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd496b9a2018-10-23 13:41:08 -07007156
7157 /* Acking an unsol FLOGI. Count 1 for link bounce
7158 * work-around.
7159 */
7160 vport->rcv_flogi_cnt++;
James Smartd6de08c2015-12-16 18:11:53 -05007161 spin_unlock_irq(shost->host_lock);
7162 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7163 "3311 Rcv Flogi PS x%x new PS x%x "
7164 "fc_flag x%x new fc_flag x%x\n",
7165 port_state, vport->port_state,
7166 fc_flag, vport->fc_flag);
7167
7168 /*
7169 * We temporarily set fc_myDID to make it look like we are
7170 * a Fabric. This is done just so we end up with the right
7171 * did / sid on the FLOGI ACC rsp.
7172 */
7173 did = vport->fc_myDID;
7174 vport->fc_myDID = Fabric_DID;
7175
7176 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04007177
James Smart0a9e9682018-11-29 16:09:36 -08007178 /* Defer ACC response until AFTER we issue a FLOGI */
7179 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7180 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7181 phba->defer_flogi_acc_ox_id =
7182 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7183
7184 vport->fc_myDID = did;
7185
7186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7187 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7188 " ox_id: x%x, hba_flag x%x\n",
7189 phba->defer_flogi_acc_rx_id,
7190 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7191
7192 phba->defer_flogi_acc_flag = true;
7193
7194 return 0;
7195 }
7196
dea31012005-04-17 16:05:31 -05007197 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05007198 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007199
James Smart939723a2012-05-09 21:19:03 -04007200 /* Now lets put fc_myDID back to what its supposed to be */
7201 vport->fc_myDID = did;
7202
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007203 return 0;
dea31012005-04-17 16:05:31 -05007204}
7205
James Smarte59058c2008-08-24 21:49:00 -04007206/**
James Smart3621a712009-04-06 18:47:14 -04007207 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04007208 * @vport: pointer to a host virtual N_Port data structure.
7209 * @cmdiocb: pointer to lpfc command iocb data structure.
7210 * @ndlp: pointer to a node-list data structure.
7211 *
7212 * This routine processes Request Node Identification Data (RNID) IOCB
7213 * received as an ELS unsolicited event. Only when the RNID specified format
7214 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7215 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7216 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7217 * rejected by invoking the lpfc_els_rsp_reject() routine.
7218 *
7219 * Return code
7220 * 0 - Successfully processed rnid iocb (currently always return 0)
7221 **/
dea31012005-04-17 16:05:31 -05007222static int
James Smart2e0fef82007-06-17 19:56:36 -05007223lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7224 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007225{
7226 struct lpfc_dmabuf *pcmd;
7227 uint32_t *lp;
dea31012005-04-17 16:05:31 -05007228 RNID *rn;
7229 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007230
dea31012005-04-17 16:05:31 -05007231 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7232 lp = (uint32_t *) pcmd->virt;
7233
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007234 lp++;
dea31012005-04-17 16:05:31 -05007235 rn = (RNID *) lp;
7236
7237 /* RNID received */
7238
7239 switch (rn->Format) {
7240 case 0:
7241 case RNID_TOPOLOGY_DISC:
7242 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05007243 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007244 break;
7245 default:
7246 /* Reject this request because format not supported */
7247 stat.un.b.lsRjtRsvd0 = 0;
7248 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7249 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7250 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007251 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7252 NULL);
dea31012005-04-17 16:05:31 -05007253 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007254 return 0;
dea31012005-04-17 16:05:31 -05007255}
7256
James Smarte59058c2008-08-24 21:49:00 -04007257/**
James Smart12265f62010-10-22 11:05:53 -04007258 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7259 * @vport: pointer to a host virtual N_Port data structure.
7260 * @cmdiocb: pointer to lpfc command iocb data structure.
7261 * @ndlp: pointer to a node-list data structure.
7262 *
7263 * Return code
7264 * 0 - Successfully processed echo iocb (currently always return 0)
7265 **/
7266static int
7267lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7268 struct lpfc_nodelist *ndlp)
7269{
7270 uint8_t *pcmd;
7271
7272 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7273
7274 /* skip over first word of echo command to find echo data */
7275 pcmd += sizeof(uint32_t);
7276
7277 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7278 return 0;
7279}
7280
7281/**
James Smart3621a712009-04-06 18:47:14 -04007282 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04007283 * @vport: pointer to a host virtual N_Port data structure.
7284 * @cmdiocb: pointer to lpfc command iocb data structure.
7285 * @ndlp: pointer to a node-list data structure.
7286 *
7287 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7288 * received as an ELS unsolicited event. Currently, this function just invokes
7289 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7290 *
7291 * Return code
7292 * 0 - Successfully processed lirr iocb (currently always return 0)
7293 **/
dea31012005-04-17 16:05:31 -05007294static int
James Smart2e0fef82007-06-17 19:56:36 -05007295lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7296 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007297{
7298 struct ls_rjt stat;
7299
7300 /* For now, unconditionally reject this command */
7301 stat.un.b.lsRjtRsvd0 = 0;
7302 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7303 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7304 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007306 return 0;
7307}
7308
James Smarte59058c2008-08-24 21:49:00 -04007309/**
James Smart5ffc2662009-11-18 15:39:44 -05007310 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7311 * @vport: pointer to a host virtual N_Port data structure.
7312 * @cmdiocb: pointer to lpfc command iocb data structure.
7313 * @ndlp: pointer to a node-list data structure.
7314 *
7315 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7316 * received as an ELS unsolicited event. A request to RRQ shall only
7317 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7318 * Nx_Port N_Port_ID of the target Exchange is the same as the
7319 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7320 * not accepted, an LS_RJT with reason code "Unable to perform
7321 * command request" and reason code explanation "Invalid Originator
7322 * S_ID" shall be returned. For now, we just unconditionally accept
7323 * RRQ from the target.
7324 **/
7325static void
7326lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7327 struct lpfc_nodelist *ndlp)
7328{
7329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05007330 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7331 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05007332}
7333
7334/**
James Smart12265f62010-10-22 11:05:53 -04007335 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7336 * @phba: pointer to lpfc hba data structure.
7337 * @pmb: pointer to the driver internal queue element for mailbox command.
7338 *
7339 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7340 * mailbox command. This callback function is to actually send the Accept
7341 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7342 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7343 * mailbox command, constructs the RPS response with the link statistics
7344 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7345 * response to the RPS.
7346 *
7347 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7348 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7349 * will be stored into the context1 field of the IOCB for the completion
7350 * callback function to the RPS Accept Response ELS IOCB command.
7351 *
7352 **/
7353static void
7354lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7355{
James Smart4430f7f2020-11-15 11:26:31 -08007356 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04007357 MAILBOX_t *mb;
7358 IOCB_t *icmd;
7359 struct RLS_RSP *rls_rsp;
7360 uint8_t *pcmd;
7361 struct lpfc_iocbq *elsiocb;
7362 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04007363 uint16_t oxid;
7364 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04007365 uint32_t cmdsize;
7366
7367 mb = &pmb->u.mb;
7368
James Smart3e1f0712018-11-29 16:09:29 -08007369 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7370 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7371 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7372 pmb->ctx_buf = NULL;
7373 pmb->ctx_ndlp = NULL;
James Smart12265f62010-10-22 11:05:53 -04007374
7375 if (mb->mbxStatus) {
7376 mempool_free(pmb, phba->mbox_mem_pool);
7377 return;
7378 }
7379
7380 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04007381 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7382 lpfc_max_els_tries, ndlp,
7383 ndlp->nlp_DID, ELS_CMD_ACC);
7384
7385 /* Decrement the ndlp reference count from previous mbox command */
7386 lpfc_nlp_put(ndlp);
7387
James Smart37db57e2012-05-09 21:17:16 -04007388 if (!elsiocb) {
7389 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007390 return;
James Smart37db57e2012-05-09 21:17:16 -04007391 }
James Smart12265f62010-10-22 11:05:53 -04007392
7393 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007394 icmd->ulpContext = rxid;
7395 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04007396
7397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7398 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7399 pcmd += sizeof(uint32_t); /* Skip past command */
7400 rls_rsp = (struct RLS_RSP *)pcmd;
7401
7402 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7403 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7404 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7405 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7406 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7407 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04007408 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007409 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7410 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7411 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7412 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7413 elsiocb->iotag, elsiocb->iocb.ulpContext,
7414 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7415 ndlp->nlp_rpi);
7416 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7417 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007418 elsiocb->context1 = lpfc_nlp_get(ndlp);
7419 if (!elsiocb->context1)
7420 goto node_err;
7421
7422 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7423 if (rc == IOCB_ERROR)
7424 goto io_err;
7425 return;
7426
7427 io_err:
7428 lpfc_nlp_put(ndlp);
7429 node_err:
7430 lpfc_els_free_iocb(phba, elsiocb);
James Smart12265f62010-10-22 11:05:53 -04007431}
7432
7433/**
James Smart12265f62010-10-22 11:05:53 -04007434 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7435 * @vport: pointer to a host virtual N_Port data structure.
7436 * @cmdiocb: pointer to lpfc command iocb data structure.
7437 * @ndlp: pointer to a node-list data structure.
7438 *
James Smart6cde2e3e2020-01-27 16:23:08 -08007439 * This routine processes Read Link Status (RLS) IOCB received as an
James Smart12265f62010-10-22 11:05:53 -04007440 * ELS unsolicited event. It first checks the remote port state. If the
7441 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7442 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7443 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7444 * for reading the HBA link statistics. It is for the callback function,
7445 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7446 * to actually sending out RPL Accept (ACC) response.
7447 *
7448 * Return codes
7449 * 0 - Successfully processed rls iocb (currently always return 0)
7450 **/
7451static int
7452lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7453 struct lpfc_nodelist *ndlp)
7454{
7455 struct lpfc_hba *phba = vport->phba;
7456 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04007457 struct ls_rjt stat;
7458
7459 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7460 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007461 /* reject the unsolicited RLS request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007462 goto reject_out;
7463
James Smart12265f62010-10-22 11:05:53 -04007464 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7465 if (mbox) {
7466 lpfc_read_lnk_stat(phba, mbox);
James Smart3e1f0712018-11-29 16:09:29 -08007467 mbox->ctx_buf = (void *)((unsigned long)
James Smart7851fe22011-07-22 18:36:52 -04007468 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7469 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart3e1f0712018-11-29 16:09:29 -08007470 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007471 if (!mbox->ctx_ndlp)
7472 goto node_err;
James Smart12265f62010-10-22 11:05:53 -04007473 mbox->vport = vport;
7474 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7475 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7476 != MBX_NOT_FINISHED)
7477 /* Mbox completion will send ELS Response */
7478 return 0;
7479 /* Decrement reference count used for the failed mbox
7480 * command.
7481 */
7482 lpfc_nlp_put(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08007483node_err:
James Smart12265f62010-10-22 11:05:53 -04007484 mempool_free(mbox, phba->mbox_mem_pool);
7485 }
7486reject_out:
7487 /* issue rejection response */
7488 stat.un.b.lsRjtRsvd0 = 0;
7489 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7490 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7491 stat.un.b.vendorUnique = 0;
7492 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7493 return 0;
7494}
7495
7496/**
7497 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7498 * @vport: pointer to a host virtual N_Port data structure.
7499 * @cmdiocb: pointer to lpfc command iocb data structure.
7500 * @ndlp: pointer to a node-list data structure.
7501 *
7502 * This routine processes Read Timout Value (RTV) IOCB received as an
7503 * ELS unsolicited event. It first checks the remote port state. If the
7504 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7505 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7506 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7507 * Value (RTV) unsolicited IOCB event.
7508 *
7509 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7510 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7511 * will be stored into the context1 field of the IOCB for the completion
James Smart6cde2e3e2020-01-27 16:23:08 -08007512 * callback function to the RTV Accept Response ELS IOCB command.
James Smart12265f62010-10-22 11:05:53 -04007513 *
7514 * Return codes
7515 * 0 - Successfully processed rtv iocb (currently always return 0)
7516 **/
7517static int
7518lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7519 struct lpfc_nodelist *ndlp)
7520{
James Smart4430f7f2020-11-15 11:26:31 -08007521 int rc = 0;
James Smart12265f62010-10-22 11:05:53 -04007522 struct lpfc_hba *phba = vport->phba;
7523 struct ls_rjt stat;
7524 struct RTV_RSP *rtv_rsp;
7525 uint8_t *pcmd;
7526 struct lpfc_iocbq *elsiocb;
7527 uint32_t cmdsize;
7528
7529
7530 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7531 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007532 /* reject the unsolicited RTV request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007533 goto reject_out;
7534
7535 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7536 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7537 lpfc_max_els_tries, ndlp,
7538 ndlp->nlp_DID, ELS_CMD_ACC);
7539
7540 if (!elsiocb)
7541 return 1;
7542
7543 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
Colin Ian King8fd03fd2017-12-22 00:39:36 +00007544 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart12265f62010-10-22 11:05:53 -04007545 pcmd += sizeof(uint32_t); /* Skip past command */
7546
7547 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04007548 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7549 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04007550
7551 rtv_rsp = (struct RTV_RSP *)pcmd;
7552
7553 /* populate RTV payload */
7554 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7555 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7556 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7557 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7558 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7559
7560 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7561 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7562 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7563 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7564 "Data: x%x x%x x%x\n",
7565 elsiocb->iotag, elsiocb->iocb.ulpContext,
7566 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7567 ndlp->nlp_rpi,
7568 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7569 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7570 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007571 elsiocb->context1 = lpfc_nlp_get(ndlp);
7572 if (!elsiocb->context1) {
James Smart12265f62010-10-22 11:05:53 -04007573 lpfc_els_free_iocb(phba, elsiocb);
James Smart4430f7f2020-11-15 11:26:31 -08007574 return 0;
7575 }
7576
7577 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7578 if (rc == IOCB_ERROR) {
7579 lpfc_nlp_put(ndlp);
7580 lpfc_els_free_iocb(phba, elsiocb);
7581 }
James Smart12265f62010-10-22 11:05:53 -04007582 return 0;
7583
7584reject_out:
7585 /* issue rejection response */
7586 stat.un.b.lsRjtRsvd0 = 0;
7587 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7588 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7589 stat.un.b.vendorUnique = 0;
7590 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7591 return 0;
7592}
7593
James Smart6cde2e3e2020-01-27 16:23:08 -08007594/* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
James Smart19ca7602010-11-20 23:11:55 -05007595 * @vport: pointer to a host virtual N_Port data structure.
7596 * @ndlp: pointer to a node-list data structure.
7597 * @did: DID of the target.
7598 * @rrq: Pointer to the rrq struct.
7599 *
7600 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7601 * Successful the the completion handler will clear the RRQ.
7602 *
7603 * Return codes
7604 * 0 - Successfully sent rrq els iocb.
7605 * 1 - Failed to send rrq els iocb.
7606 **/
7607static int
7608lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7609 uint32_t did, struct lpfc_node_rrq *rrq)
7610{
7611 struct lpfc_hba *phba = vport->phba;
7612 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05007613 struct lpfc_iocbq *elsiocb;
7614 uint8_t *pcmd;
7615 uint16_t cmdsize;
7616 int ret;
7617
7618
7619 if (ndlp != rrq->ndlp)
7620 ndlp = rrq->ndlp;
James Smart307e3382020-11-15 11:26:30 -08007621 if (!ndlp)
James Smart19ca7602010-11-20 23:11:55 -05007622 return 1;
7623
7624 /* If ndlp is not NULL, we will bump the reference count on it */
7625 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7626 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7627 ELS_CMD_RRQ);
7628 if (!elsiocb)
7629 return 1;
7630
James Smart19ca7602010-11-20 23:11:55 -05007631 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7632
7633 /* For RRQ request, remainder of payload is Exchange IDs */
7634 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7635 pcmd += sizeof(uint32_t);
7636 els_rrq = (struct RRQ *) pcmd;
7637
James Smartee0f4fe2012-05-09 21:19:14 -04007638 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05007639 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7640 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7641 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7642 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7643
7644
7645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7646 "Issue RRQ: did:x%x",
7647 did, rrq->xritag, rrq->rxid);
7648 elsiocb->context_un.rrq = rrq;
7649 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
James Smart4430f7f2020-11-15 11:26:31 -08007650 elsiocb->context1 = lpfc_nlp_get(ndlp);
7651 if (!elsiocb->context1)
7652 goto node_err;
James Smart19ca7602010-11-20 23:11:55 -05007653
James Smart4430f7f2020-11-15 11:26:31 -08007654 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7655 if (ret == IOCB_ERROR)
7656 goto io_err;
James Smart19ca7602010-11-20 23:11:55 -05007657 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08007658
7659 io_err:
7660 lpfc_nlp_put(ndlp);
7661 node_err:
7662 lpfc_els_free_iocb(phba, elsiocb);
7663 return 1;
James Smart19ca7602010-11-20 23:11:55 -05007664}
7665
7666/**
7667 * lpfc_send_rrq - Sends ELS RRQ if needed.
7668 * @phba: pointer to lpfc hba data structure.
7669 * @rrq: pointer to the active rrq.
7670 *
7671 * This routine will call the lpfc_issue_els_rrq if the rrq is
7672 * still active for the xri. If this function returns a failure then
7673 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7674 *
7675 * Returns 0 Success.
7676 * 1 Failure.
7677 **/
7678int
7679lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7680{
7681 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
James Smartc8cb2612019-05-06 17:26:49 -07007682 rrq->nlp_DID);
7683 if (!ndlp)
7684 return 1;
7685
James Smart19ca7602010-11-20 23:11:55 -05007686 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7687 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7688 rrq->nlp_DID, rrq);
7689 else
7690 return 1;
7691}
7692
James Smarte59058c2008-08-24 21:49:00 -04007693/**
James Smart3621a712009-04-06 18:47:14 -04007694 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04007695 * @vport: pointer to a host virtual N_Port data structure.
7696 * @cmdsize: size of the ELS command.
7697 * @oldiocb: pointer to the original lpfc command iocb data structure.
7698 * @ndlp: pointer to a node-list data structure.
7699 *
7700 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7701 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7702 *
7703 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7704 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7705 * will be stored into the context1 field of the IOCB for the completion
7706 * callback function to the RPL Accept Response ELS command.
7707 *
7708 * Return code
7709 * 0 - Successfully issued ACC RPL ELS command
7710 * 1 - Failed to issue ACC RPL ELS command
7711 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05007712static int
James Smart2e0fef82007-06-17 19:56:36 -05007713lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7714 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007715{
James Smart4430f7f2020-11-15 11:26:31 -08007716 int rc = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007717 struct lpfc_hba *phba = vport->phba;
7718 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007719 RPL_RSP rpl_rsp;
7720 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007721 uint8_t *pcmd;
7722
James Smart2e0fef82007-06-17 19:56:36 -05007723 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7724 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007725
James Smart488d1462006-03-07 15:02:37 -05007726 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007727 return 1;
James Smart488d1462006-03-07 15:02:37 -05007728
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007729 icmd = &elsiocb->iocb;
7730 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007731 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7732 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007733
7734 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7735 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007736 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007737 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7738 pcmd += sizeof(uint16_t);
7739
7740 /* Setup the RPL ACC payload */
7741 rpl_rsp.listLen = be32_to_cpu(1);
7742 rpl_rsp.index = 0;
7743 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007744 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7745 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007746 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007747 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007748 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007749 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7750 "0120 Xmit ELS RPL ACC response tag x%x "
7751 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7752 "rpi x%x\n",
7753 elsiocb->iotag, elsiocb->iocb.ulpContext,
7754 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7755 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007756 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007757 phba->fc_stat.elsXmitACC++;
James Smart4430f7f2020-11-15 11:26:31 -08007758 elsiocb->context1 = lpfc_nlp_get(ndlp);
7759 if (!elsiocb->context1)
7760 goto node_err;
7761
7762 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7763 if (rc == IOCB_ERROR)
7764 goto io_err;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007765 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08007766
7767 io_err:
7768 lpfc_nlp_put(ndlp);
7769 node_err:
7770 lpfc_els_free_iocb(phba, elsiocb);
7771 return 1;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007772}
7773
James Smarte59058c2008-08-24 21:49:00 -04007774/**
James Smart3621a712009-04-06 18:47:14 -04007775 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007776 * @vport: pointer to a host virtual N_Port data structure.
7777 * @cmdiocb: pointer to lpfc command iocb data structure.
7778 * @ndlp: pointer to a node-list data structure.
7779 *
7780 * This routine processes Read Port List (RPL) IOCB received as an ELS
7781 * unsolicited event. It first checks the remote port state. If the remote
7782 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7783 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7784 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7785 * to accept the RPL.
7786 *
7787 * Return code
7788 * 0 - Successfully processed rpl iocb (currently always return 0)
7789 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007790static int
James Smart2e0fef82007-06-17 19:56:36 -05007791lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7792 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007793{
7794 struct lpfc_dmabuf *pcmd;
7795 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007796 uint32_t maxsize;
7797 uint16_t cmdsize;
7798 RPL *rpl;
7799 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007800
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007801 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7802 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007803 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007804 stat.un.b.lsRjtRsvd0 = 0;
7805 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7806 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7807 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007808 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7809 NULL);
James Smart90160e02008-08-24 21:49:45 -04007810 /* rejected the unsolicited RPL request and done with it */
7811 return 0;
dea31012005-04-17 16:05:31 -05007812 }
7813
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007814 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7815 lp = (uint32_t *) pcmd->virt;
7816 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007817 maxsize = be32_to_cpu(rpl->maxsize);
7818
7819 /* We support only one port */
7820 if ((rpl->index == 0) &&
7821 ((maxsize == 0) ||
7822 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7823 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007824 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007825 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7826 }
James Smart2e0fef82007-06-17 19:56:36 -05007827 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007828
7829 return 0;
7830}
7831
James Smarte59058c2008-08-24 21:49:00 -04007832/**
James Smart3621a712009-04-06 18:47:14 -04007833 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007834 * @vport: pointer to a virtual N_Port data structure.
7835 * @cmdiocb: pointer to lpfc command iocb data structure.
7836 * @ndlp: pointer to a node-list data structure.
7837 *
7838 * This routine processes Fibre Channel Address Resolution Protocol
7839 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7840 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7841 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7842 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7843 * remote PortName is compared against the FC PortName stored in the @vport
7844 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7845 * compared against the FC NodeName stored in the @vport data structure.
7846 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7847 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7848 * invoked to send out FARP Response to the remote node. Before sending the
7849 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7850 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7851 * routine is invoked to log into the remote port first.
7852 *
7853 * Return code
7854 * 0 - Either the FARP Match Mode not supported or successfully processed
7855 **/
dea31012005-04-17 16:05:31 -05007856static int
James Smart2e0fef82007-06-17 19:56:36 -05007857lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7858 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007859{
7860 struct lpfc_dmabuf *pcmd;
7861 uint32_t *lp;
7862 IOCB_t *icmd;
7863 FARP *fp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007864 uint32_t cnt, did;
dea31012005-04-17 16:05:31 -05007865
7866 icmd = &cmdiocb->iocb;
7867 did = icmd->un.elsreq64.remoteID;
7868 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7869 lp = (uint32_t *) pcmd->virt;
7870
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007871 lp++;
dea31012005-04-17 16:05:31 -05007872 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007873 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7875 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007876 /* We will only support match on WWPN or WWNN */
7877 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007878 return 0;
dea31012005-04-17 16:05:31 -05007879 }
7880
7881 cnt = 0;
7882 /* If this FARP command is searching for my portname */
7883 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007884 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007885 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007886 cnt = 1;
7887 }
7888
7889 /* If this FARP command is searching for my nodename */
7890 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007891 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007892 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007893 cnt = 1;
7894 }
7895
7896 if (cnt) {
7897 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7898 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7899 /* Log back into the node before sending the FARP. */
7900 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007901 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007902 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007903 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007904 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007905 }
7906
7907 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007908 if (fp->Rflags & FARP_REQUEST_FARPR)
7909 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007910 }
7911 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007912 return 0;
dea31012005-04-17 16:05:31 -05007913}
7914
James Smarte59058c2008-08-24 21:49:00 -04007915/**
James Smart3621a712009-04-06 18:47:14 -04007916 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007917 * @vport: pointer to a host virtual N_Port data structure.
7918 * @cmdiocb: pointer to lpfc command iocb data structure.
7919 * @ndlp: pointer to a node-list data structure.
7920 *
7921 * This routine processes Fibre Channel Address Resolution Protocol
7922 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7923 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7924 * the FARP response request.
7925 *
7926 * Return code
7927 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7928 **/
dea31012005-04-17 16:05:31 -05007929static int
James Smart2e0fef82007-06-17 19:56:36 -05007930lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7931 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007932{
7933 struct lpfc_dmabuf *pcmd;
7934 uint32_t *lp;
7935 IOCB_t *icmd;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007936 uint32_t did;
dea31012005-04-17 16:05:31 -05007937
7938 icmd = &cmdiocb->iocb;
7939 did = icmd->un.elsreq64.remoteID;
7940 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7941 lp = (uint32_t *) pcmd->virt;
7942
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007943 lp++;
dea31012005-04-17 16:05:31 -05007944 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007945 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7946 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007947 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007948 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007949
7950 return 0;
7951}
7952
James Smarte59058c2008-08-24 21:49:00 -04007953/**
James Smart3621a712009-04-06 18:47:14 -04007954 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007955 * @vport: pointer to a host virtual N_Port data structure.
7956 * @cmdiocb: pointer to lpfc command iocb data structure.
7957 * @fan_ndlp: pointer to a node-list data structure.
7958 *
7959 * This routine processes a Fabric Address Notification (FAN) IOCB
7960 * command received as an ELS unsolicited event. The FAN ELS command will
7961 * only be processed on a physical port (i.e., the @vport represents the
7962 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7963 * compared against those in the phba data structure. If any of those is
7964 * different, the lpfc_initial_flogi() routine is invoked to initialize
7965 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7966 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7967 * is invoked to register login to the fabric.
7968 *
7969 * Return code
7970 * 0 - Successfully processed fan iocb (currently always return 0).
7971 **/
dea31012005-04-17 16:05:31 -05007972static int
James Smart2e0fef82007-06-17 19:56:36 -05007973lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7974 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007975{
James Smart2e0fef82007-06-17 19:56:36 -05007976 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007977 uint32_t *lp;
7978 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007979
James Smart0d2b6b82008-06-14 22:52:47 -04007980 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7981 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7982 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007983 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007984 if ((vport == phba->pport) &&
7985 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007986 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007987 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007988 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007989 sizeof(struct lpfc_name)))) {
7990 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007991 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007992 } else {
7993 /* FAN verified - skip FLOGI */
7994 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007995 if (phba->sli_rev < LPFC_SLI_REV4)
7996 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007997 else {
7998 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7999 "3138 Need register VFI: (x%x/%x)\n",
8000 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04008001 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05008002 }
dea31012005-04-17 16:05:31 -05008003 }
dea31012005-04-17 16:05:31 -05008004 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008005 return 0;
dea31012005-04-17 16:05:31 -05008006}
8007
James Smarte59058c2008-08-24 21:49:00 -04008008/**
James Smart3621a712009-04-06 18:47:14 -04008009 * lpfc_els_timeout - Handler funciton to the els timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01008010 * @t: timer context used to obtain the vport.
James Smarte59058c2008-08-24 21:49:00 -04008011 *
8012 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8013 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8014 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8015 * up the worker thread. It is for the worker thread to invoke the routine
8016 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8017 **/
dea31012005-04-17 16:05:31 -05008018void
Kees Cookf22eb4d2017-09-06 20:24:26 -07008019lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05008020{
Kees Cookf22eb4d2017-09-06 20:24:26 -07008021 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05008022 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04008023 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05008024 unsigned long iflag;
8025
James Smart2e0fef82007-06-17 19:56:36 -05008026 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04008027 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05008028 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05008029 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04008030 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05008031
James Smart06918ac2014-02-20 09:57:57 -05008032 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04008033 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05008034 return;
8035}
8036
James Smart2a9bf3d2010-06-07 15:24:45 -04008037
James Smarte59058c2008-08-24 21:49:00 -04008038/**
James Smart3621a712009-04-06 18:47:14 -04008039 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04008040 * @vport: pointer to a virtual N_Port data structure.
8041 *
8042 * This routine is the actual handler function that processes an ELS timeout
8043 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8044 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8045 * invoking the lpfc_sli_issue_abort_iotag() routine.
8046 **/
dea31012005-04-17 16:05:31 -05008047void
James Smart2e0fef82007-06-17 19:56:36 -05008048lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008049{
James Smart2e0fef82007-06-17 19:56:36 -05008050 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05008051 struct lpfc_sli_ring *pring;
8052 struct lpfc_iocbq *tmp_iocb, *piocb;
8053 IOCB_t *cmd = NULL;
8054 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05008055 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05008056 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05008057 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04008058 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05008059
James Smart2a9bf3d2010-06-07 15:24:45 -04008060
dea31012005-04-17 16:05:31 -05008061 timeout = (uint32_t)(phba->fc_ratov << 1);
8062
James Smart895427b2017-02-12 13:52:30 -08008063 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07008064 if (unlikely(!pring))
8065 return;
James Smart895427b2017-02-12 13:52:30 -08008066
James Smarte3041422020-04-21 13:33:54 -07008067 if (phba->pport->load_flag & FC_UNLOADING)
James Smart06918ac2014-02-20 09:57:57 -05008068 return;
James Smarte3041422020-04-21 13:33:54 -07008069
James Smart2a9bf3d2010-06-07 15:24:45 -04008070 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05008071 if (phba->sli_rev == LPFC_SLI_REV4)
8072 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04008073
James Smart0976e1a2013-12-17 20:29:36 -05008074 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05008075 cmd = &piocb->iocb;
8076
James Smart2e0fef82007-06-17 19:56:36 -05008077 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8078 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8079 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05008080 continue;
James Smart2e0fef82007-06-17 19:56:36 -05008081
8082 if (piocb->vport != vport)
8083 continue;
8084
dea31012005-04-17 16:05:31 -05008085 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05008086 if (pcmd)
8087 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05008088
James Smart92d7f7b2007-06-17 19:56:38 -05008089 if (els_command == ELS_CMD_FARP ||
8090 els_command == ELS_CMD_FARPR ||
8091 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05008092 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05008093
dea31012005-04-17 16:05:31 -05008094 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05008095 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05008096 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05008097 else
dea31012005-04-17 16:05:31 -05008098 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05008099 continue;
8100 }
8101
James Smart2e0fef82007-06-17 19:56:36 -05008102 remote_ID = 0xffffffff;
8103 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05008104 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05008105 else {
8106 struct lpfc_nodelist *ndlp;
8107 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart307e3382020-11-15 11:26:30 -08008108 if (ndlp)
James Smart2e0fef82007-06-17 19:56:36 -05008109 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05008110 }
James Smart2a9bf3d2010-06-07 15:24:45 -04008111 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05008112 }
James Smart0976e1a2013-12-17 20:29:36 -05008113 if (phba->sli_rev == LPFC_SLI_REV4)
8114 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05008115 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04008116
James Smart2a9bf3d2010-06-07 15:24:45 -04008117 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05008118 cmd = &piocb->iocb;
Dick Kennedy372c1872020-06-30 14:50:00 -07008119 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart2a9bf3d2010-06-07 15:24:45 -04008120 "0127 ELS timeout Data: x%x x%x x%x "
8121 "x%x\n", els_command,
8122 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8123 spin_lock_irq(&phba->hbalock);
8124 list_del_init(&piocb->dlist);
8125 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8126 spin_unlock_irq(&phba->hbalock);
8127 }
8128
James Smart895427b2017-02-12 13:52:30 -08008129 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05008130 if (!(phba->pport->load_flag & FC_UNLOADING))
8131 mod_timer(&vport->els_tmofunc,
8132 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05008133}
8134
James Smarte59058c2008-08-24 21:49:00 -04008135/**
James Smart3621a712009-04-06 18:47:14 -04008136 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04008137 * @vport: pointer to a host virtual N_Port data structure.
8138 *
8139 * This routine is used to clean up all the outstanding ELS commands on a
8140 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8141 * routine. After that, it walks the ELS transmit queue to remove all the
8142 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8143 * the IOCBs with a non-NULL completion callback function, the callback
8144 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8145 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8146 * callback function, the IOCB will simply be released. Finally, it walks
8147 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8148 * completion queue IOCB that is associated with the @vport and is not
8149 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8150 * part of the discovery state machine) out to HBA by invoking the
8151 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8152 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8153 * the IOCBs are aborted when this function returns.
8154 **/
dea31012005-04-17 16:05:31 -05008155void
James Smart2e0fef82007-06-17 19:56:36 -05008156lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008157{
James Smart0976e1a2013-12-17 20:29:36 -05008158 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05008159 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08008160 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05008161 struct lpfc_iocbq *tmp_iocb, *piocb;
8162 IOCB_t *cmd = NULL;
James Smartd38b4a52019-09-21 20:59:00 -07008163 unsigned long iflags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008164
8165 lpfc_fabric_abort_vport(vport);
James Smartd38b4a52019-09-21 20:59:00 -07008166
James Smart0976e1a2013-12-17 20:29:36 -05008167 /*
8168 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8169 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8170 * ultimately grabs the ring_lock, the driver must splice the list into
8171 * a working list and release the locks before calling the abort.
8172 */
James Smartd38b4a52019-09-21 20:59:00 -07008173 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart895427b2017-02-12 13:52:30 -08008174 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008175
8176 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8177 if (unlikely(!pring)) {
James Smartd38b4a52019-09-21 20:59:00 -07008178 spin_unlock_irqrestore(&phba->hbalock, iflags);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008179 return;
8180 }
8181
James Smart0976e1a2013-12-17 20:29:36 -05008182 if (phba->sli_rev == LPFC_SLI_REV4)
8183 spin_lock(&pring->ring_lock);
8184
James Smart6ede2dd2019-08-14 16:56:44 -07008185 /* First we need to issue aborts to outstanding cmds on txcmpl */
James Smart0976e1a2013-12-17 20:29:36 -05008186 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8187 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8188 continue;
8189
8190 if (piocb->vport != vport)
8191 continue;
James Smart6ede2dd2019-08-14 16:56:44 -07008192
James Smart15498dc2019-09-21 20:58:59 -07008193 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8194 continue;
8195
James Smart6ede2dd2019-08-14 16:56:44 -07008196 /* On the ELS ring we can have ELS_REQUESTs or
8197 * GEN_REQUESTs waiting for a response.
8198 */
8199 cmd = &piocb->iocb;
8200 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8201 list_add_tail(&piocb->dlist, &abort_list);
8202
8203 /* If the link is down when flushing ELS commands
8204 * the firmware will not complete them till after
8205 * the link comes back up. This may confuse
8206 * discovery for the new link up, so we need to
8207 * change the compl routine to just clean up the iocb
8208 * and avoid any retry logic.
8209 */
8210 if (phba->link_state == LPFC_LINK_DOWN)
8211 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8212 }
8213 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8214 list_add_tail(&piocb->dlist, &abort_list);
James Smart0976e1a2013-12-17 20:29:36 -05008215 }
James Smart6ede2dd2019-08-14 16:56:44 -07008216
James Smart0976e1a2013-12-17 20:29:36 -05008217 if (phba->sli_rev == LPFC_SLI_REV4)
8218 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008219 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6ede2dd2019-08-14 16:56:44 -07008220
8221 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
James Smart0976e1a2013-12-17 20:29:36 -05008222 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smartd38b4a52019-09-21 20:59:00 -07008223 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008224 list_del_init(&piocb->dlist);
8225 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
James Smartd38b4a52019-09-21 20:59:00 -07008226 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008227 }
8228 if (!list_empty(&abort_list))
Dick Kennedy372c1872020-06-30 14:50:00 -07008229 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart0976e1a2013-12-17 20:29:36 -05008230 "3387 abort list for txq not empty\n");
8231 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05008232
James Smartd38b4a52019-09-21 20:59:00 -07008233 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008234 if (phba->sli_rev == LPFC_SLI_REV4)
8235 spin_lock(&pring->ring_lock);
8236
James Smart6ede2dd2019-08-14 16:56:44 -07008237 /* No need to abort the txq list,
8238 * just queue them up for lpfc_sli_cancel_iocbs
8239 */
dea31012005-04-17 16:05:31 -05008240 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8241 cmd = &piocb->iocb;
8242
8243 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8244 continue;
8245 }
8246
8247 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04008248 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8249 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8250 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8251 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05008252 continue;
dea31012005-04-17 16:05:31 -05008253
James Smart2e0fef82007-06-17 19:56:36 -05008254 if (piocb->vport != vport)
8255 continue;
8256
James Smart0976e1a2013-12-17 20:29:36 -05008257 list_del_init(&piocb->list);
8258 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05008259 }
James Smart6ede2dd2019-08-14 16:56:44 -07008260
8261 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8262 if (vport == phba->pport) {
8263 list_for_each_entry_safe(piocb, tmp_iocb,
8264 &phba->fabric_iocb_list, list) {
8265 cmd = &piocb->iocb;
8266 list_del_init(&piocb->list);
8267 list_add_tail(&piocb->list, &abort_list);
8268 }
8269 }
8270
James Smart0976e1a2013-12-17 20:29:36 -05008271 if (phba->sli_rev == LPFC_SLI_REV4)
8272 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008273 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart2534ba72007-04-25 09:52:20 -04008274
James Smart6ede2dd2019-08-14 16:56:44 -07008275 /* Cancel all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05008276 lpfc_sli_cancel_iocbs(phba, &abort_list,
8277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04008278
dea31012005-04-17 16:05:31 -05008279 return;
8280}
8281
James Smarte59058c2008-08-24 21:49:00 -04008282/**
James Smart3621a712009-04-06 18:47:14 -04008283 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04008284 * @phba: pointer to lpfc hba data structure.
8285 *
8286 * This routine is used to clean up all the outstanding ELS commands on a
8287 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8288 * routine. After that, it walks the ELS transmit queue to remove all the
8289 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8290 * the IOCBs with the completion callback function associated, the callback
8291 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8292 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8293 * callback function associated, the IOCB will simply be released. Finally,
8294 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8295 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8296 * management plane IOCBs that are not part of the discovery state machine)
8297 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8298 **/
James Smart549e55c2007-08-02 11:09:51 -04008299void
8300lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8301{
James Smart0976e1a2013-12-17 20:29:36 -05008302 struct lpfc_vport *vport;
James Smart523128e2018-09-10 10:30:46 -07008303
8304 spin_lock_irq(&phba->port_list_lock);
James Smart0976e1a2013-12-17 20:29:36 -05008305 list_for_each_entry(vport, &phba->port_list, listentry)
8306 lpfc_els_flush_cmd(vport);
James Smart523128e2018-09-10 10:30:46 -07008307 spin_unlock_irq(&phba->port_list_lock);
James Smarta257bf92009-04-06 18:48:10 -04008308
James Smart549e55c2007-08-02 11:09:51 -04008309 return;
8310}
8311
James Smarte59058c2008-08-24 21:49:00 -04008312/**
James Smart3621a712009-04-06 18:47:14 -04008313 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04008314 * @phba: Pointer to hba context object.
8315 * @cmdiocbp: Pointer to command iocb which reported error.
8316 * @rspiocbp: Pointer to response iocb which reported error.
8317 *
8318 * This function sends an event when there is an ELS command
8319 * failure.
8320 **/
8321void
8322lpfc_send_els_failure_event(struct lpfc_hba *phba,
8323 struct lpfc_iocbq *cmdiocbp,
8324 struct lpfc_iocbq *rspiocbp)
8325{
8326 struct lpfc_vport *vport = cmdiocbp->vport;
8327 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8328 struct lpfc_lsrjt_event lsrjt_event;
8329 struct lpfc_fabric_event_header fabric_event;
8330 struct ls_rjt stat;
8331 struct lpfc_nodelist *ndlp;
8332 uint32_t *pcmd;
8333
8334 ndlp = cmdiocbp->context1;
James Smart307e3382020-11-15 11:26:30 -08008335 if (!ndlp)
James Smartea2151b2008-09-07 11:52:10 -04008336 return;
8337
8338 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8339 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8340 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8341 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8342 sizeof(struct lpfc_name));
8343 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8344 sizeof(struct lpfc_name));
8345 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8346 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04008347 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04008348 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8349 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8350 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8351 fc_host_post_vendor_event(shost,
8352 fc_get_event_number(),
8353 sizeof(lsrjt_event),
8354 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05008355 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008356 return;
8357 }
8358 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8359 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8360 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8361 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8362 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8363 else
8364 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8365 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8366 sizeof(struct lpfc_name));
8367 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8368 sizeof(struct lpfc_name));
8369 fc_host_post_vendor_event(shost,
8370 fc_get_event_number(),
8371 sizeof(fabric_event),
8372 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05008373 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008374 return;
8375 }
8376
8377}
8378
8379/**
James Smart3621a712009-04-06 18:47:14 -04008380 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04008381 * @vport: Pointer to vport object.
8382 * @ndlp: Pointer FC node object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01008383 * @payload: ELS command code type.
James Smartea2151b2008-09-07 11:52:10 -04008384 *
8385 * This function posts an event when there is an incoming
8386 * unsolicited ELS command.
8387 **/
8388static void
8389lpfc_send_els_event(struct lpfc_vport *vport,
8390 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05008391 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04008392{
James Smartddcc50f2008-12-04 22:38:46 -05008393 struct lpfc_els_event_header *els_data = NULL;
8394 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04008395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8396
James Smartddcc50f2008-12-04 22:38:46 -05008397 if (*payload == ELS_CMD_LOGO) {
8398 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8399 if (!logo_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008400 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05008401 "0148 Failed to allocate memory "
8402 "for LOGO event\n");
8403 return;
8404 }
8405 els_data = &logo_data->header;
8406 } else {
8407 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8408 GFP_KERNEL);
8409 if (!els_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008410 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartddcc50f2008-12-04 22:38:46 -05008411 "0149 Failed to allocate memory "
8412 "for ELS event\n");
8413 return;
8414 }
8415 }
8416 els_data->event_type = FC_REG_ELS_EVENT;
8417 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04008418 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05008419 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008420 break;
8421 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05008422 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008423 break;
8424 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05008425 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8426 break;
8427 case ELS_CMD_LOGO:
8428 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8429 /* Copy the WWPN in the LOGO payload */
8430 memcpy(logo_data->logo_wwpn, &payload[2],
8431 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04008432 break;
8433 default:
Julia Lawalle9161412009-02-08 22:43:19 +01008434 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04008435 return;
8436 }
James Smartddcc50f2008-12-04 22:38:46 -05008437 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8438 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8439 if (*payload == ELS_CMD_LOGO) {
8440 fc_host_post_vendor_event(shost,
8441 fc_get_event_number(),
8442 sizeof(struct lpfc_logo_event),
8443 (char *)logo_data,
8444 LPFC_NL_VENDOR_ID);
8445 kfree(logo_data);
8446 } else {
8447 fc_host_post_vendor_event(shost,
8448 fc_get_event_number(),
8449 sizeof(struct lpfc_els_event_header),
8450 (char *)els_data,
8451 LPFC_NL_VENDOR_ID);
8452 kfree(els_data);
8453 }
James Smartea2151b2008-09-07 11:52:10 -04008454
8455 return;
8456}
8457
8458
James Smartdf3fe762020-02-10 09:31:55 -08008459DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8460 FC_LS_TLV_DTAG_INIT);
8461
8462DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8463 FC_FPIN_LI_EVT_TYPES_INIT);
8464
8465/**
8466 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8467 * @vport: Pointer to vport object.
Lee Jonesa0e4a642020-07-23 13:24:07 +01008468 * @tlv: Pointer to the Link Integrity Notification Descriptor.
James Smartdf3fe762020-02-10 09:31:55 -08008469 *
8470 * This function processes a link integrity FPIN event by
8471 * logging a message
8472 **/
8473static void
8474lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8475{
8476 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8477 const char *li_evt_str;
8478 u32 li_evt;
8479
8480 li_evt = be16_to_cpu(li->event_type);
8481 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8482
8483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8484 "4680 FPIN Link Integrity %s (x%x) "
8485 "Detecting PN x%016llx Attached PN x%016llx "
8486 "Duration %d mSecs Count %d Port Cnt %d\n",
8487 li_evt_str, li_evt,
8488 be64_to_cpu(li->detecting_wwpn),
8489 be64_to_cpu(li->attached_wwpn),
8490 be32_to_cpu(li->event_threshold),
8491 be32_to_cpu(li->event_count),
8492 be32_to_cpu(li->pname_count));
8493}
8494
8495static void
8496lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8497 u32 fpin_length)
8498{
8499 struct fc_tlv_desc *tlv;
8500 const char *dtag_nm;
8501 uint32_t desc_cnt = 0, bytes_remain;
8502 u32 dtag;
8503
8504 /* FPINs handled only if we are in the right discovery state */
8505 if (vport->port_state < LPFC_DISC_AUTH)
8506 return;
8507
8508 /* make sure there is the full fpin header */
8509 if (fpin_length < sizeof(struct fc_els_fpin))
8510 return;
8511
8512 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8513 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8514 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8515
8516 /* process each descriptor */
8517 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8518 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8519
8520 dtag = be32_to_cpu(tlv->desc_tag);
8521 switch (dtag) {
8522 case ELS_DTAG_LNK_INTEGRITY:
8523 lpfc_els_rcv_fpin_li(vport, tlv);
8524 break;
8525 default:
8526 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
Dick Kennedy372c1872020-06-30 14:50:00 -07008527 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartdf3fe762020-02-10 09:31:55 -08008528 "4678 skipped FPIN descriptor[%d]: "
8529 "tag x%x (%s)\n",
8530 desc_cnt, dtag, dtag_nm);
8531 break;
8532 }
8533
8534 desc_cnt++;
8535 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8536 tlv = fc_tlv_next_desc(tlv);
8537 }
8538
8539 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8540 (char *)fpin);
8541}
8542
James Smartea2151b2008-09-07 11:52:10 -04008543/**
James Smart3621a712009-04-06 18:47:14 -04008544 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04008545 * @phba: pointer to lpfc hba data structure.
8546 * @pring: pointer to a SLI ring.
8547 * @vport: pointer to a host virtual N_Port data structure.
8548 * @elsiocb: pointer to lpfc els command iocb data structure.
8549 *
8550 * This routine is used for processing the IOCB associated with a unsolicited
8551 * event. It first determines whether there is an existing ndlp that matches
8552 * the DID from the unsolicited IOCB. If not, it will create a new one with
8553 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8554 * IOCB is then used to invoke the proper routine and to set up proper state
8555 * of the discovery state machine.
8556 **/
James Smarted957682007-06-17 19:56:37 -05008557static void
8558lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05008559 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05008560{
James Smart87af33f2007-10-27 13:37:43 -04008561 struct Scsi_Host *shost;
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 Smart466e8402015-05-21 13:55:28 -04008622 shost = lpfc_shost_from_vport(vport);
8623 spin_lock_irq(shost->host_lock);
8624 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8625 spin_unlock_irq(shost->host_lock);
Xiyu Yang7217e6e2020-05-25 22:16:24 +08008626 if (newnode)
8627 lpfc_nlp_put(ndlp);
James Smart12838e72014-09-03 12:57:19 -04008628 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04008629 }
8630 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04008631
James Smart329f9bc2007-04-25 09:53:01 -04008632 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08008633 if (!elsiocb->context1)
8634 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05008635 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05008636
8637 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8638 cmd &= ELS_CMD_MASK;
8639 }
8640 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8642 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04008643 "Data: x%x x%x x%x x%x\n",
8644 cmd, did, vport->port_state, vport->fc_flag,
8645 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04008646
James Smart0a9e9682018-11-29 16:09:36 -08008647 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
James Smarteec3d312015-08-31 16:48:18 -04008648 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smart0a9e9682018-11-29 16:09:36 -08008649 (cmd != ELS_CMD_FLOGI) &&
8650 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
James Smart401304c2016-10-13 15:06:14 -07008651 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04008652 rjt_exp = LSEXP_NOTHING_MORE;
8653 goto lsrjt;
8654 }
8655
dea31012005-04-17 16:05:31 -05008656 switch (cmd) {
8657 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8659 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8660 did, vport->port_state, ndlp->nlp_flag);
8661
dea31012005-04-17 16:05:31 -05008662 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05008663 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04008664 if (phba->sli_rev == LPFC_SLI_REV4 &&
8665 (phba->pport->fc_flag & FC_PT2PT)) {
8666 vport->fc_prevDID = vport->fc_myDID;
8667 /* Our DID needs to be updated before registering
8668 * the vfi. This is done in lpfc_rcv_plogi but
8669 * that is called after the reg_vfi.
8670 */
8671 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8673 "3312 Remote port assigned DID x%x "
8674 "%x\n", vport->fc_myDID,
8675 vport->fc_prevDID);
8676 }
James Smart858c9f62007-06-17 19:56:39 -05008677
James Smartddcc50f2008-12-04 22:38:46 -05008678 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05008679
8680 /* If Nport discovery is delayed, reject PLOGIs */
8681 if (vport->fc_flag & FC_DISC_DELAYED) {
8682 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008683 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05008684 break;
8685 }
James Smartd6de08c2015-12-16 18:11:53 -05008686
James Smart858c9f62007-06-17 19:56:39 -05008687 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05008688 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8689 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8690 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008691 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05008692 break;
8693 }
dea31012005-04-17 16:05:31 -05008694 }
James Smart87af33f2007-10-27 13:37:43 -04008695
James Smart87af33f2007-10-27 13:37:43 -04008696 spin_lock_irq(shost->host_lock);
8697 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8698 spin_unlock_irq(shost->host_lock);
8699
James Smart2e0fef82007-06-17 19:56:36 -05008700 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8701 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05008702
dea31012005-04-17 16:05:31 -05008703 break;
8704 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8706 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8707 did, vport->port_state, ndlp->nlp_flag);
8708
dea31012005-04-17 16:05:31 -05008709 phba->fc_stat.elsRcvFLOGI++;
James Smartd496b9a2018-10-23 13:41:08 -07008710
8711 /* If the driver believes fabric discovery is done and is ready,
8712 * bounce the link. There is some descrepancy.
8713 */
8714 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8715 vport->fc_flag & FC_PT2PT &&
8716 vport->rcv_flogi_cnt >= 1) {
8717 rjt_err = LSRJT_LOGICAL_BSY;
8718 rjt_exp = LSEXP_NOTHING_MORE;
8719 init_link++;
8720 goto lsrjt;
8721 }
8722
James Smart51ef4c22007-08-02 11:10:31 -04008723 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008724 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008725 lpfc_nlp_put(ndlp);
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 Smart98c9ea52007-10-27 13:37:33 -04008767 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008768 break;
8769 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05008770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8771 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8772 did, vport->port_state, ndlp->nlp_flag);
8773
James Smartddcc50f2008-12-04 22:38:46 -05008774 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05008775 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008776 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008777 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008778 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008779 break;
8780 }
James Smart2e0fef82007-06-17 19:56:36 -05008781 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8782 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05008783 break;
8784 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05008785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8786 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8787 did, vport->port_state, ndlp->nlp_flag);
8788
dea31012005-04-17 16:05:31 -05008789 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008790 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008791 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008792 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008793 break;
8794 }
James Smart2e0fef82007-06-17 19:56:36 -05008795 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8796 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05008797 break;
8798 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05008799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8800 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8801 did, vport->port_state, ndlp->nlp_flag);
8802
dea31012005-04-17 16:05:31 -05008803 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05008804 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008805 break;
8806 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05008807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8808 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8809 did, vport->port_state, ndlp->nlp_flag);
8810
dea31012005-04-17 16:05:31 -05008811 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05008812 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008813 break;
8814 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05008815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8816 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8817 did, vport->port_state, ndlp->nlp_flag);
8818
dea31012005-04-17 16:05:31 -05008819 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05008820 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008821 break;
dea31012005-04-17 16:05:31 -05008822 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08008823 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05008824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8825 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8826 did, vport->port_state, ndlp->nlp_flag);
8827
dea31012005-04-17 16:05:31 -05008828 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04008829 if ((vport->port_state < LPFC_DISC_AUTH) &&
8830 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05008831 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008832 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008833 break;
8834 }
James Smart2e0fef82007-06-17 19:56:36 -05008835 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05008836 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008837 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05008838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8839 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8840 did, vport->port_state, ndlp->nlp_flag);
8841
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008842 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05008843 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008844 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008845 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008846 break;
James Smart12265f62010-10-22 11:05:53 -04008847 case ELS_CMD_RLS:
8848 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8849 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8850 did, vport->port_state, ndlp->nlp_flag);
8851
8852 phba->fc_stat.elsRcvRLS++;
8853 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8854 if (newnode)
8855 lpfc_nlp_put(ndlp);
8856 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008857 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05008858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8859 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8860 did, vport->port_state, ndlp->nlp_flag);
8861
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008862 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008863 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008864 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008865 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008866 break;
dea31012005-04-17 16:05:31 -05008867 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8869 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8870 did, vport->port_state, ndlp->nlp_flag);
8871
dea31012005-04-17 16:05:31 -05008872 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008873 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008874 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008875 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008876 break;
James Smart12265f62010-10-22 11:05:53 -04008877 case ELS_CMD_RTV:
8878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8879 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8880 did, vport->port_state, ndlp->nlp_flag);
8881 phba->fc_stat.elsRcvRTV++;
8882 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8883 if (newnode)
8884 lpfc_nlp_put(ndlp);
8885 break;
James Smart5ffc2662009-11-18 15:39:44 -05008886 case ELS_CMD_RRQ:
8887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8888 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8889 did, vport->port_state, ndlp->nlp_flag);
8890
8891 phba->fc_stat.elsRcvRRQ++;
8892 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8893 if (newnode)
8894 lpfc_nlp_put(ndlp);
8895 break;
James Smart12265f62010-10-22 11:05:53 -04008896 case ELS_CMD_ECHO:
8897 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8898 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8899 did, vport->port_state, ndlp->nlp_flag);
8900
8901 phba->fc_stat.elsRcvECHO++;
8902 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8903 if (newnode)
8904 lpfc_nlp_put(ndlp);
8905 break;
James Smart303f2f92013-01-03 15:43:11 -05008906 case ELS_CMD_REC:
Colin Ian King8fd03fd2017-12-22 00:39:36 +00008907 /* receive this due to exchange closed */
8908 rjt_err = LSRJT_UNABLE_TPC;
8909 rjt_exp = LSEXP_INVALID_OX_RX;
James Smart303f2f92013-01-03 15:43:11 -05008910 break;
James Smart1a61e542019-04-05 16:04:23 -07008911 case ELS_CMD_FPIN:
James Smartdf3fe762020-02-10 09:31:55 -08008912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8913 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8914 did, vport->port_state, ndlp->nlp_flag);
8915
8916 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8917 payload_len);
8918
8919 /* There are no replies, so no rjt codes */
James Smart1a61e542019-04-05 16:04:23 -07008920 break;
dea31012005-04-17 16:05:31 -05008921 default:
James Smart858c9f62007-06-17 19:56:39 -05008922 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8923 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8924 cmd, did, vport->port_state);
8925
dea31012005-04-17 16:05:31 -05008926 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008927 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008928 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008929
8930 /* Unknown ELS command <elsCmd> received from NPORT <did> */
Dick Kennedy372c1872020-06-30 14:50:00 -07008931 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04008932 "0115 Unknown ELS command x%x "
8933 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008934 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008935 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008936 break;
8937 }
8938
James Smarteec3d312015-08-31 16:48:18 -04008939lsrjt:
dea31012005-04-17 16:05:31 -05008940 /* check if need to LS_RJT received ELS cmd */
8941 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008942 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008943 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008944 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008945 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
James Smart4430f7f2020-11-15 11:26:31 -08008946 NULL);
8947 /* Remove the reference from above for new nodes. */
8948 if (newnode)
8949 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008950 }
8951
James Smartd7c255b2008-08-24 21:50:00 -04008952 lpfc_nlp_put(elsiocb->context1);
8953 elsiocb->context1 = NULL;
James Smartd496b9a2018-10-23 13:41:08 -07008954
8955 /* Special case. Driver received an unsolicited command that
8956 * unsupportable given the driver's current state. Reset the
8957 * link and start over.
8958 */
8959 if (init_link) {
8960 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8961 if (!mbox)
8962 return;
8963 lpfc_linkdown(phba);
8964 lpfc_init_link(phba, mbox,
8965 phba->cfg_topology,
8966 phba->cfg_link_speed);
8967 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8968 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8969 mbox->vport = vport;
8970 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8971 MBX_NOT_FINISHED)
8972 mempool_free(mbox, phba->mbox_mem_pool);
8973 }
8974
James Smarted957682007-06-17 19:56:37 -05008975 return;
8976
8977dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008978 if (vport && !(vport->load_flag & FC_UNLOADING))
Dick Kennedy372c1872020-06-30 14:50:00 -07008979 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04008980 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008981 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008982 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008983 phba->fc_stat.elsRcvDrop++;
8984}
8985
James Smarte59058c2008-08-24 21:49:00 -04008986/**
James Smart3621a712009-04-06 18:47:14 -04008987 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008988 * @phba: pointer to lpfc hba data structure.
8989 * @pring: pointer to a SLI ring.
8990 * @elsiocb: pointer to lpfc els iocb data structure.
8991 *
8992 * This routine is used to process an unsolicited event received from a SLI
8993 * (Service Level Interface) ring. The actual processing of the data buffer
8994 * associated with the unsolicited event is done by invoking the routine
8995 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8996 * SLI ring on which the unsolicited event was received.
8997 **/
James Smarted957682007-06-17 19:56:37 -05008998void
8999lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9000 struct lpfc_iocbq *elsiocb)
9001{
9002 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05009003 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05009004 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05009005 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9006 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05009007
James Smartd7c255b2008-08-24 21:50:00 -04009008 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05009009 elsiocb->context2 = NULL;
9010 elsiocb->context3 = NULL;
9011
9012 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9013 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9014 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04009015 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9016 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05009017 phba->fc_stat.NoRcvBuf++;
9018 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05009019 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04009020 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05009021 return;
9022 }
9023
James Smart92d7f7b2007-06-17 19:56:38 -05009024 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9025 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9026 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9027 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9028 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04009029 else
9030 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04009031 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05009032 }
James Smart6d368e52011-05-24 11:44:12 -04009033
James Smart7f5f3d02008-02-08 18:50:14 -05009034 /* If there are no BDEs associated
9035 * with this IOCB, there is nothing to do.
9036 */
James Smarted957682007-06-17 19:56:37 -05009037 if (icmd->ulpBdeCount == 0)
9038 return;
9039
James Smart7f5f3d02008-02-08 18:50:14 -05009040 /* type of ELS cmd is first 32bit word
9041 * in packet
9042 */
James Smarted957682007-06-17 19:56:37 -05009043 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05009044 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05009045 } else {
9046 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9047 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05009048 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9049 paddr);
James Smarted957682007-06-17 19:56:37 -05009050 }
9051
James Smart92d7f7b2007-06-17 19:56:38 -05009052 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9053 /*
9054 * The different unsolicited event handlers would tell us
9055 * if they are done with "mp" by setting context2 to NULL.
9056 */
dea31012005-04-17 16:05:31 -05009057 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009058 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9059 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05009060 }
James Smarted957682007-06-17 19:56:37 -05009061
9062 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05009063 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05009064 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009065 elsiocb->context2 = bdeBuf2;
9066 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05009067 /* free mp if we are done with it */
9068 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05009069 lpfc_in_buf_free(phba, elsiocb->context2);
9070 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05009071 }
dea31012005-04-17 16:05:31 -05009072 }
dea31012005-04-17 16:05:31 -05009073}
James Smart92d7f7b2007-06-17 19:56:38 -05009074
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08009075static void
James Smart4258e982015-12-16 18:11:58 -05009076lpfc_start_fdmi(struct lpfc_vport *vport)
9077{
James Smart4258e982015-12-16 18:11:58 -05009078 struct lpfc_nodelist *ndlp;
9079
9080 /* If this is the first time, allocate an ndlp and initialize
9081 * it. Otherwise, make sure the node is enabled and then do the
9082 * login.
9083 */
9084 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9085 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07009086 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05009087 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05009088 ndlp->nlp_type |= NLP_FABRIC;
9089 } else {
9090 return;
9091 }
9092 }
James Smart4258e982015-12-16 18:11:58 -05009093
James Smart307e3382020-11-15 11:26:30 -08009094 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9095 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart4258e982015-12-16 18:11:58 -05009096}
9097
James Smarte59058c2008-08-24 21:49:00 -04009098/**
James Smart3621a712009-04-06 18:47:14 -04009099 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04009100 * @phba: pointer to lpfc hba data structure.
9101 * @vport: pointer to a virtual N_Port data structure.
9102 *
9103 * This routine issues a Port Login (PLOGI) to the Name Server with
9104 * State Change Request (SCR) for a @vport. This routine will create an
9105 * ndlp for the Name Server associated to the @vport if such node does
9106 * not already exist. The PLOGI to Name Server is issued by invoking the
9107 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9108 * (FDMI) is configured to the @vport, a FDMI node will be created and
9109 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9110 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009111void
9112lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9113{
James Smart4258e982015-12-16 18:11:58 -05009114 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05009115 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9116
9117 /*
9118 * If lpfc_delay_discovery parameter is set and the clean address
9119 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9120 * discovery.
9121 */
9122 spin_lock_irq(shost->host_lock);
9123 if (vport->fc_flag & FC_DISC_DELAYED) {
9124 spin_unlock_irq(shost->host_lock);
Dick Kennedy372c1872020-06-30 14:50:00 -07009125 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart18775702013-04-17 20:19:25 -04009126 "3334 Delay fc port discovery for %d seconds\n",
9127 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05009128 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04009129 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05009130 return;
9131 }
9132 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009133
9134 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9135 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07009136 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05009137 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05009138 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05009139 lpfc_disc_start(vport);
9140 return;
9141 }
9142 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009143 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009144 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009145 return;
9146 }
James Smart92d7f7b2007-06-17 19:56:38 -05009147 }
James Smart307e3382020-11-15 11:26:30 -08009148
James Smart58da1ff2008-04-07 10:15:56 -04009149 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05009150
9151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9152
9153 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9154 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009155 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009156 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009157 return;
9158 }
9159
James Smart8663cbb2016-03-31 14:12:33 -07009160 if ((phba->cfg_enable_SmartSAN ||
9161 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9162 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05009163 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009164}
9165
James Smarte59058c2008-08-24 21:49:00 -04009166/**
James Smart3621a712009-04-06 18:47:14 -04009167 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04009168 * @phba: pointer to lpfc hba data structure.
9169 * @pmb: pointer to the driver internal queue element for mailbox command.
9170 *
9171 * This routine is the completion callback function to register new vport
9172 * mailbox command. If the new vport mailbox command completes successfully,
9173 * the fabric registration login shall be performed on physical port (the
9174 * new vport created is actually a physical port, with VPI 0) or the port
9175 * login to Name Server for State Change Request (SCR) will be performed
9176 * on virtual port (real virtual port, with VPI greater than 0).
9177 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009178static void
9179lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9180{
9181 struct lpfc_vport *vport = pmb->vport;
9182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart3e1f0712018-11-29 16:09:29 -08009183 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart04c68492009-05-22 14:52:52 -04009184 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05009185 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009186
James Smart09372822008-01-11 01:52:54 -05009187 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009188 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009189 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009190
9191 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009192 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart38b92ef2010-08-04 16:11:39 -04009193 "0915 Register VPI failed : Status: x%x"
9194 " upd bit: x%x \n", mb->mbxStatus,
9195 mb->un.varRegVpi.upd);
9196 if (phba->sli_rev == LPFC_SLI_REV4 &&
9197 mb->un.varRegVpi.upd)
9198 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05009199
9200 switch (mb->mbxStatus) {
9201 case 0x11: /* unsupported feature */
9202 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05009203 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05009204 /* giving up on vport registration */
9205 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9206 spin_lock_irq(shost->host_lock);
9207 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9208 spin_unlock_irq(shost->host_lock);
9209 lpfc_can_disctmo(vport);
9210 break;
James Smart695a8142010-01-26 23:08:03 -05009211 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9212 case 0x20:
9213 spin_lock_irq(shost->host_lock);
9214 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9215 spin_unlock_irq(shost->host_lock);
9216 lpfc_init_vpi(phba, pmb, vport->vpi);
9217 pmb->vport = vport;
9218 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9219 rc = lpfc_sli_issue_mbox(phba, pmb,
9220 MBX_NOWAIT);
9221 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009222 lpfc_printf_vlog(vport, KERN_ERR,
9223 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -05009224 "2732 Failed to issue INIT_VPI"
9225 " mailbox command\n");
9226 } else {
9227 lpfc_nlp_put(ndlp);
9228 return;
9229 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05009230 fallthrough;
James Smart92d7f7b2007-06-17 19:56:38 -05009231 default:
9232 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04009233 if (phba->sli_rev == LPFC_SLI_REV4)
9234 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009235 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05009236 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009237 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009238 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08009239 if (mb->mbxStatus == MBX_NOT_FINISHED)
9240 break;
9241 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9242 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9243 if (phba->sli_rev == LPFC_SLI_REV4)
9244 lpfc_issue_init_vfi(vport);
9245 else
9246 lpfc_initial_flogi(vport);
9247 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05009248 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08009249 }
James Smart92d7f7b2007-06-17 19:56:38 -05009250 break;
9251 }
James Smart92d7f7b2007-06-17 19:56:38 -05009252 } else {
James Smart695a8142010-01-26 23:08:03 -05009253 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05009254 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05009255 spin_unlock_irq(shost->host_lock);
9256 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04009257 if (phba->sli_rev < LPFC_SLI_REV4)
9258 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05009259 else {
James Smartfc2b9892010-02-26 14:15:29 -05009260 /*
9261 * If the physical port is instantiated using
9262 * FDISC, do not start vport discovery.
9263 */
9264 if (vport->port_state != LPFC_FDISC)
9265 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05009266 lpfc_do_scr_ns_plogi(phba, vport);
9267 }
9268 } else
James Smart92d7f7b2007-06-17 19:56:38 -05009269 lpfc_do_scr_ns_plogi(phba, vport);
9270 }
James Smart38b92ef2010-08-04 16:11:39 -04009271mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05009272 /* Now, we decrement the ndlp reference count held for this
9273 * callback function
9274 */
9275 lpfc_nlp_put(ndlp);
9276
James Smart92d7f7b2007-06-17 19:56:38 -05009277 mempool_free(pmb, phba->mbox_mem_pool);
9278 return;
9279}
9280
James Smarte59058c2008-08-24 21:49:00 -04009281/**
James Smart3621a712009-04-06 18:47:14 -04009282 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04009283 * @phba: pointer to lpfc hba data structure.
9284 * @vport: pointer to a host virtual N_Port data structure.
9285 * @ndlp: pointer to a node-list data structure.
9286 *
9287 * This routine registers the @vport as a new virtual port with a HBA.
9288 * It is done through a registering vpi mailbox command.
9289 **/
James Smart695a8142010-01-26 23:08:03 -05009290void
James Smart92d7f7b2007-06-17 19:56:38 -05009291lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9292 struct lpfc_nodelist *ndlp)
9293{
James Smart09372822008-01-11 01:52:54 -05009294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009295 LPFC_MBOXQ_t *mbox;
9296
9297 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9298 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04009299 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05009300 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08009301 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08009302 if (!mbox->ctx_ndlp) {
9303 mempool_free(mbox, phba->mbox_mem_pool);
9304 goto mbox_err_exit;
9305 }
9306
James Smart92d7f7b2007-06-17 19:56:38 -05009307 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04009308 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05009309 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05009310 /* mailbox command not success, decrement ndlp
9311 * reference count for this command
9312 */
9313 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009314 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05009315
Dick Kennedy372c1872020-06-30 14:50:00 -07009316 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009317 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05009318 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009319 }
9320 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -07009321 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009322 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05009323 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009324 }
James Smartfa4066b2008-01-11 01:53:27 -05009325 return;
9326
9327mbox_err_exit:
9328 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9329 spin_lock_irq(shost->host_lock);
9330 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9331 spin_unlock_irq(shost->host_lock);
9332 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009333}
9334
James Smarte59058c2008-08-24 21:49:00 -04009335/**
James Smart0c9ab6f2010-02-26 14:15:57 -05009336 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05009337 * @phba: pointer to lpfc hba data structure.
9338 *
James Smart0c9ab6f2010-02-26 14:15:57 -05009339 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05009340 **/
9341void
James Smart0c9ab6f2010-02-26 14:15:57 -05009342lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05009343{
9344 struct lpfc_vport **vports;
9345 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05009346 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05009347 int i;
James Smart695a8142010-01-26 23:08:03 -05009348
9349 /* Treat this failure as linkdown for all vports */
9350 link_state = phba->link_state;
9351 lpfc_linkdown(phba);
9352 phba->link_state = link_state;
9353
9354 vports = lpfc_create_vport_work_array(phba);
9355
9356 if (vports) {
9357 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9358 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9359 if (ndlp)
9360 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9361 lpfc_els_flush_cmd(vports[i]);
9362 }
9363 lpfc_destroy_vport_work_array(phba, vports);
9364 }
James Smart0c9ab6f2010-02-26 14:15:57 -05009365}
9366
9367/**
9368 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9369 * @phba: pointer to lpfc hba data structure.
9370 *
9371 * This routine abort all pending discovery commands and
9372 * start a timer to retry FLOGI for the physical port
9373 * discovery.
9374 **/
9375void
9376lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9377{
9378 struct lpfc_nodelist *ndlp;
9379 struct Scsi_Host *shost;
9380
9381 /* Cancel the all vports retry delay retry timers */
9382 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05009383
9384 /* If fabric require FLOGI, then re-instantiate physical login */
9385 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9386 if (!ndlp)
9387 return;
9388
James Smart695a8142010-01-26 23:08:03 -05009389 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04009390 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05009391 spin_lock_irq(shost->host_lock);
9392 ndlp->nlp_flag |= NLP_DELAY_TMO;
9393 spin_unlock_irq(shost->host_lock);
9394 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9395 phba->pport->port_state = LPFC_FLOGI;
9396 return;
9397}
9398
9399/**
9400 * lpfc_fabric_login_reqd - Check if FLOGI required.
9401 * @phba: pointer to lpfc hba data structure.
9402 * @cmdiocb: pointer to FDISC command iocb.
9403 * @rspiocb: pointer to FDISC response iocb.
9404 *
9405 * This routine checks if a FLOGI is reguired for FDISC
9406 * to succeed.
9407 **/
9408static int
9409lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9410 struct lpfc_iocbq *cmdiocb,
9411 struct lpfc_iocbq *rspiocb)
9412{
9413
9414 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9415 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9416 return 0;
9417 else
9418 return 1;
9419}
9420
9421/**
James Smart3621a712009-04-06 18:47:14 -04009422 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009423 * @phba: pointer to lpfc hba data structure.
9424 * @cmdiocb: pointer to lpfc command iocb data structure.
9425 * @rspiocb: pointer to lpfc response iocb data structure.
9426 *
9427 * This routine is the completion callback function to a Fabric Discover
9428 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9429 * single threaded, each FDISC completion callback function will reset
9430 * the discovery timer for all vports such that the timers will not get
9431 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9432 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9433 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9434 * assigned to the vport has been changed with the completion of the FDISC
9435 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9436 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9437 * routine is invoked to register new vport with the HBA. Otherwise, the
9438 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9439 * Server for State Change Request (SCR).
9440 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009441static void
9442lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9443 struct lpfc_iocbq *rspiocb)
9444{
9445 struct lpfc_vport *vport = cmdiocb->vport;
9446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9447 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9448 struct lpfc_nodelist *np;
9449 struct lpfc_nodelist *next_np;
9450 IOCB_t *irsp = &rspiocb->iocb;
9451 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05009452 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9453 struct serv_parm *sp;
9454 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05009455
James Smarte8b62012007-08-02 11:10:09 -04009456 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9457 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9458 irsp->ulpStatus, irsp->un.ulpWord[4],
9459 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05009460 /* Since all FDISCs are being single threaded, we
9461 * must reset the discovery timer for ALL vports
9462 * waiting to send FDISC when one completes.
9463 */
9464 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9465 lpfc_set_disctmo(piocb->vport);
9466 }
9467
James Smart858c9f62007-06-17 19:56:39 -05009468 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9469 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9470 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9471
James Smart92d7f7b2007-06-17 19:56:38 -05009472 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05009473
9474 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9475 lpfc_retry_pport_discovery(phba);
9476 goto out;
9477 }
9478
James Smart92d7f7b2007-06-17 19:56:38 -05009479 /* Check for retry */
9480 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9481 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009482 /* FDISC failed */
Dick Kennedy372c1872020-06-30 14:50:00 -07009483 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6b5151f2012-01-18 16:24:06 -05009484 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04009485 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04009486 goto fdisc_failed;
9487 }
James Smartd7c255b2008-08-24 21:50:00 -04009488 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05009489 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04009490 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04009491 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05009492 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04009493 vport->fc_flag |= FC_PUBLIC_LOOP;
9494 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009495
James Smartd7c255b2008-08-24 21:50:00 -04009496 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9497 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05009498 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04009499 if (!prsp)
9500 goto out;
James Smart92494142011-02-16 12:39:44 -05009501 sp = prsp->virt + sizeof(uint32_t);
9502 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9503 memcpy(&vport->fabric_portname, &sp->portName,
9504 sizeof(struct lpfc_name));
9505 memcpy(&vport->fabric_nodename, &sp->nodeName,
9506 sizeof(struct lpfc_name));
9507 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04009508 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9509 /* If our NportID changed, we need to ensure all
9510 * remaining NPORTs get unreg_login'ed so we can
9511 * issue unreg_vpi.
9512 */
9513 list_for_each_entry_safe(np, next_np,
9514 &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08009515 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
James Smartd7c255b2008-08-24 21:50:00 -04009516 !(np->nlp_flag & NLP_NPR_ADISC))
9517 continue;
James Smart09372822008-01-11 01:52:54 -05009518 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04009519 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05009520 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04009521 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05009522 }
James Smart78730cf2010-04-06 15:06:30 -04009523 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04009524
9525 if (phba->sli_rev == LPFC_SLI_REV4)
9526 lpfc_sli4_unreg_all_rpis(vport);
9527
James Smartd7c255b2008-08-24 21:50:00 -04009528 lpfc_mbx_unreg_vpi(vport);
9529 spin_lock_irq(shost->host_lock);
9530 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05009531 if (phba->sli_rev == LPFC_SLI_REV4)
9532 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04009533 else
9534 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04009535 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04009536 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9537 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9538 /*
9539 * Driver needs to re-reg VPI in order for f/w
9540 * to update the MAC address.
9541 */
9542 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04009543 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009544 }
9545
James Smartecfd03c2010-02-12 14:41:27 -05009546 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9547 lpfc_issue_init_vpi(vport);
9548 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04009549 lpfc_register_new_vport(phba, vport, ndlp);
9550 else
9551 lpfc_do_scr_ns_plogi(phba, vport);
9552 goto out;
9553fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -07009554 if (vport->fc_vport &&
9555 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -04009556 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04009557 /* Cancel discovery timer */
9558 lpfc_can_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009559out:
9560 lpfc_els_free_iocb(phba, cmdiocb);
James Smart4430f7f2020-11-15 11:26:31 -08009561 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009562}
9563
James Smarte59058c2008-08-24 21:49:00 -04009564/**
James Smart3621a712009-04-06 18:47:14 -04009565 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009566 * @vport: pointer to a virtual N_Port data structure.
9567 * @ndlp: pointer to a node-list data structure.
9568 * @retry: number of retries to the command IOCB.
9569 *
9570 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9571 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9572 * routine to issue the IOCB, which makes sure only one outstanding fabric
9573 * IOCB will be sent off HBA at any given time.
9574 *
9575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9577 * will be stored into the context1 field of the IOCB for the completion
9578 * callback function to the FDISC ELS command.
9579 *
9580 * Return code
9581 * 0 - Successfully issued fdisc iocb command
9582 * 1 - Failed to issue fdisc iocb command
9583 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009584static int
James Smart92d7f7b2007-06-17 19:56:38 -05009585lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9586 uint8_t retry)
9587{
9588 struct lpfc_hba *phba = vport->phba;
9589 IOCB_t *icmd;
9590 struct lpfc_iocbq *elsiocb;
9591 struct serv_parm *sp;
9592 uint8_t *pcmd;
9593 uint16_t cmdsize;
9594 int did = ndlp->nlp_DID;
9595 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009596
James Smart5ffc2662009-11-18 15:39:44 -05009597 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05009598 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009599 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9600 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9601 ELS_CMD_FDISC);
9602 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05009603 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07009604 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04009605 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009606 return 1;
9607 }
9608
9609 icmd = &elsiocb->iocb;
9610 icmd->un.elsreq64.myID = 0;
9611 icmd->un.elsreq64.fl = 1;
9612
James Smart73d91e52011-10-10 21:32:10 -04009613 /*
9614 * SLI3 ports require a different context type value than SLI4.
9615 * Catch SLI3 ports here and override the prep.
9616 */
9617 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04009618 icmd->ulpCt_h = 1;
9619 icmd->ulpCt_l = 0;
9620 }
James Smart92d7f7b2007-06-17 19:56:38 -05009621
9622 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9623 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9624 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9625 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9626 sp = (struct serv_parm *) pcmd;
9627 /* Setup CSPs accordingly for Fabric */
9628 sp->cmn.e_d_tov = 0;
9629 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05009630 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009631 sp->cls1.classValid = 0;
9632 sp->cls2.seqDelivery = 1;
9633 sp->cls3.seqDelivery = 1;
9634
9635 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9636 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9637 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9638 pcmd += sizeof(uint32_t); /* Port Name */
9639 memcpy(pcmd, &vport->fc_portname, 8);
9640 pcmd += sizeof(uint32_t); /* Node Name */
9641 pcmd += sizeof(uint32_t); /* Node Name */
9642 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -07009643 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -07009644 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05009645 lpfc_set_disctmo(vport);
9646
9647 phba->fc_stat.elsXmitFDISC++;
9648 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9649
James Smart858c9f62007-06-17 19:56:39 -05009650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9651 "Issue FDISC: did:x%x",
9652 did, 0, 0);
9653
James Smart4430f7f2020-11-15 11:26:31 -08009654 elsiocb->context1 = lpfc_nlp_get(ndlp);
9655 if (!elsiocb->context1)
9656 goto err_out;
9657
James Smart92d7f7b2007-06-17 19:56:38 -05009658 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9659 if (rc == IOCB_ERROR) {
James Smart4430f7f2020-11-15 11:26:31 -08009660 lpfc_nlp_put(ndlp);
9661 goto err_out;
James Smart92d7f7b2007-06-17 19:56:38 -05009662 }
James Smart4430f7f2020-11-15 11:26:31 -08009663
James Smart92d7f7b2007-06-17 19:56:38 -05009664 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05009665 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08009666
9667 err_out:
9668 lpfc_els_free_iocb(phba, elsiocb);
9669 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9670 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9671 "0256 Issue FDISC: Cannot send IOCB\n");
9672 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05009673}
9674
James Smarte59058c2008-08-24 21:49:00 -04009675/**
James Smart3621a712009-04-06 18:47:14 -04009676 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04009677 * @phba: pointer to lpfc hba data structure.
9678 * @cmdiocb: pointer to lpfc command iocb data structure.
9679 * @rspiocb: pointer to lpfc response iocb data structure.
9680 *
9681 * This routine is the completion callback function to the issuing of a LOGO
9682 * ELS command off a vport. It frees the command IOCB and then decrement the
9683 * reference count held on ndlp for this completion function, indicating that
9684 * the reference to the ndlp is no long needed. Note that the
9685 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9686 * callback function and an additional explicit ndlp reference decrementation
9687 * will trigger the actual release of the ndlp.
9688 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009689static void
9690lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9691 struct lpfc_iocbq *rspiocb)
9692{
9693 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05009694 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05009695 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04009696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05009697
James Smart9589b0622011-04-16 11:03:17 -04009698 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05009699 irsp = &rspiocb->iocb;
9700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9701 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9702 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05009703
James Smart4430f7f2020-11-15 11:26:31 -08009704 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009705 lpfc_els_free_iocb(phba, cmdiocb);
9706 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05009707
9708 /* Trigger the release of the ndlp after logo */
9709 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04009710
9711 /* NPIV LOGO completes to NPort <nlp_DID> */
9712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9713 "2928 NPIV LOGO completes to NPort x%x "
9714 "Data: x%x x%x x%x x%x\n",
9715 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9716 irsp->ulpTimeout, vport->num_disc_nodes);
9717
9718 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9719 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009720 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04009721 vport->fc_flag &= ~FC_FABRIC;
9722 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009723 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04009724 }
James Smart4430f7f2020-11-15 11:26:31 -08009725 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009726}
9727
James Smarte59058c2008-08-24 21:49:00 -04009728/**
James Smart3621a712009-04-06 18:47:14 -04009729 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04009730 * @vport: pointer to a virtual N_Port data structure.
9731 * @ndlp: pointer to a node-list data structure.
9732 *
9733 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9734 *
9735 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9736 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9737 * will be stored into the context1 field of the IOCB for the completion
9738 * callback function to the LOGO ELS command.
9739 *
9740 * Return codes
9741 * 0 - Successfully issued logo off the @vport
9742 * 1 - Failed to issue logo off the @vport
9743 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009744int
9745lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9746{
James Smart4430f7f2020-11-15 11:26:31 -08009747 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9749 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009750 struct lpfc_iocbq *elsiocb;
9751 uint8_t *pcmd;
9752 uint16_t cmdsize;
9753
9754 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9755 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9756 ELS_CMD_LOGO);
9757 if (!elsiocb)
9758 return 1;
9759
James Smart92d7f7b2007-06-17 19:56:38 -05009760 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9761 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9762 pcmd += sizeof(uint32_t);
9763
9764 /* Fill in LOGO payload */
9765 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9766 pcmd += sizeof(uint32_t);
9767 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9768
James Smart858c9f62007-06-17 19:56:39 -05009769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9770 "Issue LOGO npiv did:x%x flg:x%x",
9771 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9772
James Smart92d7f7b2007-06-17 19:56:38 -05009773 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9774 spin_lock_irq(shost->host_lock);
9775 ndlp->nlp_flag |= NLP_LOGO_SND;
9776 spin_unlock_irq(shost->host_lock);
James Smart4430f7f2020-11-15 11:26:31 -08009777 elsiocb->context1 = lpfc_nlp_get(ndlp);
9778 if (!elsiocb->context1)
9779 goto node_err;
9780 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9781 if (rc == IOCB_ERROR)
9782 goto io_err;
James Smart92d7f7b2007-06-17 19:56:38 -05009783 return 0;
James Smart4430f7f2020-11-15 11:26:31 -08009784
9785 io_err:
9786 lpfc_nlp_put(ndlp);
9787 node_err:
9788 spin_lock_irq(shost->host_lock);
9789 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9790 spin_unlock_irq(shost->host_lock);
9791 lpfc_els_free_iocb(phba, elsiocb);
9792 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05009793}
9794
James Smarte59058c2008-08-24 21:49:00 -04009795/**
James Smart3621a712009-04-06 18:47:14 -04009796 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
Lee Jonesa0e4a642020-07-23 13:24:07 +01009797 * @t: timer context used to obtain the lpfc hba.
James Smarte59058c2008-08-24 21:49:00 -04009798 *
9799 * This routine is invoked by the fabric iocb block timer after
9800 * timeout. It posts the fabric iocb block timeout event by setting the
9801 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9802 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9803 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9804 * posted event WORKER_FABRIC_BLOCK_TMO.
9805 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009806void
Kees Cookf22eb4d2017-09-06 20:24:26 -07009807lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -05009808{
Kees Cookf22eb4d2017-09-06 20:24:26 -07009809 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -05009810 unsigned long iflags;
9811 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04009812
James Smart92d7f7b2007-06-17 19:56:38 -05009813 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9814 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9815 if (!tmo_posted)
9816 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9817 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9818
James Smart5e9d9b82008-06-14 22:52:53 -04009819 if (!tmo_posted)
9820 lpfc_worker_wake_up(phba);
9821 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009822}
9823
James Smarte59058c2008-08-24 21:49:00 -04009824/**
James Smart3621a712009-04-06 18:47:14 -04009825 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04009826 * @phba: pointer to lpfc hba data structure.
9827 *
9828 * This routine issues one fabric iocb from the driver internal list to
9829 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9830 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9831 * remove one pending fabric iocb from the driver internal list and invokes
9832 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9833 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009834static void
9835lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9836{
9837 struct lpfc_iocbq *iocb;
9838 unsigned long iflags;
9839 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05009840 IOCB_t *cmd;
9841
9842repeat:
9843 iocb = NULL;
9844 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05009845 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05009846 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9847 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9848 list);
9849 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05009850 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05009851 atomic_inc(&phba->fabric_iocb_count);
9852 }
9853 spin_unlock_irqrestore(&phba->hbalock, iflags);
9854 if (iocb) {
9855 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9856 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9857 iocb->iocb_flag |= LPFC_IO_FABRIC;
9858
James Smart858c9f62007-06-17 19:56:39 -05009859 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9860 "Fabric sched1: ste:x%x",
9861 iocb->vport->port_state, 0, 0);
9862
James Smart3772a992009-05-22 14:50:54 -04009863 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009864
9865 if (ret == IOCB_ERROR) {
9866 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9867 iocb->fabric_iocb_cmpl = NULL;
9868 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9869 cmd = &iocb->iocb;
9870 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9871 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9872 iocb->iocb_cmpl(phba, iocb, iocb);
9873
9874 atomic_dec(&phba->fabric_iocb_count);
9875 goto repeat;
9876 }
9877 }
James Smart92d7f7b2007-06-17 19:56:38 -05009878}
9879
James Smarte59058c2008-08-24 21:49:00 -04009880/**
James Smart3621a712009-04-06 18:47:14 -04009881 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009882 * @phba: pointer to lpfc hba data structure.
9883 *
9884 * This routine unblocks the issuing fabric iocb command. The function
9885 * will clear the fabric iocb block bit and then invoke the routine
9886 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9887 * from the driver internal fabric iocb list.
9888 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009889void
9890lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9891{
9892 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9893
9894 lpfc_resume_fabric_iocbs(phba);
9895 return;
9896}
9897
James Smarte59058c2008-08-24 21:49:00 -04009898/**
James Smart3621a712009-04-06 18:47:14 -04009899 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009900 * @phba: pointer to lpfc hba data structure.
9901 *
9902 * This routine blocks the issuing fabric iocb for a specified amount of
9903 * time (currently 100 ms). This is done by set the fabric iocb block bit
9904 * and set up a timeout timer for 100ms. When the block bit is set, no more
9905 * fabric iocb will be issued out of the HBA.
9906 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009907static void
9908lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9909{
9910 int blocked;
9911
9912 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009913 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009914 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009915 mod_timer(&phba->fabric_block_timer,
9916 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009917
9918 return;
9919}
9920
James Smarte59058c2008-08-24 21:49:00 -04009921/**
James Smart3621a712009-04-06 18:47:14 -04009922 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009923 * @phba: pointer to lpfc hba data structure.
9924 * @cmdiocb: pointer to lpfc command iocb data structure.
9925 * @rspiocb: pointer to lpfc response iocb data structure.
9926 *
9927 * This routine is the callback function that is put to the fabric iocb's
9928 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9929 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9930 * function first restores and invokes the original iocb's callback function
9931 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9932 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9933 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009934static void
9935lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9936 struct lpfc_iocbq *rspiocb)
9937{
9938 struct ls_rjt stat;
9939
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309940 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009941
9942 switch (rspiocb->iocb.ulpStatus) {
9943 case IOSTAT_NPORT_RJT:
9944 case IOSTAT_FABRIC_RJT:
9945 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9946 lpfc_block_fabric_iocbs(phba);
9947 }
9948 break;
9949
9950 case IOSTAT_NPORT_BSY:
9951 case IOSTAT_FABRIC_BSY:
9952 lpfc_block_fabric_iocbs(phba);
9953 break;
9954
9955 case IOSTAT_LS_RJT:
9956 stat.un.lsRjtError =
9957 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9958 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9959 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9960 lpfc_block_fabric_iocbs(phba);
9961 break;
9962 }
9963
James Smarta0f2d3e2017-02-12 13:52:31 -08009964 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009965
9966 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9967 cmdiocb->fabric_iocb_cmpl = NULL;
9968 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9969 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9970
9971 atomic_dec(&phba->fabric_iocb_count);
9972 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009973 /* Post any pending iocbs to HBA */
9974 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009975 }
9976}
9977
James Smarte59058c2008-08-24 21:49:00 -04009978/**
James Smart3621a712009-04-06 18:47:14 -04009979 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009980 * @phba: pointer to lpfc hba data structure.
9981 * @iocb: pointer to lpfc command iocb data structure.
9982 *
9983 * This routine is used as the top-level API for issuing a fabric iocb command
9984 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9985 * function makes sure that only one fabric bound iocb will be outstanding at
9986 * any given time. As such, this function will first check to see whether there
9987 * is already an outstanding fabric iocb on the wire. If so, it will put the
9988 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9989 * issued later. Otherwise, it will issue the iocb on the wire and update the
9990 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9991 *
9992 * Note, this implementation has a potential sending out fabric IOCBs out of
9993 * order. The problem is caused by the construction of the "ready" boolen does
9994 * not include the condition that the internal fabric IOCB list is empty. As
9995 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9996 * ahead of the fabric IOCBs in the internal list.
9997 *
9998 * Return code
9999 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10000 * IOCB_ERROR - failed to issue fabric iocb
10001 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010010002static int
James Smart92d7f7b2007-06-17 19:56:38 -050010003lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10004{
10005 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -050010006 int ready;
10007 int ret;
10008
James Smarta0f2d3e2017-02-12 13:52:31 -080010009 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -050010010
10011 spin_lock_irqsave(&phba->hbalock, iflags);
10012 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10013 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10014
James Smart7f5f3d02008-02-08 18:50:14 -050010015 if (ready)
10016 /* Increment fabric iocb count to hold the position */
10017 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -050010018 spin_unlock_irqrestore(&phba->hbalock, iflags);
10019 if (ready) {
10020 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10021 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10022 iocb->iocb_flag |= LPFC_IO_FABRIC;
10023
James Smart858c9f62007-06-17 19:56:39 -050010024 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10025 "Fabric sched2: ste:x%x",
10026 iocb->vport->port_state, 0, 0);
10027
James Smart3772a992009-05-22 14:50:54 -040010028 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -050010029
10030 if (ret == IOCB_ERROR) {
10031 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10032 iocb->fabric_iocb_cmpl = NULL;
10033 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10034 atomic_dec(&phba->fabric_iocb_count);
10035 }
10036 } else {
10037 spin_lock_irqsave(&phba->hbalock, iflags);
10038 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10039 spin_unlock_irqrestore(&phba->hbalock, iflags);
10040 ret = IOCB_SUCCESS;
10041 }
10042 return ret;
10043}
10044
James Smarte59058c2008-08-24 21:49:00 -040010045/**
James Smart3621a712009-04-06 18:47:14 -040010046 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010047 * @vport: pointer to a virtual N_Port data structure.
10048 *
10049 * This routine aborts all the IOCBs associated with a @vport from the
10050 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10051 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10052 * list, removes each IOCB associated with the @vport off the list, set the
10053 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10054 * associated with the IOCB.
10055 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +010010056static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -050010057{
10058 LIST_HEAD(completions);
10059 struct lpfc_hba *phba = vport->phba;
10060 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -050010061
10062 spin_lock_irq(&phba->hbalock);
10063 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10064 list) {
10065
10066 if (piocb->vport != vport)
10067 continue;
10068
10069 list_move_tail(&piocb->list, &completions);
10070 }
10071 spin_unlock_irq(&phba->hbalock);
10072
James Smarta257bf92009-04-06 18:48:10 -040010073 /* Cancel all the IOCBs from the completions list */
10074 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10075 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010076}
10077
James Smarte59058c2008-08-24 21:49:00 -040010078/**
James Smart3621a712009-04-06 18:47:14 -040010079 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010080 * @ndlp: pointer to a node-list data structure.
10081 *
10082 * This routine aborts all the IOCBs associated with an @ndlp from the
10083 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10084 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10085 * list, removes each IOCB associated with the @ndlp off the list, set the
10086 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10087 * associated with the IOCB.
10088 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010089void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10090{
10091 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -040010092 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -050010093 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -080010094 struct lpfc_sli_ring *pring;
10095
10096 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -050010097
Dick Kennedy1234a6d2017-09-29 17:34:29 -070010098 if (unlikely(!pring))
10099 return;
10100
James Smart92d7f7b2007-06-17 19:56:38 -050010101 spin_lock_irq(&phba->hbalock);
10102 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10103 list) {
10104 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10105
10106 list_move_tail(&piocb->list, &completions);
10107 }
10108 }
10109 spin_unlock_irq(&phba->hbalock);
10110
James Smarta257bf92009-04-06 18:48:10 -040010111 /* Cancel all the IOCBs from the completions list */
10112 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10113 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010114}
10115
James Smarte59058c2008-08-24 21:49:00 -040010116/**
James Smart3621a712009-04-06 18:47:14 -040010117 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -040010118 * @phba: pointer to lpfc hba data structure.
10119 *
10120 * This routine aborts all the IOCBs currently on the driver internal
10121 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10122 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10123 * list, removes IOCBs off the list, set the status feild to
10124 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10125 * the IOCB.
10126 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010127void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10128{
10129 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -050010130
10131 spin_lock_irq(&phba->hbalock);
10132 list_splice_init(&phba->fabric_iocb_list, &completions);
10133 spin_unlock_irq(&phba->hbalock);
10134
James Smarta257bf92009-04-06 18:48:10 -040010135 /* Cancel all the IOCBs from the completions list */
10136 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10137 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010138}
James Smart6fb120a2009-05-22 14:52:59 -040010139
10140/**
James Smart1151e3e2011-02-16 12:39:35 -050010141 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10142 * @vport: pointer to lpfc vport data structure.
10143 *
10144 * This routine is invoked by the vport cleanup for deletions and the cleanup
10145 * for an ndlp on removal.
10146 **/
10147void
10148lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10149{
10150 struct lpfc_hba *phba = vport->phba;
10151 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10152 unsigned long iflag = 0;
10153
10154 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010155 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010156 list_for_each_entry_safe(sglq_entry, sglq_next,
10157 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
James Smart307e3382020-11-15 11:26:30 -080010158 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10159 lpfc_nlp_put(sglq_entry->ndlp);
James Smart1151e3e2011-02-16 12:39:35 -050010160 sglq_entry->ndlp = NULL;
James Smart307e3382020-11-15 11:26:30 -080010161 }
James Smart1151e3e2011-02-16 12:39:35 -050010162 }
James Smart895427b2017-02-12 13:52:30 -080010163 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010164 spin_unlock_irqrestore(&phba->hbalock, iflag);
10165 return;
10166}
10167
10168/**
James Smart6fb120a2009-05-22 14:52:59 -040010169 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10170 * @phba: pointer to lpfc hba data structure.
10171 * @axri: pointer to the els xri abort wcqe structure.
10172 *
10173 * This routine is invoked by the worker thread to process a SLI4 slow-path
10174 * ELS aborted xri.
10175 **/
10176void
10177lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10178 struct sli4_wcqe_xri_aborted *axri)
10179{
10180 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -050010181 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -040010182 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -050010183
James Smart6fb120a2009-05-22 14:52:59 -040010184 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10185 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -050010186 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -080010187 struct lpfc_sli_ring *pring;
10188
10189 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010190
James Smart0f65ff62010-02-26 14:14:23 -050010191 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010192 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010193 list_for_each_entry_safe(sglq_entry, sglq_next,
10194 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10195 if (sglq_entry->sli4_xritag == xri) {
10196 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -050010197 ndlp = sglq_entry->ndlp;
10198 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -040010199 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -080010200 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -050010201 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -080010202 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010203 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart307e3382020-11-15 11:26:30 -080010204
10205 if (ndlp) {
10206 lpfc_set_rrq_active(phba, ndlp,
10207 sglq_entry->sli4_lxritag,
10208 rxid, 1);
10209 lpfc_nlp_put(ndlp);
10210 }
James Smart589a52d2010-07-14 15:30:54 -040010211
10212 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -070010213 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -040010214 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010215 return;
10216 }
10217 }
James Smart895427b2017-02-12 13:52:30 -080010218 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010219 lxri = lpfc_sli4_xri_inrange(phba, xri);
10220 if (lxri == NO_XRI) {
10221 spin_unlock_irqrestore(&phba->hbalock, iflag);
10222 return;
10223 }
James Smart895427b2017-02-12 13:52:30 -080010224 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010225 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -050010226 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -080010227 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010228 spin_unlock_irqrestore(&phba->hbalock, iflag);
10229 return;
10230 }
10231 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -080010232 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010233 spin_unlock_irqrestore(&phba->hbalock, iflag);
10234 return;
James Smart6fb120a2009-05-22 14:52:59 -040010235}
James Smart086a3452012-08-14 14:25:21 -040010236
10237/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10238 * @vport: pointer to virtual port object.
10239 * @ndlp: nodelist pointer for the impacted node.
10240 *
10241 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10242 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10243 * the driver is required to send a LOGO to the remote node before it
10244 * attempts to recover its login to the remote node.
10245 */
10246void
10247lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10248 struct lpfc_nodelist *ndlp)
10249{
10250 struct Scsi_Host *shost;
10251 struct lpfc_hba *phba;
10252 unsigned long flags = 0;
10253
10254 shost = lpfc_shost_from_vport(vport);
10255 phba = vport->phba;
10256 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10257 lpfc_printf_log(phba, KERN_INFO,
10258 LOG_SLI, "3093 No rport recovery needed. "
10259 "rport in state 0x%x\n", ndlp->nlp_state);
10260 return;
10261 }
Dick Kennedy372c1872020-06-30 14:50:00 -070010262 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart086a3452012-08-14 14:25:21 -040010263 "3094 Start rport recovery on shost id 0x%x "
10264 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10265 "flags 0x%x\n",
10266 shost->host_no, ndlp->nlp_DID,
10267 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10268 ndlp->nlp_flag);
10269 /*
10270 * The rport is not responding. Remove the FCP-2 flag to prevent
10271 * an ADISC in the follow-up recovery code.
10272 */
10273 spin_lock_irqsave(shost->host_lock, flags);
10274 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart30e196c2018-10-23 13:41:03 -070010275 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
James Smart086a3452012-08-14 14:25:21 -040010276 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart30e196c2018-10-23 13:41:03 -070010277 lpfc_unreg_rpi(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -040010278}
10279