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)
839 lpfc_linkdown_port(vport);
840 spin_lock_irq(shost->host_lock);
841 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
842 spin_unlock_irq(shost->host_lock);
843 vports = lpfc_create_vport_work_array(phba);
845 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
847 if ((!(vports[i]->fc_flag &
848 FC_VPORT_LOGO_RCVD)) &&
849 (vports[i]->port_state > LPFC_FDISC)) {
850 active_vlink_present = 1;
854 lpfc_destroy_vport_work_array(phba, vports);
858 * Don't re-instantiate if vport is marked for deletion.
859 * If we are here first then vport_delete is going to wait
860 * for discovery to complete.
862 if (!(vport->load_flag & FC_UNLOADING) &&
863 active_vlink_present) {
865 * If there are other active VLinks present,
866 * re-instantiate the Vlink using FDISC.
868 mod_timer(&ndlp->nlp_delayfunc,
869 jiffies + msecs_to_jiffies(1000));
870 spin_lock_irq(&ndlp->lock);
871 ndlp->nlp_flag |= NLP_DELAY_TMO;
872 spin_unlock_irq(&ndlp->lock);
873 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
874 vport->port_state = LPFC_FDISC;
876 spin_lock_irq(shost->host_lock);
877 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
878 spin_unlock_irq(shost->host_lock);
879 lpfc_retry_pport_discovery(phba);
881 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
882 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
883 (ndlp->nlp_type & NLP_NVME_TARGET) ||
884 (vport->fc_flag & FC_PT2PT))) ||
885 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
886 /* Only try to re-login if this is NOT a Fabric Node
887 * AND the remote NPORT is a FCP/NVME Target or we
888 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
889 * case for LOGO as a response to ADISC behavior.
891 mod_timer(&ndlp->nlp_delayfunc,
892 jiffies + msecs_to_jiffies(1000 * 1));
893 spin_lock_irq(&ndlp->lock);
894 ndlp->nlp_flag |= NLP_DELAY_TMO;
895 spin_unlock_irq(&ndlp->lock);
897 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
900 /* Unregister from backend, could have been skipped due to ADISC */
901 lpfc_nlp_unreg_node(vport, ndlp);
903 ndlp->nlp_prev_state = ndlp->nlp_state;
904 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
906 spin_lock_irq(&ndlp->lock);
907 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
908 spin_unlock_irq(&ndlp->lock);
909 /* The driver has to wait until the ACC completes before it continues
910 * processing the LOGO. The action will resume in
911 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
912 * unreg_login, the driver waits so the ACC does not get aborted.
918 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
919 struct lpfc_nodelist *ndlp,
920 struct lpfc_iocbq *cmdiocb)
926 payload = cmdiocb->cmd_dmabuf->virt;
928 if (vport->phba->nvmet_support) {
929 /* Must be a NVME PRLI */
930 if (cmd == ELS_CMD_PRLI)
933 /* Initiator mode. */
934 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
939 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
940 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
941 "state x%x flags x%x\n",
942 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
944 memset(&stat, 0, sizeof(struct ls_rjt));
945 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
946 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
947 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
953 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
954 struct lpfc_iocbq *cmdiocb)
956 struct lpfc_hba *phba = vport->phba;
957 struct lpfc_dmabuf *pcmd;
960 struct fc_rport *rport = ndlp->rport;
963 pcmd = cmdiocb->cmd_dmabuf;
964 lp = (uint32_t *)pcmd->virt;
965 npr = (PRLI *)((uint8_t *)lp + sizeof(uint32_t));
967 if ((npr->prliType == PRLI_FCP_TYPE) ||
968 (npr->prliType == PRLI_NVME_TYPE)) {
969 if (npr->initiatorFunc) {
970 if (npr->prliType == PRLI_FCP_TYPE)
971 ndlp->nlp_type |= NLP_FCP_INITIATOR;
972 if (npr->prliType == PRLI_NVME_TYPE)
973 ndlp->nlp_type |= NLP_NVME_INITIATOR;
975 if (npr->targetFunc) {
976 if (npr->prliType == PRLI_FCP_TYPE)
977 ndlp->nlp_type |= NLP_FCP_TARGET;
978 if (npr->prliType == PRLI_NVME_TYPE)
979 ndlp->nlp_type |= NLP_NVME_TARGET;
980 if (npr->writeXferRdyDis)
981 ndlp->nlp_flag |= NLP_FIRSTBURST;
983 if (npr->Retry && ndlp->nlp_type &
984 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
985 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
987 if (npr->Retry && phba->nsler &&
988 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
989 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
992 /* If this driver is in nvme target mode, set the ndlp's fc4
993 * type to NVME provided the PRLI response claims NVME FC4
994 * type. Target mode does not issue gft_id so doesn't get
995 * the fc4 type set until now.
997 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
998 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
999 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1002 /* Fabric Controllers send FCP PRLI as an initiator but should
1003 * not get recognized as FCP type and registered with transport.
1005 if (npr->prliType == PRLI_FCP_TYPE &&
1006 !(ndlp->nlp_type & NLP_FABRIC))
1007 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1010 /* We need to update the rport role values */
1011 roles = FC_RPORT_ROLE_UNKNOWN;
1012 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1013 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1014 if (ndlp->nlp_type & NLP_FCP_TARGET)
1015 roles |= FC_RPORT_ROLE_FCP_TARGET;
1017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1018 "rport rolechg: role:x%x did:x%x flg:x%x",
1019 roles, ndlp->nlp_DID, ndlp->nlp_flag);
1021 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1022 fc_remote_port_rolechg(rport, roles);
1027 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1029 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1030 spin_lock_irq(&ndlp->lock);
1031 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1032 spin_unlock_irq(&ndlp->lock);
1036 if (!(vport->fc_flag & FC_PT2PT)) {
1037 /* Check config parameter use-adisc or FCP-2 */
1038 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1039 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1040 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1041 spin_lock_irq(&ndlp->lock);
1042 ndlp->nlp_flag |= NLP_NPR_ADISC;
1043 spin_unlock_irq(&ndlp->lock);
1048 spin_lock_irq(&ndlp->lock);
1049 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1050 spin_unlock_irq(&ndlp->lock);
1051 lpfc_unreg_rpi(vport, ndlp);
1056 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1057 * @phba : Pointer to lpfc_hba structure.
1058 * @vport: Pointer to lpfc_vport structure.
1059 * @ndlp: Pointer to lpfc_nodelist structure.
1060 * @rpi : rpi to be release.
1062 * This function will send a unreg_login mailbox command to the firmware
1066 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1067 struct lpfc_nodelist *ndlp, uint16_t rpi)
1072 /* If there is already an UNREG in progress for this ndlp,
1073 * no need to queue up another one.
1075 if (ndlp->nlp_flag & NLP_UNREG_INP) {
1076 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1077 "1435 release_rpi SKIP UNREG x%x on "
1078 "NPort x%x deferred x%x flg x%x "
1080 ndlp->nlp_rpi, ndlp->nlp_DID,
1081 ndlp->nlp_defer_did,
1082 ndlp->nlp_flag, ndlp);
1086 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1089 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1090 "2796 mailbox memory allocation failed \n");
1092 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1093 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1095 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1096 if (!pmb->ctx_ndlp) {
1097 mempool_free(pmb, phba->mbox_mem_pool);
1101 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1102 (!(vport->fc_flag & FC_OFFLINE_MODE)))
1103 ndlp->nlp_flag |= NLP_UNREG_INP;
1105 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1106 "1437 release_rpi UNREG x%x "
1107 "on NPort x%x flg x%x\n",
1108 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1110 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1111 if (rc == MBX_NOT_FINISHED) {
1113 mempool_free(pmb, phba->mbox_mem_pool);
1119 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1120 void *arg, uint32_t evt)
1122 struct lpfc_hba *phba;
1123 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1127 /* Release the RPI if reglogin completing */
1128 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1129 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
1130 (!pmb->u.mb.mbxStatus)) {
1131 rpi = pmb->u.mb.un.varWords[0];
1132 lpfc_release_rpi(phba, vport, ndlp, rpi);
1134 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1135 "0271 Illegal State Transition: node x%x "
1136 "event x%x, state x%x Data: x%x x%x\n",
1137 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1139 return ndlp->nlp_state;
1143 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1144 void *arg, uint32_t evt)
1146 /* This transition is only legal if we previously
1147 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1148 * working on the same NPortID, do nothing for this thread
1151 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1152 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1153 "0272 Illegal State Transition: node x%x "
1154 "event x%x, state x%x Data: x%x x%x\n",
1155 ndlp->nlp_DID, evt, ndlp->nlp_state,
1156 ndlp->nlp_rpi, ndlp->nlp_flag);
1158 return ndlp->nlp_state;
1161 /* Start of Discovery State Machine routines */
1164 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1165 void *arg, uint32_t evt)
1167 struct lpfc_iocbq *cmdiocb;
1169 cmdiocb = (struct lpfc_iocbq *) arg;
1171 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1172 return ndlp->nlp_state;
1174 return NLP_STE_FREED_NODE;
1178 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1179 void *arg, uint32_t evt)
1181 lpfc_issue_els_logo(vport, ndlp, 0);
1182 return ndlp->nlp_state;
1186 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1187 void *arg, uint32_t evt)
1189 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1191 spin_lock_irq(&ndlp->lock);
1192 ndlp->nlp_flag |= NLP_LOGO_ACC;
1193 spin_unlock_irq(&ndlp->lock);
1194 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1196 return ndlp->nlp_state;
1200 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1201 void *arg, uint32_t evt)
1203 return NLP_STE_FREED_NODE;
1207 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1208 void *arg, uint32_t evt)
1210 return NLP_STE_FREED_NODE;
1214 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1215 struct lpfc_nodelist *ndlp,
1216 void *arg, uint32_t evt)
1218 return ndlp->nlp_state;
1222 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1223 void *arg, uint32_t evt)
1225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1226 struct lpfc_hba *phba = vport->phba;
1227 struct lpfc_iocbq *cmdiocb = arg;
1228 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
1229 uint32_t *lp = (uint32_t *) pcmd->virt;
1230 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1234 memset(&stat, 0, sizeof (struct ls_rjt));
1236 /* For a PLOGI, we only accept if our portname is less
1237 * than the remote portname.
1239 phba->fc_stat.elsLogiCol++;
1240 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1241 sizeof(struct lpfc_name));
1243 if (port_cmp >= 0) {
1244 /* Reject this request because the remote node will accept
1246 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1247 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1248 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1251 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1252 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1253 (vport->num_disc_nodes)) {
1254 spin_lock_irq(&ndlp->lock);
1255 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1256 spin_unlock_irq(&ndlp->lock);
1257 /* Check if there are more PLOGIs to be sent */
1258 lpfc_more_plogi(vport);
1259 if (vport->num_disc_nodes == 0) {
1260 spin_lock_irq(shost->host_lock);
1261 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1262 spin_unlock_irq(shost->host_lock);
1263 lpfc_can_disctmo(vport);
1264 lpfc_end_rscn(vport);
1267 } /* If our portname was less */
1269 return ndlp->nlp_state;
1273 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1274 void *arg, uint32_t evt)
1276 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1279 memset(&stat, 0, sizeof (struct ls_rjt));
1280 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1281 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1282 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1283 return ndlp->nlp_state;
1287 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1288 void *arg, uint32_t evt)
1290 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1292 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1293 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1294 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1295 /* software abort outstanding PLOGI */
1296 lpfc_els_abort(vport->phba, ndlp);
1298 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1299 return ndlp->nlp_state;
1303 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1304 void *arg, uint32_t evt)
1306 struct lpfc_hba *phba = vport->phba;
1307 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1309 /* software abort outstanding PLOGI */
1310 lpfc_els_abort(phba, ndlp);
1312 if (evt == NLP_EVT_RCV_LOGO) {
1313 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1315 lpfc_issue_els_logo(vport, ndlp, 0);
1318 /* Put ndlp in npr state set plogi timer for 1 sec */
1319 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1320 spin_lock_irq(&ndlp->lock);
1321 ndlp->nlp_flag |= NLP_DELAY_TMO;
1322 spin_unlock_irq(&ndlp->lock);
1323 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1324 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1327 return ndlp->nlp_state;
1331 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1332 struct lpfc_nodelist *ndlp,
1336 struct lpfc_hba *phba = vport->phba;
1337 struct lpfc_iocbq *cmdiocb, *rspiocb;
1338 struct lpfc_dmabuf *pcmd, *prsp;
1341 struct serv_parm *sp;
1348 cmdiocb = (struct lpfc_iocbq *) arg;
1349 rspiocb = cmdiocb->rsp_iocb;
1351 ulp_status = get_job_ulpstatus(phba, rspiocb);
1353 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1354 /* Recovery from PLOGI collision logic */
1355 return ndlp->nlp_state;
1361 pcmd = cmdiocb->cmd_dmabuf;
1363 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1367 lp = (uint32_t *) prsp->virt;
1368 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1370 /* Some switches have FDMI servers returning 0 for WWN */
1371 if ((ndlp->nlp_DID != FDMI_DID) &&
1372 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1373 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1374 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1375 "0142 PLOGI RSP: Invalid WWN.\n");
1378 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1380 /* PLOGI chkparm OK */
1381 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1382 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1383 ndlp->nlp_DID, ndlp->nlp_state,
1384 ndlp->nlp_flag, ndlp->nlp_rpi);
1385 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1386 ndlp->nlp_fcp_info |= CLASS2;
1388 ndlp->nlp_fcp_info |= CLASS3;
1390 ndlp->nlp_class_sup = 0;
1391 if (sp->cls1.classValid)
1392 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1393 if (sp->cls2.classValid)
1394 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1395 if (sp->cls3.classValid)
1396 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1397 if (sp->cls4.classValid)
1398 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1399 ndlp->nlp_maxframe =
1400 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1402 if ((vport->fc_flag & FC_PT2PT) &&
1403 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1404 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1405 if (sp->cmn.edtovResolution) {
1406 /* E_D_TOV ticks are in nanoseconds */
1407 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1410 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1411 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1412 sp->cmn.valid_vendor_ver_level) {
1413 vid = be32_to_cpu(sp->un.vv.vid);
1414 flag = be32_to_cpu(sp->un.vv.flags);
1415 if ((vid == LPFC_VV_EMLX_ID) &&
1416 (flag & LPFC_VV_SUPPRESS_RSP))
1417 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1421 * Use the larger EDTOV
1422 * RATOV = 2 * EDTOV for pt-to-pt
1424 if (ed_tov > phba->fc_edtov)
1425 phba->fc_edtov = ed_tov;
1426 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1428 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1430 /* Issue config_link / reg_vfi to account for updated TOV's */
1431 if (phba->sli_rev == LPFC_SLI_REV4) {
1432 lpfc_issue_reg_vfi(vport);
1434 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1436 lpfc_printf_vlog(vport, KERN_ERR,
1438 "0133 PLOGI: no memory "
1440 "Data: x%x x%x x%x x%x\n",
1441 ndlp->nlp_DID, ndlp->nlp_state,
1442 ndlp->nlp_flag, ndlp->nlp_rpi);
1446 lpfc_config_link(phba, mbox);
1448 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1449 mbox->vport = vport;
1450 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1451 if (rc == MBX_NOT_FINISHED) {
1452 mempool_free(mbox, phba->mbox_mem_pool);
1458 lpfc_unreg_rpi(vport, ndlp);
1460 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1462 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1463 "0018 PLOGI: no memory for reg_login "
1464 "Data: x%x x%x x%x x%x\n",
1465 ndlp->nlp_DID, ndlp->nlp_state,
1466 ndlp->nlp_flag, ndlp->nlp_rpi);
1470 did = get_job_els_rsp64_did(phba, cmdiocb);
1472 if (lpfc_reg_rpi(phba, vport->vpi, did,
1473 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1474 switch (ndlp->nlp_DID) {
1475 case NameServer_DID:
1476 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1477 /* Fabric Controller Node needs these parameters. */
1478 memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
1481 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1484 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1485 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1488 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1489 if (!mbox->ctx_ndlp)
1492 mbox->vport = vport;
1493 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1494 != MBX_NOT_FINISHED) {
1495 lpfc_nlp_set_state(vport, ndlp,
1496 NLP_STE_REG_LOGIN_ISSUE);
1497 return ndlp->nlp_state;
1499 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1500 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1501 /* decrement node reference count to the failed mbox
1505 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
1506 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1507 "0134 PLOGI: cannot issue reg_login "
1508 "Data: x%x x%x x%x x%x\n",
1509 ndlp->nlp_DID, ndlp->nlp_state,
1510 ndlp->nlp_flag, ndlp->nlp_rpi);
1512 mempool_free(mbox, phba->mbox_mem_pool);
1514 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1515 "0135 PLOGI: cannot format reg_login "
1516 "Data: x%x x%x x%x x%x\n",
1517 ndlp->nlp_DID, ndlp->nlp_state,
1518 ndlp->nlp_flag, ndlp->nlp_rpi);
1523 if (ndlp->nlp_DID == NameServer_DID) {
1524 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1525 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1526 "0261 Cannot Register NameServer login\n");
1530 ** In case the node reference counter does not go to zero, ensure that
1531 ** the stale state for the node is not processed.
1534 ndlp->nlp_prev_state = ndlp->nlp_state;
1535 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1536 return NLP_STE_FREED_NODE;
1540 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1541 void *arg, uint32_t evt)
1543 return ndlp->nlp_state;
1547 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1548 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1550 struct lpfc_hba *phba;
1551 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1552 MAILBOX_t *mb = &pmb->u.mb;
1556 /* Release the RPI */
1557 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1559 rpi = pmb->u.mb.un.varWords[0];
1560 lpfc_release_rpi(phba, vport, ndlp, rpi);
1562 return ndlp->nlp_state;
1566 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1567 void *arg, uint32_t evt)
1569 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1570 spin_lock_irq(&ndlp->lock);
1571 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1572 spin_unlock_irq(&ndlp->lock);
1573 return ndlp->nlp_state;
1575 /* software abort outstanding PLOGI */
1576 lpfc_els_abort(vport->phba, ndlp);
1578 lpfc_drop_node(vport, ndlp);
1579 return NLP_STE_FREED_NODE;
1584 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1585 struct lpfc_nodelist *ndlp,
1589 struct lpfc_hba *phba = vport->phba;
1591 /* Don't do anything that will mess up processing of the
1594 if (vport->fc_flag & FC_RSCN_DEFERRED)
1595 return ndlp->nlp_state;
1597 /* software abort outstanding PLOGI */
1598 lpfc_els_abort(phba, ndlp);
1600 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1601 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1602 spin_lock_irq(&ndlp->lock);
1603 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1604 spin_unlock_irq(&ndlp->lock);
1606 return ndlp->nlp_state;
1610 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1611 void *arg, uint32_t evt)
1613 struct lpfc_hba *phba = vport->phba;
1614 struct lpfc_iocbq *cmdiocb;
1616 /* software abort outstanding ADISC */
1617 lpfc_els_abort(phba, ndlp);
1619 cmdiocb = (struct lpfc_iocbq *) arg;
1621 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1622 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1623 spin_lock_irq(&ndlp->lock);
1624 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1625 spin_unlock_irq(&ndlp->lock);
1626 if (vport->num_disc_nodes)
1627 lpfc_more_adisc(vport);
1629 return ndlp->nlp_state;
1631 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1632 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1635 return ndlp->nlp_state;
1639 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1640 void *arg, uint32_t evt)
1642 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1644 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1645 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1646 return ndlp->nlp_state;
1650 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1651 void *arg, uint32_t evt)
1653 struct lpfc_hba *phba = vport->phba;
1654 struct lpfc_iocbq *cmdiocb;
1656 cmdiocb = (struct lpfc_iocbq *) arg;
1658 /* software abort outstanding ADISC */
1659 lpfc_els_abort(phba, ndlp);
1661 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1662 return ndlp->nlp_state;
1666 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1667 struct lpfc_nodelist *ndlp,
1668 void *arg, uint32_t evt)
1670 struct lpfc_iocbq *cmdiocb;
1672 cmdiocb = (struct lpfc_iocbq *) arg;
1674 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1675 return ndlp->nlp_state;
1679 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1680 void *arg, uint32_t evt)
1682 struct lpfc_iocbq *cmdiocb;
1684 cmdiocb = (struct lpfc_iocbq *) arg;
1686 /* Treat like rcv logo */
1687 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1688 return ndlp->nlp_state;
1692 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1693 struct lpfc_nodelist *ndlp,
1694 void *arg, uint32_t evt)
1696 struct lpfc_hba *phba = vport->phba;
1697 struct lpfc_iocbq *cmdiocb, *rspiocb;
1702 cmdiocb = (struct lpfc_iocbq *) arg;
1703 rspiocb = cmdiocb->rsp_iocb;
1705 ulp_status = get_job_ulpstatus(phba, rspiocb);
1707 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1710 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1712 mod_timer(&ndlp->nlp_delayfunc,
1713 jiffies + msecs_to_jiffies(1000));
1714 spin_lock_irq(&ndlp->lock);
1715 ndlp->nlp_flag |= NLP_DELAY_TMO;
1716 spin_unlock_irq(&ndlp->lock);
1717 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1719 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1721 lpfc_unreg_rpi(vport, ndlp);
1722 return ndlp->nlp_state;
1725 if (phba->sli_rev == LPFC_SLI_REV4) {
1726 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1728 /* Stay in state and retry. */
1729 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1730 return ndlp->nlp_state;
1734 if (ndlp->nlp_type & NLP_FCP_TARGET)
1735 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1737 if (ndlp->nlp_type & NLP_NVME_TARGET)
1738 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1740 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1741 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1744 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1745 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1748 return ndlp->nlp_state;
1752 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1753 void *arg, uint32_t evt)
1755 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1756 spin_lock_irq(&ndlp->lock);
1757 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1758 spin_unlock_irq(&ndlp->lock);
1759 return ndlp->nlp_state;
1761 /* software abort outstanding ADISC */
1762 lpfc_els_abort(vport->phba, ndlp);
1764 lpfc_drop_node(vport, ndlp);
1765 return NLP_STE_FREED_NODE;
1770 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1771 struct lpfc_nodelist *ndlp,
1775 struct lpfc_hba *phba = vport->phba;
1777 /* Don't do anything that will mess up processing of the
1780 if (vport->fc_flag & FC_RSCN_DEFERRED)
1781 return ndlp->nlp_state;
1783 /* software abort outstanding ADISC */
1784 lpfc_els_abort(phba, ndlp);
1786 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1787 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1788 spin_lock_irq(&ndlp->lock);
1789 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1790 spin_unlock_irq(&ndlp->lock);
1791 lpfc_disc_set_adisc(vport, ndlp);
1792 return ndlp->nlp_state;
1796 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1797 struct lpfc_nodelist *ndlp,
1801 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1803 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1804 return ndlp->nlp_state;
1808 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1809 struct lpfc_nodelist *ndlp,
1813 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1816 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1817 return ndlp->nlp_state;
1819 if (vport->phba->nvmet_support) {
1820 /* NVME Target mode. Handle and respond to the PRLI and
1821 * transition to UNMAPPED provided the RPI has completed
1824 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1825 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1826 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1828 /* RPI registration has not completed. Reject the PRLI
1829 * to prevent an illegal state transition when the
1830 * rpi registration does complete.
1832 memset(&stat, 0, sizeof(struct ls_rjt));
1833 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1834 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1835 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1837 return ndlp->nlp_state;
1840 /* Initiator mode. */
1841 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1843 return ndlp->nlp_state;
1847 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1848 struct lpfc_nodelist *ndlp,
1852 struct lpfc_hba *phba = vport->phba;
1853 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1855 LPFC_MBOXQ_t *nextmb;
1856 struct lpfc_nodelist *ns_ndlp;
1858 cmdiocb = (struct lpfc_iocbq *) arg;
1860 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1861 if ((mb = phba->sli.mbox_active)) {
1862 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1863 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1864 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1866 mb->ctx_ndlp = NULL;
1867 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1871 spin_lock_irq(&phba->hbalock);
1872 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1873 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1874 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1875 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1877 list_del(&mb->list);
1878 phba->sli.mboxq_cnt--;
1879 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
1882 spin_unlock_irq(&phba->hbalock);
1884 /* software abort if any GID_FT is outstanding */
1885 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1886 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1888 lpfc_els_abort(phba, ns_ndlp);
1891 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1892 return ndlp->nlp_state;
1896 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1897 struct lpfc_nodelist *ndlp,
1901 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1903 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1904 return ndlp->nlp_state;
1908 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1909 struct lpfc_nodelist *ndlp,
1913 struct lpfc_iocbq *cmdiocb;
1915 cmdiocb = (struct lpfc_iocbq *) arg;
1916 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1917 return ndlp->nlp_state;
1921 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1922 struct lpfc_nodelist *ndlp,
1926 struct lpfc_hba *phba = vport->phba;
1927 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1928 MAILBOX_t *mb = &pmb->u.mb;
1929 uint32_t did = mb->un.varWords[1];
1931 if (mb->mbxStatus) {
1932 /* RegLogin failed */
1933 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1934 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1936 did, mb->mbxStatus, vport->port_state,
1937 mb->un.varRegLogin.vpi,
1938 mb->un.varRegLogin.rpi);
1940 * If RegLogin failed due to lack of HBA resources do not
1943 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1944 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1945 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1946 return ndlp->nlp_state;
1949 /* Put ndlp in npr state set plogi timer for 1 sec */
1950 mod_timer(&ndlp->nlp_delayfunc,
1951 jiffies + msecs_to_jiffies(1000 * 1));
1952 spin_lock_irq(&ndlp->lock);
1953 ndlp->nlp_flag |= NLP_DELAY_TMO;
1954 spin_unlock_irq(&ndlp->lock);
1955 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1957 lpfc_issue_els_logo(vport, ndlp, 0);
1958 return ndlp->nlp_state;
1961 /* SLI4 ports have preallocated logical rpis. */
1962 if (phba->sli_rev < LPFC_SLI_REV4)
1963 ndlp->nlp_rpi = mb->un.varWords[0];
1965 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1967 /* Only if we are not a fabric nport do we issue PRLI */
1968 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1969 "3066 RegLogin Complete on x%x x%x x%x\n",
1970 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1971 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1972 (phba->nvmet_support == 0)) {
1973 /* The driver supports FCP and NVME concurrently. If the
1974 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1975 * know what PRLI to send yet. Figure that out now and
1976 * call PRLI depending on the outcome.
1978 if (vport->fc_flag & FC_PT2PT) {
1979 /* If we are pt2pt, there is no Fabric to determine
1980 * the FC4 type of the remote nport. So if NVME
1981 * is configured try it.
1983 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1984 if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
1985 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1986 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1987 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1988 /* We need to update the localport also */
1989 lpfc_nvme_update_localport(vport);
1992 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1993 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1995 } else if (ndlp->nlp_fc4_type == 0) {
1996 /* If we are only configured for FCP, the driver
1997 * should just issue PRLI for FCP. Otherwise issue
1998 * GFT_ID to determine if remote port supports NVME.
2000 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
2001 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
2003 return ndlp->nlp_state;
2005 ndlp->nlp_fc4_type = NLP_FC4_FCP;
2008 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2010 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
2011 lpfc_issue_els_logo(vport, ndlp, 0);
2012 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2016 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
2017 phba->targetport->port_id = vport->fc_myDID;
2019 /* Only Fabric ports should transition. NVME target
2020 * must complete PRLI.
2022 if (ndlp->nlp_type & NLP_FABRIC) {
2023 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2024 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2028 return ndlp->nlp_state;
2032 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2033 struct lpfc_nodelist *ndlp,
2037 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2038 spin_lock_irq(&ndlp->lock);
2039 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2040 spin_unlock_irq(&ndlp->lock);
2041 return ndlp->nlp_state;
2043 lpfc_drop_node(vport, ndlp);
2044 return NLP_STE_FREED_NODE;
2049 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2050 struct lpfc_nodelist *ndlp,
2054 /* Don't do anything that will mess up processing of the
2057 if (vport->fc_flag & FC_RSCN_DEFERRED)
2058 return ndlp->nlp_state;
2060 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2061 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2062 spin_lock_irq(&ndlp->lock);
2064 /* If we are a target we won't immediately transition into PRLI,
2065 * so if REG_LOGIN already completed we don't need to ignore it.
2067 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2068 !vport->phba->nvmet_support)
2069 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2071 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2072 spin_unlock_irq(&ndlp->lock);
2073 lpfc_disc_set_adisc(vport, ndlp);
2074 return ndlp->nlp_state;
2078 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2079 void *arg, uint32_t evt)
2081 struct lpfc_iocbq *cmdiocb;
2083 cmdiocb = (struct lpfc_iocbq *) arg;
2085 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2086 return ndlp->nlp_state;
2090 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2091 void *arg, uint32_t evt)
2093 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2095 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2096 return ndlp->nlp_state;
2097 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2098 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2099 return ndlp->nlp_state;
2103 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2104 void *arg, uint32_t evt)
2106 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2108 /* Software abort outstanding PRLI before sending acc */
2109 lpfc_els_abort(vport->phba, ndlp);
2111 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2112 return ndlp->nlp_state;
2116 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2117 void *arg, uint32_t evt)
2119 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2121 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2122 return ndlp->nlp_state;
2125 /* This routine is envoked when we rcv a PRLO request from a nport
2126 * we are logged into. We should send back a PRLO rsp setting the
2128 * NEXT STATE = PRLI_ISSUE
2131 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2132 void *arg, uint32_t evt)
2134 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2136 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2137 return ndlp->nlp_state;
2141 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2142 void *arg, uint32_t evt)
2144 struct lpfc_iocbq *cmdiocb, *rspiocb;
2145 struct lpfc_hba *phba = vport->phba;
2147 struct lpfc_nvme_prli *nvpr;
2151 cmdiocb = (struct lpfc_iocbq *) arg;
2152 rspiocb = cmdiocb->rsp_iocb;
2154 ulp_status = get_job_ulpstatus(phba, rspiocb);
2156 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2157 * format is different so NULL the two PRLI types so that the
2158 * driver correctly gets the correct context.
2162 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2163 if (cmdiocb->cmd_flag & LPFC_PRLI_FCP_REQ)
2164 npr = (PRLI *) temp_ptr;
2165 else if (cmdiocb->cmd_flag & LPFC_PRLI_NVME_REQ)
2166 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2169 if ((vport->port_type == LPFC_NPIV_PORT) &&
2170 vport->cfg_restrict_login) {
2174 /* Adjust the nlp_type accordingly if the PRLI failed */
2176 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2178 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2180 /* We can't set the DSM state till BOTH PRLIs complete */
2184 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2185 (npr->prliType == PRLI_FCP_TYPE)) {
2186 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2187 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2190 if (npr->initiatorFunc)
2191 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2192 if (npr->targetFunc) {
2193 ndlp->nlp_type |= NLP_FCP_TARGET;
2194 if (npr->writeXferRdyDis)
2195 ndlp->nlp_flag |= NLP_FIRSTBURST;
2198 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2201 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2202 PRLI_REQ_EXECUTED) &&
2203 (bf_get_be32(prli_type_code, nvpr) ==
2206 /* Complete setting up the remote ndlp personality. */
2207 if (bf_get_be32(prli_init, nvpr))
2208 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2210 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2211 bf_get_be32(prli_conf, nvpr))
2213 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2215 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2217 /* Target driver cannot solicit NVME FB. */
2218 if (bf_get_be32(prli_tgt, nvpr)) {
2219 /* Complete the nvme target roles. The transport
2220 * needs to know if the rport is capable of
2221 * discovery in addition to its role.
2223 ndlp->nlp_type |= NLP_NVME_TARGET;
2224 if (bf_get_be32(prli_disc, nvpr))
2225 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2228 * If prli_fba is set, the Target supports FirstBurst.
2229 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2230 * otherwise it defines the actual size supported by
2233 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2234 (phba->cfg_nvme_enable_fb) &&
2235 (!phba->nvmet_support)) {
2236 /* Both sides support FB. The target's first
2237 * burst size is a 512 byte encoded value.
2239 ndlp->nlp_flag |= NLP_FIRSTBURST;
2240 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2243 /* Expressed in units of 512 bytes */
2244 if (ndlp->nvme_fb_size)
2245 ndlp->nvme_fb_size <<=
2248 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2252 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2253 "6029 NVME PRLI Cmpl w1 x%08x "
2254 "w4 x%08x w5 x%08x flag x%x, "
2255 "fcp_info x%x nlp_type x%x\n",
2256 be32_to_cpu(nvpr->word1),
2257 be32_to_cpu(nvpr->word4),
2258 be32_to_cpu(nvpr->word5),
2259 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2262 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2263 (vport->port_type == LPFC_NPIV_PORT) &&
2264 vport->cfg_restrict_login) {
2266 spin_lock_irq(&ndlp->lock);
2267 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2268 spin_unlock_irq(&ndlp->lock);
2269 lpfc_issue_els_logo(vport, ndlp, 0);
2271 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2272 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2273 return ndlp->nlp_state;
2277 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2280 if (ndlp->fc4_prli_sent == 0) {
2281 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2282 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2283 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2284 else if (ndlp->nlp_type &
2285 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2288 lpfc_printf_vlog(vport,
2290 "3067 PRLI's still outstanding "
2291 "on x%06x - count %d, Pend Node Mode "
2293 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2295 return ndlp->nlp_state;
2298 /*! lpfc_device_rm_prli_issue
2309 * This routine is envoked when we a request to remove a nport we are in the
2310 * process of PRLIing. We should software abort outstanding prli, unreg
2311 * login, send a logout. We will change node state to UNUSED_NODE, put it
2312 * on plogi list so it can be freed when LOGO completes.
2317 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2318 void *arg, uint32_t evt)
2320 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2321 spin_lock_irq(&ndlp->lock);
2322 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2323 spin_unlock_irq(&ndlp->lock);
2324 return ndlp->nlp_state;
2326 /* software abort outstanding PLOGI */
2327 lpfc_els_abort(vport->phba, ndlp);
2329 lpfc_drop_node(vport, ndlp);
2330 return NLP_STE_FREED_NODE;
2335 /*! lpfc_device_recov_prli_issue
2346 * The routine is envoked when the state of a device is unknown, like
2347 * during a link down. We should remove the nodelist entry from the
2348 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2349 * outstanding PRLI command, then free the node entry.
2352 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2353 struct lpfc_nodelist *ndlp,
2357 struct lpfc_hba *phba = vport->phba;
2359 /* Don't do anything that will mess up processing of the
2362 if (vport->fc_flag & FC_RSCN_DEFERRED)
2363 return ndlp->nlp_state;
2365 /* software abort outstanding PRLI */
2366 lpfc_els_abort(phba, ndlp);
2368 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2370 spin_lock_irq(&ndlp->lock);
2371 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2372 spin_unlock_irq(&ndlp->lock);
2373 lpfc_disc_set_adisc(vport, ndlp);
2374 return ndlp->nlp_state;
2378 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2379 void *arg, uint32_t evt)
2381 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2384 memset(&stat, 0, sizeof(struct ls_rjt));
2385 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2386 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2387 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2388 return ndlp->nlp_state;
2392 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2393 void *arg, uint32_t evt)
2395 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2398 memset(&stat, 0, sizeof(struct ls_rjt));
2399 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2400 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2401 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2402 return ndlp->nlp_state;
2406 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2407 void *arg, uint32_t evt)
2409 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2411 spin_lock_irq(&ndlp->lock);
2412 ndlp->nlp_flag |= NLP_LOGO_ACC;
2413 spin_unlock_irq(&ndlp->lock);
2414 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2415 return ndlp->nlp_state;
2419 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2420 void *arg, uint32_t evt)
2422 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2425 memset(&stat, 0, sizeof(struct ls_rjt));
2426 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2427 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2428 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2429 return ndlp->nlp_state;
2433 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2434 void *arg, uint32_t evt)
2436 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2439 memset(&stat, 0, sizeof(struct ls_rjt));
2440 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2441 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2442 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2443 return ndlp->nlp_state;
2447 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2448 void *arg, uint32_t evt)
2450 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2451 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2452 spin_lock_irq(&ndlp->lock);
2453 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2454 spin_unlock_irq(&ndlp->lock);
2455 lpfc_disc_set_adisc(vport, ndlp);
2456 return ndlp->nlp_state;
2460 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2461 void *arg, uint32_t evt)
2464 * DevLoss has timed out and is calling for Device Remove.
2465 * In this case, abort the LOGO and cleanup the ndlp
2468 lpfc_unreg_rpi(vport, ndlp);
2469 /* software abort outstanding PLOGI */
2470 lpfc_els_abort(vport->phba, ndlp);
2471 lpfc_drop_node(vport, ndlp);
2472 return NLP_STE_FREED_NODE;
2476 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2477 struct lpfc_nodelist *ndlp,
2478 void *arg, uint32_t evt)
2481 * Device Recovery events have no meaning for a node with a LOGO
2482 * outstanding. The LOGO has to complete first and handle the
2483 * node from that point.
2485 return ndlp->nlp_state;
2489 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2490 void *arg, uint32_t evt)
2492 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2494 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2495 return ndlp->nlp_state;
2499 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2500 void *arg, uint32_t evt)
2502 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2504 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2505 return ndlp->nlp_state;
2507 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2508 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2509 return ndlp->nlp_state;
2513 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2514 void *arg, uint32_t evt)
2516 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2518 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2519 return ndlp->nlp_state;
2523 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2524 void *arg, uint32_t evt)
2526 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2528 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2529 return ndlp->nlp_state;
2533 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2534 void *arg, uint32_t evt)
2536 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2538 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2539 return ndlp->nlp_state;
2543 lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2544 struct lpfc_nodelist *ndlp,
2548 lpfc_drop_node(vport, ndlp);
2549 return NLP_STE_FREED_NODE;
2553 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2554 struct lpfc_nodelist *ndlp,
2558 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2559 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2560 spin_lock_irq(&ndlp->lock);
2561 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2562 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2563 spin_unlock_irq(&ndlp->lock);
2564 lpfc_disc_set_adisc(vport, ndlp);
2566 return ndlp->nlp_state;
2570 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2571 void *arg, uint32_t evt)
2573 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2575 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2576 return ndlp->nlp_state;
2580 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2581 void *arg, uint32_t evt)
2583 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2585 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2586 return ndlp->nlp_state;
2587 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2588 return ndlp->nlp_state;
2592 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2593 void *arg, uint32_t evt)
2595 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2597 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2598 return ndlp->nlp_state;
2602 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2603 struct lpfc_nodelist *ndlp,
2604 void *arg, uint32_t evt)
2606 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2608 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2609 return ndlp->nlp_state;
2613 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2614 void *arg, uint32_t evt)
2616 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2618 /* flush the target */
2619 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2621 /* Treat like rcv logo */
2622 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2623 return ndlp->nlp_state;
2627 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2628 struct lpfc_nodelist *ndlp,
2632 lpfc_disc_set_adisc(vport, ndlp);
2634 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2635 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2636 spin_lock_irq(&ndlp->lock);
2637 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2638 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2639 spin_unlock_irq(&ndlp->lock);
2640 return ndlp->nlp_state;
2644 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2645 void *arg, uint32_t evt)
2647 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2649 /* Ignore PLOGI if we have an outstanding LOGO */
2650 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2651 return ndlp->nlp_state;
2652 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2653 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2654 spin_lock_irq(&ndlp->lock);
2655 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2656 spin_unlock_irq(&ndlp->lock);
2657 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2658 /* send PLOGI immediately, move to PLOGI issue state */
2659 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2660 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2661 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2662 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2665 return ndlp->nlp_state;
2669 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2670 void *arg, uint32_t evt)
2672 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2675 memset(&stat, 0, sizeof (struct ls_rjt));
2676 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2677 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2678 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2680 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2682 * ADISC nodes will be handled in regular discovery path after
2683 * receiving response from NS.
2685 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2687 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2688 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2690 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2693 return ndlp->nlp_state;
2697 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2698 void *arg, uint32_t evt)
2700 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2702 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2703 return ndlp->nlp_state;
2707 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2708 void *arg, uint32_t evt)
2710 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2712 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2714 * Do not start discovery if discovery is about to start
2715 * or discovery in progress for this node. Starting discovery
2716 * here will affect the counting of discovery threads.
2718 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2719 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2721 * ADISC nodes will be handled in regular discovery path after
2722 * receiving response from NS.
2724 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2726 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2727 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2729 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2732 return ndlp->nlp_state;
2736 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2737 void *arg, uint32_t evt)
2739 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2741 spin_lock_irq(&ndlp->lock);
2742 ndlp->nlp_flag |= NLP_LOGO_ACC;
2743 spin_unlock_irq(&ndlp->lock);
2745 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2747 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2748 mod_timer(&ndlp->nlp_delayfunc,
2749 jiffies + msecs_to_jiffies(1000 * 1));
2750 spin_lock_irq(&ndlp->lock);
2751 ndlp->nlp_flag |= NLP_DELAY_TMO;
2752 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2753 spin_unlock_irq(&ndlp->lock);
2754 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2756 spin_lock_irq(&ndlp->lock);
2757 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2758 spin_unlock_irq(&ndlp->lock);
2760 return ndlp->nlp_state;
2764 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2765 void *arg, uint32_t evt)
2767 struct lpfc_hba *phba = vport->phba;
2768 struct lpfc_iocbq *cmdiocb, *rspiocb;
2771 cmdiocb = (struct lpfc_iocbq *) arg;
2772 rspiocb = cmdiocb->rsp_iocb;
2774 ulp_status = get_job_ulpstatus(phba, rspiocb);
2777 return NLP_STE_FREED_NODE;
2779 return ndlp->nlp_state;
2783 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2784 void *arg, uint32_t evt)
2786 struct lpfc_hba *phba = vport->phba;
2787 struct lpfc_iocbq *cmdiocb, *rspiocb;
2790 cmdiocb = (struct lpfc_iocbq *) arg;
2791 rspiocb = cmdiocb->rsp_iocb;
2793 ulp_status = get_job_ulpstatus(phba, rspiocb);
2795 if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2796 lpfc_drop_node(vport, ndlp);
2797 return NLP_STE_FREED_NODE;
2799 return ndlp->nlp_state;
2803 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2804 void *arg, uint32_t evt)
2806 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2808 /* For the fabric port just clear the fc flags. */
2809 if (ndlp->nlp_DID == Fabric_DID) {
2810 spin_lock_irq(shost->host_lock);
2811 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2812 spin_unlock_irq(shost->host_lock);
2814 lpfc_unreg_rpi(vport, ndlp);
2815 return ndlp->nlp_state;
2819 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2820 void *arg, uint32_t evt)
2822 struct lpfc_hba *phba = vport->phba;
2823 struct lpfc_iocbq *cmdiocb, *rspiocb;
2826 cmdiocb = (struct lpfc_iocbq *) arg;
2827 rspiocb = cmdiocb->rsp_iocb;
2829 ulp_status = get_job_ulpstatus(phba, rspiocb);
2831 if (ulp_status && (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_reglogin_npr_node(struct lpfc_vport *vport,
2840 struct lpfc_nodelist *ndlp,
2841 void *arg, uint32_t evt)
2843 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2844 MAILBOX_t *mb = &pmb->u.mb;
2846 if (!mb->mbxStatus) {
2847 /* SLI4 ports have preallocated logical rpis. */
2848 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2849 ndlp->nlp_rpi = mb->un.varWords[0];
2850 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2851 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2852 lpfc_unreg_rpi(vport, ndlp);
2855 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2856 lpfc_drop_node(vport, ndlp);
2857 return NLP_STE_FREED_NODE;
2860 return ndlp->nlp_state;
2864 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2865 void *arg, uint32_t evt)
2867 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2868 spin_lock_irq(&ndlp->lock);
2869 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2870 spin_unlock_irq(&ndlp->lock);
2871 return ndlp->nlp_state;
2873 lpfc_drop_node(vport, ndlp);
2874 return NLP_STE_FREED_NODE;
2878 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2879 void *arg, uint32_t evt)
2881 /* Don't do anything that will mess up processing of the
2884 if (vport->fc_flag & FC_RSCN_DEFERRED)
2885 return ndlp->nlp_state;
2887 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2888 spin_lock_irq(&ndlp->lock);
2889 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2890 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2891 spin_unlock_irq(&ndlp->lock);
2892 return ndlp->nlp_state;
2896 /* This next section defines the NPort Discovery State Machine */
2898 /* There are 4 different double linked lists nodelist entries can reside on.
2899 * The plogi list and adisc list are used when Link Up discovery or RSCN
2900 * processing is needed. Each list holds the nodes that we will send PLOGI
2901 * or ADISC on. These lists will keep track of what nodes will be effected
2902 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2903 * The unmapped_list will contain all nodes that we have successfully logged
2904 * into at the Fibre Channel level. The mapped_list will contain all nodes
2905 * that are mapped FCP targets.
2908 * The bind list is a list of undiscovered (potentially non-existent) nodes
2909 * that we have saved binding information on. This information is used when
2910 * nodes transition from the unmapped to the mapped list.
2912 /* For UNUSED_NODE state, the node has just been allocated .
2913 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2914 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2915 * and put on the unmapped list. For ADISC processing, the node is taken off
2916 * the ADISC list and placed on either the mapped or unmapped list (depending
2917 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2918 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2919 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2920 * node, the node is taken off the unmapped list. The binding list is checked
2921 * for a valid binding, or a binding is automatically assigned. If binding
2922 * assignment is unsuccessful, the node is left on the unmapped list. If
2923 * binding assignment is successful, the associated binding list entry (if
2924 * any) is removed, and the node is placed on the mapped list.
2927 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2928 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2929 * expire, all effected nodes will receive a DEVICE_RM event.
2932 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2933 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2934 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2935 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2936 * we will first process the ADISC list. 32 entries are processed initially and
2937 * ADISC is initited for each one. Completions / Events for each node are
2938 * funnelled thru the state machine. As each node finishes ADISC processing, it
2939 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2940 * waiting, and the ADISC list count is identically 0, then we are done. For
2941 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2942 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2943 * list. 32 entries are processed initially and PLOGI is initited for each one.
2944 * Completions / Events for each node are funnelled thru the state machine. As
2945 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2946 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2947 * indentically 0, then we are done. We have now completed discovery / RSCN
2948 * handling. Upon completion, ALL nodes should be on either the mapped or
2952 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2953 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2954 /* Action routine Event Current State */
2955 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2956 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2957 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2958 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2959 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2960 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2961 lpfc_disc_illegal, /* CMPL_PLOGI */
2962 lpfc_disc_illegal, /* CMPL_PRLI */
2963 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2964 lpfc_disc_illegal, /* CMPL_ADISC */
2965 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2966 lpfc_device_rm_unused_node, /* DEVICE_RM */
2967 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2969 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2970 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2971 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2972 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2973 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2974 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2975 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2976 lpfc_disc_illegal, /* CMPL_PRLI */
2977 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2978 lpfc_disc_illegal, /* CMPL_ADISC */
2979 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2980 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2981 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2983 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2984 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2985 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2986 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2987 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2988 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2989 lpfc_disc_illegal, /* CMPL_PLOGI */
2990 lpfc_disc_illegal, /* CMPL_PRLI */
2991 lpfc_disc_illegal, /* CMPL_LOGO */
2992 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2993 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2994 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2995 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2997 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2998 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2999 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
3000 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
3001 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
3002 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
3003 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3004 lpfc_disc_illegal, /* CMPL_PRLI */
3005 lpfc_disc_illegal, /* CMPL_LOGO */
3006 lpfc_disc_illegal, /* CMPL_ADISC */
3007 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
3008 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
3009 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
3011 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
3012 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
3013 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
3014 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
3015 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
3016 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
3017 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3018 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
3019 lpfc_disc_illegal, /* CMPL_LOGO */
3020 lpfc_disc_illegal, /* CMPL_ADISC */
3021 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3022 lpfc_device_rm_prli_issue, /* DEVICE_RM */
3023 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
3025 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3026 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3027 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3028 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3029 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3030 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3031 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3032 lpfc_disc_illegal, /* CMPL_PRLI */
3033 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3034 lpfc_disc_illegal, /* CMPL_ADISC */
3035 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3036 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3037 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3039 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3040 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3041 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3042 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3043 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3044 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3045 lpfc_disc_illegal, /* CMPL_PLOGI */
3046 lpfc_disc_illegal, /* CMPL_PRLI */
3047 lpfc_disc_illegal, /* CMPL_LOGO */
3048 lpfc_disc_illegal, /* CMPL_ADISC */
3049 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3050 lpfc_device_rm_unmap_node, /* DEVICE_RM */
3051 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3053 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3054 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3055 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3056 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3057 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3058 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
3059 lpfc_disc_illegal, /* CMPL_PLOGI */
3060 lpfc_disc_illegal, /* CMPL_PRLI */
3061 lpfc_disc_illegal, /* CMPL_LOGO */
3062 lpfc_disc_illegal, /* CMPL_ADISC */
3063 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3064 lpfc_disc_illegal, /* DEVICE_RM */
3065 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3067 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3068 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3069 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3070 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3071 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3072 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3073 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3074 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3075 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3076 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3077 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3078 lpfc_device_rm_npr_node, /* DEVICE_RM */
3079 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3083 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3084 void *arg, uint32_t evt)
3086 uint32_t cur_state, rc;
3087 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3089 uint32_t got_ndlp = 0;
3092 if (lpfc_nlp_get(ndlp))
3095 cur_state = ndlp->nlp_state;
3097 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3098 ((uint32_t)ndlp->nlp_type));
3099 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3100 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3101 "0211 DSM in event x%x on NPort x%x in "
3102 "state %d rpi x%x Data: x%x x%x\n",
3103 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3104 ndlp->nlp_flag, data1);
3106 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3107 "DSM in: evt:%d ste:%d did:x%x",
3108 evt, cur_state, ndlp->nlp_DID);
3110 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3111 rc = (func) (vport, ndlp, arg, evt);
3113 /* DSM out state <rc> on NPort <nlp_DID> */
3115 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3116 ((uint32_t)ndlp->nlp_type));
3117 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3118 "0212 DSM out state %d on NPort x%x "
3119 "rpi x%x Data: x%x x%x\n",
3120 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3124 "DSM out: ste:%d did:x%x flg:x%x",
3125 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3126 /* Decrement the ndlp reference count held for this function */
3129 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3130 "0213 DSM out state %d on NPort free\n", rc);
3132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3133 "DSM out: ste:%d did:x%x flg:x%x",