Page MenuHomeFreeBSD

D60006.id.diff
No OneTemporary

D60006.id.diff

Index: share/man/man9/Makefile
===================================================================
--- share/man/man9/Makefile
+++ share/man/man9/Makefile
@@ -1315,6 +1315,7 @@
MLINKS+=iflibdd.9 ifdi_attach_pre.9 \
iflibdd.9 ifdi_attach_post.9 \
iflibdd.9 ifdi_detach.9 \
+ iflibdd.9 ifdi_detach_pre.9 \
iflibdd.9 ifdi_get_counter.9 \
iflibdd.9 ifdi_i2c_req.9 \
iflibdd.9 ifdi_init.9 \
Index: share/man/man9/iflibdd.9
===================================================================
--- share/man/man9/iflibdd.9
+++ share/man/man9/iflibdd.9
@@ -54,6 +54,10 @@
.Fa "if_ctx_t ctx"
.Fc
.Ss "Optional Functions"
+.Ft int
+.Fo ifdi_detach_pre
+.Fa "if_ctx_t ctx"
+.Fc
.Ft void
.Fo ifdi_vlan_register
.Fa "if_ctx_t ctx"
@@ -238,6 +242,23 @@
.It Fn ifdi_detach
Mandatory function that frees any resources allocated by the driver in
ifdi_attach_pre and ifdi_attach_post.
+.It Fn ifdi_detach_pre
+Optional function called with the context lock after iflib stops the
+datapath, but before normal detach removes the interface or releases queue
+structures, interrupts, and driver state.
+It may return an error to leave the device attached and stopped.
+For example, a driver that disabled bus mastering after a failed reset
+must retain its quarantine state until stale DMA addresses are discarded;
+it may reset the device here or refuse detach.
+It must not restart queue DMA or destroy resources needed after a refusal.
+When refusing detach, it must undo any detach-specific policy established by
+.Fn ifdi_power_prepare .
+.Pp
+This method is also called during failed-attach cleanup after a successful
+.Fn ifdi_attach_pre .
+The driver must tolerate partial initialization.
+There is no attached device to retain in that case, so an error is fatal
+rather than silently discarding quarantine state.
.It Fn ifdi_vlan_register
Optional function called by the VLAN config eventhandler.
.Va vtag
Index: sys/net/ifdi_if.m
===================================================================
--- sys/net/ifdi_if.m
+++ sys/net/ifdi_if.m
@@ -182,6 +182,16 @@
if_ctx_t _ctx;
};
+#
+# Optional veto after the datapath has stopped, but before detach releases
+# queue structures, interrupts, or the softc. A failure leaves the device
+# attached and stopped. Called with the context lock, including during
+# failed-attach cleanup; a failed attach cannot retain a vetoed device.
+#
+METHOD int detach_pre {
+ if_ctx_t _ctx;
+} DEFAULT null_int_op;
+
#
# Prepare driver policy which must be established before a terminal stop used
# for detach, suspend, or shutdown. This method must not start, stop, or alter
Index: sys/net/iflib.c
===================================================================
--- sys/net/iflib.c
+++ sys/net/iflib.c
@@ -5907,6 +5907,10 @@
CTX_LOCK(ctx);
}
+ if (attach_pre_succeeded && IFDI_DETACH_PRE(ctx) != 0)
+ panic("%s: cannot discard driver state after failed attach",
+ device_get_nameunit(dev));
+
if (queues_allocated) {
iflib_tqg_detach(ctx);
iflib_tx_structures_free(ctx);
@@ -5962,6 +5966,9 @@
{
if_t ifp = ctx->ifc_ifp;
device_t dev = ctx->ifc_dev;
+ kobjop_desc_t kobj_desc;
+ kobj_method_t *kobj_method;
+ bool detach_pre;
int error;
/* Make sure VLANS are not using driver */
@@ -5988,6 +5995,21 @@
CTX_UNLOCK(ctx);
return (error);
}
+ /* Only opt-in drivers need an early stop and a hardware detach veto. */
+ kobj_desc = &ifdi_detach_pre_desc;
+ kobj_method = kobj_lookup_method(((kobj_t)ctx)->ops->cls, NULL,
+ kobj_desc);
+ detach_pre = kobj_method != &kobj_desc->deflt;
+ if (detach_pre) {
+ iflib_stop(ctx);
+ error = IFDI_DETACH_PRE(ctx);
+ if (error != 0) {
+ device_printf(dev,
+ "Driver cannot safely detach: %d\n", error);
+ CTX_UNLOCK(ctx);
+ return (error);
+ }
+ }
STATE_LOCK(ctx);
ctx->ifc_flags |= IFC_IN_DETACH;
STATE_UNLOCK(ctx);
@@ -6011,7 +6033,8 @@
ether_ifdetach(ifp);
CTX_LOCK(ctx);
- iflib_stop(ctx);
+ if (!detach_pre)
+ iflib_stop(ctx);
CTX_UNLOCK(ctx);
iflib_rem_pfil(ctx);

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 5, 8:19 PM (2 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40248218
Default Alt Text
D60006.id.diff (3 KB)

Event Timeline