1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
43 #include "lpfc_nvme.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
50 /* Called to verify a rcv'ed ADISC was intended for us. */
52 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
53 struct lpfc_name *nn, struct lpfc_name *pn)
55 /* First, we MUST have a RPI registered */
56 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
59 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
60 * table entry for that node.
62 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
65 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
68 /* we match, return success */
73 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
74 struct serv_parm *sp, uint32_t class, int flogi)
76 volatile struct serv_parm *hsp = &vport->fc_sparam;
77 uint16_t hsp_value, ssp_value = 0;
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.
86 if (sp->cls1.classValid) {
88 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
89 hsp->cls1.rcvDataSizeLsb);
90 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
91 sp->cls1.rcvDataSizeLsb);
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;
101 } else if (class == CLASS1)
102 goto bad_service_param;
103 if (sp->cls2.classValid) {
105 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
106 hsp->cls2.rcvDataSizeLsb);
107 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
108 sp->cls2.rcvDataSizeLsb);
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;
118 } else if (class == CLASS2)
119 goto bad_service_param;
120 if (sp->cls3.classValid) {
122 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
123 hsp->cls3.rcvDataSizeLsb);
124 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
125 sp->cls3.rcvDataSizeLsb);
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;
135 } else if (class == CLASS3)
136 goto bad_service_param;
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.
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) {
146 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
147 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
148 (hsp->cmn.bbRcvSizeMsb & 0x0F);
151 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
152 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
155 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
157 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
158 "invalid service parameters. Ignoring device.\n",
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]);
168 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
169 struct lpfc_iocbq *rspiocb)
171 struct lpfc_dmabuf *pcmd, *prsp;
176 irsp = &rspiocb->iocb;
177 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
179 /* For lpfc_els_abort, context2 could be zero'ed to delay
180 * freeing associated memory till after ABTS completes.
183 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
186 lp = (uint32_t *) prsp->virt;
187 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
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;
203 * Free resources / clean up outstanding I/Os
204 * associated with a LPFC_NODELIST entry. This
205 * routine effectively results in a "software abort".
208 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
210 LIST_HEAD(abort_list);
211 struct lpfc_sli_ring *pring;
212 struct lpfc_iocbq *iocb, *next_iocb;
214 pring = lpfc_phba_elsring(phba);
216 /* In case of error recovery path, we might have a NULL pring here */
217 if (unlikely(!pring))
220 /* Abort outstanding I/O on NPort <nlp_DID> */
221 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
222 "2819 Abort outstanding I/O on NPort x%x "
223 "Data: x%x x%x x%x\n",
224 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
226 /* Clean up all fabric IOs first.*/
227 lpfc_fabric_abort_nport(ndlp);
230 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
231 * of all ELS IOs that need an ABTS. The IOs need to stay on the
232 * txcmplq so that the abort operation completes them successfully.
234 spin_lock_irq(&phba->hbalock);
235 if (phba->sli_rev == LPFC_SLI_REV4)
236 spin_lock(&pring->ring_lock);
237 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
238 /* Add to abort_list on on NDLP match. */
239 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 list_add_tail(&iocb->dlist, &abort_list);
242 if (phba->sli_rev == LPFC_SLI_REV4)
243 spin_unlock(&pring->ring_lock);
244 spin_unlock_irq(&phba->hbalock);
246 /* Abort the targeted IOs and remove them from the abort list. */
247 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
248 spin_lock_irq(&phba->hbalock);
249 list_del_init(&iocb->dlist);
250 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
251 spin_unlock_irq(&phba->hbalock);
253 /* Make sure HBA is alive */
254 lpfc_issue_hb_tmo(phba);
256 INIT_LIST_HEAD(&abort_list);
258 /* Now process the txq */
259 spin_lock_irq(&phba->hbalock);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_lock(&pring->ring_lock);
263 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
266 list_del_init(&iocb->list);
267 list_add_tail(&iocb->list, &abort_list);
271 if (phba->sli_rev == LPFC_SLI_REV4)
272 spin_unlock(&pring->ring_lock);
273 spin_unlock_irq(&phba->hbalock);
275 /* Cancel all the IOCBs from the completions list */
276 lpfc_sli_cancel_iocbs(phba, &abort_list,
277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
279 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
282 /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
283 * @phba: pointer to lpfc hba data structure.
284 * @login_mbox: pointer to REG_RPI mailbox object
286 * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
289 lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox)
291 struct lpfc_iocbq *save_iocb;
292 struct lpfc_nodelist *ndlp;
293 MAILBOX_t *mb = &login_mbox->u.mb;
297 ndlp = login_mbox->ctx_ndlp;
298 save_iocb = login_mbox->context3;
300 if (mb->mbxStatus == MBX_SUCCESS) {
301 /* Now that REG_RPI completed successfully,
302 * we can now proceed with sending the PLOGI ACC.
304 rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI,
305 save_iocb, ndlp, NULL);
307 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
308 "4576 PLOGI ACC fails pt2pt discovery: "
309 "DID %x Data: %x\n", ndlp->nlp_DID, rc);
313 /* Now process the REG_RPI cmpl */
314 lpfc_mbx_cmpl_reg_login(phba, login_mbox);
315 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
320 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
321 struct lpfc_iocbq *cmdiocb)
323 struct lpfc_hba *phba = vport->phba;
324 struct lpfc_dmabuf *pcmd;
325 struct lpfc_dmabuf *mp;
326 uint64_t nlp_portwwn = 0;
329 struct serv_parm *sp;
331 LPFC_MBOXQ_t *link_mbox;
332 LPFC_MBOXQ_t *login_mbox;
333 struct lpfc_iocbq *save_iocb;
338 memset(&stat, 0, sizeof (struct ls_rjt));
339 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
340 lp = (uint32_t *) pcmd->virt;
341 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
342 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
343 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
344 "0140 PLOGI Reject: invalid pname\n");
345 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
346 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
347 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
351 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
352 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
353 "0141 PLOGI Reject: invalid nname\n");
354 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
355 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
356 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
361 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
362 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
363 /* Reject this request because invalid parameters */
364 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
365 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
366 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
370 icmd = &cmdiocb->iocb;
372 /* PLOGI chkparm OK */
373 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
374 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
376 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
377 ndlp->nlp_rpi, vport->port_state,
380 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
381 ndlp->nlp_fcp_info |= CLASS2;
383 ndlp->nlp_fcp_info |= CLASS3;
385 ndlp->nlp_class_sup = 0;
386 if (sp->cls1.classValid)
387 ndlp->nlp_class_sup |= FC_COS_CLASS1;
388 if (sp->cls2.classValid)
389 ndlp->nlp_class_sup |= FC_COS_CLASS2;
390 if (sp->cls3.classValid)
391 ndlp->nlp_class_sup |= FC_COS_CLASS3;
392 if (sp->cls4.classValid)
393 ndlp->nlp_class_sup |= FC_COS_CLASS4;
395 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
396 /* if already logged in, do implicit logout */
397 switch (ndlp->nlp_state) {
398 case NLP_STE_NPR_NODE:
399 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
402 case NLP_STE_REG_LOGIN_ISSUE:
403 case NLP_STE_PRLI_ISSUE:
404 case NLP_STE_UNMAPPED_NODE:
405 case NLP_STE_MAPPED_NODE:
406 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
407 * For target mode, execute implicit logo.
408 * Fabric nodes go into NPR.
410 if (!(ndlp->nlp_type & NLP_FABRIC) &&
411 !(phba->nvmet_support)) {
412 /* Clear ndlp info, since follow up PRLI may have
413 * updated ndlp information
415 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
416 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
417 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
418 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
419 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
421 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
425 if (nlp_portwwn != 0 &&
426 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
427 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
428 "0143 PLOGI recv'd from DID: x%x "
429 "WWPN changed: old %llx new %llx\n",
431 (unsigned long long)nlp_portwwn,
433 wwn_to_u64(sp->portName.u.wwn));
435 /* Notify transport of connectivity loss to trigger cleanup. */
436 if (phba->nvmet_support &&
437 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
438 lpfc_nvmet_invalidate_host(phba, ndlp);
440 ndlp->nlp_prev_state = ndlp->nlp_state;
441 /* rport needs to be unregistered first */
442 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
446 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
447 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
448 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
449 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
450 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
456 /* Check for Nport to NPort pt2pt protocol */
457 if ((vport->fc_flag & FC_PT2PT) &&
458 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
459 /* rcv'ed PLOGI decides what our NPortId will be */
460 vport->fc_myDID = icmd->un.rcvels.parmRo;
462 /* If there is an outstanding FLOGI, abort it now.
463 * The remote NPort is not going to ACC our FLOGI
464 * if its already issuing a PLOGI for pt2pt mode.
465 * This indicates our FLOGI was dropped; however, we
466 * must have ACCed the remote NPorts FLOGI to us
469 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
470 lpfc_els_abort_flogi(phba);
472 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
473 if (sp->cmn.edtovResolution) {
474 /* E_D_TOV ticks are in nanoseconds */
475 ed_tov = (phba->fc_edtov + 999999) / 1000000;
479 * For pt-to-pt, use the larger EDTOV
482 if (ed_tov > phba->fc_edtov)
483 phba->fc_edtov = ed_tov;
484 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
486 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
488 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
489 * to account for updated TOV's / parameters
491 if (phba->sli_rev == LPFC_SLI_REV4)
492 lpfc_issue_reg_vfi(vport);
494 link_mbox = mempool_alloc(phba->mbox_mem_pool,
498 lpfc_config_link(phba, link_mbox);
499 link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
500 link_mbox->vport = vport;
501 link_mbox->ctx_ndlp = ndlp;
503 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
504 if (rc == MBX_NOT_FINISHED) {
505 mempool_free(link_mbox, phba->mbox_mem_pool);
510 lpfc_can_disctmo(vport);
513 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
514 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
515 sp->cmn.valid_vendor_ver_level) {
516 vid = be32_to_cpu(sp->un.vv.vid);
517 flag = be32_to_cpu(sp->un.vv.flags);
518 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
519 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
522 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
526 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
530 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
531 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
532 sizeof(struct lpfc_iocbq));
534 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
535 if (phba->sli_rev == LPFC_SLI_REV4)
536 lpfc_unreg_rpi(vport, ndlp);
538 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
539 * always be deferring the ACC.
541 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
542 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
546 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
547 login_mbox->vport = vport;
550 * If there is an outstanding PLOGI issued, abort it before
551 * sending ACC rsp for received PLOGI. If pending plogi
552 * is not canceled here, the plogi will be rejected by
553 * remote port and will be retried. On a configuration with
554 * single discovery thread, this will cause a huge delay in
555 * discovery. Also this will cause multiple state machines
556 * running in parallel for this node.
557 * This only applies to a fabric environment.
559 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
560 (vport->fc_flag & FC_FABRIC)) {
561 /* software abort outstanding PLOGI */
562 lpfc_els_abort(phba, ndlp);
565 if ((vport->port_type == LPFC_NPIV_PORT &&
566 vport->cfg_restrict_login)) {
568 /* no deferred ACC */
571 /* This is an NPIV SLI4 instance that does not need to register
574 if (phba->sli_rev == LPFC_SLI_REV4) {
575 mp = (struct lpfc_dmabuf *)login_mbox->ctx_buf;
577 lpfc_mbuf_free(phba, mp->virt, mp->phys);
580 mempool_free(login_mbox, phba->mbox_mem_pool);
583 /* In order to preserve RPIs, we want to cleanup
584 * the default RPI the firmware created to rcv
585 * this ELS request. The only way to do this is
586 * to register, then unregister the RPI.
588 spin_lock_irq(&ndlp->lock);
589 ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN |
591 spin_unlock_irq(&ndlp->lock);
594 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
595 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
596 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
599 mempool_free(login_mbox, phba->mbox_mem_pool);
603 /* So the order here should be:
605 * Issue CONFIG_LINK mbox
611 * Issue UNREG RPI mbx
618 login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
619 login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
620 login_mbox->context3 = save_iocb; /* For PLOGI ACC */
622 spin_lock_irq(&ndlp->lock);
623 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
624 spin_unlock_irq(&ndlp->lock);
626 /* Start the ball rolling by issuing REG_LOGIN here */
627 rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
628 if (rc == MBX_NOT_FINISHED)
630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
636 mempool_free(login_mbox, phba->mbox_mem_pool);
638 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
639 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
640 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
645 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
646 * @phba: pointer to lpfc hba data structure.
647 * @mboxq: pointer to mailbox object
649 * This routine is invoked to issue a completion to a rcv'ed
650 * ADISC or PDISC after the paused RPI has been resumed.
653 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
655 struct lpfc_vport *vport;
656 struct lpfc_iocbq *elsiocb;
657 struct lpfc_nodelist *ndlp;
660 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
661 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
662 vport = mboxq->vport;
663 cmd = elsiocb->drvrTimeout;
665 if (cmd == ELS_CMD_ADISC) {
666 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
668 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
672 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
676 mempool_free(mboxq, phba->mbox_mem_pool);
680 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
681 struct lpfc_iocbq *cmdiocb)
683 struct lpfc_iocbq *elsiocb;
684 struct lpfc_dmabuf *pcmd;
685 struct serv_parm *sp;
686 struct lpfc_name *pnn, *ppn;
693 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
694 lp = (uint32_t *) pcmd->virt;
697 if (cmd == ELS_CMD_ADISC) {
699 pnn = (struct lpfc_name *) & ap->nodeName;
700 ppn = (struct lpfc_name *) & ap->portName;
702 sp = (struct serv_parm *) lp;
703 pnn = (struct lpfc_name *) & sp->nodeName;
704 ppn = (struct lpfc_name *) & sp->portName;
707 icmd = &cmdiocb->iocb;
708 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
711 * As soon as we send ACC, the remote NPort can
712 * start sending us data. Thus, for SLI4 we must
713 * resume the RPI before the ACC goes out.
715 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
716 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
720 /* Save info from cmd IOCB used in rsp */
721 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
722 sizeof(struct lpfc_iocbq));
724 /* Save the ELS cmd */
725 elsiocb->drvrTimeout = cmd;
727 lpfc_sli4_resume_rpi(ndlp,
728 lpfc_mbx_cmpl_resume_rpi, elsiocb);
733 if (cmd == ELS_CMD_ADISC) {
734 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
736 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
740 /* If we are authenticated, move to the proper state.
741 * It is possible an ADISC arrived and the remote nport
742 * is already in MAPPED or UNMAPPED state. Catch this
743 * condition and don't set the nlp_state again because
744 * it causes an unnecessary transport unregister/register.
746 * Nodes marked for ADISC will move MAPPED or UNMAPPED state
747 * after issuing ADISC
749 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
750 if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) &&
751 !(ndlp->nlp_flag & NLP_NPR_ADISC))
752 lpfc_nlp_set_state(vport, ndlp,
753 NLP_STE_MAPPED_NODE);
758 /* Reject this request because invalid parameters */
759 stat.un.b.lsRjtRsvd0 = 0;
760 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
761 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
762 stat.un.b.vendorUnique = 0;
763 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
766 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
768 spin_lock_irq(&ndlp->lock);
769 ndlp->nlp_flag |= NLP_DELAY_TMO;
770 spin_unlock_irq(&ndlp->lock);
771 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
772 ndlp->nlp_prev_state = ndlp->nlp_state;
773 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
778 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
779 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
782 struct lpfc_hba *phba = vport->phba;
783 struct lpfc_vport **vports;
784 int i, active_vlink_present = 0 ;
786 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
787 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
788 * PLOGIs during LOGO storms from a device.
790 spin_lock_irq(&ndlp->lock);
791 ndlp->nlp_flag |= NLP_LOGO_ACC;
792 spin_unlock_irq(&ndlp->lock);
793 if (els_cmd == ELS_CMD_PRLO)
794 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
796 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
798 /* This clause allows the initiator to ACC the LOGO back to the
799 * Fabric Domain Controller. It does deliberately skip all other
800 * steps because some fabrics send RDP requests after logging out
801 * from the initiator.
803 if (ndlp->nlp_type & NLP_FABRIC &&
804 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
807 /* Notify transport of connectivity loss to trigger cleanup. */
808 if (phba->nvmet_support &&
809 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
810 lpfc_nvmet_invalidate_host(phba, ndlp);
812 if (ndlp->nlp_DID == Fabric_DID) {
813 if (vport->port_state <= LPFC_FDISC ||
814 vport->fc_flag & FC_PT2PT)
816 lpfc_linkdown_port(vport);
817 spin_lock_irq(shost->host_lock);
818 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
819 spin_unlock_irq(shost->host_lock);
820 vports = lpfc_create_vport_work_array(phba);
822 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
824 if ((!(vports[i]->fc_flag &
825 FC_VPORT_LOGO_RCVD)) &&
826 (vports[i]->port_state > LPFC_FDISC)) {
827 active_vlink_present = 1;
831 lpfc_destroy_vport_work_array(phba, vports);
835 * Don't re-instantiate if vport is marked for deletion.
836 * If we are here first then vport_delete is going to wait
837 * for discovery to complete.
839 if (!(vport->load_flag & FC_UNLOADING) &&
840 active_vlink_present) {
842 * If there are other active VLinks present,
843 * re-instantiate the Vlink using FDISC.
845 mod_timer(&ndlp->nlp_delayfunc,
846 jiffies + msecs_to_jiffies(1000));
847 spin_lock_irq(&ndlp->lock);
848 ndlp->nlp_flag |= NLP_DELAY_TMO;
849 spin_unlock_irq(&ndlp->lock);
850 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
851 vport->port_state = LPFC_FDISC;
853 spin_lock_irq(shost->host_lock);
854 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
855 spin_unlock_irq(shost->host_lock);
856 lpfc_retry_pport_discovery(phba);
858 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
859 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
860 (ndlp->nlp_type & NLP_NVME_TARGET) ||
861 (vport->fc_flag & FC_PT2PT))) ||
862 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
863 /* Only try to re-login if this is NOT a Fabric Node
864 * AND the remote NPORT is a FCP/NVME Target or we
865 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
866 * case for LOGO as a response to ADISC behavior.
868 mod_timer(&ndlp->nlp_delayfunc,
869 jiffies + msecs_to_jiffies(1000 * 1));
870 spin_lock_irq(&ndlp->lock);
871 ndlp->nlp_flag |= NLP_DELAY_TMO;
872 spin_unlock_irq(&ndlp->lock);
874 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
877 /* Unregister from backend, could have been skipped due to ADISC */
878 lpfc_nlp_unreg_node(vport, ndlp);
880 ndlp->nlp_prev_state = ndlp->nlp_state;
881 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
883 spin_lock_irq(&ndlp->lock);
884 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
885 spin_unlock_irq(&ndlp->lock);
886 /* The driver has to wait until the ACC completes before it continues
887 * processing the LOGO. The action will resume in
888 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
889 * unreg_login, the driver waits so the ACC does not get aborted.
895 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
896 struct lpfc_nodelist *ndlp,
897 struct lpfc_iocbq *cmdiocb)
903 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
905 if (vport->phba->nvmet_support) {
906 /* Must be a NVME PRLI */
907 if (cmd == ELS_CMD_PRLI)
910 /* Initiator mode. */
911 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
916 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
917 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
918 "state x%x flags x%x\n",
919 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
921 memset(&stat, 0, sizeof(struct ls_rjt));
922 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
923 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
924 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
930 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
931 struct lpfc_iocbq *cmdiocb)
933 struct lpfc_hba *phba = vport->phba;
934 struct lpfc_dmabuf *pcmd;
937 struct fc_rport *rport = ndlp->rport;
940 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
941 lp = (uint32_t *) pcmd->virt;
942 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
944 if ((npr->prliType == PRLI_FCP_TYPE) ||
945 (npr->prliType == PRLI_NVME_TYPE)) {
946 if (npr->initiatorFunc) {
947 if (npr->prliType == PRLI_FCP_TYPE)
948 ndlp->nlp_type |= NLP_FCP_INITIATOR;
949 if (npr->prliType == PRLI_NVME_TYPE)
950 ndlp->nlp_type |= NLP_NVME_INITIATOR;
952 if (npr->targetFunc) {
953 if (npr->prliType == PRLI_FCP_TYPE)
954 ndlp->nlp_type |= NLP_FCP_TARGET;
955 if (npr->prliType == PRLI_NVME_TYPE)
956 ndlp->nlp_type |= NLP_NVME_TARGET;
957 if (npr->writeXferRdyDis)
958 ndlp->nlp_flag |= NLP_FIRSTBURST;
960 if (npr->Retry && ndlp->nlp_type &
961 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
962 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
964 if (npr->Retry && phba->nsler &&
965 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
966 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
969 /* If this driver is in nvme target mode, set the ndlp's fc4
970 * type to NVME provided the PRLI response claims NVME FC4
971 * type. Target mode does not issue gft_id so doesn't get
972 * the fc4 type set until now.
974 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
975 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
979 /* Fabric Controllers send FCP PRLI as an initiator but should
980 * not get recognized as FCP type and registered with transport.
982 if (npr->prliType == PRLI_FCP_TYPE &&
983 !(ndlp->nlp_type & NLP_FABRIC))
984 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
987 /* We need to update the rport role values */
988 roles = FC_RPORT_ROLE_UNKNOWN;
989 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
990 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
991 if (ndlp->nlp_type & NLP_FCP_TARGET)
992 roles |= FC_RPORT_ROLE_FCP_TARGET;
994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
995 "rport rolechg: role:x%x did:x%x flg:x%x",
996 roles, ndlp->nlp_DID, ndlp->nlp_flag);
998 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
999 fc_remote_port_rolechg(rport, roles);
1004 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1006 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1007 spin_lock_irq(&ndlp->lock);
1008 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1009 spin_unlock_irq(&ndlp->lock);
1013 if (!(vport->fc_flag & FC_PT2PT)) {
1014 /* Check config parameter use-adisc or FCP-2 */
1015 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1016 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1017 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1018 spin_lock_irq(&ndlp->lock);
1019 ndlp->nlp_flag |= NLP_NPR_ADISC;
1020 spin_unlock_irq(&ndlp->lock);
1025 spin_lock_irq(&ndlp->lock);
1026 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1027 spin_unlock_irq(&ndlp->lock);
1028 lpfc_unreg_rpi(vport, ndlp);
1033 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1034 * @phba : Pointer to lpfc_hba structure.
1035 * @vport: Pointer to lpfc_vport structure.
1036 * @ndlp: Pointer to lpfc_nodelist structure.
1037 * @rpi : rpi to be release.
1039 * This function will send a unreg_login mailbox command to the firmware
1043 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1044 struct lpfc_nodelist *ndlp, uint16_t rpi)
1049 /* If there is already an UNREG in progress for this ndlp,
1050 * no need to queue up another one.
1052 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1053 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1054 "1435 release_rpi SKIP UNREG x%x on "
1055 "NPort x%x deferred x%x flg x%x "
1057 ndlp->nlp_rpi, ndlp->nlp_DID,
1058 ndlp->nlp_defer_did,
1059 ndlp->nlp_flag, ndlp);
1063 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1066 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1067 "2796 mailbox memory allocation failed \n");
1069 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1070 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1072 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1073 if (!pmb->ctx_ndlp) {
1074 mempool_free(pmb, phba->mbox_mem_pool);
1078 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1079 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1080 ndlp->nlp_flag |= NLP_UNREG_INP;
1082 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1083 "1437 release_rpi UNREG x%x "
1084 "on NPort x%x flg x%x\n",
1085 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1087 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1088 if (rc == MBX_NOT_FINISHED)
1089 mempool_free(pmb, phba->mbox_mem_pool);
1094 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1095 void *arg, uint32_t evt)
1097 struct lpfc_hba *phba;
1098 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1102 /* Release the RPI if reglogin completing */
1103 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1104 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1105 (!pmb->u.mb.mbxStatus)) {
1106 rpi = pmb->u.mb.un.varWords[0];
1107 lpfc_release_rpi(phba, vport, ndlp, rpi);
1109 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1110 "0271 Illegal State Transition: node x%x "
1111 "event x%x, state x%x Data: x%x x%x\n",
1112 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1114 return ndlp->nlp_state;
1118 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1119 void *arg, uint32_t evt)
1121 /* This transition is only legal if we previously
1122 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1123 * working on the same NPortID, do nothing for this thread
1126 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1127 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1128 "0272 Illegal State Transition: node x%x "
1129 "event x%x, state x%x Data: x%x x%x\n",
1130 ndlp->nlp_DID, evt, ndlp->nlp_state,
1131 ndlp->nlp_rpi, ndlp->nlp_flag);
1133 return ndlp->nlp_state;
1136 /* Start of Discovery State Machine routines */
1139 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1140 void *arg, uint32_t evt)
1142 struct lpfc_iocbq *cmdiocb;
1144 cmdiocb = (struct lpfc_iocbq *) arg;
1146 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1147 return ndlp->nlp_state;
1149 return NLP_STE_FREED_NODE;
1153 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1154 void *arg, uint32_t evt)
1156 lpfc_issue_els_logo(vport, ndlp, 0);
1157 return ndlp->nlp_state;
1161 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1162 void *arg, uint32_t evt)
1164 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1166 spin_lock_irq(&ndlp->lock);
1167 ndlp->nlp_flag |= NLP_LOGO_ACC;
1168 spin_unlock_irq(&ndlp->lock);
1169 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1171 return ndlp->nlp_state;
1175 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1176 void *arg, uint32_t evt)
1178 return NLP_STE_FREED_NODE;
1182 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1183 void *arg, uint32_t evt)
1185 return NLP_STE_FREED_NODE;
1189 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1190 struct lpfc_nodelist *ndlp,
1191 void *arg, uint32_t evt)
1193 return ndlp->nlp_state;
1197 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1198 void *arg, uint32_t evt)
1200 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1201 struct lpfc_hba *phba = vport->phba;
1202 struct lpfc_iocbq *cmdiocb = arg;
1203 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1204 uint32_t *lp = (uint32_t *) pcmd->virt;
1205 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1209 memset(&stat, 0, sizeof (struct ls_rjt));
1211 /* For a PLOGI, we only accept if our portname is less
1212 * than the remote portname.
1214 phba->fc_stat.elsLogiCol++;
1215 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1216 sizeof(struct lpfc_name));
1218 if (port_cmp >= 0) {
1219 /* Reject this request because the remote node will accept
1221 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1222 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1223 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1226 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1227 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1228 (vport->num_disc_nodes)) {
1229 spin_lock_irq(&ndlp->lock);
1230 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1231 spin_unlock_irq(&ndlp->lock);
1232 /* Check if there are more PLOGIs to be sent */
1233 lpfc_more_plogi(vport);
1234 if (vport->num_disc_nodes == 0) {
1235 spin_lock_irq(shost->host_lock);
1236 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1237 spin_unlock_irq(shost->host_lock);
1238 lpfc_can_disctmo(vport);
1239 lpfc_end_rscn(vport);
1242 } /* If our portname was less */
1244 return ndlp->nlp_state;
1248 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1249 void *arg, uint32_t evt)
1251 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1254 memset(&stat, 0, sizeof (struct ls_rjt));
1255 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1256 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1257 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1258 return ndlp->nlp_state;
1262 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1263 void *arg, uint32_t evt)
1265 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1267 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1268 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1269 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1270 /* software abort outstanding PLOGI */
1271 lpfc_els_abort(vport->phba, ndlp);
1273 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1274 return ndlp->nlp_state;
1278 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1279 void *arg, uint32_t evt)
1281 struct lpfc_hba *phba = vport->phba;
1282 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1284 /* software abort outstanding PLOGI */
1285 lpfc_els_abort(phba, ndlp);
1287 if (evt == NLP_EVT_RCV_LOGO) {
1288 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1290 lpfc_issue_els_logo(vport, ndlp, 0);
1293 /* Put ndlp in npr state set plogi timer for 1 sec */
1294 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1295 spin_lock_irq(&ndlp->lock);
1296 ndlp->nlp_flag |= NLP_DELAY_TMO;
1297 spin_unlock_irq(&ndlp->lock);
1298 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1299 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1300 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1302 return ndlp->nlp_state;
1306 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1307 struct lpfc_nodelist *ndlp,
1311 struct lpfc_hba *phba = vport->phba;
1312 struct lpfc_iocbq *cmdiocb, *rspiocb;
1313 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1317 struct serv_parm *sp;
1322 cmdiocb = (struct lpfc_iocbq *) arg;
1323 rspiocb = cmdiocb->context_un.rsp_iocb;
1325 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1326 /* Recovery from PLOGI collision logic */
1327 return ndlp->nlp_state;
1330 irsp = &rspiocb->iocb;
1332 if (irsp->ulpStatus)
1335 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1337 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1341 lp = (uint32_t *) prsp->virt;
1342 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1344 /* Some switches have FDMI servers returning 0 for WWN */
1345 if ((ndlp->nlp_DID != FDMI_DID) &&
1346 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1347 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1348 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1349 "0142 PLOGI RSP: Invalid WWN.\n");
1352 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1354 /* PLOGI chkparm OK */
1355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1356 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1357 ndlp->nlp_DID, ndlp->nlp_state,
1358 ndlp->nlp_flag, ndlp->nlp_rpi);
1359 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1360 ndlp->nlp_fcp_info |= CLASS2;
1362 ndlp->nlp_fcp_info |= CLASS3;
1364 ndlp->nlp_class_sup = 0;
1365 if (sp->cls1.classValid)
1366 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1367 if (sp->cls2.classValid)
1368 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1369 if (sp->cls3.classValid)
1370 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1371 if (sp->cls4.classValid)
1372 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1373 ndlp->nlp_maxframe =
1374 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1376 if ((vport->fc_flag & FC_PT2PT) &&
1377 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1378 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1379 if (sp->cmn.edtovResolution) {
1380 /* E_D_TOV ticks are in nanoseconds */
1381 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1384 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1385 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1386 sp->cmn.valid_vendor_ver_level) {
1387 vid = be32_to_cpu(sp->un.vv.vid);
1388 flag = be32_to_cpu(sp->un.vv.flags);
1389 if ((vid == LPFC_VV_EMLX_ID) &&
1390 (flag & LPFC_VV_SUPPRESS_RSP))
1391 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1395 * Use the larger EDTOV
1396 * RATOV = 2 * EDTOV for pt-to-pt
1398 if (ed_tov > phba->fc_edtov)
1399 phba->fc_edtov = ed_tov;
1400 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1402 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1404 /* Issue config_link / reg_vfi to account for updated TOV's */
1405 if (phba->sli_rev == LPFC_SLI_REV4) {
1406 lpfc_issue_reg_vfi(vport);
1408 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1410 lpfc_printf_vlog(vport, KERN_ERR,
1412 "0133 PLOGI: no memory "
1414 "Data: x%x x%x x%x x%x\n",
1415 ndlp->nlp_DID, ndlp->nlp_state,
1416 ndlp->nlp_flag, ndlp->nlp_rpi);
1420 lpfc_config_link(phba, mbox);
1422 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1423 mbox->vport = vport;
1424 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1425 if (rc == MBX_NOT_FINISHED) {
1426 mempool_free(mbox, phba->mbox_mem_pool);
1432 lpfc_unreg_rpi(vport, ndlp);
1434 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1436 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1437 "0018 PLOGI: no memory for reg_login "
1438 "Data: x%x x%x x%x x%x\n",
1439 ndlp->nlp_DID, ndlp->nlp_state,
1440 ndlp->nlp_flag, ndlp->nlp_rpi);
1444 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1445 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1446 switch (ndlp->nlp_DID) {
1447 case NameServer_DID:
1448 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1449 /* Fabric Controller Node needs these parameters. */
1450 memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
1453 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1456 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1457 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1460 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1461 if (!mbox->ctx_ndlp)
1464 mbox->vport = vport;
1465 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1466 != MBX_NOT_FINISHED) {
1467 lpfc_nlp_set_state(vport, ndlp,
1468 NLP_STE_REG_LOGIN_ISSUE);
1469 return ndlp->nlp_state;
1471 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1472 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1473 /* decrement node reference count to the failed mbox
1477 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1478 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1480 mempool_free(mbox, phba->mbox_mem_pool);
1482 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1483 "0134 PLOGI: cannot issue reg_login "
1484 "Data: x%x x%x x%x x%x\n",
1485 ndlp->nlp_DID, ndlp->nlp_state,
1486 ndlp->nlp_flag, ndlp->nlp_rpi);
1488 mempool_free(mbox, phba->mbox_mem_pool);
1490 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1491 "0135 PLOGI: cannot format reg_login "
1492 "Data: x%x x%x x%x x%x\n",
1493 ndlp->nlp_DID, ndlp->nlp_state,
1494 ndlp->nlp_flag, ndlp->nlp_rpi);
1499 if (ndlp->nlp_DID == NameServer_DID) {
1500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1501 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1502 "0261 Cannot Register NameServer login\n");
1506 ** In case the node reference counter does not go to zero, ensure that
1507 ** the stale state for the node is not processed.
1510 ndlp->nlp_prev_state = ndlp->nlp_state;
1511 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1512 return NLP_STE_FREED_NODE;
1516 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1517 void *arg, uint32_t evt)
1519 return ndlp->nlp_state;
1523 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1524 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1526 struct lpfc_hba *phba;
1527 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1528 MAILBOX_t *mb = &pmb->u.mb;
1532 /* Release the RPI */
1533 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1535 rpi = pmb->u.mb.un.varWords[0];
1536 lpfc_release_rpi(phba, vport, ndlp, rpi);
1538 return ndlp->nlp_state;
1542 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1543 void *arg, uint32_t evt)
1545 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1546 spin_lock_irq(&ndlp->lock);
1547 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1548 spin_unlock_irq(&ndlp->lock);
1549 return ndlp->nlp_state;
1551 /* software abort outstanding PLOGI */
1552 lpfc_els_abort(vport->phba, ndlp);
1554 lpfc_drop_node(vport, ndlp);
1555 return NLP_STE_FREED_NODE;
1560 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1561 struct lpfc_nodelist *ndlp,
1565 struct lpfc_hba *phba = vport->phba;
1567 /* Don't do anything that will mess up processing of the
1570 if (vport->fc_flag & FC_RSCN_DEFERRED)
1571 return ndlp->nlp_state;
1573 /* software abort outstanding PLOGI */
1574 lpfc_els_abort(phba, ndlp);
1576 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1578 spin_lock_irq(&ndlp->lock);
1579 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1580 spin_unlock_irq(&ndlp->lock);
1582 return ndlp->nlp_state;
1586 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1587 void *arg, uint32_t evt)
1589 struct lpfc_hba *phba = vport->phba;
1590 struct lpfc_iocbq *cmdiocb;
1592 /* software abort outstanding ADISC */
1593 lpfc_els_abort(phba, ndlp);
1595 cmdiocb = (struct lpfc_iocbq *) arg;
1597 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1598 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1599 spin_lock_irq(&ndlp->lock);
1600 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1601 spin_unlock_irq(&ndlp->lock);
1602 if (vport->num_disc_nodes)
1603 lpfc_more_adisc(vport);
1605 return ndlp->nlp_state;
1607 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1608 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1611 return ndlp->nlp_state;
1615 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1616 void *arg, uint32_t evt)
1618 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1620 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1621 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1622 return ndlp->nlp_state;
1626 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1627 void *arg, uint32_t evt)
1629 struct lpfc_hba *phba = vport->phba;
1630 struct lpfc_iocbq *cmdiocb;
1632 cmdiocb = (struct lpfc_iocbq *) arg;
1634 /* software abort outstanding ADISC */
1635 lpfc_els_abort(phba, ndlp);
1637 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1638 return ndlp->nlp_state;
1642 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1643 struct lpfc_nodelist *ndlp,
1644 void *arg, uint32_t evt)
1646 struct lpfc_iocbq *cmdiocb;
1648 cmdiocb = (struct lpfc_iocbq *) arg;
1650 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1651 return ndlp->nlp_state;
1655 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1656 void *arg, uint32_t evt)
1658 struct lpfc_iocbq *cmdiocb;
1660 cmdiocb = (struct lpfc_iocbq *) arg;
1662 /* Treat like rcv logo */
1663 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1664 return ndlp->nlp_state;
1668 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1669 struct lpfc_nodelist *ndlp,
1670 void *arg, uint32_t evt)
1672 struct lpfc_hba *phba = vport->phba;
1673 struct lpfc_iocbq *cmdiocb, *rspiocb;
1678 cmdiocb = (struct lpfc_iocbq *) arg;
1679 rspiocb = cmdiocb->context_un.rsp_iocb;
1681 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1682 irsp = &rspiocb->iocb;
1684 if ((irsp->ulpStatus) ||
1685 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1687 mod_timer(&ndlp->nlp_delayfunc,
1688 jiffies + msecs_to_jiffies(1000));
1689 spin_lock_irq(&ndlp->lock);
1690 ndlp->nlp_flag |= NLP_DELAY_TMO;
1691 spin_unlock_irq(&ndlp->lock);
1692 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1694 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1695 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1696 lpfc_unreg_rpi(vport, ndlp);
1697 return ndlp->nlp_state;
1700 if (phba->sli_rev == LPFC_SLI_REV4) {
1701 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1703 /* Stay in state and retry. */
1704 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1705 return ndlp->nlp_state;
1709 if (ndlp->nlp_type & NLP_FCP_TARGET)
1710 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1712 if (ndlp->nlp_type & NLP_NVME_TARGET)
1713 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1715 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1716 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1719 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1723 return ndlp->nlp_state;
1727 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1728 void *arg, uint32_t evt)
1730 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1731 spin_lock_irq(&ndlp->lock);
1732 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1733 spin_unlock_irq(&ndlp->lock);
1734 return ndlp->nlp_state;
1736 /* software abort outstanding ADISC */
1737 lpfc_els_abort(vport->phba, ndlp);
1739 lpfc_drop_node(vport, ndlp);
1740 return NLP_STE_FREED_NODE;
1745 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1746 struct lpfc_nodelist *ndlp,
1750 struct lpfc_hba *phba = vport->phba;
1752 /* Don't do anything that will mess up processing of the
1755 if (vport->fc_flag & FC_RSCN_DEFERRED)
1756 return ndlp->nlp_state;
1758 /* software abort outstanding ADISC */
1759 lpfc_els_abort(phba, ndlp);
1761 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1762 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1763 spin_lock_irq(&ndlp->lock);
1764 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1765 spin_unlock_irq(&ndlp->lock);
1766 lpfc_disc_set_adisc(vport, ndlp);
1767 return ndlp->nlp_state;
1771 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1772 struct lpfc_nodelist *ndlp,
1776 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1778 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1779 return ndlp->nlp_state;
1783 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1784 struct lpfc_nodelist *ndlp,
1788 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1791 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1792 return ndlp->nlp_state;
1794 if (vport->phba->nvmet_support) {
1795 /* NVME Target mode. Handle and respond to the PRLI and
1796 * transition to UNMAPPED provided the RPI has completed
1799 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1800 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1801 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1803 /* RPI registration has not completed. Reject the PRLI
1804 * to prevent an illegal state transition when the
1805 * rpi registration does complete.
1807 memset(&stat, 0, sizeof(struct ls_rjt));
1808 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1809 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1810 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1812 return ndlp->nlp_state;
1815 /* Initiator mode. */
1816 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1818 return ndlp->nlp_state;
1822 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1823 struct lpfc_nodelist *ndlp,
1827 struct lpfc_hba *phba = vport->phba;
1828 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1830 LPFC_MBOXQ_t *nextmb;
1831 struct lpfc_dmabuf *mp;
1832 struct lpfc_nodelist *ns_ndlp;
1834 cmdiocb = (struct lpfc_iocbq *) arg;
1836 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1837 if ((mb = phba->sli.mbox_active)) {
1838 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1839 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1840 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1842 mb->ctx_ndlp = NULL;
1843 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1847 spin_lock_irq(&phba->hbalock);
1848 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1849 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1850 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1851 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1853 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1856 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1858 list_del(&mb->list);
1859 phba->sli.mboxq_cnt--;
1860 mempool_free(mb, phba->mbox_mem_pool);
1863 spin_unlock_irq(&phba->hbalock);
1865 /* software abort if any GID_FT is outstanding */
1866 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1867 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1869 lpfc_els_abort(phba, ns_ndlp);
1872 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1873 return ndlp->nlp_state;
1877 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1878 struct lpfc_nodelist *ndlp,
1882 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1884 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1885 return ndlp->nlp_state;
1889 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1890 struct lpfc_nodelist *ndlp,
1894 struct lpfc_iocbq *cmdiocb;
1896 cmdiocb = (struct lpfc_iocbq *) arg;
1897 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1898 return ndlp->nlp_state;
1902 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1903 struct lpfc_nodelist *ndlp,
1907 struct lpfc_hba *phba = vport->phba;
1908 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1909 MAILBOX_t *mb = &pmb->u.mb;
1910 uint32_t did = mb->un.varWords[1];
1912 if (mb->mbxStatus) {
1913 /* RegLogin failed */
1914 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1915 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1917 did, mb->mbxStatus, vport->port_state,
1918 mb->un.varRegLogin.vpi,
1919 mb->un.varRegLogin.rpi);
1921 * If RegLogin failed due to lack of HBA resources do not
1924 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1925 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1926 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1927 return ndlp->nlp_state;
1930 /* Put ndlp in npr state set plogi timer for 1 sec */
1931 mod_timer(&ndlp->nlp_delayfunc,
1932 jiffies + msecs_to_jiffies(1000 * 1));
1933 spin_lock_irq(&ndlp->lock);
1934 ndlp->nlp_flag |= NLP_DELAY_TMO;
1935 spin_unlock_irq(&ndlp->lock);
1936 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1938 lpfc_issue_els_logo(vport, ndlp, 0);
1939 return ndlp->nlp_state;
1942 /* SLI4 ports have preallocated logical rpis. */
1943 if (phba->sli_rev < LPFC_SLI_REV4)
1944 ndlp->nlp_rpi = mb->un.varWords[0];
1946 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1948 /* Only if we are not a fabric nport do we issue PRLI */
1949 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1950 "3066 RegLogin Complete on x%x x%x x%x\n",
1951 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1952 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1953 (phba->nvmet_support == 0)) {
1954 /* The driver supports FCP and NVME concurrently. If the
1955 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1956 * know what PRLI to send yet. Figure that out now and
1957 * call PRLI depending on the outcome.
1959 if (vport->fc_flag & FC_PT2PT) {
1960 /* If we are pt2pt, there is no Fabric to determine
1961 * the FC4 type of the remote nport. So if NVME
1962 * is configured try it.
1964 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1965 if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
1966 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1967 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1968 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1969 /* We need to update the localport also */
1970 lpfc_nvme_update_localport(vport);
1973 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1974 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1976 } else if (ndlp->nlp_fc4_type == 0) {
1977 /* If we are only configured for FCP, the driver
1978 * should just issue PRLI for FCP. Otherwise issue
1979 * GFT_ID to determine if remote port supports NVME.
1981 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1982 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
1984 return ndlp->nlp_state;
1986 ndlp->nlp_fc4_type = NLP_FC4_FCP;
1989 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1990 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1991 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
1992 lpfc_issue_els_logo(vport, ndlp, 0);
1993 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1997 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1998 phba->targetport->port_id = vport->fc_myDID;
2000 /* Only Fabric ports should transition. NVME target
2001 * must complete PRLI.
2003 if (ndlp->nlp_type & NLP_FABRIC) {
2004 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2005 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2006 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2009 return ndlp->nlp_state;
2013 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2014 struct lpfc_nodelist *ndlp,
2018 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2019 spin_lock_irq(&ndlp->lock);
2020 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2021 spin_unlock_irq(&ndlp->lock);
2022 return ndlp->nlp_state;
2024 lpfc_drop_node(vport, ndlp);
2025 return NLP_STE_FREED_NODE;
2030 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2031 struct lpfc_nodelist *ndlp,
2035 /* Don't do anything that will mess up processing of the
2038 if (vport->fc_flag & FC_RSCN_DEFERRED)
2039 return ndlp->nlp_state;
2041 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2042 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2043 spin_lock_irq(&ndlp->lock);
2045 /* If we are a target we won't immediately transition into PRLI,
2046 * so if REG_LOGIN already completed we don't need to ignore it.
2048 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2049 !vport->phba->nvmet_support)
2050 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2052 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2053 spin_unlock_irq(&ndlp->lock);
2054 lpfc_disc_set_adisc(vport, ndlp);
2055 return ndlp->nlp_state;
2059 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2060 void *arg, uint32_t evt)
2062 struct lpfc_iocbq *cmdiocb;
2064 cmdiocb = (struct lpfc_iocbq *) arg;
2066 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2067 return ndlp->nlp_state;
2071 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2072 void *arg, uint32_t evt)
2074 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2076 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2077 return ndlp->nlp_state;
2078 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2079 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2080 return ndlp->nlp_state;
2084 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2085 void *arg, uint32_t evt)
2087 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2089 /* Software abort outstanding PRLI before sending acc */
2090 lpfc_els_abort(vport->phba, ndlp);
2092 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2093 return ndlp->nlp_state;
2097 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2098 void *arg, uint32_t evt)
2100 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2102 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2103 return ndlp->nlp_state;
2106 /* This routine is envoked when we rcv a PRLO request from a nport
2107 * we are logged into. We should send back a PRLO rsp setting the
2109 * NEXT STATE = PRLI_ISSUE
2112 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2113 void *arg, uint32_t evt)
2115 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2117 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2118 return ndlp->nlp_state;
2122 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2123 void *arg, uint32_t evt)
2125 struct lpfc_iocbq *cmdiocb, *rspiocb;
2126 struct lpfc_hba *phba = vport->phba;
2129 struct lpfc_nvme_prli *nvpr;
2132 cmdiocb = (struct lpfc_iocbq *) arg;
2133 rspiocb = cmdiocb->context_un.rsp_iocb;
2135 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2136 * format is different so NULL the two PRLI types so that the
2137 * driver correctly gets the correct context.
2141 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2142 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2143 npr = (PRLI *) temp_ptr;
2144 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2145 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2147 irsp = &rspiocb->iocb;
2148 if (irsp->ulpStatus) {
2149 if ((vport->port_type == LPFC_NPIV_PORT) &&
2150 vport->cfg_restrict_login) {
2154 /* Adjust the nlp_type accordingly if the PRLI failed */
2156 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2158 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2160 /* We can't set the DSM state till BOTH PRLIs complete */
2164 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2165 (npr->prliType == PRLI_FCP_TYPE)) {
2166 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2167 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2170 if (npr->initiatorFunc)
2171 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2172 if (npr->targetFunc) {
2173 ndlp->nlp_type |= NLP_FCP_TARGET;
2174 if (npr->writeXferRdyDis)
2175 ndlp->nlp_flag |= NLP_FIRSTBURST;
2178 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2181 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2182 PRLI_REQ_EXECUTED) &&
2183 (bf_get_be32(prli_type_code, nvpr) ==
2186 /* Complete setting up the remote ndlp personality. */
2187 if (bf_get_be32(prli_init, nvpr))
2188 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2190 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2191 bf_get_be32(prli_conf, nvpr))
2193 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2195 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2197 /* Target driver cannot solicit NVME FB. */
2198 if (bf_get_be32(prli_tgt, nvpr)) {
2199 /* Complete the nvme target roles. The transport
2200 * needs to know if the rport is capable of
2201 * discovery in addition to its role.
2203 ndlp->nlp_type |= NLP_NVME_TARGET;
2204 if (bf_get_be32(prli_disc, nvpr))
2205 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2208 * If prli_fba is set, the Target supports FirstBurst.
2209 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2210 * otherwise it defines the actual size supported by
2213 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2214 (phba->cfg_nvme_enable_fb) &&
2215 (!phba->nvmet_support)) {
2216 /* Both sides support FB. The target's first
2217 * burst size is a 512 byte encoded value.
2219 ndlp->nlp_flag |= NLP_FIRSTBURST;
2220 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2223 /* Expressed in units of 512 bytes */
2224 if (ndlp->nvme_fb_size)
2225 ndlp->nvme_fb_size <<=
2228 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2232 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2233 "6029 NVME PRLI Cmpl w1 x%08x "
2234 "w4 x%08x w5 x%08x flag x%x, "
2235 "fcp_info x%x nlp_type x%x\n",
2236 be32_to_cpu(nvpr->word1),
2237 be32_to_cpu(nvpr->word4),
2238 be32_to_cpu(nvpr->word5),
2239 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2242 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2243 (vport->port_type == LPFC_NPIV_PORT) &&
2244 vport->cfg_restrict_login) {
2246 spin_lock_irq(&ndlp->lock);
2247 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2248 spin_unlock_irq(&ndlp->lock);
2249 lpfc_issue_els_logo(vport, ndlp, 0);
2251 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2252 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2253 return ndlp->nlp_state;
2257 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2260 if (ndlp->fc4_prli_sent == 0) {
2261 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2262 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2263 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2264 else if (ndlp->nlp_type &
2265 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2268 lpfc_printf_vlog(vport,
2270 "3067 PRLI's still outstanding "
2271 "on x%06x - count %d, Pend Node Mode "
2273 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2275 return ndlp->nlp_state;
2278 /*! lpfc_device_rm_prli_issue
2289 * This routine is envoked when we a request to remove a nport we are in the
2290 * process of PRLIing. We should software abort outstanding prli, unreg
2291 * login, send a logout. We will change node state to UNUSED_NODE, put it
2292 * on plogi list so it can be freed when LOGO completes.
2297 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2298 void *arg, uint32_t evt)
2300 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2301 spin_lock_irq(&ndlp->lock);
2302 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2303 spin_unlock_irq(&ndlp->lock);
2304 return ndlp->nlp_state;
2306 /* software abort outstanding PLOGI */
2307 lpfc_els_abort(vport->phba, ndlp);
2309 lpfc_drop_node(vport, ndlp);
2310 return NLP_STE_FREED_NODE;
2315 /*! lpfc_device_recov_prli_issue
2326 * The routine is envoked when the state of a device is unknown, like
2327 * during a link down. We should remove the nodelist entry from the
2328 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2329 * outstanding PRLI command, then free the node entry.
2332 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2333 struct lpfc_nodelist *ndlp,
2337 struct lpfc_hba *phba = vport->phba;
2339 /* Don't do anything that will mess up processing of the
2342 if (vport->fc_flag & FC_RSCN_DEFERRED)
2343 return ndlp->nlp_state;
2345 /* software abort outstanding PRLI */
2346 lpfc_els_abort(phba, ndlp);
2348 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2349 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2350 spin_lock_irq(&ndlp->lock);
2351 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2352 spin_unlock_irq(&ndlp->lock);
2353 lpfc_disc_set_adisc(vport, ndlp);
2354 return ndlp->nlp_state;
2358 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2359 void *arg, uint32_t evt)
2361 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2364 memset(&stat, 0, sizeof(struct ls_rjt));
2365 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2366 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2367 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2368 return ndlp->nlp_state;
2372 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2373 void *arg, uint32_t evt)
2375 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2378 memset(&stat, 0, sizeof(struct ls_rjt));
2379 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2380 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2381 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2382 return ndlp->nlp_state;
2386 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2387 void *arg, uint32_t evt)
2389 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2391 spin_lock_irq(&ndlp->lock);
2392 ndlp->nlp_flag |= NLP_LOGO_ACC;
2393 spin_unlock_irq(&ndlp->lock);
2394 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2395 return ndlp->nlp_state;
2399 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2400 void *arg, uint32_t evt)
2402 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2405 memset(&stat, 0, sizeof(struct ls_rjt));
2406 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2407 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2408 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2409 return ndlp->nlp_state;
2413 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2414 void *arg, uint32_t evt)
2416 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2419 memset(&stat, 0, sizeof(struct ls_rjt));
2420 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2421 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2422 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2423 return ndlp->nlp_state;
2427 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2428 void *arg, uint32_t evt)
2430 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2432 spin_lock_irq(&ndlp->lock);
2433 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2434 spin_unlock_irq(&ndlp->lock);
2435 lpfc_disc_set_adisc(vport, ndlp);
2436 return ndlp->nlp_state;
2440 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2441 void *arg, uint32_t evt)
2444 * DevLoss has timed out and is calling for Device Remove.
2445 * In this case, abort the LOGO and cleanup the ndlp
2448 lpfc_unreg_rpi(vport, ndlp);
2449 /* software abort outstanding PLOGI */
2450 lpfc_els_abort(vport->phba, ndlp);
2451 lpfc_drop_node(vport, ndlp);
2452 return NLP_STE_FREED_NODE;
2456 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2457 struct lpfc_nodelist *ndlp,
2458 void *arg, uint32_t evt)
2461 * Device Recovery events have no meaning for a node with a LOGO
2462 * outstanding. The LOGO has to complete first and handle the
2463 * node from that point.
2465 return ndlp->nlp_state;
2469 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2470 void *arg, uint32_t evt)
2472 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2474 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2475 return ndlp->nlp_state;
2479 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2480 void *arg, uint32_t evt)
2482 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2484 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2485 return ndlp->nlp_state;
2487 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2488 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2489 return ndlp->nlp_state;
2493 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2494 void *arg, uint32_t evt)
2496 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2498 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2499 return ndlp->nlp_state;
2503 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2504 void *arg, uint32_t evt)
2506 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2508 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2509 return ndlp->nlp_state;
2513 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2514 void *arg, uint32_t evt)
2516 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2518 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2519 return ndlp->nlp_state;
2523 lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2524 struct lpfc_nodelist *ndlp,
2528 lpfc_drop_node(vport, ndlp);
2529 return NLP_STE_FREED_NODE;
2533 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2534 struct lpfc_nodelist *ndlp,
2538 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2540 spin_lock_irq(&ndlp->lock);
2541 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2542 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2543 spin_unlock_irq(&ndlp->lock);
2544 lpfc_disc_set_adisc(vport, ndlp);
2546 return ndlp->nlp_state;
2550 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2551 void *arg, uint32_t evt)
2553 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2555 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2556 return ndlp->nlp_state;
2560 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2561 void *arg, uint32_t evt)
2563 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2565 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2566 return ndlp->nlp_state;
2567 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2568 return ndlp->nlp_state;
2572 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2573 void *arg, uint32_t evt)
2575 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2577 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2578 return ndlp->nlp_state;
2582 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2583 struct lpfc_nodelist *ndlp,
2584 void *arg, uint32_t evt)
2586 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2588 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2589 return ndlp->nlp_state;
2593 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2594 void *arg, uint32_t evt)
2596 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2598 /* flush the target */
2599 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2601 /* Treat like rcv logo */
2602 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2603 return ndlp->nlp_state;
2607 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2608 struct lpfc_nodelist *ndlp,
2612 lpfc_disc_set_adisc(vport, ndlp);
2614 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2615 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2616 spin_lock_irq(&ndlp->lock);
2617 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2618 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2619 spin_unlock_irq(&ndlp->lock);
2620 return ndlp->nlp_state;
2624 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2625 void *arg, uint32_t evt)
2627 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2629 /* Ignore PLOGI if we have an outstanding LOGO */
2630 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2631 return ndlp->nlp_state;
2632 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2633 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2634 spin_lock_irq(&ndlp->lock);
2635 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2636 spin_unlock_irq(&ndlp->lock);
2637 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2638 /* send PLOGI immediately, move to PLOGI issue state */
2639 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2640 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2641 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2642 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2645 return ndlp->nlp_state;
2649 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2650 void *arg, uint32_t evt)
2652 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2655 memset(&stat, 0, sizeof (struct ls_rjt));
2656 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2657 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2658 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2660 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2662 * ADISC nodes will be handled in regular discovery path after
2663 * receiving response from NS.
2665 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2667 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2668 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2669 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2670 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2673 return ndlp->nlp_state;
2677 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2678 void *arg, uint32_t evt)
2680 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2682 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2683 return ndlp->nlp_state;
2687 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2688 void *arg, uint32_t evt)
2690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2692 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2694 * Do not start discovery if discovery is about to start
2695 * or discovery in progress for this node. Starting discovery
2696 * here will affect the counting of discovery threads.
2698 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2699 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2701 * ADISC nodes will be handled in regular discovery path after
2702 * receiving response from NS.
2704 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2706 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2707 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2708 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2709 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2712 return ndlp->nlp_state;
2716 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2717 void *arg, uint32_t evt)
2719 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2721 spin_lock_irq(&ndlp->lock);
2722 ndlp->nlp_flag |= NLP_LOGO_ACC;
2723 spin_unlock_irq(&ndlp->lock);
2725 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2727 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2728 mod_timer(&ndlp->nlp_delayfunc,
2729 jiffies + msecs_to_jiffies(1000 * 1));
2730 spin_lock_irq(&ndlp->lock);
2731 ndlp->nlp_flag |= NLP_DELAY_TMO;
2732 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2733 spin_unlock_irq(&ndlp->lock);
2734 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2736 spin_lock_irq(&ndlp->lock);
2737 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2738 spin_unlock_irq(&ndlp->lock);
2740 return ndlp->nlp_state;
2744 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2745 void *arg, uint32_t evt)
2747 struct lpfc_iocbq *cmdiocb, *rspiocb;
2750 cmdiocb = (struct lpfc_iocbq *) arg;
2751 rspiocb = cmdiocb->context_un.rsp_iocb;
2753 irsp = &rspiocb->iocb;
2754 if (irsp->ulpStatus) {
2755 return NLP_STE_FREED_NODE;
2757 return ndlp->nlp_state;
2761 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2762 void *arg, uint32_t evt)
2764 struct lpfc_iocbq *cmdiocb, *rspiocb;
2767 cmdiocb = (struct lpfc_iocbq *) arg;
2768 rspiocb = cmdiocb->context_un.rsp_iocb;
2770 irsp = &rspiocb->iocb;
2771 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2772 lpfc_drop_node(vport, ndlp);
2773 return NLP_STE_FREED_NODE;
2775 return ndlp->nlp_state;
2779 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2780 void *arg, uint32_t evt)
2782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2784 /* For the fabric port just clear the fc flags. */
2785 if (ndlp->nlp_DID == Fabric_DID) {
2786 spin_lock_irq(shost->host_lock);
2787 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2788 spin_unlock_irq(shost->host_lock);
2790 lpfc_unreg_rpi(vport, ndlp);
2791 return ndlp->nlp_state;
2795 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2796 void *arg, uint32_t evt)
2798 struct lpfc_iocbq *cmdiocb, *rspiocb;
2801 cmdiocb = (struct lpfc_iocbq *) arg;
2802 rspiocb = cmdiocb->context_un.rsp_iocb;
2804 irsp = &rspiocb->iocb;
2805 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2806 lpfc_drop_node(vport, ndlp);
2807 return NLP_STE_FREED_NODE;
2809 return ndlp->nlp_state;
2813 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2814 struct lpfc_nodelist *ndlp,
2815 void *arg, uint32_t evt)
2817 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2818 MAILBOX_t *mb = &pmb->u.mb;
2820 if (!mb->mbxStatus) {
2821 /* SLI4 ports have preallocated logical rpis. */
2822 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2823 ndlp->nlp_rpi = mb->un.varWords[0];
2824 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2825 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2826 lpfc_unreg_rpi(vport, ndlp);
2829 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2830 lpfc_drop_node(vport, ndlp);
2831 return NLP_STE_FREED_NODE;
2834 return ndlp->nlp_state;
2838 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2839 void *arg, uint32_t evt)
2841 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2842 spin_lock_irq(&ndlp->lock);
2843 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2844 spin_unlock_irq(&ndlp->lock);
2845 return ndlp->nlp_state;
2847 lpfc_drop_node(vport, ndlp);
2848 return NLP_STE_FREED_NODE;
2852 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2853 void *arg, uint32_t evt)
2855 /* Don't do anything that will mess up processing of the
2858 if (vport->fc_flag & FC_RSCN_DEFERRED)
2859 return ndlp->nlp_state;
2861 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2862 spin_lock_irq(&ndlp->lock);
2863 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2864 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2865 spin_unlock_irq(&ndlp->lock);
2866 return ndlp->nlp_state;
2870 /* This next section defines the NPort Discovery State Machine */
2872 /* There are 4 different double linked lists nodelist entries can reside on.
2873 * The plogi list and adisc list are used when Link Up discovery or RSCN
2874 * processing is needed. Each list holds the nodes that we will send PLOGI
2875 * or ADISC on. These lists will keep track of what nodes will be effected
2876 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2877 * The unmapped_list will contain all nodes that we have successfully logged
2878 * into at the Fibre Channel level. The mapped_list will contain all nodes
2879 * that are mapped FCP targets.
2882 * The bind list is a list of undiscovered (potentially non-existent) nodes
2883 * that we have saved binding information on. This information is used when
2884 * nodes transition from the unmapped to the mapped list.
2886 /* For UNUSED_NODE state, the node has just been allocated .
2887 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2888 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2889 * and put on the unmapped list. For ADISC processing, the node is taken off
2890 * the ADISC list and placed on either the mapped or unmapped list (depending
2891 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2892 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2893 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2894 * node, the node is taken off the unmapped list. The binding list is checked
2895 * for a valid binding, or a binding is automatically assigned. If binding
2896 * assignment is unsuccessful, the node is left on the unmapped list. If
2897 * binding assignment is successful, the associated binding list entry (if
2898 * any) is removed, and the node is placed on the mapped list.
2901 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2902 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2903 * expire, all effected nodes will receive a DEVICE_RM event.
2906 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2907 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2908 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2909 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2910 * we will first process the ADISC list. 32 entries are processed initially and
2911 * ADISC is initited for each one. Completions / Events for each node are
2912 * funnelled thru the state machine. As each node finishes ADISC processing, it
2913 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2914 * waiting, and the ADISC list count is identically 0, then we are done. For
2915 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2916 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2917 * list. 32 entries are processed initially and PLOGI is initited for each one.
2918 * Completions / Events for each node are funnelled thru the state machine. As
2919 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2920 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2921 * indentically 0, then we are done. We have now completed discovery / RSCN
2922 * handling. Upon completion, ALL nodes should be on either the mapped or
2926 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2927 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2928 /* Action routine Event Current State */
2929 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2930 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2931 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2932 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2933 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2934 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2935 lpfc_disc_illegal, /* CMPL_PLOGI */
2936 lpfc_disc_illegal, /* CMPL_PRLI */
2937 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2938 lpfc_disc_illegal, /* CMPL_ADISC */
2939 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2940 lpfc_device_rm_unused_node, /* DEVICE_RM */
2941 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2943 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2944 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2945 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2946 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2947 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2948 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2949 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2950 lpfc_disc_illegal, /* CMPL_PRLI */
2951 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2952 lpfc_disc_illegal, /* CMPL_ADISC */
2953 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2954 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2955 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2957 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2958 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2959 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2960 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2961 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2962 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2963 lpfc_disc_illegal, /* CMPL_PLOGI */
2964 lpfc_disc_illegal, /* CMPL_PRLI */
2965 lpfc_disc_illegal, /* CMPL_LOGO */
2966 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2967 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2968 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2969 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2971 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2972 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2973 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2974 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2975 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2976 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2977 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2978 lpfc_disc_illegal, /* CMPL_PRLI */
2979 lpfc_disc_illegal, /* CMPL_LOGO */
2980 lpfc_disc_illegal, /* CMPL_ADISC */
2981 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2982 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2983 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2985 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2986 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2987 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2988 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2989 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2990 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2991 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2992 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2993 lpfc_disc_illegal, /* CMPL_LOGO */
2994 lpfc_disc_illegal, /* CMPL_ADISC */
2995 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2996 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2997 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2999 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3000 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3001 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3002 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3003 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3004 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3005 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3006 lpfc_disc_illegal, /* CMPL_PRLI */
3007 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3008 lpfc_disc_illegal, /* CMPL_ADISC */
3009 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3010 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3011 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3013 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3014 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3015 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3016 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3017 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3018 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3019 lpfc_disc_illegal, /* CMPL_PLOGI */
3020 lpfc_disc_illegal, /* CMPL_PRLI */
3021 lpfc_disc_illegal, /* CMPL_LOGO */
3022 lpfc_disc_illegal, /* CMPL_ADISC */
3023 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3024 lpfc_device_rm_unmap_node, /* DEVICE_RM */
3025 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3027 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3028 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3029 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3030 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3031 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3032 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3033 lpfc_disc_illegal, /* CMPL_PLOGI */
3034 lpfc_disc_illegal, /* CMPL_PRLI */
3035 lpfc_disc_illegal, /* CMPL_LOGO */
3036 lpfc_disc_illegal, /* CMPL_ADISC */
3037 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3038 lpfc_disc_illegal, /* DEVICE_RM */
3039 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3041 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3042 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3043 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3044 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3045 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3046 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3047 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3048 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3049 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3050 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3051 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3052 lpfc_device_rm_npr_node, /* DEVICE_RM */
3053 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3057 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3058 void *arg, uint32_t evt)
3060 uint32_t cur_state, rc;
3061 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3063 uint32_t got_ndlp = 0;
3066 if (lpfc_nlp_get(ndlp))
3069 cur_state = ndlp->nlp_state;
3071 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3072 ((uint32_t)ndlp->nlp_type));
3073 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3074 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3075 "0211 DSM in event x%x on NPort x%x in "
3076 "state %d rpi x%x Data: x%x x%x\n",
3077 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3078 ndlp->nlp_flag, data1);
3080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3081 "DSM in: evt:%d ste:%d did:x%x",
3082 evt, cur_state, ndlp->nlp_DID);
3084 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3085 rc = (func) (vport, ndlp, arg, evt);
3087 /* DSM out state <rc> on NPort <nlp_DID> */
3089 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3090 ((uint32_t)ndlp->nlp_type));
3091 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3092 "0212 DSM out state %d on NPort x%x "
3093 "rpi x%x Data: x%x x%x\n",
3094 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3098 "DSM out: ste:%d did:x%x flg:x%x",
3099 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3100 /* Decrement the ndlp reference count held for this function */
3103 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3104 "0213 DSM out state %d on NPort free\n", rc);
3106 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3107 "DSM out: ste:%d did:x%x flg:x%x",