1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 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;
174 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
176 pcmd = cmdiocb->cmd_dmabuf;
178 /* For lpfc_els_abort, cmd_dmabuf could be zero'ed to delay
179 * freeing associated memory till after ABTS completes.
182 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
185 lp = (uint32_t *) prsp->virt;
186 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
189 /* Force ulp_status error since we are returning NULL ptr */
191 if (phba->sli_rev == LPFC_SLI_REV4) {
192 bf_set(lpfc_wcqe_c_status, &rspiocb->wcqe_cmpl,
193 IOSTAT_LOCAL_REJECT);
194 rspiocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
196 rspiocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
197 rspiocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
208 * Free resources / clean up outstanding I/Os
209 * associated with a LPFC_NODELIST entry. This
210 * routine effectively results in a "software abort".
213 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
215 LIST_HEAD(abort_list);
216 struct lpfc_sli_ring *pring;
217 struct lpfc_iocbq *iocb, *next_iocb;
219 pring = lpfc_phba_elsring(phba);
221 /* In case of error recovery path, we might have a NULL pring here */
222 if (unlikely(!pring))
225 /* Abort outstanding I/O on NPort <nlp_DID> */
226 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
227 "2819 Abort outstanding I/O on NPort x%x "
228 "Data: x%x x%x x%x\n",
229 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
231 /* Clean up all fabric IOs first.*/
232 lpfc_fabric_abort_nport(ndlp);
235 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
236 * of all ELS IOs that need an ABTS. The IOs need to stay on the
237 * txcmplq so that the abort operation completes them successfully.
239 spin_lock_irq(&phba->hbalock);
240 if (phba->sli_rev == LPFC_SLI_REV4)
241 spin_lock(&pring->ring_lock);
242 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
243 /* Add to abort_list on on NDLP match. */
244 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
245 list_add_tail(&iocb->dlist, &abort_list);
247 if (phba->sli_rev == LPFC_SLI_REV4)
248 spin_unlock(&pring->ring_lock);
249 spin_unlock_irq(&phba->hbalock);
251 /* Abort the targeted IOs and remove them from the abort list. */
252 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
253 spin_lock_irq(&phba->hbalock);
254 list_del_init(&iocb->dlist);
255 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
256 spin_unlock_irq(&phba->hbalock);
258 /* Make sure HBA is alive */
259 lpfc_issue_hb_tmo(phba);
261 INIT_LIST_HEAD(&abort_list);
263 /* Now process the txq */
264 spin_lock_irq(&phba->hbalock);
265 if (phba->sli_rev == LPFC_SLI_REV4)
266 spin_lock(&pring->ring_lock);
268 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
269 /* Check to see if iocb matches the nport we are looking for */
270 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
271 list_del_init(&iocb->list);
272 list_add_tail(&iocb->list, &abort_list);
276 if (phba->sli_rev == LPFC_SLI_REV4)
277 spin_unlock(&pring->ring_lock);
278 spin_unlock_irq(&phba->hbalock);
280 /* Cancel all the IOCBs from the completions list */
281 lpfc_sli_cancel_iocbs(phba, &abort_list,
282 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
284 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
287 /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
288 * @phba: pointer to lpfc hba data structure.
289 * @login_mbox: pointer to REG_RPI mailbox object
291 * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
294 lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox)
296 struct lpfc_iocbq *save_iocb;
297 struct lpfc_nodelist *ndlp;
298 MAILBOX_t *mb = &login_mbox->u.mb;
302 ndlp = login_mbox->ctx_ndlp;
303 save_iocb = login_mbox->context3;
305 if (mb->mbxStatus == MBX_SUCCESS) {
306 /* Now that REG_RPI completed successfully,
307 * we can now proceed with sending the PLOGI ACC.
309 rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI,
310 save_iocb, ndlp, NULL);
312 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
313 "4576 PLOGI ACC fails pt2pt discovery: "
314 "DID %x Data: %x\n", ndlp->nlp_DID, rc);
318 /* Now process the REG_RPI cmpl */
319 lpfc_mbx_cmpl_reg_login(phba, login_mbox);
320 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
325 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
326 struct lpfc_iocbq *cmdiocb)
328 struct lpfc_hba *phba = vport->phba;
329 struct lpfc_dmabuf *pcmd;
330 uint64_t nlp_portwwn = 0;
332 union lpfc_wqe128 *wqe;
334 struct serv_parm *sp;
336 LPFC_MBOXQ_t *link_mbox;
337 LPFC_MBOXQ_t *login_mbox;
338 struct lpfc_iocbq *save_iocb;
344 memset(&stat, 0, sizeof (struct ls_rjt));
345 pcmd = cmdiocb->cmd_dmabuf;
346 lp = (uint32_t *) pcmd->virt;
347 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
348 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
349 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
350 "0140 PLOGI Reject: invalid pname\n");
351 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
352 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
353 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
357 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
358 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
359 "0141 PLOGI Reject: invalid nname\n");
360 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
361 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
362 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
367 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
368 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
369 /* Reject this request because invalid parameters */
370 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
371 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
372 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
377 if (phba->sli_rev == LPFC_SLI_REV4)
380 icmd = &cmdiocb->iocb;
382 /* PLOGI chkparm OK */
383 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
384 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
386 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
387 ndlp->nlp_rpi, vport->port_state,
390 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
391 ndlp->nlp_fcp_info |= CLASS2;
393 ndlp->nlp_fcp_info |= CLASS3;
395 ndlp->nlp_class_sup = 0;
396 if (sp->cls1.classValid)
397 ndlp->nlp_class_sup |= FC_COS_CLASS1;
398 if (sp->cls2.classValid)
399 ndlp->nlp_class_sup |= FC_COS_CLASS2;
400 if (sp->cls3.classValid)
401 ndlp->nlp_class_sup |= FC_COS_CLASS3;
402 if (sp->cls4.classValid)
403 ndlp->nlp_class_sup |= FC_COS_CLASS4;
405 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
406 /* if already logged in, do implicit logout */
407 switch (ndlp->nlp_state) {
408 case NLP_STE_NPR_NODE:
409 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
412 case NLP_STE_REG_LOGIN_ISSUE:
413 case NLP_STE_PRLI_ISSUE:
414 case NLP_STE_UNMAPPED_NODE:
415 case NLP_STE_MAPPED_NODE:
416 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
417 * For target mode, execute implicit logo.
418 * Fabric nodes go into NPR.
420 if (!(ndlp->nlp_type & NLP_FABRIC) &&
421 !(phba->nvmet_support)) {
422 /* Clear ndlp info, since follow up PRLI may have
423 * updated ndlp information
425 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
426 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
427 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
428 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
429 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
431 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
435 if (nlp_portwwn != 0 &&
436 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
437 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
438 "0143 PLOGI recv'd from DID: x%x "
439 "WWPN changed: old %llx new %llx\n",
441 (unsigned long long)nlp_portwwn,
443 wwn_to_u64(sp->portName.u.wwn));
445 /* Notify transport of connectivity loss to trigger cleanup. */
446 if (phba->nvmet_support &&
447 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
448 lpfc_nvmet_invalidate_host(phba, ndlp);
450 ndlp->nlp_prev_state = ndlp->nlp_state;
451 /* rport needs to be unregistered first */
452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
456 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
457 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
458 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
459 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
460 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
466 /* Check for Nport to NPort pt2pt protocol */
467 if ((vport->fc_flag & FC_PT2PT) &&
468 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
469 /* rcv'ed PLOGI decides what our NPortId will be */
470 if (phba->sli_rev == LPFC_SLI_REV4) {
471 vport->fc_myDID = bf_get(els_rsp64_sid,
472 &cmdiocb->wqe.xmit_els_rsp);
474 vport->fc_myDID = icmd->un.rcvels.parmRo;
477 /* If there is an outstanding FLOGI, abort it now.
478 * The remote NPort is not going to ACC our FLOGI
479 * if its already issuing a PLOGI for pt2pt mode.
480 * This indicates our FLOGI was dropped; however, we
481 * must have ACCed the remote NPorts FLOGI to us
484 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
485 lpfc_els_abort_flogi(phba);
487 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
488 if (sp->cmn.edtovResolution) {
489 /* E_D_TOV ticks are in nanoseconds */
490 ed_tov = (phba->fc_edtov + 999999) / 1000000;
494 * For pt-to-pt, use the larger EDTOV
497 if (ed_tov > phba->fc_edtov)
498 phba->fc_edtov = ed_tov;
499 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
501 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
503 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
504 * to account for updated TOV's / parameters
506 if (phba->sli_rev == LPFC_SLI_REV4)
507 lpfc_issue_reg_vfi(vport);
509 link_mbox = mempool_alloc(phba->mbox_mem_pool,
513 lpfc_config_link(phba, link_mbox);
514 link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
515 link_mbox->vport = vport;
517 /* The default completion handling for CONFIG_LINK
518 * does not require the ndlp so no reference is needed.
520 link_mbox->ctx_ndlp = ndlp;
522 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
523 if (rc == MBX_NOT_FINISHED) {
524 mempool_free(link_mbox, phba->mbox_mem_pool);
529 lpfc_can_disctmo(vport);
532 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
533 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
534 sp->cmn.valid_vendor_ver_level) {
535 vid = be32_to_cpu(sp->un.vv.vid);
536 flag = be32_to_cpu(sp->un.vv.flags);
537 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
538 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
541 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
545 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
549 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
550 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
551 sizeof(struct lpfc_iocbq));
553 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
554 if (phba->sli_rev == LPFC_SLI_REV4)
555 lpfc_unreg_rpi(vport, ndlp);
557 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
558 * always be deferring the ACC.
560 if (phba->sli_rev == LPFC_SLI_REV4)
561 remote_did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
563 remote_did = icmd->un.rcvels.remoteID;
564 rc = lpfc_reg_rpi(phba, vport->vpi, remote_did,
565 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
569 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
570 login_mbox->vport = vport;
573 * If there is an outstanding PLOGI issued, abort it before
574 * sending ACC rsp for received PLOGI. If pending plogi
575 * is not canceled here, the plogi will be rejected by
576 * remote port and will be retried. On a configuration with
577 * single discovery thread, this will cause a huge delay in
578 * discovery. Also this will cause multiple state machines
579 * running in parallel for this node.
580 * This only applies to a fabric environment.
582 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
583 (vport->fc_flag & FC_FABRIC)) {
584 /* software abort outstanding PLOGI */
585 lpfc_els_abort(phba, ndlp);
588 if ((vport->port_type == LPFC_NPIV_PORT &&
589 vport->cfg_restrict_login)) {
591 /* no deferred ACC */
594 /* This is an NPIV SLI4 instance that does not need to register
597 if (phba->sli_rev == LPFC_SLI_REV4) {
598 lpfc_mbox_rsrc_cleanup(phba, login_mbox,
602 /* In order to preserve RPIs, we want to cleanup
603 * the default RPI the firmware created to rcv
604 * this ELS request. The only way to do this is
605 * to register, then unregister the RPI.
607 spin_lock_irq(&ndlp->lock);
608 ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN |
610 spin_unlock_irq(&ndlp->lock);
613 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
614 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
615 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
617 if (rc && login_mbox)
618 lpfc_mbox_rsrc_cleanup(phba, login_mbox,
623 /* So the order here should be:
625 * Issue CONFIG_LINK mbox
631 * Issue UNREG RPI mbx
638 login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
639 login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
640 if (!login_mbox->ctx_ndlp)
643 login_mbox->context3 = save_iocb; /* For PLOGI ACC */
645 spin_lock_irq(&ndlp->lock);
646 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
647 spin_unlock_irq(&ndlp->lock);
649 /* Start the ball rolling by issuing REG_LOGIN here */
650 rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
651 if (rc == MBX_NOT_FINISHED) {
655 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
661 mempool_free(login_mbox, phba->mbox_mem_pool);
663 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
664 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
665 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
670 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
671 * @phba: pointer to lpfc hba data structure.
672 * @mboxq: pointer to mailbox object
674 * This routine is invoked to issue a completion to a rcv'ed
675 * ADISC or PDISC after the paused RPI has been resumed.
678 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
680 struct lpfc_vport *vport;
681 struct lpfc_iocbq *elsiocb;
682 struct lpfc_nodelist *ndlp;
685 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
686 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
687 vport = mboxq->vport;
688 cmd = elsiocb->drvrTimeout;
690 if (cmd == ELS_CMD_ADISC) {
691 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
693 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
697 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
701 mempool_free(mboxq, phba->mbox_mem_pool);
705 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
706 struct lpfc_iocbq *cmdiocb)
708 struct lpfc_hba *phba = vport->phba;
709 struct lpfc_iocbq *elsiocb;
710 struct lpfc_dmabuf *pcmd;
711 struct serv_parm *sp;
712 struct lpfc_name *pnn, *ppn;
718 pcmd = cmdiocb->cmd_dmabuf;
719 lp = (uint32_t *) pcmd->virt;
722 if (cmd == ELS_CMD_ADISC) {
724 pnn = (struct lpfc_name *) & ap->nodeName;
725 ppn = (struct lpfc_name *) & ap->portName;
727 sp = (struct serv_parm *) lp;
728 pnn = (struct lpfc_name *) & sp->nodeName;
729 ppn = (struct lpfc_name *) & sp->portName;
732 if (get_job_ulpstatus(phba, cmdiocb) == 0 &&
733 lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
736 * As soon as we send ACC, the remote NPort can
737 * start sending us data. Thus, for SLI4 we must
738 * resume the RPI before the ACC goes out.
740 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
741 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
744 /* Save info from cmd IOCB used in rsp */
745 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
746 sizeof(struct lpfc_iocbq));
748 /* Save the ELS cmd */
749 elsiocb->drvrTimeout = cmd;
751 lpfc_sli4_resume_rpi(ndlp,
752 lpfc_mbx_cmpl_resume_rpi, elsiocb);
757 if (cmd == ELS_CMD_ADISC) {
758 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
760 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
764 /* If we are authenticated, move to the proper state.
765 * It is possible an ADISC arrived and the remote nport
766 * is already in MAPPED or UNMAPPED state. Catch this
767 * condition and don't set the nlp_state again because
768 * it causes an unnecessary transport unregister/register.
770 * Nodes marked for ADISC will move MAPPED or UNMAPPED state
771 * after issuing ADISC
773 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
774 if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) &&
775 !(ndlp->nlp_flag & NLP_NPR_ADISC))
776 lpfc_nlp_set_state(vport, ndlp,
777 NLP_STE_MAPPED_NODE);
782 /* Reject this request because invalid parameters */
783 stat.un.b.lsRjtRsvd0 = 0;
784 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
785 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
786 stat.un.b.vendorUnique = 0;
787 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
790 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
792 spin_lock_irq(&ndlp->lock);
793 ndlp->nlp_flag |= NLP_DELAY_TMO;
794 spin_unlock_irq(&ndlp->lock);
795 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
796 ndlp->nlp_prev_state = ndlp->nlp_state;
797 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
802 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
803 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
806 struct lpfc_hba *phba = vport->phba;
807 struct lpfc_vport **vports;
808 int i, active_vlink_present = 0 ;
810 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
811 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
812 * PLOGIs during LOGO storms from a device.
814 spin_lock_irq(&ndlp->lock);
815 ndlp->nlp_flag |= NLP_LOGO_ACC;
816 spin_unlock_irq(&ndlp->lock);
817 if (els_cmd == ELS_CMD_PRLO)
818 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
820 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
822 /* This clause allows the initiator to ACC the LOGO back to the
823 * Fabric Domain Controller. It does deliberately skip all other
824 * steps because some fabrics send RDP requests after logging out
825 * from the initiator.
827 if (ndlp->nlp_type & NLP_FABRIC &&
828 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
831 /* Notify transport of connectivity loss to trigger cleanup. */
832 if (phba->nvmet_support &&
833 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
834 lpfc_nvmet_invalidate_host(phba, ndlp);
836 if (ndlp->nlp_DID == Fabric_DID) {
837 if (vport->port_state <= LPFC_FDISC ||
838 vport->fc_flag & FC_PT2PT)
840 lpfc_linkdown_port(vport);
841 spin_lock_irq(shost->host_lock);
842 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
843 spin_unlock_irq(shost->host_lock);
844 vports = lpfc_create_vport_work_array(phba);
846 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
848 if ((!(vports[i]->fc_flag &
849 FC_VPORT_LOGO_RCVD)) &&
850 (vports[i]->port_state > LPFC_FDISC)) {
851 active_vlink_present = 1;
855 lpfc_destroy_vport_work_array(phba, vports);
859 * Don't re-instantiate if vport is marked for deletion.
860 * If we are here first then vport_delete is going to wait
861 * for discovery to complete.
863 if (!(vport->load_flag & FC_UNLOADING) &&
864 active_vlink_present) {
866 * If there are other active VLinks present,
867 * re-instantiate the Vlink using FDISC.
869 mod_timer(&ndlp->nlp_delayfunc,
870 jiffies + msecs_to_jiffies(1000));
871 spin_lock_irq(&ndlp->lock);
872 ndlp->nlp_flag |= NLP_DELAY_TMO;
873 spin_unlock_irq(&ndlp->lock);
874 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
875 vport->port_state = LPFC_FDISC;
877 spin_lock_irq(shost->host_lock);
878 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
879 spin_unlock_irq(shost->host_lock);
880 lpfc_retry_pport_discovery(phba);
882 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
883 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
884 (ndlp->nlp_type & NLP_NVME_TARGET) ||
885 (vport->fc_flag & FC_PT2PT))) ||
886 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
887 /* Only try to re-login if this is NOT a Fabric Node
888 * AND the remote NPORT is a FCP/NVME Target or we
889 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
890 * case for LOGO as a response to ADISC behavior.
892 mod_timer(&ndlp->nlp_delayfunc,
893 jiffies + msecs_to_jiffies(1000 * 1));
894 spin_lock_irq(&ndlp->lock);
895 ndlp->nlp_flag |= NLP_DELAY_TMO;
896 spin_unlock_irq(&ndlp->lock);
898 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
901 /* Unregister from backend, could have been skipped due to ADISC */
902 lpfc_nlp_unreg_node(vport, ndlp);
904 ndlp->nlp_prev_state = ndlp->nlp_state;
905 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
907 spin_lock_irq(&ndlp->lock);
908 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
909 spin_unlock_irq(&ndlp->lock);
910 /* The driver has to wait until the ACC completes before it continues
911 * processing the LOGO. The action will resume in
912 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
913 * unreg_login, the driver waits so the ACC does not get aborted.
919 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
920 struct lpfc_nodelist *ndlp,
921 struct lpfc_iocbq *cmdiocb)
927 payload = cmdiocb->cmd_dmabuf->virt;
929 if (vport->phba->nvmet_support) {
930 /* Must be a NVME PRLI */
931 if (cmd == ELS_CMD_PRLI)
934 /* Initiator mode. */
935 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
940 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
941 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
942 "state x%x flags x%x\n",
943 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
945 memset(&stat, 0, sizeof(struct ls_rjt));
946 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
947 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
948 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
954 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
955 struct lpfc_iocbq *cmdiocb)
957 struct lpfc_hba *phba = vport->phba;
958 struct lpfc_dmabuf *pcmd;
961 struct fc_rport *rport = ndlp->rport;
964 pcmd = cmdiocb->cmd_dmabuf;
965 lp = (uint32_t *)pcmd->virt;
966 npr = (PRLI *)((uint8_t *)lp + sizeof(uint32_t));
968 if ((npr->prliType == PRLI_FCP_TYPE) ||
969 (npr->prliType == PRLI_NVME_TYPE)) {
970 if (npr->initiatorFunc) {
971 if (npr->prliType == PRLI_FCP_TYPE)
972 ndlp->nlp_type |= NLP_FCP_INITIATOR;
973 if (npr->prliType == PRLI_NVME_TYPE)
974 ndlp->nlp_type |= NLP_NVME_INITIATOR;
976 if (npr->targetFunc) {
977 if (npr->prliType == PRLI_FCP_TYPE)
978 ndlp->nlp_type |= NLP_FCP_TARGET;
979 if (npr->prliType == PRLI_NVME_TYPE)
980 ndlp->nlp_type |= NLP_NVME_TARGET;
981 if (npr->writeXferRdyDis)
982 ndlp->nlp_flag |= NLP_FIRSTBURST;
984 if (npr->Retry && ndlp->nlp_type &
985 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
986 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
988 if (npr->Retry && phba->nsler &&
989 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
990 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
993 /* If this driver is in nvme target mode, set the ndlp's fc4
994 * type to NVME provided the PRLI response claims NVME FC4
995 * type. Target mode does not issue gft_id so doesn't get
996 * the fc4 type set until now.
998 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
999 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1000 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1003 /* Fabric Controllers send FCP PRLI as an initiator but should
1004 * not get recognized as FCP type and registered with transport.
1006 if (npr->prliType == PRLI_FCP_TYPE &&
1007 !(ndlp->nlp_type & NLP_FABRIC))
1008 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1011 /* We need to update the rport role values */
1012 roles = FC_RPORT_ROLE_UNKNOWN;
1013 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1014 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1015 if (ndlp->nlp_type & NLP_FCP_TARGET)
1016 roles |= FC_RPORT_ROLE_FCP_TARGET;
1018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1019 "rport rolechg: role:x%x did:x%x flg:x%x",
1020 roles, ndlp->nlp_DID, ndlp->nlp_flag);
1022 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1023 fc_remote_port_rolechg(rport, roles);
1028 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1030 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1031 spin_lock_irq(&ndlp->lock);
1032 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1033 spin_unlock_irq(&ndlp->lock);
1037 if (!(vport->fc_flag & FC_PT2PT)) {
1038 /* Check config parameter use-adisc or FCP-2 */
1039 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1040 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1041 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1042 spin_lock_irq(&ndlp->lock);
1043 ndlp->nlp_flag |= NLP_NPR_ADISC;
1044 spin_unlock_irq(&ndlp->lock);
1049 spin_lock_irq(&ndlp->lock);
1050 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1051 spin_unlock_irq(&ndlp->lock);
1052 lpfc_unreg_rpi(vport, ndlp);
1057 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1058 * @phba : Pointer to lpfc_hba structure.
1059 * @vport: Pointer to lpfc_vport structure.
1060 * @ndlp: Pointer to lpfc_nodelist structure.
1061 * @rpi : rpi to be release.
1063 * This function will send a unreg_login mailbox command to the firmware
1067 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1068 struct lpfc_nodelist *ndlp, uint16_t rpi)
1073 /* If there is already an UNREG in progress for this ndlp,
1074 * no need to queue up another one.
1076 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1077 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1078 "1435 release_rpi SKIP UNREG x%x on "
1079 "NPort x%x deferred x%x flg x%x "
1081 ndlp->nlp_rpi, ndlp->nlp_DID,
1082 ndlp->nlp_defer_did,
1083 ndlp->nlp_flag, ndlp);
1087 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1090 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1091 "2796 mailbox memory allocation failed \n");
1093 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1094 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1096 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1097 if (!pmb->ctx_ndlp) {
1098 mempool_free(pmb, phba->mbox_mem_pool);
1102 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1103 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1104 ndlp->nlp_flag |= NLP_UNREG_INP;
1106 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1107 "1437 release_rpi UNREG x%x "
1108 "on NPort x%x flg x%x\n",
1109 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1111 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1112 if (rc == MBX_NOT_FINISHED) {
1114 mempool_free(pmb, phba->mbox_mem_pool);
1120 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1121 void *arg, uint32_t evt)
1123 struct lpfc_hba *phba;
1124 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1128 /* Release the RPI if reglogin completing */
1129 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1130 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1131 (!pmb->u.mb.mbxStatus)) {
1132 rpi = pmb->u.mb.un.varWords[0];
1133 lpfc_release_rpi(phba, vport, ndlp, rpi);
1135 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1136 "0271 Illegal State Transition: node x%x "
1137 "event x%x, state x%x Data: x%x x%x\n",
1138 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1140 return ndlp->nlp_state;
1144 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1145 void *arg, uint32_t evt)
1147 /* This transition is only legal if we previously
1148 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1149 * working on the same NPortID, do nothing for this thread
1152 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1153 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1154 "0272 Illegal State Transition: node x%x "
1155 "event x%x, state x%x Data: x%x x%x\n",
1156 ndlp->nlp_DID, evt, ndlp->nlp_state,
1157 ndlp->nlp_rpi, ndlp->nlp_flag);
1159 return ndlp->nlp_state;
1162 /* Start of Discovery State Machine routines */
1165 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1166 void *arg, uint32_t evt)
1168 struct lpfc_iocbq *cmdiocb;
1170 cmdiocb = (struct lpfc_iocbq *) arg;
1172 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1173 return ndlp->nlp_state;
1175 return NLP_STE_FREED_NODE;
1179 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1180 void *arg, uint32_t evt)
1182 lpfc_issue_els_logo(vport, ndlp, 0);
1183 return ndlp->nlp_state;
1187 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1188 void *arg, uint32_t evt)
1190 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1192 spin_lock_irq(&ndlp->lock);
1193 ndlp->nlp_flag |= NLP_LOGO_ACC;
1194 spin_unlock_irq(&ndlp->lock);
1195 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1197 return ndlp->nlp_state;
1201 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1202 void *arg, uint32_t evt)
1204 return NLP_STE_FREED_NODE;
1208 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1209 void *arg, uint32_t evt)
1211 return NLP_STE_FREED_NODE;
1215 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1216 struct lpfc_nodelist *ndlp,
1217 void *arg, uint32_t evt)
1219 return ndlp->nlp_state;
1223 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1224 void *arg, uint32_t evt)
1226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1227 struct lpfc_hba *phba = vport->phba;
1228 struct lpfc_iocbq *cmdiocb = arg;
1229 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
1230 uint32_t *lp = (uint32_t *) pcmd->virt;
1231 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1235 memset(&stat, 0, sizeof (struct ls_rjt));
1237 /* For a PLOGI, we only accept if our portname is less
1238 * than the remote portname.
1240 phba->fc_stat.elsLogiCol++;
1241 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1242 sizeof(struct lpfc_name));
1244 if (port_cmp >= 0) {
1245 /* Reject this request because the remote node will accept
1247 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1248 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1249 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1252 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1253 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1254 (vport->num_disc_nodes)) {
1255 spin_lock_irq(&ndlp->lock);
1256 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1257 spin_unlock_irq(&ndlp->lock);
1258 /* Check if there are more PLOGIs to be sent */
1259 lpfc_more_plogi(vport);
1260 if (vport->num_disc_nodes == 0) {
1261 spin_lock_irq(shost->host_lock);
1262 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1263 spin_unlock_irq(shost->host_lock);
1264 lpfc_can_disctmo(vport);
1265 lpfc_end_rscn(vport);
1268 } /* If our portname was less */
1270 return ndlp->nlp_state;
1274 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1275 void *arg, uint32_t evt)
1277 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1280 memset(&stat, 0, sizeof (struct ls_rjt));
1281 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1282 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1283 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1284 return ndlp->nlp_state;
1288 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1289 void *arg, uint32_t evt)
1291 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1293 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1294 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1295 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1296 /* software abort outstanding PLOGI */
1297 lpfc_els_abort(vport->phba, ndlp);
1299 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1300 return ndlp->nlp_state;
1304 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1305 void *arg, uint32_t evt)
1307 struct lpfc_hba *phba = vport->phba;
1308 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1310 /* software abort outstanding PLOGI */
1311 lpfc_els_abort(phba, ndlp);
1313 if (evt == NLP_EVT_RCV_LOGO) {
1314 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1316 lpfc_issue_els_logo(vport, ndlp, 0);
1319 /* Put ndlp in npr state set plogi timer for 1 sec */
1320 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1321 spin_lock_irq(&ndlp->lock);
1322 ndlp->nlp_flag |= NLP_DELAY_TMO;
1323 spin_unlock_irq(&ndlp->lock);
1324 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1325 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1328 return ndlp->nlp_state;
1332 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1333 struct lpfc_nodelist *ndlp,
1337 struct lpfc_hba *phba = vport->phba;
1338 struct lpfc_iocbq *cmdiocb, *rspiocb;
1339 struct lpfc_dmabuf *pcmd, *prsp;
1342 struct serv_parm *sp;
1349 cmdiocb = (struct lpfc_iocbq *) arg;
1350 rspiocb = cmdiocb->rsp_iocb;
1352 ulp_status = get_job_ulpstatus(phba, rspiocb);
1354 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1355 /* Recovery from PLOGI collision logic */
1356 return ndlp->nlp_state;
1362 pcmd = cmdiocb->cmd_dmabuf;
1364 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1368 lp = (uint32_t *) prsp->virt;
1369 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1371 /* Some switches have FDMI servers returning 0 for WWN */
1372 if ((ndlp->nlp_DID != FDMI_DID) &&
1373 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1374 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1375 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1376 "0142 PLOGI RSP: Invalid WWN.\n");
1379 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1381 /* PLOGI chkparm OK */
1382 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1383 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1384 ndlp->nlp_DID, ndlp->nlp_state,
1385 ndlp->nlp_flag, ndlp->nlp_rpi);
1386 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1387 ndlp->nlp_fcp_info |= CLASS2;
1389 ndlp->nlp_fcp_info |= CLASS3;
1391 ndlp->nlp_class_sup = 0;
1392 if (sp->cls1.classValid)
1393 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1394 if (sp->cls2.classValid)
1395 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1396 if (sp->cls3.classValid)
1397 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1398 if (sp->cls4.classValid)
1399 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1400 ndlp->nlp_maxframe =
1401 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1403 if ((vport->fc_flag & FC_PT2PT) &&
1404 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1405 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1406 if (sp->cmn.edtovResolution) {
1407 /* E_D_TOV ticks are in nanoseconds */
1408 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1411 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1412 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1413 sp->cmn.valid_vendor_ver_level) {
1414 vid = be32_to_cpu(sp->un.vv.vid);
1415 flag = be32_to_cpu(sp->un.vv.flags);
1416 if ((vid == LPFC_VV_EMLX_ID) &&
1417 (flag & LPFC_VV_SUPPRESS_RSP))
1418 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1422 * Use the larger EDTOV
1423 * RATOV = 2 * EDTOV for pt-to-pt
1425 if (ed_tov > phba->fc_edtov)
1426 phba->fc_edtov = ed_tov;
1427 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1429 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1431 /* Issue config_link / reg_vfi to account for updated TOV's */
1432 if (phba->sli_rev == LPFC_SLI_REV4) {
1433 lpfc_issue_reg_vfi(vport);
1435 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1437 lpfc_printf_vlog(vport, KERN_ERR,
1439 "0133 PLOGI: no memory "
1441 "Data: x%x x%x x%x x%x\n",
1442 ndlp->nlp_DID, ndlp->nlp_state,
1443 ndlp->nlp_flag, ndlp->nlp_rpi);
1447 lpfc_config_link(phba, mbox);
1449 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1450 mbox->vport = vport;
1451 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1452 if (rc == MBX_NOT_FINISHED) {
1453 mempool_free(mbox, phba->mbox_mem_pool);
1459 lpfc_unreg_rpi(vport, ndlp);
1461 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1463 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1464 "0018 PLOGI: no memory for reg_login "
1465 "Data: x%x x%x x%x x%x\n",
1466 ndlp->nlp_DID, ndlp->nlp_state,
1467 ndlp->nlp_flag, ndlp->nlp_rpi);
1471 did = get_job_els_rsp64_did(phba, cmdiocb);
1473 if (lpfc_reg_rpi(phba, vport->vpi, did,
1474 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1475 switch (ndlp->nlp_DID) {
1476 case NameServer_DID:
1477 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1478 /* Fabric Controller Node needs these parameters. */
1479 memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
1482 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1485 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1486 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1489 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1490 if (!mbox->ctx_ndlp)
1493 mbox->vport = vport;
1494 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1495 != MBX_NOT_FINISHED) {
1496 lpfc_nlp_set_state(vport, ndlp,
1497 NLP_STE_REG_LOGIN_ISSUE);
1498 return ndlp->nlp_state;
1500 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1501 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1502 /* decrement node reference count to the failed mbox
1506 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
1507 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1508 "0134 PLOGI: cannot issue reg_login "
1509 "Data: x%x x%x x%x x%x\n",
1510 ndlp->nlp_DID, ndlp->nlp_state,
1511 ndlp->nlp_flag, ndlp->nlp_rpi);
1513 mempool_free(mbox, phba->mbox_mem_pool);
1515 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1516 "0135 PLOGI: cannot format reg_login "
1517 "Data: x%x x%x x%x x%x\n",
1518 ndlp->nlp_DID, ndlp->nlp_state,
1519 ndlp->nlp_flag, ndlp->nlp_rpi);
1524 if (ndlp->nlp_DID == NameServer_DID) {
1525 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1526 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1527 "0261 Cannot Register NameServer login\n");
1531 ** In case the node reference counter does not go to zero, ensure that
1532 ** the stale state for the node is not processed.
1535 ndlp->nlp_prev_state = ndlp->nlp_state;
1536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1537 return NLP_STE_FREED_NODE;
1541 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1542 void *arg, uint32_t evt)
1544 return ndlp->nlp_state;
1548 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1549 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1551 struct lpfc_hba *phba;
1552 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1553 MAILBOX_t *mb = &pmb->u.mb;
1557 /* Release the RPI */
1558 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1560 rpi = pmb->u.mb.un.varWords[0];
1561 lpfc_release_rpi(phba, vport, ndlp, rpi);
1563 return ndlp->nlp_state;
1567 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1568 void *arg, uint32_t evt)
1570 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1571 spin_lock_irq(&ndlp->lock);
1572 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1573 spin_unlock_irq(&ndlp->lock);
1574 return ndlp->nlp_state;
1576 /* software abort outstanding PLOGI */
1577 lpfc_els_abort(vport->phba, ndlp);
1579 lpfc_drop_node(vport, ndlp);
1580 return NLP_STE_FREED_NODE;
1585 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1586 struct lpfc_nodelist *ndlp,
1590 struct lpfc_hba *phba = vport->phba;
1592 /* Don't do anything that will mess up processing of the
1595 if (vport->fc_flag & FC_RSCN_DEFERRED)
1596 return ndlp->nlp_state;
1598 /* software abort outstanding PLOGI */
1599 lpfc_els_abort(phba, ndlp);
1601 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1602 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1603 spin_lock_irq(&ndlp->lock);
1604 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1605 spin_unlock_irq(&ndlp->lock);
1607 return ndlp->nlp_state;
1611 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1612 void *arg, uint32_t evt)
1614 struct lpfc_hba *phba = vport->phba;
1615 struct lpfc_iocbq *cmdiocb;
1617 /* software abort outstanding ADISC */
1618 lpfc_els_abort(phba, ndlp);
1620 cmdiocb = (struct lpfc_iocbq *) arg;
1622 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1623 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1624 spin_lock_irq(&ndlp->lock);
1625 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1626 spin_unlock_irq(&ndlp->lock);
1627 if (vport->num_disc_nodes)
1628 lpfc_more_adisc(vport);
1630 return ndlp->nlp_state;
1632 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1633 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1634 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1636 return ndlp->nlp_state;
1640 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1641 void *arg, uint32_t evt)
1643 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1645 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1646 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1647 return ndlp->nlp_state;
1651 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1652 void *arg, uint32_t evt)
1654 struct lpfc_hba *phba = vport->phba;
1655 struct lpfc_iocbq *cmdiocb;
1657 cmdiocb = (struct lpfc_iocbq *) arg;
1659 /* software abort outstanding ADISC */
1660 lpfc_els_abort(phba, ndlp);
1662 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1663 return ndlp->nlp_state;
1667 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1668 struct lpfc_nodelist *ndlp,
1669 void *arg, uint32_t evt)
1671 struct lpfc_iocbq *cmdiocb;
1673 cmdiocb = (struct lpfc_iocbq *) arg;
1675 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1676 return ndlp->nlp_state;
1680 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1681 void *arg, uint32_t evt)
1683 struct lpfc_iocbq *cmdiocb;
1685 cmdiocb = (struct lpfc_iocbq *) arg;
1687 /* Treat like rcv logo */
1688 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1689 return ndlp->nlp_state;
1693 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1694 struct lpfc_nodelist *ndlp,
1695 void *arg, uint32_t evt)
1697 struct lpfc_hba *phba = vport->phba;
1698 struct lpfc_iocbq *cmdiocb, *rspiocb;
1703 cmdiocb = (struct lpfc_iocbq *) arg;
1704 rspiocb = cmdiocb->rsp_iocb;
1706 ulp_status = get_job_ulpstatus(phba, rspiocb);
1708 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1711 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1713 mod_timer(&ndlp->nlp_delayfunc,
1714 jiffies + msecs_to_jiffies(1000));
1715 spin_lock_irq(&ndlp->lock);
1716 ndlp->nlp_flag |= NLP_DELAY_TMO;
1717 spin_unlock_irq(&ndlp->lock);
1718 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1720 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1722 lpfc_unreg_rpi(vport, ndlp);
1723 return ndlp->nlp_state;
1726 if (phba->sli_rev == LPFC_SLI_REV4) {
1727 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1729 /* Stay in state and retry. */
1730 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1731 return ndlp->nlp_state;
1735 if (ndlp->nlp_type & NLP_FCP_TARGET)
1736 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1738 if (ndlp->nlp_type & NLP_NVME_TARGET)
1739 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1741 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1742 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1745 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1746 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1749 return ndlp->nlp_state;
1753 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1754 void *arg, uint32_t evt)
1756 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1757 spin_lock_irq(&ndlp->lock);
1758 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1759 spin_unlock_irq(&ndlp->lock);
1760 return ndlp->nlp_state;
1762 /* software abort outstanding ADISC */
1763 lpfc_els_abort(vport->phba, ndlp);
1765 lpfc_drop_node(vport, ndlp);
1766 return NLP_STE_FREED_NODE;
1771 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1772 struct lpfc_nodelist *ndlp,
1776 struct lpfc_hba *phba = vport->phba;
1778 /* Don't do anything that will mess up processing of the
1781 if (vport->fc_flag & FC_RSCN_DEFERRED)
1782 return ndlp->nlp_state;
1784 /* software abort outstanding ADISC */
1785 lpfc_els_abort(phba, ndlp);
1787 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1788 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1789 spin_lock_irq(&ndlp->lock);
1790 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1791 spin_unlock_irq(&ndlp->lock);
1792 lpfc_disc_set_adisc(vport, ndlp);
1793 return ndlp->nlp_state;
1797 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1798 struct lpfc_nodelist *ndlp,
1802 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1804 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1805 return ndlp->nlp_state;
1809 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1810 struct lpfc_nodelist *ndlp,
1814 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1817 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1818 return ndlp->nlp_state;
1820 if (vport->phba->nvmet_support) {
1821 /* NVME Target mode. Handle and respond to the PRLI and
1822 * transition to UNMAPPED provided the RPI has completed
1825 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1826 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1827 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1829 /* RPI registration has not completed. Reject the PRLI
1830 * to prevent an illegal state transition when the
1831 * rpi registration does complete.
1833 memset(&stat, 0, sizeof(struct ls_rjt));
1834 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1835 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1836 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1838 return ndlp->nlp_state;
1841 /* Initiator mode. */
1842 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1844 return ndlp->nlp_state;
1848 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1849 struct lpfc_nodelist *ndlp,
1853 struct lpfc_hba *phba = vport->phba;
1854 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1856 LPFC_MBOXQ_t *nextmb;
1857 struct lpfc_nodelist *ns_ndlp;
1859 cmdiocb = (struct lpfc_iocbq *) arg;
1861 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1862 if ((mb = phba->sli.mbox_active)) {
1863 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1864 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1865 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1867 mb->ctx_ndlp = NULL;
1868 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1872 spin_lock_irq(&phba->hbalock);
1873 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1874 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1875 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1876 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1878 list_del(&mb->list);
1879 phba->sli.mboxq_cnt--;
1880 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
1883 spin_unlock_irq(&phba->hbalock);
1885 /* software abort if any GID_FT is outstanding */
1886 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1887 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1889 lpfc_els_abort(phba, ns_ndlp);
1892 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1893 return ndlp->nlp_state;
1897 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1898 struct lpfc_nodelist *ndlp,
1902 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1904 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1905 return ndlp->nlp_state;
1909 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1910 struct lpfc_nodelist *ndlp,
1914 struct lpfc_iocbq *cmdiocb;
1916 cmdiocb = (struct lpfc_iocbq *) arg;
1917 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1918 return ndlp->nlp_state;
1922 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1923 struct lpfc_nodelist *ndlp,
1927 struct lpfc_hba *phba = vport->phba;
1928 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1929 MAILBOX_t *mb = &pmb->u.mb;
1930 uint32_t did = mb->un.varWords[1];
1932 if (mb->mbxStatus) {
1933 /* RegLogin failed */
1934 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1935 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1937 did, mb->mbxStatus, vport->port_state,
1938 mb->un.varRegLogin.vpi,
1939 mb->un.varRegLogin.rpi);
1941 * If RegLogin failed due to lack of HBA resources do not
1944 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1945 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1946 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1947 return ndlp->nlp_state;
1950 /* Put ndlp in npr state set plogi timer for 1 sec */
1951 mod_timer(&ndlp->nlp_delayfunc,
1952 jiffies + msecs_to_jiffies(1000 * 1));
1953 spin_lock_irq(&ndlp->lock);
1954 ndlp->nlp_flag |= NLP_DELAY_TMO;
1955 spin_unlock_irq(&ndlp->lock);
1956 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1958 lpfc_issue_els_logo(vport, ndlp, 0);
1959 return ndlp->nlp_state;
1962 /* SLI4 ports have preallocated logical rpis. */
1963 if (phba->sli_rev < LPFC_SLI_REV4)
1964 ndlp->nlp_rpi = mb->un.varWords[0];
1966 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1968 /* Only if we are not a fabric nport do we issue PRLI */
1969 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1970 "3066 RegLogin Complete on x%x x%x x%x\n",
1971 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1972 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1973 (phba->nvmet_support == 0)) {
1974 /* The driver supports FCP and NVME concurrently. If the
1975 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1976 * know what PRLI to send yet. Figure that out now and
1977 * call PRLI depending on the outcome.
1979 if (vport->fc_flag & FC_PT2PT) {
1980 /* If we are pt2pt, there is no Fabric to determine
1981 * the FC4 type of the remote nport. So if NVME
1982 * is configured try it.
1984 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1985 if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
1986 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1987 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1988 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1989 /* We need to update the localport also */
1990 lpfc_nvme_update_localport(vport);
1993 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1994 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1996 } else if (ndlp->nlp_fc4_type == 0) {
1997 /* If we are only configured for FCP, the driver
1998 * should just issue PRLI for FCP. Otherwise issue
1999 * GFT_ID to determine if remote port supports NVME.
2001 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
2002 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
2004 return ndlp->nlp_state;
2006 ndlp->nlp_fc4_type = NLP_FC4_FCP;
2009 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2010 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2011 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
2012 lpfc_issue_els_logo(vport, ndlp, 0);
2013 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2017 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
2018 phba->targetport->port_id = vport->fc_myDID;
2020 /* Only Fabric ports should transition. NVME target
2021 * must complete PRLI.
2023 if (ndlp->nlp_type & NLP_FABRIC) {
2024 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2025 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2029 return ndlp->nlp_state;
2033 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2034 struct lpfc_nodelist *ndlp,
2038 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2039 spin_lock_irq(&ndlp->lock);
2040 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2041 spin_unlock_irq(&ndlp->lock);
2042 return ndlp->nlp_state;
2044 lpfc_drop_node(vport, ndlp);
2045 return NLP_STE_FREED_NODE;
2050 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2051 struct lpfc_nodelist *ndlp,
2055 /* Don't do anything that will mess up processing of the
2058 if (vport->fc_flag & FC_RSCN_DEFERRED)
2059 return ndlp->nlp_state;
2061 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2062 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2063 spin_lock_irq(&ndlp->lock);
2065 /* If we are a target we won't immediately transition into PRLI,
2066 * so if REG_LOGIN already completed we don't need to ignore it.
2068 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2069 !vport->phba->nvmet_support)
2070 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2072 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2073 spin_unlock_irq(&ndlp->lock);
2074 lpfc_disc_set_adisc(vport, ndlp);
2075 return ndlp->nlp_state;
2079 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2080 void *arg, uint32_t evt)
2082 struct lpfc_iocbq *cmdiocb;
2084 cmdiocb = (struct lpfc_iocbq *) arg;
2086 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2087 return ndlp->nlp_state;
2091 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2092 void *arg, uint32_t evt)
2094 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2096 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2097 return ndlp->nlp_state;
2098 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2099 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2100 return ndlp->nlp_state;
2104 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2105 void *arg, uint32_t evt)
2107 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2109 /* Software abort outstanding PRLI before sending acc */
2110 lpfc_els_abort(vport->phba, ndlp);
2112 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2113 return ndlp->nlp_state;
2117 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2118 void *arg, uint32_t evt)
2120 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2122 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2123 return ndlp->nlp_state;
2126 /* This routine is envoked when we rcv a PRLO request from a nport
2127 * we are logged into. We should send back a PRLO rsp setting the
2129 * NEXT STATE = PRLI_ISSUE
2132 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2133 void *arg, uint32_t evt)
2135 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2137 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2138 return ndlp->nlp_state;
2142 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2143 void *arg, uint32_t evt)
2145 struct lpfc_iocbq *cmdiocb, *rspiocb;
2146 struct lpfc_hba *phba = vport->phba;
2148 struct lpfc_nvme_prli *nvpr;
2152 cmdiocb = (struct lpfc_iocbq *) arg;
2153 rspiocb = cmdiocb->rsp_iocb;
2155 ulp_status = get_job_ulpstatus(phba, rspiocb);
2157 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2158 * format is different so NULL the two PRLI types so that the
2159 * driver correctly gets the correct context.
2163 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2164 if (cmdiocb->cmd_flag & LPFC_PRLI_FCP_REQ)
2165 npr = (PRLI *) temp_ptr;
2166 else if (cmdiocb->cmd_flag & LPFC_PRLI_NVME_REQ)
2167 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2170 if ((vport->port_type == LPFC_NPIV_PORT) &&
2171 vport->cfg_restrict_login) {
2175 /* Adjust the nlp_type accordingly if the PRLI failed */
2177 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2179 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2181 /* We can't set the DSM state till BOTH PRLIs complete */
2185 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2186 (npr->prliType == PRLI_FCP_TYPE)) {
2187 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2188 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2191 if (npr->initiatorFunc)
2192 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2193 if (npr->targetFunc) {
2194 ndlp->nlp_type |= NLP_FCP_TARGET;
2195 if (npr->writeXferRdyDis)
2196 ndlp->nlp_flag |= NLP_FIRSTBURST;
2199 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2202 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2203 PRLI_REQ_EXECUTED) &&
2204 (bf_get_be32(prli_type_code, nvpr) ==
2207 /* Complete setting up the remote ndlp personality. */
2208 if (bf_get_be32(prli_init, nvpr))
2209 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2211 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2212 bf_get_be32(prli_conf, nvpr))
2214 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2216 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2218 /* Target driver cannot solicit NVME FB. */
2219 if (bf_get_be32(prli_tgt, nvpr)) {
2220 /* Complete the nvme target roles. The transport
2221 * needs to know if the rport is capable of
2222 * discovery in addition to its role.
2224 ndlp->nlp_type |= NLP_NVME_TARGET;
2225 if (bf_get_be32(prli_disc, nvpr))
2226 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2229 * If prli_fba is set, the Target supports FirstBurst.
2230 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2231 * otherwise it defines the actual size supported by
2234 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2235 (phba->cfg_nvme_enable_fb) &&
2236 (!phba->nvmet_support)) {
2237 /* Both sides support FB. The target's first
2238 * burst size is a 512 byte encoded value.
2240 ndlp->nlp_flag |= NLP_FIRSTBURST;
2241 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2244 /* Expressed in units of 512 bytes */
2245 if (ndlp->nvme_fb_size)
2246 ndlp->nvme_fb_size <<=
2249 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2253 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2254 "6029 NVME PRLI Cmpl w1 x%08x "
2255 "w4 x%08x w5 x%08x flag x%x, "
2256 "fcp_info x%x nlp_type x%x\n",
2257 be32_to_cpu(nvpr->word1),
2258 be32_to_cpu(nvpr->word4),
2259 be32_to_cpu(nvpr->word5),
2260 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2263 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2264 (vport->port_type == LPFC_NPIV_PORT) &&
2265 vport->cfg_restrict_login) {
2267 spin_lock_irq(&ndlp->lock);
2268 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2269 spin_unlock_irq(&ndlp->lock);
2270 lpfc_issue_els_logo(vport, ndlp, 0);
2272 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2273 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2274 return ndlp->nlp_state;
2278 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2281 if (ndlp->fc4_prli_sent == 0) {
2282 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2283 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2284 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2285 else if (ndlp->nlp_type &
2286 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2287 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2289 lpfc_printf_vlog(vport,
2291 "3067 PRLI's still outstanding "
2292 "on x%06x - count %d, Pend Node Mode "
2294 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2296 return ndlp->nlp_state;
2299 /*! lpfc_device_rm_prli_issue
2310 * This routine is envoked when we a request to remove a nport we are in the
2311 * process of PRLIing. We should software abort outstanding prli, unreg
2312 * login, send a logout. We will change node state to UNUSED_NODE, put it
2313 * on plogi list so it can be freed when LOGO completes.
2318 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2319 void *arg, uint32_t evt)
2321 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2322 spin_lock_irq(&ndlp->lock);
2323 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2324 spin_unlock_irq(&ndlp->lock);
2325 return ndlp->nlp_state;
2327 /* software abort outstanding PLOGI */
2328 lpfc_els_abort(vport->phba, ndlp);
2330 lpfc_drop_node(vport, ndlp);
2331 return NLP_STE_FREED_NODE;
2336 /*! lpfc_device_recov_prli_issue
2347 * The routine is envoked when the state of a device is unknown, like
2348 * during a link down. We should remove the nodelist entry from the
2349 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2350 * outstanding PRLI command, then free the node entry.
2353 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2354 struct lpfc_nodelist *ndlp,
2358 struct lpfc_hba *phba = vport->phba;
2360 /* Don't do anything that will mess up processing of the
2363 if (vport->fc_flag & FC_RSCN_DEFERRED)
2364 return ndlp->nlp_state;
2366 /* software abort outstanding PRLI */
2367 lpfc_els_abort(phba, ndlp);
2369 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2370 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2371 spin_lock_irq(&ndlp->lock);
2372 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2373 spin_unlock_irq(&ndlp->lock);
2374 lpfc_disc_set_adisc(vport, ndlp);
2375 return ndlp->nlp_state;
2379 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2380 void *arg, uint32_t evt)
2382 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2385 memset(&stat, 0, sizeof(struct ls_rjt));
2386 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2387 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2388 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2389 return ndlp->nlp_state;
2393 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2394 void *arg, uint32_t evt)
2396 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2399 memset(&stat, 0, sizeof(struct ls_rjt));
2400 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2401 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2402 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2403 return ndlp->nlp_state;
2407 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2408 void *arg, uint32_t evt)
2410 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2412 spin_lock_irq(&ndlp->lock);
2413 ndlp->nlp_flag |= NLP_LOGO_ACC;
2414 spin_unlock_irq(&ndlp->lock);
2415 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2416 return ndlp->nlp_state;
2420 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2421 void *arg, uint32_t evt)
2423 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2426 memset(&stat, 0, sizeof(struct ls_rjt));
2427 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2428 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2429 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2430 return ndlp->nlp_state;
2434 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2435 void *arg, uint32_t evt)
2437 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2440 memset(&stat, 0, sizeof(struct ls_rjt));
2441 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2442 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2444 return ndlp->nlp_state;
2448 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2449 void *arg, uint32_t evt)
2451 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2453 spin_lock_irq(&ndlp->lock);
2454 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2455 spin_unlock_irq(&ndlp->lock);
2456 lpfc_disc_set_adisc(vport, ndlp);
2457 return ndlp->nlp_state;
2461 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2462 void *arg, uint32_t evt)
2465 * DevLoss has timed out and is calling for Device Remove.
2466 * In this case, abort the LOGO and cleanup the ndlp
2469 lpfc_unreg_rpi(vport, ndlp);
2470 /* software abort outstanding PLOGI */
2471 lpfc_els_abort(vport->phba, ndlp);
2472 lpfc_drop_node(vport, ndlp);
2473 return NLP_STE_FREED_NODE;
2477 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2478 struct lpfc_nodelist *ndlp,
2479 void *arg, uint32_t evt)
2482 * Device Recovery events have no meaning for a node with a LOGO
2483 * outstanding. The LOGO has to complete first and handle the
2484 * node from that point.
2486 return ndlp->nlp_state;
2490 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2491 void *arg, uint32_t evt)
2493 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2495 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2496 return ndlp->nlp_state;
2500 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2501 void *arg, uint32_t evt)
2503 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2505 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2506 return ndlp->nlp_state;
2508 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2509 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2510 return ndlp->nlp_state;
2514 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2515 void *arg, uint32_t evt)
2517 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2519 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2520 return ndlp->nlp_state;
2524 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2525 void *arg, uint32_t evt)
2527 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2529 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2530 return ndlp->nlp_state;
2534 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2535 void *arg, uint32_t evt)
2537 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2539 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2540 return ndlp->nlp_state;
2544 lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2545 struct lpfc_nodelist *ndlp,
2549 lpfc_drop_node(vport, ndlp);
2550 return NLP_STE_FREED_NODE;
2554 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2555 struct lpfc_nodelist *ndlp,
2559 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2560 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2561 spin_lock_irq(&ndlp->lock);
2562 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2563 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2564 spin_unlock_irq(&ndlp->lock);
2565 lpfc_disc_set_adisc(vport, ndlp);
2567 return ndlp->nlp_state;
2571 lpfc_rcv_plogi_mapped_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_rcv_plogi(vport, ndlp, cmdiocb);
2577 return ndlp->nlp_state;
2581 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2582 void *arg, uint32_t evt)
2584 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2586 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2587 return ndlp->nlp_state;
2588 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2589 return ndlp->nlp_state;
2593 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2594 void *arg, uint32_t evt)
2596 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2598 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2599 return ndlp->nlp_state;
2603 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2604 struct lpfc_nodelist *ndlp,
2605 void *arg, uint32_t evt)
2607 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2609 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2610 return ndlp->nlp_state;
2614 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2615 void *arg, uint32_t evt)
2617 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2619 /* flush the target */
2620 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2622 /* Treat like rcv logo */
2623 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2624 return ndlp->nlp_state;
2628 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2629 struct lpfc_nodelist *ndlp,
2633 lpfc_disc_set_adisc(vport, ndlp);
2635 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2636 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2637 spin_lock_irq(&ndlp->lock);
2638 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2639 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2640 spin_unlock_irq(&ndlp->lock);
2641 return ndlp->nlp_state;
2645 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2646 void *arg, uint32_t evt)
2648 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2650 /* Ignore PLOGI if we have an outstanding LOGO */
2651 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2652 return ndlp->nlp_state;
2653 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2654 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2655 spin_lock_irq(&ndlp->lock);
2656 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2657 spin_unlock_irq(&ndlp->lock);
2658 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2659 /* send PLOGI immediately, move to PLOGI issue state */
2660 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2661 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2662 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2663 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2666 return ndlp->nlp_state;
2670 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2671 void *arg, uint32_t evt)
2673 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2676 memset(&stat, 0, sizeof (struct ls_rjt));
2677 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2678 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2679 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2681 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2683 * ADISC nodes will be handled in regular discovery path after
2684 * receiving response from NS.
2686 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2688 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2689 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2690 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2691 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2694 return ndlp->nlp_state;
2698 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2699 void *arg, uint32_t evt)
2701 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2703 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2704 return ndlp->nlp_state;
2708 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2709 void *arg, uint32_t evt)
2711 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2713 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2715 * Do not start discovery if discovery is about to start
2716 * or discovery in progress for this node. Starting discovery
2717 * here will affect the counting of discovery threads.
2719 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2720 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2722 * ADISC nodes will be handled in regular discovery path after
2723 * receiving response from NS.
2725 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2727 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2728 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2730 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2733 return ndlp->nlp_state;
2737 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2738 void *arg, uint32_t evt)
2740 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2742 spin_lock_irq(&ndlp->lock);
2743 ndlp->nlp_flag |= NLP_LOGO_ACC;
2744 spin_unlock_irq(&ndlp->lock);
2746 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2748 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2749 mod_timer(&ndlp->nlp_delayfunc,
2750 jiffies + msecs_to_jiffies(1000 * 1));
2751 spin_lock_irq(&ndlp->lock);
2752 ndlp->nlp_flag |= NLP_DELAY_TMO;
2753 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2754 spin_unlock_irq(&ndlp->lock);
2755 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2757 spin_lock_irq(&ndlp->lock);
2758 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2759 spin_unlock_irq(&ndlp->lock);
2761 return ndlp->nlp_state;
2765 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2766 void *arg, uint32_t evt)
2768 struct lpfc_hba *phba = vport->phba;
2769 struct lpfc_iocbq *cmdiocb, *rspiocb;
2772 cmdiocb = (struct lpfc_iocbq *) arg;
2773 rspiocb = cmdiocb->rsp_iocb;
2775 ulp_status = get_job_ulpstatus(phba, rspiocb);
2778 return NLP_STE_FREED_NODE;
2780 return ndlp->nlp_state;
2784 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2785 void *arg, uint32_t evt)
2787 struct lpfc_hba *phba = vport->phba;
2788 struct lpfc_iocbq *cmdiocb, *rspiocb;
2791 cmdiocb = (struct lpfc_iocbq *) arg;
2792 rspiocb = cmdiocb->rsp_iocb;
2794 ulp_status = get_job_ulpstatus(phba, rspiocb);
2796 if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2797 lpfc_drop_node(vport, ndlp);
2798 return NLP_STE_FREED_NODE;
2800 return ndlp->nlp_state;
2804 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2805 void *arg, uint32_t evt)
2807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2809 /* For the fabric port just clear the fc flags. */
2810 if (ndlp->nlp_DID == Fabric_DID) {
2811 spin_lock_irq(shost->host_lock);
2812 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2813 spin_unlock_irq(shost->host_lock);
2815 lpfc_unreg_rpi(vport, ndlp);
2816 return ndlp->nlp_state;
2820 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2821 void *arg, uint32_t evt)
2823 struct lpfc_hba *phba = vport->phba;
2824 struct lpfc_iocbq *cmdiocb, *rspiocb;
2827 cmdiocb = (struct lpfc_iocbq *) arg;
2828 rspiocb = cmdiocb->rsp_iocb;
2830 ulp_status = get_job_ulpstatus(phba, rspiocb);
2832 if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2833 lpfc_drop_node(vport, ndlp);
2834 return NLP_STE_FREED_NODE;
2836 return ndlp->nlp_state;
2840 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2841 struct lpfc_nodelist *ndlp,
2842 void *arg, uint32_t evt)
2844 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2845 MAILBOX_t *mb = &pmb->u.mb;
2847 if (!mb->mbxStatus) {
2848 /* SLI4 ports have preallocated logical rpis. */
2849 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2850 ndlp->nlp_rpi = mb->un.varWords[0];
2851 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2852 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2853 lpfc_unreg_rpi(vport, ndlp);
2856 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2857 lpfc_drop_node(vport, ndlp);
2858 return NLP_STE_FREED_NODE;
2861 return ndlp->nlp_state;
2865 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2866 void *arg, uint32_t evt)
2868 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2869 spin_lock_irq(&ndlp->lock);
2870 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2871 spin_unlock_irq(&ndlp->lock);
2872 return ndlp->nlp_state;
2874 lpfc_drop_node(vport, ndlp);
2875 return NLP_STE_FREED_NODE;
2879 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2880 void *arg, uint32_t evt)
2882 /* Don't do anything that will mess up processing of the
2885 if (vport->fc_flag & FC_RSCN_DEFERRED)
2886 return ndlp->nlp_state;
2888 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2889 spin_lock_irq(&ndlp->lock);
2890 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2891 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2892 spin_unlock_irq(&ndlp->lock);
2893 return ndlp->nlp_state;
2897 /* This next section defines the NPort Discovery State Machine */
2899 /* There are 4 different double linked lists nodelist entries can reside on.
2900 * The plogi list and adisc list are used when Link Up discovery or RSCN
2901 * processing is needed. Each list holds the nodes that we will send PLOGI
2902 * or ADISC on. These lists will keep track of what nodes will be effected
2903 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2904 * The unmapped_list will contain all nodes that we have successfully logged
2905 * into at the Fibre Channel level. The mapped_list will contain all nodes
2906 * that are mapped FCP targets.
2909 * The bind list is a list of undiscovered (potentially non-existent) nodes
2910 * that we have saved binding information on. This information is used when
2911 * nodes transition from the unmapped to the mapped list.
2913 /* For UNUSED_NODE state, the node has just been allocated .
2914 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2915 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2916 * and put on the unmapped list. For ADISC processing, the node is taken off
2917 * the ADISC list and placed on either the mapped or unmapped list (depending
2918 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2919 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2920 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2921 * node, the node is taken off the unmapped list. The binding list is checked
2922 * for a valid binding, or a binding is automatically assigned. If binding
2923 * assignment is unsuccessful, the node is left on the unmapped list. If
2924 * binding assignment is successful, the associated binding list entry (if
2925 * any) is removed, and the node is placed on the mapped list.
2928 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2929 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2930 * expire, all effected nodes will receive a DEVICE_RM event.
2933 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2934 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2935 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2936 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2937 * we will first process the ADISC list. 32 entries are processed initially and
2938 * ADISC is initited for each one. Completions / Events for each node are
2939 * funnelled thru the state machine. As each node finishes ADISC processing, it
2940 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2941 * waiting, and the ADISC list count is identically 0, then we are done. For
2942 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2943 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2944 * list. 32 entries are processed initially and PLOGI is initited for each one.
2945 * Completions / Events for each node are funnelled thru the state machine. As
2946 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2947 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2948 * indentically 0, then we are done. We have now completed discovery / RSCN
2949 * handling. Upon completion, ALL nodes should be on either the mapped or
2953 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2954 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2955 /* Action routine Event Current State */
2956 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2957 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2958 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2959 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2960 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2961 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2962 lpfc_disc_illegal, /* CMPL_PLOGI */
2963 lpfc_disc_illegal, /* CMPL_PRLI */
2964 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2965 lpfc_disc_illegal, /* CMPL_ADISC */
2966 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2967 lpfc_device_rm_unused_node, /* DEVICE_RM */
2968 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2970 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2971 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2972 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2973 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2974 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2975 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2976 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2977 lpfc_disc_illegal, /* CMPL_PRLI */
2978 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2979 lpfc_disc_illegal, /* CMPL_ADISC */
2980 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2981 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2982 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2984 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2985 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2986 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2987 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2988 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2989 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2990 lpfc_disc_illegal, /* CMPL_PLOGI */
2991 lpfc_disc_illegal, /* CMPL_PRLI */
2992 lpfc_disc_illegal, /* CMPL_LOGO */
2993 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2994 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2995 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2996 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2998 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2999 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
3000 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
3001 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
3002 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
3003 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
3004 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3005 lpfc_disc_illegal, /* CMPL_PRLI */
3006 lpfc_disc_illegal, /* CMPL_LOGO */
3007 lpfc_disc_illegal, /* CMPL_ADISC */
3008 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
3009 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
3010 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
3012 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
3013 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
3014 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
3015 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
3016 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
3017 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
3018 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3019 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
3020 lpfc_disc_illegal, /* CMPL_LOGO */
3021 lpfc_disc_illegal, /* CMPL_ADISC */
3022 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3023 lpfc_device_rm_prli_issue, /* DEVICE_RM */
3024 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
3026 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3027 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3028 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3029 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3030 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3031 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3032 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3033 lpfc_disc_illegal, /* CMPL_PRLI */
3034 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3035 lpfc_disc_illegal, /* CMPL_ADISC */
3036 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3037 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3038 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3040 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3041 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3042 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3043 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3044 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3045 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3046 lpfc_disc_illegal, /* CMPL_PLOGI */
3047 lpfc_disc_illegal, /* CMPL_PRLI */
3048 lpfc_disc_illegal, /* CMPL_LOGO */
3049 lpfc_disc_illegal, /* CMPL_ADISC */
3050 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3051 lpfc_device_rm_unmap_node, /* DEVICE_RM */
3052 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3054 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3055 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3056 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3057 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3058 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3059 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3060 lpfc_disc_illegal, /* CMPL_PLOGI */
3061 lpfc_disc_illegal, /* CMPL_PRLI */
3062 lpfc_disc_illegal, /* CMPL_LOGO */
3063 lpfc_disc_illegal, /* CMPL_ADISC */
3064 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3065 lpfc_disc_illegal, /* DEVICE_RM */
3066 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3068 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3069 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3070 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3071 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3072 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3073 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3074 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3075 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3076 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3077 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3078 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3079 lpfc_device_rm_npr_node, /* DEVICE_RM */
3080 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3084 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3085 void *arg, uint32_t evt)
3087 uint32_t cur_state, rc;
3088 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3090 uint32_t got_ndlp = 0;
3093 if (lpfc_nlp_get(ndlp))
3096 cur_state = ndlp->nlp_state;
3098 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3099 ((uint32_t)ndlp->nlp_type));
3100 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3101 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3102 "0211 DSM in event x%x on NPort x%x in "
3103 "state %d rpi x%x Data: x%x x%x\n",
3104 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3105 ndlp->nlp_flag, data1);
3107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3108 "DSM in: evt:%d ste:%d did:x%x",
3109 evt, cur_state, ndlp->nlp_DID);
3111 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3112 rc = (func) (vport, ndlp, arg, evt);
3114 /* DSM out state <rc> on NPort <nlp_DID> */
3116 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3117 ((uint32_t)ndlp->nlp_type));
3118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3119 "0212 DSM out state %d on NPort x%x "
3120 "rpi x%x Data: x%x x%x\n",
3121 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3125 "DSM out: ste:%d did:x%x flg:x%x",
3126 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3127 /* Decrement the ndlp reference count held for this function */
3130 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3131 "0213 DSM out state %d on NPort free\n", rc);
3133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3134 "DSM out: ste:%d did:x%x flg:x%x",