From: Justin Tee <justintee8345@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: jsmart833426@gmail.com, justin.tee@broadcom.com,
Justin Tee <justintee8345@gmail.com>
Subject: [PATCH v3 08/14] lpfc: Improve PLOGI retry handling for large SAN configurations
Date: Mon, 13 Jul 2026 18:18:06 -0700 [thread overview]
Message-ID: <20260714011812.106753-9-justintee8345@gmail.com> (raw)
In-Reply-To: <20260714011812.106753-1-justintee8345@gmail.com>
In large SAN configurations with link perturbations, rediscovery of target
ports is problematic due to PLOGI retry race conditions.
This patch improves target rediscovery by ensuring PLOGI retries are
serialized in unregistration and retry handler paths.
Signed-off-by: Justin Tee <justintee8345@gmail.com>
---
drivers/scsi/lpfc/lpfc_els.c | 62 +++++++++++++++++++--
drivers/scsi/lpfc/lpfc_nportdisc.c | 58 ++++++++++++++++++++
drivers/scsi/lpfc/lpfc_sli.c | 87 +++++++++++++++++-------------
3 files changed, 167 insertions(+), 40 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 6720fd5ec523..16b10377a095 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -2159,6 +2159,8 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
goto out_freeiocb;
}
+ clear_bit(NLP_PLOGI_SND, &ndlp->nlp_flag);
+
/* Since ndlp can be freed in the disc state machine, note if this node
* is being used during discovery.
*/
@@ -2329,17 +2331,43 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
test_bit(NLP_UNREG_INP, &ndlp->nlp_flag)) &&
((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
!test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_ELS | LOG_NODE | LOG_DISCOVERY,
"4110 Issue PLOGI x%x deferred "
"on NPort x%x rpi x%x flg x%lx Data:"
" x%px\n",
ndlp->nlp_defer_did, ndlp->nlp_DID,
ndlp->nlp_rpi, ndlp->nlp_flag, ndlp);
- /* We can only defer 1st PLOGI */
- if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
+ /* Don't defer a PLOGI that is already in that condition.
+ * Also set the nlp_last_elscmd to PLOGI to get the retry.
+ */
+ if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) {
ndlp->nlp_defer_did = did;
- return 0;
+ ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
+ }
+ return 1;
+ }
+
+ if (test_bit(NLP_PLOGI_SND, &ndlp->nlp_flag)) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_ELS | LOG_NODE | LOG_DISCOVERY,
+ "4113 Reject PLOGI issue, PLOGI in-flight "
+ "x%px, DID x%x nflag x%lx\n",
+ ndlp, ndlp->nlp_DID, ndlp->nlp_flag);
+ return 1;
+ }
+
+ if (ndlp->nlp_state > NLP_STE_PLOGI_ISSUE &&
+ ndlp->nlp_state <= NLP_STE_MAPPED_NODE) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_ELS | LOG_NODE | LOG_DISCOVERY,
+ "4114 Reject PLOGI issue, Node in "
+ "unexpected state x%px, DID x%x nflag x%lx "
+ "in State x%x\n",
+ ndlp, ndlp->nlp_DID,
+ ndlp->nlp_flag, ndlp->nlp_state);
+ return 1;
}
cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
@@ -2415,6 +2443,7 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
return 1;
}
+ set_bit(NLP_PLOGI_SND, &ndlp->nlp_flag);
return 0;
}
@@ -4614,6 +4643,31 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
lpfc_issue_els_flogi(vport, ndlp, retry);
break;
case ELS_CMD_PLOGI:
+ /* The driver delayed a PLOGI via the nlp_delayfunc, but
+ * it's possible the PLOGI is already on a deferred retry.
+ * Catch this case and skip this delayed PLOGI. This prevents
+ * multiple PLOGIs in flight. The defer code flow cleans
+ * up.
+ */
+ if ((test_bit(NLP_IGNR_REG_CMPL, &ndlp->nlp_flag) ||
+ test_bit(NLP_UNREG_INP, &ndlp->nlp_flag)) &&
+ ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING &&
+ ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
+ !test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
+ /* When UNREG_RPI completes we need to have the
+ * nlp_last_elscmd set.
+ */
+ ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_ELS | LOG_NODE | LOG_DISCOVERY,
+ "4112 Skip delayed PLOGI x%x deferred "
+ "on NPort x%x rpi x%x flg x%lx Data:"
+ " x%px\n",
+ ndlp->nlp_defer_did, ndlp->nlp_DID,
+ ndlp->nlp_rpi, ndlp->nlp_flag, ndlp);
+ break;
+ }
+
if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
ndlp->nlp_prev_state = ndlp->nlp_state;
lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index f917a5bcfd02..0270ab7e602f 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -920,6 +920,64 @@ lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
ndlp->nlp_DID, ndlp->nlp_state,
ndlp->nlp_type, vport->fc_flag);
+ /* The driver wants to schedule a delayed PLOGI to recover
+ * the remote Nport. However, there are two cases that
+ * stop this so that multiple PLOGI are not inflight to
+ * the same NPortID
+ *
+ * Do not schedule a delayed PLOGI if the deferred PLOGI
+ * code already set up a PLOGI retry after an UNREG_RPI
+ * mailbox completes.
+ */
+ if (test_bit(NLP_UNREG_INP, &ndlp->nlp_flag) &&
+ ndlp->nlp_defer_did == ndlp->nlp_DID &&
+ ndlp->nlp_last_elscmd == ELS_CMD_PLOGI) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_NODE | LOG_ELS | LOG_DISCOVERY,
+ "3206 No PLOGI delay, defer PLOGI "
+ "waiting on DID x%06x UNREG_RPI "
+ "nflag x%lx state x%x lastels x%x "
+ "defer_did x%x\n",
+ ndlp->nlp_DID, ndlp->nlp_flag,
+ ndlp->nlp_state, ndlp->nlp_last_elscmd,
+ ndlp->nlp_defer_did);
+ goto out;
+ }
+
+ /* A delayed PLOGI retry is not required if the ndlp's delay
+ * timer is running and the last command was PLOGI.
+ */
+ if (test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) &&
+ ndlp->nlp_last_elscmd == ELS_CMD_PLOGI) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_NODE | LOG_ELS | LOG_DISCOVERY,
+ "3207 No PLOGI delay, PLOGI_DELAY_TMO "
+ "active on DID x%06x "
+ "nflag x%lx state x%x lastels x%x "
+ "defer_did x%x\n",
+ ndlp->nlp_DID, ndlp->nlp_flag,
+ ndlp->nlp_state, ndlp->nlp_last_elscmd,
+ ndlp->nlp_defer_did);
+ goto out;
+ }
+
+ /* Do not schedule a PLOGI retry if the ndlp state is NPR
+ * and vport has received an RSCN
+ */
+ if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
+ test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_NODE | LOG_ELS | LOG_DISCOVERY,
+ "3939 No PLOGI delay, RSCN in "
+ "progress for NPR DID x%06x "
+ "nflag x%lx state x%x last_els x%x "
+ "defer_did x%06x\n",
+ ndlp->nlp_DID, ndlp->nlp_flag,
+ ndlp->nlp_state, ndlp->nlp_last_elscmd,
+ ndlp->nlp_defer_did);
+ goto out;
+ }
+
/* Special cases for rports that recover post LOGO. */
if ((!(ndlp->nlp_type == NLP_FABRIC) &&
(ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) ||
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 10db07771ccf..54bc5d8984fc 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -2914,7 +2914,19 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING) {
clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
+
+ if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) &&
+ ndlp->nlp_last_elscmd == ELS_CMD_PLOGI) {
+ rc = lpfc_issue_els_plogi(vport,
+ ndlp->nlp_DID,
+ 0);
+ if (!rc) {
+ ndlp->nlp_prev_state =
+ ndlp->nlp_state;
+ lpfc_nlp_set_state(vport, ndlp,
+ NLP_STE_PLOGI_ISSUE);
+ }
+ }
} else {
clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
}
@@ -2967,52 +2979,55 @@ lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
bool unreg_inp;
ndlp = pmb->ctx_ndlp;
- if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
+ if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN && ndlp) {
if (phba->sli_rev == LPFC_SLI_REV4 &&
(bf_get(lpfc_sli_intf_if_type,
&phba->sli4_hba.sli_intf) >=
LPFC_SLI_INTF_IF_TYPE_2)) {
- if (ndlp) {
- lpfc_printf_vlog(
- vport, KERN_INFO,
+ lpfc_printf_vlog(vport, KERN_INFO,
LOG_MBOX | LOG_SLI | LOG_NODE,
- "0010 UNREG_LOGIN vpi:x%x "
- "rpi:%x DID:%x defer x%x flg x%lx "
- "x%px\n",
+ "0010 UNREG_LOGIN vpi:x%x rpi:%x "
+ "DID:%x defer x%x flg x%lx x%px\n",
vport->vpi, ndlp->nlp_rpi,
ndlp->nlp_DID, ndlp->nlp_defer_did,
- ndlp->nlp_flag,
- ndlp);
+ ndlp->nlp_flag, ndlp);
- /* Cleanup the nlp_flag now that the UNREG RPI
- * has completed.
- */
- unreg_inp = test_and_clear_bit(NLP_UNREG_INP,
- &ndlp->nlp_flag);
- clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
+ /* Cleanup the nlp_flag now that the UNREG RPI
+ * has completed.
+ */
+ unreg_inp = test_and_clear_bit(NLP_UNREG_INP,
+ &ndlp->nlp_flag);
+ clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
- /* Check to see if there are any deferred
- * events to process
- */
- if (unreg_inp &&
- ndlp->nlp_defer_did !=
- NLP_EVT_NOTHING_PENDING) {
- lpfc_printf_vlog(
- vport, KERN_INFO,
- LOG_MBOX | LOG_SLI | LOG_NODE,
- "4111 UNREG cmpl deferred "
- "clr x%x on "
- "NPort x%x Data: x%x x%px\n",
- ndlp->nlp_rpi, ndlp->nlp_DID,
- ndlp->nlp_defer_did, ndlp);
- ndlp->nlp_defer_did =
- NLP_EVT_NOTHING_PENDING;
- lpfc_issue_els_plogi(
- vport, ndlp->nlp_DID, 0);
- }
+ /* Check to see if there are any deferred
+ * events to process
+ */
+ if (unreg_inp &&
+ ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING) {
+ lpfc_printf_vlog(vport, KERN_INFO,
+ LOG_MBOX | LOG_SLI | LOG_NODE,
+ "4111 UNREG cmpl deferred "
+ "clr x%x on NPort x%x "
+ "Data: x%x x%x x%px\n",
+ ndlp->nlp_rpi, ndlp->nlp_DID,
+ ndlp->nlp_defer_did,
+ ndlp->nlp_last_elscmd, ndlp);
+ ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
- lpfc_nlp_put(ndlp);
+ if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) &&
+ ndlp->nlp_last_elscmd == ELS_CMD_PLOGI) {
+ if (lpfc_issue_els_plogi(vport,
+ ndlp->nlp_DID,
+ 0))
+ goto out;
+
+ ndlp->nlp_prev_state = ndlp->nlp_state;
+ lpfc_nlp_set_state(vport, ndlp,
+ NLP_STE_PLOGI_ISSUE);
+ }
}
+out:
+ lpfc_nlp_put(ndlp);
}
}
--
2.38.0
next prev parent reply other threads:[~2026-07-14 0:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 1:17 [PATCH v3 00/14] Update lpfc to revision 15.0.0.1 Justin Tee
2026-07-14 1:17 ` [PATCH v3 01/14] lpfc: Fix use-after-free in lpfc_cmpl_ct_cmd_vmid Justin Tee
2026-07-14 0:51 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 02/14] lpfc: Early return out of lpfc_els_abort when HBA_SETUP flag is not set Justin Tee
2026-07-14 0:53 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 03/14] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd Justin Tee
2026-07-14 0:57 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 04/14] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error Justin Tee
2026-07-14 0:55 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 05/14] lpfc: Add handling for when PLOGI or PRLI is dropped during link failure Justin Tee
2026-07-14 1:02 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 06/14] lpfc: Fix ndlp use-after-free during repeated RSCN and rediscovery sequence Justin Tee
2026-07-14 0:50 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 07/14] lpfc: Rework I/O flush ordering when unloading driver Justin Tee
2026-07-14 1:00 ` sashiko-bot
2026-07-14 1:18 ` Justin Tee [this message]
2026-07-14 0:55 ` [PATCH v3 08/14] lpfc: Improve PLOGI retry handling for large SAN configurations sashiko-bot
2026-07-14 1:18 ` [PATCH v3 09/14] lpfc: Send inhibited ABORT_WQE when PLOGI CQE SEQUENCE_TMO is received Justin Tee
2026-07-14 1:05 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 10/14] lpfc: Remove slowpath cqe process limiter in slow ring event handler Justin Tee
2026-07-14 0:54 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 11/14] lpfc: Put iocbq on phba->txq when ELS WQ is full or ELS SGL unavailable Justin Tee
2026-07-14 0:50 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 12/14] lpfc: Update ELS ACC logging for diagnostic troubleshooting Justin Tee
2026-07-14 1:02 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 13/14] lpfc: Refactor calls on fc_disctmo to lpfc_set_disctmo in RSCN handler Justin Tee
2026-07-14 1:00 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 14/14] lpfc: Update lpfc version to 15.0.0.1 Justin Tee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260714011812.106753-9-justintee8345@gmail.com \
--to=justintee8345@gmail.com \
--cc=jsmart833426@gmail.com \
--cc=justin.tee@broadcom.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.