From: Nigel Kirkland <nkirkland2304@gmail.com>
To: linux-scsi@vger.kernel.org, nigel.kirkland@broadcom.com
Cc: paul.ely@broadcom.com, nkirkland2304@gmail.com
Subject: [PATCH v4 08/14] lpfc: Improve PLOGI retry handling for large SAN configurations
Date: Thu, 17 Sep 2026 15:20:09 -0700 [thread overview]
Message-ID: <20260917222015.61053-9-nkirkland2304@gmail.com> (raw)
In-Reply-To: <20260917222015.61053-1-nkirkland2304@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: Nigel Kirkland <nkirkland2304@gmail.com>
---
drivers/scsi/lpfc/lpfc_els.c | 92 ++++++++++++++++++++++++++++--
drivers/scsi/lpfc/lpfc_nportdisc.c | 72 ++++++++++++++++++++++-
drivers/scsi/lpfc/lpfc_sli.c | 41 +++++++++++--
3 files changed, 191 insertions(+), 14 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index cd431c7bd9f0..3e26654a8286 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));
@@ -2410,11 +2438,26 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
if (ret) {
+ lpfc_vlog_msg(vport, KERN_NOTICE,
+ LOG_ELS | LOG_DISCOVERY | LOG_NODE,
+ "0157 PLOGI WQE Put returned %d\n",
+ ret);
+
+ /* Under heavy vpi counts, the driver's host_index can catch up
+ * to the hba_index causing a put error. Catch this case and
+ * put the IO on phba->txq.
+ */
+ if (ret == IOCB_FAILED_PUT && phba->sli_rev == LPFC_SLI_REV4) {
+ lpfc_sli4_queue_io_for_retry(phba, elsiocb, false);
+ return 0;
+ }
+
lpfc_els_free_iocb(phba, elsiocb);
lpfc_nlp_put(ndlp);
return 1;
}
+ set_bit(NLP_PLOGI_SND, &ndlp->nlp_flag);
return 0;
}
@@ -2735,7 +2778,21 @@ lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
}
rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
- if (rc == IOCB_ERROR) {
+ if (rc) {
+ lpfc_vlog_msg(vport, KERN_NOTICE,
+ LOG_ELS | LOG_DISCOVERY | LOG_NODE,
+ "0155 PRLI WQE Put returned %d\n",
+ rc);
+
+ /* Under heavy vpi counts, the driver's host_index can catch up
+ * to the hba_index causing a put error. Catch this case and
+ * put the IO on phba->txq.
+ */
+ if (rc == IOCB_FAILED_PUT && phba->sli_rev == LPFC_SLI_REV4) {
+ lpfc_sli4_queue_io_for_retry(phba, elsiocb, false);
+ return 0;
+ }
+
lpfc_els_free_iocb(phba, elsiocb);
lpfc_nlp_put(ndlp);
return 1;
@@ -4614,6 +4671,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..b0af279480fb 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) ||
@@ -1651,9 +1709,14 @@ lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
}
return ndlp->nlp_state;
}
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
+
+ /* lpfc_issue_els_plogi rejects a request if the ndlp state
+ * has advanced beyond PLOGI_ISSUE. Since the ADISC was aborted
+ * and the lpfc_rcv_plogi failed, ensure the PLOGI is sent.
+ */
+ ndlp->nlp_prev_state = ndlp->nlp_state;
lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
+ lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
return ndlp->nlp_state;
}
@@ -2675,7 +2738,10 @@ lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
} else if (!test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
- /* send PLOGI immediately, move to PLOGI issue state */
+ /* Provided a delay timer isn't running, send a PLOGI.
+ * Otherwise the nlp_delay_func will expire and send
+ * a PLOGI to the remote node.
+ */
if (!test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) {
ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index b370a64e6b67..dab5411f876d 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -2915,7 +2915,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);
}
@@ -2966,6 +2978,7 @@ lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
struct lpfc_vport *vport = pmb->vport;
struct lpfc_nodelist *ndlp;
bool unreg_inp;
+ int rc = 0;
ndlp = pmb->ctx_ndlp;
if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
@@ -3003,15 +3016,31 @@ lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
LOG_MBOX | LOG_SLI | LOG_NODE,
"4111 UNREG cmpl deferred "
"clr x%x on "
- "NPort x%x Data: x%x x%px\n",
+ "NPort x%x Data: x%x x%x x%px\n",
ndlp->nlp_rpi, ndlp->nlp_DID,
- ndlp->nlp_defer_did, ndlp);
+ ndlp->nlp_defer_did,
+ ndlp->nlp_last_elscmd,
+ ndlp);
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)
+ 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-09-17 21:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 22:20 [PATCH v4 00/14] Update lpfc to revision 15.0.0.1 Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 01/14] lpfc: Fix use-after-free in lpfc_cmpl_ct_cmd_vmid Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 02/14] lpfc: Early return out of lpfc_els_abort when HBA_SETUP flag is not set Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 03/14] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 04/14] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 05/14] lpfc: Add handling for when PLOGI or PRLI is dropped during link failure Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 06/14] lpfc: Fix ndlp use-after-free during repeated RSCN and rediscovery sequence Nigel Kirkland
2026-09-17 22:10 ` sashiko-bot
2026-09-17 22:20 ` [PATCH v4 07/14] lpfc: Rework I/O flush ordering when unloading driver Nigel Kirkland
2026-09-17 22:20 ` Nigel Kirkland [this message]
2026-09-17 22:12 ` [PATCH v4 08/14] lpfc: Improve PLOGI retry handling for large SAN configurations sashiko-bot
2026-09-17 22:20 ` [PATCH v4 09/14] lpfc: Send inhibited ABORT_WQE when PLOGI CQE SEQUENCE_TMO is received Nigel Kirkland
2026-09-17 22:15 ` sashiko-bot
2026-09-17 22:20 ` [PATCH v4 10/14] lpfc: Remove slowpath cqe process limiter in slow ring event handler Nigel Kirkland
2026-09-17 22:20 ` sashiko-bot
2026-09-17 22:20 ` [PATCH v4 11/14] lpfc: Put iocbq on phba->txq when ELS WQ is full or ELS SGL unavailable Nigel Kirkland
2026-09-17 22:20 ` sashiko-bot
2026-09-17 22:20 ` [PATCH v4 12/14] lpfc: Update ELS ACC logging for diagnostic troubleshooting Nigel Kirkland
2026-09-17 22:22 ` sashiko-bot
2026-09-17 22:20 ` [PATCH v4 13/14] lpfc: Refactor calls on fc_disctmo to lpfc_set_disctmo in RSCN handler Nigel Kirkland
2026-09-17 22:20 ` [PATCH v4 14/14] lpfc: Update lpfc version to 15.0.0.1 Nigel Kirkland
2026-09-19 7:45 ` [PATCH v4 00/14] Update lpfc to revision 15.0.0.1 Nigel Kirkland
2026-09-28 17:13 ` Nigel Kirkland
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=20260917222015.61053-9-nkirkland2304@gmail.com \
--to=nkirkland2304@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=nigel.kirkland@broadcom.com \
--cc=paul.ely@broadcom.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox