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