git: b2fe18e78db4 - stable/15 - ixgbe: Report SR-IOV VF status

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Sat, 31 Oct 2026 18:58:45 UTC
The branch stable/15 has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=b2fe18e78db4bcde3e3101204f4f105ca1267226

commit b2fe18e78db4bcde3e3101204f4f105ca1267226
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-08-10 22:29:37 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-10-31 18:57:04 +0000

    ixgbe: Report SR-IOV VF status
    
    Expose cached VF configuration, policy, and runtime state through the
    iflib VF status method.  Include access or trunk VLAN mode, transmit and
    receive queue counts selected by the current virtualization mode,
    negotiated mailbox API, PF traffic permission, fault containment, and
    quarantine state.
    
    Initialize every cached API version before VF enumeration so an
    unconfigured slot cannot be mistaken for API 1.0.
    
    The query does not issue mailbox requests or read hardware registers.
    
    Place the new attachment flag in existing padding on stable/15 to retain
    the softc size and all existing member offsets.
    
    Sponsored by:   BBOX.io
    
    (cherry picked from commit 049331b20657cf0e7723c071efb75fda53a655fd)
---
 sys/dev/ixgbe/if_ix.c       |   3 +-
 sys/dev/ixgbe/if_sriov.c    | 105 +++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/ixgbe/ixgbe.h       |   1 +
 sys/dev/ixgbe/ixgbe_sriov.h |   4 +-
 4 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c
index 518d4da52cb9..e5b1fdecd4f4 100644
--- a/sys/dev/ixgbe/if_ix.c
+++ b/sys/dev/ixgbe/if_ix.c
@@ -389,6 +389,7 @@ static device_method_t ixgbe_if_methods[] = {
 	DEVMETHOD(ifdi_iov_init, ixgbe_if_iov_init),
 	DEVMETHOD(ifdi_iov_uninit, ixgbe_if_iov_uninit),
 	DEVMETHOD(ifdi_iov_vf_add, ixgbe_if_iov_vf_add),
+	DEVMETHOD(ifdi_vf_status, ixgbe_if_vf_status),
 #endif /* PCI_IOV */
 	DEVMETHOD_END
 };
@@ -1379,7 +1380,7 @@ ixgbe_if_attach_post(if_ctx_t ctx)
 	sc->advertise = ixgbe_get_default_advertise(sc);
 
 	if (sc->feat_cap & IXGBE_FEATURE_SRIOV)
-		ixgbe_define_iov_schemas(dev, &error);
+		ixgbe_define_iov_schemas(sc, &error);
 
 	/* Add sysctls */
 	ixgbe_add_device_sysctls(ctx);
diff --git a/sys/dev/ixgbe/if_sriov.c b/sys/dev/ixgbe/if_sriov.c
index 13ba3cdaf132..7f2689f39459 100644
--- a/sys/dev/ixgbe/if_sriov.c
+++ b/sys/dev/ixgbe/if_sriov.c
@@ -39,6 +39,8 @@
 #include <sys/iov.h>
 #include <sys/ktr.h>
 
+#include <net/if_vf_status.h>
+
 MALLOC_DEFINE(M_IXGBE_SRIOV, "ix_sriov", "ix SR-IOV allocations");
 
 #define IXGBE_VF_MBX_CLEANUP_GRACE	(2 * SBT_1S)
@@ -59,10 +61,12 @@ ixgbe_has_legacy_iov_recovery(const struct ixgbe_hw *hw)
  * ixgbe_define_iov_schemas
  ************************************************************************/
 void
-ixgbe_define_iov_schemas(device_t dev, int *error)
+ixgbe_define_iov_schemas(struct ixgbe_softc *sc, int *error)
 {
+	device_t dev;
 	nvlist_t *pf_schema, *vf_schema;
 
+	dev = sc->dev;
 	pf_schema = pci_iov_schema_alloc_node();
 	vf_schema = pci_iov_schema_alloc_node();
 	pci_iov_schema_add_unicast_mac(vf_schema, "mac-addr", 0, NULL);
@@ -78,6 +82,8 @@ ixgbe_define_iov_schemas(device_t dev, int *error)
 	if (*error != 0) {
 		device_printf(dev,
 		    "Error %d setting up SR-IOV\n", *error);
+	} else {
+		sc->iov_attached = true;
 	}
 } /* ixgbe_define_iov_schemas */
 
@@ -1743,6 +1749,101 @@ ixgbe_mbx_pending(struct ixgbe_softc *sc)
 	return (false);
 }
 
+static const char *
+ixgbe_vf_api_version(uint16_t api_ver)
+{
+	switch (api_ver) {
+	case ixgbe_mbox_api_10:
+		return ("1.0");
+	case ixgbe_mbox_api_11:
+		return ("1.1");
+	case ixgbe_mbox_api_12:
+		return ("1.2");
+	case ixgbe_mbox_api_13:
+		return ("1.3");
+	case ixgbe_mbox_api_14:
+		return ("1.4");
+	case ixgbe_mbox_api_15:
+		return ("1.5");
+	case ixgbe_mbox_api_16:
+		return ("1.6");
+	case ixgbe_mbox_api_20:
+		return ("2.0");
+	default:
+		return (NULL);
+	}
+}
+
+int
+ixgbe_if_vf_status(if_ctx_t ctx, struct if_vf_status **statusp)
+{
+	struct ixgbe_softc *sc;
+	struct ixgbe_vf *vf;
+	struct if_vf_info *info;
+	struct if_vf_status *status;
+	const char *api_ver;
+	int i;
+
+	sc = iflib_get_softc(ctx);
+	if (!sc->iov_attached)
+		return (EOPNOTSUPP);
+	status = if_vf_status_alloc(sc->num_vfs);
+	if (status == NULL)
+		return (ENOMEM);
+	for (i = 0; i < sc->num_vfs; i++) {
+		vf = &sc->vfs[i];
+		info = &status->vfs[i];
+		info->fields = IFVF_F_CONFIGURED | IFVF_F_INITIALIZED |
+		    IFVF_F_VLAN_MODE | IFVF_F_VLAN_COUNT |
+		    IFVF_F_NUM_TX_QUEUES | IFVF_F_NUM_RX_QUEUES |
+		    IFVF_F_ALLOW_SET_MAC |
+		    IFVF_F_ALLOW_SET_VLAN | IFVF_F_MAC_ANTI_SPOOF |
+		    IFVF_F_ALLOW_PROMISC | IFVF_F_TRAFFIC_ALLOWED |
+		    IFVF_F_FAULT_BLOCKED | IFVF_F_QUARANTINED;
+		info->index = i;
+		info->configured = (vf->flags & IXGBE_VF_ACTIVE) != 0;
+		info->initialized =
+		    (vf->flags & (IXGBE_VF_CTS | IXGBE_VF_INIT_DONE)) ==
+		    (IXGBE_VF_CTS | IXGBE_VF_INIT_DONE);
+		if (!ETHER_IS_ZERO(vf->ether_addr)) {
+			memcpy(info->mac, vf->ether_addr, sizeof(info->mac));
+			info->fields |= IFVF_F_MAC;
+		}
+		if (vf->default_vlan == 0)
+			info->vlan_mode = IFVF_VLAN_TRUNK;
+		else {
+			info->vlan_mode = IFVF_VLAN_ACCESS;
+			info->vlan = vf->default_vlan;
+			info->vlan_pcp = 0;
+			info->vlan_proto = ETHERTYPE_VLAN;
+			info->fields |= IFVF_F_VLAN | IFVF_F_VLAN_PCP |
+			    IFVF_F_VLAN_PROTO;
+		}
+		info->vlan_count = vf->num_vlans;
+		info->tx_queue_count = ixgbe_vf_queues(sc->iov_mode);
+		info->rx_queue_count = ixgbe_vf_queues(sc->iov_mode);
+		info->allow_set_mac = (vf->flags & IXGBE_VF_CAP_MAC) != 0;
+		info->allow_set_vlan = (vf->flags & IXGBE_VF_CAP_VLAN) != 0;
+		info->mac_anti_spoof =
+		    (vf->flags & IXGBE_VF_ANTI_SPOOF) != 0;
+		info->allow_promisc =
+		    (vf->flags & IXGBE_VF_ALLOW_PROMISC) != 0;
+		info->traffic_allowed = info->configured &&
+		    (vf->flags & IXGBE_VF_TRAFFIC_DISABLED) == 0;
+		info->fault_blocked =
+		    (vf->flags & IXGBE_VF_TRAFFIC_DISABLED) != 0;
+		info->quarantined = (vf->flags & IXGBE_VF_QUARANTINED) != 0;
+		api_ver = ixgbe_vf_api_version(vf->api_ver);
+		if (api_ver != NULL) {
+			strlcpy(info->api_version, api_ver,
+			    sizeof(info->api_version));
+			info->fields |= IFVF_F_API_VERSION;
+		}
+	}
+	*statusp = status;
+	return (0);
+}
+
 int
 ixgbe_iov_validate(struct ixgbe_softc *sc, u16 num_vfs)
 {
@@ -1817,6 +1918,8 @@ ixgbe_if_iov_init(if_ctx_t ctx, u16 num_vfs, const nvlist_t *config)
 		retval = ENOMEM;
 		goto err_init_iov;
 	}
+	for (i = 0; i < num_vfs; i++)
+		sc->vfs[i].api_ver = IXGBE_API_VER_UNKNOWN;
 	num_filters = sc->hw.mac.num_rar_entries - num_vfs - 1 -
 	    IXGBE_MAX_PF_MAC_FILTERS;
 	if (num_filters > 0) {
diff --git a/sys/dev/ixgbe/ixgbe.h b/sys/dev/ixgbe/ixgbe.h
index 46b84dd948c3..499c9a5bf056 100644
--- a/sys/dev/ixgbe/ixgbe.h
+++ b/sys/dev/ixgbe/ixgbe.h
@@ -497,6 +497,7 @@ struct ixgbe_softc {
 	sbintime_t		iov_recovery_time;
 	bool			iov_recovery_stop;
 	uint8_t			iov_recovery_cursor;
+	bool			iov_attached;
 	uint64_t		iov_dma_abort_events;
 	uint64_t		iov_dma_abort_flr_failures;
 	uint64_t		iov_dma_abort_quarantines;
diff --git a/sys/dev/ixgbe/ixgbe_sriov.h b/sys/dev/ixgbe/ixgbe_sriov.h
index 0a1eeb642366..9f1a1eb65aab 100644
--- a/sys/dev/ixgbe/ixgbe_sriov.h
+++ b/sys/dev/ixgbe/ixgbe_sriov.h
@@ -86,6 +86,8 @@
 
 int  ixgbe_if_iov_vf_add(if_ctx_t, u16, const nvlist_t *);
 int  ixgbe_if_iov_init(if_ctx_t, u16, const nvlist_t *);
+struct if_vf_status;
+int  ixgbe_if_vf_status(if_ctx_t, struct if_vf_status **);
 int  ixgbe_iov_validate(struct ixgbe_softc *, u16);
 void ixgbe_if_iov_uninit(if_ctx_t);
 void ixgbe_initialize_iov(struct ixgbe_softc *);
@@ -96,7 +98,7 @@ void ixgbe_ping_all_vfs(struct ixgbe_softc *);
 void ixgbe_init_iov_recovery(struct ixgbe_softc *);
 void ixgbe_schedule_iov_recovery(struct ixgbe_softc *);
 u_int ixgbe_iov_rebuild_mta(struct ixgbe_softc *);
-void ixgbe_define_iov_schemas(device_t, int *);
+void ixgbe_define_iov_schemas(struct ixgbe_softc *, int *);
 void ixgbe_align_all_queue_indices(struct ixgbe_softc *);
 int  ixgbe_vf_que_index(int, int, int);
 u32  ixgbe_get_mtqc(int);