1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 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);
251 spin_unlock_irq(&phba->hbalock);
254 INIT_LIST_HEAD(&abort_list);
256 /* Now process the txq */
257 spin_lock_irq(&phba->hbalock);
258 if (phba->sli_rev == LPFC_SLI_REV4)
259 spin_lock(&pring->ring_lock);
261 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
262 /* Check to see if iocb matches the nport we are looking for */
263 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
264 list_del_init(&iocb->list);
265 list_add_tail(&iocb->list, &abort_list);
269 if (phba->sli_rev == LPFC_SLI_REV4)
270 spin_unlock(&pring->ring_lock);
271 spin_unlock_irq(&phba->hbalock);
273 /* Cancel all the IOCBs from the completions list */
274 lpfc_sli_cancel_iocbs(phba, &abort_list,
275 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
277 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
280 /* lpfc_defer_pt2pt_acc - Complete SLI3 pt2pt processing on link up
281 * @phba: pointer to lpfc hba data structure.
282 * @link_mbox: pointer to CONFIG_LINK mailbox object
284 * This routine is only called if we are SLI3, direct connect pt2pt
285 * mode and the remote NPort issues the PLOGI after link up.
288 lpfc_defer_pt2pt_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *link_mbox)
290 LPFC_MBOXQ_t *login_mbox;
291 MAILBOX_t *mb = &link_mbox->u.mb;
292 struct lpfc_iocbq *save_iocb;
293 struct lpfc_nodelist *ndlp;
296 ndlp = link_mbox->ctx_ndlp;
297 login_mbox = link_mbox->context3;
298 save_iocb = login_mbox->context3;
299 link_mbox->context3 = NULL;
300 login_mbox->context3 = NULL;
302 /* Check for CONFIG_LINK error */
304 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
305 "4575 CONFIG_LINK fails pt2pt discovery: %x\n",
307 mempool_free(login_mbox, phba->mbox_mem_pool);
308 mempool_free(link_mbox, phba->mbox_mem_pool);
313 /* Now that CONFIG_LINK completed, and our SID is configured,
314 * we can now proceed with sending the PLOGI ACC.
316 rc = lpfc_els_rsp_acc(link_mbox->vport, ELS_CMD_PLOGI,
317 save_iocb, ndlp, login_mbox);
319 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
320 "4576 PLOGI ACC fails pt2pt discovery: %x\n",
322 mempool_free(login_mbox, phba->mbox_mem_pool);
325 mempool_free(link_mbox, phba->mbox_mem_pool);
330 * lpfc_defer_tgt_acc - Progress SLI4 target rcv PLOGI handler
331 * @phba: Pointer to HBA context object.
332 * @pmb: Pointer to mailbox object.
334 * This function provides the unreg rpi mailbox completion handler for a tgt.
335 * The routine frees the memory resources associated with the completed
336 * mailbox command and transmits the ELS ACC.
338 * This routine is only called if we are SLI4, acting in target
339 * mode and the remote NPort issues the PLOGI after link up.
342 lpfc_defer_acc_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
344 struct lpfc_vport *vport = pmb->vport;
345 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
346 LPFC_MBOXQ_t *mbox = pmb->context3;
347 struct lpfc_iocbq *piocb = NULL;
351 pmb->context3 = NULL;
352 piocb = mbox->context3;
353 mbox->context3 = NULL;
357 * Complete the unreg rpi mbx request, and update flags.
358 * This will also restart any deferred events.
361 lpfc_sli4_unreg_rpi_cmpl_clr(phba, pmb);
364 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
365 "4578 PLOGI ACC fail\n");
367 mempool_free(mbox, phba->mbox_mem_pool);
371 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, piocb, ndlp, mbox);
373 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
374 "4579 PLOGI ACC fail %x\n", rc);
376 mempool_free(mbox, phba->mbox_mem_pool);
384 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
385 struct lpfc_iocbq *cmdiocb)
387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
388 struct lpfc_hba *phba = vport->phba;
389 struct lpfc_dmabuf *pcmd;
390 uint64_t nlp_portwwn = 0;
393 struct serv_parm *sp;
395 LPFC_MBOXQ_t *link_mbox;
396 LPFC_MBOXQ_t *login_mbox;
397 struct lpfc_iocbq *save_iocb;
403 memset(&stat, 0, sizeof (struct ls_rjt));
404 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
405 lp = (uint32_t *) pcmd->virt;
406 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
407 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
408 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
409 "0140 PLOGI Reject: invalid nname\n");
410 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
411 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
412 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
416 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
417 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
418 "0141 PLOGI Reject: invalid pname\n");
419 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
420 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
421 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
426 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
427 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
428 /* Reject this request because invalid parameters */
429 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
430 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
431 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
435 icmd = &cmdiocb->iocb;
437 /* PLOGI chkparm OK */
438 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
439 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
441 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
442 ndlp->nlp_rpi, vport->port_state,
445 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
446 ndlp->nlp_fcp_info |= CLASS2;
448 ndlp->nlp_fcp_info |= CLASS3;
451 ndlp->nlp_class_sup = 0;
452 if (sp->cls1.classValid)
453 ndlp->nlp_class_sup |= FC_COS_CLASS1;
454 if (sp->cls2.classValid)
455 ndlp->nlp_class_sup |= FC_COS_CLASS2;
456 if (sp->cls3.classValid)
457 ndlp->nlp_class_sup |= FC_COS_CLASS3;
458 if (sp->cls4.classValid)
459 ndlp->nlp_class_sup |= FC_COS_CLASS4;
461 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
462 /* if already logged in, do implicit logout */
463 switch (ndlp->nlp_state) {
464 case NLP_STE_NPR_NODE:
465 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
468 case NLP_STE_REG_LOGIN_ISSUE:
469 case NLP_STE_PRLI_ISSUE:
470 case NLP_STE_UNMAPPED_NODE:
471 case NLP_STE_MAPPED_NODE:
472 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
473 * For target mode, execute implicit logo.
474 * Fabric nodes go into NPR.
476 if (!(ndlp->nlp_type & NLP_FABRIC) &&
477 !(phba->nvmet_support)) {
478 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
482 if (nlp_portwwn != 0 &&
483 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
484 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
485 "0143 PLOGI recv'd from DID: x%x "
486 "WWPN changed: old %llx new %llx\n",
488 (unsigned long long)nlp_portwwn,
490 wwn_to_u64(sp->portName.u.wwn));
492 /* Notify transport of connectivity loss to trigger cleanup. */
493 if (phba->nvmet_support &&
494 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
495 lpfc_nvmet_invalidate_host(phba, ndlp);
497 ndlp->nlp_prev_state = ndlp->nlp_state;
498 /* rport needs to be unregistered first */
499 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
503 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
504 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
505 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
506 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
512 /* Check for Nport to NPort pt2pt protocol */
513 if ((vport->fc_flag & FC_PT2PT) &&
514 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
515 /* rcv'ed PLOGI decides what our NPortId will be */
516 vport->fc_myDID = icmd->un.rcvels.parmRo;
518 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
519 if (sp->cmn.edtovResolution) {
520 /* E_D_TOV ticks are in nanoseconds */
521 ed_tov = (phba->fc_edtov + 999999) / 1000000;
525 * For pt-to-pt, use the larger EDTOV
528 if (ed_tov > phba->fc_edtov)
529 phba->fc_edtov = ed_tov;
530 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
532 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
534 /* Issue config_link / reg_vfi to account for updated TOV's */
536 if (phba->sli_rev == LPFC_SLI_REV4)
537 lpfc_issue_reg_vfi(vport);
540 link_mbox = mempool_alloc(phba->mbox_mem_pool,
544 lpfc_config_link(phba, link_mbox);
545 link_mbox->mbox_cmpl = lpfc_defer_pt2pt_acc;
546 link_mbox->vport = vport;
547 link_mbox->ctx_ndlp = ndlp;
549 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
552 /* Save info from cmd IOCB used in rsp */
553 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
554 sizeof(struct lpfc_iocbq));
557 lpfc_can_disctmo(vport);
560 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
561 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
562 sp->cmn.valid_vendor_ver_level) {
563 vid = be32_to_cpu(sp->un.vv.vid);
564 flag = be32_to_cpu(sp->un.vv.flags);
565 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
566 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
569 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
573 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
574 if (phba->nvmet_support && !defer_acc) {
575 link_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
579 /* As unique identifiers such as iotag would be overwritten
580 * with those from the cmdiocb, allocate separate temporary
581 * storage for the copy.
583 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
587 /* Unreg RPI is required for SLI4. */
588 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
589 lpfc_unreg_login(phba, vport->vpi, rpi, link_mbox);
590 link_mbox->vport = vport;
591 link_mbox->ctx_ndlp = ndlp;
592 link_mbox->mbox_cmpl = lpfc_defer_acc_rsp;
594 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
595 (!(vport->fc_flag & FC_OFFLINE_MODE)))
596 ndlp->nlp_flag |= NLP_UNREG_INP;
598 /* Save info from cmd IOCB used in rsp */
599 memcpy(save_iocb, cmdiocb, sizeof(*save_iocb));
601 /* Delay sending ACC till unreg RPI completes. */
603 } else if (phba->sli_rev == LPFC_SLI_REV4)
604 lpfc_unreg_rpi(vport, ndlp);
606 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
607 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
611 /* ACC PLOGI rsp command needs to execute first,
612 * queue this login_mbox command to be processed later.
614 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
616 * login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp) deferred until mailbox
617 * command issued in lpfc_cmpl_els_acc().
619 login_mbox->vport = vport;
620 spin_lock_irq(shost->host_lock);
621 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
622 spin_unlock_irq(shost->host_lock);
625 * If there is an outstanding PLOGI issued, abort it before
626 * sending ACC rsp for received PLOGI. If pending plogi
627 * is not canceled here, the plogi will be rejected by
628 * remote port and will be retried. On a configuration with
629 * single discovery thread, this will cause a huge delay in
630 * discovery. Also this will cause multiple state machines
631 * running in parallel for this node.
632 * This only applies to a fabric environment.
634 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
635 (vport->fc_flag & FC_FABRIC)) {
636 /* software abort outstanding PLOGI */
637 lpfc_els_abort(phba, ndlp);
640 if ((vport->port_type == LPFC_NPIV_PORT &&
641 vport->cfg_restrict_login)) {
643 /* no deferred ACC */
646 /* In order to preserve RPIs, we want to cleanup
647 * the default RPI the firmware created to rcv
648 * this ELS request. The only way to do this is
649 * to register, then unregister the RPI.
651 spin_lock_irq(shost->host_lock);
652 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
653 spin_unlock_irq(shost->host_lock);
654 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
655 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
656 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
659 mempool_free(login_mbox, phba->mbox_mem_pool);
663 /* So the order here should be:
665 * Issue CONFIG_LINK mbox
668 * Issue UNREG RPI mbx
672 * Issue REG_LOGIN mbox
675 /* Save the REG_LOGIN mbox for and rcv IOCB copy later */
676 link_mbox->context3 = login_mbox;
677 login_mbox->context3 = save_iocb;
679 /* Start the ball rolling by issuing CONFIG_LINK here */
680 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
681 if (rc == MBX_NOT_FINISHED)
686 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, login_mbox);
688 mempool_free(login_mbox, phba->mbox_mem_pool);
692 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
693 "4577 discovery failure: %p %p %p\n",
694 save_iocb, link_mbox, login_mbox);
697 mempool_free(link_mbox, phba->mbox_mem_pool);
699 mempool_free(login_mbox, phba->mbox_mem_pool);
701 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
702 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
703 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
708 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
709 * @phba: pointer to lpfc hba data structure.
710 * @mboxq: pointer to mailbox object
712 * This routine is invoked to issue a completion to a rcv'ed
713 * ADISC or PDISC after the paused RPI has been resumed.
716 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
718 struct lpfc_vport *vport;
719 struct lpfc_iocbq *elsiocb;
720 struct lpfc_nodelist *ndlp;
723 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
724 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
725 vport = mboxq->vport;
726 cmd = elsiocb->drvrTimeout;
728 if (cmd == ELS_CMD_ADISC) {
729 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
731 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
735 mempool_free(mboxq, phba->mbox_mem_pool);
739 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
740 struct lpfc_iocbq *cmdiocb)
742 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
743 struct lpfc_iocbq *elsiocb;
744 struct lpfc_dmabuf *pcmd;
745 struct serv_parm *sp;
746 struct lpfc_name *pnn, *ppn;
753 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
754 lp = (uint32_t *) pcmd->virt;
757 if (cmd == ELS_CMD_ADISC) {
759 pnn = (struct lpfc_name *) & ap->nodeName;
760 ppn = (struct lpfc_name *) & ap->portName;
762 sp = (struct serv_parm *) lp;
763 pnn = (struct lpfc_name *) & sp->nodeName;
764 ppn = (struct lpfc_name *) & sp->portName;
767 icmd = &cmdiocb->iocb;
768 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
771 * As soon as we send ACC, the remote NPort can
772 * start sending us data. Thus, for SLI4 we must
773 * resume the RPI before the ACC goes out.
775 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
776 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
780 /* Save info from cmd IOCB used in rsp */
781 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
782 sizeof(struct lpfc_iocbq));
784 /* Save the ELS cmd */
785 elsiocb->drvrTimeout = cmd;
787 if (lpfc_sli4_resume_rpi(ndlp,
788 lpfc_mbx_cmpl_resume_rpi,
795 if (cmd == ELS_CMD_ADISC) {
796 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
798 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
802 /* If we are authenticated, move to the proper state.
803 * It is possible an ADISC arrived and the remote nport
804 * is already in MAPPED or UNMAPPED state. Catch this
805 * condition and don't set the nlp_state again because
806 * it causes an unnecessary transport unregister/register.
808 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
809 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE)
810 lpfc_nlp_set_state(vport, ndlp,
811 NLP_STE_MAPPED_NODE);
816 /* Reject this request because invalid parameters */
817 stat.un.b.lsRjtRsvd0 = 0;
818 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
819 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
820 stat.un.b.vendorUnique = 0;
821 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
824 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
826 spin_lock_irq(shost->host_lock);
827 ndlp->nlp_flag |= NLP_DELAY_TMO;
828 spin_unlock_irq(shost->host_lock);
829 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
830 ndlp->nlp_prev_state = ndlp->nlp_state;
831 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
836 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
837 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
840 struct lpfc_hba *phba = vport->phba;
841 struct lpfc_vport **vports;
842 int i, active_vlink_present = 0 ;
844 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
845 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
846 * PLOGIs during LOGO storms from a device.
848 spin_lock_irq(shost->host_lock);
849 ndlp->nlp_flag |= NLP_LOGO_ACC;
850 spin_unlock_irq(shost->host_lock);
851 if (els_cmd == ELS_CMD_PRLO)
852 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
854 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
856 /* Notify transport of connectivity loss to trigger cleanup. */
857 if (phba->nvmet_support &&
858 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
859 lpfc_nvmet_invalidate_host(phba, ndlp);
861 if (ndlp->nlp_DID == Fabric_DID) {
862 if (vport->port_state <= LPFC_FDISC ||
863 vport->fc_flag & FC_PT2PT)
865 lpfc_linkdown_port(vport);
866 spin_lock_irq(shost->host_lock);
867 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
868 spin_unlock_irq(shost->host_lock);
869 vports = lpfc_create_vport_work_array(phba);
871 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
873 if ((!(vports[i]->fc_flag &
874 FC_VPORT_LOGO_RCVD)) &&
875 (vports[i]->port_state > LPFC_FDISC)) {
876 active_vlink_present = 1;
880 lpfc_destroy_vport_work_array(phba, vports);
884 * Don't re-instantiate if vport is marked for deletion.
885 * If we are here first then vport_delete is going to wait
886 * for discovery to complete.
888 if (!(vport->load_flag & FC_UNLOADING) &&
889 active_vlink_present) {
891 * If there are other active VLinks present,
892 * re-instantiate the Vlink using FDISC.
894 mod_timer(&ndlp->nlp_delayfunc,
895 jiffies + msecs_to_jiffies(1000));
896 spin_lock_irq(shost->host_lock);
897 ndlp->nlp_flag |= NLP_DELAY_TMO;
898 spin_unlock_irq(shost->host_lock);
899 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
900 vport->port_state = LPFC_FDISC;
902 spin_lock_irq(shost->host_lock);
903 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
904 spin_unlock_irq(shost->host_lock);
905 lpfc_retry_pport_discovery(phba);
907 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
908 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
909 (ndlp->nlp_type & NLP_NVME_TARGET) ||
910 (vport->fc_flag & FC_PT2PT))) ||
911 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
912 /* Only try to re-login if this is NOT a Fabric Node
913 * AND the remote NPORT is a FCP/NVME Target or we
914 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
915 * case for LOGO as a response to ADISC behavior.
917 mod_timer(&ndlp->nlp_delayfunc,
918 jiffies + msecs_to_jiffies(1000 * 1));
919 spin_lock_irq(shost->host_lock);
920 ndlp->nlp_flag |= NLP_DELAY_TMO;
921 spin_unlock_irq(shost->host_lock);
923 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
926 ndlp->nlp_prev_state = ndlp->nlp_state;
927 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
929 spin_lock_irq(shost->host_lock);
930 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
931 spin_unlock_irq(shost->host_lock);
932 /* The driver has to wait until the ACC completes before it continues
933 * processing the LOGO. The action will resume in
934 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
935 * unreg_login, the driver waits so the ACC does not get aborted.
941 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
942 struct lpfc_nodelist *ndlp,
943 struct lpfc_iocbq *cmdiocb)
949 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
951 if (vport->phba->nvmet_support) {
952 /* Must be a NVME PRLI */
953 if (cmd == ELS_CMD_PRLI)
956 /* Initiator mode. */
957 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
962 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
963 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
964 "state x%x flags x%x\n",
965 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
967 memset(&stat, 0, sizeof(struct ls_rjt));
968 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
969 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
970 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
976 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
977 struct lpfc_iocbq *cmdiocb)
979 struct lpfc_hba *phba = vport->phba;
980 struct lpfc_dmabuf *pcmd;
983 struct fc_rport *rport = ndlp->rport;
986 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
987 lp = (uint32_t *) pcmd->virt;
988 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
990 if ((npr->prliType == PRLI_FCP_TYPE) ||
991 (npr->prliType == PRLI_NVME_TYPE)) {
992 if (npr->initiatorFunc) {
993 if (npr->prliType == PRLI_FCP_TYPE)
994 ndlp->nlp_type |= NLP_FCP_INITIATOR;
995 if (npr->prliType == PRLI_NVME_TYPE)
996 ndlp->nlp_type |= NLP_NVME_INITIATOR;
998 if (npr->targetFunc) {
999 if (npr->prliType == PRLI_FCP_TYPE)
1000 ndlp->nlp_type |= NLP_FCP_TARGET;
1001 if (npr->prliType == PRLI_NVME_TYPE)
1002 ndlp->nlp_type |= NLP_NVME_TARGET;
1003 if (npr->writeXferRdyDis)
1004 ndlp->nlp_flag |= NLP_FIRSTBURST;
1006 if (npr->Retry && ndlp->nlp_type &
1007 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
1008 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1010 if (npr->Retry && phba->nsler &&
1011 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
1012 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
1015 /* If this driver is in nvme target mode, set the ndlp's fc4
1016 * type to NVME provided the PRLI response claims NVME FC4
1017 * type. Target mode does not issue gft_id so doesn't get
1018 * the fc4 type set until now.
1020 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
1021 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1022 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1024 if (npr->prliType == PRLI_FCP_TYPE)
1025 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1028 /* We need to update the rport role values */
1029 roles = FC_RPORT_ROLE_UNKNOWN;
1030 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1031 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1032 if (ndlp->nlp_type & NLP_FCP_TARGET)
1033 roles |= FC_RPORT_ROLE_FCP_TARGET;
1035 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1036 "rport rolechg: role:x%x did:x%x flg:x%x",
1037 roles, ndlp->nlp_DID, ndlp->nlp_flag);
1039 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1040 fc_remote_port_rolechg(rport, roles);
1045 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1049 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1050 spin_lock_irq(shost->host_lock);
1051 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1052 spin_unlock_irq(shost->host_lock);
1056 if (!(vport->fc_flag & FC_PT2PT)) {
1057 /* Check config parameter use-adisc or FCP-2 */
1058 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1059 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1060 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1061 spin_lock_irq(shost->host_lock);
1062 ndlp->nlp_flag |= NLP_NPR_ADISC;
1063 spin_unlock_irq(shost->host_lock);
1068 spin_lock_irq(shost->host_lock);
1069 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1070 spin_unlock_irq(shost->host_lock);
1071 lpfc_unreg_rpi(vport, ndlp);
1076 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1077 * @phba : Pointer to lpfc_hba structure.
1078 * @vport: Pointer to lpfc_vport structure.
1079 * @ndlp: Pointer to lpfc_nodelist structure.
1080 * @rpi : rpi to be release.
1082 * This function will send a unreg_login mailbox command to the firmware
1086 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1087 struct lpfc_nodelist *ndlp, uint16_t rpi)
1092 /* If there is already an UNREG in progress for this ndlp,
1093 * no need to queue up another one.
1095 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1097 "1435 release_rpi SKIP UNREG x%x on "
1098 "NPort x%x deferred x%x flg x%x "
1100 ndlp->nlp_rpi, ndlp->nlp_DID,
1101 ndlp->nlp_defer_did,
1102 ndlp->nlp_flag, ndlp);
1106 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1109 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1110 "2796 mailbox memory allocation failed \n");
1112 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1113 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1115 pmb->ctx_ndlp = ndlp;
1117 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1118 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1119 ndlp->nlp_flag |= NLP_UNREG_INP;
1121 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1122 "1437 release_rpi UNREG x%x "
1123 "on NPort x%x flg x%x\n",
1124 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1126 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1127 if (rc == MBX_NOT_FINISHED)
1128 mempool_free(pmb, phba->mbox_mem_pool);
1133 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1134 void *arg, uint32_t evt)
1136 struct lpfc_hba *phba;
1137 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1141 /* Release the RPI if reglogin completing */
1142 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1143 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1144 (!pmb->u.mb.mbxStatus)) {
1145 rpi = pmb->u.mb.un.varWords[0];
1146 lpfc_release_rpi(phba, vport, ndlp, rpi);
1148 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1149 "0271 Illegal State Transition: node x%x "
1150 "event x%x, state x%x Data: x%x x%x\n",
1151 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1153 return ndlp->nlp_state;
1157 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1158 void *arg, uint32_t evt)
1160 /* This transition is only legal if we previously
1161 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1162 * working on the same NPortID, do nothing for this thread
1165 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1166 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1167 "0272 Illegal State Transition: node x%x "
1168 "event x%x, state x%x Data: x%x x%x\n",
1169 ndlp->nlp_DID, evt, ndlp->nlp_state,
1170 ndlp->nlp_rpi, ndlp->nlp_flag);
1172 return ndlp->nlp_state;
1175 /* Start of Discovery State Machine routines */
1178 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1179 void *arg, uint32_t evt)
1181 struct lpfc_iocbq *cmdiocb;
1183 cmdiocb = (struct lpfc_iocbq *) arg;
1185 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1186 return ndlp->nlp_state;
1188 return NLP_STE_FREED_NODE;
1192 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1193 void *arg, uint32_t evt)
1195 lpfc_issue_els_logo(vport, ndlp, 0);
1196 return ndlp->nlp_state;
1200 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1201 void *arg, uint32_t evt)
1203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1204 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1206 spin_lock_irq(shost->host_lock);
1207 ndlp->nlp_flag |= NLP_LOGO_ACC;
1208 spin_unlock_irq(shost->host_lock);
1209 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1211 return ndlp->nlp_state;
1215 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1216 void *arg, uint32_t evt)
1218 return NLP_STE_FREED_NODE;
1222 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1223 void *arg, uint32_t evt)
1225 return NLP_STE_FREED_NODE;
1229 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1230 struct lpfc_nodelist *ndlp,
1231 void *arg, uint32_t evt)
1233 return ndlp->nlp_state;
1237 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1238 void *arg, uint32_t evt)
1240 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1241 struct lpfc_hba *phba = vport->phba;
1242 struct lpfc_iocbq *cmdiocb = arg;
1243 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1244 uint32_t *lp = (uint32_t *) pcmd->virt;
1245 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1249 memset(&stat, 0, sizeof (struct ls_rjt));
1251 /* For a PLOGI, we only accept if our portname is less
1252 * than the remote portname.
1254 phba->fc_stat.elsLogiCol++;
1255 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1256 sizeof(struct lpfc_name));
1258 if (port_cmp >= 0) {
1259 /* Reject this request because the remote node will accept
1261 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1262 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1263 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1266 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1267 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1268 (vport->num_disc_nodes)) {
1269 spin_lock_irq(shost->host_lock);
1270 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1271 spin_unlock_irq(shost->host_lock);
1272 /* Check if there are more PLOGIs to be sent */
1273 lpfc_more_plogi(vport);
1274 if (vport->num_disc_nodes == 0) {
1275 spin_lock_irq(shost->host_lock);
1276 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1277 spin_unlock_irq(shost->host_lock);
1278 lpfc_can_disctmo(vport);
1279 lpfc_end_rscn(vport);
1282 } /* If our portname was less */
1284 return ndlp->nlp_state;
1288 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1289 void *arg, uint32_t evt)
1291 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1294 memset(&stat, 0, sizeof (struct ls_rjt));
1295 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1296 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1297 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1298 return ndlp->nlp_state;
1302 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1303 void *arg, uint32_t evt)
1305 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1307 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1308 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1309 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1310 /* software abort outstanding PLOGI */
1311 lpfc_els_abort(vport->phba, ndlp);
1313 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1314 return ndlp->nlp_state;
1318 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1319 void *arg, uint32_t evt)
1321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1322 struct lpfc_hba *phba = vport->phba;
1323 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1325 /* software abort outstanding PLOGI */
1326 lpfc_els_abort(phba, ndlp);
1328 if (evt == NLP_EVT_RCV_LOGO) {
1329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1331 lpfc_issue_els_logo(vport, ndlp, 0);
1334 /* Put ndlp in npr state set plogi timer for 1 sec */
1335 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1336 spin_lock_irq(shost->host_lock);
1337 ndlp->nlp_flag |= NLP_DELAY_TMO;
1338 spin_unlock_irq(shost->host_lock);
1339 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1340 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1341 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1343 return ndlp->nlp_state;
1347 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1348 struct lpfc_nodelist *ndlp,
1352 struct lpfc_hba *phba = vport->phba;
1353 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1354 struct lpfc_iocbq *cmdiocb, *rspiocb;
1355 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1359 struct serv_parm *sp;
1364 cmdiocb = (struct lpfc_iocbq *) arg;
1365 rspiocb = cmdiocb->context_un.rsp_iocb;
1367 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1368 /* Recovery from PLOGI collision logic */
1369 return ndlp->nlp_state;
1372 irsp = &rspiocb->iocb;
1374 if (irsp->ulpStatus)
1377 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1379 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1383 lp = (uint32_t *) prsp->virt;
1384 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1386 /* Some switches have FDMI servers returning 0 for WWN */
1387 if ((ndlp->nlp_DID != FDMI_DID) &&
1388 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1389 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1390 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1391 "0142 PLOGI RSP: Invalid WWN.\n");
1394 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1396 /* PLOGI chkparm OK */
1397 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1398 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1399 ndlp->nlp_DID, ndlp->nlp_state,
1400 ndlp->nlp_flag, ndlp->nlp_rpi);
1401 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1402 ndlp->nlp_fcp_info |= CLASS2;
1404 ndlp->nlp_fcp_info |= CLASS3;
1406 ndlp->nlp_class_sup = 0;
1407 if (sp->cls1.classValid)
1408 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1409 if (sp->cls2.classValid)
1410 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1411 if (sp->cls3.classValid)
1412 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1413 if (sp->cls4.classValid)
1414 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1415 ndlp->nlp_maxframe =
1416 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1418 if ((vport->fc_flag & FC_PT2PT) &&
1419 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1420 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1421 if (sp->cmn.edtovResolution) {
1422 /* E_D_TOV ticks are in nanoseconds */
1423 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1426 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1427 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1428 sp->cmn.valid_vendor_ver_level) {
1429 vid = be32_to_cpu(sp->un.vv.vid);
1430 flag = be32_to_cpu(sp->un.vv.flags);
1431 if ((vid == LPFC_VV_EMLX_ID) &&
1432 (flag & LPFC_VV_SUPPRESS_RSP))
1433 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1437 * Use the larger EDTOV
1438 * RATOV = 2 * EDTOV for pt-to-pt
1440 if (ed_tov > phba->fc_edtov)
1441 phba->fc_edtov = ed_tov;
1442 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1444 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1446 /* Issue config_link / reg_vfi to account for updated TOV's */
1447 if (phba->sli_rev == LPFC_SLI_REV4) {
1448 lpfc_issue_reg_vfi(vport);
1450 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1452 lpfc_printf_vlog(vport, KERN_ERR,
1454 "0133 PLOGI: no memory "
1456 "Data: x%x x%x x%x x%x\n",
1457 ndlp->nlp_DID, ndlp->nlp_state,
1458 ndlp->nlp_flag, ndlp->nlp_rpi);
1462 lpfc_config_link(phba, mbox);
1464 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1465 mbox->vport = vport;
1466 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1467 if (rc == MBX_NOT_FINISHED) {
1468 mempool_free(mbox, phba->mbox_mem_pool);
1474 lpfc_unreg_rpi(vport, ndlp);
1476 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1478 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1479 "0018 PLOGI: no memory for reg_login "
1480 "Data: x%x x%x x%x x%x\n",
1481 ndlp->nlp_DID, ndlp->nlp_state,
1482 ndlp->nlp_flag, ndlp->nlp_rpi);
1486 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1487 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1488 switch (ndlp->nlp_DID) {
1489 case NameServer_DID:
1490 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1493 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1496 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1497 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1499 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1500 mbox->vport = vport;
1501 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1502 != MBX_NOT_FINISHED) {
1503 lpfc_nlp_set_state(vport, ndlp,
1504 NLP_STE_REG_LOGIN_ISSUE);
1505 return ndlp->nlp_state;
1507 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1508 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1509 /* decrement node reference count to the failed mbox
1513 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1514 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1516 mempool_free(mbox, phba->mbox_mem_pool);
1518 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1519 "0134 PLOGI: cannot issue reg_login "
1520 "Data: x%x x%x x%x x%x\n",
1521 ndlp->nlp_DID, ndlp->nlp_state,
1522 ndlp->nlp_flag, ndlp->nlp_rpi);
1524 mempool_free(mbox, phba->mbox_mem_pool);
1526 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1527 "0135 PLOGI: cannot format reg_login "
1528 "Data: x%x x%x x%x x%x\n",
1529 ndlp->nlp_DID, ndlp->nlp_state,
1530 ndlp->nlp_flag, ndlp->nlp_rpi);
1535 if (ndlp->nlp_DID == NameServer_DID) {
1536 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1537 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1538 "0261 Cannot Register NameServer login\n");
1542 ** In case the node reference counter does not go to zero, ensure that
1543 ** the stale state for the node is not processed.
1546 ndlp->nlp_prev_state = ndlp->nlp_state;
1547 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1548 spin_lock_irq(shost->host_lock);
1549 ndlp->nlp_flag |= NLP_DEFER_RM;
1550 spin_unlock_irq(shost->host_lock);
1551 return NLP_STE_FREED_NODE;
1555 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1556 void *arg, uint32_t evt)
1558 return ndlp->nlp_state;
1562 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1563 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1565 struct lpfc_hba *phba;
1566 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1567 MAILBOX_t *mb = &pmb->u.mb;
1571 /* Release the RPI */
1572 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1574 rpi = pmb->u.mb.un.varWords[0];
1575 lpfc_release_rpi(phba, vport, ndlp, rpi);
1577 return ndlp->nlp_state;
1581 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1582 void *arg, uint32_t evt)
1584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1586 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1587 spin_lock_irq(shost->host_lock);
1588 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1589 spin_unlock_irq(shost->host_lock);
1590 return ndlp->nlp_state;
1592 /* software abort outstanding PLOGI */
1593 lpfc_els_abort(vport->phba, ndlp);
1595 lpfc_drop_node(vport, ndlp);
1596 return NLP_STE_FREED_NODE;
1601 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1602 struct lpfc_nodelist *ndlp,
1606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1607 struct lpfc_hba *phba = vport->phba;
1609 /* Don't do anything that will mess up processing of the
1612 if (vport->fc_flag & FC_RSCN_DEFERRED)
1613 return ndlp->nlp_state;
1615 /* software abort outstanding PLOGI */
1616 lpfc_els_abort(phba, ndlp);
1618 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1620 spin_lock_irq(shost->host_lock);
1621 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1622 spin_unlock_irq(shost->host_lock);
1624 return ndlp->nlp_state;
1628 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1629 void *arg, uint32_t evt)
1631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632 struct lpfc_hba *phba = vport->phba;
1633 struct lpfc_iocbq *cmdiocb;
1635 /* software abort outstanding ADISC */
1636 lpfc_els_abort(phba, ndlp);
1638 cmdiocb = (struct lpfc_iocbq *) arg;
1640 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1641 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1642 spin_lock_irq(shost->host_lock);
1643 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1644 spin_unlock_irq(shost->host_lock);
1645 if (vport->num_disc_nodes)
1646 lpfc_more_adisc(vport);
1648 return ndlp->nlp_state;
1650 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1651 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1654 return ndlp->nlp_state;
1658 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1659 void *arg, uint32_t evt)
1661 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1663 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1664 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1665 return ndlp->nlp_state;
1669 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1670 void *arg, uint32_t evt)
1672 struct lpfc_hba *phba = vport->phba;
1673 struct lpfc_iocbq *cmdiocb;
1675 cmdiocb = (struct lpfc_iocbq *) arg;
1677 /* software abort outstanding ADISC */
1678 lpfc_els_abort(phba, ndlp);
1680 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1681 return ndlp->nlp_state;
1685 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1686 struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
1689 struct lpfc_iocbq *cmdiocb;
1691 cmdiocb = (struct lpfc_iocbq *) arg;
1693 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1694 return ndlp->nlp_state;
1698 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1699 void *arg, uint32_t evt)
1701 struct lpfc_iocbq *cmdiocb;
1703 cmdiocb = (struct lpfc_iocbq *) arg;
1705 /* Treat like rcv logo */
1706 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1707 return ndlp->nlp_state;
1711 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1712 struct lpfc_nodelist *ndlp,
1713 void *arg, uint32_t evt)
1715 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1716 struct lpfc_hba *phba = vport->phba;
1717 struct lpfc_iocbq *cmdiocb, *rspiocb;
1722 cmdiocb = (struct lpfc_iocbq *) arg;
1723 rspiocb = cmdiocb->context_un.rsp_iocb;
1725 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1726 irsp = &rspiocb->iocb;
1728 if ((irsp->ulpStatus) ||
1729 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1731 mod_timer(&ndlp->nlp_delayfunc,
1732 jiffies + msecs_to_jiffies(1000));
1733 spin_lock_irq(shost->host_lock);
1734 ndlp->nlp_flag |= NLP_DELAY_TMO;
1735 spin_unlock_irq(shost->host_lock);
1736 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1738 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1739 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1741 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1743 lpfc_unreg_rpi(vport, ndlp);
1744 return ndlp->nlp_state;
1747 if (phba->sli_rev == LPFC_SLI_REV4) {
1748 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1750 /* Stay in state and retry. */
1751 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1752 return ndlp->nlp_state;
1756 if (ndlp->nlp_type & NLP_FCP_TARGET)
1757 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1759 if (ndlp->nlp_type & NLP_NVME_TARGET)
1760 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1762 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1763 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1764 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1766 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1767 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1770 return ndlp->nlp_state;
1774 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1775 void *arg, uint32_t evt)
1777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1779 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1780 spin_lock_irq(shost->host_lock);
1781 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1782 spin_unlock_irq(shost->host_lock);
1783 return ndlp->nlp_state;
1785 /* software abort outstanding ADISC */
1786 lpfc_els_abort(vport->phba, ndlp);
1788 lpfc_drop_node(vport, ndlp);
1789 return NLP_STE_FREED_NODE;
1794 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1795 struct lpfc_nodelist *ndlp,
1799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1800 struct lpfc_hba *phba = vport->phba;
1802 /* Don't do anything that will mess up processing of the
1805 if (vport->fc_flag & FC_RSCN_DEFERRED)
1806 return ndlp->nlp_state;
1808 /* software abort outstanding ADISC */
1809 lpfc_els_abort(phba, ndlp);
1811 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1813 spin_lock_irq(shost->host_lock);
1814 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1815 spin_unlock_irq(shost->host_lock);
1816 lpfc_disc_set_adisc(vport, ndlp);
1817 return ndlp->nlp_state;
1821 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1822 struct lpfc_nodelist *ndlp,
1826 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1828 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1829 return ndlp->nlp_state;
1833 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1834 struct lpfc_nodelist *ndlp,
1838 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1841 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1842 return ndlp->nlp_state;
1844 if (vport->phba->nvmet_support) {
1845 /* NVME Target mode. Handle and respond to the PRLI and
1846 * transition to UNMAPPED provided the RPI has completed
1849 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1850 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1851 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1853 /* RPI registration has not completed. Reject the PRLI
1854 * to prevent an illegal state transition when the
1855 * rpi registration does complete.
1857 memset(&stat, 0, sizeof(struct ls_rjt));
1858 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1859 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1860 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1862 return ndlp->nlp_state;
1865 /* Initiator mode. */
1866 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1868 return ndlp->nlp_state;
1872 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1873 struct lpfc_nodelist *ndlp,
1877 struct lpfc_hba *phba = vport->phba;
1878 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1880 LPFC_MBOXQ_t *nextmb;
1881 struct lpfc_dmabuf *mp;
1882 struct lpfc_nodelist *ns_ndlp;
1884 cmdiocb = (struct lpfc_iocbq *) arg;
1886 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1887 if ((mb = phba->sli.mbox_active)) {
1888 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1889 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1890 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1892 mb->ctx_ndlp = NULL;
1893 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1897 spin_lock_irq(&phba->hbalock);
1898 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1899 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1900 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1901 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1903 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1906 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1908 list_del(&mb->list);
1909 phba->sli.mboxq_cnt--;
1910 mempool_free(mb, phba->mbox_mem_pool);
1913 spin_unlock_irq(&phba->hbalock);
1915 /* software abort if any GID_FT is outstanding */
1916 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1917 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1918 if (ns_ndlp && NLP_CHK_NODE_ACT(ns_ndlp))
1919 lpfc_els_abort(phba, ns_ndlp);
1922 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1923 return ndlp->nlp_state;
1927 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1928 struct lpfc_nodelist *ndlp,
1932 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1934 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1935 return ndlp->nlp_state;
1939 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1940 struct lpfc_nodelist *ndlp,
1944 struct lpfc_iocbq *cmdiocb;
1946 cmdiocb = (struct lpfc_iocbq *) arg;
1947 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1948 return ndlp->nlp_state;
1952 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1953 struct lpfc_nodelist *ndlp,
1957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1958 struct lpfc_hba *phba = vport->phba;
1959 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1960 MAILBOX_t *mb = &pmb->u.mb;
1961 uint32_t did = mb->un.varWords[1];
1963 if (mb->mbxStatus) {
1964 /* RegLogin failed */
1965 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1966 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1968 did, mb->mbxStatus, vport->port_state,
1969 mb->un.varRegLogin.vpi,
1970 mb->un.varRegLogin.rpi);
1972 * If RegLogin failed due to lack of HBA resources do not
1975 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1976 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1978 return ndlp->nlp_state;
1981 /* Put ndlp in npr state set plogi timer for 1 sec */
1982 mod_timer(&ndlp->nlp_delayfunc,
1983 jiffies + msecs_to_jiffies(1000 * 1));
1984 spin_lock_irq(shost->host_lock);
1985 ndlp->nlp_flag |= NLP_DELAY_TMO;
1986 spin_unlock_irq(shost->host_lock);
1987 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1989 lpfc_issue_els_logo(vport, ndlp, 0);
1990 return ndlp->nlp_state;
1993 /* SLI4 ports have preallocated logical rpis. */
1994 if (phba->sli_rev < LPFC_SLI_REV4)
1995 ndlp->nlp_rpi = mb->un.varWords[0];
1997 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1999 /* Only if we are not a fabric nport do we issue PRLI */
2000 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2001 "3066 RegLogin Complete on x%x x%x x%x\n",
2002 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
2003 if (!(ndlp->nlp_type & NLP_FABRIC) &&
2004 (phba->nvmet_support == 0)) {
2005 /* The driver supports FCP and NVME concurrently. If the
2006 * ndlp's nlp_fc4_type is still zero, the driver doesn't
2007 * know what PRLI to send yet. Figure that out now and
2008 * call PRLI depending on the outcome.
2010 if (vport->fc_flag & FC_PT2PT) {
2011 /* If we are pt2pt, there is no Fabric to determine
2012 * the FC4 type of the remote nport. So if NVME
2013 * is configured try it.
2015 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2016 if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
2017 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2018 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2019 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2020 /* We need to update the localport also */
2021 lpfc_nvme_update_localport(vport);
2024 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2025 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2027 } else if (ndlp->nlp_fc4_type == 0) {
2028 /* If we are only configured for FCP, the driver
2029 * should just issue PRLI for FCP. Otherwise issue
2030 * GFT_ID to determine if remote port supports NVME.
2032 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
2033 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
2035 return ndlp->nlp_state;
2037 ndlp->nlp_fc4_type = NLP_FC4_FCP;
2040 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2041 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2042 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
2043 lpfc_issue_els_logo(vport, ndlp, 0);
2044 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2045 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2048 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
2049 phba->targetport->port_id = vport->fc_myDID;
2051 /* Only Fabric ports should transition. NVME target
2052 * must complete PRLI.
2054 if (ndlp->nlp_type & NLP_FABRIC) {
2055 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2056 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2059 return ndlp->nlp_state;
2063 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2064 struct lpfc_nodelist *ndlp,
2068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2070 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2071 spin_lock_irq(shost->host_lock);
2072 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2073 spin_unlock_irq(shost->host_lock);
2074 return ndlp->nlp_state;
2076 lpfc_drop_node(vport, ndlp);
2077 return NLP_STE_FREED_NODE;
2082 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2083 struct lpfc_nodelist *ndlp,
2087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2089 /* Don't do anything that will mess up processing of the
2092 if (vport->fc_flag & FC_RSCN_DEFERRED)
2093 return ndlp->nlp_state;
2095 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2096 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2097 spin_lock_irq(shost->host_lock);
2099 /* If we are a target we won't immediately transition into PRLI,
2100 * so if REG_LOGIN already completed we don't need to ignore it.
2102 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2103 !vport->phba->nvmet_support)
2104 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2106 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2107 spin_unlock_irq(shost->host_lock);
2108 lpfc_disc_set_adisc(vport, ndlp);
2109 return ndlp->nlp_state;
2113 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2114 void *arg, uint32_t evt)
2116 struct lpfc_iocbq *cmdiocb;
2118 cmdiocb = (struct lpfc_iocbq *) arg;
2120 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2121 return ndlp->nlp_state;
2125 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2126 void *arg, uint32_t evt)
2128 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2130 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2131 return ndlp->nlp_state;
2132 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2133 return ndlp->nlp_state;
2137 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2138 void *arg, uint32_t evt)
2140 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2142 /* Software abort outstanding PRLI before sending acc */
2143 lpfc_els_abort(vport->phba, ndlp);
2145 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2146 return ndlp->nlp_state;
2150 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2151 void *arg, uint32_t evt)
2153 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2155 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2156 return ndlp->nlp_state;
2159 /* This routine is envoked when we rcv a PRLO request from a nport
2160 * we are logged into. We should send back a PRLO rsp setting the
2162 * NEXT STATE = PRLI_ISSUE
2165 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2166 void *arg, uint32_t evt)
2168 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2170 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2171 return ndlp->nlp_state;
2175 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2176 void *arg, uint32_t evt)
2178 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2179 struct lpfc_iocbq *cmdiocb, *rspiocb;
2180 struct lpfc_hba *phba = vport->phba;
2183 struct lpfc_nvme_prli *nvpr;
2186 cmdiocb = (struct lpfc_iocbq *) arg;
2187 rspiocb = cmdiocb->context_un.rsp_iocb;
2189 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2190 * format is different so NULL the two PRLI types so that the
2191 * driver correctly gets the correct context.
2195 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2196 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2197 npr = (PRLI *) temp_ptr;
2198 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2199 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2201 irsp = &rspiocb->iocb;
2202 if (irsp->ulpStatus) {
2203 if ((vport->port_type == LPFC_NPIV_PORT) &&
2204 vport->cfg_restrict_login) {
2208 /* Adjust the nlp_type accordingly if the PRLI failed */
2210 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2212 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2214 /* We can't set the DSM state till BOTH PRLIs complete */
2218 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2219 (npr->prliType == PRLI_FCP_TYPE)) {
2220 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2221 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2224 if (npr->initiatorFunc)
2225 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2226 if (npr->targetFunc) {
2227 ndlp->nlp_type |= NLP_FCP_TARGET;
2228 if (npr->writeXferRdyDis)
2229 ndlp->nlp_flag |= NLP_FIRSTBURST;
2232 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2235 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2236 PRLI_REQ_EXECUTED) &&
2237 (bf_get_be32(prli_type_code, nvpr) ==
2240 /* Complete setting up the remote ndlp personality. */
2241 if (bf_get_be32(prli_init, nvpr))
2242 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2244 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2245 bf_get_be32(prli_conf, nvpr))
2247 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2249 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2251 /* Target driver cannot solicit NVME FB. */
2252 if (bf_get_be32(prli_tgt, nvpr)) {
2253 /* Complete the nvme target roles. The transport
2254 * needs to know if the rport is capable of
2255 * discovery in addition to its role.
2257 ndlp->nlp_type |= NLP_NVME_TARGET;
2258 if (bf_get_be32(prli_disc, nvpr))
2259 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2262 * If prli_fba is set, the Target supports FirstBurst.
2263 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2264 * otherwise it defines the actual size supported by
2267 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2268 (phba->cfg_nvme_enable_fb) &&
2269 (!phba->nvmet_support)) {
2270 /* Both sides support FB. The target's first
2271 * burst size is a 512 byte encoded value.
2273 ndlp->nlp_flag |= NLP_FIRSTBURST;
2274 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2277 /* Expressed in units of 512 bytes */
2278 if (ndlp->nvme_fb_size)
2279 ndlp->nvme_fb_size <<=
2282 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2286 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2287 "6029 NVME PRLI Cmpl w1 x%08x "
2288 "w4 x%08x w5 x%08x flag x%x, "
2289 "fcp_info x%x nlp_type x%x\n",
2290 be32_to_cpu(nvpr->word1),
2291 be32_to_cpu(nvpr->word4),
2292 be32_to_cpu(nvpr->word5),
2293 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2296 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2297 (vport->port_type == LPFC_NPIV_PORT) &&
2298 vport->cfg_restrict_login) {
2300 spin_lock_irq(shost->host_lock);
2301 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2302 spin_unlock_irq(shost->host_lock);
2303 lpfc_issue_els_logo(vport, ndlp, 0);
2305 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2306 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2307 return ndlp->nlp_state;
2311 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2314 if (ndlp->fc4_prli_sent == 0) {
2315 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2316 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2317 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2318 else if (ndlp->nlp_type &
2319 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2320 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2322 lpfc_printf_vlog(vport,
2324 "3067 PRLI's still outstanding "
2325 "on x%06x - count %d, Pend Node Mode "
2327 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2329 return ndlp->nlp_state;
2332 /*! lpfc_device_rm_prli_issue
2343 * This routine is envoked when we a request to remove a nport we are in the
2344 * process of PRLIing. We should software abort outstanding prli, unreg
2345 * login, send a logout. We will change node state to UNUSED_NODE, put it
2346 * on plogi list so it can be freed when LOGO completes.
2351 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2352 void *arg, uint32_t evt)
2354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2356 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2357 spin_lock_irq(shost->host_lock);
2358 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2359 spin_unlock_irq(shost->host_lock);
2360 return ndlp->nlp_state;
2362 /* software abort outstanding PLOGI */
2363 lpfc_els_abort(vport->phba, ndlp);
2365 lpfc_drop_node(vport, ndlp);
2366 return NLP_STE_FREED_NODE;
2371 /*! lpfc_device_recov_prli_issue
2382 * The routine is envoked when the state of a device is unknown, like
2383 * during a link down. We should remove the nodelist entry from the
2384 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2385 * outstanding PRLI command, then free the node entry.
2388 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2389 struct lpfc_nodelist *ndlp,
2393 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2394 struct lpfc_hba *phba = vport->phba;
2396 /* Don't do anything that will mess up processing of the
2399 if (vport->fc_flag & FC_RSCN_DEFERRED)
2400 return ndlp->nlp_state;
2402 /* software abort outstanding PRLI */
2403 lpfc_els_abort(phba, ndlp);
2405 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2406 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2407 spin_lock_irq(shost->host_lock);
2408 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2409 spin_unlock_irq(shost->host_lock);
2410 lpfc_disc_set_adisc(vport, ndlp);
2411 return ndlp->nlp_state;
2415 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2416 void *arg, uint32_t evt)
2418 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2421 memset(&stat, 0, sizeof(struct ls_rjt));
2422 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2423 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2424 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2425 return ndlp->nlp_state;
2429 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2430 void *arg, uint32_t evt)
2432 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2435 memset(&stat, 0, sizeof(struct ls_rjt));
2436 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2437 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2438 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2439 return ndlp->nlp_state;
2443 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2444 void *arg, uint32_t evt)
2446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2447 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2449 spin_lock_irq(shost->host_lock);
2450 ndlp->nlp_flag |= NLP_LOGO_ACC;
2451 spin_unlock_irq(shost->host_lock);
2452 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2453 return ndlp->nlp_state;
2457 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2458 void *arg, uint32_t evt)
2460 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2463 memset(&stat, 0, sizeof(struct ls_rjt));
2464 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2465 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2466 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2467 return ndlp->nlp_state;
2471 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2472 void *arg, uint32_t evt)
2474 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2477 memset(&stat, 0, sizeof(struct ls_rjt));
2478 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2479 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2480 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2481 return ndlp->nlp_state;
2485 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2486 void *arg, uint32_t evt)
2488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2490 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2491 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2492 spin_lock_irq(shost->host_lock);
2493 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2494 spin_unlock_irq(shost->host_lock);
2495 lpfc_disc_set_adisc(vport, ndlp);
2496 return ndlp->nlp_state;
2500 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2501 void *arg, uint32_t evt)
2504 * DevLoss has timed out and is calling for Device Remove.
2505 * In this case, abort the LOGO and cleanup the ndlp
2508 lpfc_unreg_rpi(vport, ndlp);
2509 /* software abort outstanding PLOGI */
2510 lpfc_els_abort(vport->phba, ndlp);
2511 lpfc_drop_node(vport, ndlp);
2512 return NLP_STE_FREED_NODE;
2516 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2517 struct lpfc_nodelist *ndlp,
2518 void *arg, uint32_t evt)
2521 * Device Recovery events have no meaning for a node with a LOGO
2522 * outstanding. The LOGO has to complete first and handle the
2523 * node from that point.
2525 return ndlp->nlp_state;
2529 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2530 void *arg, uint32_t evt)
2532 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2534 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2535 return ndlp->nlp_state;
2539 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2540 void *arg, uint32_t evt)
2542 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2544 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2545 return ndlp->nlp_state;
2547 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2548 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2549 return ndlp->nlp_state;
2553 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2554 void *arg, uint32_t evt)
2556 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2558 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2559 return ndlp->nlp_state;
2563 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2564 void *arg, uint32_t evt)
2566 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2568 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2569 return ndlp->nlp_state;
2573 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2574 void *arg, uint32_t evt)
2576 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2578 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2579 return ndlp->nlp_state;
2583 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2584 struct lpfc_nodelist *ndlp,
2588 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2590 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2591 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2592 spin_lock_irq(shost->host_lock);
2593 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2594 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2595 spin_unlock_irq(shost->host_lock);
2596 lpfc_disc_set_adisc(vport, ndlp);
2598 return ndlp->nlp_state;
2602 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2603 void *arg, uint32_t evt)
2605 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2607 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2608 return ndlp->nlp_state;
2612 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2613 void *arg, uint32_t evt)
2615 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2617 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2618 return ndlp->nlp_state;
2619 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2620 return ndlp->nlp_state;
2624 lpfc_rcv_logo_mapped_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 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2630 return ndlp->nlp_state;
2634 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2635 struct lpfc_nodelist *ndlp,
2636 void *arg, uint32_t evt)
2638 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2640 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2641 return ndlp->nlp_state;
2645 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2646 void *arg, uint32_t evt)
2648 struct lpfc_hba *phba = vport->phba;
2649 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2651 /* flush the target */
2652 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2653 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2655 /* Treat like rcv logo */
2656 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2657 return ndlp->nlp_state;
2661 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2662 struct lpfc_nodelist *ndlp,
2666 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2668 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2669 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2670 spin_lock_irq(shost->host_lock);
2671 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2672 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2673 spin_unlock_irq(shost->host_lock);
2674 lpfc_disc_set_adisc(vport, ndlp);
2675 return ndlp->nlp_state;
2679 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2680 void *arg, uint32_t evt)
2682 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2683 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2685 /* Ignore PLOGI if we have an outstanding LOGO */
2686 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2687 return ndlp->nlp_state;
2688 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2689 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2690 spin_lock_irq(shost->host_lock);
2691 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2692 spin_unlock_irq(shost->host_lock);
2693 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2694 /* send PLOGI immediately, move to PLOGI issue state */
2695 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2696 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2697 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2698 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2701 return ndlp->nlp_state;
2705 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2706 void *arg, uint32_t evt)
2708 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2709 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2712 memset(&stat, 0, sizeof (struct ls_rjt));
2713 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2714 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2715 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2717 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2718 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2719 spin_lock_irq(shost->host_lock);
2720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2721 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2722 spin_unlock_irq(shost->host_lock);
2723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2724 lpfc_issue_els_adisc(vport, ndlp, 0);
2726 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2728 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2731 return ndlp->nlp_state;
2735 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2736 void *arg, uint32_t evt)
2738 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2740 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2741 return ndlp->nlp_state;
2745 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2746 void *arg, uint32_t evt)
2748 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2750 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2752 * Do not start discovery if discovery is about to start
2753 * or discovery in progress for this node. Starting discovery
2754 * here will affect the counting of discovery threads.
2756 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2757 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2758 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2759 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2760 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2761 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2762 lpfc_issue_els_adisc(vport, ndlp, 0);
2764 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2766 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2769 return ndlp->nlp_state;
2773 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2774 void *arg, uint32_t evt)
2776 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2777 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2779 spin_lock_irq(shost->host_lock);
2780 ndlp->nlp_flag |= NLP_LOGO_ACC;
2781 spin_unlock_irq(shost->host_lock);
2783 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2785 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2786 mod_timer(&ndlp->nlp_delayfunc,
2787 jiffies + msecs_to_jiffies(1000 * 1));
2788 spin_lock_irq(shost->host_lock);
2789 ndlp->nlp_flag |= NLP_DELAY_TMO;
2790 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2791 spin_unlock_irq(shost->host_lock);
2792 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2794 spin_lock_irq(shost->host_lock);
2795 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2796 spin_unlock_irq(shost->host_lock);
2798 return ndlp->nlp_state;
2802 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2803 void *arg, uint32_t evt)
2805 struct lpfc_iocbq *cmdiocb, *rspiocb;
2807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2809 cmdiocb = (struct lpfc_iocbq *) arg;
2810 rspiocb = cmdiocb->context_un.rsp_iocb;
2812 irsp = &rspiocb->iocb;
2813 if (irsp->ulpStatus) {
2814 spin_lock_irq(shost->host_lock);
2815 ndlp->nlp_flag |= NLP_DEFER_RM;
2816 spin_unlock_irq(shost->host_lock);
2817 return NLP_STE_FREED_NODE;
2819 return ndlp->nlp_state;
2823 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2824 void *arg, uint32_t evt)
2826 struct lpfc_iocbq *cmdiocb, *rspiocb;
2829 cmdiocb = (struct lpfc_iocbq *) arg;
2830 rspiocb = cmdiocb->context_un.rsp_iocb;
2832 irsp = &rspiocb->iocb;
2833 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2834 lpfc_drop_node(vport, ndlp);
2835 return NLP_STE_FREED_NODE;
2837 return ndlp->nlp_state;
2841 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2842 void *arg, uint32_t evt)
2844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2846 /* For the fabric port just clear the fc flags. */
2847 if (ndlp->nlp_DID == Fabric_DID) {
2848 spin_lock_irq(shost->host_lock);
2849 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2850 spin_unlock_irq(shost->host_lock);
2852 lpfc_unreg_rpi(vport, ndlp);
2853 return ndlp->nlp_state;
2857 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2858 void *arg, uint32_t evt)
2860 struct lpfc_iocbq *cmdiocb, *rspiocb;
2863 cmdiocb = (struct lpfc_iocbq *) arg;
2864 rspiocb = cmdiocb->context_un.rsp_iocb;
2866 irsp = &rspiocb->iocb;
2867 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2868 lpfc_drop_node(vport, ndlp);
2869 return NLP_STE_FREED_NODE;
2871 return ndlp->nlp_state;
2875 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2876 struct lpfc_nodelist *ndlp,
2877 void *arg, uint32_t evt)
2879 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2880 MAILBOX_t *mb = &pmb->u.mb;
2882 if (!mb->mbxStatus) {
2883 /* SLI4 ports have preallocated logical rpis. */
2884 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2885 ndlp->nlp_rpi = mb->un.varWords[0];
2886 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2887 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2888 lpfc_unreg_rpi(vport, ndlp);
2891 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2892 lpfc_drop_node(vport, ndlp);
2893 return NLP_STE_FREED_NODE;
2896 return ndlp->nlp_state;
2900 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2901 void *arg, uint32_t evt)
2903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2905 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2906 spin_lock_irq(shost->host_lock);
2907 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2908 spin_unlock_irq(shost->host_lock);
2909 return ndlp->nlp_state;
2911 lpfc_drop_node(vport, ndlp);
2912 return NLP_STE_FREED_NODE;
2916 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2917 void *arg, uint32_t evt)
2919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2921 /* Don't do anything that will mess up processing of the
2924 if (vport->fc_flag & FC_RSCN_DEFERRED)
2925 return ndlp->nlp_state;
2927 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2928 spin_lock_irq(shost->host_lock);
2929 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2930 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2931 spin_unlock_irq(shost->host_lock);
2932 return ndlp->nlp_state;
2936 /* This next section defines the NPort Discovery State Machine */
2938 /* There are 4 different double linked lists nodelist entries can reside on.
2939 * The plogi list and adisc list are used when Link Up discovery or RSCN
2940 * processing is needed. Each list holds the nodes that we will send PLOGI
2941 * or ADISC on. These lists will keep track of what nodes will be effected
2942 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2943 * The unmapped_list will contain all nodes that we have successfully logged
2944 * into at the Fibre Channel level. The mapped_list will contain all nodes
2945 * that are mapped FCP targets.
2948 * The bind list is a list of undiscovered (potentially non-existent) nodes
2949 * that we have saved binding information on. This information is used when
2950 * nodes transition from the unmapped to the mapped list.
2952 /* For UNUSED_NODE state, the node has just been allocated .
2953 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2954 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2955 * and put on the unmapped list. For ADISC processing, the node is taken off
2956 * the ADISC list and placed on either the mapped or unmapped list (depending
2957 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2958 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2959 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2960 * node, the node is taken off the unmapped list. The binding list is checked
2961 * for a valid binding, or a binding is automatically assigned. If binding
2962 * assignment is unsuccessful, the node is left on the unmapped list. If
2963 * binding assignment is successful, the associated binding list entry (if
2964 * any) is removed, and the node is placed on the mapped list.
2967 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2968 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2969 * expire, all effected nodes will receive a DEVICE_RM event.
2972 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2973 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2974 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2975 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2976 * we will first process the ADISC list. 32 entries are processed initially and
2977 * ADISC is initited for each one. Completions / Events for each node are
2978 * funnelled thru the state machine. As each node finishes ADISC processing, it
2979 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2980 * waiting, and the ADISC list count is identically 0, then we are done. For
2981 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2982 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2983 * list. 32 entries are processed initially and PLOGI is initited for each one.
2984 * Completions / Events for each node are funnelled thru the state machine. As
2985 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2986 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2987 * indentically 0, then we are done. We have now completed discovery / RSCN
2988 * handling. Upon completion, ALL nodes should be on either the mapped or
2992 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2993 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2994 /* Action routine Event Current State */
2995 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2996 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2997 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2998 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2999 lpfc_rcv_els_unused_node, /* RCV_PDISC */
3000 lpfc_rcv_els_unused_node, /* RCV_PRLO */
3001 lpfc_disc_illegal, /* CMPL_PLOGI */
3002 lpfc_disc_illegal, /* CMPL_PRLI */
3003 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
3004 lpfc_disc_illegal, /* CMPL_ADISC */
3005 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3006 lpfc_device_rm_unused_node, /* DEVICE_RM */
3007 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
3009 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
3010 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
3011 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
3012 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
3013 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
3014 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
3015 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
3016 lpfc_disc_illegal, /* CMPL_PRLI */
3017 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
3018 lpfc_disc_illegal, /* CMPL_ADISC */
3019 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
3020 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
3021 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
3023 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
3024 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
3025 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
3026 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
3027 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
3028 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
3029 lpfc_disc_illegal, /* CMPL_PLOGI */
3030 lpfc_disc_illegal, /* CMPL_PRLI */
3031 lpfc_disc_illegal, /* CMPL_LOGO */
3032 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
3033 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3034 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
3035 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
3037 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
3038 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
3039 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
3040 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
3041 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
3042 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
3043 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3044 lpfc_disc_illegal, /* CMPL_PRLI */
3045 lpfc_disc_illegal, /* CMPL_LOGO */
3046 lpfc_disc_illegal, /* CMPL_ADISC */
3047 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
3048 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
3049 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
3051 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
3052 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
3053 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
3054 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
3055 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
3056 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
3057 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3058 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
3059 lpfc_disc_illegal, /* CMPL_LOGO */
3060 lpfc_disc_illegal, /* CMPL_ADISC */
3061 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3062 lpfc_device_rm_prli_issue, /* DEVICE_RM */
3063 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
3065 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3066 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3067 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3068 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3069 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3070 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3071 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3072 lpfc_disc_illegal, /* CMPL_PRLI */
3073 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3074 lpfc_disc_illegal, /* CMPL_ADISC */
3075 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3076 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3077 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3079 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3080 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3081 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3082 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3083 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3084 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3085 lpfc_disc_illegal, /* CMPL_PLOGI */
3086 lpfc_disc_illegal, /* CMPL_PRLI */
3087 lpfc_disc_illegal, /* CMPL_LOGO */
3088 lpfc_disc_illegal, /* CMPL_ADISC */
3089 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3090 lpfc_disc_illegal, /* DEVICE_RM */
3091 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3093 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3094 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3095 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3096 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3097 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3098 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3099 lpfc_disc_illegal, /* CMPL_PLOGI */
3100 lpfc_disc_illegal, /* CMPL_PRLI */
3101 lpfc_disc_illegal, /* CMPL_LOGO */
3102 lpfc_disc_illegal, /* CMPL_ADISC */
3103 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3104 lpfc_disc_illegal, /* DEVICE_RM */
3105 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3107 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3108 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3109 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3110 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3111 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3112 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3113 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3114 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3115 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3116 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3117 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3118 lpfc_device_rm_npr_node, /* DEVICE_RM */
3119 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3123 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3124 void *arg, uint32_t evt)
3126 uint32_t cur_state, rc;
3127 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3129 uint32_t got_ndlp = 0;
3132 if (lpfc_nlp_get(ndlp))
3135 cur_state = ndlp->nlp_state;
3137 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3138 ((uint32_t)ndlp->nlp_type));
3139 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3141 "0211 DSM in event x%x on NPort x%x in "
3142 "state %d rpi x%x Data: x%x x%x\n",
3143 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3144 ndlp->nlp_flag, data1);
3146 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3147 "DSM in: evt:%d ste:%d did:x%x",
3148 evt, cur_state, ndlp->nlp_DID);
3150 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3151 rc = (func) (vport, ndlp, arg, evt);
3153 /* DSM out state <rc> on NPort <nlp_DID> */
3155 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3156 ((uint32_t)ndlp->nlp_type));
3157 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3158 "0212 DSM out state %d on NPort x%x "
3159 "rpi x%x Data: x%x x%x\n",
3160 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3163 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3164 "DSM out: ste:%d did:x%x flg:x%x",
3165 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3166 /* Decrement the ndlp reference count held for this function */
3169 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3170 "0213 DSM out state %d on NPort free\n", rc);
3172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3173 "DSM out: ste:%d did:x%x flg:x%x",