From: Mehmet Fide ath9k_htc_send_beacon() checks the channel switch countdown only after ieee80211_beacon_get(). mac80211 replaces the CSA beacon only after the channel change, and ath9k_htc_set_channel() re-enables beaconing before that, so an SWBA event can fetch the CSA beacon again on the new channel and mac80211 reports "beacon TX faster than countdown". Check the vif of the beacon slot before the fetch, as ath9k does since commit 4effc6fda7ab ("ath9k: prepare for multi-interface CSA support"): skip the beacon while its countdown is complete and finish the switch from there. The check reads vif->bss_conf.csa_active instead of priv->csa_vif, which ath9k_htc_csa_is_finished() cleared at the first ieee80211_csa_finish() and which was set and cleared without a common lock, so drop csa_vif and the channel_switch_beacon callback that set it. Calling ieee80211_csa_finish() more than once is fine. Fixes: f0e449627e4a ("ath9k_htc: add support of channel switch") Signed-off-by: Mehmet Fide --- Notes: v2: - check the vif of the beacon slot as ath9k does, and drop csa_vif and channel_switch_beacon (Toke) - based on ath9k-pending main, where "wifi: ath9k_htc: clear csa_vif when a switch is aborted" is applied; its csa_vif lines go with csa_vif Tested on rtw-next on an i.MX8MP board with an AR9271 as AP, hostapd switching between channel 1 and 6, one sniffer on each channel counting CSA beacons heard on the new channel: 3 in 80 switches with a count of 5 without the patch; with it 3 in 200 with a count of 5 and none in 40 with a count of 2. The 3 left are fetched between mac80211 clearing csa_active and replacing the CSA beacon (a print in the driver showed the same 3); a mac80211 patch for that follows. With both, none in 200 switches with a count of 5 and 80 with a count of 2. 150 back-to-back switches and 65 AP stops in and out of a countdown gave no kernel report, lockdep on. v1: https://lore.kernel.org/r/20261102123430.1136741-1-mehmet.fide@gmail.com/ drivers/net/wireless/ath/ath9k/htc.h | 2 -- .../net/wireless/ath/ath9k/htc_drv_beacon.c | 36 +++++++++---------- drivers/net/wireless/ath/ath9k/htc_drv_main.c | 20 ----------- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h index 59e0b3cf7f0f..fd128426b6fe 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h @@ -534,7 +534,6 @@ struct ath9k_htc_priv { struct ath9k_debug debug; #endif struct mutex mutex; - struct ieee80211_vif *csa_vif; }; static inline void ath_read_cachesize(struct ath_common *common, int *csz) @@ -588,7 +587,6 @@ void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv); void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event); void ath9k_tx_failed_tasklet(struct tasklet_struct *t); void ath9k_htc_tx_cleanup_timer(struct timer_list *t); -bool ath9k_htc_csa_is_finished(struct ath9k_htc_priv *priv); int ath9k_rx_init(struct ath9k_htc_priv *priv); void ath9k_rx_cleanup(struct ath9k_htc_priv *priv); diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c index b478af1502f2..7e49ab8181f3 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c @@ -188,6 +188,18 @@ static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv, spin_unlock_bh(&priv->beacon_lock); } +static bool ath9k_htc_csa_is_finished(struct ieee80211_vif *vif) +{ + if (!vif->bss_conf.csa_active) + return false; + + if (!ieee80211_beacon_cntdwn_is_complete(vif, 0)) + return false; + + ieee80211_csa_finish(vif, 0); + return true; +} + static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv, int slot) { @@ -214,6 +226,11 @@ static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv, return; } + if (ath9k_htc_csa_is_finished(vif)) { + spin_unlock_bh(&priv->beacon_lock); + return; + } + /* Get a new beacon */ beacon = ieee80211_beacon_get(priv->hw, vif, 0); if (!beacon) { @@ -258,7 +275,7 @@ static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv, spin_unlock_bh(&priv->beacon_lock); - ath9k_htc_csa_is_finished(priv); + ath9k_htc_csa_is_finished(vif); } static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv, @@ -508,20 +525,3 @@ void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv) return; } } - -bool ath9k_htc_csa_is_finished(struct ath9k_htc_priv *priv) -{ - struct ieee80211_vif *vif; - - vif = priv->csa_vif; - if (!vif || !vif->bss_conf.csa_active) - return false; - - if (!ieee80211_beacon_cntdwn_is_complete(vif, 0)) - return false; - - ieee80211_csa_finish(vif, 0); - - priv->csa_vif = NULL; - return true; -} diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c index b46be3682f21..320deb6c3630 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c @@ -1135,9 +1135,6 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, priv->nvifs--; priv->vif_slot &= ~(1 << avp->index); - if (priv->csa_vif == vif) - priv->csa_vif = NULL; - ath9k_htc_remove_station(priv, vif, NULL); DEC_VIF(priv, vif->type); @@ -1569,9 +1566,6 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, priv->cur_beacon_conf.enable_beacon = 0; ath9k_htc_beacon_config(priv, vif); } - - if (priv->csa_vif == vif && !bss_conf->csa_active) - priv->csa_vif = NULL; } if (changed & BSS_CHANGED_BEACON_INT) { @@ -1861,19 +1855,6 @@ static int ath9k_htc_get_antenna(struct ieee80211_hw *hw, int radio_idx, return 0; } -static void ath9k_htc_channel_switch_beacon(struct ieee80211_hw *hw, - struct ieee80211_vif *vif, - struct cfg80211_chan_def *chandef) -{ - struct ath9k_htc_priv *priv = hw->priv; - - /* mac80211 does not support CSA in multi-if cases (yet) */ - if (WARN_ON(priv->csa_vif)) - return; - - priv->csa_vif = vif; -} - struct ieee80211_ops ath9k_htc_ops = { .add_chanctx = ieee80211_emulate_add_chanctx, .remove_chanctx = ieee80211_emulate_remove_chanctx, @@ -1905,7 +1886,6 @@ struct ieee80211_ops ath9k_htc_ops = { .set_bitrate_mask = ath9k_htc_set_bitrate_mask, .get_stats = ath9k_htc_get_stats, .get_antenna = ath9k_htc_get_antenna, - .channel_switch_beacon = ath9k_htc_channel_switch_beacon, #ifdef CONFIG_ATH9K_HTC_DEBUGFS .get_et_sset_count = ath9k_htc_get_et_sset_count, base-commit: 465fcc982a221f774594aa7d7351fde8c03a3deb -- 2.56.0