From: John Meneghini <jmeneghi@redhat.com>
To: hare@suse.de, kbusch@kernel.org, martin.petersen@oracle.com,
linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org
Cc: bgurney@redhat.com, axboe@kernel.dk, emilne@redhat.com,
gustavoars@kernel.org, hch@lst.de, james.smart@broadcom.com,
jmeneghi@redhat.com, kees@kernel.org,
linux-hardening@vger.kernel.org, njavali@marvell.com,
sagi@grimberg.me
Subject: [PATCH v10 07/11] scsi: scsi_transport_fc: add fc_host_fpin_set_nvme_rport_marginal()
Date: Thu, 25 Sep 2025 20:01:56 -0400 [thread overview]
Message-ID: <20250926000200.837025-8-jmeneghi@redhat.com> (raw)
In-Reply-To: <20250926000200.837025-1-jmeneghi@redhat.com>
Add fc_host_fpin_set_nvme_rport_marginal() function to
evaluate the FPIN LI TLV information and set the 'marginal'
path status for all affected nvme rports.
Co-developed-by: Hannes Reinecke <hare@kernel.org>
Signed-off-by: Hannes Reinecke <hare@kernel.org>
Tested-by: Bryan Gurney <bgurney@redhat.com>
Signed-off-by: John Meneghini <jmeneghi@redhat.com>
---
drivers/scsi/scsi_transport_fc.c | 81 ++++++++++++++++++++++++++++++++
include/scsi/scsi_transport_fc.h | 1 +
2 files changed, 82 insertions(+)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index f31fdc840191..4dc03cbaf3e2 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -25,6 +25,10 @@
#include <uapi/scsi/fc/fc_els.h>
#include "scsi_priv.h"
+#if (IS_ENABLED(CONFIG_NVME_FC))
+void nvme_fc_modify_rport_fpin_state(u64 local_wwpn, u64 remote_wwpn, bool marginal);
+#endif
+
static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
static void fc_vport_sched_delete(struct work_struct *work);
static int fc_vport_setup(struct Scsi_Host *shost, int channel,
@@ -873,6 +877,83 @@ fc_fpin_congn_stats_update(struct Scsi_Host *shost,
&fc_host->fpin_stats);
}
+/**
+ * fc_host_fpin_set_nvme_rport_marginal
+ * - Set FC_PORTSTATE_MARGINAL for nvme rports in FPIN
+ * @shost: host the FPIN was received on
+ * @fpin_len: length of FPIN payload, in bytes
+ * @fpin_buf: pointer to FPIN payload
+ *
+ * This function processes a received FPIN and sets FC_PORTSTATE_MARGINAL on
+ * all remote ports that have FC_PORT_ROLE_NVME_TARGET set identified in the
+ * FPIN descriptors.
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
+ */
+void
+fc_host_fpin_set_nvme_rport_marginal(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf)
+{
+ struct fc_els_fpin *fpin = (struct fc_els_fpin *)fpin_buf;
+ struct fc_rport *rport;
+ union fc_tlv_desc *tlv;
+ u64 local_wwpn = fc_host_port_name(shost);
+ u64 wwpn, attached_wwpn;
+ u32 bytes_remain;
+ u32 dtag;
+ u8 i;
+ unsigned long flags;
+
+ /* Parse FPIN descriptors */
+ tlv = &fpin->fpin_desc[0];
+ bytes_remain = fpin_len - offsetof(struct fc_els_fpin, fpin_desc);
+ bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
+
+ while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
+ bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
+ dtag = be32_to_cpu(tlv->hdr.desc_tag);
+ switch (dtag) {
+ case ELS_DTAG_LNK_INTEGRITY:
+ struct fc_fn_li_desc *li_desc = &tlv->li;
+
+ attached_wwpn = be64_to_cpu(li_desc->attached_wwpn);
+
+ /* Set marginal state for WWPNs in pname_list */
+ if (be32_to_cpu(li_desc->pname_count) > 0) {
+ for (i = 0; i < be32_to_cpu(li_desc->pname_count); i++) {
+ wwpn = be64_to_cpu(li_desc->pname_list[i]);
+ if (wwpn == attached_wwpn)
+ continue;
+
+ rport = fc_find_rport_by_wwpn(shost, wwpn);
+ if (!rport)
+ continue;
+
+ spin_lock_irqsave(shost->host_lock, flags);
+
+ if (rport->port_state == FC_PORTSTATE_ONLINE &&
+ rport->roles & FC_PORT_ROLE_NVME_TARGET) {
+ rport->port_state = FC_PORTSTATE_MARGINAL;
+ spin_unlock_irqrestore(shost->host_lock, flags);
+#if (IS_ENABLED(CONFIG_NVME_FC))
+ nvme_fc_modify_rport_fpin_state(local_wwpn,
+ wwpn, true);
+#endif
+ } else
+ spin_unlock_irqrestore(shost->host_lock, flags);
+
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
+ tlv = fc_tlv_next_desc(tlv);
+ }
+}
+EXPORT_SYMBOL(fc_host_fpin_set_nvme_rport_marginal);
+
/**
* fc_host_fpin_rcv - routine to process a received FPIN.
* @shost: host the FPIN was received on
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index b908aacfef48..e8d46b71bada 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -852,6 +852,7 @@ void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
*/
void fc_host_fpin_rcv(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf,
u8 event_acknowledge);
+void fc_host_fpin_set_nvme_rport_marginal(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf);
struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
struct fc_vport_identifiers *);
int fc_vport_terminate(struct fc_vport *vport);
--
2.51.0
next prev parent reply other threads:[~2025-09-26 0:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-26 0:01 [PATCH v10 00/11] nvme-fc: FPIN link integrity handling John Meneghini
2025-09-26 0:01 ` [PATCH v10 01/11] fc_els: use 'union fc_tlv_desc' John Meneghini
2025-09-29 17:44 ` Justin Tee
2025-09-30 10:15 ` John Meneghini
2025-09-26 0:01 ` [PATCH v10 02/11] nvme: add NVME_CTRL_MARGINAL flag John Meneghini
2025-09-26 0:01 ` [PATCH v10 03/11] nvme-fc: marginal path handling John Meneghini
2025-10-03 10:15 ` Christoph Hellwig
2025-09-26 0:01 ` [PATCH v10 04/11] nvme: sysfs: emit the marginal path state in show_state() John Meneghini
2025-09-26 0:01 ` [PATCH v10 05/11] nvme-multipath: queue-depth support for marginal paths John Meneghini
2025-09-26 0:01 ` [PATCH v10 06/11] nvme-fc: add nvme_fc_modify_rport_fpin_state() John Meneghini
2025-09-26 0:01 ` John Meneghini [this message]
2025-09-29 17:45 ` [PATCH v10 07/11] scsi: scsi_transport_fc: add fc_host_fpin_set_nvme_rport_marginal() Justin Tee
2025-09-30 10:17 ` John Meneghini
2025-09-26 0:01 ` [PATCH v10 08/11] scsi: lpfc: enable FPIN notification for NVMe John Meneghini
2025-09-26 0:01 ` [PATCH v10 09/11] scsi: qla2xxx: " John Meneghini
2025-09-26 0:01 ` [PATCH v10 10/11] scsi: scsi_transport_fc: user support for clearing NVME_CTRL_MARGINAL John Meneghini
2025-09-26 0:02 ` [PATCH v10 11/11] scsi: qla2xxx: Fix 2 memcpy field-spanning write issue John Meneghini
2025-09-26 9:00 ` Gustavo A. R. Silva
2025-09-26 9:29 ` Hannes Reinecke
2025-09-30 9:38 ` John Meneghini
2025-09-30 9:24 ` John Meneghini
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=20250926000200.837025-8-jmeneghi@redhat.com \
--to=jmeneghi@redhat.com \
--cc=axboe@kernel.dk \
--cc=bgurney@redhat.com \
--cc=emilne@redhat.com \
--cc=gustavoars@kernel.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=njavali@marvell.com \
--cc=sagi@grimberg.me \
/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