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 uint64_t nlp_portwwn = 0;
328 struct serv_parm *sp;
330 LPFC_MBOXQ_t *link_mbox;
331 LPFC_MBOXQ_t *login_mbox;
332 struct lpfc_iocbq *save_iocb;
337 memset(&stat, 0, sizeof (struct ls_rjt));
338 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
339 lp = (uint32_t *) pcmd->virt;
340 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
341 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
342 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
343 "0140 PLOGI Reject: invalid pname\n");
344 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
345 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
346 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
350 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
351 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
352 "0141 PLOGI Reject: invalid nname\n");
353 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
354 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
355 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
360 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
361 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
362 /* Reject this request because invalid parameters */
363 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
364 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
365 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
369 icmd = &cmdiocb->iocb;
371 /* PLOGI chkparm OK */
372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
373 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
375 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
376 ndlp->nlp_rpi, vport->port_state,
379 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
380 ndlp->nlp_fcp_info |= CLASS2;
382 ndlp->nlp_fcp_info |= CLASS3;
384 ndlp->nlp_class_sup = 0;
385 if (sp->cls1.classValid)
386 ndlp->nlp_class_sup |= FC_COS_CLASS1;
387 if (sp->cls2.classValid)
388 ndlp->nlp_class_sup |= FC_COS_CLASS2;
389 if (sp->cls3.classValid)
390 ndlp->nlp_class_sup |= FC_COS_CLASS3;
391 if (sp->cls4.classValid)
392 ndlp->nlp_class_sup |= FC_COS_CLASS4;
394 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
395 /* if already logged in, do implicit logout */
396 switch (ndlp->nlp_state) {
397 case NLP_STE_NPR_NODE:
398 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
401 case NLP_STE_REG_LOGIN_ISSUE:
402 case NLP_STE_PRLI_ISSUE:
403 case NLP_STE_UNMAPPED_NODE:
404 case NLP_STE_MAPPED_NODE:
405 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
406 * For target mode, execute implicit logo.
407 * Fabric nodes go into NPR.
409 if (!(ndlp->nlp_type & NLP_FABRIC) &&
410 !(phba->nvmet_support)) {
411 /* Clear ndlp info, since follow up PRLI may have
412 * updated ndlp information
414 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
415 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
416 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
417 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
418 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
420 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
424 if (nlp_portwwn != 0 &&
425 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
426 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
427 "0143 PLOGI recv'd from DID: x%x "
428 "WWPN changed: old %llx new %llx\n",
430 (unsigned long long)nlp_portwwn,
432 wwn_to_u64(sp->portName.u.wwn));
434 /* Notify transport of connectivity loss to trigger cleanup. */
435 if (phba->nvmet_support &&
436 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
437 lpfc_nvmet_invalidate_host(phba, ndlp);
439 ndlp->nlp_prev_state = ndlp->nlp_state;
440 /* rport needs to be unregistered first */
441 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
445 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
446 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
447 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
448 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
449 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
455 /* Check for Nport to NPort pt2pt protocol */
456 if ((vport->fc_flag & FC_PT2PT) &&
457 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
458 /* rcv'ed PLOGI decides what our NPortId will be */
459 vport->fc_myDID = icmd->un.rcvels.parmRo;
461 /* If there is an outstanding FLOGI, abort it now.
462 * The remote NPort is not going to ACC our FLOGI
463 * if its already issuing a PLOGI for pt2pt mode.
464 * This indicates our FLOGI was dropped; however, we
465 * must have ACCed the remote NPorts FLOGI to us
468 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
469 lpfc_els_abort_flogi(phba);
471 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
472 if (sp->cmn.edtovResolution) {
473 /* E_D_TOV ticks are in nanoseconds */
474 ed_tov = (phba->fc_edtov + 999999) / 1000000;
478 * For pt-to-pt, use the larger EDTOV
481 if (ed_tov > phba->fc_edtov)
482 phba->fc_edtov = ed_tov;
483 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
485 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
487 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
488 * to account for updated TOV's / parameters
490 if (phba->sli_rev == LPFC_SLI_REV4)
491 lpfc_issue_reg_vfi(vport);
493 link_mbox = mempool_alloc(phba->mbox_mem_pool,
497 lpfc_config_link(phba, link_mbox);
498 link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
499 link_mbox->vport = vport;
500 link_mbox->ctx_ndlp = ndlp;
502 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
503 if (rc == MBX_NOT_FINISHED) {
504 mempool_free(link_mbox, phba->mbox_mem_pool);
509 lpfc_can_disctmo(vport);
512 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
513 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
514 sp->cmn.valid_vendor_ver_level) {
515 vid = be32_to_cpu(sp->un.vv.vid);
516 flag = be32_to_cpu(sp->un.vv.flags);
517 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
518 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
521 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
525 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
529 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
530 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
531 sizeof(struct lpfc_iocbq));
533 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
534 if (phba->sli_rev == LPFC_SLI_REV4)
535 lpfc_unreg_rpi(vport, ndlp);
537 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
538 * always be deferring the ACC.
540 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
541 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
545 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
546 login_mbox->vport = vport;
549 * If there is an outstanding PLOGI issued, abort it before
550 * sending ACC rsp for received PLOGI. If pending plogi
551 * is not canceled here, the plogi will be rejected by
552 * remote port and will be retried. On a configuration with
553 * single discovery thread, this will cause a huge delay in
554 * discovery. Also this will cause multiple state machines
555 * running in parallel for this node.
556 * This only applies to a fabric environment.
558 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
559 (vport->fc_flag & FC_FABRIC)) {
560 /* software abort outstanding PLOGI */
561 lpfc_els_abort(phba, ndlp);
564 if ((vport->port_type == LPFC_NPIV_PORT &&
565 vport->cfg_restrict_login)) {
567 /* no deferred ACC */
570 /* This is an NPIV SLI4 instance that does not need to register
573 if (phba->sli_rev == LPFC_SLI_REV4) {
574 mempool_free(login_mbox, phba->mbox_mem_pool);
577 /* In order to preserve RPIs, we want to cleanup
578 * the default RPI the firmware created to rcv
579 * this ELS request. The only way to do this is
580 * to register, then unregister the RPI.
582 spin_lock_irq(&ndlp->lock);
583 ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN |
585 spin_unlock_irq(&ndlp->lock);
588 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
589 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
590 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
593 mempool_free(login_mbox, phba->mbox_mem_pool);
597 /* So the order here should be:
599 * Issue CONFIG_LINK mbox
605 * Issue UNREG RPI mbx
612 login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
613 login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
614 login_mbox->context3 = save_iocb; /* For PLOGI ACC */
616 spin_lock_irq(&ndlp->lock);
617 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
618 spin_unlock_irq(&ndlp->lock);
620 /* Start the ball rolling by issuing REG_LOGIN here */
621 rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
622 if (rc == MBX_NOT_FINISHED)
624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
630 mempool_free(login_mbox, phba->mbox_mem_pool);
632 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
633 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
634 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
639 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
640 * @phba: pointer to lpfc hba data structure.
641 * @mboxq: pointer to mailbox object
643 * This routine is invoked to issue a completion to a rcv'ed
644 * ADISC or PDISC after the paused RPI has been resumed.
647 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
649 struct lpfc_vport *vport;
650 struct lpfc_iocbq *elsiocb;
651 struct lpfc_nodelist *ndlp;
654 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
655 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
656 vport = mboxq->vport;
657 cmd = elsiocb->drvrTimeout;
659 if (cmd == ELS_CMD_ADISC) {
660 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
662 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
666 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
670 mempool_free(mboxq, phba->mbox_mem_pool);
674 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
675 struct lpfc_iocbq *cmdiocb)
677 struct lpfc_iocbq *elsiocb;
678 struct lpfc_dmabuf *pcmd;
679 struct serv_parm *sp;
680 struct lpfc_name *pnn, *ppn;
687 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
688 lp = (uint32_t *) pcmd->virt;
691 if (cmd == ELS_CMD_ADISC) {
693 pnn = (struct lpfc_name *) & ap->nodeName;
694 ppn = (struct lpfc_name *) & ap->portName;
696 sp = (struct serv_parm *) lp;
697 pnn = (struct lpfc_name *) & sp->nodeName;
698 ppn = (struct lpfc_name *) & sp->portName;
701 icmd = &cmdiocb->iocb;
702 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
705 * As soon as we send ACC, the remote NPort can
706 * start sending us data. Thus, for SLI4 we must
707 * resume the RPI before the ACC goes out.
709 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
710 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
714 /* Save info from cmd IOCB used in rsp */
715 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
716 sizeof(struct lpfc_iocbq));
718 /* Save the ELS cmd */
719 elsiocb->drvrTimeout = cmd;
721 lpfc_sli4_resume_rpi(ndlp,
722 lpfc_mbx_cmpl_resume_rpi, elsiocb);
727 if (cmd == ELS_CMD_ADISC) {
728 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
730 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
734 /* If we are authenticated, move to the proper state.
735 * It is possible an ADISC arrived and the remote nport
736 * is already in MAPPED or UNMAPPED state. Catch this
737 * condition and don't set the nlp_state again because
738 * it causes an unnecessary transport unregister/register.
740 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
741 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE)
742 lpfc_nlp_set_state(vport, ndlp,
743 NLP_STE_MAPPED_NODE);
748 /* Reject this request because invalid parameters */
749 stat.un.b.lsRjtRsvd0 = 0;
750 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
751 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
752 stat.un.b.vendorUnique = 0;
753 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
756 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
758 spin_lock_irq(&ndlp->lock);
759 ndlp->nlp_flag |= NLP_DELAY_TMO;
760 spin_unlock_irq(&ndlp->lock);
761 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
762 ndlp->nlp_prev_state = ndlp->nlp_state;
763 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
768 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
769 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
772 struct lpfc_hba *phba = vport->phba;
773 struct lpfc_vport **vports;
774 int i, active_vlink_present = 0 ;
776 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
777 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
778 * PLOGIs during LOGO storms from a device.
780 spin_lock_irq(&ndlp->lock);
781 ndlp->nlp_flag |= NLP_LOGO_ACC;
782 spin_unlock_irq(&ndlp->lock);
783 if (els_cmd == ELS_CMD_PRLO)
784 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
786 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
788 /* This clause allows the initiator to ACC the LOGO back to the
789 * Fabric Domain Controller. It does deliberately skip all other
790 * steps because some fabrics send RDP requests after logging out
791 * from the initiator.
793 if (ndlp->nlp_type & NLP_FABRIC &&
794 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
797 /* Notify transport of connectivity loss to trigger cleanup. */
798 if (phba->nvmet_support &&
799 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
800 lpfc_nvmet_invalidate_host(phba, ndlp);
802 if (ndlp->nlp_DID == Fabric_DID) {
803 if (vport->port_state <= LPFC_FDISC)
805 lpfc_linkdown_port(vport);
806 spin_lock_irq(shost->host_lock);
807 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
808 spin_unlock_irq(shost->host_lock);
809 vports = lpfc_create_vport_work_array(phba);
811 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
813 if ((!(vports[i]->fc_flag &
814 FC_VPORT_LOGO_RCVD)) &&
815 (vports[i]->port_state > LPFC_FDISC)) {
816 active_vlink_present = 1;
820 lpfc_destroy_vport_work_array(phba, vports);
824 * Don't re-instantiate if vport is marked for deletion.
825 * If we are here first then vport_delete is going to wait
826 * for discovery to complete.
828 if (!(vport->load_flag & FC_UNLOADING) &&
829 active_vlink_present) {
831 * If there are other active VLinks present,
832 * re-instantiate the Vlink using FDISC.
834 mod_timer(&ndlp->nlp_delayfunc,
835 jiffies + msecs_to_jiffies(1000));
836 spin_lock_irq(&ndlp->lock);
837 ndlp->nlp_flag |= NLP_DELAY_TMO;
838 spin_unlock_irq(&ndlp->lock);
839 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
840 vport->port_state = LPFC_FDISC;
842 spin_lock_irq(shost->host_lock);
843 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
844 spin_unlock_irq(shost->host_lock);
845 lpfc_retry_pport_discovery(phba);
847 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
848 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
849 (ndlp->nlp_type & NLP_NVME_TARGET) ||
850 (vport->fc_flag & FC_PT2PT))) ||
851 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
852 /* Only try to re-login if this is NOT a Fabric Node
853 * AND the remote NPORT is a FCP/NVME Target or we
854 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
855 * case for LOGO as a response to ADISC behavior.
857 mod_timer(&ndlp->nlp_delayfunc,
858 jiffies + msecs_to_jiffies(1000 * 1));
859 spin_lock_irq(&ndlp->lock);
860 ndlp->nlp_flag |= NLP_DELAY_TMO;
861 spin_unlock_irq(&ndlp->lock);
863 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
866 ndlp->nlp_prev_state = ndlp->nlp_state;
867 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
869 spin_lock_irq(&ndlp->lock);
870 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
871 spin_unlock_irq(&ndlp->lock);
872 /* The driver has to wait until the ACC completes before it continues
873 * processing the LOGO. The action will resume in
874 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
875 * unreg_login, the driver waits so the ACC does not get aborted.
881 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
882 struct lpfc_nodelist *ndlp,
883 struct lpfc_iocbq *cmdiocb)
889 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
891 if (vport->phba->nvmet_support) {
892 /* Must be a NVME PRLI */
893 if (cmd == ELS_CMD_PRLI)
896 /* Initiator mode. */
897 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
902 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
903 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
904 "state x%x flags x%x\n",
905 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
907 memset(&stat, 0, sizeof(struct ls_rjt));
908 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
909 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
910 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
916 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
917 struct lpfc_iocbq *cmdiocb)
919 struct lpfc_hba *phba = vport->phba;
920 struct lpfc_dmabuf *pcmd;
923 struct fc_rport *rport = ndlp->rport;
926 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
927 lp = (uint32_t *) pcmd->virt;
928 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
930 if ((npr->prliType == PRLI_FCP_TYPE) ||
931 (npr->prliType == PRLI_NVME_TYPE)) {
932 if (npr->initiatorFunc) {
933 if (npr->prliType == PRLI_FCP_TYPE)
934 ndlp->nlp_type |= NLP_FCP_INITIATOR;
935 if (npr->prliType == PRLI_NVME_TYPE)
936 ndlp->nlp_type |= NLP_NVME_INITIATOR;
938 if (npr->targetFunc) {
939 if (npr->prliType == PRLI_FCP_TYPE)
940 ndlp->nlp_type |= NLP_FCP_TARGET;
941 if (npr->prliType == PRLI_NVME_TYPE)
942 ndlp->nlp_type |= NLP_NVME_TARGET;
943 if (npr->writeXferRdyDis)
944 ndlp->nlp_flag |= NLP_FIRSTBURST;
946 if (npr->Retry && ndlp->nlp_type &
947 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
948 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
950 if (npr->Retry && phba->nsler &&
951 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
952 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
955 /* If this driver is in nvme target mode, set the ndlp's fc4
956 * type to NVME provided the PRLI response claims NVME FC4
957 * type. Target mode does not issue gft_id so doesn't get
958 * the fc4 type set until now.
960 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
961 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
962 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
965 /* Fabric Controllers send FCP PRLI as an initiator but should
966 * not get recognized as FCP type and registered with transport.
968 if (npr->prliType == PRLI_FCP_TYPE &&
969 !(ndlp->nlp_type & NLP_FABRIC))
970 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
973 /* We need to update the rport role values */
974 roles = FC_RPORT_ROLE_UNKNOWN;
975 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
976 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
977 if (ndlp->nlp_type & NLP_FCP_TARGET)
978 roles |= FC_RPORT_ROLE_FCP_TARGET;
980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
981 "rport rolechg: role:x%x did:x%x flg:x%x",
982 roles, ndlp->nlp_DID, ndlp->nlp_flag);
984 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
985 fc_remote_port_rolechg(rport, roles);
990 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
992 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
993 spin_lock_irq(&ndlp->lock);
994 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
995 spin_unlock_irq(&ndlp->lock);
999 if (!(vport->fc_flag & FC_PT2PT)) {
1000 /* Check config parameter use-adisc or FCP-2 */
1001 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1002 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1003 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1004 spin_lock_irq(&ndlp->lock);
1005 ndlp->nlp_flag |= NLP_NPR_ADISC;
1006 spin_unlock_irq(&ndlp->lock);
1011 spin_lock_irq(&ndlp->lock);
1012 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1013 spin_unlock_irq(&ndlp->lock);
1014 lpfc_unreg_rpi(vport, ndlp);
1019 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1020 * @phba : Pointer to lpfc_hba structure.
1021 * @vport: Pointer to lpfc_vport structure.
1022 * @ndlp: Pointer to lpfc_nodelist structure.
1023 * @rpi : rpi to be release.
1025 * This function will send a unreg_login mailbox command to the firmware
1029 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1030 struct lpfc_nodelist *ndlp, uint16_t rpi)
1035 /* If there is already an UNREG in progress for this ndlp,
1036 * no need to queue up another one.
1038 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1039 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1040 "1435 release_rpi SKIP UNREG x%x on "
1041 "NPort x%x deferred x%x flg x%x "
1043 ndlp->nlp_rpi, ndlp->nlp_DID,
1044 ndlp->nlp_defer_did,
1045 ndlp->nlp_flag, ndlp);
1049 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1052 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1053 "2796 mailbox memory allocation failed \n");
1055 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1056 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1058 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1059 if (!pmb->ctx_ndlp) {
1060 mempool_free(pmb, phba->mbox_mem_pool);
1064 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1065 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1066 ndlp->nlp_flag |= NLP_UNREG_INP;
1068 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1069 "1437 release_rpi UNREG x%x "
1070 "on NPort x%x flg x%x\n",
1071 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1073 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1074 if (rc == MBX_NOT_FINISHED)
1075 mempool_free(pmb, phba->mbox_mem_pool);
1080 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1081 void *arg, uint32_t evt)
1083 struct lpfc_hba *phba;
1084 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1088 /* Release the RPI if reglogin completing */
1089 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1090 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1091 (!pmb->u.mb.mbxStatus)) {
1092 rpi = pmb->u.mb.un.varWords[0];
1093 lpfc_release_rpi(phba, vport, ndlp, rpi);
1095 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1096 "0271 Illegal State Transition: node x%x "
1097 "event x%x, state x%x Data: x%x x%x\n",
1098 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1100 return ndlp->nlp_state;
1104 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1105 void *arg, uint32_t evt)
1107 /* This transition is only legal if we previously
1108 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1109 * working on the same NPortID, do nothing for this thread
1112 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1114 "0272 Illegal State Transition: node x%x "
1115 "event x%x, state x%x Data: x%x x%x\n",
1116 ndlp->nlp_DID, evt, ndlp->nlp_state,
1117 ndlp->nlp_rpi, ndlp->nlp_flag);
1119 return ndlp->nlp_state;
1122 /* Start of Discovery State Machine routines */
1125 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1126 void *arg, uint32_t evt)
1128 struct lpfc_iocbq *cmdiocb;
1130 cmdiocb = (struct lpfc_iocbq *) arg;
1132 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1133 return ndlp->nlp_state;
1135 return NLP_STE_FREED_NODE;
1139 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1140 void *arg, uint32_t evt)
1142 lpfc_issue_els_logo(vport, ndlp, 0);
1143 return ndlp->nlp_state;
1147 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1148 void *arg, uint32_t evt)
1150 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1152 spin_lock_irq(&ndlp->lock);
1153 ndlp->nlp_flag |= NLP_LOGO_ACC;
1154 spin_unlock_irq(&ndlp->lock);
1155 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1157 return ndlp->nlp_state;
1161 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1162 void *arg, uint32_t evt)
1164 return NLP_STE_FREED_NODE;
1168 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1169 void *arg, uint32_t evt)
1171 return NLP_STE_FREED_NODE;
1175 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1176 struct lpfc_nodelist *ndlp,
1177 void *arg, uint32_t evt)
1179 return ndlp->nlp_state;
1183 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1184 void *arg, uint32_t evt)
1186 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1187 struct lpfc_hba *phba = vport->phba;
1188 struct lpfc_iocbq *cmdiocb = arg;
1189 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1190 uint32_t *lp = (uint32_t *) pcmd->virt;
1191 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1195 memset(&stat, 0, sizeof (struct ls_rjt));
1197 /* For a PLOGI, we only accept if our portname is less
1198 * than the remote portname.
1200 phba->fc_stat.elsLogiCol++;
1201 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1202 sizeof(struct lpfc_name));
1204 if (port_cmp >= 0) {
1205 /* Reject this request because the remote node will accept
1207 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1208 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1209 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1212 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1213 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1214 (vport->num_disc_nodes)) {
1215 spin_lock_irq(&ndlp->lock);
1216 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1217 spin_unlock_irq(&ndlp->lock);
1218 /* Check if there are more PLOGIs to be sent */
1219 lpfc_more_plogi(vport);
1220 if (vport->num_disc_nodes == 0) {
1221 spin_lock_irq(shost->host_lock);
1222 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1223 spin_unlock_irq(shost->host_lock);
1224 lpfc_can_disctmo(vport);
1225 lpfc_end_rscn(vport);
1228 } /* If our portname was less */
1230 return ndlp->nlp_state;
1234 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1235 void *arg, uint32_t evt)
1237 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1240 memset(&stat, 0, sizeof (struct ls_rjt));
1241 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1242 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1243 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1244 return ndlp->nlp_state;
1248 lpfc_rcv_logo_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;
1253 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1254 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1255 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1256 /* software abort outstanding PLOGI */
1257 lpfc_els_abort(vport->phba, ndlp);
1259 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1260 return ndlp->nlp_state;
1264 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1265 void *arg, uint32_t evt)
1267 struct lpfc_hba *phba = vport->phba;
1268 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1270 /* software abort outstanding PLOGI */
1271 lpfc_els_abort(phba, ndlp);
1273 if (evt == NLP_EVT_RCV_LOGO) {
1274 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1276 lpfc_issue_els_logo(vport, ndlp, 0);
1279 /* Put ndlp in npr state set plogi timer for 1 sec */
1280 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1281 spin_lock_irq(&ndlp->lock);
1282 ndlp->nlp_flag |= NLP_DELAY_TMO;
1283 spin_unlock_irq(&ndlp->lock);
1284 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1285 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1288 return ndlp->nlp_state;
1292 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1293 struct lpfc_nodelist *ndlp,
1297 struct lpfc_hba *phba = vport->phba;
1298 struct lpfc_iocbq *cmdiocb, *rspiocb;
1299 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1303 struct serv_parm *sp;
1308 cmdiocb = (struct lpfc_iocbq *) arg;
1309 rspiocb = cmdiocb->context_un.rsp_iocb;
1311 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1312 /* Recovery from PLOGI collision logic */
1313 return ndlp->nlp_state;
1316 irsp = &rspiocb->iocb;
1318 if (irsp->ulpStatus)
1321 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1323 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1327 lp = (uint32_t *) prsp->virt;
1328 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1330 /* Some switches have FDMI servers returning 0 for WWN */
1331 if ((ndlp->nlp_DID != FDMI_DID) &&
1332 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1333 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1334 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1335 "0142 PLOGI RSP: Invalid WWN.\n");
1338 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1340 /* PLOGI chkparm OK */
1341 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1342 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1343 ndlp->nlp_DID, ndlp->nlp_state,
1344 ndlp->nlp_flag, ndlp->nlp_rpi);
1345 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1346 ndlp->nlp_fcp_info |= CLASS2;
1348 ndlp->nlp_fcp_info |= CLASS3;
1350 ndlp->nlp_class_sup = 0;
1351 if (sp->cls1.classValid)
1352 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1353 if (sp->cls2.classValid)
1354 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1355 if (sp->cls3.classValid)
1356 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1357 if (sp->cls4.classValid)
1358 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1359 ndlp->nlp_maxframe =
1360 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1362 if ((vport->fc_flag & FC_PT2PT) &&
1363 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1364 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1365 if (sp->cmn.edtovResolution) {
1366 /* E_D_TOV ticks are in nanoseconds */
1367 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1370 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1371 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1372 sp->cmn.valid_vendor_ver_level) {
1373 vid = be32_to_cpu(sp->un.vv.vid);
1374 flag = be32_to_cpu(sp->un.vv.flags);
1375 if ((vid == LPFC_VV_EMLX_ID) &&
1376 (flag & LPFC_VV_SUPPRESS_RSP))
1377 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1381 * Use the larger EDTOV
1382 * RATOV = 2 * EDTOV for pt-to-pt
1384 if (ed_tov > phba->fc_edtov)
1385 phba->fc_edtov = ed_tov;
1386 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1388 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1390 /* Issue config_link / reg_vfi to account for updated TOV's */
1391 if (phba->sli_rev == LPFC_SLI_REV4) {
1392 lpfc_issue_reg_vfi(vport);
1394 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1396 lpfc_printf_vlog(vport, KERN_ERR,
1398 "0133 PLOGI: no memory "
1400 "Data: x%x x%x x%x x%x\n",
1401 ndlp->nlp_DID, ndlp->nlp_state,
1402 ndlp->nlp_flag, ndlp->nlp_rpi);
1406 lpfc_config_link(phba, mbox);
1408 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1409 mbox->vport = vport;
1410 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1411 if (rc == MBX_NOT_FINISHED) {
1412 mempool_free(mbox, phba->mbox_mem_pool);
1418 lpfc_unreg_rpi(vport, ndlp);
1420 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1422 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1423 "0018 PLOGI: no memory for reg_login "
1424 "Data: x%x x%x x%x x%x\n",
1425 ndlp->nlp_DID, ndlp->nlp_state,
1426 ndlp->nlp_flag, ndlp->nlp_rpi);
1430 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1431 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1432 switch (ndlp->nlp_DID) {
1433 case NameServer_DID:
1434 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1435 /* Fabric Controller Node needs these parameters. */
1436 memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
1439 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1442 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1443 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1446 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1447 if (!mbox->ctx_ndlp)
1450 mbox->vport = vport;
1451 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1452 != MBX_NOT_FINISHED) {
1453 lpfc_nlp_set_state(vport, ndlp,
1454 NLP_STE_REG_LOGIN_ISSUE);
1455 return ndlp->nlp_state;
1457 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1458 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1459 /* decrement node reference count to the failed mbox
1463 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1464 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1466 mempool_free(mbox, phba->mbox_mem_pool);
1468 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1469 "0134 PLOGI: cannot issue reg_login "
1470 "Data: x%x x%x x%x x%x\n",
1471 ndlp->nlp_DID, ndlp->nlp_state,
1472 ndlp->nlp_flag, ndlp->nlp_rpi);
1474 mempool_free(mbox, phba->mbox_mem_pool);
1476 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1477 "0135 PLOGI: cannot format reg_login "
1478 "Data: x%x x%x x%x x%x\n",
1479 ndlp->nlp_DID, ndlp->nlp_state,
1480 ndlp->nlp_flag, ndlp->nlp_rpi);
1485 if (ndlp->nlp_DID == NameServer_DID) {
1486 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1487 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1488 "0261 Cannot Register NameServer login\n");
1492 ** In case the node reference counter does not go to zero, ensure that
1493 ** the stale state for the node is not processed.
1496 ndlp->nlp_prev_state = ndlp->nlp_state;
1497 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1498 return NLP_STE_FREED_NODE;
1502 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1503 void *arg, uint32_t evt)
1505 return ndlp->nlp_state;
1509 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1510 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1512 struct lpfc_hba *phba;
1513 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1514 MAILBOX_t *mb = &pmb->u.mb;
1518 /* Release the RPI */
1519 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1521 rpi = pmb->u.mb.un.varWords[0];
1522 lpfc_release_rpi(phba, vport, ndlp, rpi);
1524 return ndlp->nlp_state;
1528 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1529 void *arg, uint32_t evt)
1531 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1532 spin_lock_irq(&ndlp->lock);
1533 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1534 spin_unlock_irq(&ndlp->lock);
1535 return ndlp->nlp_state;
1537 /* software abort outstanding PLOGI */
1538 lpfc_els_abort(vport->phba, ndlp);
1540 lpfc_drop_node(vport, ndlp);
1541 return NLP_STE_FREED_NODE;
1546 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1547 struct lpfc_nodelist *ndlp,
1551 struct lpfc_hba *phba = vport->phba;
1553 /* Don't do anything that will mess up processing of the
1556 if (vport->fc_flag & FC_RSCN_DEFERRED)
1557 return ndlp->nlp_state;
1559 /* software abort outstanding PLOGI */
1560 lpfc_els_abort(phba, ndlp);
1562 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1563 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1564 spin_lock_irq(&ndlp->lock);
1565 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1566 spin_unlock_irq(&ndlp->lock);
1568 return ndlp->nlp_state;
1572 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1573 void *arg, uint32_t evt)
1575 struct lpfc_hba *phba = vport->phba;
1576 struct lpfc_iocbq *cmdiocb;
1578 /* software abort outstanding ADISC */
1579 lpfc_els_abort(phba, ndlp);
1581 cmdiocb = (struct lpfc_iocbq *) arg;
1583 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1584 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1585 spin_lock_irq(&ndlp->lock);
1586 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1587 spin_unlock_irq(&ndlp->lock);
1588 if (vport->num_disc_nodes)
1589 lpfc_more_adisc(vport);
1591 return ndlp->nlp_state;
1593 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1594 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1595 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1597 return ndlp->nlp_state;
1601 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1602 void *arg, uint32_t evt)
1604 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1606 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1607 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1608 return ndlp->nlp_state;
1612 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1613 void *arg, uint32_t evt)
1615 struct lpfc_hba *phba = vport->phba;
1616 struct lpfc_iocbq *cmdiocb;
1618 cmdiocb = (struct lpfc_iocbq *) arg;
1620 /* software abort outstanding ADISC */
1621 lpfc_els_abort(phba, ndlp);
1623 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1624 return ndlp->nlp_state;
1628 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1629 struct lpfc_nodelist *ndlp,
1630 void *arg, uint32_t evt)
1632 struct lpfc_iocbq *cmdiocb;
1634 cmdiocb = (struct lpfc_iocbq *) arg;
1636 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1637 return ndlp->nlp_state;
1641 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1642 void *arg, uint32_t evt)
1644 struct lpfc_iocbq *cmdiocb;
1646 cmdiocb = (struct lpfc_iocbq *) arg;
1648 /* Treat like rcv logo */
1649 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1650 return ndlp->nlp_state;
1654 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1655 struct lpfc_nodelist *ndlp,
1656 void *arg, uint32_t evt)
1658 struct lpfc_hba *phba = vport->phba;
1659 struct lpfc_iocbq *cmdiocb, *rspiocb;
1664 cmdiocb = (struct lpfc_iocbq *) arg;
1665 rspiocb = cmdiocb->context_un.rsp_iocb;
1667 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1668 irsp = &rspiocb->iocb;
1670 if ((irsp->ulpStatus) ||
1671 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1673 mod_timer(&ndlp->nlp_delayfunc,
1674 jiffies + msecs_to_jiffies(1000));
1675 spin_lock_irq(&ndlp->lock);
1676 ndlp->nlp_flag |= NLP_DELAY_TMO;
1677 spin_unlock_irq(&ndlp->lock);
1678 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1680 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1681 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1683 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1684 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1685 lpfc_unreg_rpi(vport, ndlp);
1686 return ndlp->nlp_state;
1689 if (phba->sli_rev == LPFC_SLI_REV4) {
1690 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1692 /* Stay in state and retry. */
1693 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1694 return ndlp->nlp_state;
1698 if (ndlp->nlp_type & NLP_FCP_TARGET)
1699 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1701 if (ndlp->nlp_type & NLP_NVME_TARGET)
1702 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1704 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1705 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1708 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1709 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1712 return ndlp->nlp_state;
1716 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1717 void *arg, uint32_t evt)
1719 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1720 spin_lock_irq(&ndlp->lock);
1721 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1722 spin_unlock_irq(&ndlp->lock);
1723 return ndlp->nlp_state;
1725 /* software abort outstanding ADISC */
1726 lpfc_els_abort(vport->phba, ndlp);
1728 lpfc_drop_node(vport, ndlp);
1729 return NLP_STE_FREED_NODE;
1734 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1735 struct lpfc_nodelist *ndlp,
1739 struct lpfc_hba *phba = vport->phba;
1741 /* Don't do anything that will mess up processing of the
1744 if (vport->fc_flag & FC_RSCN_DEFERRED)
1745 return ndlp->nlp_state;
1747 /* software abort outstanding ADISC */
1748 lpfc_els_abort(phba, ndlp);
1750 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1751 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1752 spin_lock_irq(&ndlp->lock);
1753 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1754 spin_unlock_irq(&ndlp->lock);
1755 lpfc_disc_set_adisc(vport, ndlp);
1756 return ndlp->nlp_state;
1760 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1761 struct lpfc_nodelist *ndlp,
1765 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1767 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1768 return ndlp->nlp_state;
1772 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1773 struct lpfc_nodelist *ndlp,
1777 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1780 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1781 return ndlp->nlp_state;
1783 if (vport->phba->nvmet_support) {
1784 /* NVME Target mode. Handle and respond to the PRLI and
1785 * transition to UNMAPPED provided the RPI has completed
1788 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1789 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1790 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1792 /* RPI registration has not completed. Reject the PRLI
1793 * to prevent an illegal state transition when the
1794 * rpi registration does complete.
1796 memset(&stat, 0, sizeof(struct ls_rjt));
1797 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1798 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1799 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1801 return ndlp->nlp_state;
1804 /* Initiator mode. */
1805 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1807 return ndlp->nlp_state;
1811 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1812 struct lpfc_nodelist *ndlp,
1816 struct lpfc_hba *phba = vport->phba;
1817 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1819 LPFC_MBOXQ_t *nextmb;
1820 struct lpfc_dmabuf *mp;
1821 struct lpfc_nodelist *ns_ndlp;
1823 cmdiocb = (struct lpfc_iocbq *) arg;
1825 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1826 if ((mb = phba->sli.mbox_active)) {
1827 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1828 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1829 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1831 mb->ctx_ndlp = NULL;
1832 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1836 spin_lock_irq(&phba->hbalock);
1837 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1838 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1839 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1840 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1842 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1845 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1847 list_del(&mb->list);
1848 phba->sli.mboxq_cnt--;
1849 mempool_free(mb, phba->mbox_mem_pool);
1852 spin_unlock_irq(&phba->hbalock);
1854 /* software abort if any GID_FT is outstanding */
1855 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1856 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1858 lpfc_els_abort(phba, ns_ndlp);
1861 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1862 return ndlp->nlp_state;
1866 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1867 struct lpfc_nodelist *ndlp,
1871 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1873 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1874 return ndlp->nlp_state;
1878 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1879 struct lpfc_nodelist *ndlp,
1883 struct lpfc_iocbq *cmdiocb;
1885 cmdiocb = (struct lpfc_iocbq *) arg;
1886 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1887 return ndlp->nlp_state;
1891 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1892 struct lpfc_nodelist *ndlp,
1896 struct lpfc_hba *phba = vport->phba;
1897 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1898 MAILBOX_t *mb = &pmb->u.mb;
1899 uint32_t did = mb->un.varWords[1];
1901 if (mb->mbxStatus) {
1902 /* RegLogin failed */
1903 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1904 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1906 did, mb->mbxStatus, vport->port_state,
1907 mb->un.varRegLogin.vpi,
1908 mb->un.varRegLogin.rpi);
1910 * If RegLogin failed due to lack of HBA resources do not
1913 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1914 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1916 return ndlp->nlp_state;
1919 /* Put ndlp in npr state set plogi timer for 1 sec */
1920 mod_timer(&ndlp->nlp_delayfunc,
1921 jiffies + msecs_to_jiffies(1000 * 1));
1922 spin_lock_irq(&ndlp->lock);
1923 ndlp->nlp_flag |= NLP_DELAY_TMO;
1924 spin_unlock_irq(&ndlp->lock);
1925 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1927 lpfc_issue_els_logo(vport, ndlp, 0);
1928 return ndlp->nlp_state;
1931 /* SLI4 ports have preallocated logical rpis. */
1932 if (phba->sli_rev < LPFC_SLI_REV4)
1933 ndlp->nlp_rpi = mb->un.varWords[0];
1935 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1937 /* Only if we are not a fabric nport do we issue PRLI */
1938 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1939 "3066 RegLogin Complete on x%x x%x x%x\n",
1940 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1941 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1942 (phba->nvmet_support == 0)) {
1943 /* The driver supports FCP and NVME concurrently. If the
1944 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1945 * know what PRLI to send yet. Figure that out now and
1946 * call PRLI depending on the outcome.
1948 if (vport->fc_flag & FC_PT2PT) {
1949 /* If we are pt2pt, there is no Fabric to determine
1950 * the FC4 type of the remote nport. So if NVME
1951 * is configured try it.
1953 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1954 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1955 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1956 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1957 /* We need to update the localport also */
1958 lpfc_nvme_update_localport(vport);
1961 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1962 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1964 } else if (ndlp->nlp_fc4_type == 0) {
1965 /* If we are only configured for FCP, the driver
1966 * should just issue PRLI for FCP. Otherwise issue
1967 * GFT_ID to determine if remote port supports NVME.
1969 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1970 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
1972 return ndlp->nlp_state;
1974 ndlp->nlp_fc4_type = NLP_FC4_FCP;
1977 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1978 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1979 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
1980 lpfc_issue_els_logo(vport, ndlp, 0);
1981 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1985 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1986 phba->targetport->port_id = vport->fc_myDID;
1988 /* Only Fabric ports should transition. NVME target
1989 * must complete PRLI.
1991 if (ndlp->nlp_type & NLP_FABRIC) {
1992 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
1993 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1997 return ndlp->nlp_state;
2001 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2002 struct lpfc_nodelist *ndlp,
2006 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2007 spin_lock_irq(&ndlp->lock);
2008 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2009 spin_unlock_irq(&ndlp->lock);
2010 return ndlp->nlp_state;
2012 lpfc_drop_node(vport, ndlp);
2013 return NLP_STE_FREED_NODE;
2018 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2019 struct lpfc_nodelist *ndlp,
2023 /* Don't do anything that will mess up processing of the
2026 if (vport->fc_flag & FC_RSCN_DEFERRED)
2027 return ndlp->nlp_state;
2029 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2030 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2031 spin_lock_irq(&ndlp->lock);
2033 /* If we are a target we won't immediately transition into PRLI,
2034 * so if REG_LOGIN already completed we don't need to ignore it.
2036 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2037 !vport->phba->nvmet_support)
2038 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2040 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2041 spin_unlock_irq(&ndlp->lock);
2042 lpfc_disc_set_adisc(vport, ndlp);
2043 return ndlp->nlp_state;
2047 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2048 void *arg, uint32_t evt)
2050 struct lpfc_iocbq *cmdiocb;
2052 cmdiocb = (struct lpfc_iocbq *) arg;
2054 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2055 return ndlp->nlp_state;
2059 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2060 void *arg, uint32_t evt)
2062 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2064 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2065 return ndlp->nlp_state;
2066 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2067 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2068 return ndlp->nlp_state;
2072 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2073 void *arg, uint32_t evt)
2075 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2077 /* Software abort outstanding PRLI before sending acc */
2078 lpfc_els_abort(vport->phba, ndlp);
2080 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2081 return ndlp->nlp_state;
2085 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2086 void *arg, uint32_t evt)
2088 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2090 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2091 return ndlp->nlp_state;
2094 /* This routine is envoked when we rcv a PRLO request from a nport
2095 * we are logged into. We should send back a PRLO rsp setting the
2097 * NEXT STATE = PRLI_ISSUE
2100 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2101 void *arg, uint32_t evt)
2103 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2105 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2106 return ndlp->nlp_state;
2110 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2111 void *arg, uint32_t evt)
2113 struct lpfc_iocbq *cmdiocb, *rspiocb;
2114 struct lpfc_hba *phba = vport->phba;
2117 struct lpfc_nvme_prli *nvpr;
2120 cmdiocb = (struct lpfc_iocbq *) arg;
2121 rspiocb = cmdiocb->context_un.rsp_iocb;
2123 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2124 * format is different so NULL the two PRLI types so that the
2125 * driver correctly gets the correct context.
2129 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2130 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2131 npr = (PRLI *) temp_ptr;
2132 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2133 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2135 irsp = &rspiocb->iocb;
2136 if (irsp->ulpStatus) {
2137 if ((vport->port_type == LPFC_NPIV_PORT) &&
2138 vport->cfg_restrict_login) {
2142 /* Adjust the nlp_type accordingly if the PRLI failed */
2144 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2146 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2148 /* We can't set the DSM state till BOTH PRLIs complete */
2152 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2153 (npr->prliType == PRLI_FCP_TYPE)) {
2154 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2155 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2158 if (npr->initiatorFunc)
2159 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2160 if (npr->targetFunc) {
2161 ndlp->nlp_type |= NLP_FCP_TARGET;
2162 if (npr->writeXferRdyDis)
2163 ndlp->nlp_flag |= NLP_FIRSTBURST;
2166 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2169 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2170 PRLI_REQ_EXECUTED) &&
2171 (bf_get_be32(prli_type_code, nvpr) ==
2174 /* Complete setting up the remote ndlp personality. */
2175 if (bf_get_be32(prli_init, nvpr))
2176 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2178 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2179 bf_get_be32(prli_conf, nvpr))
2181 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2183 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2185 /* Target driver cannot solicit NVME FB. */
2186 if (bf_get_be32(prli_tgt, nvpr)) {
2187 /* Complete the nvme target roles. The transport
2188 * needs to know if the rport is capable of
2189 * discovery in addition to its role.
2191 ndlp->nlp_type |= NLP_NVME_TARGET;
2192 if (bf_get_be32(prli_disc, nvpr))
2193 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2196 * If prli_fba is set, the Target supports FirstBurst.
2197 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2198 * otherwise it defines the actual size supported by
2201 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2202 (phba->cfg_nvme_enable_fb) &&
2203 (!phba->nvmet_support)) {
2204 /* Both sides support FB. The target's first
2205 * burst size is a 512 byte encoded value.
2207 ndlp->nlp_flag |= NLP_FIRSTBURST;
2208 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2211 /* Expressed in units of 512 bytes */
2212 if (ndlp->nvme_fb_size)
2213 ndlp->nvme_fb_size <<=
2216 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2220 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2221 "6029 NVME PRLI Cmpl w1 x%08x "
2222 "w4 x%08x w5 x%08x flag x%x, "
2223 "fcp_info x%x nlp_type x%x\n",
2224 be32_to_cpu(nvpr->word1),
2225 be32_to_cpu(nvpr->word4),
2226 be32_to_cpu(nvpr->word5),
2227 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2230 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2231 (vport->port_type == LPFC_NPIV_PORT) &&
2232 vport->cfg_restrict_login) {
2234 spin_lock_irq(&ndlp->lock);
2235 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2236 spin_unlock_irq(&ndlp->lock);
2237 lpfc_issue_els_logo(vport, ndlp, 0);
2239 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2240 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2241 return ndlp->nlp_state;
2245 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2248 if (ndlp->fc4_prli_sent == 0) {
2249 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2250 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2251 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2252 else if (ndlp->nlp_type &
2253 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2254 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2256 lpfc_printf_vlog(vport,
2258 "3067 PRLI's still outstanding "
2259 "on x%06x - count %d, Pend Node Mode "
2261 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2263 return ndlp->nlp_state;
2266 /*! lpfc_device_rm_prli_issue
2277 * This routine is envoked when we a request to remove a nport we are in the
2278 * process of PRLIing. We should software abort outstanding prli, unreg
2279 * login, send a logout. We will change node state to UNUSED_NODE, put it
2280 * on plogi list so it can be freed when LOGO completes.
2285 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2286 void *arg, uint32_t evt)
2288 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2289 spin_lock_irq(&ndlp->lock);
2290 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2291 spin_unlock_irq(&ndlp->lock);
2292 return ndlp->nlp_state;
2294 /* software abort outstanding PLOGI */
2295 lpfc_els_abort(vport->phba, ndlp);
2297 lpfc_drop_node(vport, ndlp);
2298 return NLP_STE_FREED_NODE;
2303 /*! lpfc_device_recov_prli_issue
2314 * The routine is envoked when the state of a device is unknown, like
2315 * during a link down. We should remove the nodelist entry from the
2316 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2317 * outstanding PRLI command, then free the node entry.
2320 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2321 struct lpfc_nodelist *ndlp,
2325 struct lpfc_hba *phba = vport->phba;
2327 /* Don't do anything that will mess up processing of the
2330 if (vport->fc_flag & FC_RSCN_DEFERRED)
2331 return ndlp->nlp_state;
2333 /* software abort outstanding PRLI */
2334 lpfc_els_abort(phba, ndlp);
2336 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2337 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2338 spin_lock_irq(&ndlp->lock);
2339 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2340 spin_unlock_irq(&ndlp->lock);
2341 lpfc_disc_set_adisc(vport, ndlp);
2342 return ndlp->nlp_state;
2346 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2347 void *arg, uint32_t evt)
2349 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2352 memset(&stat, 0, sizeof(struct ls_rjt));
2353 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2354 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2355 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2356 return ndlp->nlp_state;
2360 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2361 void *arg, uint32_t evt)
2363 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2366 memset(&stat, 0, sizeof(struct ls_rjt));
2367 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2368 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2369 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2370 return ndlp->nlp_state;
2374 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2375 void *arg, uint32_t evt)
2377 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2379 spin_lock_irq(&ndlp->lock);
2380 ndlp->nlp_flag |= NLP_LOGO_ACC;
2381 spin_unlock_irq(&ndlp->lock);
2382 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2383 return ndlp->nlp_state;
2387 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2388 void *arg, uint32_t evt)
2390 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2393 memset(&stat, 0, sizeof(struct ls_rjt));
2394 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2395 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2396 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2397 return ndlp->nlp_state;
2401 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2402 void *arg, uint32_t evt)
2404 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2407 memset(&stat, 0, sizeof(struct ls_rjt));
2408 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2409 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2410 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2411 return ndlp->nlp_state;
2415 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2416 void *arg, uint32_t evt)
2418 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2419 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2420 spin_lock_irq(&ndlp->lock);
2421 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2422 spin_unlock_irq(&ndlp->lock);
2423 lpfc_disc_set_adisc(vport, ndlp);
2424 return ndlp->nlp_state;
2428 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2429 void *arg, uint32_t evt)
2432 * DevLoss has timed out and is calling for Device Remove.
2433 * In this case, abort the LOGO and cleanup the ndlp
2436 lpfc_unreg_rpi(vport, ndlp);
2437 /* software abort outstanding PLOGI */
2438 lpfc_els_abort(vport->phba, ndlp);
2439 lpfc_drop_node(vport, ndlp);
2440 return NLP_STE_FREED_NODE;
2444 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2445 struct lpfc_nodelist *ndlp,
2446 void *arg, uint32_t evt)
2449 * Device Recovery events have no meaning for a node with a LOGO
2450 * outstanding. The LOGO has to complete first and handle the
2451 * node from that point.
2453 return ndlp->nlp_state;
2457 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2458 void *arg, uint32_t evt)
2460 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2462 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2463 return ndlp->nlp_state;
2467 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2468 void *arg, uint32_t evt)
2470 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2472 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2473 return ndlp->nlp_state;
2475 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2476 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2477 return ndlp->nlp_state;
2481 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2482 void *arg, uint32_t evt)
2484 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2486 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2487 return ndlp->nlp_state;
2491 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2492 void *arg, uint32_t evt)
2494 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2496 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2497 return ndlp->nlp_state;
2501 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2502 void *arg, uint32_t evt)
2504 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2506 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2507 return ndlp->nlp_state;
2511 lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2512 struct lpfc_nodelist *ndlp,
2516 lpfc_drop_node(vport, ndlp);
2517 return NLP_STE_FREED_NODE;
2521 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2522 struct lpfc_nodelist *ndlp,
2526 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2527 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2528 spin_lock_irq(&ndlp->lock);
2529 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2530 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2531 spin_unlock_irq(&ndlp->lock);
2532 lpfc_disc_set_adisc(vport, ndlp);
2534 return ndlp->nlp_state;
2538 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2539 void *arg, uint32_t evt)
2541 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2543 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2544 return ndlp->nlp_state;
2548 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2549 void *arg, uint32_t evt)
2551 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2553 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2554 return ndlp->nlp_state;
2555 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2556 return ndlp->nlp_state;
2560 lpfc_rcv_logo_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 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2566 return ndlp->nlp_state;
2570 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2571 struct lpfc_nodelist *ndlp,
2572 void *arg, uint32_t evt)
2574 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2576 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2577 return ndlp->nlp_state;
2581 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2582 void *arg, uint32_t evt)
2584 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2586 /* flush the target */
2587 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2589 /* Treat like rcv logo */
2590 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2591 return ndlp->nlp_state;
2595 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2596 struct lpfc_nodelist *ndlp,
2600 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2601 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2602 spin_lock_irq(&ndlp->lock);
2603 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2604 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2605 spin_unlock_irq(&ndlp->lock);
2606 lpfc_disc_set_adisc(vport, ndlp);
2607 return ndlp->nlp_state;
2611 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2612 void *arg, uint32_t evt)
2614 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2616 /* Ignore PLOGI if we have an outstanding LOGO */
2617 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2618 return ndlp->nlp_state;
2619 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2620 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2621 spin_lock_irq(&ndlp->lock);
2622 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2623 spin_unlock_irq(&ndlp->lock);
2624 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2625 /* send PLOGI immediately, move to PLOGI issue state */
2626 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2627 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2628 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2629 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2632 return ndlp->nlp_state;
2636 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2637 void *arg, uint32_t evt)
2639 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2642 memset(&stat, 0, sizeof (struct ls_rjt));
2643 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2644 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2645 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2647 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2648 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2649 spin_lock_irq(&ndlp->lock);
2650 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2651 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2652 spin_unlock_irq(&ndlp->lock);
2653 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2654 lpfc_issue_els_adisc(vport, ndlp, 0);
2656 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2657 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2658 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2661 return ndlp->nlp_state;
2665 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2666 void *arg, uint32_t evt)
2668 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2670 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2671 return ndlp->nlp_state;
2675 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2676 void *arg, uint32_t evt)
2678 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2680 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2682 * Do not start discovery if discovery is about to start
2683 * or discovery in progress for this node. Starting discovery
2684 * here will affect the counting of discovery threads.
2686 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2687 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2688 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2689 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2690 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2691 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2692 lpfc_issue_els_adisc(vport, ndlp, 0);
2694 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2695 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2696 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2699 return ndlp->nlp_state;
2703 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2704 void *arg, uint32_t evt)
2706 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2708 spin_lock_irq(&ndlp->lock);
2709 ndlp->nlp_flag |= NLP_LOGO_ACC;
2710 spin_unlock_irq(&ndlp->lock);
2712 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2714 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2715 mod_timer(&ndlp->nlp_delayfunc,
2716 jiffies + msecs_to_jiffies(1000 * 1));
2717 spin_lock_irq(&ndlp->lock);
2718 ndlp->nlp_flag |= NLP_DELAY_TMO;
2719 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2720 spin_unlock_irq(&ndlp->lock);
2721 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2723 spin_lock_irq(&ndlp->lock);
2724 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2725 spin_unlock_irq(&ndlp->lock);
2727 return ndlp->nlp_state;
2731 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2732 void *arg, uint32_t evt)
2734 struct lpfc_iocbq *cmdiocb, *rspiocb;
2737 cmdiocb = (struct lpfc_iocbq *) arg;
2738 rspiocb = cmdiocb->context_un.rsp_iocb;
2740 irsp = &rspiocb->iocb;
2741 if (irsp->ulpStatus) {
2742 return NLP_STE_FREED_NODE;
2744 return ndlp->nlp_state;
2748 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2749 void *arg, uint32_t evt)
2751 struct lpfc_iocbq *cmdiocb, *rspiocb;
2754 cmdiocb = (struct lpfc_iocbq *) arg;
2755 rspiocb = cmdiocb->context_un.rsp_iocb;
2757 irsp = &rspiocb->iocb;
2758 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2759 lpfc_drop_node(vport, ndlp);
2760 return NLP_STE_FREED_NODE;
2762 return ndlp->nlp_state;
2766 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2767 void *arg, uint32_t evt)
2769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2771 /* For the fabric port just clear the fc flags. */
2772 if (ndlp->nlp_DID == Fabric_DID) {
2773 spin_lock_irq(shost->host_lock);
2774 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2775 spin_unlock_irq(shost->host_lock);
2777 lpfc_unreg_rpi(vport, ndlp);
2778 return ndlp->nlp_state;
2782 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2783 void *arg, uint32_t evt)
2785 struct lpfc_iocbq *cmdiocb, *rspiocb;
2788 cmdiocb = (struct lpfc_iocbq *) arg;
2789 rspiocb = cmdiocb->context_un.rsp_iocb;
2791 irsp = &rspiocb->iocb;
2792 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2793 lpfc_drop_node(vport, ndlp);
2794 return NLP_STE_FREED_NODE;
2796 return ndlp->nlp_state;
2800 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2801 struct lpfc_nodelist *ndlp,
2802 void *arg, uint32_t evt)
2804 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2805 MAILBOX_t *mb = &pmb->u.mb;
2807 if (!mb->mbxStatus) {
2808 /* SLI4 ports have preallocated logical rpis. */
2809 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2810 ndlp->nlp_rpi = mb->un.varWords[0];
2811 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2812 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2813 lpfc_unreg_rpi(vport, ndlp);
2816 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2817 lpfc_drop_node(vport, ndlp);
2818 return NLP_STE_FREED_NODE;
2821 return ndlp->nlp_state;
2825 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2826 void *arg, uint32_t evt)
2828 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2829 spin_lock_irq(&ndlp->lock);
2830 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2831 spin_unlock_irq(&ndlp->lock);
2832 return ndlp->nlp_state;
2834 lpfc_drop_node(vport, ndlp);
2835 return NLP_STE_FREED_NODE;
2839 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2840 void *arg, uint32_t evt)
2842 /* Don't do anything that will mess up processing of the
2845 if (vport->fc_flag & FC_RSCN_DEFERRED)
2846 return ndlp->nlp_state;
2848 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2849 spin_lock_irq(&ndlp->lock);
2850 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2851 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2852 spin_unlock_irq(&ndlp->lock);
2853 return ndlp->nlp_state;
2857 /* This next section defines the NPort Discovery State Machine */
2859 /* There are 4 different double linked lists nodelist entries can reside on.
2860 * The plogi list and adisc list are used when Link Up discovery or RSCN
2861 * processing is needed. Each list holds the nodes that we will send PLOGI
2862 * or ADISC on. These lists will keep track of what nodes will be effected
2863 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2864 * The unmapped_list will contain all nodes that we have successfully logged
2865 * into at the Fibre Channel level. The mapped_list will contain all nodes
2866 * that are mapped FCP targets.
2869 * The bind list is a list of undiscovered (potentially non-existent) nodes
2870 * that we have saved binding information on. This information is used when
2871 * nodes transition from the unmapped to the mapped list.
2873 /* For UNUSED_NODE state, the node has just been allocated .
2874 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2875 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2876 * and put on the unmapped list. For ADISC processing, the node is taken off
2877 * the ADISC list and placed on either the mapped or unmapped list (depending
2878 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2879 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2880 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2881 * node, the node is taken off the unmapped list. The binding list is checked
2882 * for a valid binding, or a binding is automatically assigned. If binding
2883 * assignment is unsuccessful, the node is left on the unmapped list. If
2884 * binding assignment is successful, the associated binding list entry (if
2885 * any) is removed, and the node is placed on the mapped list.
2888 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2889 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2890 * expire, all effected nodes will receive a DEVICE_RM event.
2893 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2894 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2895 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2896 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2897 * we will first process the ADISC list. 32 entries are processed initially and
2898 * ADISC is initited for each one. Completions / Events for each node are
2899 * funnelled thru the state machine. As each node finishes ADISC processing, it
2900 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2901 * waiting, and the ADISC list count is identically 0, then we are done. For
2902 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2903 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2904 * list. 32 entries are processed initially and PLOGI is initited for each one.
2905 * Completions / Events for each node are funnelled thru the state machine. As
2906 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2907 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2908 * indentically 0, then we are done. We have now completed discovery / RSCN
2909 * handling. Upon completion, ALL nodes should be on either the mapped or
2913 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2914 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2915 /* Action routine Event Current State */
2916 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2917 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2918 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2919 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2920 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2921 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2922 lpfc_disc_illegal, /* CMPL_PLOGI */
2923 lpfc_disc_illegal, /* CMPL_PRLI */
2924 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2925 lpfc_disc_illegal, /* CMPL_ADISC */
2926 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2927 lpfc_device_rm_unused_node, /* DEVICE_RM */
2928 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2930 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2931 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2932 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2933 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2934 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2935 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2936 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2937 lpfc_disc_illegal, /* CMPL_PRLI */
2938 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2939 lpfc_disc_illegal, /* CMPL_ADISC */
2940 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2941 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2942 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2944 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2945 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2946 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2947 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2948 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2949 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2950 lpfc_disc_illegal, /* CMPL_PLOGI */
2951 lpfc_disc_illegal, /* CMPL_PRLI */
2952 lpfc_disc_illegal, /* CMPL_LOGO */
2953 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2954 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2955 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2956 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2958 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2959 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2960 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2961 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2962 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2963 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2964 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2965 lpfc_disc_illegal, /* CMPL_PRLI */
2966 lpfc_disc_illegal, /* CMPL_LOGO */
2967 lpfc_disc_illegal, /* CMPL_ADISC */
2968 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2969 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2970 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2972 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2973 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2974 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2975 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2976 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2977 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2978 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2979 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2980 lpfc_disc_illegal, /* CMPL_LOGO */
2981 lpfc_disc_illegal, /* CMPL_ADISC */
2982 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2983 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2984 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2986 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2987 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2988 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2989 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2990 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2991 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2992 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2993 lpfc_disc_illegal, /* CMPL_PRLI */
2994 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2995 lpfc_disc_illegal, /* CMPL_ADISC */
2996 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2997 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2998 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3000 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3001 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3002 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3003 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3004 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3005 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3006 lpfc_disc_illegal, /* CMPL_PLOGI */
3007 lpfc_disc_illegal, /* CMPL_PRLI */
3008 lpfc_disc_illegal, /* CMPL_LOGO */
3009 lpfc_disc_illegal, /* CMPL_ADISC */
3010 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3011 lpfc_device_rm_unmap_node, /* DEVICE_RM */
3012 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3014 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3015 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3016 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3017 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3018 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3019 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3020 lpfc_disc_illegal, /* CMPL_PLOGI */
3021 lpfc_disc_illegal, /* CMPL_PRLI */
3022 lpfc_disc_illegal, /* CMPL_LOGO */
3023 lpfc_disc_illegal, /* CMPL_ADISC */
3024 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3025 lpfc_disc_illegal, /* DEVICE_RM */
3026 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3028 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3029 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3030 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3031 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3032 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3033 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3034 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3035 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3036 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3037 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3038 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3039 lpfc_device_rm_npr_node, /* DEVICE_RM */
3040 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3044 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3045 void *arg, uint32_t evt)
3047 uint32_t cur_state, rc;
3048 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3050 uint32_t got_ndlp = 0;
3053 if (lpfc_nlp_get(ndlp))
3056 cur_state = ndlp->nlp_state;
3058 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3059 ((uint32_t)ndlp->nlp_type));
3060 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3061 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3062 "0211 DSM in event x%x on NPort x%x in "
3063 "state %d rpi x%x Data: x%x x%x\n",
3064 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3065 ndlp->nlp_flag, data1);
3067 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3068 "DSM in: evt:%d ste:%d did:x%x",
3069 evt, cur_state, ndlp->nlp_DID);
3071 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3072 rc = (func) (vport, ndlp, arg, evt);
3074 /* DSM out state <rc> on NPort <nlp_DID> */
3076 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3077 ((uint32_t)ndlp->nlp_type));
3078 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3079 "0212 DSM out state %d on NPort x%x "
3080 "rpi x%x Data: x%x x%x\n",
3081 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3085 "DSM out: ste:%d did:x%x flg:x%x",
3086 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3087 /* Decrement the ndlp reference count held for this function */
3090 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3091 "0213 DSM out state %d on NPort free\n", rc);
3093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3094 "DSM out: ste:%d did:x%x flg:x%x",