git: f75a28ea852c - stable/14 - iflib: Add restart transactions for IOV reconfiguration

Kevin Bowling <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a823773.2313c.612143d5__15291.5607717418$1786918785$gmane$org@gitrepo.freebsd.org>
The branch stable/14 has been updated by kbowling:

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

commit f75a28ea852c824d92f2fbc10de9412e8b3b7de4
Author:     Kevin Bowling <[email protected]>
AuthorDate: 2026-07-28 21:53:18 +0000
Commit:     Kevin Bowling <[email protected]>
CommitDate: 2026-08-16 22:18:01 +0000

    iflib: Add restart transactions for IOV reconfiguration
    
    Some devices remap the PF queues when entering or leaving SR-IOV. Add
    opt-in PCI IOV helpers that hold the iflib context lock across the
    complete stop, driver callback, and restart transaction.
    
    Existing drivers continue to use the non-restarting helpers.
    
    Sponsored by:   BBOX.io
    
    (cherry picked from commit f8fa2d77bc305bec519f9f02afe211e903c57573)
---
 sys/net/iflib.c | 22 ++++++++++++++++++++++
 sys/net/iflib.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index dcdbe816f9aa..0403b2d63ca8 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -5626,6 +5626,28 @@ iflib_device_iov_uninit(device_t dev)
 	CTX_UNLOCK(ctx);
 }
 
+void
+iflib_device_iov_uninit_restart(device_t dev)
+{
+	if_ctx_t ctx;
+	bool restart;
+
+	ctx = device_get_softc(dev);
+
+	CTX_LOCK(ctx);
+	/*
+	 * RUNNING can be clear while a watchdog reset is pending but the
+	 * hardware is still live.  Always stop before the driver changes its
+	 * queue layout, and use IFF_UP only to preserve administrative state.
+	 */
+	restart = (if_getflags(ctx->ifc_ifp) & IFF_UP) != 0;
+	iflib_stop(ctx);
+	IFDI_IOV_UNINIT(ctx);
+	if (restart)
+		iflib_init_locked(ctx);
+	CTX_UNLOCK(ctx);
+}
+
 int
 iflib_device_iov_add_vf(device_t dev, uint16_t vfnum, const nvlist_t *params)
 {
diff --git a/sys/net/iflib.h b/sys/net/iflib.h
index fbadab0af565..69ac12b27d0b 100644
--- a/sys/net/iflib.h
+++ b/sys/net/iflib.h
@@ -446,7 +446,9 @@ int iflib_device_shutdown(device_t);
 int iflib_device_probe_vendor(device_t);
 
 int iflib_device_iov_init(device_t, uint16_t, const nvlist_t *);
+int iflib_device_iov_init_restart(device_t, uint16_t, const nvlist_t *);
 void iflib_device_iov_uninit(device_t);
+void iflib_device_iov_uninit_restart(device_t);
 int iflib_device_iov_add_vf(device_t, uint16_t, const nvlist_t *);
 
 /*
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.