* [PATCH wireless-next] wifi: cfg80211: keep the DFS state when a self-managed wiphy applies its domain again
@ 2026-12-01 16:07 Stanislaw Pal
0 siblings, 0 replies; only message in thread
From: Stanislaw Pal @ 2026-12-01 16:07 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, Louis Komiwes
A self-managed wiphy applies its regulatory domain again whenever the
driver asks for it, and handle_channel_custom() then starts every
channel at NL80211_DFS_USABLE. A channel that had completed its CAC is
no longer available, and one in its non-occupancy period is usable
again. Nothing acts on that at once. reg_check_chans_work() does, 60 s
later (REG_ENFORCE_GRACE_MS): an AP or a mesh on a chandef that needs
DFS is now on channels that are only usable, so it is stopped. hostapd
logs the NL80211_CMD_STOP_AP only at debug level and keeps reporting
the AP as enabled.
ath11k asks after every restart of its firmware: the firmware sends its
channel list again and the driver passes it on. Seen on an IPQ5018 with
a QCN6122 (TP-Link Archer AX55 v1) and reported with a QCN9074 (Xiaomi
AX6000): AP and mesh on channel 36 at 160 MHz, which takes in channels
52-64, a simulated firmware crash, recovery within 5 s, "DFS state:
usable" 7 s after the crash, and carrier and channel gone 61 s after
that. At 80 MHz, without a radar channel, nothing happens.
ath12k does the same, and there one wiphy can carry several radios.
Reported with a QCN9224 on an IPQ53xx (5 GHz and 6 GHz on one wiphy):
a 5 GHz AP on channel 100 at 80 MHz after a completed CAC, then a
restart of the 6 GHz radio only. Channel 100 drops to usable, and the
5 GHz AP stops 61 s after the restart although its own radio was never
touched. Setting the country again (iw reg set) takes the same path
through the driver and ends a non-occupancy period after a radar early.
Save the DFS state of every channel before the domain is applied and
put it back on the channels whose place in the DFS scheme did not
change: radar before and after, not disabled, and the DFS region of
the domain the same. These are the conditions under which
reg_copy_dfs_chan_state() already carries a state from one wiphy to
another. A domain with another DFS region, or a channel that gained or
lost its radar flag, starts from usable as before.
Tested as a backport to the cfg80211 of OpenWrt on 6.18, on an Archer
AX55 v1 and a GL.iNet GL-B3000 (both IPQ5018 with a QCN6122): three
firmware crashes on each, channel 52 stays available throughout and the
AP and the mesh stay up. Tested the same way by Louis Komiwes on the
QCN9224: channel 100 stays available, both APs stay up, and a radar
channel keeps its non-occupancy period across iw reg set. On this tree
it is build-tested only (arm64, W=1).
I used an LLM (Claude) to help find the cause and write this patch; I
reviewed and tested the result.
Tested-by: Louis Komiwes <louis.komiwes@viarezo.fr>
Signed-off-by: Stanislaw Pal <kuncy7@gmail.com>
---
net/wireless/reg.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 090d21739d..0a2af9c3d5 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -3230,11 +3230,100 @@ static void reg_process_pending_beacon_hints(void)
}
}
+/*
+ * The DFS state of a channel before a regulatory domain is applied to the
+ * wiphy, see reg_dfs_state_save().
+ */
+struct reg_dfs_chan_state {
+ u32 flags;
+ enum nl80211_dfs_state dfs_state;
+ unsigned long dfs_state_entered;
+};
+
+/*
+ * handle_channel_custom() starts every channel at NL80211_DFS_USABLE, so a
+ * self-managed wiphy that applies a regulatory domain again loses the CAC
+ * results and the non-occupancy periods it had. Nothing acts on that right
+ * away, but reg_check_chans_work() does REG_ENFORCE_GRACE_MS later: an AP or
+ * a mesh on a channel that needs DFS is then stopped.
+ *
+ * Save the states before the domain is applied and put them back on the
+ * channels whose place in the DFS scheme did not change: radar before and
+ * after, not disabled, and the DFS region of the domain the same. These are
+ * the conditions under which reg_copy_dfs_chan_state() carries a state from
+ * one wiphy to another.
+ */
+static struct reg_dfs_chan_state *reg_dfs_state_save(struct wiphy *wiphy)
+{
+ struct reg_dfs_chan_state *saved, *s;
+ struct ieee80211_supported_band *sband;
+ enum nl80211_band band;
+ unsigned int n = 0, i;
+
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ sband = wiphy->bands[band];
+ if (sband)
+ n += sband->n_channels;
+ }
+
+ saved = kzalloc_objs(*saved, n);
+ if (!saved)
+ return NULL;
+
+ s = saved;
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ sband = wiphy->bands[band];
+ if (!sband)
+ continue;
+ for (i = 0; i < sband->n_channels; i++, s++) {
+ const struct ieee80211_channel *chan = &sband->channels[i];
+
+ s->flags = chan->flags;
+ s->dfs_state = chan->dfs_state;
+ s->dfs_state_entered = chan->dfs_state_entered;
+ }
+ }
+
+ return saved;
+}
+
+static void reg_dfs_state_restore(struct wiphy *wiphy,
+ const struct reg_dfs_chan_state *saved)
+{
+ struct ieee80211_supported_band *sband;
+ const struct reg_dfs_chan_state *s = saved;
+ enum nl80211_band band;
+ unsigned int i;
+
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ sband = wiphy->bands[band];
+ if (!sband)
+ continue;
+ for (i = 0; i < sband->n_channels; i++, s++) {
+ struct ieee80211_channel *chan = &sband->channels[i];
+
+ if (!(s->flags & IEEE80211_CHAN_RADAR) ||
+ s->flags & IEEE80211_CHAN_DISABLED)
+ continue;
+ if (!(chan->flags & IEEE80211_CHAN_RADAR) ||
+ chan->flags & IEEE80211_CHAN_DISABLED)
+ continue;
+ if (chan->dfs_state != NL80211_DFS_USABLE ||
+ s->dfs_state == NL80211_DFS_USABLE)
+ continue;
+
+ chan->dfs_state = s->dfs_state;
+ chan->dfs_state_entered = s->dfs_state_entered;
+ }
+ }
+}
+
static void reg_process_self_managed_hint(struct wiphy *wiphy)
{
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
const struct ieee80211_regdomain *tmp;
const struct ieee80211_regdomain *regd;
+ struct reg_dfs_chan_state *dfs_saved = NULL;
enum nl80211_band band;
struct regulatory_request request = {};
@@ -3253,12 +3342,19 @@ static void reg_process_self_managed_hint(struct wiphy *wiphy)
return;
tmp = get_wiphy_regdom(wiphy);
+ if (tmp && tmp->dfs_region == regd->dfs_region)
+ dfs_saved = reg_dfs_state_save(wiphy);
rcu_assign_pointer(wiphy->regd, regd);
rcu_free_regdom(tmp);
for (band = 0; band < NUM_NL80211_BANDS; band++)
handle_band_custom(wiphy, wiphy->bands[band], regd);
+ if (dfs_saved) {
+ reg_dfs_state_restore(wiphy, dfs_saved);
+ kfree(dfs_saved);
+ }
+
reg_process_ht_flags(wiphy);
request.wiphy_idx = get_wiphy_idx(wiphy);
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 16:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:07 [PATCH wireless-next] wifi: cfg80211: keep the DFS state when a self-managed wiphy applies its domain again Stanislaw Pal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.