mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown
@ 2026-11-02 12:34 Mehmet Fide
  2026-11-17 10:25 ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 5+ messages in thread
From: Mehmet Fide @ 2026-11-02 12:34 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Chun-Yeow Yeoh, linux-wireless, linux-kernel, mehmet.fide

From: Mehmet Fide <mehmet.fide@screeningeagle.com>

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".

Skip the beacon while the countdown is complete and finish the switch
from there, as ath9k does for non-EDMA chips. Finishing from the skip
also covers a count of 2, where the first fetch can complete the
countdown before csa_vif is set.

Tested on 6.12 with an AR9271 AP and hostapd chan_switch: the CSA beacon
was fetched again in 3 of 40 switches with a count of 5 before and in
none after, and all 60 switches with a count of 2 completed.

Fixes: f0e449627e4a ("ath9k_htc: add support of channel switch")
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
 drivers/net/wireless/ath/ath9k/htc_drv_beacon.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
index 81fa7cbad892..2b5bf07511bb 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
@@ -214,6 +214,13 @@ static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
 		return;
 	}
 
+	if (vif->bss_conf.csa_active &&
+	    ieee80211_beacon_cntdwn_is_complete(vif, 0)) {
+		spin_unlock_bh(&priv->beacon_lock);
+		ath9k_htc_csa_is_finished(priv);
+		return;
+	}
+
 	/* Get a new beacon */
 	beacon = ieee80211_beacon_get(priv->hw, vif, 0);
 	if (!beacon) {

base-commit: a3ddbb45768717b5c9f923489387cf55c838d1ad
-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown
  2026-11-02 12:34 [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown Mehmet Fide
@ 2026-11-17 10:25 ` Toke Høiland-Jørgensen
  2026-11-17 12:26   ` Mehmet Fide
  0 siblings, 1 reply; 5+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-17 10:25 UTC (permalink / raw)
  To: Mehmet Fide; +Cc: Chun-Yeow Yeoh, linux-wireless, linux-kernel, mehmet.fide

Mehmet Fide <mehmet.fide@gmail.com> writes:

> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
>
> 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".
>
> Skip the beacon while the countdown is complete and finish the switch
> from there, as ath9k does for non-EDMA chips. Finishing from the skip
> also covers a count of 2, where the first fetch can complete the
> countdown before csa_vif is set.
>
> Tested on 6.12 with an AR9271 AP and hostapd chan_switch: the CSA beacon
> was fetched again in 3 of 40 switches with a count of 5 before and in
> none after, and all 60 switches with a count of 2 completed.
>
> Fixes: f0e449627e4a ("ath9k_htc: add support of channel switch")
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
> ---
>  drivers/net/wireless/ath/ath9k/htc_drv_beacon.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
> index 81fa7cbad892..2b5bf07511bb 100644
> --- a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
> +++ b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
> @@ -214,6 +214,13 @@ static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
>  		return;
>  	}
>  
> +	if (vif->bss_conf.csa_active &&
> +	    ieee80211_beacon_cntdwn_is_complete(vif, 0)) {
> +		spin_unlock_bh(&priv->beacon_lock);
> +		ath9k_htc_csa_is_finished(priv);
> +		return;
> +	}
> +

Hmm, there's something odd going on with the locking / vif selection
here. In the snippet above, you're basically replicating the checks
inside ath9k_htc_csa_is_finished(), before then calling
ath9k_htc_csa_is_finished() itself. Which presumably then repeats the
same checks, and does the ieee80211_csa_finish()? Or at least that's
the logic for why this is correct, AFAIU, no?

But ath9k_htc_csa_is_finished() doesn't take the 'vif' from the beacon
slot, it takes the 'priv' pointer that was passed to the function. Which
implies that either:

(1) priv->csa_vif is guaranteed to be the same whenever csa_active is
set, and thus this doesn't matter, or

(2) there's a bug here and things can get mixed up.

Since there's already a call to ath9k_htc_csa_is_finished(priv) at the
end of that same function, I'm assuming it's case (1) that holds. In
which case, I don't see any reason why we can't just do an early return
before taking the lock as:

if (ath9k_htc_csa_is_finished(priv))
   return;

The priv->csa_vif pointer is not protected by the beacon lock anyway[0], so
I don't think this would lead to trouble?

Thoughts?

-Toke

[0] Side note - the priv->csa_vif pointer seems to be quite
inconsistently lock-protected: it's set under priv->mutex in the driver
setup paths, under the mac80211 wiphy lock by the
channel_switch_beacon() callback, and under the wmi lock by
ath9k_htc_csa_is_finished() itself. Not quite sure if there's some other
dependency between these locks that ensures this works, or if that's
just a total coincidence...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown
  2026-11-17 10:25 ` Toke Høiland-Jørgensen
@ 2026-11-17 12:26   ` Mehmet Fide
  2026-11-17 13:57     ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 5+ messages in thread
From: Mehmet Fide @ 2026-11-17 12:26 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Chun-Yeow Yeoh, linux-wireless, linux-kernel, mehmet.fide

Hi Toke,

> if (ath9k_htc_csa_is_finished(priv))
>    return;

That would skip one beacon at most. ath9k_htc_csa_is_finished() clears
csa_vif when it calls ieee80211_csa_finish(), but csa_active stays set
until the second round of __ieee80211_csa_finalize(), after the channel
change, and ath9k_htc_set_channel() turns beaconing back on in between.
The next SWBA finds csa_vif NULL and fetches the CSA beacon again.

On an AR9271 AP, with a sniffer on each channel counting CSA beacons
heard on the new channel, in 120 switches: 3 without a change, 5 with
the early return, 1 with this patch.

The one left comes from mac80211. __ieee80211_csa_finalize() clears
csa_active before ieee80211_set_after_csa_beacon() replaces the CSA
beacon, and ieee80211_beacon_get() still counts that beacon down, so an
SWBA in between passes the csa_active test and gets the old beacon.
With a print added: 3 such fetches in 200 switches, the same 3 beacons
on the air. ath9k_csa_is_finished() has the same window.

Dropping the csa_active test here would close it, but
ieee80211_beacon_cntdwn_is_complete() warns when the AP has no beacon,
and ieee80211_stop_ap() removes it before beaconing is disabled. So I'd
rather fix the order in mac80211 in a separate patch. Does that sound
right to you?

On csa_vif: remove_interface, bss_info_changed and
channel_switch_beacon all run under the wiphy mutex; only the WMI
tasklet does not, as wmi_lock is dropped before the SWBA is handled.
250 back-to-back switches and 25 AP stops in a countdown showed no
problem.

Mehmet

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown
  2026-11-17 12:26   ` Mehmet Fide
@ 2026-11-17 13:57     ` Toke Høiland-Jørgensen
  2026-11-17 15:13       ` Mehmet Fide
  0 siblings, 1 reply; 5+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-17 13:57 UTC (permalink / raw)
  To: Mehmet Fide; +Cc: Chun-Yeow Yeoh, linux-wireless, linux-kernel, mehmet.fide

Mehmet Fide <mehmet.fide@gmail.com> writes:

> Hi Toke,
>
>> if (ath9k_htc_csa_is_finished(priv))
>>    return;
>
> That would skip one beacon at most. ath9k_htc_csa_is_finished() clears
> csa_vif when it calls ieee80211_csa_finish(), but csa_active stays set
> until the second round of __ieee80211_csa_finalize(), after the channel
> change, and ath9k_htc_set_channel() turns beaconing back on in between.
> The next SWBA finds csa_vif NULL and fetches the CSA beacon again.

Hmm, so it seems that the ath9k driver used to have a similar structure
(with the csa_vif pointer), but that was changed in commit:

4effc6fda7ab ("ath9k: prepare for multi-interface CSA support")

I think doing a similar change in ath9k_htc would allow us to have the
pre-check use the same function without this issue, *and* get rid of the
setting of csa_vif without any locks protecting it, no?

-Toke

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown
  2026-11-17 13:57     ` Toke Høiland-Jørgensen
@ 2026-11-17 15:13       ` Mehmet Fide
  0 siblings, 0 replies; 5+ messages in thread
From: Mehmet Fide @ 2026-11-17 15:13 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Chun-Yeow Yeoh, linux-wireless, linux-kernel, mehmet.fide

Hi Toke,

> I think doing a similar change in ath9k_htc would allow us to have the
> pre-check use the same function without this issue, *and* get rid of the
> setting of csa_vif without any locks protecting it, no?

Yes. With the check on the vif of the beacon slot, csa_vif and the
channel_switch_beacon callback can go. I'll send that as v2, and the
mac80211 order change as a separate patch.

Mehmet

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 12:34 [PATCH ath-next] wifi: ath9k_htc: do not fetch the beacon of a finished countdown Mehmet Fide
2026-11-17 10:25 ` Toke Høiland-Jørgensen
2026-11-17 12:26   ` Mehmet Fide
2026-11-17 13:57     ` Toke Høiland-Jørgensen
2026-11-17 15:13       ` Mehmet Fide

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®