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 lpfc_sli4_resume_rpi(ndlp,
788 lpfc_mbx_cmpl_resume_rpi, elsiocb);
793 if (cmd == ELS_CMD_ADISC) {
794 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
796 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
800 /* If we are authenticated, move to the proper state.
801 * It is possible an ADISC arrived and the remote nport
802 * is already in MAPPED or UNMAPPED state. Catch this
803 * condition and don't set the nlp_state again because
804 * it causes an unnecessary transport unregister/register.
806 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
807 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE)
808 lpfc_nlp_set_state(vport, ndlp,
809 NLP_STE_MAPPED_NODE);
814 /* Reject this request because invalid parameters */
815 stat.un.b.lsRjtRsvd0 = 0;
816 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
817 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
818 stat.un.b.vendorUnique = 0;
819 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
822 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
824 spin_lock_irq(shost->host_lock);
825 ndlp->nlp_flag |= NLP_DELAY_TMO;
826 spin_unlock_irq(shost->host_lock);
827 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
828 ndlp->nlp_prev_state = ndlp->nlp_state;
829 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
834 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
835 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
837 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
838 struct lpfc_hba *phba = vport->phba;
839 struct lpfc_vport **vports;
840 int i, active_vlink_present = 0 ;
842 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
843 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
844 * PLOGIs during LOGO storms from a device.
846 spin_lock_irq(shost->host_lock);
847 ndlp->nlp_flag |= NLP_LOGO_ACC;
848 spin_unlock_irq(shost->host_lock);
849 if (els_cmd == ELS_CMD_PRLO)
850 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
852 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
854 /* Notify transport of connectivity loss to trigger cleanup. */
855 if (phba->nvmet_support &&
856 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
857 lpfc_nvmet_invalidate_host(phba, ndlp);
859 if (ndlp->nlp_DID == Fabric_DID) {
860 if (vport->port_state <= LPFC_FDISC ||
861 vport->fc_flag & FC_PT2PT)
863 lpfc_linkdown_port(vport);
864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
866 spin_unlock_irq(shost->host_lock);
867 vports = lpfc_create_vport_work_array(phba);
869 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
871 if ((!(vports[i]->fc_flag &
872 FC_VPORT_LOGO_RCVD)) &&
873 (vports[i]->port_state > LPFC_FDISC)) {
874 active_vlink_present = 1;
878 lpfc_destroy_vport_work_array(phba, vports);
882 * Don't re-instantiate if vport is marked for deletion.
883 * If we are here first then vport_delete is going to wait
884 * for discovery to complete.
886 if (!(vport->load_flag & FC_UNLOADING) &&
887 active_vlink_present) {
889 * If there are other active VLinks present,
890 * re-instantiate the Vlink using FDISC.
892 mod_timer(&ndlp->nlp_delayfunc,
893 jiffies + msecs_to_jiffies(1000));
894 spin_lock_irq(shost->host_lock);
895 ndlp->nlp_flag |= NLP_DELAY_TMO;
896 spin_unlock_irq(shost->host_lock);
897 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
898 vport->port_state = LPFC_FDISC;
900 spin_lock_irq(shost->host_lock);
901 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
902 spin_unlock_irq(shost->host_lock);
903 lpfc_retry_pport_discovery(phba);
905 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
906 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
907 (ndlp->nlp_type & NLP_NVME_TARGET) ||
908 (vport->fc_flag & FC_PT2PT))) ||
909 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
910 /* Only try to re-login if this is NOT a Fabric Node
911 * AND the remote NPORT is a FCP/NVME Target or we
912 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
913 * case for LOGO as a response to ADISC behavior.
915 mod_timer(&ndlp->nlp_delayfunc,
916 jiffies + msecs_to_jiffies(1000 * 1));
917 spin_lock_irq(shost->host_lock);
918 ndlp->nlp_flag |= NLP_DELAY_TMO;
919 spin_unlock_irq(shost->host_lock);
921 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
924 ndlp->nlp_prev_state = ndlp->nlp_state;
925 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
927 spin_lock_irq(shost->host_lock);
928 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
929 spin_unlock_irq(shost->host_lock);
930 /* The driver has to wait until the ACC completes before it continues
931 * processing the LOGO. The action will resume in
932 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
933 * unreg_login, the driver waits so the ACC does not get aborted.
939 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
940 struct lpfc_nodelist *ndlp,
941 struct lpfc_iocbq *cmdiocb)
947 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
949 if (vport->phba->nvmet_support) {
950 /* Must be a NVME PRLI */
951 if (cmd == ELS_CMD_PRLI)
954 /* Initiator mode. */
955 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
960 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
961 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
962 "state x%x flags x%x\n",
963 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
965 memset(&stat, 0, sizeof(struct ls_rjt));
966 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
967 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
968 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
974 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
975 struct lpfc_iocbq *cmdiocb)
977 struct lpfc_hba *phba = vport->phba;
978 struct lpfc_dmabuf *pcmd;
981 struct fc_rport *rport = ndlp->rport;
984 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
985 lp = (uint32_t *) pcmd->virt;
986 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
988 if ((npr->prliType == PRLI_FCP_TYPE) ||
989 (npr->prliType == PRLI_NVME_TYPE)) {
990 if (npr->initiatorFunc) {
991 if (npr->prliType == PRLI_FCP_TYPE)
992 ndlp->nlp_type |= NLP_FCP_INITIATOR;
993 if (npr->prliType == PRLI_NVME_TYPE)
994 ndlp->nlp_type |= NLP_NVME_INITIATOR;
996 if (npr->targetFunc) {
997 if (npr->prliType == PRLI_FCP_TYPE)
998 ndlp->nlp_type |= NLP_FCP_TARGET;
999 if (npr->prliType == PRLI_NVME_TYPE)
1000 ndlp->nlp_type |= NLP_NVME_TARGET;
1001 if (npr->writeXferRdyDis)
1002 ndlp->nlp_flag |= NLP_FIRSTBURST;
1004 if (npr->Retry && ndlp->nlp_type &
1005 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
1006 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1008 if (npr->Retry && phba->nsler &&
1009 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
1010 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
1013 /* If this driver is in nvme target mode, set the ndlp's fc4
1014 * type to NVME provided the PRLI response claims NVME FC4
1015 * type. Target mode does not issue gft_id so doesn't get
1016 * the fc4 type set until now.
1018 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
1019 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1020 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1022 if (npr->prliType == PRLI_FCP_TYPE)
1023 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1026 /* We need to update the rport role values */
1027 roles = FC_RPORT_ROLE_UNKNOWN;
1028 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1029 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1030 if (ndlp->nlp_type & NLP_FCP_TARGET)
1031 roles |= FC_RPORT_ROLE_FCP_TARGET;
1033 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1034 "rport rolechg: role:x%x did:x%x flg:x%x",
1035 roles, ndlp->nlp_DID, ndlp->nlp_flag);
1037 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1038 fc_remote_port_rolechg(rport, roles);
1043 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1045 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1047 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1048 spin_lock_irq(shost->host_lock);
1049 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1050 spin_unlock_irq(shost->host_lock);
1054 if (!(vport->fc_flag & FC_PT2PT)) {
1055 /* Check config parameter use-adisc or FCP-2 */
1056 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1057 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1058 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1059 spin_lock_irq(shost->host_lock);
1060 ndlp->nlp_flag |= NLP_NPR_ADISC;
1061 spin_unlock_irq(shost->host_lock);
1066 spin_lock_irq(shost->host_lock);
1067 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1068 spin_unlock_irq(shost->host_lock);
1069 lpfc_unreg_rpi(vport, ndlp);
1074 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1075 * @phba : Pointer to lpfc_hba structure.
1076 * @vport: Pointer to lpfc_vport structure.
1077 * @ndlp: Pointer to lpfc_nodelist structure.
1078 * @rpi : rpi to be release.
1080 * This function will send a unreg_login mailbox command to the firmware
1084 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1085 struct lpfc_nodelist *ndlp, uint16_t rpi)
1090 /* If there is already an UNREG in progress for this ndlp,
1091 * no need to queue up another one.
1093 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1094 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1095 "1435 release_rpi SKIP UNREG x%x on "
1096 "NPort x%x deferred x%x flg x%x "
1098 ndlp->nlp_rpi, ndlp->nlp_DID,
1099 ndlp->nlp_defer_did,
1100 ndlp->nlp_flag, ndlp);
1104 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1107 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1108 "2796 mailbox memory allocation failed \n");
1110 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1111 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1113 pmb->ctx_ndlp = ndlp;
1115 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1116 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1117 ndlp->nlp_flag |= NLP_UNREG_INP;
1119 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1120 "1437 release_rpi UNREG x%x "
1121 "on NPort x%x flg x%x\n",
1122 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1124 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1125 if (rc == MBX_NOT_FINISHED)
1126 mempool_free(pmb, phba->mbox_mem_pool);
1131 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1132 void *arg, uint32_t evt)
1134 struct lpfc_hba *phba;
1135 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1139 /* Release the RPI if reglogin completing */
1140 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1141 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1142 (!pmb->u.mb.mbxStatus)) {
1143 rpi = pmb->u.mb.un.varWords[0];
1144 lpfc_release_rpi(phba, vport, ndlp, rpi);
1146 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1147 "0271 Illegal State Transition: node x%x "
1148 "event x%x, state x%x Data: x%x x%x\n",
1149 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1151 return ndlp->nlp_state;
1155 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1156 void *arg, uint32_t evt)
1158 /* This transition is only legal if we previously
1159 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1160 * working on the same NPortID, do nothing for this thread
1163 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1164 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1165 "0272 Illegal State Transition: node x%x "
1166 "event x%x, state x%x Data: x%x x%x\n",
1167 ndlp->nlp_DID, evt, ndlp->nlp_state,
1168 ndlp->nlp_rpi, ndlp->nlp_flag);
1170 return ndlp->nlp_state;
1173 /* Start of Discovery State Machine routines */
1176 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1177 void *arg, uint32_t evt)
1179 struct lpfc_iocbq *cmdiocb;
1181 cmdiocb = (struct lpfc_iocbq *) arg;
1183 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1184 return ndlp->nlp_state;
1186 return NLP_STE_FREED_NODE;
1190 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1191 void *arg, uint32_t evt)
1193 lpfc_issue_els_logo(vport, ndlp, 0);
1194 return ndlp->nlp_state;
1198 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1199 void *arg, uint32_t evt)
1201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1202 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1204 spin_lock_irq(shost->host_lock);
1205 ndlp->nlp_flag |= NLP_LOGO_ACC;
1206 spin_unlock_irq(shost->host_lock);
1207 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1209 return ndlp->nlp_state;
1213 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1214 void *arg, uint32_t evt)
1216 return NLP_STE_FREED_NODE;
1220 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1221 void *arg, uint32_t evt)
1223 return NLP_STE_FREED_NODE;
1227 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1228 struct lpfc_nodelist *ndlp,
1229 void *arg, uint32_t evt)
1231 return ndlp->nlp_state;
1235 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1236 void *arg, uint32_t evt)
1238 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1239 struct lpfc_hba *phba = vport->phba;
1240 struct lpfc_iocbq *cmdiocb = arg;
1241 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1242 uint32_t *lp = (uint32_t *) pcmd->virt;
1243 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1247 memset(&stat, 0, sizeof (struct ls_rjt));
1249 /* For a PLOGI, we only accept if our portname is less
1250 * than the remote portname.
1252 phba->fc_stat.elsLogiCol++;
1253 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1254 sizeof(struct lpfc_name));
1256 if (port_cmp >= 0) {
1257 /* Reject this request because the remote node will accept
1259 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1260 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1264 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1265 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1266 (vport->num_disc_nodes)) {
1267 spin_lock_irq(shost->host_lock);
1268 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1269 spin_unlock_irq(shost->host_lock);
1270 /* Check if there are more PLOGIs to be sent */
1271 lpfc_more_plogi(vport);
1272 if (vport->num_disc_nodes == 0) {
1273 spin_lock_irq(shost->host_lock);
1274 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1275 spin_unlock_irq(shost->host_lock);
1276 lpfc_can_disctmo(vport);
1277 lpfc_end_rscn(vport);
1280 } /* If our portname was less */
1282 return ndlp->nlp_state;
1286 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1287 void *arg, uint32_t evt)
1289 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1292 memset(&stat, 0, sizeof (struct ls_rjt));
1293 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1294 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1295 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1296 return ndlp->nlp_state;
1300 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1301 void *arg, uint32_t evt)
1303 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1305 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1306 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1307 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1308 /* software abort outstanding PLOGI */
1309 lpfc_els_abort(vport->phba, ndlp);
1311 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1312 return ndlp->nlp_state;
1316 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1317 void *arg, uint32_t evt)
1319 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1320 struct lpfc_hba *phba = vport->phba;
1321 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1323 /* software abort outstanding PLOGI */
1324 lpfc_els_abort(phba, ndlp);
1326 if (evt == NLP_EVT_RCV_LOGO) {
1327 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1329 lpfc_issue_els_logo(vport, ndlp, 0);
1332 /* Put ndlp in npr state set plogi timer for 1 sec */
1333 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1334 spin_lock_irq(shost->host_lock);
1335 ndlp->nlp_flag |= NLP_DELAY_TMO;
1336 spin_unlock_irq(shost->host_lock);
1337 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1338 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1341 return ndlp->nlp_state;
1345 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1346 struct lpfc_nodelist *ndlp,
1350 struct lpfc_hba *phba = vport->phba;
1351 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1352 struct lpfc_iocbq *cmdiocb, *rspiocb;
1353 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1357 struct serv_parm *sp;
1362 cmdiocb = (struct lpfc_iocbq *) arg;
1363 rspiocb = cmdiocb->context_un.rsp_iocb;
1365 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1366 /* Recovery from PLOGI collision logic */
1367 return ndlp->nlp_state;
1370 irsp = &rspiocb->iocb;
1372 if (irsp->ulpStatus)
1375 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1377 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1381 lp = (uint32_t *) prsp->virt;
1382 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1384 /* Some switches have FDMI servers returning 0 for WWN */
1385 if ((ndlp->nlp_DID != FDMI_DID) &&
1386 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1387 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1388 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1389 "0142 PLOGI RSP: Invalid WWN.\n");
1392 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1394 /* PLOGI chkparm OK */
1395 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1396 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1397 ndlp->nlp_DID, ndlp->nlp_state,
1398 ndlp->nlp_flag, ndlp->nlp_rpi);
1399 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1400 ndlp->nlp_fcp_info |= CLASS2;
1402 ndlp->nlp_fcp_info |= CLASS3;
1404 ndlp->nlp_class_sup = 0;
1405 if (sp->cls1.classValid)
1406 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1407 if (sp->cls2.classValid)
1408 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1409 if (sp->cls3.classValid)
1410 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1411 if (sp->cls4.classValid)
1412 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1413 ndlp->nlp_maxframe =
1414 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1416 if ((vport->fc_flag & FC_PT2PT) &&
1417 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1418 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1419 if (sp->cmn.edtovResolution) {
1420 /* E_D_TOV ticks are in nanoseconds */
1421 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1424 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1425 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1426 sp->cmn.valid_vendor_ver_level) {
1427 vid = be32_to_cpu(sp->un.vv.vid);
1428 flag = be32_to_cpu(sp->un.vv.flags);
1429 if ((vid == LPFC_VV_EMLX_ID) &&
1430 (flag & LPFC_VV_SUPPRESS_RSP))
1431 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1435 * Use the larger EDTOV
1436 * RATOV = 2 * EDTOV for pt-to-pt
1438 if (ed_tov > phba->fc_edtov)
1439 phba->fc_edtov = ed_tov;
1440 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1442 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1444 /* Issue config_link / reg_vfi to account for updated TOV's */
1445 if (phba->sli_rev == LPFC_SLI_REV4) {
1446 lpfc_issue_reg_vfi(vport);
1448 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1450 lpfc_printf_vlog(vport, KERN_ERR,
1452 "0133 PLOGI: no memory "
1454 "Data: x%x x%x x%x x%x\n",
1455 ndlp->nlp_DID, ndlp->nlp_state,
1456 ndlp->nlp_flag, ndlp->nlp_rpi);
1460 lpfc_config_link(phba, mbox);
1462 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1463 mbox->vport = vport;
1464 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1465 if (rc == MBX_NOT_FINISHED) {
1466 mempool_free(mbox, phba->mbox_mem_pool);
1472 lpfc_unreg_rpi(vport, ndlp);
1474 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1476 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1477 "0018 PLOGI: no memory for reg_login "
1478 "Data: x%x x%x x%x x%x\n",
1479 ndlp->nlp_DID, ndlp->nlp_state,
1480 ndlp->nlp_flag, ndlp->nlp_rpi);
1484 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1485 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1486 switch (ndlp->nlp_DID) {
1487 case NameServer_DID:
1488 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1491 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1494 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1495 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1497 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1498 mbox->vport = vport;
1499 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1500 != MBX_NOT_FINISHED) {
1501 lpfc_nlp_set_state(vport, ndlp,
1502 NLP_STE_REG_LOGIN_ISSUE);
1503 return ndlp->nlp_state;
1505 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1506 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1507 /* decrement node reference count to the failed mbox
1511 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1512 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1514 mempool_free(mbox, phba->mbox_mem_pool);
1516 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1517 "0134 PLOGI: cannot issue reg_login "
1518 "Data: x%x x%x x%x x%x\n",
1519 ndlp->nlp_DID, ndlp->nlp_state,
1520 ndlp->nlp_flag, ndlp->nlp_rpi);
1522 mempool_free(mbox, phba->mbox_mem_pool);
1524 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1525 "0135 PLOGI: cannot format reg_login "
1526 "Data: x%x x%x x%x x%x\n",
1527 ndlp->nlp_DID, ndlp->nlp_state,
1528 ndlp->nlp_flag, ndlp->nlp_rpi);
1533 if (ndlp->nlp_DID == NameServer_DID) {
1534 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1535 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1536 "0261 Cannot Register NameServer login\n");
1540 ** In case the node reference counter does not go to zero, ensure that
1541 ** the stale state for the node is not processed.
1544 ndlp->nlp_prev_state = ndlp->nlp_state;
1545 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1546 spin_lock_irq(shost->host_lock);
1547 ndlp->nlp_flag |= NLP_DEFER_RM;
1548 spin_unlock_irq(shost->host_lock);
1549 return NLP_STE_FREED_NODE;
1553 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1554 void *arg, uint32_t evt)
1556 return ndlp->nlp_state;
1560 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1561 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1563 struct lpfc_hba *phba;
1564 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1565 MAILBOX_t *mb = &pmb->u.mb;
1569 /* Release the RPI */
1570 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1572 rpi = pmb->u.mb.un.varWords[0];
1573 lpfc_release_rpi(phba, vport, ndlp, rpi);
1575 return ndlp->nlp_state;
1579 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1580 void *arg, uint32_t evt)
1582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1584 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1585 spin_lock_irq(shost->host_lock);
1586 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1587 spin_unlock_irq(shost->host_lock);
1588 return ndlp->nlp_state;
1590 /* software abort outstanding PLOGI */
1591 lpfc_els_abort(vport->phba, ndlp);
1593 lpfc_drop_node(vport, ndlp);
1594 return NLP_STE_FREED_NODE;
1599 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1600 struct lpfc_nodelist *ndlp,
1604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1605 struct lpfc_hba *phba = vport->phba;
1607 /* Don't do anything that will mess up processing of the
1610 if (vport->fc_flag & FC_RSCN_DEFERRED)
1611 return ndlp->nlp_state;
1613 /* software abort outstanding PLOGI */
1614 lpfc_els_abort(phba, ndlp);
1616 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1618 spin_lock_irq(shost->host_lock);
1619 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1620 spin_unlock_irq(shost->host_lock);
1622 return ndlp->nlp_state;
1626 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1627 void *arg, uint32_t evt)
1629 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1630 struct lpfc_hba *phba = vport->phba;
1631 struct lpfc_iocbq *cmdiocb;
1633 /* software abort outstanding ADISC */
1634 lpfc_els_abort(phba, ndlp);
1636 cmdiocb = (struct lpfc_iocbq *) arg;
1638 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1639 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1640 spin_lock_irq(shost->host_lock);
1641 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1642 spin_unlock_irq(shost->host_lock);
1643 if (vport->num_disc_nodes)
1644 lpfc_more_adisc(vport);
1646 return ndlp->nlp_state;
1648 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1649 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1650 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1652 return ndlp->nlp_state;
1656 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1657 void *arg, uint32_t evt)
1659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1661 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1662 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1663 return ndlp->nlp_state;
1667 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1668 void *arg, uint32_t evt)
1670 struct lpfc_hba *phba = vport->phba;
1671 struct lpfc_iocbq *cmdiocb;
1673 cmdiocb = (struct lpfc_iocbq *) arg;
1675 /* software abort outstanding ADISC */
1676 lpfc_els_abort(phba, ndlp);
1678 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1679 return ndlp->nlp_state;
1683 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1684 struct lpfc_nodelist *ndlp,
1685 void *arg, uint32_t evt)
1687 struct lpfc_iocbq *cmdiocb;
1689 cmdiocb = (struct lpfc_iocbq *) arg;
1691 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1692 return ndlp->nlp_state;
1696 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1697 void *arg, uint32_t evt)
1699 struct lpfc_iocbq *cmdiocb;
1701 cmdiocb = (struct lpfc_iocbq *) arg;
1703 /* Treat like rcv logo */
1704 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1705 return ndlp->nlp_state;
1709 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1710 struct lpfc_nodelist *ndlp,
1711 void *arg, uint32_t evt)
1713 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1714 struct lpfc_hba *phba = vport->phba;
1715 struct lpfc_iocbq *cmdiocb, *rspiocb;
1720 cmdiocb = (struct lpfc_iocbq *) arg;
1721 rspiocb = cmdiocb->context_un.rsp_iocb;
1723 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1724 irsp = &rspiocb->iocb;
1726 if ((irsp->ulpStatus) ||
1727 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1729 mod_timer(&ndlp->nlp_delayfunc,
1730 jiffies + msecs_to_jiffies(1000));
1731 spin_lock_irq(shost->host_lock);
1732 ndlp->nlp_flag |= NLP_DELAY_TMO;
1733 spin_unlock_irq(shost->host_lock);
1734 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1736 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1737 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1739 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1741 lpfc_unreg_rpi(vport, ndlp);
1742 return ndlp->nlp_state;
1745 if (phba->sli_rev == LPFC_SLI_REV4) {
1746 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1748 /* Stay in state and retry. */
1749 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1750 return ndlp->nlp_state;
1754 if (ndlp->nlp_type & NLP_FCP_TARGET)
1755 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1757 if (ndlp->nlp_type & NLP_NVME_TARGET)
1758 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1760 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1761 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1762 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1764 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1768 return ndlp->nlp_state;
1772 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1773 void *arg, uint32_t evt)
1775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1777 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1778 spin_lock_irq(shost->host_lock);
1779 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1780 spin_unlock_irq(shost->host_lock);
1781 return ndlp->nlp_state;
1783 /* software abort outstanding ADISC */
1784 lpfc_els_abort(vport->phba, ndlp);
1786 lpfc_drop_node(vport, ndlp);
1787 return NLP_STE_FREED_NODE;
1792 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1793 struct lpfc_nodelist *ndlp,
1797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1798 struct lpfc_hba *phba = vport->phba;
1800 /* Don't do anything that will mess up processing of the
1803 if (vport->fc_flag & FC_RSCN_DEFERRED)
1804 return ndlp->nlp_state;
1806 /* software abort outstanding ADISC */
1807 lpfc_els_abort(phba, ndlp);
1809 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1811 spin_lock_irq(shost->host_lock);
1812 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1813 spin_unlock_irq(shost->host_lock);
1814 lpfc_disc_set_adisc(vport, ndlp);
1815 return ndlp->nlp_state;
1819 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1820 struct lpfc_nodelist *ndlp,
1824 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1826 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1827 return ndlp->nlp_state;
1831 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1832 struct lpfc_nodelist *ndlp,
1836 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1839 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1840 return ndlp->nlp_state;
1842 if (vport->phba->nvmet_support) {
1843 /* NVME Target mode. Handle and respond to the PRLI and
1844 * transition to UNMAPPED provided the RPI has completed
1847 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1848 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1849 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1851 /* RPI registration has not completed. Reject the PRLI
1852 * to prevent an illegal state transition when the
1853 * rpi registration does complete.
1855 memset(&stat, 0, sizeof(struct ls_rjt));
1856 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1857 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1858 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1860 return ndlp->nlp_state;
1863 /* Initiator mode. */
1864 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1866 return ndlp->nlp_state;
1870 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1871 struct lpfc_nodelist *ndlp,
1875 struct lpfc_hba *phba = vport->phba;
1876 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1878 LPFC_MBOXQ_t *nextmb;
1879 struct lpfc_dmabuf *mp;
1880 struct lpfc_nodelist *ns_ndlp;
1882 cmdiocb = (struct lpfc_iocbq *) arg;
1884 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1885 if ((mb = phba->sli.mbox_active)) {
1886 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1887 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1888 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1890 mb->ctx_ndlp = NULL;
1891 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1895 spin_lock_irq(&phba->hbalock);
1896 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1897 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1898 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1899 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1901 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1904 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1906 list_del(&mb->list);
1907 phba->sli.mboxq_cnt--;
1908 mempool_free(mb, phba->mbox_mem_pool);
1911 spin_unlock_irq(&phba->hbalock);
1913 /* software abort if any GID_FT is outstanding */
1914 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1915 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1916 if (ns_ndlp && NLP_CHK_NODE_ACT(ns_ndlp))
1917 lpfc_els_abort(phba, ns_ndlp);
1920 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1921 return ndlp->nlp_state;
1925 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1926 struct lpfc_nodelist *ndlp,
1930 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1932 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1933 return ndlp->nlp_state;
1937 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1938 struct lpfc_nodelist *ndlp,
1942 struct lpfc_iocbq *cmdiocb;
1944 cmdiocb = (struct lpfc_iocbq *) arg;
1945 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1946 return ndlp->nlp_state;
1950 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1951 struct lpfc_nodelist *ndlp,
1955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1956 struct lpfc_hba *phba = vport->phba;
1957 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1958 MAILBOX_t *mb = &pmb->u.mb;
1959 uint32_t did = mb->un.varWords[1];
1961 if (mb->mbxStatus) {
1962 /* RegLogin failed */
1963 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1964 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1966 did, mb->mbxStatus, vport->port_state,
1967 mb->un.varRegLogin.vpi,
1968 mb->un.varRegLogin.rpi);
1970 * If RegLogin failed due to lack of HBA resources do not
1973 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1974 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1975 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1976 return ndlp->nlp_state;
1979 /* Put ndlp in npr state set plogi timer for 1 sec */
1980 mod_timer(&ndlp->nlp_delayfunc,
1981 jiffies + msecs_to_jiffies(1000 * 1));
1982 spin_lock_irq(shost->host_lock);
1983 ndlp->nlp_flag |= NLP_DELAY_TMO;
1984 spin_unlock_irq(shost->host_lock);
1985 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1987 lpfc_issue_els_logo(vport, ndlp, 0);
1988 return ndlp->nlp_state;
1991 /* SLI4 ports have preallocated logical rpis. */
1992 if (phba->sli_rev < LPFC_SLI_REV4)
1993 ndlp->nlp_rpi = mb->un.varWords[0];
1995 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1997 /* Only if we are not a fabric nport do we issue PRLI */
1998 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1999 "3066 RegLogin Complete on x%x x%x x%x\n",
2000 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
2001 if (!(ndlp->nlp_type & NLP_FABRIC) &&
2002 (phba->nvmet_support == 0)) {
2003 /* The driver supports FCP and NVME concurrently. If the
2004 * ndlp's nlp_fc4_type is still zero, the driver doesn't
2005 * know what PRLI to send yet. Figure that out now and
2006 * call PRLI depending on the outcome.
2008 if (vport->fc_flag & FC_PT2PT) {
2009 /* If we are pt2pt, there is no Fabric to determine
2010 * the FC4 type of the remote nport. So if NVME
2011 * is configured try it.
2013 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2014 if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
2015 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2016 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2017 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2018 /* We need to update the localport also */
2019 lpfc_nvme_update_localport(vport);
2022 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2023 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2025 } else if (ndlp->nlp_fc4_type == 0) {
2026 /* If we are only configured for FCP, the driver
2027 * should just issue PRLI for FCP. Otherwise issue
2028 * GFT_ID to determine if remote port supports NVME.
2030 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
2031 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
2033 return ndlp->nlp_state;
2035 ndlp->nlp_fc4_type = NLP_FC4_FCP;
2038 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2039 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2040 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
2041 lpfc_issue_els_logo(vport, ndlp, 0);
2042 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2046 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
2047 phba->targetport->port_id = vport->fc_myDID;
2049 /* Only Fabric ports should transition. NVME target
2050 * must complete PRLI.
2052 if (ndlp->nlp_type & NLP_FABRIC) {
2053 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2057 return ndlp->nlp_state;
2061 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2062 struct lpfc_nodelist *ndlp,
2066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2068 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2069 spin_lock_irq(shost->host_lock);
2070 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2071 spin_unlock_irq(shost->host_lock);
2072 return ndlp->nlp_state;
2074 lpfc_drop_node(vport, ndlp);
2075 return NLP_STE_FREED_NODE;
2080 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2081 struct lpfc_nodelist *ndlp,
2085 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2087 /* Don't do anything that will mess up processing of the
2090 if (vport->fc_flag & FC_RSCN_DEFERRED)
2091 return ndlp->nlp_state;
2093 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2094 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2095 spin_lock_irq(shost->host_lock);
2097 /* If we are a target we won't immediately transition into PRLI,
2098 * so if REG_LOGIN already completed we don't need to ignore it.
2100 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2101 !vport->phba->nvmet_support)
2102 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2104 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2105 spin_unlock_irq(shost->host_lock);
2106 lpfc_disc_set_adisc(vport, ndlp);
2107 return ndlp->nlp_state;
2111 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2112 void *arg, uint32_t evt)
2114 struct lpfc_iocbq *cmdiocb;
2116 cmdiocb = (struct lpfc_iocbq *) arg;
2118 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2119 return ndlp->nlp_state;
2123 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2124 void *arg, uint32_t evt)
2126 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2128 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2129 return ndlp->nlp_state;
2130 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2131 return ndlp->nlp_state;
2135 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2136 void *arg, uint32_t evt)
2138 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2140 /* Software abort outstanding PRLI before sending acc */
2141 lpfc_els_abort(vport->phba, ndlp);
2143 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2144 return ndlp->nlp_state;
2148 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2149 void *arg, uint32_t evt)
2151 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2153 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2154 return ndlp->nlp_state;
2157 /* This routine is envoked when we rcv a PRLO request from a nport
2158 * we are logged into. We should send back a PRLO rsp setting the
2160 * NEXT STATE = PRLI_ISSUE
2163 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2164 void *arg, uint32_t evt)
2166 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2168 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2169 return ndlp->nlp_state;
2173 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2174 void *arg, uint32_t evt)
2176 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2177 struct lpfc_iocbq *cmdiocb, *rspiocb;
2178 struct lpfc_hba *phba = vport->phba;
2181 struct lpfc_nvme_prli *nvpr;
2184 cmdiocb = (struct lpfc_iocbq *) arg;
2185 rspiocb = cmdiocb->context_un.rsp_iocb;
2187 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2188 * format is different so NULL the two PRLI types so that the
2189 * driver correctly gets the correct context.
2193 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2194 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2195 npr = (PRLI *) temp_ptr;
2196 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2197 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2199 irsp = &rspiocb->iocb;
2200 if (irsp->ulpStatus) {
2201 if ((vport->port_type == LPFC_NPIV_PORT) &&
2202 vport->cfg_restrict_login) {
2206 /* Adjust the nlp_type accordingly if the PRLI failed */
2208 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2210 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2212 /* We can't set the DSM state till BOTH PRLIs complete */
2216 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2217 (npr->prliType == PRLI_FCP_TYPE)) {
2218 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2219 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2222 if (npr->initiatorFunc)
2223 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2224 if (npr->targetFunc) {
2225 ndlp->nlp_type |= NLP_FCP_TARGET;
2226 if (npr->writeXferRdyDis)
2227 ndlp->nlp_flag |= NLP_FIRSTBURST;
2230 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2233 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2234 PRLI_REQ_EXECUTED) &&
2235 (bf_get_be32(prli_type_code, nvpr) ==
2238 /* Complete setting up the remote ndlp personality. */
2239 if (bf_get_be32(prli_init, nvpr))
2240 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2242 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2243 bf_get_be32(prli_conf, nvpr))
2245 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2247 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2249 /* Target driver cannot solicit NVME FB. */
2250 if (bf_get_be32(prli_tgt, nvpr)) {
2251 /* Complete the nvme target roles. The transport
2252 * needs to know if the rport is capable of
2253 * discovery in addition to its role.
2255 ndlp->nlp_type |= NLP_NVME_TARGET;
2256 if (bf_get_be32(prli_disc, nvpr))
2257 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2260 * If prli_fba is set, the Target supports FirstBurst.
2261 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2262 * otherwise it defines the actual size supported by
2265 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2266 (phba->cfg_nvme_enable_fb) &&
2267 (!phba->nvmet_support)) {
2268 /* Both sides support FB. The target's first
2269 * burst size is a 512 byte encoded value.
2271 ndlp->nlp_flag |= NLP_FIRSTBURST;
2272 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2275 /* Expressed in units of 512 bytes */
2276 if (ndlp->nvme_fb_size)
2277 ndlp->nvme_fb_size <<=
2280 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2284 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2285 "6029 NVME PRLI Cmpl w1 x%08x "
2286 "w4 x%08x w5 x%08x flag x%x, "
2287 "fcp_info x%x nlp_type x%x\n",
2288 be32_to_cpu(nvpr->word1),
2289 be32_to_cpu(nvpr->word4),
2290 be32_to_cpu(nvpr->word5),
2291 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2294 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2295 (vport->port_type == LPFC_NPIV_PORT) &&
2296 vport->cfg_restrict_login) {
2298 spin_lock_irq(shost->host_lock);
2299 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2300 spin_unlock_irq(shost->host_lock);
2301 lpfc_issue_els_logo(vport, ndlp, 0);
2303 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2304 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2305 return ndlp->nlp_state;
2309 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2312 if (ndlp->fc4_prli_sent == 0) {
2313 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2314 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2315 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2316 else if (ndlp->nlp_type &
2317 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2318 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2320 lpfc_printf_vlog(vport,
2322 "3067 PRLI's still outstanding "
2323 "on x%06x - count %d, Pend Node Mode "
2325 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2327 return ndlp->nlp_state;
2330 /*! lpfc_device_rm_prli_issue
2341 * This routine is envoked when we a request to remove a nport we are in the
2342 * process of PRLIing. We should software abort outstanding prli, unreg
2343 * login, send a logout. We will change node state to UNUSED_NODE, put it
2344 * on plogi list so it can be freed when LOGO completes.
2349 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2350 void *arg, uint32_t evt)
2352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2354 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2355 spin_lock_irq(shost->host_lock);
2356 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2357 spin_unlock_irq(shost->host_lock);
2358 return ndlp->nlp_state;
2360 /* software abort outstanding PLOGI */
2361 lpfc_els_abort(vport->phba, ndlp);
2363 lpfc_drop_node(vport, ndlp);
2364 return NLP_STE_FREED_NODE;
2369 /*! lpfc_device_recov_prli_issue
2380 * The routine is envoked when the state of a device is unknown, like
2381 * during a link down. We should remove the nodelist entry from the
2382 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2383 * outstanding PRLI command, then free the node entry.
2386 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2387 struct lpfc_nodelist *ndlp,
2391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2392 struct lpfc_hba *phba = vport->phba;
2394 /* Don't do anything that will mess up processing of the
2397 if (vport->fc_flag & FC_RSCN_DEFERRED)
2398 return ndlp->nlp_state;
2400 /* software abort outstanding PRLI */
2401 lpfc_els_abort(phba, ndlp);
2403 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2404 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2405 spin_lock_irq(shost->host_lock);
2406 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2407 spin_unlock_irq(shost->host_lock);
2408 lpfc_disc_set_adisc(vport, ndlp);
2409 return ndlp->nlp_state;
2413 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2414 void *arg, uint32_t evt)
2416 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2419 memset(&stat, 0, sizeof(struct ls_rjt));
2420 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2421 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2422 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2423 return ndlp->nlp_state;
2427 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2428 void *arg, uint32_t evt)
2430 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2433 memset(&stat, 0, sizeof(struct ls_rjt));
2434 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2435 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2436 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2437 return ndlp->nlp_state;
2441 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2442 void *arg, uint32_t evt)
2444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2445 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2447 spin_lock_irq(shost->host_lock);
2448 ndlp->nlp_flag |= NLP_LOGO_ACC;
2449 spin_unlock_irq(shost->host_lock);
2450 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2451 return ndlp->nlp_state;
2455 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2456 void *arg, uint32_t evt)
2458 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2461 memset(&stat, 0, sizeof(struct ls_rjt));
2462 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2463 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2464 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2465 return ndlp->nlp_state;
2469 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2470 void *arg, uint32_t evt)
2472 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2475 memset(&stat, 0, sizeof(struct ls_rjt));
2476 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2477 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2478 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2479 return ndlp->nlp_state;
2483 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2484 void *arg, uint32_t evt)
2486 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2488 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2490 spin_lock_irq(shost->host_lock);
2491 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2492 spin_unlock_irq(shost->host_lock);
2493 lpfc_disc_set_adisc(vport, ndlp);
2494 return ndlp->nlp_state;
2498 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2499 void *arg, uint32_t evt)
2502 * DevLoss has timed out and is calling for Device Remove.
2503 * In this case, abort the LOGO and cleanup the ndlp
2506 lpfc_unreg_rpi(vport, ndlp);
2507 /* software abort outstanding PLOGI */
2508 lpfc_els_abort(vport->phba, ndlp);
2509 lpfc_drop_node(vport, ndlp);
2510 return NLP_STE_FREED_NODE;
2514 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2515 struct lpfc_nodelist *ndlp,
2516 void *arg, uint32_t evt)
2519 * Device Recovery events have no meaning for a node with a LOGO
2520 * outstanding. The LOGO has to complete first and handle the
2521 * node from that point.
2523 return ndlp->nlp_state;
2527 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2528 void *arg, uint32_t evt)
2530 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2532 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2533 return ndlp->nlp_state;
2537 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2538 void *arg, uint32_t evt)
2540 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2542 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2543 return ndlp->nlp_state;
2545 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2546 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2547 return ndlp->nlp_state;
2551 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2552 void *arg, uint32_t evt)
2554 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2556 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2557 return ndlp->nlp_state;
2561 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2562 void *arg, uint32_t evt)
2564 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2566 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2567 return ndlp->nlp_state;
2571 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2572 void *arg, uint32_t evt)
2574 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2576 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2577 return ndlp->nlp_state;
2581 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2582 struct lpfc_nodelist *ndlp,
2586 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2588 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2589 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2590 spin_lock_irq(shost->host_lock);
2591 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2592 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2593 spin_unlock_irq(shost->host_lock);
2594 lpfc_disc_set_adisc(vport, ndlp);
2596 return ndlp->nlp_state;
2600 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2601 void *arg, uint32_t evt)
2603 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2605 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2606 return ndlp->nlp_state;
2610 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2611 void *arg, uint32_t evt)
2613 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2615 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2616 return ndlp->nlp_state;
2617 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2618 return ndlp->nlp_state;
2622 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2623 void *arg, uint32_t evt)
2625 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2627 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2628 return ndlp->nlp_state;
2632 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2633 struct lpfc_nodelist *ndlp,
2634 void *arg, uint32_t evt)
2636 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2638 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2639 return ndlp->nlp_state;
2643 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2644 void *arg, uint32_t evt)
2646 struct lpfc_hba *phba = vport->phba;
2647 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2649 /* flush the target */
2650 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2651 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2653 /* Treat like rcv logo */
2654 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2655 return ndlp->nlp_state;
2659 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2660 struct lpfc_nodelist *ndlp,
2664 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2666 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2667 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2668 spin_lock_irq(shost->host_lock);
2669 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2670 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2671 spin_unlock_irq(shost->host_lock);
2672 lpfc_disc_set_adisc(vport, ndlp);
2673 return ndlp->nlp_state;
2677 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2678 void *arg, uint32_t evt)
2680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2681 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2683 /* Ignore PLOGI if we have an outstanding LOGO */
2684 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2685 return ndlp->nlp_state;
2686 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2687 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2688 spin_lock_irq(shost->host_lock);
2689 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2690 spin_unlock_irq(shost->host_lock);
2691 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2692 /* send PLOGI immediately, move to PLOGI issue state */
2693 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2694 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2695 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2696 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2699 return ndlp->nlp_state;
2703 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2704 void *arg, uint32_t evt)
2706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2707 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2710 memset(&stat, 0, sizeof (struct ls_rjt));
2711 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2712 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2713 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2715 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2716 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2717 spin_lock_irq(shost->host_lock);
2718 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2719 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2720 spin_unlock_irq(shost->host_lock);
2721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2722 lpfc_issue_els_adisc(vport, ndlp, 0);
2724 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2725 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2726 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2729 return ndlp->nlp_state;
2733 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2734 void *arg, uint32_t evt)
2736 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2738 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2739 return ndlp->nlp_state;
2743 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2744 void *arg, uint32_t evt)
2746 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2748 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2750 * Do not start discovery if discovery is about to start
2751 * or discovery in progress for this node. Starting discovery
2752 * here will affect the counting of discovery threads.
2754 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2755 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2756 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2757 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2758 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2760 lpfc_issue_els_adisc(vport, ndlp, 0);
2762 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2763 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2764 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2767 return ndlp->nlp_state;
2771 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2772 void *arg, uint32_t evt)
2774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2775 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2777 spin_lock_irq(shost->host_lock);
2778 ndlp->nlp_flag |= NLP_LOGO_ACC;
2779 spin_unlock_irq(shost->host_lock);
2781 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2783 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2784 mod_timer(&ndlp->nlp_delayfunc,
2785 jiffies + msecs_to_jiffies(1000 * 1));
2786 spin_lock_irq(shost->host_lock);
2787 ndlp->nlp_flag |= NLP_DELAY_TMO;
2788 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2789 spin_unlock_irq(shost->host_lock);
2790 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2792 spin_lock_irq(shost->host_lock);
2793 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2794 spin_unlock_irq(shost->host_lock);
2796 return ndlp->nlp_state;
2800 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2801 void *arg, uint32_t evt)
2803 struct lpfc_iocbq *cmdiocb, *rspiocb;
2805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2807 cmdiocb = (struct lpfc_iocbq *) arg;
2808 rspiocb = cmdiocb->context_un.rsp_iocb;
2810 irsp = &rspiocb->iocb;
2811 if (irsp->ulpStatus) {
2812 spin_lock_irq(shost->host_lock);
2813 ndlp->nlp_flag |= NLP_DEFER_RM;
2814 spin_unlock_irq(shost->host_lock);
2815 return NLP_STE_FREED_NODE;
2817 return ndlp->nlp_state;
2821 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2822 void *arg, uint32_t evt)
2824 struct lpfc_iocbq *cmdiocb, *rspiocb;
2827 cmdiocb = (struct lpfc_iocbq *) arg;
2828 rspiocb = cmdiocb->context_un.rsp_iocb;
2830 irsp = &rspiocb->iocb;
2831 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2832 lpfc_drop_node(vport, ndlp);
2833 return NLP_STE_FREED_NODE;
2835 return ndlp->nlp_state;
2839 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2840 void *arg, uint32_t evt)
2842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2844 /* For the fabric port just clear the fc flags. */
2845 if (ndlp->nlp_DID == Fabric_DID) {
2846 spin_lock_irq(shost->host_lock);
2847 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2848 spin_unlock_irq(shost->host_lock);
2850 lpfc_unreg_rpi(vport, ndlp);
2851 return ndlp->nlp_state;
2855 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2856 void *arg, uint32_t evt)
2858 struct lpfc_iocbq *cmdiocb, *rspiocb;
2861 cmdiocb = (struct lpfc_iocbq *) arg;
2862 rspiocb = cmdiocb->context_un.rsp_iocb;
2864 irsp = &rspiocb->iocb;
2865 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2866 lpfc_drop_node(vport, ndlp);
2867 return NLP_STE_FREED_NODE;
2869 return ndlp->nlp_state;
2873 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2874 struct lpfc_nodelist *ndlp,
2875 void *arg, uint32_t evt)
2877 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2878 MAILBOX_t *mb = &pmb->u.mb;
2880 if (!mb->mbxStatus) {
2881 /* SLI4 ports have preallocated logical rpis. */
2882 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2883 ndlp->nlp_rpi = mb->un.varWords[0];
2884 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2885 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2886 lpfc_unreg_rpi(vport, ndlp);
2889 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2890 lpfc_drop_node(vport, ndlp);
2891 return NLP_STE_FREED_NODE;
2894 return ndlp->nlp_state;
2898 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2899 void *arg, uint32_t evt)
2901 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2903 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2904 spin_lock_irq(shost->host_lock);
2905 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2906 spin_unlock_irq(shost->host_lock);
2907 return ndlp->nlp_state;
2909 lpfc_drop_node(vport, ndlp);
2910 return NLP_STE_FREED_NODE;
2914 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2915 void *arg, uint32_t evt)
2917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2919 /* Don't do anything that will mess up processing of the
2922 if (vport->fc_flag & FC_RSCN_DEFERRED)
2923 return ndlp->nlp_state;
2925 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2926 spin_lock_irq(shost->host_lock);
2927 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2928 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2929 spin_unlock_irq(shost->host_lock);
2930 return ndlp->nlp_state;
2934 /* This next section defines the NPort Discovery State Machine */
2936 /* There are 4 different double linked lists nodelist entries can reside on.
2937 * The plogi list and adisc list are used when Link Up discovery or RSCN
2938 * processing is needed. Each list holds the nodes that we will send PLOGI
2939 * or ADISC on. These lists will keep track of what nodes will be effected
2940 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2941 * The unmapped_list will contain all nodes that we have successfully logged
2942 * into at the Fibre Channel level. The mapped_list will contain all nodes
2943 * that are mapped FCP targets.
2946 * The bind list is a list of undiscovered (potentially non-existent) nodes
2947 * that we have saved binding information on. This information is used when
2948 * nodes transition from the unmapped to the mapped list.
2950 /* For UNUSED_NODE state, the node has just been allocated .
2951 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2952 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2953 * and put on the unmapped list. For ADISC processing, the node is taken off
2954 * the ADISC list and placed on either the mapped or unmapped list (depending
2955 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2956 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2957 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2958 * node, the node is taken off the unmapped list. The binding list is checked
2959 * for a valid binding, or a binding is automatically assigned. If binding
2960 * assignment is unsuccessful, the node is left on the unmapped list. If
2961 * binding assignment is successful, the associated binding list entry (if
2962 * any) is removed, and the node is placed on the mapped list.
2965 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2966 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2967 * expire, all effected nodes will receive a DEVICE_RM event.
2970 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2971 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2972 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2973 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2974 * we will first process the ADISC list. 32 entries are processed initially and
2975 * ADISC is initited for each one. Completions / Events for each node are
2976 * funnelled thru the state machine. As each node finishes ADISC processing, it
2977 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2978 * waiting, and the ADISC list count is identically 0, then we are done. For
2979 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2980 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2981 * list. 32 entries are processed initially and PLOGI is initited for each one.
2982 * Completions / Events for each node are funnelled thru the state machine. As
2983 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2984 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2985 * indentically 0, then we are done. We have now completed discovery / RSCN
2986 * handling. Upon completion, ALL nodes should be on either the mapped or
2990 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2991 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2992 /* Action routine Event Current State */
2993 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2994 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2995 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2996 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2997 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2998 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2999 lpfc_disc_illegal, /* CMPL_PLOGI */
3000 lpfc_disc_illegal, /* CMPL_PRLI */
3001 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
3002 lpfc_disc_illegal, /* CMPL_ADISC */
3003 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3004 lpfc_device_rm_unused_node, /* DEVICE_RM */
3005 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
3007 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
3008 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
3009 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
3010 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
3011 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
3012 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
3013 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
3014 lpfc_disc_illegal, /* CMPL_PRLI */
3015 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
3016 lpfc_disc_illegal, /* CMPL_ADISC */
3017 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
3018 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
3019 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
3021 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
3022 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
3023 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
3024 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
3025 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
3026 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
3027 lpfc_disc_illegal, /* CMPL_PLOGI */
3028 lpfc_disc_illegal, /* CMPL_PRLI */
3029 lpfc_disc_illegal, /* CMPL_LOGO */
3030 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
3031 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3032 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
3033 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
3035 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
3036 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
3037 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
3038 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
3039 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
3040 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
3041 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3042 lpfc_disc_illegal, /* CMPL_PRLI */
3043 lpfc_disc_illegal, /* CMPL_LOGO */
3044 lpfc_disc_illegal, /* CMPL_ADISC */
3045 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
3046 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
3047 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
3049 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
3050 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
3051 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
3052 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
3053 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
3054 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
3055 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3056 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
3057 lpfc_disc_illegal, /* CMPL_LOGO */
3058 lpfc_disc_illegal, /* CMPL_ADISC */
3059 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3060 lpfc_device_rm_prli_issue, /* DEVICE_RM */
3061 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
3063 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3064 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3065 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3066 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3067 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3068 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3069 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3070 lpfc_disc_illegal, /* CMPL_PRLI */
3071 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3072 lpfc_disc_illegal, /* CMPL_ADISC */
3073 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3074 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3075 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3077 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3078 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3079 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3080 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3081 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3082 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3083 lpfc_disc_illegal, /* CMPL_PLOGI */
3084 lpfc_disc_illegal, /* CMPL_PRLI */
3085 lpfc_disc_illegal, /* CMPL_LOGO */
3086 lpfc_disc_illegal, /* CMPL_ADISC */
3087 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3088 lpfc_disc_illegal, /* DEVICE_RM */
3089 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3091 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3092 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3093 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3094 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3095 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3096 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3097 lpfc_disc_illegal, /* CMPL_PLOGI */
3098 lpfc_disc_illegal, /* CMPL_PRLI */
3099 lpfc_disc_illegal, /* CMPL_LOGO */
3100 lpfc_disc_illegal, /* CMPL_ADISC */
3101 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3102 lpfc_disc_illegal, /* DEVICE_RM */
3103 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3105 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3106 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3107 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3108 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3109 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3110 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3111 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3112 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3113 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3114 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3115 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3116 lpfc_device_rm_npr_node, /* DEVICE_RM */
3117 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3121 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3122 void *arg, uint32_t evt)
3124 uint32_t cur_state, rc;
3125 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3127 uint32_t got_ndlp = 0;
3130 if (lpfc_nlp_get(ndlp))
3133 cur_state = ndlp->nlp_state;
3135 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3136 ((uint32_t)ndlp->nlp_type));
3137 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3138 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3139 "0211 DSM in event x%x on NPort x%x in "
3140 "state %d rpi x%x Data: x%x x%x\n",
3141 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3142 ndlp->nlp_flag, data1);
3144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3145 "DSM in: evt:%d ste:%d did:x%x",
3146 evt, cur_state, ndlp->nlp_DID);
3148 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3149 rc = (func) (vport, ndlp, arg, evt);
3151 /* DSM out state <rc> on NPort <nlp_DID> */
3153 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3154 ((uint32_t)ndlp->nlp_type));
3155 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3156 "0212 DSM out state %d on NPort x%x "
3157 "rpi x%x Data: x%x x%x\n",
3158 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3161 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3162 "DSM out: ste:%d did:x%x flg:x%x",
3163 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3164 /* Decrement the ndlp reference count held for this function */
3167 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3168 "0213 DSM out state %d on NPort free\n", rc);
3170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3171 "DSM out: ste:%d did:x%x flg:x%x",