mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Koral Ilgun <koralilgun@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: johannes@sipsolutions.net, nbd@nbd.name,
	linux-kernel@vger.kernel.org,
	Koral Ilgun <koral.ilgun@adtran.com>
Subject: [PATCH wireless] wifi: mac80211: keep the radio index of a replaced chanctx
Date: Wed, 28 Oct 2026 12:06:13 -0700	[thread overview]
Message-ID: <20261028190613.497063-1-koralilgun@gmail.com> (raw)

From: Koral Ilgun <koral.ilgun@adtran.com>

ieee80211_replace_chanctx() gives the replacing context radio index
-1. After the swap, the radio of the replaced context counts one
context less. If the wiphy has room for one more channel, the next
reservation on that radio creates a second context there, beyond
the channel limit of the radio.

On an mt7996 with three radios and no interface on one of them,
every second channel switch that a station follows then moves the
station alone to a new context. The driver retunes the radio while
the APs on the old context still count down their own switch.

The replacing context now takes the radio of the context that it
replaces, if the new channel is valid on that radio.

Fixes: 27d4c03441eb ("wifi: mac80211: add wiphy radio assignment and validation")
Signed-off-by: Koral Ilgun <koral.ilgun@adtran.com>
---
Tested with Linux 6.18 and the mac80211 of backports-7.2 on an MT7996
device with three radios, one of them without an interface. The station
followed 16 channel switches of its uplink, 50 s apart. Without this
change, every second switch added a second context on the 5 GHz radio,
and the station moved alone. With it, all 16 switches swapped the
context, and the station and its APs moved together.

 net/mac80211/chan.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 9cba79507767..b814619e6701 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -1457,6 +1457,7 @@ ieee80211_replace_chanctx(struct ieee80211_local *local,
 	struct ieee80211_chanctx *new_ctx, *ctx;
 	struct wiphy *wiphy = local->hw.wiphy;
 	const struct wiphy_radio *radio;
+	int radio_idx;
 
 	if (!curr_ctx ||
 	    curr_ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED ||
@@ -1506,7 +1507,20 @@ ieee80211_replace_chanctx(struct ieee80211_local *local,
 	    ieee80211_chanctx_num_reserved(local, curr_ctx) != 0)
 		return ERR_PTR(-EBUSY);
 
-	new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1);
+	/*
+	 * The new context takes the place of curr_ctx on its radio. Without
+	 * a radio index, ieee80211_num_chanctx() counts one context less on
+	 * that radio, and the next reservation can add a context beyond the
+	 * channel limit of the radio.
+	 */
+	radio_idx = curr_ctx->conf.radio_idx;
+	if (radio_idx >= 0) {
+		radio = &wiphy->radio[radio_idx];
+		if (!cfg80211_radio_chandef_valid(radio, &chanreq->oper))
+			radio_idx = -1;
+	}
+
+	new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, radio_idx);
 	if (!new_ctx)
 		return ERR_PTR(-ENOMEM);
 

base-commit: 25e73f1d6868c759c8eb56cad4e411692c5341b4
-- 
2.43.0


                 reply	other threads:[~2026-10-28 19:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028190613.497063-1-koralilgun@gmail.com \
    --to=koralilgun@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=koral.ilgun@adtran.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®