From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Cc: johannes@sipsolutions.net
Subject: [RFC 2/2] mac80211: ensure that only one channel context is active per radio
Date: Wed, 22 May 2024 14:30:05 +0200 [thread overview]
Message-ID: <20240522123005.41026-2-nbd@nbd.name> (raw)
In-Reply-To: <20240522123005.41026-1-nbd@nbd.name>
With multi-radio hardware, we need to ensure that a radio is not assigned to
multiple channels at the same time.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
include/net/mac80211.h | 2 +
net/mac80211/chan.c | 96 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 87 insertions(+), 11 deletions(-)
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 2bb24aba84fd..0e9b61726067 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -250,6 +250,7 @@ struct ieee80211_chan_req {
* @min_def: the minimum channel definition currently required.
* @ap: the channel definition the AP actually is operating as,
* for use with (wider bandwidth) OFDMA
+ * @radio_idx: index of the wiphy radio used used for this channel
* @rx_chains_static: The number of RX chains that must always be
* active on the channel to receive MIMO transmissions
* @rx_chains_dynamic: The number of RX chains that must be enabled
@@ -264,6 +265,7 @@ struct ieee80211_chanctx_conf {
struct cfg80211_chan_def min_def;
struct cfg80211_chan_def ap;
+ int radio_idx;
u8 rx_chains_static, rx_chains_dynamic;
bool radar_enabled;
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 380695fdc32f..589041de99c6 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -60,11 +60,24 @@ static int ieee80211_num_chanctx(struct ieee80211_local *local)
return num;
}
-static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local)
+static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local,
+ int radio_idx)
{
+ struct ieee80211_chanctx *ctx;
+
lockdep_assert_wiphy(local->hw.wiphy);
- return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local);
+ if (ieee80211_num_chanctx(local) >= ieee80211_max_num_channels(local))
+ return false;
+
+ if (radio_idx < 0)
+ return true;
+
+ list_for_each_entry(ctx, &local->chanctx_list, list)
+ if (ctx->conf.radio_idx == radio_idx)
+ return false;
+
+ return true;
}
static struct ieee80211_chanctx *
@@ -638,7 +651,8 @@ ieee80211_chanctx_radar_required(struct ieee80211_local *local,
static struct ieee80211_chanctx *
ieee80211_alloc_chanctx(struct ieee80211_local *local,
const struct ieee80211_chan_req *chanreq,
- enum ieee80211_chanctx_mode mode)
+ enum ieee80211_chanctx_mode mode,
+ int radio_idx)
{
struct ieee80211_chanctx *ctx;
@@ -656,6 +670,7 @@ ieee80211_alloc_chanctx(struct ieee80211_local *local,
ctx->conf.rx_chains_dynamic = 1;
ctx->mode = mode;
ctx->conf.radar_enabled = false;
+ ctx->conf.radio_idx = radio_idx;
_ieee80211_recalc_chanctx_min_def(local, ctx, NULL);
return ctx;
@@ -689,14 +704,14 @@ static struct ieee80211_chanctx *
ieee80211_new_chanctx(struct ieee80211_local *local,
const struct ieee80211_chan_req *chanreq,
enum ieee80211_chanctx_mode mode,
- bool assign_on_failure)
+ bool assign_on_failure, int radio_idx)
{
struct ieee80211_chanctx *ctx;
int err;
lockdep_assert_wiphy(local->hw.wiphy);
- ctx = ieee80211_alloc_chanctx(local, chanreq, mode);
+ ctx = ieee80211_alloc_chanctx(local, chanreq, mode, radio_idx);
if (!ctx)
return ERR_PTR(-ENOMEM);
@@ -1053,6 +1068,51 @@ int ieee80211_link_unreserve_chanctx(struct ieee80211_link_data *link)
return 0;
}
+static bool
+ieee80211_get_radio_freq_match(const struct wiphy_radio *radio,
+ const struct ieee80211_chan_req *chanreq)
+{
+ const struct wiphy_radio_freq_range *r;
+ u32 freq;
+ int i;
+
+ if (!radio->n_freq_range)
+ return true;
+
+ freq = ieee80211_channel_to_khz(chanreq->oper.chan);
+ for (i = 0; i < radio->n_freq_range; i++) {
+ r = &radio->freq_range[i];
+ if (freq >= r->start_freq && freq <= r->end_freq)
+ return true;
+ }
+
+ return false;
+}
+
+static int
+ieee80211_get_chanreq_radio(struct ieee80211_local *local,
+ const struct ieee80211_chan_req *chanreq)
+{
+ struct wiphy *wiphy = local->hw.wiphy;
+ const struct wiphy_radio *radio;
+ u32 band_mask;
+ int i;
+
+ band_mask = BIT(chanreq->oper.chan->band);
+ for (i = 0; i < wiphy->n_radio; i++) {
+ radio = &wiphy->radio[i];
+ if (!(radio->band_mask & band_mask))
+ continue;
+
+ if (!ieee80211_get_radio_freq_match(radio, chanreq))
+ continue;
+
+ return i;
+ }
+
+ return -1;
+}
+
int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
const struct ieee80211_chan_req *chanreq,
enum ieee80211_chanctx_mode mode,
@@ -1061,6 +1121,7 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
struct ieee80211_sub_if_data *sdata = link->sdata;
struct ieee80211_local *local = sdata->local;
struct ieee80211_chanctx *new_ctx, *curr_ctx, *ctx;
+ int radio_idx;
lockdep_assert_wiphy(local->hw.wiphy);
@@ -1070,9 +1131,10 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
new_ctx = ieee80211_find_reservation_chanctx(local, chanreq, mode);
if (!new_ctx) {
- if (ieee80211_can_create_new_chanctx(local)) {
+ radio_idx = ieee80211_get_chanreq_radio(local, chanreq);
+ if (ieee80211_can_create_new_chanctx(local, radio_idx)) {
new_ctx = ieee80211_new_chanctx(local, chanreq, mode,
- false);
+ false, radio_idx);
if (IS_ERR(new_ctx))
return PTR_ERR(new_ctx);
} else {
@@ -1111,6 +1173,9 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
if (!list_empty(&ctx->reserved_links))
continue;
+ if (ctx->conf.radio_idx != radio_idx)
+ continue;
+
curr_ctx = ctx;
break;
}
@@ -1126,7 +1191,8 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
!list_empty(&curr_ctx->reserved_links))
return -EBUSY;
- new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode);
+ new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode,
+ radio_idx);
if (!new_ctx)
return -ENOMEM;
@@ -1745,6 +1811,7 @@ int _ieee80211_link_use_channel(struct ieee80211_link_data *link,
struct ieee80211_chanctx *ctx;
u8 radar_detect_width = 0;
bool reserved = false;
+ int radio_idx;
int ret;
lockdep_assert_wiphy(local->hw.wiphy);
@@ -1773,11 +1840,18 @@ int _ieee80211_link_use_channel(struct ieee80211_link_data *link,
ctx = ieee80211_find_chanctx(local, link, chanreq, mode);
/* Note: context is now reserved */
- if (ctx)
+ if (ctx) {
reserved = true;
- else
+ } else {
+ radio_idx = ieee80211_get_chanreq_radio(local, chanreq);
+ if (ieee80211_can_create_new_chanctx(local, radio_idx)) {
+ ret = -EBUSY;
+ goto out;
+ }
+
ctx = ieee80211_new_chanctx(local, chanreq, mode,
- assign_on_failure);
+ assign_on_failure, radio_idx);
+ }
if (IS_ERR(ctx)) {
ret = PTR_ERR(ctx);
goto out;
--
2.44.0
next prev parent reply other threads:[~2024-05-22 12:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-22 12:30 [RFC 1/2] cfg80211: add support for advertising multiple radios belonging to a wiphy Felix Fietkau
2024-05-22 12:30 ` Felix Fietkau [this message]
2024-05-22 14:23 ` Ben Greear
2024-05-22 14:46 ` Felix Fietkau
2024-05-22 16:43 ` Ben Greear
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=20240522123005.41026-2-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/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