1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 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 clear RSCN discovery flags when driver is unloading. */
52 lpfc_check_unload_and_clr_rscn(unsigned long *fc_flag)
54 /* If unloading, then clear the FC_RSCN_DEFERRED flag */
55 if (test_bit(FC_UNLOADING, fc_flag)) {
56 clear_bit(FC_RSCN_DEFERRED, fc_flag);
59 return test_bit(FC_RSCN_DEFERRED, fc_flag);
62 /* Called to verify a rcv'ed ADISC was intended for us. */
64 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
65 struct lpfc_name *nn, struct lpfc_name *pn)
67 /* First, we MUST have a RPI registered */
68 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag))
71 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
72 * table entry for that node.
74 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
77 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
80 /* we match, return success */
85 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
86 struct serv_parm *sp, uint32_t class, int flogi)
88 volatile struct serv_parm *hsp = &vport->fc_sparam;
89 uint16_t hsp_value, ssp_value = 0;
92 * The receive data field size and buffer-to-buffer receive data field
93 * size entries are 16 bits but are represented as two 8-bit fields in
94 * the driver data structure to account for rsvd bits and other control
95 * bits. Reconstruct and compare the fields as a 16-bit values before
96 * correcting the byte values.
98 if (sp->cls1.classValid) {
100 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
101 hsp->cls1.rcvDataSizeLsb);
102 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
103 sp->cls1.rcvDataSizeLsb);
105 goto bad_service_param;
106 if (ssp_value > hsp_value) {
107 sp->cls1.rcvDataSizeLsb =
108 hsp->cls1.rcvDataSizeLsb;
109 sp->cls1.rcvDataSizeMsb =
110 hsp->cls1.rcvDataSizeMsb;
113 } else if (class == CLASS1)
114 goto bad_service_param;
115 if (sp->cls2.classValid) {
117 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
118 hsp->cls2.rcvDataSizeLsb);
119 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
120 sp->cls2.rcvDataSizeLsb);
122 goto bad_service_param;
123 if (ssp_value > hsp_value) {
124 sp->cls2.rcvDataSizeLsb =
125 hsp->cls2.rcvDataSizeLsb;
126 sp->cls2.rcvDataSizeMsb =
127 hsp->cls2.rcvDataSizeMsb;
130 } else if (class == CLASS2)
131 goto bad_service_param;
132 if (sp->cls3.classValid) {
134 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
135 hsp->cls3.rcvDataSizeLsb);
136 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
137 sp->cls3.rcvDataSizeLsb);
139 goto bad_service_param;
140 if (ssp_value > hsp_value) {
141 sp->cls3.rcvDataSizeLsb =
142 hsp->cls3.rcvDataSizeLsb;
143 sp->cls3.rcvDataSizeMsb =
144 hsp->cls3.rcvDataSizeMsb;
147 } else if (class == CLASS3)
148 goto bad_service_param;
151 * Preserve the upper four bits of the MSB from the PLOGI response.
152 * These bits contain the Buffer-to-Buffer State Change Number
153 * from the target and need to be passed to the FW.
155 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
156 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
157 if (ssp_value > hsp_value) {
158 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
159 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
160 (hsp->cmn.bbRcvSizeMsb & 0x0F);
163 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
164 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
167 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
169 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
170 "invalid service parameters. Ignoring device.\n",
172 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
173 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
174 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
175 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
180 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
181 struct lpfc_iocbq *rspiocb)
183 struct lpfc_dmabuf *pcmd, *prsp;
186 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
188 pcmd = cmdiocb->cmd_dmabuf;
190 /* For lpfc_els_abort, cmd_dmabuf could be zero'ed to delay
191 * freeing associated memory till after ABTS completes.
194 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
197 lp = (uint32_t *) prsp->virt;
198 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
201 /* Force ulp_status error since we are returning NULL ptr */
203 if (phba->sli_rev == LPFC_SLI_REV4) {
204 bf_set(lpfc_wcqe_c_status, &rspiocb->wcqe_cmpl,
205 IOSTAT_LOCAL_REJECT);
206 rspiocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
208 rspiocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
209 rspiocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
220 * Free resources / clean up outstanding I/Os
221 * associated with a LPFC_NODELIST entry. This
222 * routine effectively results in a "software abort".
225 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
227 LIST_HEAD(abort_list);
228 LIST_HEAD(drv_cmpl_list);
229 struct lpfc_sli_ring *pring;
230 struct lpfc_iocbq *iocb, *next_iocb;
233 pring = lpfc_phba_elsring(phba);
235 /* In case of error recovery path, we might have a NULL pring here */
236 if (unlikely(!pring))
239 /* Abort outstanding I/O on NPort <nlp_DID> */
240 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
241 "2819 Abort outstanding I/O on NPort x%x "
242 "Data: x%lx x%x x%x\n",
243 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
245 /* Clean up all fabric IOs first.*/
246 lpfc_fabric_abort_nport(ndlp);
249 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
250 * of all ELS IOs that need an ABTS. The IOs need to stay on the
251 * txcmplq so that the abort operation completes them successfully.
253 spin_lock_irq(&phba->hbalock);
254 if (phba->sli_rev == LPFC_SLI_REV4)
255 spin_lock(&pring->ring_lock);
256 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
257 /* Add to abort_list on on NDLP match. */
258 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
259 list_add_tail(&iocb->dlist, &abort_list);
261 if (phba->sli_rev == LPFC_SLI_REV4)
262 spin_unlock(&pring->ring_lock);
263 spin_unlock_irq(&phba->hbalock);
265 /* Abort the targeted IOs and remove them from the abort list. */
266 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
267 spin_lock_irq(&phba->hbalock);
268 list_del_init(&iocb->dlist);
269 retval = lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
270 spin_unlock_irq(&phba->hbalock);
272 if (retval && test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
273 list_del_init(&iocb->list);
274 list_add_tail(&iocb->list, &drv_cmpl_list);
278 lpfc_sli_cancel_iocbs(phba, &drv_cmpl_list, IOSTAT_LOCAL_REJECT,
281 /* Make sure HBA is alive */
282 lpfc_issue_hb_tmo(phba);
284 INIT_LIST_HEAD(&abort_list);
286 /* Now process the txq */
287 spin_lock_irq(&phba->hbalock);
288 if (phba->sli_rev == LPFC_SLI_REV4)
289 spin_lock(&pring->ring_lock);
291 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
292 /* Check to see if iocb matches the nport we are looking for */
293 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
294 list_del_init(&iocb->list);
295 list_add_tail(&iocb->list, &abort_list);
299 if (phba->sli_rev == LPFC_SLI_REV4)
300 spin_unlock(&pring->ring_lock);
301 spin_unlock_irq(&phba->hbalock);
303 /* Cancel all the IOCBs from the completions list */
304 lpfc_sli_cancel_iocbs(phba, &abort_list,
305 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
307 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
310 /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
311 * @phba: pointer to lpfc hba data structure.
312 * @login_mbox: pointer to REG_RPI mailbox object
314 * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
317 lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox)
319 struct lpfc_iocbq *save_iocb;
320 struct lpfc_nodelist *ndlp;
321 MAILBOX_t *mb = &login_mbox->u.mb;
325 ndlp = login_mbox->ctx_ndlp;
326 save_iocb = login_mbox->ctx_u.save_iocb;
328 if (mb->mbxStatus == MBX_SUCCESS) {
329 /* Now that REG_RPI completed successfully,
330 * we can now proceed with sending the PLOGI ACC.
332 rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI,
333 save_iocb, ndlp, NULL);
335 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
336 "4576 PLOGI ACC fails pt2pt discovery: "
337 "DID %x Data: %x\n", ndlp->nlp_DID, rc);
341 /* Now process the REG_RPI cmpl */
342 lpfc_mbx_cmpl_reg_login(phba, login_mbox);
343 clear_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag);
348 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
349 struct lpfc_iocbq *cmdiocb)
351 struct lpfc_hba *phba = vport->phba;
352 struct lpfc_dmabuf *pcmd;
353 uint64_t nlp_portwwn = 0;
355 union lpfc_wqe128 *wqe;
357 struct serv_parm *sp;
359 LPFC_MBOXQ_t *link_mbox;
360 LPFC_MBOXQ_t *login_mbox;
361 struct lpfc_iocbq *save_iocb;
367 memset(&stat, 0, sizeof (struct ls_rjt));
368 pcmd = cmdiocb->cmd_dmabuf;
369 lp = (uint32_t *) pcmd->virt;
370 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
371 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
372 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
373 "0140 PLOGI Reject: invalid pname\n");
374 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
375 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
376 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
380 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
381 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
382 "0141 PLOGI Reject: invalid nname\n");
383 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
384 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
385 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
390 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
391 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
392 /* Reject this request because invalid parameters */
393 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
394 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
395 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
400 if (phba->sli_rev == LPFC_SLI_REV4)
403 icmd = &cmdiocb->iocb;
405 /* PLOGI chkparm OK */
406 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
407 "0114 PLOGI chkparm OK Data: x%x x%x x%lx "
409 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
410 ndlp->nlp_rpi, vport->port_state,
413 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
414 ndlp->nlp_fcp_info |= CLASS2;
416 ndlp->nlp_fcp_info |= CLASS3;
418 ndlp->nlp_class_sup = 0;
419 if (sp->cls1.classValid)
420 ndlp->nlp_class_sup |= FC_COS_CLASS1;
421 if (sp->cls2.classValid)
422 ndlp->nlp_class_sup |= FC_COS_CLASS2;
423 if (sp->cls3.classValid)
424 ndlp->nlp_class_sup |= FC_COS_CLASS3;
425 if (sp->cls4.classValid)
426 ndlp->nlp_class_sup |= FC_COS_CLASS4;
428 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
429 /* if already logged in, do implicit logout */
430 switch (ndlp->nlp_state) {
431 case NLP_STE_NPR_NODE:
432 if (!test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag))
435 case NLP_STE_REG_LOGIN_ISSUE:
436 case NLP_STE_PRLI_ISSUE:
437 case NLP_STE_UNMAPPED_NODE:
438 case NLP_STE_MAPPED_NODE:
439 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
440 * For target mode, execute implicit logo.
441 * Fabric nodes go into NPR.
443 if (!(ndlp->nlp_type & NLP_FABRIC) &&
444 !(phba->nvmet_support)) {
445 /* Clear ndlp info, since follow up PRLI may have
446 * updated ndlp information
448 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
449 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
450 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
451 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
452 clear_bit(NLP_FIRSTBURST, &ndlp->nlp_flag);
454 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
458 if (nlp_portwwn != 0 &&
459 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
461 "0143 PLOGI recv'd from DID: x%x "
462 "WWPN changed: old %llx new %llx\n",
464 (unsigned long long)nlp_portwwn,
466 wwn_to_u64(sp->portName.u.wwn));
468 /* Notify transport of connectivity loss to trigger cleanup. */
469 if (phba->nvmet_support &&
470 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
471 lpfc_nvmet_invalidate_host(phba, ndlp);
473 ndlp->nlp_prev_state = ndlp->nlp_state;
474 /* rport needs to be unregistered first */
475 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
479 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
480 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
481 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
482 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
483 clear_bit(NLP_FIRSTBURST, &ndlp->nlp_flag);
489 /* Check for Nport to NPort pt2pt protocol */
490 if (test_bit(FC_PT2PT, &vport->fc_flag) &&
491 !test_bit(FC_PT2PT_PLOGI, &vport->fc_flag)) {
492 /* rcv'ed PLOGI decides what our NPortId will be */
493 if (phba->sli_rev == LPFC_SLI_REV4) {
494 vport->fc_myDID = bf_get(els_rsp64_sid,
495 &cmdiocb->wqe.xmit_els_rsp);
497 vport->fc_myDID = icmd->un.rcvels.parmRo;
500 /* If there is an outstanding FLOGI, abort it now.
501 * The remote NPort is not going to ACC our FLOGI
502 * if its already issuing a PLOGI for pt2pt mode.
503 * This indicates our FLOGI was dropped; however, we
504 * must have ACCed the remote NPorts FLOGI to us
507 if (test_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag))
508 lpfc_els_abort_flogi(phba);
510 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
511 if (sp->cmn.edtovResolution) {
512 /* E_D_TOV ticks are in nanoseconds */
513 ed_tov = (phba->fc_edtov + 999999) / 1000000;
517 * For pt-to-pt, use the larger EDTOV
520 if (ed_tov > phba->fc_edtov)
521 phba->fc_edtov = ed_tov;
522 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
524 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
526 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
527 * to account for updated TOV's / parameters
529 if (phba->sli_rev == LPFC_SLI_REV4)
530 lpfc_issue_reg_vfi(vport);
532 link_mbox = mempool_alloc(phba->mbox_mem_pool,
536 lpfc_config_link(phba, link_mbox);
537 link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
538 link_mbox->vport = vport;
540 /* The default completion handling for CONFIG_LINK
541 * does not require the ndlp so no reference is needed.
543 link_mbox->ctx_ndlp = ndlp;
545 rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
546 if (rc == MBX_NOT_FINISHED) {
547 mempool_free(link_mbox, phba->mbox_mem_pool);
552 lpfc_can_disctmo(vport);
555 clear_bit(NLP_SUPPRESS_RSP, &ndlp->nlp_flag);
556 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
557 sp->cmn.valid_vendor_ver_level) {
558 vid = be32_to_cpu(sp->un.vv.vid);
559 flag = be32_to_cpu(sp->un.vv.flags);
560 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
561 set_bit(NLP_SUPPRESS_RSP, &ndlp->nlp_flag);
564 login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
568 save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
572 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
573 memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
574 sizeof(struct lpfc_iocbq));
576 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
577 if (phba->sli_rev == LPFC_SLI_REV4)
578 lpfc_unreg_rpi(vport, ndlp);
580 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
581 * always be deferring the ACC.
583 if (phba->sli_rev == LPFC_SLI_REV4)
584 remote_did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
586 remote_did = icmd->un.rcvels.remoteID;
587 rc = lpfc_reg_rpi(phba, vport->vpi, remote_did,
588 (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
592 login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
593 login_mbox->vport = vport;
596 * If there is an outstanding PLOGI issued, abort it before
597 * sending ACC rsp for received PLOGI. If pending plogi
598 * is not canceled here, the plogi will be rejected by
599 * remote port and will be retried. On a configuration with
600 * single discovery thread, this will cause a huge delay in
601 * discovery. Also this will cause multiple state machines
602 * running in parallel for this node.
603 * This only applies to a fabric environment.
605 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
606 test_bit(FC_FABRIC, &vport->fc_flag)) {
607 /* software abort outstanding PLOGI */
608 lpfc_els_abort(phba, ndlp);
611 if ((vport->port_type == LPFC_NPIV_PORT &&
612 vport->cfg_restrict_login)) {
614 /* no deferred ACC */
617 /* This is an NPIV SLI4 instance that does not need to register
620 if (phba->sli_rev == LPFC_SLI_REV4) {
621 lpfc_mbox_rsrc_cleanup(phba, login_mbox,
625 /* In order to preserve RPIs, we want to cleanup
626 * the default RPI the firmware created to rcv
627 * this ELS request. The only way to do this is
628 * to register, then unregister the RPI.
630 set_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag);
631 set_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag);
632 set_bit(NLP_RCV_PLOGI, &ndlp->nlp_flag);
635 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
636 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
637 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
639 if (rc && login_mbox)
640 lpfc_mbox_rsrc_cleanup(phba, login_mbox,
645 /* So the order here should be:
647 * Issue CONFIG_LINK mbox
653 * Issue UNREG RPI mbx
660 login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
661 login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
662 if (!login_mbox->ctx_ndlp)
665 login_mbox->ctx_u.save_iocb = save_iocb; /* For PLOGI ACC */
667 set_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag);
668 set_bit(NLP_RCV_PLOGI, &ndlp->nlp_flag);
670 /* Start the ball rolling by issuing REG_LOGIN here */
671 rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
672 if (rc == MBX_NOT_FINISHED) {
676 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
682 mempool_free(login_mbox, phba->mbox_mem_pool);
684 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
685 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
686 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
691 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
692 * @phba: pointer to lpfc hba data structure.
693 * @mboxq: pointer to mailbox object
695 * This routine is invoked to issue a completion to a rcv'ed
696 * ADISC or PDISC after the paused RPI has been resumed.
699 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
701 struct lpfc_vport *vport;
702 struct lpfc_iocbq *elsiocb;
703 struct lpfc_nodelist *ndlp;
706 elsiocb = mboxq->ctx_u.save_iocb;
707 ndlp = mboxq->ctx_ndlp;
708 vport = mboxq->vport;
709 cmd = elsiocb->drvrTimeout;
711 if (cmd == ELS_CMD_ADISC) {
712 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
714 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
718 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
722 mempool_free(mboxq, phba->mbox_mem_pool);
726 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
727 struct lpfc_iocbq *cmdiocb)
729 struct lpfc_hba *phba = vport->phba;
730 struct lpfc_iocbq *elsiocb;
731 struct lpfc_dmabuf *pcmd;
732 struct serv_parm *sp;
733 struct lpfc_name *pnn, *ppn;
739 pcmd = cmdiocb->cmd_dmabuf;
740 lp = (uint32_t *) pcmd->virt;
743 if (cmd == ELS_CMD_ADISC) {
745 pnn = (struct lpfc_name *) & ap->nodeName;
746 ppn = (struct lpfc_name *) & ap->portName;
748 sp = (struct serv_parm *) lp;
749 pnn = (struct lpfc_name *) & sp->nodeName;
750 ppn = (struct lpfc_name *) & sp->portName;
753 if (get_job_ulpstatus(phba, cmdiocb) == 0 &&
754 lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
757 * As soon as we send ACC, the remote NPort can
758 * start sending us data. Thus, for SLI4 we must
759 * resume the RPI before the ACC goes out.
761 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
762 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
765 /* Save info from cmd IOCB used in rsp */
766 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
767 sizeof(struct lpfc_iocbq));
769 /* Save the ELS cmd */
770 elsiocb->drvrTimeout = cmd;
772 if (lpfc_sli4_resume_rpi(ndlp,
773 lpfc_mbx_cmpl_resume_rpi,
780 if (cmd == ELS_CMD_ADISC) {
781 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
783 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
787 /* If we are authenticated, move to the proper state.
788 * It is possible an ADISC arrived and the remote nport
789 * is already in MAPPED or UNMAPPED state. Catch this
790 * condition and don't set the nlp_state again because
791 * it causes an unnecessary transport unregister/register.
793 * Nodes marked for ADISC will move MAPPED or UNMAPPED state
794 * after issuing ADISC
796 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
797 if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) &&
798 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag))
799 lpfc_nlp_set_state(vport, ndlp,
800 NLP_STE_MAPPED_NODE);
805 /* Reject this request because invalid parameters */
806 stat.un.b.lsRjtRsvd0 = 0;
807 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
808 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
809 stat.un.b.vendorUnique = 0;
810 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
813 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
815 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
816 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
817 ndlp->nlp_prev_state = ndlp->nlp_state;
818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
823 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
824 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
826 struct lpfc_hba *phba = vport->phba;
827 struct lpfc_vport **vports;
828 int i, active_vlink_present = 0 ;
830 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
831 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
832 * PLOGIs during LOGO storms from a device.
834 set_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
835 if (els_cmd == ELS_CMD_PRLO)
836 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
838 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
840 /* This clause allows the initiator to ACC the LOGO back to the
841 * Fabric Domain Controller. It does deliberately skip all other
842 * steps because some fabrics send RDP requests after logging out
843 * from the initiator.
845 if (ndlp->nlp_type & NLP_FABRIC &&
846 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
849 /* Notify transport of connectivity loss to trigger cleanup. */
850 if (phba->nvmet_support &&
851 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
852 lpfc_nvmet_invalidate_host(phba, ndlp);
854 if (ndlp->nlp_DID == Fabric_DID) {
855 if (vport->port_state <= LPFC_FDISC ||
856 test_bit(FC_PT2PT, &vport->fc_flag))
858 lpfc_linkdown_port(vport);
859 set_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag);
860 vports = lpfc_create_vport_work_array(phba);
862 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
864 if (!test_bit(FC_VPORT_LOGO_RCVD,
865 &vports[i]->fc_flag) &&
866 vports[i]->port_state > LPFC_FDISC) {
867 active_vlink_present = 1;
871 lpfc_destroy_vport_work_array(phba, vports);
875 * Don't re-instantiate if vport is marked for deletion.
876 * If we are here first then vport_delete is going to wait
877 * for discovery to complete.
879 if (!test_bit(FC_UNLOADING, &vport->load_flag) &&
880 active_vlink_present) {
882 * If there are other active VLinks present,
883 * re-instantiate the Vlink using FDISC.
885 mod_timer(&ndlp->nlp_delayfunc,
886 jiffies + msecs_to_jiffies(1000));
887 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
888 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
889 vport->port_state = LPFC_FDISC;
891 clear_bit(FC_LOGO_RCVD_DID_CHNG, &phba->pport->fc_flag);
892 lpfc_retry_pport_discovery(phba);
895 lpfc_printf_vlog(vport, KERN_INFO,
896 LOG_NODE | LOG_ELS | LOG_DISCOVERY,
897 "3203 LOGO recover nport x%06x state x%x "
898 "ntype x%x fc_flag x%lx\n",
899 ndlp->nlp_DID, ndlp->nlp_state,
900 ndlp->nlp_type, vport->fc_flag);
902 /* Special cases for rports that recover post LOGO. */
903 if ((!(ndlp->nlp_type == NLP_FABRIC) &&
904 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) ||
905 test_bit(FC_PT2PT, &vport->fc_flag))) ||
906 (ndlp->nlp_state >= NLP_STE_ADISC_ISSUE ||
907 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE)) {
908 mod_timer(&ndlp->nlp_delayfunc,
909 jiffies + msecs_to_jiffies(1000 * 1));
910 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
911 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
912 lpfc_printf_vlog(vport, KERN_INFO,
913 LOG_NODE | LOG_ELS | LOG_DISCOVERY,
914 "3204 Start nlpdelay on DID x%06x "
915 "nflag x%lx lastels x%x ref cnt %u",
916 ndlp->nlp_DID, ndlp->nlp_flag,
917 ndlp->nlp_last_elscmd,
918 kref_read(&ndlp->kref));
922 /* Unregister from backend, could have been skipped due to ADISC */
923 lpfc_nlp_unreg_node(vport, ndlp);
925 ndlp->nlp_prev_state = ndlp->nlp_state;
926 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
928 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
929 /* The driver has to wait until the ACC completes before it continues
930 * processing the LOGO. The action will resume in
931 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
932 * unreg_login, the driver waits so the ACC does not get aborted.
938 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
939 struct lpfc_nodelist *ndlp,
940 struct lpfc_iocbq *cmdiocb)
947 payload = cmdiocb->cmd_dmabuf->virt;
949 npr = (PRLI *)((uint8_t *)payload + sizeof(uint32_t));
951 if (vport->phba->nvmet_support) {
952 /* Must be a NVME PRLI */
953 if (cmd == ELS_CMD_PRLI)
956 /* Initiator mode. */
957 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
960 /* NPIV ports will RJT initiator only functions */
961 if (vport->port_type == LPFC_NPIV_PORT &&
962 npr->initiatorFunc && !npr->targetFunc)
967 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
968 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
969 "state x%x flags x%lx port_type: x%x "
970 "npr->initfcn: x%x npr->tgtfcn: x%x\n",
971 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
972 ndlp->nlp_flag, vport->port_type,
973 npr->initiatorFunc, npr->targetFunc);
974 memset(&stat, 0, sizeof(struct ls_rjt));
975 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
976 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
977 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
983 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
984 struct lpfc_iocbq *cmdiocb)
986 struct lpfc_hba *phba = vport->phba;
987 struct lpfc_dmabuf *pcmd;
990 struct fc_rport *rport = ndlp->rport;
993 pcmd = cmdiocb->cmd_dmabuf;
994 lp = (uint32_t *)pcmd->virt;
995 npr = (PRLI *)((uint8_t *)lp + sizeof(uint32_t));
997 if ((npr->prliType == PRLI_FCP_TYPE) ||
998 (npr->prliType == PRLI_NVME_TYPE)) {
999 if (npr->initiatorFunc) {
1000 if (npr->prliType == PRLI_FCP_TYPE)
1001 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1002 if (npr->prliType == PRLI_NVME_TYPE)
1003 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1005 if (npr->targetFunc) {
1006 if (npr->prliType == PRLI_FCP_TYPE)
1007 ndlp->nlp_type |= NLP_FCP_TARGET;
1008 if (npr->prliType == PRLI_NVME_TYPE)
1009 ndlp->nlp_type |= NLP_NVME_TARGET;
1010 if (npr->writeXferRdyDis)
1011 set_bit(NLP_FIRSTBURST, &ndlp->nlp_flag);
1013 if (npr->Retry && ndlp->nlp_type &
1014 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
1015 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1017 if (npr->Retry && phba->nsler &&
1018 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
1019 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
1022 /* If this driver is in nvme target mode, set the ndlp's fc4
1023 * type to NVME provided the PRLI response claims NVME FC4
1024 * type. Target mode does not issue gft_id so doesn't get
1025 * the fc4 type set until now.
1027 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
1028 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1032 /* Fabric Controllers send FCP PRLI as an initiator but should
1033 * not get recognized as FCP type and registered with transport.
1035 if (npr->prliType == PRLI_FCP_TYPE &&
1036 !(ndlp->nlp_type & NLP_FABRIC))
1037 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1040 /* We need to update the rport role values */
1041 roles = FC_RPORT_ROLE_UNKNOWN;
1042 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1043 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1044 if (ndlp->nlp_type & NLP_FCP_TARGET)
1045 roles |= FC_RPORT_ROLE_FCP_TARGET;
1047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1048 "rport rolechg: role:x%x did:x%x flg:x%lx",
1049 roles, ndlp->nlp_DID, ndlp->nlp_flag);
1051 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1052 fc_remote_port_rolechg(rport, roles);
1057 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1059 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag)) {
1060 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
1064 if (!test_bit(FC_PT2PT, &vport->fc_flag)) {
1065 /* Check config parameter use-adisc or FCP-2 */
1066 if (vport->cfg_use_adisc &&
1067 (test_bit(FC_RSCN_MODE, &vport->fc_flag) ||
1068 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1069 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1070 set_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
1075 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
1076 lpfc_unreg_rpi(vport, ndlp);
1081 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1082 * @phba : Pointer to lpfc_hba structure.
1083 * @vport: Pointer to lpfc_vport structure.
1084 * @ndlp: Pointer to lpfc_nodelist structure.
1085 * @rpi : rpi to be release.
1087 * This function will send a unreg_login mailbox command to the firmware
1091 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1092 struct lpfc_nodelist *ndlp, uint16_t rpi)
1097 /* If there is already an UNREG in progress for this ndlp,
1098 * no need to queue up another one.
1100 if (test_bit(NLP_UNREG_INP, &ndlp->nlp_flag)) {
1101 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1102 "1435 release_rpi SKIP UNREG x%x on "
1103 "NPort x%x deferred x%x flg x%lx "
1105 ndlp->nlp_rpi, ndlp->nlp_DID,
1106 ndlp->nlp_defer_did,
1107 ndlp->nlp_flag, ndlp);
1111 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1114 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1115 "2796 mailbox memory allocation failed \n");
1117 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1118 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1120 pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
1121 if (!pmb->ctx_ndlp) {
1122 mempool_free(pmb, phba->mbox_mem_pool);
1126 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1127 (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag)))
1128 set_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
1130 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1131 "1437 release_rpi UNREG x%x "
1132 "on NPort x%x flg x%lx\n",
1133 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1135 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1136 if (rc == MBX_NOT_FINISHED) {
1138 mempool_free(pmb, phba->mbox_mem_pool);
1144 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1145 void *arg, uint32_t evt)
1147 struct lpfc_hba *phba;
1148 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1152 /* Release the RPI if reglogin completing */
1153 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag) &&
1154 evt == NLP_EVT_CMPL_REG_LOGIN && !pmb->u.mb.mbxStatus) {
1155 rpi = pmb->u.mb.un.varWords[0];
1156 lpfc_release_rpi(phba, vport, ndlp, rpi);
1158 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1159 "0271 Illegal State Transition: node x%x "
1160 "event x%x, state x%x Data: x%x x%lx\n",
1161 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1163 return ndlp->nlp_state;
1167 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1168 void *arg, uint32_t evt)
1170 /* This transition is only legal if we previously
1171 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1172 * working on the same NPortID, do nothing for this thread
1175 if (!test_bit(NLP_RCV_PLOGI, &ndlp->nlp_flag))
1176 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1177 "0272 Illegal State Transition: node x%x "
1178 "event x%x, state x%x Data: x%x x%lx\n",
1179 ndlp->nlp_DID, evt, ndlp->nlp_state,
1180 ndlp->nlp_rpi, ndlp->nlp_flag);
1181 return ndlp->nlp_state;
1184 /* Start of Discovery State Machine routines */
1187 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1188 void *arg, uint32_t evt)
1190 struct lpfc_iocbq *cmdiocb;
1192 cmdiocb = (struct lpfc_iocbq *) arg;
1194 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1195 return ndlp->nlp_state;
1197 return NLP_STE_FREED_NODE;
1201 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1202 void *arg, uint32_t evt)
1204 lpfc_issue_els_logo(vport, ndlp, 0);
1205 return ndlp->nlp_state;
1209 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1210 void *arg, uint32_t evt)
1212 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1214 set_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
1215 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1217 return ndlp->nlp_state;
1221 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1222 void *arg, uint32_t evt)
1224 return NLP_STE_FREED_NODE;
1228 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1229 void *arg, uint32_t evt)
1231 return NLP_STE_FREED_NODE;
1235 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1236 struct lpfc_nodelist *ndlp,
1237 void *arg, uint32_t evt)
1239 return ndlp->nlp_state;
1243 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1244 void *arg, uint32_t evt)
1246 struct lpfc_hba *phba = vport->phba;
1247 struct lpfc_iocbq *cmdiocb = arg;
1248 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
1249 uint32_t *lp = (uint32_t *) pcmd->virt;
1250 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1254 memset(&stat, 0, sizeof (struct ls_rjt));
1256 /* For a PLOGI, we only accept if our portname is less
1257 * than the remote portname.
1259 phba->fc_stat.elsLogiCol++;
1260 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1261 sizeof(struct lpfc_name));
1263 if (port_cmp >= 0) {
1264 /* Reject this request because the remote node will accept
1266 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1267 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1268 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1271 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1272 test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag) &&
1273 vport->num_disc_nodes) {
1274 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
1275 /* Check if there are more PLOGIs to be sent */
1276 lpfc_more_plogi(vport);
1277 if (vport->num_disc_nodes == 0) {
1278 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
1279 lpfc_can_disctmo(vport);
1280 lpfc_end_rscn(vport);
1283 } /* If our portname was less */
1285 return ndlp->nlp_state;
1289 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1290 void *arg, uint32_t evt)
1292 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1295 memset(&stat, 0, sizeof (struct ls_rjt));
1296 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1297 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1298 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1299 return ndlp->nlp_state;
1303 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1304 void *arg, uint32_t evt)
1306 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1308 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1309 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1310 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1311 /* software abort outstanding PLOGI */
1312 lpfc_els_abort(vport->phba, ndlp);
1314 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1315 return ndlp->nlp_state;
1319 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1320 void *arg, uint32_t evt)
1322 struct lpfc_hba *phba = vport->phba;
1323 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1325 /* software abort outstanding PLOGI */
1326 lpfc_els_abort(phba, ndlp);
1328 if (evt == NLP_EVT_RCV_LOGO) {
1329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1331 lpfc_issue_els_logo(vport, ndlp, 0);
1334 /* Put ndlp in npr state set plogi timer for 1 sec */
1335 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1336 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
1337 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1338 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1341 return ndlp->nlp_state;
1345 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1346 struct lpfc_nodelist *ndlp,
1350 struct lpfc_hba *phba = vport->phba;
1351 struct lpfc_iocbq *cmdiocb, *rspiocb;
1352 struct lpfc_dmabuf *pcmd, *prsp;
1355 struct serv_parm *sp;
1362 cmdiocb = (struct lpfc_iocbq *) arg;
1363 rspiocb = cmdiocb->rsp_iocb;
1365 ulp_status = get_job_ulpstatus(phba, rspiocb);
1367 if (test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag)) {
1368 /* Recovery from PLOGI collision logic */
1369 return ndlp->nlp_state;
1375 pcmd = cmdiocb->cmd_dmabuf;
1377 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1381 lp = (uint32_t *) prsp->virt;
1382 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1384 /* Some switches have FDMI servers returning 0 for WWN */
1385 if ((ndlp->nlp_DID != FDMI_DID) &&
1386 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1387 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1388 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1389 "0142 PLOGI RSP: Invalid WWN.\n");
1392 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1394 /* PLOGI chkparm OK */
1395 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1396 "0121 PLOGI chkparm OK Data: x%x x%x x%lx x%x\n",
1397 ndlp->nlp_DID, ndlp->nlp_state,
1398 ndlp->nlp_flag, ndlp->nlp_rpi);
1399 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1400 ndlp->nlp_fcp_info |= CLASS2;
1402 ndlp->nlp_fcp_info |= CLASS3;
1404 ndlp->nlp_class_sup = 0;
1405 if (sp->cls1.classValid)
1406 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1407 if (sp->cls2.classValid)
1408 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1409 if (sp->cls3.classValid)
1410 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1411 if (sp->cls4.classValid)
1412 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1413 ndlp->nlp_maxframe =
1414 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1416 if (test_bit(FC_PT2PT, &vport->fc_flag) &&
1417 test_bit(FC_PT2PT_PLOGI, &vport->fc_flag)) {
1418 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1419 if (sp->cmn.edtovResolution) {
1420 /* E_D_TOV ticks are in nanoseconds */
1421 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1424 clear_bit(NLP_SUPPRESS_RSP, &ndlp->nlp_flag);
1425 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1426 sp->cmn.valid_vendor_ver_level) {
1427 vid = be32_to_cpu(sp->un.vv.vid);
1428 flag = be32_to_cpu(sp->un.vv.flags);
1429 if ((vid == LPFC_VV_EMLX_ID) &&
1430 (flag & LPFC_VV_SUPPRESS_RSP))
1431 set_bit(NLP_SUPPRESS_RSP, &ndlp->nlp_flag);
1435 * Use the larger EDTOV
1436 * RATOV = 2 * EDTOV for pt-to-pt
1438 if (ed_tov > phba->fc_edtov)
1439 phba->fc_edtov = ed_tov;
1440 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1442 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1444 /* Issue config_link / reg_vfi to account for updated TOV's */
1445 if (phba->sli_rev == LPFC_SLI_REV4) {
1446 lpfc_issue_reg_vfi(vport);
1448 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1450 lpfc_printf_vlog(vport, KERN_ERR,
1452 "0133 PLOGI: no memory "
1454 "Data: x%x x%x x%lx x%x\n",
1455 ndlp->nlp_DID, ndlp->nlp_state,
1456 ndlp->nlp_flag, ndlp->nlp_rpi);
1460 lpfc_config_link(phba, mbox);
1462 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1463 mbox->vport = vport;
1464 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1465 if (rc == MBX_NOT_FINISHED) {
1466 mempool_free(mbox, phba->mbox_mem_pool);
1472 lpfc_unreg_rpi(vport, ndlp);
1474 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1476 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1477 "0018 PLOGI: no memory for reg_login "
1478 "Data: x%x x%x x%lx x%x\n",
1479 ndlp->nlp_DID, ndlp->nlp_state,
1480 ndlp->nlp_flag, ndlp->nlp_rpi);
1484 did = get_job_els_rsp64_did(phba, cmdiocb);
1486 if (lpfc_reg_rpi(phba, vport->vpi, did,
1487 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1488 switch (ndlp->nlp_DID) {
1489 case NameServer_DID:
1490 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1491 /* Fabric Controller Node needs these parameters. */
1492 memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
1495 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1498 set_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
1499 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1502 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1503 if (!mbox->ctx_ndlp)
1506 mbox->vport = vport;
1507 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1508 != MBX_NOT_FINISHED) {
1509 lpfc_nlp_set_state(vport, ndlp,
1510 NLP_STE_REG_LOGIN_ISSUE);
1511 return ndlp->nlp_state;
1513 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
1514 /* decrement node reference count to the failed mbox
1518 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
1519 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1520 "0134 PLOGI: cannot issue reg_login "
1521 "Data: x%x x%x x%lx x%x\n",
1522 ndlp->nlp_DID, ndlp->nlp_state,
1523 ndlp->nlp_flag, ndlp->nlp_rpi);
1525 mempool_free(mbox, phba->mbox_mem_pool);
1527 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1528 "0135 PLOGI: cannot format reg_login "
1529 "Data: x%x x%x x%lx x%x\n",
1530 ndlp->nlp_DID, ndlp->nlp_state,
1531 ndlp->nlp_flag, ndlp->nlp_rpi);
1536 if (ndlp->nlp_DID == NameServer_DID) {
1537 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1538 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1539 "0261 Cannot Register NameServer login\n");
1543 ** In case the node reference counter does not go to zero, ensure that
1544 ** the stale state for the node is not processed.
1547 ndlp->nlp_prev_state = ndlp->nlp_state;
1548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1549 return NLP_STE_FREED_NODE;
1553 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1554 void *arg, uint32_t evt)
1556 return ndlp->nlp_state;
1560 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1561 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1563 struct lpfc_hba *phba;
1564 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1565 MAILBOX_t *mb = &pmb->u.mb;
1569 /* Release the RPI */
1570 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag) &&
1572 rpi = pmb->u.mb.un.varWords[0];
1573 lpfc_release_rpi(phba, vport, ndlp, rpi);
1575 return ndlp->nlp_state;
1579 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1580 void *arg, uint32_t evt)
1582 if (test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
1583 set_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
1584 return ndlp->nlp_state;
1586 /* software abort outstanding PLOGI */
1587 lpfc_els_abort(vport->phba, ndlp);
1589 lpfc_drop_node(vport, ndlp);
1590 return NLP_STE_FREED_NODE;
1594 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1595 struct lpfc_nodelist *ndlp,
1599 struct lpfc_hba *phba = vport->phba;
1601 /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */
1602 if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag))
1603 return ndlp->nlp_state;
1605 /* software abort outstanding PLOGI */
1606 lpfc_els_abort(phba, ndlp);
1608 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1610 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
1611 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
1613 return ndlp->nlp_state;
1617 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1618 void *arg, uint32_t evt)
1620 struct lpfc_hba *phba = vport->phba;
1621 struct lpfc_iocbq *cmdiocb;
1623 /* software abort outstanding ADISC */
1624 lpfc_els_abort(phba, ndlp);
1626 cmdiocb = (struct lpfc_iocbq *) arg;
1628 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1629 if (test_and_clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
1630 if (vport->num_disc_nodes)
1631 lpfc_more_adisc(vport);
1633 return ndlp->nlp_state;
1635 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1636 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1637 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1639 return ndlp->nlp_state;
1643 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1644 void *arg, uint32_t evt)
1646 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1648 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1649 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1650 return ndlp->nlp_state;
1654 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1655 void *arg, uint32_t evt)
1657 struct lpfc_hba *phba = vport->phba;
1658 struct lpfc_iocbq *cmdiocb;
1660 cmdiocb = (struct lpfc_iocbq *) arg;
1662 /* software abort outstanding ADISC */
1663 lpfc_els_abort(phba, ndlp);
1665 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1666 return ndlp->nlp_state;
1670 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1671 struct lpfc_nodelist *ndlp,
1672 void *arg, uint32_t evt)
1674 struct lpfc_iocbq *cmdiocb;
1676 cmdiocb = (struct lpfc_iocbq *) arg;
1678 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1679 return ndlp->nlp_state;
1683 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1684 void *arg, uint32_t evt)
1686 struct lpfc_iocbq *cmdiocb;
1688 cmdiocb = (struct lpfc_iocbq *) arg;
1690 /* Treat like rcv logo */
1691 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1692 return ndlp->nlp_state;
1696 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1697 struct lpfc_nodelist *ndlp,
1698 void *arg, uint32_t evt)
1700 struct lpfc_hba *phba = vport->phba;
1701 struct lpfc_iocbq *cmdiocb, *rspiocb;
1706 cmdiocb = (struct lpfc_iocbq *) arg;
1707 rspiocb = cmdiocb->rsp_iocb;
1709 ulp_status = get_job_ulpstatus(phba, rspiocb);
1711 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1714 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1716 mod_timer(&ndlp->nlp_delayfunc,
1717 jiffies + msecs_to_jiffies(1000));
1718 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
1719 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1721 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1722 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1723 lpfc_unreg_rpi(vport, ndlp);
1724 return ndlp->nlp_state;
1727 if (phba->sli_rev == LPFC_SLI_REV4) {
1728 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1730 /* Stay in state and retry. */
1731 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1732 return ndlp->nlp_state;
1736 if (ndlp->nlp_type & NLP_FCP_TARGET)
1737 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1739 if (ndlp->nlp_type & NLP_NVME_TARGET)
1740 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1742 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1743 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1746 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1747 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1750 return ndlp->nlp_state;
1754 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1755 void *arg, uint32_t evt)
1757 if (test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
1758 set_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
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;
1769 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1770 struct lpfc_nodelist *ndlp,
1774 struct lpfc_hba *phba = vport->phba;
1776 /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */
1777 if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag))
1778 return ndlp->nlp_state;
1780 /* software abort outstanding ADISC */
1781 lpfc_els_abort(phba, ndlp);
1783 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1785 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
1786 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
1787 lpfc_disc_set_adisc(vport, ndlp);
1788 return ndlp->nlp_state;
1792 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1793 struct lpfc_nodelist *ndlp,
1797 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1799 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1800 return ndlp->nlp_state;
1804 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1805 struct lpfc_nodelist *ndlp,
1809 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1812 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1813 return ndlp->nlp_state;
1815 if (vport->phba->nvmet_support) {
1816 /* NVME Target mode. Handle and respond to the PRLI and
1817 * transition to UNMAPPED provided the RPI has completed
1820 if (test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag)) {
1821 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1822 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1824 /* RPI registration has not completed. Reject the PRLI
1825 * to prevent an illegal state transition when the
1826 * rpi registration does complete.
1828 memset(&stat, 0, sizeof(struct ls_rjt));
1829 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1830 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1831 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1833 return ndlp->nlp_state;
1836 /* Initiator mode. */
1837 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1839 return ndlp->nlp_state;
1843 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1844 struct lpfc_nodelist *ndlp,
1848 struct lpfc_hba *phba = vport->phba;
1849 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1851 LPFC_MBOXQ_t *nextmb;
1853 cmdiocb = (struct lpfc_iocbq *) arg;
1855 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1856 if ((mb = phba->sli.mbox_active)) {
1857 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1858 (ndlp == mb->ctx_ndlp)) {
1859 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
1861 mb->ctx_ndlp = NULL;
1862 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1866 spin_lock_irq(&phba->hbalock);
1867 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1868 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1869 (ndlp == mb->ctx_ndlp)) {
1870 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
1872 list_del(&mb->list);
1873 phba->sli.mboxq_cnt--;
1874 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
1877 spin_unlock_irq(&phba->hbalock);
1879 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1880 return ndlp->nlp_state;
1884 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1885 struct lpfc_nodelist *ndlp,
1889 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1891 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1892 return ndlp->nlp_state;
1896 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1897 struct lpfc_nodelist *ndlp,
1901 struct lpfc_iocbq *cmdiocb;
1903 cmdiocb = (struct lpfc_iocbq *) arg;
1904 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1905 return ndlp->nlp_state;
1909 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1910 struct lpfc_nodelist *ndlp,
1914 struct lpfc_hba *phba = vport->phba;
1915 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1916 MAILBOX_t *mb = &pmb->u.mb;
1917 uint32_t did = mb->un.varWords[1];
1919 if (mb->mbxStatus) {
1920 /* RegLogin failed */
1921 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1922 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1924 did, mb->mbxStatus, vport->port_state,
1925 mb->un.varRegLogin.vpi,
1926 mb->un.varRegLogin.rpi);
1928 * If RegLogin failed due to lack of HBA resources do not
1931 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1932 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1933 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1934 return ndlp->nlp_state;
1937 /* Put ndlp in npr state set plogi timer for 1 sec */
1938 mod_timer(&ndlp->nlp_delayfunc,
1939 jiffies + msecs_to_jiffies(1000 * 1));
1940 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
1941 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1943 lpfc_issue_els_logo(vport, ndlp, 0);
1944 return ndlp->nlp_state;
1947 /* SLI4 ports have preallocated logical rpis. */
1948 if (phba->sli_rev < LPFC_SLI_REV4)
1949 ndlp->nlp_rpi = mb->un.varWords[0];
1951 set_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag);
1953 /* Only if we are not a fabric nport do we issue PRLI */
1954 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1955 "3066 RegLogin Complete on x%x x%x x%x\n",
1956 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1957 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1958 (phba->nvmet_support == 0)) {
1959 /* The driver supports FCP and NVME concurrently. If the
1960 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1961 * know what PRLI to send yet. Figure that out now and
1962 * call PRLI depending on the outcome.
1964 if (test_bit(FC_PT2PT, &vport->fc_flag)) {
1965 /* If we are pt2pt, there is no Fabric to determine
1966 * the FC4 type of the remote nport. So if NVME
1967 * is configured try it.
1969 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1970 if ((!test_bit(FC_PT2PT_NO_NVME, &vport->fc_flag)) &&
1971 (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1972 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1973 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1974 /* We need to update the localport also */
1975 lpfc_nvme_update_localport(vport);
1978 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1979 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1981 } else if (ndlp->nlp_fc4_type == 0) {
1982 /* If we are only configured for FCP, the driver
1983 * should just issue PRLI for FCP. Otherwise issue
1984 * GFT_ID to determine if remote port supports NVME.
1986 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1987 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
1989 return ndlp->nlp_state;
1991 ndlp->nlp_fc4_type = NLP_FC4_FCP;
1994 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1996 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
1997 lpfc_issue_els_logo(vport, ndlp, 0);
1998 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1999 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2002 if (test_bit(FC_PT2PT, &vport->fc_flag) && phba->nvmet_support)
2003 phba->targetport->port_id = vport->fc_myDID;
2005 /* Only Fabric ports should transition. NVME target
2006 * must complete PRLI.
2008 if (ndlp->nlp_type & NLP_FABRIC) {
2009 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2010 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2011 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2014 return ndlp->nlp_state;
2018 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2019 struct lpfc_nodelist *ndlp,
2023 if (test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
2024 set_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2025 return ndlp->nlp_state;
2027 lpfc_drop_node(vport, ndlp);
2028 return NLP_STE_FREED_NODE;
2032 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2033 struct lpfc_nodelist *ndlp,
2037 /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */
2038 if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag))
2039 return ndlp->nlp_state;
2041 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2042 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2044 /* If we are a target we won't immediately transition into PRLI,
2045 * so if REG_LOGIN already completed we don't need to ignore it.
2047 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag) ||
2048 !vport->phba->nvmet_support)
2049 set_bit(NLP_IGNR_REG_CMPL, &ndlp->nlp_flag);
2051 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2052 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2053 lpfc_disc_set_adisc(vport, ndlp);
2054 return ndlp->nlp_state;
2058 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2059 void *arg, uint32_t evt)
2061 struct lpfc_iocbq *cmdiocb;
2063 cmdiocb = (struct lpfc_iocbq *) arg;
2065 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2066 return ndlp->nlp_state;
2070 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2071 void *arg, uint32_t evt)
2073 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2075 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2076 return ndlp->nlp_state;
2077 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2078 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2079 return ndlp->nlp_state;
2083 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2084 void *arg, uint32_t evt)
2086 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2088 /* Software abort outstanding PRLI before sending acc */
2089 lpfc_els_abort(vport->phba, ndlp);
2091 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2092 return ndlp->nlp_state;
2096 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2097 void *arg, uint32_t evt)
2099 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2101 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2102 return ndlp->nlp_state;
2105 /* This routine is envoked when we rcv a PRLO request from a nport
2106 * we are logged into. We should send back a PRLO rsp setting the
2108 * NEXT STATE = PRLI_ISSUE
2111 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2112 void *arg, uint32_t evt)
2114 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2116 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2117 return ndlp->nlp_state;
2121 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2122 void *arg, uint32_t evt)
2124 struct lpfc_iocbq *cmdiocb, *rspiocb;
2125 struct lpfc_hba *phba = vport->phba;
2127 struct lpfc_nvme_prli *nvpr;
2130 bool acc_imode_sps = false;
2132 cmdiocb = (struct lpfc_iocbq *) arg;
2133 rspiocb = cmdiocb->rsp_iocb;
2135 ulp_status = get_job_ulpstatus(phba, rspiocb);
2137 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2138 * format is different so NULL the two PRLI types so that the
2139 * driver correctly gets the correct context.
2143 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2144 if (cmdiocb->cmd_flag & LPFC_PRLI_FCP_REQ)
2145 npr = (PRLI *) temp_ptr;
2146 else if (cmdiocb->cmd_flag & LPFC_PRLI_NVME_REQ)
2147 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2150 if ((vport->port_type == LPFC_NPIV_PORT) &&
2151 vport->cfg_restrict_login) {
2155 /* Adjust the nlp_type accordingly if the PRLI failed */
2157 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2159 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2161 /* We can't set the DSM state till BOTH PRLIs complete */
2165 if (npr && npr->prliType == PRLI_FCP_TYPE) {
2166 lpfc_printf_vlog(vport, KERN_INFO,
2167 LOG_ELS | LOG_NODE | LOG_DISCOVERY,
2168 "6028 FCP NPR PRLI Cmpl Init %d Target %d "
2169 "EIP %d AccCode x%x\n",
2170 npr->initiatorFunc, npr->targetFunc,
2171 npr->estabImagePair, npr->acceptRspCode);
2173 if (npr->acceptRspCode == PRLI_INV_SRV_PARM) {
2174 /* Strict initiators don't establish an image pair. */
2175 if (npr->initiatorFunc && !npr->targetFunc &&
2176 !npr->estabImagePair)
2177 acc_imode_sps = true;
2180 if (npr->acceptRspCode == PRLI_REQ_EXECUTED || acc_imode_sps) {
2181 if (npr->initiatorFunc)
2182 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2183 if (npr->targetFunc) {
2184 ndlp->nlp_type |= NLP_FCP_TARGET;
2185 if (npr->writeXferRdyDis)
2186 set_bit(NLP_FIRSTBURST,
2190 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2193 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2194 PRLI_REQ_EXECUTED) &&
2195 (bf_get_be32(prli_type_code, nvpr) ==
2198 /* Complete setting up the remote ndlp personality. */
2199 if (bf_get_be32(prli_init, nvpr))
2200 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2202 if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2203 bf_get_be32(prli_conf, nvpr))
2205 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2207 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2209 /* Target driver cannot solicit NVME FB. */
2210 if (bf_get_be32(prli_tgt, nvpr)) {
2211 /* Complete the nvme target roles. The transport
2212 * needs to know if the rport is capable of
2213 * discovery in addition to its role.
2215 ndlp->nlp_type |= NLP_NVME_TARGET;
2216 if (bf_get_be32(prli_disc, nvpr))
2217 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2220 * If prli_fba is set, the Target supports FirstBurst.
2221 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2222 * otherwise it defines the actual size supported by
2225 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2226 (phba->cfg_nvme_enable_fb) &&
2227 (!phba->nvmet_support)) {
2228 /* Both sides support FB. The target's first
2229 * burst size is a 512 byte encoded value.
2231 set_bit(NLP_FIRSTBURST, &ndlp->nlp_flag);
2232 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2235 /* Expressed in units of 512 bytes */
2236 if (ndlp->nvme_fb_size)
2237 ndlp->nvme_fb_size <<=
2240 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2244 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2245 "6029 NVME PRLI Cmpl w1 x%08x "
2246 "w4 x%08x w5 x%08x flag x%lx, "
2247 "fcp_info x%x nlp_type x%x\n",
2248 be32_to_cpu(nvpr->word1),
2249 be32_to_cpu(nvpr->word4),
2250 be32_to_cpu(nvpr->word5),
2251 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2254 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2255 (vport->port_type == LPFC_NPIV_PORT) &&
2256 vport->cfg_restrict_login) {
2258 set_bit(NLP_TARGET_REMOVE, &ndlp->nlp_flag);
2259 lpfc_issue_els_logo(vport, ndlp, 0);
2261 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2262 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2263 return ndlp->nlp_state;
2267 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2270 if (ndlp->fc4_prli_sent == 0) {
2271 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2272 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2273 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2274 else if (ndlp->nlp_type &
2275 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2278 lpfc_printf_vlog(vport,
2280 "3067 PRLI's still outstanding "
2281 "on x%06x - count %d, Pend Node Mode "
2283 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2285 return ndlp->nlp_state;
2288 /*! lpfc_device_rm_prli_issue
2299 * This routine is envoked when we a request to remove a nport we are in the
2300 * process of PRLIing. We should software abort outstanding prli, unreg
2301 * login, send a logout. We will change node state to UNUSED_NODE, put it
2302 * on plogi list so it can be freed when LOGO completes.
2307 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2308 void *arg, uint32_t evt)
2310 if (test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
2311 set_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2312 return ndlp->nlp_state;
2314 /* software abort outstanding PLOGI */
2315 lpfc_els_abort(vport->phba, ndlp);
2317 lpfc_drop_node(vport, ndlp);
2318 return NLP_STE_FREED_NODE;
2322 /*! lpfc_device_recov_prli_issue
2333 * The routine is envoked when the state of a device is unknown, like
2334 * during a link down. We should remove the nodelist entry from the
2335 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2336 * outstanding PRLI command, then free the node entry.
2339 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2340 struct lpfc_nodelist *ndlp,
2344 struct lpfc_hba *phba = vport->phba;
2346 /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */
2347 if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag))
2348 return ndlp->nlp_state;
2350 /* software abort outstanding PRLI */
2351 lpfc_els_abort(phba, ndlp);
2353 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2354 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2355 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2356 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2357 lpfc_disc_set_adisc(vport, ndlp);
2358 return ndlp->nlp_state;
2362 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2363 void *arg, uint32_t evt)
2365 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2368 memset(&stat, 0, sizeof(struct ls_rjt));
2369 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2370 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2371 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2372 return ndlp->nlp_state;
2376 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2377 void *arg, uint32_t evt)
2379 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2382 memset(&stat, 0, sizeof(struct ls_rjt));
2383 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2384 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2385 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2386 return ndlp->nlp_state;
2390 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2391 void *arg, uint32_t evt)
2393 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2395 set_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
2396 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2397 return ndlp->nlp_state;
2401 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2402 void *arg, uint32_t evt)
2404 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2407 memset(&stat, 0, sizeof(struct ls_rjt));
2408 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2409 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2410 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2411 return ndlp->nlp_state;
2415 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2416 void *arg, uint32_t evt)
2418 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2421 memset(&stat, 0, sizeof(struct ls_rjt));
2422 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2423 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2424 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2425 return ndlp->nlp_state;
2429 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2430 void *arg, uint32_t evt)
2432 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2433 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2434 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2435 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2436 lpfc_disc_set_adisc(vport, ndlp);
2437 return ndlp->nlp_state;
2441 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2442 void *arg, uint32_t evt)
2445 * DevLoss has timed out and is calling for Device Remove.
2446 * In this case, abort the LOGO and cleanup the ndlp
2449 lpfc_unreg_rpi(vport, ndlp);
2450 /* software abort outstanding PLOGI */
2451 lpfc_els_abort(vport->phba, ndlp);
2452 lpfc_drop_node(vport, ndlp);
2453 return NLP_STE_FREED_NODE;
2457 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2458 struct lpfc_nodelist *ndlp,
2459 void *arg, uint32_t evt)
2462 * Device Recovery events have no meaning for a node with a LOGO
2463 * outstanding. The LOGO has to complete first and handle the
2464 * node from that point.
2466 return ndlp->nlp_state;
2470 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2471 void *arg, uint32_t evt)
2473 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2475 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2476 return ndlp->nlp_state;
2480 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2481 void *arg, uint32_t evt)
2483 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2485 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2486 return ndlp->nlp_state;
2488 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2489 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2490 return ndlp->nlp_state;
2494 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2495 void *arg, uint32_t evt)
2497 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2499 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2500 return ndlp->nlp_state;
2504 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2505 void *arg, uint32_t evt)
2507 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2509 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2510 return ndlp->nlp_state;
2514 lpfc_rcv_prlo_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_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2520 return ndlp->nlp_state;
2524 lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
2525 struct lpfc_nodelist *ndlp,
2529 lpfc_drop_node(vport, ndlp);
2530 return NLP_STE_FREED_NODE;
2534 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2535 struct lpfc_nodelist *ndlp,
2539 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2540 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2541 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2542 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2543 spin_lock_irq(&ndlp->lock);
2544 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2545 spin_unlock_irq(&ndlp->lock);
2546 lpfc_disc_set_adisc(vport, ndlp);
2548 return ndlp->nlp_state;
2552 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2553 void *arg, uint32_t evt)
2555 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2557 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2558 return ndlp->nlp_state;
2562 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2563 void *arg, uint32_t evt)
2565 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2567 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2568 return ndlp->nlp_state;
2569 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2570 return ndlp->nlp_state;
2574 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2575 void *arg, uint32_t evt)
2577 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2579 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2580 return ndlp->nlp_state;
2584 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2585 struct lpfc_nodelist *ndlp,
2586 void *arg, uint32_t evt)
2588 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2590 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2591 return ndlp->nlp_state;
2595 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2596 void *arg, uint32_t evt)
2598 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2600 /* flush the target */
2601 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2604 set_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
2605 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2607 /* Save ELS_CMD_PRLO as the last elscmd and then set to NPR.
2608 * lpfc_cmpl_els_logo_acc is expected to restart discovery.
2610 ndlp->nlp_last_elscmd = ELS_CMD_PRLO;
2611 ndlp->nlp_prev_state = ndlp->nlp_state;
2613 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_ELS | LOG_DISCOVERY,
2614 "3422 DID x%06x nflag x%lx lastels x%x ref cnt %u\n",
2615 ndlp->nlp_DID, ndlp->nlp_flag,
2616 ndlp->nlp_last_elscmd,
2617 kref_read(&ndlp->kref));
2619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2621 return ndlp->nlp_state;
2625 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2626 struct lpfc_nodelist *ndlp,
2630 lpfc_disc_set_adisc(vport, ndlp);
2632 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2634 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2635 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2636 spin_lock_irq(&ndlp->lock);
2637 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2638 spin_unlock_irq(&ndlp->lock);
2639 return ndlp->nlp_state;
2643 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2644 void *arg, uint32_t evt)
2646 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2648 /* Ignore PLOGI if we have an outstanding LOGO */
2649 if (test_bit(NLP_LOGO_SND, &ndlp->nlp_flag) ||
2650 test_bit(NLP_LOGO_ACC, &ndlp->nlp_flag))
2651 return ndlp->nlp_state;
2652 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2653 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2654 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
2655 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2656 } else if (!test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
2657 /* send PLOGI immediately, move to PLOGI issue state */
2658 if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) {
2659 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2661 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2664 return ndlp->nlp_state;
2668 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2669 void *arg, uint32_t evt)
2671 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2674 memset(&stat, 0, sizeof (struct ls_rjt));
2675 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2676 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2677 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2679 if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) {
2681 * ADISC nodes will be handled in regular discovery path after
2682 * receiving response from NS.
2684 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2686 if (!test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) {
2687 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2689 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2692 return ndlp->nlp_state;
2696 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2697 void *arg, uint32_t evt)
2699 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2701 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2702 return ndlp->nlp_state;
2706 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2707 void *arg, uint32_t evt)
2709 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2711 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2713 * Do not start discovery if discovery is about to start
2714 * or discovery in progress for this node. Starting discovery
2715 * here will affect the counting of discovery threads.
2717 if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) &&
2718 !test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
2720 * ADISC nodes will be handled in regular discovery path after
2721 * receiving response from NS.
2723 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2725 if (!test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) {
2726 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2728 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2731 return ndlp->nlp_state;
2735 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2736 void *arg, uint32_t evt)
2738 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2740 set_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
2742 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2744 if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) {
2745 mod_timer(&ndlp->nlp_delayfunc,
2746 jiffies + msecs_to_jiffies(1000 * 1));
2747 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
2748 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
2749 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2751 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
2753 return ndlp->nlp_state;
2757 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2758 void *arg, uint32_t evt)
2760 struct lpfc_hba *phba = vport->phba;
2761 struct lpfc_iocbq *cmdiocb, *rspiocb;
2764 cmdiocb = (struct lpfc_iocbq *) arg;
2765 rspiocb = cmdiocb->rsp_iocb;
2767 ulp_status = get_job_ulpstatus(phba, rspiocb);
2770 return NLP_STE_FREED_NODE;
2772 return ndlp->nlp_state;
2776 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2777 void *arg, uint32_t evt)
2779 struct lpfc_hba *phba = vport->phba;
2780 struct lpfc_iocbq *cmdiocb, *rspiocb;
2783 cmdiocb = (struct lpfc_iocbq *) arg;
2784 rspiocb = cmdiocb->rsp_iocb;
2786 ulp_status = get_job_ulpstatus(phba, rspiocb);
2788 if (ulp_status && test_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag)) {
2789 lpfc_drop_node(vport, ndlp);
2790 return NLP_STE_FREED_NODE;
2792 return ndlp->nlp_state;
2796 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2797 void *arg, uint32_t evt)
2799 /* For the fabric port just clear the fc flags. */
2800 if (ndlp->nlp_DID == Fabric_DID) {
2801 clear_bit(FC_FABRIC, &vport->fc_flag);
2802 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
2804 lpfc_unreg_rpi(vport, ndlp);
2805 return ndlp->nlp_state;
2809 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2810 void *arg, uint32_t evt)
2812 struct lpfc_hba *phba = vport->phba;
2813 struct lpfc_iocbq *cmdiocb, *rspiocb;
2816 cmdiocb = (struct lpfc_iocbq *) arg;
2817 rspiocb = cmdiocb->rsp_iocb;
2819 ulp_status = get_job_ulpstatus(phba, rspiocb);
2821 if (ulp_status && test_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag)) {
2822 lpfc_drop_node(vport, ndlp);
2823 return NLP_STE_FREED_NODE;
2825 return ndlp->nlp_state;
2829 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2830 struct lpfc_nodelist *ndlp,
2831 void *arg, uint32_t evt)
2833 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2834 MAILBOX_t *mb = &pmb->u.mb;
2836 if (!mb->mbxStatus) {
2837 /* SLI4 ports have preallocated logical rpis. */
2838 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2839 ndlp->nlp_rpi = mb->un.varWords[0];
2840 set_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag);
2841 if (test_bit(NLP_LOGO_ACC, &ndlp->nlp_flag))
2842 lpfc_unreg_rpi(vport, ndlp);
2844 if (test_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag)) {
2845 lpfc_drop_node(vport, ndlp);
2846 return NLP_STE_FREED_NODE;
2849 return ndlp->nlp_state;
2853 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2854 void *arg, uint32_t evt)
2856 if (test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
2857 set_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2858 return ndlp->nlp_state;
2860 lpfc_drop_node(vport, ndlp);
2861 return NLP_STE_FREED_NODE;
2865 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2866 void *arg, uint32_t evt)
2868 /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */
2869 if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag))
2870 return ndlp->nlp_state;
2872 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2873 clear_bit(NLP_NODEV_REMOVE, &ndlp->nlp_flag);
2874 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2875 spin_lock_irq(&ndlp->lock);
2876 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2877 spin_unlock_irq(&ndlp->lock);
2878 return ndlp->nlp_state;
2882 /* This next section defines the NPort Discovery State Machine */
2884 /* There are 4 different double linked lists nodelist entries can reside on.
2885 * The plogi list and adisc list are used when Link Up discovery or RSCN
2886 * processing is needed. Each list holds the nodes that we will send PLOGI
2887 * or ADISC on. These lists will keep track of what nodes will be effected
2888 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2889 * The unmapped_list will contain all nodes that we have successfully logged
2890 * into at the Fibre Channel level. The mapped_list will contain all nodes
2891 * that are mapped FCP targets.
2894 * The bind list is a list of undiscovered (potentially non-existent) nodes
2895 * that we have saved binding information on. This information is used when
2896 * nodes transition from the unmapped to the mapped list.
2898 /* For UNUSED_NODE state, the node has just been allocated .
2899 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2900 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2901 * and put on the unmapped list. For ADISC processing, the node is taken off
2902 * the ADISC list and placed on either the mapped or unmapped list (depending
2903 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2904 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2905 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2906 * node, the node is taken off the unmapped list. The binding list is checked
2907 * for a valid binding, or a binding is automatically assigned. If binding
2908 * assignment is unsuccessful, the node is left on the unmapped list. If
2909 * binding assignment is successful, the associated binding list entry (if
2910 * any) is removed, and the node is placed on the mapped list.
2913 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2914 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2915 * expire, all effected nodes will receive a DEVICE_RM event.
2918 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2919 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2920 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2921 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2922 * we will first process the ADISC list. 32 entries are processed initially and
2923 * ADISC is initited for each one. Completions / Events for each node are
2924 * funnelled thru the state machine. As each node finishes ADISC processing, it
2925 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2926 * waiting, and the ADISC list count is identically 0, then we are done. For
2927 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2928 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2929 * list. 32 entries are processed initially and PLOGI is initited for each one.
2930 * Completions / Events for each node are funnelled thru the state machine. As
2931 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2932 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2933 * indentically 0, then we are done. We have now completed discovery / RSCN
2934 * handling. Upon completion, ALL nodes should be on either the mapped or
2938 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2939 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2940 /* Action routine Event Current State */
2941 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2942 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2943 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2944 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2945 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2946 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2947 lpfc_disc_illegal, /* CMPL_PLOGI */
2948 lpfc_disc_illegal, /* CMPL_PRLI */
2949 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2950 lpfc_disc_illegal, /* CMPL_ADISC */
2951 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2952 lpfc_device_rm_unused_node, /* DEVICE_RM */
2953 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2955 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2956 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2957 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2958 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2959 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2960 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2961 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2962 lpfc_disc_illegal, /* CMPL_PRLI */
2963 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2964 lpfc_disc_illegal, /* CMPL_ADISC */
2965 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2966 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2967 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2969 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2970 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2971 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2972 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2973 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2974 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2975 lpfc_disc_illegal, /* CMPL_PLOGI */
2976 lpfc_disc_illegal, /* CMPL_PRLI */
2977 lpfc_disc_illegal, /* CMPL_LOGO */
2978 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2979 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2980 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2981 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2983 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2984 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2985 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2986 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2987 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2988 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2989 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2990 lpfc_disc_illegal, /* CMPL_PRLI */
2991 lpfc_disc_illegal, /* CMPL_LOGO */
2992 lpfc_disc_illegal, /* CMPL_ADISC */
2993 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2994 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2995 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2997 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2998 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2999 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
3000 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
3001 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
3002 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
3003 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3004 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
3005 lpfc_disc_illegal, /* CMPL_LOGO */
3006 lpfc_disc_illegal, /* CMPL_ADISC */
3007 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3008 lpfc_device_rm_prli_issue, /* DEVICE_RM */
3009 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
3011 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
3012 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
3013 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
3014 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
3015 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
3016 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
3017 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
3018 lpfc_disc_illegal, /* CMPL_PRLI */
3019 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
3020 lpfc_disc_illegal, /* CMPL_ADISC */
3021 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3022 lpfc_device_rm_logo_issue, /* DEVICE_RM */
3023 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
3025 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
3026 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
3027 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
3028 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
3029 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
3030 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
3031 lpfc_disc_illegal, /* CMPL_PLOGI */
3032 lpfc_disc_illegal, /* CMPL_PRLI */
3033 lpfc_disc_illegal, /* CMPL_LOGO */
3034 lpfc_disc_illegal, /* CMPL_ADISC */
3035 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
3036 lpfc_device_rm_unmap_node, /* DEVICE_RM */
3037 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
3039 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
3040 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
3041 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
3042 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
3043 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
3044 lpfc_rcv_prlo_mapped_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_disc_illegal, /* DEVICE_RM */
3051 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
3053 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
3054 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
3055 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
3056 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
3057 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
3058 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
3059 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
3060 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
3061 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
3062 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
3063 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
3064 lpfc_device_rm_npr_node, /* DEVICE_RM */
3065 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
3069 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3070 void *arg, uint32_t evt)
3072 uint32_t cur_state, rc;
3073 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3075 uint32_t got_ndlp = 0;
3078 if (lpfc_nlp_get(ndlp))
3081 cur_state = ndlp->nlp_state;
3083 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3084 ((uint32_t)ndlp->nlp_type));
3085 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3086 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3087 "0211 DSM in event x%x on NPort x%x in "
3088 "state %d rpi x%x Data: x%lx x%x\n",
3089 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3090 ndlp->nlp_flag, data1);
3092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3093 "DSM in: evt:%d ste:%d did:x%x",
3094 evt, cur_state, ndlp->nlp_DID);
3096 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3097 rc = (func) (vport, ndlp, arg, evt);
3099 /* DSM out state <rc> on NPort <nlp_DID> */
3101 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3102 ((uint32_t)ndlp->nlp_type));
3103 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3104 "0212 DSM out state %d on NPort x%x "
3105 "rpi x%x Data: x%lx x%x\n",
3106 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3110 "DSM out: ste:%d did:x%x flg:x%lx",
3111 rc, ndlp->nlp_DID, ndlp->nlp_flag);
3112 /* Decrement the ndlp reference count held for this function */
3115 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3116 "0213 DSM out state %d on NPort free\n", rc);
3118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3119 "DSM out: ste:%d did:x%x flg:x%x",