* [PATCH v6 3/6] nvme-fc: nvme_fc_fpin_rcv() callback
@ 2025-06-20 17:57 Bryan Gurney
2025-06-23 15:58 ` John Meneghini
0 siblings, 1 reply; 2+ messages in thread
From: Bryan Gurney @ 2025-06-20 17:57 UTC (permalink / raw)
To: linux-nvme, kbusch, hch, sagi, axboe
Cc: james.smart, dick.kennedy, njavali, linux-scsi, hare, bgurney,
jmeneghi
From: Hannes Reinecke <hare@kernel.org>
Add a callback nvme_fc_fpin_rcv() to evaluate the FPIN LI TLV
information and set the 'marginal' path status for all affected
rports.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
Tested-by: Bryan Gurney <bgurney@redhat.com>
---
drivers/nvme/host/fc.c | 95 ++++++++++++++++++++++++++++++++++
include/linux/nvme-fc-driver.h | 3 ++
2 files changed, 98 insertions(+)
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 7e81c815bb83..71a77917a14f 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -3724,6 +3724,101 @@ static struct nvmf_transport_ops nvme_fc_transport = {
.create_ctrl = nvme_fc_create_ctrl,
};
+static struct nvme_fc_rport *nvme_fc_rport_from_wwpn(struct nvme_fc_lport *lport,
+ u64 rport_wwpn)
+{
+ struct nvme_fc_rport *rport;
+
+ list_for_each_entry(rport, &lport->endp_list, endp_list) {
+ if (!nvme_fc_rport_get(rport))
+ continue;
+ if (rport->remoteport.port_name == rport_wwpn &&
+ rport->remoteport.port_role & FC_PORT_ROLE_NVME_TARGET)
+ return rport;
+ nvme_fc_rport_put(rport);
+ }
+ return NULL;
+}
+
+static void
+nvme_fc_fpin_li_lport_update(struct nvme_fc_lport *lport, struct fc_fn_li_desc *li)
+{
+ unsigned int i, pname_count = be32_to_cpu(li->pname_count);
+ u64 attached_wwpn = be64_to_cpu(li->attached_wwpn);
+ struct nvme_fc_rport *attached_rport;
+
+ for (i = 0; i < pname_count; i++) {
+ struct nvme_fc_rport *rport;
+ u64 wwpn = be64_to_cpu(li->pname_list[i]);
+
+ rport = nvme_fc_rport_from_wwpn(lport, wwpn);
+ if (!rport)
+ continue;
+ if (wwpn != attached_wwpn) {
+ struct nvme_fc_ctrl *ctrl;
+
+ spin_lock_irq(&rport->lock);
+ list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list)
+ set_bit(NVME_CTRL_MARGINAL, &ctrl->ctrl.flags);
+ spin_unlock_irq(&rport->lock);
+ }
+ nvme_fc_rport_put(rport);
+ }
+
+ attached_rport = nvme_fc_rport_from_wwpn(lport, attached_wwpn);
+ if (attached_rport) {
+ struct nvme_fc_ctrl *ctrl;
+
+ spin_lock_irq(&attached_rport->lock);
+ list_for_each_entry(ctrl, &attached_rport->ctrl_list, ctrl_list)
+ set_bit(NVME_CTRL_MARGINAL, &ctrl->ctrl.flags);
+ spin_unlock_irq(&attached_rport->lock);
+ nvme_fc_rport_put(attached_rport);
+ }
+}
+
+/**
+ * fc_host_fpin_rcv() - Process a received FPIN.
+ * @localport: local port the FPIN was received on
+ * @fpin_len: length of FPIN payload, in bytes
+ * @fpin_buf: pointer to FPIN payload
+ * Notes:
+ * This routine assumes no locks are held on entry.
+ */
+void
+nvme_fc_fpin_rcv(struct nvme_fc_local_port *localport,
+ u32 fpin_len, char *fpin_buf)
+{
+ struct nvme_fc_lport *lport;
+ struct fc_els_fpin *fpin = (struct fc_els_fpin *)fpin_buf;
+ union fc_tlv_desc *tlv;
+ u32 bytes_remain;
+ u32 dtag;
+
+ if (!localport)
+ return;
+ lport = localport_to_lport(localport);
+ 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:
+ nvme_fc_fpin_li_lport_update(lport, &tlv->li);
+ break;
+ default:
+ break;
+ }
+
+ bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
+ tlv = fc_tlv_next_desc(tlv);
+ }
+}
+EXPORT_SYMBOL(nvme_fc_fpin_rcv);
+
/* Arbitrary successive failures max. With lots of subsystems could be high */
#define DISCOVERY_MAX_FAIL 20
diff --git a/include/linux/nvme-fc-driver.h b/include/linux/nvme-fc-driver.h
index 9f6acadfe0c8..bcd3b1e5a256 100644
--- a/include/linux/nvme-fc-driver.h
+++ b/include/linux/nvme-fc-driver.h
@@ -536,6 +536,9 @@ void nvme_fc_rescan_remoteport(struct nvme_fc_remote_port *remoteport);
int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport,
u32 dev_loss_tmo);
+void nvme_fc_fpin_rcv(struct nvme_fc_local_port *localport,
+ u32 fpin_len, char *fpin_buf);
+
/*
* Routine called to pass a NVME-FC LS request, received by the lldd,
* to the nvme-fc transport.
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v6 3/6] nvme-fc: nvme_fc_fpin_rcv() callback
2025-06-20 17:57 [PATCH v6 3/6] nvme-fc: nvme_fc_fpin_rcv() callback Bryan Gurney
@ 2025-06-23 15:58 ` John Meneghini
0 siblings, 0 replies; 2+ messages in thread
From: John Meneghini @ 2025-06-23 15:58 UTC (permalink / raw)
To: Bryan Gurney, linux-nvme, kbusch, hch, sagi, axboe
Cc: james.smart, dick.kennedy, njavali, linux-scsi, hare
Reviewed-by: John Meneghini <jmeneghi@redhat.com>
On 6/20/25 1:57 PM, Bryan Gurney wrote:
> From: Hannes Reinecke <hare@kernel.org>
>
> Add a callback nvme_fc_fpin_rcv() to evaluate the FPIN LI TLV
> information and set the 'marginal' path status for all affected
> rports.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>
> Tested-by: Bryan Gurney <bgurney@redhat.com>
> ---
> drivers/nvme/host/fc.c | 95 ++++++++++++++++++++++++++++++++++
> include/linux/nvme-fc-driver.h | 3 ++
> 2 files changed, 98 insertions(+)
>
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 7e81c815bb83..71a77917a14f 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -3724,6 +3724,101 @@ static struct nvmf_transport_ops nvme_fc_transport = {
> .create_ctrl = nvme_fc_create_ctrl,
> };
>
> +static struct nvme_fc_rport *nvme_fc_rport_from_wwpn(struct nvme_fc_lport *lport,
> + u64 rport_wwpn)
> +{
> + struct nvme_fc_rport *rport;
> +
> + list_for_each_entry(rport, &lport->endp_list, endp_list) {
> + if (!nvme_fc_rport_get(rport))
> + continue;
> + if (rport->remoteport.port_name == rport_wwpn &&
> + rport->remoteport.port_role & FC_PORT_ROLE_NVME_TARGET)
> + return rport;
> + nvme_fc_rport_put(rport);
> + }
> + return NULL;
> +}
> +
> +static void
> +nvme_fc_fpin_li_lport_update(struct nvme_fc_lport *lport, struct fc_fn_li_desc *li)
> +{
> + unsigned int i, pname_count = be32_to_cpu(li->pname_count);
> + u64 attached_wwpn = be64_to_cpu(li->attached_wwpn);
> + struct nvme_fc_rport *attached_rport;
> +
> + for (i = 0; i < pname_count; i++) {
> + struct nvme_fc_rport *rport;
> + u64 wwpn = be64_to_cpu(li->pname_list[i]);
> +
> + rport = nvme_fc_rport_from_wwpn(lport, wwpn);
> + if (!rport)
> + continue;
> + if (wwpn != attached_wwpn) {
> + struct nvme_fc_ctrl *ctrl;
> +
> + spin_lock_irq(&rport->lock);
> + list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list)
> + set_bit(NVME_CTRL_MARGINAL, &ctrl->ctrl.flags);
> + spin_unlock_irq(&rport->lock);
> + }
> + nvme_fc_rport_put(rport);
> + }
> +
> + attached_rport = nvme_fc_rport_from_wwpn(lport, attached_wwpn);
> + if (attached_rport) {
> + struct nvme_fc_ctrl *ctrl;
> +
> + spin_lock_irq(&attached_rport->lock);
> + list_for_each_entry(ctrl, &attached_rport->ctrl_list, ctrl_list)
> + set_bit(NVME_CTRL_MARGINAL, &ctrl->ctrl.flags);
> + spin_unlock_irq(&attached_rport->lock);
> + nvme_fc_rport_put(attached_rport);
> + }
> +}
> +
> +/**
> + * fc_host_fpin_rcv() - Process a received FPIN.
> + * @localport: local port the FPIN was received on
> + * @fpin_len: length of FPIN payload, in bytes
> + * @fpin_buf: pointer to FPIN payload
> + * Notes:
> + * This routine assumes no locks are held on entry.
> + */
> +void
> +nvme_fc_fpin_rcv(struct nvme_fc_local_port *localport,
> + u32 fpin_len, char *fpin_buf)
> +{
> + struct nvme_fc_lport *lport;
> + struct fc_els_fpin *fpin = (struct fc_els_fpin *)fpin_buf;
> + union fc_tlv_desc *tlv;
> + u32 bytes_remain;
> + u32 dtag;
> +
> + if (!localport)
> + return;
> + lport = localport_to_lport(localport);
> + 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:
> + nvme_fc_fpin_li_lport_update(lport, &tlv->li);
> + break;
> + default:
> + break;
> + }
> +
> + bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
> + tlv = fc_tlv_next_desc(tlv);
> + }
> +}
> +EXPORT_SYMBOL(nvme_fc_fpin_rcv);
> +
> /* Arbitrary successive failures max. With lots of subsystems could be high */
> #define DISCOVERY_MAX_FAIL 20
>
> diff --git a/include/linux/nvme-fc-driver.h b/include/linux/nvme-fc-driver.h
> index 9f6acadfe0c8..bcd3b1e5a256 100644
> --- a/include/linux/nvme-fc-driver.h
> +++ b/include/linux/nvme-fc-driver.h
> @@ -536,6 +536,9 @@ void nvme_fc_rescan_remoteport(struct nvme_fc_remote_port *remoteport);
> int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport,
> u32 dev_loss_tmo);
>
> +void nvme_fc_fpin_rcv(struct nvme_fc_local_port *localport,
> + u32 fpin_len, char *fpin_buf);
> +
> /*
> * Routine called to pass a NVME-FC LS request, received by the lldd,
> * to the nvme-fc transport.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-23 19:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 17:57 [PATCH v6 3/6] nvme-fc: nvme_fc_fpin_rcv() callback Bryan Gurney
2025-06-23 15:58 ` John Meneghini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).