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