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