scsi: isci: Remove unnecessary struct declaration
[linux-block.git] / drivers / scsi / lpfc / lpfc_nportdisc.c
CommitLineData
128bddac 1/*******************************************************************
dea3101e 2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
67073c69 4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
4ae2ebde 5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
50611577 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
c44ce173 7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
c44ce173 9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 10 * *
11 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea3101e 22 *******************************************************************/
23
dea3101e 24#include <linux/blkdev.h>
25#include <linux/pci.h>
5a0e3ad6 26#include <linux/slab.h>
dea3101e 27#include <linux/interrupt.h>
28
91886523 29#include <scsi/scsi.h>
dea3101e 30#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
a0f2d3ef
JS
33#include <scsi/fc/fc_fs.h>
34
da0436e9 35#include "lpfc_hw4.h"
dea3101e 36#include "lpfc_hw.h"
37#include "lpfc_sli.h"
da0436e9 38#include "lpfc_sli4.h"
ea2151b4 39#include "lpfc_nl.h"
dea3101e 40#include "lpfc_disc.h"
dea3101e 41#include "lpfc.h"
a0f2d3ef
JS
42#include "lpfc_scsi.h"
43#include "lpfc_nvme.h"
dea3101e 44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
92d7f7b0 46#include "lpfc_vport.h"
858c9f6c 47#include "lpfc_debugfs.h"
dea3101e 48
49
50/* Called to verify a rcv'ed ADISC was intended for us. */
51static int
2e0fef85
JS
52lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
53 struct lpfc_name *nn, struct lpfc_name *pn)
dea3101e 54{
6b5151fd
JS
55 /* First, we MUST have a RPI registered */
56 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
57 return 0;
58
dea3101e 59 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
60 * table entry for that node.
61 */
2e0fef85 62 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
c9f8735b 63 return 0;
dea3101e 64
2e0fef85 65 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
c9f8735b 66 return 0;
dea3101e 67
68 /* we match, return success */
c9f8735b 69 return 1;
dea3101e 70}
71
dea3101e 72int
2e0fef85 73lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
341af102 74 struct serv_parm *sp, uint32_t class, int flogi)
dea3101e 75{
2e0fef85 76 volatile struct serv_parm *hsp = &vport->fc_sparam;
2fb70f79
JSEC
77 uint16_t hsp_value, ssp_value = 0;
78
79 /*
80 * The receive data field size and buffer-to-buffer receive data field
81 * size entries are 16 bits but are represented as two 8-bit fields in
82 * the driver data structure to account for rsvd bits and other control
83 * bits. Reconstruct and compare the fields as a 16-bit values before
84 * correcting the byte values.
85 */
dea3101e 86 if (sp->cls1.classValid) {
341af102
JS
87 if (!flogi) {
88 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
89 hsp->cls1.rcvDataSizeLsb);
90 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
91 sp->cls1.rcvDataSizeLsb);
92 if (!ssp_value)
93 goto bad_service_param;
94 if (ssp_value > hsp_value) {
95 sp->cls1.rcvDataSizeLsb =
96 hsp->cls1.rcvDataSizeLsb;
97 sp->cls1.rcvDataSizeMsb =
98 hsp->cls1.rcvDataSizeMsb;
99 }
2fb70f79 100 }
341af102 101 } else if (class == CLASS1)
92d7f7b0 102 goto bad_service_param;
dea3101e 103 if (sp->cls2.classValid) {
341af102
JS
104 if (!flogi) {
105 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
106 hsp->cls2.rcvDataSizeLsb);
107 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
108 sp->cls2.rcvDataSizeLsb);
109 if (!ssp_value)
110 goto bad_service_param;
111 if (ssp_value > hsp_value) {
112 sp->cls2.rcvDataSizeLsb =
113 hsp->cls2.rcvDataSizeLsb;
114 sp->cls2.rcvDataSizeMsb =
115 hsp->cls2.rcvDataSizeMsb;
116 }
2fb70f79 117 }
341af102 118 } else if (class == CLASS2)
92d7f7b0 119 goto bad_service_param;
dea3101e 120 if (sp->cls3.classValid) {
341af102
JS
121 if (!flogi) {
122 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
123 hsp->cls3.rcvDataSizeLsb);
124 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
125 sp->cls3.rcvDataSizeLsb);
126 if (!ssp_value)
127 goto bad_service_param;
128 if (ssp_value > hsp_value) {
129 sp->cls3.rcvDataSizeLsb =
130 hsp->cls3.rcvDataSizeLsb;
131 sp->cls3.rcvDataSizeMsb =
132 hsp->cls3.rcvDataSizeMsb;
133 }
2fb70f79 134 }
341af102 135 } else if (class == CLASS3)
92d7f7b0 136 goto bad_service_param;
dea3101e 137
2fb70f79
JSEC
138 /*
139 * Preserve the upper four bits of the MSB from the PLOGI response.
140 * These bits contain the Buffer-to-Buffer State Change Number
141 * from the target and need to be passed to the FW.
142 */
143 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
144 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
145 if (ssp_value > hsp_value) {
dea3101e 146 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
2fb70f79
JSEC
147 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
148 (hsp->cmn.bbRcvSizeMsb & 0x0F);
149 }
dea3101e 150
dea3101e 151 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
152 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
2fb70f79 153 return 1;
92d7f7b0 154bad_service_param:
372c187b 155 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
e8b62011
JS
156 "0207 Device %x "
157 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
158 "invalid service parameters. Ignoring device.\n",
159 ndlp->nlp_DID,
160 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
161 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
162 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
163 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
92d7f7b0 164 return 0;
dea3101e 165}
166
167static void *
2e0fef85 168lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
92d7f7b0 169 struct lpfc_iocbq *rspiocb)
dea3101e 170{
171 struct lpfc_dmabuf *pcmd, *prsp;
172 uint32_t *lp;
173 void *ptr = NULL;
174 IOCB_t *irsp;
175
176 irsp = &rspiocb->iocb;
177 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
178
179 /* For lpfc_els_abort, context2 could be zero'ed to delay
180 * freeing associated memory till after ABTS completes.
181 */
182 if (pcmd) {
183 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
184 list);
185 if (prsp) {
186 lp = (uint32_t *) prsp->virt;
187 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
188 }
2fe165b6 189 } else {
dea3101e 190 /* Force ulpStatus error since we are returning NULL ptr */
191 if (!(irsp->ulpStatus)) {
192 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
193 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
194 }
195 ptr = NULL;
196 }
c9f8735b 197 return ptr;
dea3101e 198}
199
200
2a9bf3d0 201
dea3101e 202/*
203 * Free resources / clean up outstanding I/Os
204 * associated with a LPFC_NODELIST entry. This
205 * routine effectively results in a "software abort".
206 */
7c9fdfb7 207void
2e0fef85 208lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea3101e 209{
2a9bf3d0 210 LIST_HEAD(abort_list);
895427bd 211 struct lpfc_sli_ring *pring;
dea3101e 212 struct lpfc_iocbq *iocb, *next_iocb;
dea3101e 213
895427bd
JS
214 pring = lpfc_phba_elsring(phba);
215
7c9fdfb7 216 /* In case of error recovery path, we might have a NULL pring here */
1234a6d5 217 if (unlikely(!pring))
7c9fdfb7
GP
218 return;
219
dea3101e 220 /* Abort outstanding I/O on NPort <nlp_DID> */
e8b62011 221 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
2a9bf3d0 222 "2819 Abort outstanding I/O on NPort x%x "
e8b62011
JS
223 "Data: x%x x%x x%x\n",
224 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
225 ndlp->nlp_rpi);
0976e1a6 226 /* Clean up all fabric IOs first.*/
92d7f7b0 227 lpfc_fabric_abort_nport(ndlp);
dea3101e 228
0976e1a6
JS
229 /*
230 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
231 * of all ELS IOs that need an ABTS. The IOs need to stay on the
232 * txcmplq so that the abort operation completes them successfully.
233 */
2e0fef85 234 spin_lock_irq(&phba->hbalock);
0976e1a6
JS
235 if (phba->sli_rev == LPFC_SLI_REV4)
236 spin_lock(&pring->ring_lock);
237 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
238 /* Add to abort_list on on NDLP match. */
2a9bf3d0
JS
239 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 list_add_tail(&iocb->dlist, &abort_list);
07951076 241 }
0976e1a6
JS
242 if (phba->sli_rev == LPFC_SLI_REV4)
243 spin_unlock(&pring->ring_lock);
2e0fef85 244 spin_unlock_irq(&phba->hbalock);
dea3101e 245
0976e1a6 246 /* Abort the targeted IOs and remove them from the abort list. */
2a9bf3d0
JS
247 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
248 spin_lock_irq(&phba->hbalock);
249 list_del_init(&iocb->dlist);
db7531d2 250 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
2a9bf3d0
JS
251 spin_unlock_irq(&phba->hbalock);
252 }
a22d73b6
JS
253 /* Make sure HBA is alive */
254 lpfc_issue_hb_tmo(phba);
2a9bf3d0 255
0976e1a6
JS
256 INIT_LIST_HEAD(&abort_list);
257
258 /* Now process the txq */
259 spin_lock_irq(&phba->hbalock);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_lock(&pring->ring_lock);
262
263 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
266 list_del_init(&iocb->list);
267 list_add_tail(&iocb->list, &abort_list);
268 }
269 }
270
271 if (phba->sli_rev == LPFC_SLI_REV4)
272 spin_unlock(&pring->ring_lock);
273 spin_unlock_irq(&phba->hbalock);
274
a257bf90 275 /* Cancel all the IOCBs from the completions list */
0976e1a6
JS
276 lpfc_sli_cancel_iocbs(phba, &abort_list,
277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
2534ba75 278
0d2b6b83 279 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
dea3101e 280}
281
14375305 282/* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
359e10f0 283 * @phba: pointer to lpfc hba data structure.
14375305 284 * @login_mbox: pointer to REG_RPI mailbox object
359e10f0 285 *
14375305 286 * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
359e10f0 287 */
f7cb0d09 288static void
14375305 289lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox)
359e10f0 290{
359e10f0
JS
291 struct lpfc_iocbq *save_iocb;
292 struct lpfc_nodelist *ndlp;
14375305
JS
293 MAILBOX_t *mb = &login_mbox->u.mb;
294
359e10f0
JS
295 int rc;
296
14375305 297 ndlp = login_mbox->ctx_ndlp;
359e10f0 298 save_iocb = login_mbox->context3;
359e10f0 299
14375305
JS
300 if (mb->mbxStatus == MBX_SUCCESS) {
301 /* Now that REG_RPI completed successfully,
302 * we can now proceed with sending the PLOGI ACC.
303 */
304 rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI,
305 save_iocb, ndlp, NULL);
306 if (rc) {
307 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
308 "4576 PLOGI ACC fails pt2pt discovery: "
309 "DID %x Data: %x\n", ndlp->nlp_DID, rc);
310 }
359e10f0
JS
311 }
312
14375305
JS
313 /* Now process the REG_RPI cmpl */
314 lpfc_mbx_cmpl_reg_login(phba, login_mbox);
315 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
be0709e4
JS
316 kfree(save_iocb);
317}
318
dea3101e 319static int
2e0fef85 320lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
92d7f7b0 321 struct lpfc_iocbq *cmdiocb)
dea3101e 322{
2e0fef85 323 struct lpfc_hba *phba = vport->phba;
dea3101e 324 struct lpfc_dmabuf *pcmd;
ed4afe74 325 uint64_t nlp_portwwn = 0;
dea3101e 326 uint32_t *lp;
327 IOCB_t *icmd;
328 struct serv_parm *sp;
d6de08cc 329 uint32_t ed_tov;
359e10f0
JS
330 LPFC_MBOXQ_t *link_mbox;
331 LPFC_MBOXQ_t *login_mbox;
332 struct lpfc_iocbq *save_iocb;
dea3101e 333 struct ls_rjt stat;
8c258641 334 uint32_t vid, flag;
14375305 335 int rc;
dea3101e 336
337 memset(&stat, 0, sizeof (struct ls_rjt));
dea3101e 338 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
339 lp = (uint32_t *) pcmd->virt;
340 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
a8adb832 341 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
372c187b 342 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
a8adb832
JS
343 "0140 PLOGI Reject: invalid nname\n");
344 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
345 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
346 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
347 NULL);
348 return 0;
349 }
350 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
372c187b 351 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
a8adb832
JS
352 "0141 PLOGI Reject: invalid pname\n");
353 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
354 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
355 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
356 NULL);
357 return 0;
358 }
ed4afe74
JS
359
360 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
341af102 361 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea3101e 362 /* Reject this request because invalid parameters */
363 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
364 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
858c9f6c
JS
365 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
366 NULL);
c9f8735b 367 return 0;
dea3101e 368 }
369 icmd = &cmdiocb->iocb;
370
371 /* PLOGI chkparm OK */
e8b62011 372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
e74c03c8
JS
373 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
374 "x%x x%x x%x\n",
e8b62011 375 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
e74c03c8
JS
376 ndlp->nlp_rpi, vport->port_state,
377 vport->fc_flag);
dea3101e 378
3de2a653 379 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea3101e 380 ndlp->nlp_fcp_info |= CLASS2;
ed957684 381 else
dea3101e 382 ndlp->nlp_fcp_info |= CLASS3;
2e0fef85 383
dea3101e 384 ndlp->nlp_class_sup = 0;
385 if (sp->cls1.classValid)
386 ndlp->nlp_class_sup |= FC_COS_CLASS1;
387 if (sp->cls2.classValid)
388 ndlp->nlp_class_sup |= FC_COS_CLASS2;
389 if (sp->cls3.classValid)
390 ndlp->nlp_class_sup |= FC_COS_CLASS3;
391 if (sp->cls4.classValid)
392 ndlp->nlp_class_sup |= FC_COS_CLASS4;
393 ndlp->nlp_maxframe =
394 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
ed4afe74 395 /* if already logged in, do implicit logout */
2fe165b6 396 switch (ndlp->nlp_state) {
dea3101e 397 case NLP_STE_NPR_NODE:
398 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
399 break;
df561f66 400 fallthrough;
dea3101e 401 case NLP_STE_REG_LOGIN_ISSUE:
402 case NLP_STE_PRLI_ISSUE:
403 case NLP_STE_UNMAPPED_NODE:
404 case NLP_STE_MAPPED_NODE:
1c5b12f7
JS
405 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
406 * For target mode, execute implicit logo.
407 * Fabric nodes go into NPR.
408 */
409 if (!(ndlp->nlp_type & NLP_FABRIC) &&
410 !(phba->nvmet_support)) {
ecf041fe
JS
411 /* Clear ndlp info, since follow up PRLI may have
412 * updated ndlp information
413 */
414 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
415 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
416 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
417 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
418 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
419
ed4afe74
JS
420 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
421 ndlp, NULL);
422 return 1;
423 }
424 if (nlp_portwwn != 0 &&
425 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
372c187b 426 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
ed4afe74
JS
427 "0143 PLOGI recv'd from DID: x%x "
428 "WWPN changed: old %llx new %llx\n",
429 ndlp->nlp_DID,
430 (unsigned long long)nlp_portwwn,
431 (unsigned long long)
432 wwn_to_u64(sp->portName.u.wwn));
433
4c2805aa
JS
434 /* Notify transport of connectivity loss to trigger cleanup. */
435 if (phba->nvmet_support &&
436 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
437 lpfc_nvmet_invalidate_host(phba, ndlp);
438
ed4afe74
JS
439 ndlp->nlp_prev_state = ndlp->nlp_state;
440 /* rport needs to be unregistered first */
441 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
442 break;
dea3101e 443 }
444
9de416ac
JS
445 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
446 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
447 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
ecf041fe 448 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
9de416ac
JS
449 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
450
359e10f0
JS
451 login_mbox = NULL;
452 link_mbox = NULL;
453 save_iocb = NULL;
454
939723a4 455 /* Check for Nport to NPort pt2pt protocol */
92d7f7b0
JS
456 if ((vport->fc_flag & FC_PT2PT) &&
457 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea3101e 458 /* rcv'ed PLOGI decides what our NPortId will be */
2e0fef85 459 vport->fc_myDID = icmd->un.rcvels.parmRo;
d6de08cc 460
9dd83f75
JS
461 /* If there is an outstanding FLOGI, abort it now.
462 * The remote NPort is not going to ACC our FLOGI
463 * if its already issuing a PLOGI for pt2pt mode.
464 * This indicates our FLOGI was dropped; however, we
465 * must have ACCed the remote NPorts FLOGI to us
466 * to make it here.
467 */
468 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
469 lpfc_els_abort_flogi(phba);
470
d6de08cc
JS
471 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
472 if (sp->cmn.edtovResolution) {
473 /* E_D_TOV ticks are in nanoseconds */
474 ed_tov = (phba->fc_edtov + 999999) / 1000000;
dea3101e 475 }
d6de08cc 476
939723a4 477 /*
d6de08cc
JS
478 * For pt-to-pt, use the larger EDTOV
479 * RATOV = 2 * EDTOV
939723a4 480 */
d6de08cc
JS
481 if (ed_tov > phba->fc_edtov)
482 phba->fc_edtov = ed_tov;
483 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
484
485 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
486
14375305
JS
487 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
488 * to account for updated TOV's / parameters
489 */
939723a4
JS
490 if (phba->sli_rev == LPFC_SLI_REV4)
491 lpfc_issue_reg_vfi(vport);
d6de08cc 492 else {
359e10f0
JS
493 link_mbox = mempool_alloc(phba->mbox_mem_pool,
494 GFP_KERNEL);
495 if (!link_mbox)
d6de08cc 496 goto out;
359e10f0 497 lpfc_config_link(phba, link_mbox);
14375305 498 link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
359e10f0
JS
499 link_mbox->vport = vport;
500 link_mbox->ctx_ndlp = ndlp;
501
14375305
JS
502 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
503 if (rc == MBX_NOT_FINISHED) {
504 mempool_free(link_mbox, phba->mbox_mem_pool);
d6de08cc 505 goto out;
14375305 506 }
d6de08cc 507 }
dea3101e 508
2e0fef85 509 lpfc_can_disctmo(vport);
dea3101e 510 }
d6de08cc 511
8c258641
JS
512 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
513 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
514 sp->cmn.valid_vendor_ver_level) {
515 vid = be32_to_cpu(sp->un.vv.vid);
516 flag = be32_to_cpu(sp->un.vv.flags);
517 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
518 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
519 }
520
359e10f0
JS
521 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
522 if (!login_mbox)
dea3101e 523 goto out;
524
14375305
JS
525 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
526 if (!save_iocb)
527 goto out;
528
529 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
530 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
531 sizeof(struct lpfc_iocbq));
532
6b5151fd 533 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
14375305 534 if (phba->sli_rev == LPFC_SLI_REV4)
6b5151fd
JS
535 lpfc_unreg_rpi(vport, ndlp);
536
14375305
JS
537 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
538 * always be deferring the ACC.
539 */
6fb120a7 540 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
359e10f0
JS
541 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
542 if (rc)
dea3101e 543 goto out;
dea3101e 544
359e10f0 545 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
359e10f0 546 login_mbox->vport = vport;
dea3101e 547
33ccf8d1
JS
548 /*
549 * If there is an outstanding PLOGI issued, abort it before
550 * sending ACC rsp for received PLOGI. If pending plogi
551 * is not canceled here, the plogi will be rejected by
552 * remote port and will be retried. On a configuration with
553 * single discovery thread, this will cause a huge delay in
554 * discovery. Also this will cause multiple state machines
555 * running in parallel for this node.
feff8b3d 556 * This only applies to a fabric environment.
33ccf8d1 557 */
feff8b3d
JS
558 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
559 (vport->fc_flag & FC_FABRIC)) {
33ccf8d1 560 /* software abort outstanding PLOGI */
07951076 561 lpfc_els_abort(phba, ndlp);
33ccf8d1
JS
562 }
563
858c9f6c 564 if ((vport->port_type == LPFC_NPIV_PORT &&
3de2a653 565 vport->cfg_restrict_login)) {
858c9f6c 566
be0709e4
JS
567 /* no deferred ACC */
568 kfree(save_iocb);
569
858c9f6c
JS
570 /* In order to preserve RPIs, we want to cleanup
571 * the default RPI the firmware created to rcv
572 * this ELS request. The only way to do this is
573 * to register, then unregister the RPI.
574 */
c6adba15 575 spin_lock_irq(&ndlp->lock);
14375305
JS
576 ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN |
577 NLP_RCV_PLOGI);
c6adba15 578 spin_unlock_irq(&ndlp->lock);
858c9f6c
JS
579 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
580 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
0a8a86fa 581 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
359e10f0 582 ndlp, login_mbox);
0a8a86fa 583 if (rc)
359e10f0
JS
584 mempool_free(login_mbox, phba->mbox_mem_pool);
585 return 1;
586 }
359e10f0 587
14375305
JS
588 /* So the order here should be:
589 * SLI3 pt2pt
590 * Issue CONFIG_LINK mbox
591 * CONFIG_LINK cmpl
592 * SLI4 pt2pt
593 * Issue REG_VFI mbox
594 * REG_VFI cmpl
595 * SLI4
596 * Issue UNREG RPI mbx
597 * UNREG RPI cmpl
598 * Issue REG_RPI mbox
599 * REG RPI cmpl
600 * Issue PLOGI ACC
601 * PLOGI ACC cmpl
602 */
603 login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
604 login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
605 login_mbox->context3 = save_iocb; /* For PLOGI ACC */
359e10f0 606
14375305
JS
607 spin_lock_irq(&ndlp->lock);
608 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
609 spin_unlock_irq(&ndlp->lock);
610
611 /* Start the ball rolling by issuing REG_LOGIN here */
612 rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
613 if (rc == MBX_NOT_FINISHED)
614 goto out;
615 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
359e10f0 616
c9f8735b 617 return 1;
dea3101e 618out:
be0709e4 619 kfree(save_iocb);
359e10f0
JS
620 if (login_mbox)
621 mempool_free(login_mbox, phba->mbox_mem_pool);
622
dea3101e 623 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
624 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
858c9f6c 625 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
c9f8735b 626 return 0;
dea3101e 627}
628
6b5151fd
JS
629/**
630 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
631 * @phba: pointer to lpfc hba data structure.
632 * @mboxq: pointer to mailbox object
633 *
634 * This routine is invoked to issue a completion to a rcv'ed
635 * ADISC or PDISC after the paused RPI has been resumed.
636 **/
637static void
638lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
639{
640 struct lpfc_vport *vport;
641 struct lpfc_iocbq *elsiocb;
642 struct lpfc_nodelist *ndlp;
643 uint32_t cmd;
644
3e1f0718
JS
645 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
646 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
6b5151fd
JS
647 vport = mboxq->vport;
648 cmd = elsiocb->drvrTimeout;
649
650 if (cmd == ELS_CMD_ADISC) {
651 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
652 } else {
653 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
654 ndlp, NULL);
655 }
656 kfree(elsiocb);
72859909 657 mempool_free(mboxq, phba->mbox_mem_pool);
6b5151fd
JS
658}
659
dea3101e 660static int
2e0fef85 661lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea3101e 662 struct lpfc_iocbq *cmdiocb)
663{
6b5151fd 664 struct lpfc_iocbq *elsiocb;
dea3101e 665 struct lpfc_dmabuf *pcmd;
2e0fef85
JS
666 struct serv_parm *sp;
667 struct lpfc_name *pnn, *ppn;
dea3101e 668 struct ls_rjt stat;
669 ADISC *ap;
670 IOCB_t *icmd;
671 uint32_t *lp;
672 uint32_t cmd;
673
674 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
675 lp = (uint32_t *) pcmd->virt;
676
677 cmd = *lp++;
678 if (cmd == ELS_CMD_ADISC) {
679 ap = (ADISC *) lp;
680 pnn = (struct lpfc_name *) & ap->nodeName;
681 ppn = (struct lpfc_name *) & ap->portName;
682 } else {
683 sp = (struct serv_parm *) lp;
684 pnn = (struct lpfc_name *) & sp->nodeName;
685 ppn = (struct lpfc_name *) & sp->portName;
686 }
687
688 icmd = &cmdiocb->iocb;
2e0fef85 689 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
6b5151fd
JS
690
691 /*
692 * As soon as we send ACC, the remote NPort can
693 * start sending us data. Thus, for SLI4 we must
694 * resume the RPI before the ACC goes out.
695 */
696 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
697 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
698 GFP_KERNEL);
699 if (elsiocb) {
700
701 /* Save info from cmd IOCB used in rsp */
702 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
703 sizeof(struct lpfc_iocbq));
704
705 /* Save the ELS cmd */
706 elsiocb->drvrTimeout = cmd;
707
708 lpfc_sli4_resume_rpi(ndlp,
709 lpfc_mbx_cmpl_resume_rpi, elsiocb);
710 goto out;
711 }
712 }
713
dea3101e 714 if (cmd == ELS_CMD_ADISC) {
2e0fef85 715 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
2fe165b6 716 } else {
6b5151fd
JS
717 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
718 ndlp, NULL);
dea3101e 719 }
6b5151fd 720out:
9806c984
DK
721 /* If we are authenticated, move to the proper state.
722 * It is possible an ADISC arrived and the remote nport
723 * is already in MAPPED or UNMAPPED state. Catch this
724 * condition and don't set the nlp_state again because
725 * it causes an unnecessary transport unregister/register.
726 */
727 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
728 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE)
729 lpfc_nlp_set_state(vport, ndlp,
730 NLP_STE_MAPPED_NODE);
731 }
6b5151fd 732
c9f8735b 733 return 1;
dea3101e 734 }
735 /* Reject this request because invalid parameters */
736 stat.un.b.lsRjtRsvd0 = 0;
737 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
738 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
739 stat.un.b.vendorUnique = 0;
858c9f6c 740 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea3101e 741
dea3101e 742 /* 1 sec timeout */
256ec0d0 743 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
dea3101e 744
c6adba15 745 spin_lock_irq(&ndlp->lock);
dea3101e 746 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 747 spin_unlock_irq(&ndlp->lock);
5024ab17
JW
748 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
749 ndlp->nlp_prev_state = ndlp->nlp_state;
2e0fef85 750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c9f8735b 751 return 0;
dea3101e 752}
753
754static int
2e0fef85
JS
755lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
756 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea3101e 757{
2e0fef85 758 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4b40c59e
JS
759 struct lpfc_hba *phba = vport->phba;
760 struct lpfc_vport **vports;
761 int i, active_vlink_present = 0 ;
2e0fef85
JS
762
763 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea3101e 764 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
765 * PLOGIs during LOGO storms from a device.
766 */
c6adba15 767 spin_lock_irq(&ndlp->lock);
dea3101e 768 ndlp->nlp_flag |= NLP_LOGO_ACC;
c6adba15 769 spin_unlock_irq(&ndlp->lock);
82d9a2a2 770 if (els_cmd == ELS_CMD_PRLO)
51ef4c26 771 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
82d9a2a2 772 else
51ef4c26 773 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4c2805aa
JS
774
775 /* Notify transport of connectivity loss to trigger cleanup. */
776 if (phba->nvmet_support &&
777 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
778 lpfc_nvmet_invalidate_host(phba, ndlp);
779
4b40c59e
JS
780 if (ndlp->nlp_DID == Fabric_DID) {
781 if (vport->port_state <= LPFC_FDISC)
782 goto out;
6fb120a7 783 lpfc_linkdown_port(vport);
6fb120a7 784 spin_lock_irq(shost->host_lock);
4b40c59e 785 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
6fb120a7 786 spin_unlock_irq(shost->host_lock);
4b40c59e
JS
787 vports = lpfc_create_vport_work_array(phba);
788 if (vports) {
789 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
790 i++) {
791 if ((!(vports[i]->fc_flag &
792 FC_VPORT_LOGO_RCVD)) &&
793 (vports[i]->port_state > LPFC_FDISC)) {
794 active_vlink_present = 1;
795 break;
796 }
797 }
798 lpfc_destroy_vport_work_array(phba, vports);
799 }
dea3101e 800
cc82355a
JS
801 /*
802 * Don't re-instantiate if vport is marked for deletion.
803 * If we are here first then vport_delete is going to wait
804 * for discovery to complete.
805 */
806 if (!(vport->load_flag & FC_UNLOADING) &&
807 active_vlink_present) {
4b40c59e
JS
808 /*
809 * If there are other active VLinks present,
810 * re-instantiate the Vlink using FDISC.
811 */
256ec0d0
JS
812 mod_timer(&ndlp->nlp_delayfunc,
813 jiffies + msecs_to_jiffies(1000));
c6adba15 814 spin_lock_irq(&ndlp->lock);
4b40c59e 815 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 816 spin_unlock_irq(&ndlp->lock);
4b40c59e
JS
817 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
818 vport->port_state = LPFC_FDISC;
819 } else {
820 spin_lock_irq(shost->host_lock);
821 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
822 spin_unlock_irq(shost->host_lock);
823 lpfc_retry_pport_discovery(phba);
824 }
6fb120a7
JS
825 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
826 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
bd4f5100
JS
827 (ndlp->nlp_type & NLP_NVME_TARGET) ||
828 (vport->fc_flag & FC_PT2PT))) ||
6fb120a7 829 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
bd4f5100
JS
830 /* Only try to re-login if this is NOT a Fabric Node
831 * AND the remote NPORT is a FCP/NVME Target or we
832 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
833 * case for LOGO as a response to ADISC behavior.
834 */
256ec0d0
JS
835 mod_timer(&ndlp->nlp_delayfunc,
836 jiffies + msecs_to_jiffies(1000 * 1));
c6adba15 837 spin_lock_irq(&ndlp->lock);
dea3101e 838 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 839 spin_unlock_irq(&ndlp->lock);
dea3101e 840
5024ab17 841 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
c9f8735b 842 }
4b40c59e 843out:
87af33fe
JS
844 ndlp->nlp_prev_state = ndlp->nlp_state;
845 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea3101e 846
c6adba15 847 spin_lock_irq(&ndlp->lock);
dea3101e 848 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c6adba15 849 spin_unlock_irq(&ndlp->lock);
dea3101e 850 /* The driver has to wait until the ACC completes before it continues
851 * processing the LOGO. The action will resume in
852 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
853 * unreg_login, the driver waits so the ACC does not get aborted.
854 */
c9f8735b 855 return 0;
dea3101e 856}
857
b95e29b7
JS
858static uint32_t
859lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
860 struct lpfc_nodelist *ndlp,
861 struct lpfc_iocbq *cmdiocb)
862{
863 struct ls_rjt stat;
864 uint32_t *payload;
865 uint32_t cmd;
866
867 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
868 cmd = *payload;
869 if (vport->phba->nvmet_support) {
870 /* Must be a NVME PRLI */
871 if (cmd == ELS_CMD_PRLI)
872 goto out;
873 } else {
874 /* Initiator mode. */
875 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
876 goto out;
877 }
878 return 1;
879out:
880 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
881 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
882 "state x%x flags x%x\n",
883 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
884 ndlp->nlp_flag);
885 memset(&stat, 0, sizeof(struct ls_rjt));
886 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
887 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
888 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
889 ndlp, NULL);
890 return 0;
891}
892
dea3101e 893static void
2e0fef85
JS
894lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
895 struct lpfc_iocbq *cmdiocb)
dea3101e 896{
a0f2d3ef 897 struct lpfc_hba *phba = vport->phba;
dea3101e 898 struct lpfc_dmabuf *pcmd;
899 uint32_t *lp;
900 PRLI *npr;
901 struct fc_rport *rport = ndlp->rport;
902 u32 roles;
903
904 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
905 lp = (uint32_t *) pcmd->virt;
906 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
907
a0f2d3ef
JS
908 if ((npr->prliType == PRLI_FCP_TYPE) ||
909 (npr->prliType == PRLI_NVME_TYPE)) {
910 if (npr->initiatorFunc) {
911 if (npr->prliType == PRLI_FCP_TYPE)
912 ndlp->nlp_type |= NLP_FCP_INITIATOR;
913 if (npr->prliType == PRLI_NVME_TYPE)
914 ndlp->nlp_type |= NLP_NVME_INITIATOR;
915 }
3cb01c57 916 if (npr->targetFunc) {
a0f2d3ef
JS
917 if (npr->prliType == PRLI_FCP_TYPE)
918 ndlp->nlp_type |= NLP_FCP_TARGET;
919 if (npr->prliType == PRLI_NVME_TYPE)
920 ndlp->nlp_type |= NLP_NVME_TARGET;
3cb01c57
JS
921 if (npr->writeXferRdyDis)
922 ndlp->nlp_flag |= NLP_FIRSTBURST;
923 }
0d8af096
JS
924 if (npr->Retry && ndlp->nlp_type &
925 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
dea3101e 926 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
8c258641 927
0d8af096
JS
928 if (npr->Retry && phba->nsler &&
929 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
930 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
931
932
8c258641
JS
933 /* If this driver is in nvme target mode, set the ndlp's fc4
934 * type to NVME provided the PRLI response claims NVME FC4
935 * type. Target mode does not issue gft_id so doesn't get
936 * the fc4 type set until now.
937 */
9de416ac 938 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
8c258641 939 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
9de416ac
JS
940 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
941 }
07aaefdf
JS
942
943 /* Fabric Controllers send FCP PRLI as an initiator but should
944 * not get recognized as FCP type and registered with transport.
945 */
946 if (npr->prliType == PRLI_FCP_TYPE &&
947 !(ndlp->nlp_type & NLP_FABRIC))
9de416ac 948 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
dea3101e 949 }
950 if (rport) {
951 /* We need to update the rport role values */
952 roles = FC_RPORT_ROLE_UNKNOWN;
953 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
954 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
955 if (ndlp->nlp_type & NLP_FCP_TARGET)
956 roles |= FC_RPORT_ROLE_FCP_TARGET;
858c9f6c
JS
957
958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
959 "rport rolechg: role:x%x did:x%x flg:x%x",
960 roles, ndlp->nlp_DID, ndlp->nlp_flag);
961
f6e84790 962 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
a0f2d3ef 963 fc_remote_port_rolechg(rport, roles);
dea3101e 964 }
965}
966
967static uint32_t
2e0fef85 968lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 969{
4042629e 970 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
c6adba15 971 spin_lock_irq(&ndlp->lock);
51ef4c26 972 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c6adba15 973 spin_unlock_irq(&ndlp->lock);
51ef4c26
JS
974 return 0;
975 }
976
1b32f6aa
JS
977 if (!(vport->fc_flag & FC_PT2PT)) {
978 /* Check config parameter use-adisc or FCP-2 */
0fd103cc 979 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
ffc95493 980 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
0fd103cc 981 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
c6adba15 982 spin_lock_irq(&ndlp->lock);
1b32f6aa 983 ndlp->nlp_flag |= NLP_NPR_ADISC;
c6adba15 984 spin_unlock_irq(&ndlp->lock);
1b32f6aa
JS
985 return 1;
986 }
92d7f7b0 987 }
30e196ca 988
c6adba15 989 spin_lock_irq(&ndlp->lock);
92d7f7b0 990 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c6adba15 991 spin_unlock_irq(&ndlp->lock);
92d7f7b0
JS
992 lpfc_unreg_rpi(vport, ndlp);
993 return 0;
dea3101e 994}
6d368e53 995
78730cfe 996/**
25985edc 997 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
78730cfe
JS
998 * @phba : Pointer to lpfc_hba structure.
999 * @vport: Pointer to lpfc_vport structure.
22f8c077 1000 * @ndlp: Pointer to lpfc_nodelist structure.
78730cfe
JS
1001 * @rpi : rpi to be release.
1002 *
1003 * This function will send a unreg_login mailbox command to the firmware
1004 * to release a rpi.
1005 **/
3999df75 1006static void
dea16bda
JS
1007lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1008 struct lpfc_nodelist *ndlp, uint16_t rpi)
78730cfe
JS
1009{
1010 LPFC_MBOXQ_t *pmb;
1011 int rc;
1012
dea16bda
JS
1013 /* If there is already an UNREG in progress for this ndlp,
1014 * no need to queue up another one.
1015 */
1016 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1017 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1018 "1435 release_rpi SKIP UNREG x%x on "
1019 "NPort x%x deferred x%x flg x%x "
32350664 1020 "Data: x%px\n",
dea16bda
JS
1021 ndlp->nlp_rpi, ndlp->nlp_DID,
1022 ndlp->nlp_defer_did,
1023 ndlp->nlp_flag, ndlp);
1024 return;
1025 }
1026
78730cfe
JS
1027 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1028 GFP_KERNEL);
1029 if (!pmb)
372c187b
DK
1030 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1031 "2796 mailbox memory allocation failed \n");
78730cfe
JS
1032 else {
1033 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1034 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
dea16bda 1035 pmb->vport = vport;
4430f7fd
JS
1036 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1037 if (!pmb->ctx_ndlp) {
1038 mempool_free(pmb, phba->mbox_mem_pool);
1039 return;
1040 }
dea16bda
JS
1041
1042 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1043 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1044 ndlp->nlp_flag |= NLP_UNREG_INP;
1045
1046 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1047 "1437 release_rpi UNREG x%x "
1048 "on NPort x%x flg x%x\n",
1049 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1050
78730cfe
JS
1051 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1052 if (rc == MBX_NOT_FINISHED)
1053 mempool_free(pmb, phba->mbox_mem_pool);
1054 }
1055}
dea3101e 1056
1057static uint32_t
2e0fef85
JS
1058lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1059 void *arg, uint32_t evt)
dea3101e 1060{
78730cfe
JS
1061 struct lpfc_hba *phba;
1062 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
78730cfe
JS
1063 uint16_t rpi;
1064
1065 phba = vport->phba;
1066 /* Release the RPI if reglogin completing */
1067 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1068 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1069 (!pmb->u.mb.mbxStatus)) {
78730cfe 1070 rpi = pmb->u.mb.un.varWords[0];
dea16bda 1071 lpfc_release_rpi(phba, vport, ndlp, rpi);
78730cfe 1072 }
372c187b 1073 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
e47c9093 1074 "0271 Illegal State Transition: node x%x "
e8b62011
JS
1075 "event x%x, state x%x Data: x%x x%x\n",
1076 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1077 ndlp->nlp_flag);
c9f8735b 1078 return ndlp->nlp_state;
dea3101e 1079}
1080
87af33fe
JS
1081static uint32_t
1082lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1083 void *arg, uint32_t evt)
1084{
1085 /* This transition is only legal if we previously
1086 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1087 * working on the same NPortID, do nothing for this thread
1088 * to stop it.
1089 */
1090 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
372c187b
DK
1091 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1092 "0272 Illegal State Transition: node x%x "
1093 "event x%x, state x%x Data: x%x x%x\n",
1094 ndlp->nlp_DID, evt, ndlp->nlp_state,
1095 ndlp->nlp_rpi, ndlp->nlp_flag);
87af33fe
JS
1096 }
1097 return ndlp->nlp_state;
1098}
1099
dea3101e 1100/* Start of Discovery State Machine routines */
1101
1102static uint32_t
2e0fef85
JS
1103lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1104 void *arg, uint32_t evt)
dea3101e 1105{
1106 struct lpfc_iocbq *cmdiocb;
1107
1108 cmdiocb = (struct lpfc_iocbq *) arg;
1109
2e0fef85 1110 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
c9f8735b 1111 return ndlp->nlp_state;
dea3101e 1112 }
c9f8735b 1113 return NLP_STE_FREED_NODE;
dea3101e 1114}
1115
1116static uint32_t
2e0fef85
JS
1117lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1118 void *arg, uint32_t evt)
dea3101e 1119{
2e0fef85 1120 lpfc_issue_els_logo(vport, ndlp, 0);
c9f8735b 1121 return ndlp->nlp_state;
dea3101e 1122}
1123
1124static uint32_t
2e0fef85
JS
1125lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1126 void *arg, uint32_t evt)
dea3101e 1127{
2e0fef85 1128 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1129
c6adba15 1130 spin_lock_irq(&ndlp->lock);
dea3101e 1131 ndlp->nlp_flag |= NLP_LOGO_ACC;
c6adba15 1132 spin_unlock_irq(&ndlp->lock);
51ef4c26 1133 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea3101e 1134
c9f8735b 1135 return ndlp->nlp_state;
dea3101e 1136}
1137
1138static uint32_t
2e0fef85
JS
1139lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1140 void *arg, uint32_t evt)
dea3101e 1141{
c9f8735b 1142 return NLP_STE_FREED_NODE;
dea3101e 1143}
1144
1145static uint32_t
2e0fef85
JS
1146lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1147 void *arg, uint32_t evt)
dea3101e 1148{
c9f8735b 1149 return NLP_STE_FREED_NODE;
dea3101e 1150}
1151
df9e1b59
JS
1152static uint32_t
1153lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1154 struct lpfc_nodelist *ndlp,
1155 void *arg, uint32_t evt)
1156{
1157 return ndlp->nlp_state;
1158}
1159
dea3101e 1160static uint32_t
2e0fef85 1161lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea3101e 1162 void *arg, uint32_t evt)
1163{
0d2b6b83 1164 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 1165 struct lpfc_hba *phba = vport->phba;
dea3101e 1166 struct lpfc_iocbq *cmdiocb = arg;
2e0fef85
JS
1167 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1168 uint32_t *lp = (uint32_t *) pcmd->virt;
1169 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea3101e 1170 struct ls_rjt stat;
1171 int port_cmp;
1172
dea3101e 1173 memset(&stat, 0, sizeof (struct ls_rjt));
1174
1175 /* For a PLOGI, we only accept if our portname is less
1176 * than the remote portname.
1177 */
1178 phba->fc_stat.elsLogiCol++;
2e0fef85 1179 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
92d7f7b0 1180 sizeof(struct lpfc_name));
dea3101e 1181
1182 if (port_cmp >= 0) {
1183 /* Reject this request because the remote node will accept
1184 ours */
1185 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1186 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
858c9f6c
JS
1187 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1188 NULL);
2fe165b6 1189 } else {
0d2b6b83
JS
1190 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1191 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1192 (vport->num_disc_nodes)) {
c6adba15 1193 spin_lock_irq(&ndlp->lock);
0d2b6b83 1194 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
c6adba15 1195 spin_unlock_irq(&ndlp->lock);
0d2b6b83
JS
1196 /* Check if there are more PLOGIs to be sent */
1197 lpfc_more_plogi(vport);
1198 if (vport->num_disc_nodes == 0) {
1199 spin_lock_irq(shost->host_lock);
1200 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1201 spin_unlock_irq(shost->host_lock);
1202 lpfc_can_disctmo(vport);
1203 lpfc_end_rscn(vport);
1204 }
1205 }
2e0fef85 1206 } /* If our portname was less */
dea3101e 1207
c9f8735b
JW
1208 return ndlp->nlp_state;
1209}
1210
92d7f7b0
JS
1211static uint32_t
1212lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1213 void *arg, uint32_t evt)
1214{
1215 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1216 struct ls_rjt stat;
1217
1218 memset(&stat, 0, sizeof (struct ls_rjt));
1219 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1220 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
858c9f6c 1221 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
92d7f7b0
JS
1222 return ndlp->nlp_state;
1223}
1224
c9f8735b 1225static uint32_t
2e0fef85
JS
1226lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1227 void *arg, uint32_t evt)
c9f8735b 1228{
2e0fef85 1229 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
c9f8735b 1230
faa832e9
JS
1231 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1232 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1233 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
92d7f7b0 1234 /* software abort outstanding PLOGI */
2e0fef85 1235 lpfc_els_abort(vport->phba, ndlp);
c9f8735b 1236
2e0fef85 1237 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1238 return ndlp->nlp_state;
dea3101e 1239}
1240
1241static uint32_t
2e0fef85
JS
1242lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1243 void *arg, uint32_t evt)
dea3101e 1244{
2e0fef85
JS
1245 struct lpfc_hba *phba = vport->phba;
1246 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1247
1248 /* software abort outstanding PLOGI */
07951076 1249 lpfc_els_abort(phba, ndlp);
dea3101e 1250
1251 if (evt == NLP_EVT_RCV_LOGO) {
51ef4c26 1252 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2fe165b6 1253 } else {
2e0fef85 1254 lpfc_issue_els_logo(vport, ndlp, 0);
dea3101e 1255 }
1256
2e0fef85 1257 /* Put ndlp in npr state set plogi timer for 1 sec */
256ec0d0 1258 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
c6adba15 1259 spin_lock_irq(&ndlp->lock);
5024ab17 1260 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 1261 spin_unlock_irq(&ndlp->lock);
5024ab17
JW
1262 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1263 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
2e0fef85 1264 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea3101e 1265
c9f8735b 1266 return ndlp->nlp_state;
dea3101e 1267}
1268
1269static uint32_t
2e0fef85
JS
1270lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1271 struct lpfc_nodelist *ndlp,
1272 void *arg,
dea3101e 1273 uint32_t evt)
1274{
2e0fef85
JS
1275 struct lpfc_hba *phba = vport->phba;
1276 struct lpfc_iocbq *cmdiocb, *rspiocb;
14691150 1277 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea3101e 1278 uint32_t *lp;
8c258641 1279 uint32_t vid, flag;
dea3101e 1280 IOCB_t *irsp;
1281 struct serv_parm *sp;
d6de08cc 1282 uint32_t ed_tov;
dea3101e 1283 LPFC_MBOXQ_t *mbox;
d6de08cc 1284 int rc;
dea3101e 1285
1286 cmdiocb = (struct lpfc_iocbq *) arg;
1287 rspiocb = cmdiocb->context_un.rsp_iocb;
1288
1289 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
5024ab17 1290 /* Recovery from PLOGI collision logic */
c9f8735b 1291 return ndlp->nlp_state;
dea3101e 1292 }
1293
1294 irsp = &rspiocb->iocb;
1295
1296 if (irsp->ulpStatus)
1297 goto out;
1298
1299 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1300
2e0fef85 1301 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
a2fc4aef
JS
1302 if (!prsp)
1303 goto out;
dea3101e 1304
2e0fef85 1305 lp = (uint32_t *) prsp->virt;
dea3101e 1306 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
58da1ffb
JS
1307
1308 /* Some switches have FDMI servers returning 0 for WWN */
1309 if ((ndlp->nlp_DID != FDMI_DID) &&
1310 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1311 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
372c187b 1312 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
a8adb832
JS
1313 "0142 PLOGI RSP: Invalid WWN.\n");
1314 goto out;
1315 }
341af102 1316 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea3101e 1317 goto out;
dea3101e 1318 /* PLOGI chkparm OK */
e8b62011
JS
1319 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1320 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1321 ndlp->nlp_DID, ndlp->nlp_state,
1322 ndlp->nlp_flag, ndlp->nlp_rpi);
3de2a653 1323 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea3101e 1324 ndlp->nlp_fcp_info |= CLASS2;
2e0fef85 1325 else
dea3101e 1326 ndlp->nlp_fcp_info |= CLASS3;
2e0fef85 1327
dea3101e 1328 ndlp->nlp_class_sup = 0;
1329 if (sp->cls1.classValid)
1330 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1331 if (sp->cls2.classValid)
1332 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1333 if (sp->cls3.classValid)
1334 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1335 if (sp->cls4.classValid)
1336 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1337 ndlp->nlp_maxframe =
2e0fef85 1338 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea3101e 1339
d6de08cc
JS
1340 if ((vport->fc_flag & FC_PT2PT) &&
1341 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1342 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1343 if (sp->cmn.edtovResolution) {
1344 /* E_D_TOV ticks are in nanoseconds */
1345 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1346 }
1347
8c258641
JS
1348 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1349 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1350 sp->cmn.valid_vendor_ver_level) {
1351 vid = be32_to_cpu(sp->un.vv.vid);
1352 flag = be32_to_cpu(sp->un.vv.flags);
1353 if ((vid == LPFC_VV_EMLX_ID) &&
1354 (flag & LPFC_VV_SUPPRESS_RSP))
1355 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1356 }
1357
d6de08cc
JS
1358 /*
1359 * Use the larger EDTOV
1360 * RATOV = 2 * EDTOV for pt-to-pt
1361 */
1362 if (ed_tov > phba->fc_edtov)
1363 phba->fc_edtov = ed_tov;
1364 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1365
1366 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1367
1368 /* Issue config_link / reg_vfi to account for updated TOV's */
1369 if (phba->sli_rev == LPFC_SLI_REV4) {
1370 lpfc_issue_reg_vfi(vport);
1371 } else {
01c73bbc
JS
1372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1373 if (!mbox) {
372c187b
DK
1374 lpfc_printf_vlog(vport, KERN_ERR,
1375 LOG_TRACE_EVENT,
01c73bbc
JS
1376 "0133 PLOGI: no memory "
1377 "for config_link "
1378 "Data: x%x x%x x%x x%x\n",
1379 ndlp->nlp_DID, ndlp->nlp_state,
1380 ndlp->nlp_flag, ndlp->nlp_rpi);
1381 goto out;
1382 }
1383
d6de08cc
JS
1384 lpfc_config_link(phba, mbox);
1385
1386 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1387 mbox->vport = vport;
1388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1389 if (rc == MBX_NOT_FINISHED) {
1390 mempool_free(mbox, phba->mbox_mem_pool);
1391 goto out;
1392 }
1393 }
92d7f7b0 1394 }
dea3101e 1395
2e0fef85
JS
1396 lpfc_unreg_rpi(vport, ndlp);
1397
01c73bbc
JS
1398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1399 if (!mbox) {
372c187b 1400 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
01c73bbc
JS
1401 "0018 PLOGI: no memory for reg_login "
1402 "Data: x%x x%x x%x x%x\n",
1403 ndlp->nlp_DID, ndlp->nlp_state,
1404 ndlp->nlp_flag, ndlp->nlp_rpi);
1405 goto out;
1406 }
1407
6fb120a7 1408 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
4042629e 1409 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
2fe165b6 1410 switch (ndlp->nlp_DID) {
dea3101e 1411 case NameServer_DID:
de0c5b32 1412 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea3101e 1413 break;
1414 case FDMI_DID:
de0c5b32 1415 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea3101e 1416 break;
1417 default:
ffc95493 1418 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
de0c5b32 1419 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea3101e 1420 }
4430f7fd 1421
3e1f0718 1422 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4430f7fd
JS
1423 if (!mbox->ctx_ndlp)
1424 goto out;
1425
2e0fef85 1426 mbox->vport = vport;
0b727fea 1427 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea3101e 1428 != MBX_NOT_FINISHED) {
2e0fef85
JS
1429 lpfc_nlp_set_state(vport, ndlp,
1430 NLP_STE_REG_LOGIN_ISSUE);
c9f8735b 1431 return ndlp->nlp_state;
dea3101e 1432 }
ffc95493
JS
1433 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1434 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
fa4066b6
JS
1435 /* decrement node reference count to the failed mbox
1436 * command
1437 */
329f9bc7 1438 lpfc_nlp_put(ndlp);
3e1f0718 1439 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
14691150
JS
1440 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1441 kfree(mp);
dea3101e 1442 mempool_free(mbox, phba->mbox_mem_pool);
92d7f7b0 1443
372c187b 1444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
e8b62011
JS
1445 "0134 PLOGI: cannot issue reg_login "
1446 "Data: x%x x%x x%x x%x\n",
1447 ndlp->nlp_DID, ndlp->nlp_state,
1448 ndlp->nlp_flag, ndlp->nlp_rpi);
dea3101e 1449 } else {
1450 mempool_free(mbox, phba->mbox_mem_pool);
92d7f7b0 1451
372c187b 1452 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
e8b62011
JS
1453 "0135 PLOGI: cannot format reg_login "
1454 "Data: x%x x%x x%x x%x\n",
1455 ndlp->nlp_DID, ndlp->nlp_state,
1456 ndlp->nlp_flag, ndlp->nlp_rpi);
dea3101e 1457 }
1458
1459
92d7f7b0
JS
1460out:
1461 if (ndlp->nlp_DID == NameServer_DID) {
1462 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
372c187b 1463 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
e8b62011 1464 "0261 Cannot Register NameServer login\n");
92d7f7b0
JS
1465 }
1466
8b455cf3
JS
1467 /*
1468 ** In case the node reference counter does not go to zero, ensure that
1469 ** the stale state for the node is not processed.
1470 */
1471
1472 ndlp->nlp_prev_state = ndlp->nlp_state;
1473 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c9f8735b 1474 return NLP_STE_FREED_NODE;
dea3101e 1475}
1476
0ff10d46
JS
1477static uint32_t
1478lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1479 void *arg, uint32_t evt)
1480{
1481 return ndlp->nlp_state;
1482}
1483
1484static uint32_t
1485lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1486 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1487{
78730cfe
JS
1488 struct lpfc_hba *phba;
1489 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1490 MAILBOX_t *mb = &pmb->u.mb;
1491 uint16_t rpi;
1492
1493 phba = vport->phba;
1494 /* Release the RPI */
1495 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1496 !mb->mbxStatus) {
1497 rpi = pmb->u.mb.un.varWords[0];
dea16bda 1498 lpfc_release_rpi(phba, vport, ndlp, rpi);
78730cfe 1499 }
0ff10d46
JS
1500 return ndlp->nlp_state;
1501}
1502
dea3101e 1503static uint32_t
2e0fef85
JS
1504lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1505 void *arg, uint32_t evt)
dea3101e 1506{
2e0fef85 1507 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 1508 spin_lock_irq(&ndlp->lock);
a0f9b48d 1509 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
c6adba15 1510 spin_unlock_irq(&ndlp->lock);
a0f9b48d 1511 return ndlp->nlp_state;
2e0fef85 1512 } else {
a0f9b48d 1513 /* software abort outstanding PLOGI */
2e0fef85 1514 lpfc_els_abort(vport->phba, ndlp);
dea3101e 1515
2e0fef85 1516 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1517 return NLP_STE_FREED_NODE;
1518 }
dea3101e 1519}
1520
1521static uint32_t
2e0fef85
JS
1522lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1523 struct lpfc_nodelist *ndlp,
1524 void *arg,
1525 uint32_t evt)
dea3101e 1526{
2e0fef85
JS
1527 struct lpfc_hba *phba = vport->phba;
1528
92d7f7b0
JS
1529 /* Don't do anything that will mess up processing of the
1530 * previous RSCN.
1531 */
1532 if (vport->fc_flag & FC_RSCN_DEFERRED)
1533 return ndlp->nlp_state;
1534
dea3101e 1535 /* software abort outstanding PLOGI */
07951076 1536 lpfc_els_abort(phba, ndlp);
dea3101e 1537
5024ab17 1538 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
2e0fef85 1539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 1540 spin_lock_irq(&ndlp->lock);
a0f9b48d 1541 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c6adba15 1542 spin_unlock_irq(&ndlp->lock);
dea3101e 1543
c9f8735b 1544 return ndlp->nlp_state;
dea3101e 1545}
1546
1547static uint32_t
2e0fef85
JS
1548lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1549 void *arg, uint32_t evt)
dea3101e 1550{
2e0fef85 1551 struct lpfc_hba *phba = vport->phba;
dea3101e 1552 struct lpfc_iocbq *cmdiocb;
1553
1554 /* software abort outstanding ADISC */
07951076 1555 lpfc_els_abort(phba, ndlp);
dea3101e 1556
1557 cmdiocb = (struct lpfc_iocbq *) arg;
1558
0d2b6b83
JS
1559 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1560 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 1561 spin_lock_irq(&ndlp->lock);
0d2b6b83 1562 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
c6adba15 1563 spin_unlock_irq(&ndlp->lock);
90160e01 1564 if (vport->num_disc_nodes)
0d2b6b83 1565 lpfc_more_adisc(vport);
0d2b6b83
JS
1566 }
1567 return ndlp->nlp_state;
1568 }
5024ab17 1569 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85
JS
1570 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1571 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea3101e 1572
c9f8735b 1573 return ndlp->nlp_state;
dea3101e 1574}
1575
1576static uint32_t
2e0fef85
JS
1577lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1578 void *arg, uint32_t evt)
dea3101e 1579{
2e0fef85 1580 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1581
b95e29b7
JS
1582 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1583 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1584 return ndlp->nlp_state;
dea3101e 1585}
1586
1587static uint32_t
2e0fef85
JS
1588lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1589 void *arg, uint32_t evt)
dea3101e 1590{
2e0fef85 1591 struct lpfc_hba *phba = vport->phba;
dea3101e 1592 struct lpfc_iocbq *cmdiocb;
1593
1594 cmdiocb = (struct lpfc_iocbq *) arg;
1595
1596 /* software abort outstanding ADISC */
07951076 1597 lpfc_els_abort(phba, ndlp);
dea3101e 1598
2e0fef85 1599 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1600 return ndlp->nlp_state;
dea3101e 1601}
1602
1603static uint32_t
2e0fef85
JS
1604lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1605 struct lpfc_nodelist *ndlp,
1606 void *arg, uint32_t evt)
dea3101e 1607{
1608 struct lpfc_iocbq *cmdiocb;
1609
1610 cmdiocb = (struct lpfc_iocbq *) arg;
1611
2e0fef85 1612 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1613 return ndlp->nlp_state;
dea3101e 1614}
1615
1616static uint32_t
2e0fef85
JS
1617lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1618 void *arg, uint32_t evt)
dea3101e 1619{
1620 struct lpfc_iocbq *cmdiocb;
1621
1622 cmdiocb = (struct lpfc_iocbq *) arg;
1623
1624 /* Treat like rcv logo */
2e0fef85 1625 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 1626 return ndlp->nlp_state;
dea3101e 1627}
1628
1629static uint32_t
2e0fef85
JS
1630lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1631 struct lpfc_nodelist *ndlp,
1632 void *arg, uint32_t evt)
dea3101e 1633{
2e0fef85 1634 struct lpfc_hba *phba = vport->phba;
dea3101e 1635 struct lpfc_iocbq *cmdiocb, *rspiocb;
1636 IOCB_t *irsp;
1637 ADISC *ap;
6fb120a7 1638 int rc;
dea3101e 1639
1640 cmdiocb = (struct lpfc_iocbq *) arg;
1641 rspiocb = cmdiocb->context_un.rsp_iocb;
1642
1643 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1644 irsp = &rspiocb->iocb;
1645
1646 if ((irsp->ulpStatus) ||
92d7f7b0 1647 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea3101e 1648 /* 1 sec timeout */
256ec0d0
JS
1649 mod_timer(&ndlp->nlp_delayfunc,
1650 jiffies + msecs_to_jiffies(1000));
c6adba15 1651 spin_lock_irq(&ndlp->lock);
dea3101e 1652 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 1653 spin_unlock_irq(&ndlp->lock);
5024ab17 1654 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 1655
2e0fef85
JS
1656 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1657 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea3101e 1658
5024ab17 1659 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85
JS
1660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1661 lpfc_unreg_rpi(vport, ndlp);
c9f8735b 1662 return ndlp->nlp_state;
dea3101e 1663 }
5024ab17 1664
6fb120a7 1665 if (phba->sli_rev == LPFC_SLI_REV4) {
6b5151fd 1666 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
6fb120a7
JS
1667 if (rc) {
1668 /* Stay in state and retry. */
1669 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1670 return ndlp->nlp_state;
1671 }
1672 }
1673
00081c5c
DK
1674 if (ndlp->nlp_type & NLP_FCP_TARGET)
1675 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1676
1677 if (ndlp->nlp_type & NLP_NVME_TARGET)
1678 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1679
1680 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
5024ab17 1681 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85 1682 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2501322e 1683 } else {
5024ab17 1684 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85 1685 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2501322e 1686 }
6fb120a7 1687
c9f8735b 1688 return ndlp->nlp_state;
dea3101e 1689}
1690
1691static uint32_t
2e0fef85
JS
1692lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1693 void *arg, uint32_t evt)
dea3101e 1694{
2e0fef85 1695 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 1696 spin_lock_irq(&ndlp->lock);
a0f9b48d 1697 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
c6adba15 1698 spin_unlock_irq(&ndlp->lock);
a0f9b48d 1699 return ndlp->nlp_state;
2e0fef85 1700 } else {
a0f9b48d 1701 /* software abort outstanding ADISC */
2e0fef85 1702 lpfc_els_abort(vport->phba, ndlp);
dea3101e 1703
2e0fef85 1704 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1705 return NLP_STE_FREED_NODE;
1706 }
dea3101e 1707}
1708
1709static uint32_t
2e0fef85
JS
1710lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1711 struct lpfc_nodelist *ndlp,
1712 void *arg,
1713 uint32_t evt)
dea3101e 1714{
2e0fef85
JS
1715 struct lpfc_hba *phba = vport->phba;
1716
92d7f7b0
JS
1717 /* Don't do anything that will mess up processing of the
1718 * previous RSCN.
1719 */
1720 if (vport->fc_flag & FC_RSCN_DEFERRED)
1721 return ndlp->nlp_state;
1722
dea3101e 1723 /* software abort outstanding ADISC */
07951076 1724 lpfc_els_abort(phba, ndlp);
dea3101e 1725
5024ab17 1726 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85 1727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 1728 spin_lock_irq(&ndlp->lock);
a0f9b48d 1729 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c6adba15 1730 spin_unlock_irq(&ndlp->lock);
92d7f7b0 1731 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 1732 return ndlp->nlp_state;
dea3101e 1733}
1734
1735static uint32_t
2e0fef85
JS
1736lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1737 struct lpfc_nodelist *ndlp,
1738 void *arg,
dea3101e 1739 uint32_t evt)
1740{
2e0fef85 1741 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1742
2e0fef85 1743 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 1744 return ndlp->nlp_state;
dea3101e 1745}
1746
1747static uint32_t
2e0fef85
JS
1748lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1749 struct lpfc_nodelist *ndlp,
1750 void *arg,
dea3101e 1751 uint32_t evt)
1752{
2e0fef85 1753 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
8c258641 1754 struct ls_rjt stat;
dea3101e 1755
b95e29b7
JS
1756 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1757 return ndlp->nlp_state;
1758 }
8c258641
JS
1759 if (vport->phba->nvmet_support) {
1760 /* NVME Target mode. Handle and respond to the PRLI and
1761 * transition to UNMAPPED provided the RPI has completed
1762 * registration.
1763 */
1764 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1765 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1766 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
8c258641
JS
1767 } else {
1768 /* RPI registration has not completed. Reject the PRLI
1769 * to prevent an illegal state transition when the
1770 * rpi registration does complete.
1771 */
8c258641 1772 memset(&stat, 0, sizeof(struct ls_rjt));
e06351a0
JS
1773 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1774 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
8c258641
JS
1775 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1776 ndlp, NULL);
9de416ac 1777 return ndlp->nlp_state;
8c258641
JS
1778 }
1779 } else {
1780 /* Initiator mode. */
1781 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1782 }
c9f8735b 1783 return ndlp->nlp_state;
dea3101e 1784}
1785
1786static uint32_t
2e0fef85
JS
1787lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1788 struct lpfc_nodelist *ndlp,
1789 void *arg,
dea3101e 1790 uint32_t evt)
1791{
2e0fef85
JS
1792 struct lpfc_hba *phba = vport->phba;
1793 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
7054a606
JS
1794 LPFC_MBOXQ_t *mb;
1795 LPFC_MBOXQ_t *nextmb;
1796 struct lpfc_dmabuf *mp;
57178b92 1797 struct lpfc_nodelist *ns_ndlp;
dea3101e 1798
1799 cmdiocb = (struct lpfc_iocbq *) arg;
1800
7054a606
JS
1801 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1802 if ((mb = phba->sli.mbox_active)) {
04c68496 1803 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
3e1f0718 1804 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
de96e9c5 1805 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
92d7f7b0 1806 lpfc_nlp_put(ndlp);
3e1f0718 1807 mb->ctx_ndlp = NULL;
7054a606
JS
1808 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1809 }
1810 }
1811
2e0fef85 1812 spin_lock_irq(&phba->hbalock);
7054a606 1813 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
04c68496 1814 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
3e1f0718
JS
1815 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1816 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
7054a606 1817 if (mp) {
98c9ea5c 1818 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
7054a606
JS
1819 kfree(mp);
1820 }
de96e9c5 1821 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
92d7f7b0 1822 lpfc_nlp_put(ndlp);
7054a606 1823 list_del(&mb->list);
5ffc266e 1824 phba->sli.mboxq_cnt--;
7054a606
JS
1825 mempool_free(mb, phba->mbox_mem_pool);
1826 }
1827 }
2e0fef85 1828 spin_unlock_irq(&phba->hbalock);
7054a606 1829
57178b92
JS
1830 /* software abort if any GID_FT is outstanding */
1831 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1832 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
307e3380 1833 if (ns_ndlp)
57178b92
JS
1834 lpfc_els_abort(phba, ns_ndlp);
1835 }
1836
2e0fef85 1837 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1838 return ndlp->nlp_state;
dea3101e 1839}
1840
1841static uint32_t
2e0fef85
JS
1842lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1843 struct lpfc_nodelist *ndlp,
1844 void *arg,
dea3101e 1845 uint32_t evt)
1846{
2e0fef85 1847 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1848
2e0fef85 1849 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1850 return ndlp->nlp_state;
dea3101e 1851}
1852
1853static uint32_t
2e0fef85
JS
1854lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1855 struct lpfc_nodelist *ndlp,
1856 void *arg,
dea3101e 1857 uint32_t evt)
1858{
1859 struct lpfc_iocbq *cmdiocb;
1860
1861 cmdiocb = (struct lpfc_iocbq *) arg;
51ef4c26 1862 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 1863 return ndlp->nlp_state;
dea3101e 1864}
1865
1866static uint32_t
2e0fef85
JS
1867lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1868 struct lpfc_nodelist *ndlp,
1869 void *arg,
1870 uint32_t evt)
dea3101e 1871{
a0f2d3ef 1872 struct lpfc_hba *phba = vport->phba;
2e0fef85 1873 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
04c68496 1874 MAILBOX_t *mb = &pmb->u.mb;
2e0fef85 1875 uint32_t did = mb->un.varWords[1];
dea3101e 1876
dea3101e 1877 if (mb->mbxStatus) {
1878 /* RegLogin failed */
372c187b
DK
1879 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1880 "0246 RegLogin failed Data: x%x x%x x%x x%x "
6d368e53
JS
1881 "x%x\n",
1882 did, mb->mbxStatus, vport->port_state,
1883 mb->un.varRegLogin.vpi,
1884 mb->un.varRegLogin.rpi);
d0e56dad
JS
1885 /*
1886 * If RegLogin failed due to lack of HBA resources do not
1887 * retry discovery.
1888 */
1889 if (mb->mbxStatus == MBXERR_RPI_FULL) {
87af33fe
JS
1890 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1891 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
d0e56dad
JS
1892 return ndlp->nlp_state;
1893 }
1894
2e0fef85 1895 /* Put ndlp in npr state set plogi timer for 1 sec */
256ec0d0
JS
1896 mod_timer(&ndlp->nlp_delayfunc,
1897 jiffies + msecs_to_jiffies(1000 * 1));
c6adba15 1898 spin_lock_irq(&ndlp->lock);
dea3101e 1899 ndlp->nlp_flag |= NLP_DELAY_TMO;
c6adba15 1900 spin_unlock_irq(&ndlp->lock);
5024ab17 1901 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 1902
2e0fef85 1903 lpfc_issue_els_logo(vport, ndlp, 0);
5024ab17 1904 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85 1905 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c9f8735b 1906 return ndlp->nlp_state;
dea3101e 1907 }
1908
6d368e53 1909 /* SLI4 ports have preallocated logical rpis. */
a0f2d3ef 1910 if (phba->sli_rev < LPFC_SLI_REV4)
6d368e53
JS
1911 ndlp->nlp_rpi = mb->un.varWords[0];
1912
4042629e 1913 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea3101e 1914
1915 /* Only if we are not a fabric nport do we issue PRLI */
a0f2d3ef
JS
1916 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1917 "3066 RegLogin Complete on x%x x%x x%x\n",
1918 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1919 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1920 (phba->nvmet_support == 0)) {
1921 /* The driver supports FCP and NVME concurrently. If the
1922 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1923 * know what PRLI to send yet. Figure that out now and
1924 * call PRLI depending on the outcome.
1925 */
1926 if (vport->fc_flag & FC_PT2PT) {
1927 /* If we are pt2pt, there is no Fabric to determine
1928 * the FC4 type of the remote nport. So if NVME
1929 * is configured try it.
1930 */
1931 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
f6e84790
JS
1932 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1933 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
a0f2d3ef
JS
1934 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1935 /* We need to update the localport also */
01649561 1936 lpfc_nvme_update_localport(vport);
a0f2d3ef
JS
1937 }
1938
2877cbff
DK
1939 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1940 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1941
a0f2d3ef 1942 } else if (ndlp->nlp_fc4_type == 0) {
7ea92eb4
JS
1943 /* If we are only configured for FCP, the driver
1944 * should just issue PRLI for FCP. Otherwise issue
1945 * GFT_ID to determine if remote port supports NVME.
1946 */
f6e84790 1947 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
b27cbd55
BVA
1948 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
1949 ndlp->nlp_DID);
7ea92eb4
JS
1950 return ndlp->nlp_state;
1951 }
1952 ndlp->nlp_fc4_type = NLP_FC4_FCP;
a0f2d3ef
JS
1953 }
1954
5024ab17 1955 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85 1956 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
7f20c1cb
JS
1957 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
1958 lpfc_issue_els_logo(vport, ndlp, 0);
1959 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1960 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1961 }
dea3101e 1962 } else {
8c258641
JS
1963 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1964 phba->targetport->port_id = vport->fc_myDID;
1965
1966 /* Only Fabric ports should transition. NVME target
1967 * must complete PRLI.
1968 */
a0f2d3ef 1969 if (ndlp->nlp_type & NLP_FABRIC) {
07aaefdf 1970 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
a0f2d3ef
JS
1971 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1972 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1973 }
dea3101e 1974 }
c9f8735b 1975 return ndlp->nlp_state;
dea3101e 1976}
1977
1978static uint32_t
2e0fef85
JS
1979lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1980 struct lpfc_nodelist *ndlp,
1981 void *arg,
dea3101e 1982 uint32_t evt)
1983{
2e0fef85 1984 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 1985 spin_lock_irq(&ndlp->lock);
a0f9b48d 1986 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
c6adba15 1987 spin_unlock_irq(&ndlp->lock);
a0f9b48d 1988 return ndlp->nlp_state;
2e0fef85
JS
1989 } else {
1990 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1991 return NLP_STE_FREED_NODE;
1992 }
dea3101e 1993}
1994
1995static uint32_t
2e0fef85
JS
1996lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1997 struct lpfc_nodelist *ndlp,
1998 void *arg,
1999 uint32_t evt)
dea3101e 2000{
92d7f7b0
JS
2001 /* Don't do anything that will mess up processing of the
2002 * previous RSCN.
2003 */
2004 if (vport->fc_flag & FC_RSCN_DEFERRED)
2005 return ndlp->nlp_state;
2006
5024ab17 2007 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85 2008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 2009 spin_lock_irq(&ndlp->lock);
a0f2d3ef 2010
8c258641
JS
2011 /* If we are a target we won't immediately transition into PRLI,
2012 * so if REG_LOGIN already completed we don't need to ignore it.
2013 */
2014 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2015 !vport->phba->nvmet_support)
2016 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2017
a0f9b48d 2018 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c6adba15 2019 spin_unlock_irq(&ndlp->lock);
92d7f7b0 2020 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 2021 return ndlp->nlp_state;
dea3101e 2022}
2023
2024static uint32_t
2e0fef85
JS
2025lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2026 void *arg, uint32_t evt)
dea3101e 2027{
2028 struct lpfc_iocbq *cmdiocb;
2029
2030 cmdiocb = (struct lpfc_iocbq *) arg;
2031
2e0fef85 2032 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 2033 return ndlp->nlp_state;
dea3101e 2034}
2035
2036static uint32_t
2e0fef85
JS
2037lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2038 void *arg, uint32_t evt)
dea3101e 2039{
2e0fef85 2040 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2041
b95e29b7
JS
2042 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2043 return ndlp->nlp_state;
ecf041fe 2044 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2e0fef85 2045 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 2046 return ndlp->nlp_state;
dea3101e 2047}
2048
2049static uint32_t
2e0fef85
JS
2050lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2051 void *arg, uint32_t evt)
dea3101e 2052{
2e0fef85 2053 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2054
2055 /* Software abort outstanding PRLI before sending acc */
2e0fef85 2056 lpfc_els_abort(vport->phba, ndlp);
dea3101e 2057
2e0fef85 2058 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 2059 return ndlp->nlp_state;
dea3101e 2060}
2061
2062static uint32_t
2e0fef85
JS
2063lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2064 void *arg, uint32_t evt)
dea3101e 2065{
2e0fef85 2066 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2067
2e0fef85 2068 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 2069 return ndlp->nlp_state;
dea3101e 2070}
2071
2072/* This routine is envoked when we rcv a PRLO request from a nport
2073 * we are logged into. We should send back a PRLO rsp setting the
2074 * appropriate bits.
2075 * NEXT STATE = PRLI_ISSUE
2076 */
2077static uint32_t
2e0fef85
JS
2078lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2079 void *arg, uint32_t evt)
dea3101e 2080{
2e0fef85 2081 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2082
51ef4c26 2083 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 2084 return ndlp->nlp_state;
dea3101e 2085}
2086
2087static uint32_t
2e0fef85
JS
2088lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2089 void *arg, uint32_t evt)
dea3101e 2090{
2091 struct lpfc_iocbq *cmdiocb, *rspiocb;
2e0fef85 2092 struct lpfc_hba *phba = vport->phba;
dea3101e 2093 IOCB_t *irsp;
2094 PRLI *npr;
a0f2d3ef
JS
2095 struct lpfc_nvme_prli *nvpr;
2096 void *temp_ptr;
dea3101e 2097
2098 cmdiocb = (struct lpfc_iocbq *) arg;
2099 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f2d3ef
JS
2100
2101 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2102 * format is different so NULL the two PRLI types so that the
2103 * driver correctly gets the correct context.
2104 */
2105 npr = NULL;
2106 nvpr = NULL;
2107 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2108 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2109 npr = (PRLI *) temp_ptr;
2110 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2111 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
dea3101e 2112
2113 irsp = &rspiocb->iocb;
2114 if (irsp->ulpStatus) {
858c9f6c 2115 if ((vport->port_type == LPFC_NPIV_PORT) &&
3de2a653 2116 vport->cfg_restrict_login) {
858c9f6c
JS
2117 goto out;
2118 }
a0f2d3ef 2119
118c0415
JS
2120 /* Adjust the nlp_type accordingly if the PRLI failed */
2121 if (npr)
8db1c2b3 2122 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
118c0415
JS
2123 if (nvpr)
2124 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
8db1c2b3 2125
118c0415
JS
2126 /* We can't set the DSM state till BOTH PRLIs complete */
2127 goto out_err;
dea3101e 2128 }
2129
a0f2d3ef 2130 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
dea3101e 2131 (npr->prliType == PRLI_FCP_TYPE)) {
a0f2d3ef
JS
2132 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2133 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2134 npr->initiatorFunc,
2135 npr->targetFunc);
dea3101e 2136 if (npr->initiatorFunc)
2137 ndlp->nlp_type |= NLP_FCP_INITIATOR;
3cb01c57 2138 if (npr->targetFunc) {
dea3101e 2139 ndlp->nlp_type |= NLP_FCP_TARGET;
3cb01c57
JS
2140 if (npr->writeXferRdyDis)
2141 ndlp->nlp_flag |= NLP_FIRSTBURST;
2142 }
dea3101e 2143 if (npr->Retry)
2144 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
a0f2d3ef 2145
a0f2d3ef
JS
2146 } else if (nvpr &&
2147 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2148 PRLI_REQ_EXECUTED) &&
2149 (bf_get_be32(prli_type_code, nvpr) ==
2150 PRLI_NVME_TYPE)) {
2151
2152 /* Complete setting up the remote ndlp personality. */
2153 if (bf_get_be32(prli_init, nvpr))
2154 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2155
69641627
JS
2156 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2157 bf_get_be32(prli_conf, nvpr))
2158
0d8af096
JS
2159 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2160 else
2161 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2162
a0f2d3ef
JS
2163 /* Target driver cannot solicit NVME FB. */
2164 if (bf_get_be32(prli_tgt, nvpr)) {
dc53a618
JS
2165 /* Complete the nvme target roles. The transport
2166 * needs to know if the rport is capable of
2167 * discovery in addition to its role.
2168 */
a0f2d3ef 2169 ndlp->nlp_type |= NLP_NVME_TARGET;
dc53a618
JS
2170 if (bf_get_be32(prli_disc, nvpr))
2171 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
0709263a
JS
2172
2173 /*
2174 * If prli_fba is set, the Target supports FirstBurst.
2175 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2176 * otherwise it defines the actual size supported by
2177 * the NVME Target.
2178 */
a0f2d3ef 2179 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
a0f2d3ef
JS
2180 (phba->cfg_nvme_enable_fb) &&
2181 (!phba->nvmet_support)) {
2182 /* Both sides support FB. The target's first
2183 * burst size is a 512 byte encoded value.
2184 */
2185 ndlp->nlp_flag |= NLP_FIRSTBURST;
2186 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2187 nvpr);
0709263a
JS
2188
2189 /* Expressed in units of 512 bytes */
2190 if (ndlp->nvme_fb_size)
2191 ndlp->nvme_fb_size <<=
2192 LPFC_NVME_FB_SHIFT;
2193 else
2194 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
a0f2d3ef
JS
2195 }
2196 }
2197
a0f2d3ef
JS
2198 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2199 "6029 NVME PRLI Cmpl w1 x%08x "
2200 "w4 x%08x w5 x%08x flag x%x, "
2201 "fcp_info x%x nlp_type x%x\n",
2202 be32_to_cpu(nvpr->word1),
2203 be32_to_cpu(nvpr->word4),
2204 be32_to_cpu(nvpr->word5),
2205 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2206 ndlp->nlp_type);
dea3101e 2207 }
92d7f7b0
JS
2208 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2209 (vport->port_type == LPFC_NPIV_PORT) &&
3de2a653 2210 vport->cfg_restrict_login) {
858c9f6c 2211out:
c6adba15 2212 spin_lock_irq(&ndlp->lock);
92d7f7b0 2213 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
c6adba15 2214 spin_unlock_irq(&ndlp->lock);
92d7f7b0
JS
2215 lpfc_issue_els_logo(vport, ndlp, 0);
2216
2217 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
87af33fe 2218 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
92d7f7b0
JS
2219 return ndlp->nlp_state;
2220 }
dea3101e 2221
a0f2d3ef
JS
2222out_err:
2223 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2224 * are complete.
2225 */
2226 if (ndlp->fc4_prli_sent == 0) {
2227 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2228 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
9de416ac
JS
2230 else if (ndlp->nlp_type &
2231 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
a0f2d3ef
JS
2232 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2233 } else
2234 lpfc_printf_vlog(vport,
2235 KERN_INFO, LOG_ELS,
2236 "3067 PRLI's still outstanding "
2237 "on x%06x - count %d, Pend Node Mode "
2238 "transition...\n",
2239 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2240
c9f8735b 2241 return ndlp->nlp_state;
dea3101e 2242}
2243
2244/*! lpfc_device_rm_prli_issue
92d7f7b0
JS
2245 *
2246 * \pre
2247 * \post
2248 * \param phba
2249 * \param ndlp
2250 * \param arg
2251 * \param evt
2252 * \return uint32_t
2253 *
2254 * \b Description:
2255 * This routine is envoked when we a request to remove a nport we are in the
2256 * process of PRLIing. We should software abort outstanding prli, unreg
2257 * login, send a logout. We will change node state to UNUSED_NODE, put it
2258 * on plogi list so it can be freed when LOGO completes.
2259 *
2260 */
2261
dea3101e 2262static uint32_t
2e0fef85
JS
2263lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2264 void *arg, uint32_t evt)
dea3101e 2265{
2e0fef85 2266 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 2267 spin_lock_irq(&ndlp->lock);
a0f9b48d 2268 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
c6adba15 2269 spin_unlock_irq(&ndlp->lock);
a0f9b48d 2270 return ndlp->nlp_state;
2e0fef85 2271 } else {
a0f9b48d 2272 /* software abort outstanding PLOGI */
2e0fef85 2273 lpfc_els_abort(vport->phba, ndlp);
dea3101e 2274
2e0fef85 2275 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
2276 return NLP_STE_FREED_NODE;
2277 }
dea3101e 2278}
2279
2280
2281/*! lpfc_device_recov_prli_issue
92d7f7b0
JS
2282 *
2283 * \pre
2284 * \post
2285 * \param phba
2286 * \param ndlp
2287 * \param arg
2288 * \param evt
2289 * \return uint32_t
2290 *
2291 * \b Description:
2292 * The routine is envoked when the state of a device is unknown, like
2293 * during a link down. We should remove the nodelist entry from the
2294 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2295 * outstanding PRLI command, then free the node entry.
2296 */
dea3101e 2297static uint32_t
2e0fef85
JS
2298lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2299 struct lpfc_nodelist *ndlp,
2300 void *arg,
2301 uint32_t evt)
dea3101e 2302{
2e0fef85
JS
2303 struct lpfc_hba *phba = vport->phba;
2304
92d7f7b0
JS
2305 /* Don't do anything that will mess up processing of the
2306 * previous RSCN.
2307 */
2308 if (vport->fc_flag & FC_RSCN_DEFERRED)
2309 return ndlp->nlp_state;
2310
dea3101e 2311 /* software abort outstanding PRLI */
07951076 2312 lpfc_els_abort(phba, ndlp);
dea3101e 2313
5024ab17 2314 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2e0fef85 2315 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 2316 spin_lock_irq(&ndlp->lock);
a0f9b48d 2317 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c6adba15 2318 spin_unlock_irq(&ndlp->lock);
92d7f7b0 2319 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 2320 return ndlp->nlp_state;
dea3101e 2321}
2322
086a345f
JS
2323static uint32_t
2324lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2325 void *arg, uint32_t evt)
2326{
2327 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2328 struct ls_rjt stat;
2329
2330 memset(&stat, 0, sizeof(struct ls_rjt));
2331 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2332 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2333 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2334 return ndlp->nlp_state;
2335}
2336
2337static uint32_t
2338lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2339 void *arg, uint32_t evt)
2340{
2341 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2342 struct ls_rjt stat;
2343
2344 memset(&stat, 0, sizeof(struct ls_rjt));
2345 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2346 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2347 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2348 return ndlp->nlp_state;
2349}
2350
2351static uint32_t
2352lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2353 void *arg, uint32_t evt)
2354{
086a345f
JS
2355 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2356
c6adba15 2357 spin_lock_irq(&ndlp->lock);
7c5e518c 2358 ndlp->nlp_flag |= NLP_LOGO_ACC;
c6adba15 2359 spin_unlock_irq(&ndlp->lock);
086a345f
JS
2360 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2361 return ndlp->nlp_state;
2362}
2363
2364static uint32_t
2365lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2366 void *arg, uint32_t evt)
2367{
2368 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2369 struct ls_rjt stat;
2370
2371 memset(&stat, 0, sizeof(struct ls_rjt));
2372 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2373 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2374 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2375 return ndlp->nlp_state;
2376}
2377
2378static uint32_t
2379lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2380 void *arg, uint32_t evt)
2381{
2382 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2383 struct ls_rjt stat;
2384
2385 memset(&stat, 0, sizeof(struct ls_rjt));
2386 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2387 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2388 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2389 return ndlp->nlp_state;
2390}
2391
2392static uint32_t
2393lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2394 void *arg, uint32_t evt)
2395{
086a345f
JS
2396 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2397 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 2398 spin_lock_irq(&ndlp->lock);
086a345f 2399 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c6adba15 2400 spin_unlock_irq(&ndlp->lock);
086a345f
JS
2401 lpfc_disc_set_adisc(vport, ndlp);
2402 return ndlp->nlp_state;
2403}
2404
2405static uint32_t
2406lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2407 void *arg, uint32_t evt)
2408{
2409 /*
d2aa4876
DK
2410 * DevLoss has timed out and is calling for Device Remove.
2411 * In this case, abort the LOGO and cleanup the ndlp
086a345f 2412 */
d2aa4876
DK
2413
2414 lpfc_unreg_rpi(vport, ndlp);
2415 /* software abort outstanding PLOGI */
2416 lpfc_els_abort(vport->phba, ndlp);
2417 lpfc_drop_node(vport, ndlp);
2418 return NLP_STE_FREED_NODE;
086a345f
JS
2419}
2420
2421static uint32_t
2422lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2423 struct lpfc_nodelist *ndlp,
2424 void *arg, uint32_t evt)
2425{
2426 /*
2427 * Device Recovery events have no meaning for a node with a LOGO
2428 * outstanding. The LOGO has to complete first and handle the
2429 * node from that point.
2430 */
2431 return ndlp->nlp_state;
2432}
2433
dea3101e 2434static uint32_t
2e0fef85
JS
2435lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2436 void *arg, uint32_t evt)
dea3101e 2437{
2e0fef85 2438 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2439
2e0fef85 2440 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 2441 return ndlp->nlp_state;
dea3101e 2442}
2443
2444static uint32_t
2e0fef85
JS
2445lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2446 void *arg, uint32_t evt)
dea3101e 2447{
2e0fef85 2448 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2449
b95e29b7
JS
2450 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2451 return ndlp->nlp_state;
2452
2e0fef85
JS
2453 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2454 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 2455 return ndlp->nlp_state;
dea3101e 2456}
2457
2458static uint32_t
2e0fef85
JS
2459lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2460 void *arg, uint32_t evt)
dea3101e 2461{
2e0fef85 2462 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2463
2e0fef85 2464 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 2465 return ndlp->nlp_state;
dea3101e 2466}
2467
2468static uint32_t
2e0fef85
JS
2469lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2470 void *arg, uint32_t evt)
dea3101e 2471{
2e0fef85 2472 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2473
2e0fef85 2474 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 2475 return ndlp->nlp_state;
dea3101e 2476}
2477
2478static uint32_t
2e0fef85
JS
2479lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2480 void *arg, uint32_t evt)
dea3101e 2481{
2e0fef85 2482 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2483
51ef4c26 2484 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 2485 return ndlp->nlp_state;
dea3101e 2486}
2487
debbc1e2
JS
2488static uint32_t
2489lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2490 struct lpfc_nodelist *ndlp,
2491 void *arg,
2492 uint32_t evt)
2493{
2494 lpfc_drop_node(vport, ndlp);
2495 return NLP_STE_FREED_NODE;
2496}
2497
dea3101e 2498static uint32_t
2e0fef85
JS
2499lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2500 struct lpfc_nodelist *ndlp,
2501 void *arg,
2502 uint32_t evt)
dea3101e 2503{
5024ab17 2504 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2e0fef85 2505 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 2506 spin_lock_irq(&ndlp->lock);
a0f9b48d 2507 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
01a8aed6 2508 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
c6adba15 2509 spin_unlock_irq(&ndlp->lock);
2e0fef85 2510 lpfc_disc_set_adisc(vport, ndlp);
dea3101e 2511
c9f8735b 2512 return ndlp->nlp_state;
dea3101e 2513}
2514
2515static uint32_t
2e0fef85
JS
2516lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2517 void *arg, uint32_t evt)
dea3101e 2518{
2e0fef85 2519 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2520
2e0fef85 2521 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 2522 return ndlp->nlp_state;
dea3101e 2523}
2524
2525static uint32_t
2e0fef85
JS
2526lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2527 void *arg, uint32_t evt)
dea3101e 2528{
2e0fef85 2529 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2530
b95e29b7
JS
2531 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2532 return ndlp->nlp_state;
2e0fef85 2533 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 2534 return ndlp->nlp_state;
dea3101e 2535}
2536
2537static uint32_t
2e0fef85
JS
2538lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2539 void *arg, uint32_t evt)
dea3101e 2540{
2e0fef85 2541 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2542
2e0fef85 2543 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 2544 return ndlp->nlp_state;
dea3101e 2545}
2546
2547static uint32_t
2e0fef85
JS
2548lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2549 struct lpfc_nodelist *ndlp,
2550 void *arg, uint32_t evt)
dea3101e 2551{
2e0fef85 2552 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2553
2e0fef85 2554 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 2555 return ndlp->nlp_state;
dea3101e 2556}
2557
2558static uint32_t
2e0fef85
JS
2559lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2560 void *arg, uint32_t evt)
dea3101e 2561{
2e0fef85
JS
2562 struct lpfc_hba *phba = vport->phba;
2563 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2564
2565 /* flush the target */
895427bd 2566 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
51ef4c26 2567 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea3101e 2568
2569 /* Treat like rcv logo */
2e0fef85 2570 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 2571 return ndlp->nlp_state;
dea3101e 2572}
2573
2574static uint32_t
2e0fef85
JS
2575lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2576 struct lpfc_nodelist *ndlp,
2577 void *arg,
2578 uint32_t evt)
dea3101e 2579{
5024ab17 2580 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2e0fef85 2581 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c6adba15 2582 spin_lock_irq(&ndlp->lock);
a0f9b48d 2583 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
01a8aed6 2584 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
c6adba15 2585 spin_unlock_irq(&ndlp->lock);
2e0fef85 2586 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 2587 return ndlp->nlp_state;
dea3101e 2588}
2589
2590static uint32_t
2e0fef85
JS
2591lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2592 void *arg, uint32_t evt)
dea3101e 2593{
2e0fef85 2594 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2595
2596 /* Ignore PLOGI if we have an outstanding LOGO */
0d2b6b83 2597 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
c9f8735b 2598 return ndlp->nlp_state;
2e0fef85 2599 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
0d2b6b83 2600 lpfc_cancel_retry_delay_tmo(vport, ndlp);
c6adba15 2601 spin_lock_irq(&ndlp->lock);
0d2b6b83 2602 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
c6adba15 2603 spin_unlock_irq(&ndlp->lock);
0d2b6b83
JS
2604 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2605 /* send PLOGI immediately, move to PLOGI issue state */
2606 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2607 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2609 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2610 }
dea3101e 2611 }
c9f8735b 2612 return ndlp->nlp_state;
dea3101e 2613}
2614
2615static uint32_t
2e0fef85
JS
2616lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2617 void *arg, uint32_t evt)
dea3101e 2618{
2e0fef85
JS
2619 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2620 struct ls_rjt stat;
dea3101e 2621
2622 memset(&stat, 0, sizeof (struct ls_rjt));
2623 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2624 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
858c9f6c 2625 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea3101e 2626
2627 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2628 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
c6adba15 2629 spin_lock_irq(&ndlp->lock);
c9f8735b 2630 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5024ab17 2631 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
c6adba15 2632 spin_unlock_irq(&ndlp->lock);
2e0fef85
JS
2633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2634 lpfc_issue_els_adisc(vport, ndlp, 0);
dea3101e 2635 } else {
5024ab17 2636 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
2637 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2638 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea3101e 2639 }
2640 }
c9f8735b 2641 return ndlp->nlp_state;
dea3101e 2642}
2643
2644static uint32_t
2e0fef85
JS
2645lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2646 void *arg, uint32_t evt)
dea3101e 2647{
2e0fef85 2648 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2649
2e0fef85 2650 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 2651 return ndlp->nlp_state;
dea3101e 2652}
2653
2654static uint32_t
2e0fef85
JS
2655lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2656 void *arg, uint32_t evt)
dea3101e 2657{
2e0fef85 2658 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2659
2e0fef85 2660 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
33ccf8d1
JS
2661 /*
2662 * Do not start discovery if discovery is about to start
2663 * or discovery in progress for this node. Starting discovery
2664 * here will affect the counting of discovery threads.
2665 */
2fb9bd8b 2666 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
92d7f7b0 2667 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea3101e 2668 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
92d7f7b0 2669 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5024ab17 2670 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
2671 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2672 lpfc_issue_els_adisc(vport, ndlp, 0);
dea3101e 2673 } else {
5024ab17 2674 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
2675 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2676 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea3101e 2677 }
2678 }
c9f8735b 2679 return ndlp->nlp_state;
dea3101e 2680}
2681
2682static uint32_t
2e0fef85
JS
2683lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2684 void *arg, uint32_t evt)
dea3101e 2685{
2e0fef85 2686 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 2687
c6adba15 2688 spin_lock_irq(&ndlp->lock);
c9f8735b 2689 ndlp->nlp_flag |= NLP_LOGO_ACC;
c6adba15 2690 spin_unlock_irq(&ndlp->lock);
c9f8735b 2691
51ef4c26 2692 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea3101e 2693
2e0fef85 2694 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
256ec0d0
JS
2695 mod_timer(&ndlp->nlp_delayfunc,
2696 jiffies + msecs_to_jiffies(1000 * 1));
c6adba15 2697 spin_lock_irq(&ndlp->lock);
c9f8735b
JW
2698 ndlp->nlp_flag |= NLP_DELAY_TMO;
2699 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c6adba15 2700 spin_unlock_irq(&ndlp->lock);
5024ab17 2701 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
c9f8735b 2702 } else {
c6adba15 2703 spin_lock_irq(&ndlp->lock);
c9f8735b 2704 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c6adba15 2705 spin_unlock_irq(&ndlp->lock);
dea3101e 2706 }
c9f8735b
JW
2707 return ndlp->nlp_state;
2708}
dea3101e 2709
c9f8735b 2710static uint32_t
2e0fef85
JS
2711lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2712 void *arg, uint32_t evt)
c9f8735b
JW
2713{
2714 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 2715 IOCB_t *irsp;
c9f8735b
JW
2716
2717 cmdiocb = (struct lpfc_iocbq *) arg;
2718 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
2719
2720 irsp = &rspiocb->iocb;
2721 if (irsp->ulpStatus) {
a0f9b48d
JS
2722 return NLP_STE_FREED_NODE;
2723 }
c9f8735b
JW
2724 return ndlp->nlp_state;
2725}
2726
2727static uint32_t
2e0fef85
JS
2728lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2729 void *arg, uint32_t evt)
c9f8735b
JW
2730{
2731 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 2732 IOCB_t *irsp;
c9f8735b
JW
2733
2734 cmdiocb = (struct lpfc_iocbq *) arg;
2735 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
2736
2737 irsp = &rspiocb->iocb;
2738 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2e0fef85 2739 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
2740 return NLP_STE_FREED_NODE;
2741 }
c9f8735b 2742 return ndlp->nlp_state;
dea3101e 2743}
2744
2745static uint32_t
2e0fef85
JS
2746lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2747 void *arg, uint32_t evt)
dea3101e 2748{
d7c255b2 2749 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
086a345f
JS
2750
2751 /* For the fabric port just clear the fc flags. */
d7c255b2
JS
2752 if (ndlp->nlp_DID == Fabric_DID) {
2753 spin_lock_irq(shost->host_lock);
2754 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2755 spin_unlock_irq(shost->host_lock);
2756 }
2e0fef85 2757 lpfc_unreg_rpi(vport, ndlp);
c9f8735b
JW
2758 return ndlp->nlp_state;
2759}
2760
2761static uint32_t
2e0fef85
JS
2762lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2763 void *arg, uint32_t evt)
c9f8735b
JW
2764{
2765 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 2766 IOCB_t *irsp;
c9f8735b
JW
2767
2768 cmdiocb = (struct lpfc_iocbq *) arg;
2769 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
2770
2771 irsp = &rspiocb->iocb;
2772 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2e0fef85 2773 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
2774 return NLP_STE_FREED_NODE;
2775 }
c9f8735b 2776 return ndlp->nlp_state;
dea3101e 2777}
2778
2779static uint32_t
2e0fef85
JS
2780lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2781 struct lpfc_nodelist *ndlp,
2782 void *arg, uint32_t evt)
dea3101e 2783{
2e0fef85 2784 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
04c68496 2785 MAILBOX_t *mb = &pmb->u.mb;
dea3101e 2786
04c68496 2787 if (!mb->mbxStatus) {
6d368e53
JS
2788 /* SLI4 ports have preallocated logical rpis. */
2789 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2790 ndlp->nlp_rpi = mb->un.varWords[0];
4042629e 2791 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4b7789b7
JS
2792 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2793 lpfc_unreg_rpi(vport, ndlp);
2794 }
04c68496 2795 } else {
a0f9b48d 2796 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2e0fef85 2797 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
2798 return NLP_STE_FREED_NODE;
2799 }
2800 }
c9f8735b 2801 return ndlp->nlp_state;
dea3101e 2802}
2803
2804static uint32_t
2e0fef85
JS
2805lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2806 void *arg, uint32_t evt)
dea3101e 2807{
a0f9b48d 2808 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
c6adba15 2809 spin_lock_irq(&ndlp->lock);
a0f9b48d 2810 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
c6adba15 2811 spin_unlock_irq(&ndlp->lock);
a0f9b48d
JS
2812 return ndlp->nlp_state;
2813 }
2e0fef85 2814 lpfc_drop_node(vport, ndlp);
c9f8735b 2815 return NLP_STE_FREED_NODE;
dea3101e 2816}
2817
2818static uint32_t
2e0fef85
JS
2819lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2820 void *arg, uint32_t evt)
dea3101e 2821{
92d7f7b0
JS
2822 /* Don't do anything that will mess up processing of the
2823 * previous RSCN.
2824 */
2825 if (vport->fc_flag & FC_RSCN_DEFERRED)
2826 return ndlp->nlp_state;
2827
eaf15d5b 2828 lpfc_cancel_retry_delay_tmo(vport, ndlp);
c6adba15 2829 spin_lock_irq(&ndlp->lock);
a0f9b48d 2830 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
01a8aed6 2831 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
c6adba15 2832 spin_unlock_irq(&ndlp->lock);
c9f8735b 2833 return ndlp->nlp_state;
dea3101e 2834}
2835
2836
2837/* This next section defines the NPort Discovery State Machine */
2838
2839/* There are 4 different double linked lists nodelist entries can reside on.
2840 * The plogi list and adisc list are used when Link Up discovery or RSCN
2841 * processing is needed. Each list holds the nodes that we will send PLOGI
2842 * or ADISC on. These lists will keep track of what nodes will be effected
2843 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2844 * The unmapped_list will contain all nodes that we have successfully logged
2845 * into at the Fibre Channel level. The mapped_list will contain all nodes
2846 * that are mapped FCP targets.
2847 */
2848/*
2849 * The bind list is a list of undiscovered (potentially non-existent) nodes
2850 * that we have saved binding information on. This information is used when
2851 * nodes transition from the unmapped to the mapped list.
2852 */
2853/* For UNUSED_NODE state, the node has just been allocated .
2854 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2855 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2856 * and put on the unmapped list. For ADISC processing, the node is taken off
2857 * the ADISC list and placed on either the mapped or unmapped list (depending
2858 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2859 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2860 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2861 * node, the node is taken off the unmapped list. The binding list is checked
2862 * for a valid binding, or a binding is automatically assigned. If binding
2863 * assignment is unsuccessful, the node is left on the unmapped list. If
2864 * binding assignment is successful, the associated binding list entry (if
2865 * any) is removed, and the node is placed on the mapped list.
2866 */
2867/*
2868 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
c01f3208 2869 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea3101e 2870 * expire, all effected nodes will receive a DEVICE_RM event.
2871 */
2872/*
2873 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2874 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2875 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2876 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2877 * we will first process the ADISC list. 32 entries are processed initially and
2878 * ADISC is initited for each one. Completions / Events for each node are
2879 * funnelled thru the state machine. As each node finishes ADISC processing, it
2880 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2881 * waiting, and the ADISC list count is identically 0, then we are done. For
2882 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2883 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2884 * list. 32 entries are processed initially and PLOGI is initited for each one.
2885 * Completions / Events for each node are funnelled thru the state machine. As
2886 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2887 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2888 * indentically 0, then we are done. We have now completed discovery / RSCN
2889 * handling. Upon completion, ALL nodes should be on either the mapped or
2890 * unmapped lists.
2891 */
2892
2893static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2e0fef85 2894 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea3101e 2895 /* Action routine Event Current State */
2896 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2897 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2898 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2899 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2900 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2901 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2902 lpfc_disc_illegal, /* CMPL_PLOGI */
2903 lpfc_disc_illegal, /* CMPL_PRLI */
2904 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2905 lpfc_disc_illegal, /* CMPL_ADISC */
2906 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2907 lpfc_device_rm_unused_node, /* DEVICE_RM */
df9e1b59 2908 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
dea3101e 2909
2910 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
92d7f7b0 2911 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
c9f8735b 2912 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea3101e 2913 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2914 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2915 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2916 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2917 lpfc_disc_illegal, /* CMPL_PRLI */
0ff10d46 2918 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea3101e 2919 lpfc_disc_illegal, /* CMPL_ADISC */
0ff10d46 2920 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea3101e 2921 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2922 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2923
2924 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2925 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2926 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2927 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2928 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2929 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2930 lpfc_disc_illegal, /* CMPL_PLOGI */
2931 lpfc_disc_illegal, /* CMPL_PRLI */
2932 lpfc_disc_illegal, /* CMPL_LOGO */
2933 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2934 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2935 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2936 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2937
2938 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2939 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2940 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2941 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2942 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2943 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
87af33fe 2944 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea3101e 2945 lpfc_disc_illegal, /* CMPL_PRLI */
2946 lpfc_disc_illegal, /* CMPL_LOGO */
2947 lpfc_disc_illegal, /* CMPL_ADISC */
2948 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2949 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2950 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2951
2952 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2953 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2954 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2955 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2956 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2957 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
87af33fe 2958 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea3101e 2959 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2960 lpfc_disc_illegal, /* CMPL_LOGO */
2961 lpfc_disc_illegal, /* CMPL_ADISC */
2962 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2963 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2964 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2965
086a345f
JS
2966 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2967 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2968 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2969 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2970 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2971 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2972 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2973 lpfc_disc_illegal, /* CMPL_PRLI */
2974 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2975 lpfc_disc_illegal, /* CMPL_ADISC */
2976 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2977 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2978 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2979
dea3101e 2980 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2981 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2982 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2983 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2984 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2985 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2986 lpfc_disc_illegal, /* CMPL_PLOGI */
2987 lpfc_disc_illegal, /* CMPL_PRLI */
2988 lpfc_disc_illegal, /* CMPL_LOGO */
2989 lpfc_disc_illegal, /* CMPL_ADISC */
2990 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
debbc1e2 2991 lpfc_device_rm_unmap_node, /* DEVICE_RM */
dea3101e 2992 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2993
2994 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2995 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2996 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2997 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2998 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2999 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3000 lpfc_disc_illegal, /* CMPL_PLOGI */
3001 lpfc_disc_illegal, /* CMPL_PRLI */
3002 lpfc_disc_illegal, /* CMPL_LOGO */
3003 lpfc_disc_illegal, /* CMPL_ADISC */
3004 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3005 lpfc_disc_illegal, /* DEVICE_RM */
3006 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3007
3008 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3009 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3010 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3011 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3012 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3013 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
c9f8735b
JW
3014 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3015 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea3101e 3016 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
c9f8735b 3017 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea3101e 3018 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3019 lpfc_device_rm_npr_node, /* DEVICE_RM */
3020 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3021};
3022
3023int
2e0fef85
JS
3024lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3025 void *arg, uint32_t evt)
dea3101e 3026{
3027 uint32_t cur_state, rc;
2e0fef85 3028 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea3101e 3029 uint32_t);
e47c9093 3030 uint32_t got_ndlp = 0;
26d824ca 3031 uint32_t data1;
e47c9093
JS
3032
3033 if (lpfc_nlp_get(ndlp))
3034 got_ndlp = 1;
dea3101e 3035
dea3101e 3036 cur_state = ndlp->nlp_state;
3037
26d824ca
JS
3038 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3039 ((uint32_t)ndlp->nlp_type));
dea3101e 3040 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
e8b62011
JS
3041 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3042 "0211 DSM in event x%x on NPort x%x in "
dea16bda
JS
3043 "state %d rpi x%x Data: x%x x%x\n",
3044 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
26d824ca 3045 ndlp->nlp_flag, data1);
dea3101e 3046
858c9f6c
JS
3047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3048 "DSM in: evt:%d ste:%d did:x%x",
3049 evt, cur_state, ndlp->nlp_DID);
3050
dea3101e 3051 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2e0fef85 3052 rc = (func) (vport, ndlp, arg, evt);
dea3101e 3053
3054 /* DSM out state <rc> on NPort <nlp_DID> */
e47c9093 3055 if (got_ndlp) {
26d824ca
JS
3056 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3057 ((uint32_t)ndlp->nlp_type));
e47c9093 3058 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
dea16bda 3059 "0212 DSM out state %d on NPort x%x "
26d824ca
JS
3060 "rpi x%x Data: x%x x%x\n",
3061 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3062 data1);
dea3101e 3063
e47c9093
JS
3064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3065 "DSM out: ste:%d did:x%x flg:x%x",
3066 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3067 /* Decrement the ndlp reference count held for this function */
3068 lpfc_nlp_put(ndlp);
3069 } else {
3070 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
d7c255b2 3071 "0213 DSM out state %d on NPort free\n", rc);
858c9f6c 3072
e47c9093
JS
3073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3074 "DSM out: ste:%d did:x%x flg:x%x",
3075 rc, 0, 0);
3076 }
dea3101e 3077
c9f8735b 3078 return rc;
dea3101e 3079}